Linux Container Development
 help / color / mirror / Atom feed
* [PATCH 1/4] cr_tests: futex: pi: Adjust RT priority range
@ 2010-04-13 22:25 Matt Helsley
       [not found] ` <2925834e94ea965d668717d0c993b6bc02697799.1271197507.git.matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Matt Helsley @ 2010-04-13 22:25 UTC (permalink / raw)
  To: Serge E. Hallyn; +Cc: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA

Merely checking the priority values does not work on some systems. For example,
my Fedora 12 system shows default realtime priority limits of 0 (soft) 0 (hard)
even for root.

Instead, read the limits and attempt to set them such that they will work
for the test. If we fail to set them then fail the test as well.

Signed-off-by: Matt Helsley <matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
---
 futex/pi.c |   91 ++++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 62 insertions(+), 29 deletions(-)

diff --git a/futex/pi.c b/futex/pi.c
index 36a357c..41f539b 100644
--- a/futex/pi.c
+++ b/futex/pi.c
@@ -552,6 +552,67 @@ out:
 	return retval;
 }
 
+void set_rtprio_range(void)
+{
+	struct rlimit lim;
+	int num_tries;
+
+	/*
+	 * These are the maximums allowed by the scheduler --
+	 * not the maximum prios we are permitted to set. Hence
+	 * the rlimit bits below.
+	 */
+	prio_min = sched_get_priority_min(sched_policy);
+	prio_max = sched_get_priority_max(sched_policy);
+	if (prio_min < 0  || prio_max < 0) {
+		log_error("sched_get_priority_min|max");
+		fclose(logfp);
+		exit(1);
+	}
+
+	if ((prio_max - prio_min) < 1) {
+		log("FAIL", "Too fewer priority levels for this test.\n");
+		fclose(logfp);
+		exit(13);
+	}
+	if (N > (prio_max - prio_min)) {
+		N = prio_max - prio_min;
+		log("WARN", "Fewer priority levels than specified processes. Using %d processes (the number of priority levels)\n", N);
+	}
+
+	for (num_tries = 2; num_tries; num_tries--) {
+
+		if (getrlimit(RLIMIT_RTPRIO, &lim) == -1) {
+			log_error("getrlimit");
+			fclose(logfp);
+			exit(12);
+		}
+		if (lim.rlim_cur == RLIM_INFINITY)
+			break;
+		if (lim.rlim_cur >= N)
+			break;
+
+		/* Else we must try to adjust the allowable range */
+		if (lim.rlim_cur < N)
+			lim.rlim_cur = N;
+		if (lim.rlim_cur > lim.rlim_max)
+			lim.rlim_max = lim.rlim_cur;
+		if (setrlimit(RLIMIT_RTPRIO, &lim) == -1) {
+			log_error("setrlimit");
+			fclose(logfp);
+			exit(10);
+		}
+	}
+
+	if (getrlimit(RLIMIT_RTPRIO, &lim) == -1) {
+		log_error("getrlimit");
+		fclose(logfp);
+		exit(13);
+	}
+	log("INFO", "RLIMIT_RTPRIO: soft (cur): %ld hard (max): %ld\n",
+		lim.rlim_cur, lim.rlim_max);
+}
+
 int main(int argc, char **argv)
 {
 	struct sched_param proc_sched_param;
@@ -574,28 +635,7 @@ int main(int argc, char **argv)
 	dup2(fileno(logfp), 1);
 	dup2(fileno(logfp), 2);
 
-	prio_min = sched_get_priority_min(sched_policy);
-	prio_max = sched_get_priority_max(sched_policy);
-	if (prio_min < 0  || prio_max < 0) {
-		log_error("sched_get_priority_min|max");
-		fclose(logfp);
-		exit(1);
-	}
-
-	/* rlimit also restricts prio_max */
-	{
-		struct rlimit lim;
-		getrlimit(RLIMIT_RTPRIO, &lim);
-		log("INFO", "RLIMIT_RTPRIO: soft (cur): %ld hard (max): %ld\n",
-			lim.rlim_cur, lim.rlim_max);
-		if (lim.rlim_cur == 0) {
-			log("FAIL", "process is restricted from manipulating priorities.\n");
-			fclose(logfp);
-			exit(2);
-		}
-		if (lim.rlim_cur > prio_max)
-			prio_max = lim.rlim_cur;
-	}
+	set_rtprio_range();
 
 	proc_sched_param.sched_priority = prio_min;
 	if (sched_setscheduler(getpid(), sched_policy,
@@ -604,13 +644,6 @@ int main(int argc, char **argv)
 		fclose(logfp);
 		exit(3);
 	}
-	if (N > (prio_max - prio_min))
-		N = prio_max - prio_min;
-	if (N < 1) {
-		log("FAIL", "Not enough priority levels to run test.\n");
-		fclose(logfp);
-		exit(4);
-	}
 
 	log("INFO", "running test with %d children\n", N);
 
-- 
1.6.3.3

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2010-04-14 14:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-13 22:25 [PATCH 1/4] cr_tests: futex: pi: Adjust RT priority range Matt Helsley
     [not found] ` <2925834e94ea965d668717d0c993b6bc02697799.1271197507.git.matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-04-13 22:25   ` [PATCH 2/4] cr_tests: futex: pi: Factor out release_pi_futex() Matt Helsley
2010-04-13 22:25   ` [PATCH 3/4] cr_tests: futex: pu: Fix potential livelock Matt Helsley
     [not found]     ` <4b62b2004556809368f788e9baaf39c529dc3d80.1271197507.git.matthltc-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-04-14 14:58       ` Serge E. Hallyn
2010-04-13 22:25   ` [PATCH 4/4] cr_tests: futex: pi: Set the FUTEX_WAITERS bit Matt Helsley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox