Re: [PATCH] schedutils: don't assume SCHED_BATCH and SCHED_IDLE exist

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Apr 20, 2009 at 01:13:28AM -0400, Mike Frysinger wrote:
> On Sunday 19 April 2009 10:34:10 Aurelien Jarno wrote:
> > SCHED_FIFO, SCHED_OTHER, SCHED_RR are part of POSIX 1003.1b Process
> > Scheduling, so it is correct to assume they always exists.
> >
> > SCHED_BATCH and SCHED_IDLE are Linux specific, we should not assume
> > they exists.
> 
> looks like you add a whole lot of ifdef's for no real gain.  on non-Linux 
> systems, you end up with options that simply dont work.  not a big deal.  on 
> the flip side, these ifdef's are pretty invasive and split up code in a pretty 
> bad way.

Ok, please find a simpler patch below, we only adds the #ifdef to the
locations where we really need the values of SCHED_BATCH and SCHED_IDLE.

>From df1fda26685167ed26a9e27de36ef572b3fa6776 Mon Sep 17 00:00:00 2001
From: Aurelien Jarno <aurelien@xxxxxxxxxxx>
Date: Tue, 22 Apr 2009 09:07:02 +0200
Subject: [PATCH] schedutils: don't assume SCHED_BATCH and SCHED_IDLE exist

SCHED_FIFO, SCHED_OTHER, SCHED_RR are part of POSIX 1003.1b Process
Scheduling, so it is correct to assume they always exists.

SCHED_BATCH and SCHED_IDLE are Linux specific, we should not assume
they exists.

Signed-off-by: Aurelien Jarno <aurelien@xxxxxxxxxxx>
---
 schedutils/chrt.c |   29 +++++++++++++++++++++++++----
 1 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/schedutils/chrt.c b/schedutils/chrt.c
index dcd0524..7d6bb2d 100644
--- a/schedutils/chrt.c
+++ b/schedutils/chrt.c
@@ -34,7 +34,7 @@
 /* the SCHED_BATCH is supported since Linux 2.6.16
  *  -- temporary workaround for people with old glibc headers
  */
-#ifndef SCHED_BATCH
+#if defined (__linux__) && !defined(SCHED_BATCH)
 # define SCHED_BATCH 3
 #endif
 
@@ -42,7 +42,7 @@
  * commit id 0e6aca43e08a62a48d6770e9a159dbec167bf4c6
  * -- temporary workaround for people with old glibc headers
  */
-#ifndef SCHED_IDLE
+#if defined (__linux__) && !defined(SCHED_IDLE)
 # define SCHED_IDLE 5
 #endif
 
@@ -95,15 +95,19 @@ static void show_rt_info(const char *what, pid_t pid)
 	case SCHED_FIFO:
 		printf("SCHED_FIFO\n");
 		break;
+#ifdef SCHED_IDLE
 	case SCHED_IDLE:
 		printf("SCHED_IDLE\n");
 		break;
+#endif
 	case SCHED_RR:
 		printf("SCHED_RR\n");
 		break;
+#ifdef SCHED_BATCH
 	case SCHED_BATCH:
 		printf("SCHED_BATCH\n");
 		break;
+#endif
 	default:
 		printf(_("unknown\n"));
 	}
@@ -119,8 +123,21 @@ static void show_min_max(void)
 {
 	int i;
 	int policies[] = { SCHED_OTHER, SCHED_FIFO, SCHED_RR,
-			   SCHED_BATCH, SCHED_IDLE };
-	const char *names[] = { "OTHER", "FIFO", "RR", "BATCH", "IDLE" };
+#ifdef SCHED_BATCH
+			   SCHED_BATCH,
+#endif
+#ifdef SCHED_IDLE
+			   SCHED_IDLE,
+#endif
+			 };
+	const char *names[] = { "OTHER", "FIFO", "RR",
+#ifdef SCHED_BATCH
+				"BATCH",
+#endif
+#ifdef SCHED_IDLE
+				"IDLE",
+#endif
+			      };
 
 	for (i = 0; i < ARRAY_SIZE(policies); i++) {
 		int max = sched_get_priority_max(policies[i]);
@@ -164,13 +181,17 @@ int main(int argc, char *argv[])
 
 		switch (i) {
 		case 'b':
+#ifdef SCHED_BATCH
 			policy = SCHED_BATCH;
+#endif
 			break;
 		case 'f':
 			policy = SCHED_FIFO;
 			break;
 		case 'i':
+#ifdef SCHED_IDLE
 			policy = SCHED_IDLE;
+#endif
 			break;
 		case 'm':
 			show_min_max();
-- 
1.6.2.3




-- 
Aurelien Jarno	                        GPG: 1024D/F1BCDB73
aurelien@xxxxxxxxxxx                 http://www.aurel32.net
--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux