Linux-rt-users Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH v2] rt-tests: pi_stress: fix testing threads' smp affinity
@ 2021-03-29  3:00 Jiafei Pan
  0 siblings, 0 replies; only message in thread
From: Jiafei Pan @ 2021-03-29  3:00 UTC (permalink / raw)
  To: williams, jkacur; +Cc: linux-rt-users, jiafei.pan, Jiafei Pan

This patch include the following modifications:
1. Make sure test threads and admin threads don't run on the same CPU
   Core if uniprocessor is not set or not on single Core platform to
   avoid starvation of admin threads.
2. Force to use SCHED_RR if more than one Group running on a CPU
   Core to avoid test failure because threads in different Groups
   are using the same priority, SCHED_FIFO which is default policy
   and it maybe trigger deadlock of testing threads.

Signed-off-by: Jiafei Pan <Jiafei.Pan@nxp.com>

Changes for v2:
	fix some typo.

---
 src/pi_tests/pi_stress.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/src/pi_tests/pi_stress.c b/src/pi_tests/pi_stress.c
index 49f89b7..e8925e3 100644
--- a/src/pi_tests/pi_stress.c
+++ b/src/pi_tests/pi_stress.c
@@ -237,6 +237,13 @@ int main(int argc, char **argv)
 	/* process command line arguments */
 	process_command_line(argc, argv);
 
+	if (ngroups > (num_processors - 1)) {
+		printf("Warning: Administor thread will run on one CPU Core, and test thread Groups should run on the other CPU Cores,\n");
+		printf("\t it will run more than one Group on one Core and force to use SCHED_RR policy because\n");
+		printf("\t (groups > num_of_processors -1), or please change number of groups to be lower than processor numbers %ld \n", num_processors);
+		policy = SCHED_RR;
+	}
+
 	/* set default sched attributes */
 	setup_sched_config(policy);
 
@@ -285,9 +292,17 @@ int main(int argc, char **argv)
 			break;
 	for (i = 0; i < ngroups; i++) {
 		groups[i].id = i;
-		groups[i].cpu = core++;
-		if (core >= num_processors)
-			core = 0;
+		if (num_processors == 1 || uniprocessor) {
+			groups[i].cpu = 0;
+		} else {
+			groups[i].cpu = core;
+			/* Find next non-admin Core */
+			do {
+				core++;
+				if (core >= num_processors)
+					core = 0;
+			} while (CPU_ISSET(core, &admin_cpu_mask));
+		}
 		if (create_group(&groups[i]) != SUCCESS)
 			return FAILURE;
 	}
@@ -1143,7 +1158,7 @@ int create_group(struct group_parameters *group)
 	CPU_ZERO(&mask);
 	CPU_SET(group->cpu, &mask);
 
-	pi_debug("group %d bound to cpu %ld\n", group->id, group->cpu);
+	printf("group %d bound to cpu %ld\n", group->id, group->cpu);
 
 	/* start the low priority thread */
 	pi_debug("creating low priority thread\n");
-- 
2.17.1


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-29  3:00 [PATCH v2] rt-tests: pi_stress: fix testing threads' smp affinity Jiafei Pan

Linux-rt-users Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-rt-users/0 linux-rt-users/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-rt-users linux-rt-users/ https://lore.kernel.org/linux-rt-users \
		linux-rt-users@vger.kernel.org
	public-inbox-index linux-rt-users

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-rt-users


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git