Re: ionice and ioprio_[gs]et

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

 



Hello Mike,

I have reviewed your patch and noticed a bug:
In the most common path, when SYS_something is set, the variable
`syscall' is not set and thus the subsequent AM_CONDITIONAL is set
incorrectly.  (Symptom: on corrent computer, pivot_root is not build.)

Other then that, the patch should work OK.

But I proceed with some pedantic comments:

I suggest to add AC_REQUIRE([AC_CANONICAL_HOST]) to the beginning of
the macro, because that is what provides $host_cpu.  But that macro
is already there, IIRC it is brought in AM_INIT_AUTOMAKE, so this
does not cause problems in practice.

On Thu, Sep 06, 2007 at 08:09:06PM -0400, Mike Frysinger wrote:
> On Thursday 06 September 2007, Mike Frysinger wrote:
> one thing this is missing is cache handling ... but i dont know if you really 
> care that much ...

The caching is important for ``inner'' macros, which may get called
several times; then the subsequent calls do not repeat the expensive
compiler calls.  I agree it does not matter here...

> so it shouldnt be too hard to integrate AC_CACHE_CHECK ...

... but OTOH it's really easy, so I added it.  ;-)

There is one thing you have to remember: the checking code may be
skipped if the result is known from a cache.  So the checking code
may not call AC_DEFINE, AC_CONDITIONAL, or anything which sets the
values for output.  And, of course, none of the shell variables from
the check can be used outside (in this case `syscall').
All you have after AC_CACHE_CHECK is the ``cache variable'',
util_cv_syscall_$1 in this case.

But if you avoid this trap, AC_CACHE_CHECK actually helps: it calls
AC_MSG_{CHECKING,RESULT} for you.

Attached please find my variation on Mike's patch.
Karel: Is there a way to declare two co-authors of a patch in git?

Have a nice day,
	Stepan

From: Mike Frysinger <vapier@xxxxxxxxxx>, Stepan Kasal <skasal@xxxxxxxxxx>
Date: Fri, 7 Sep 2007 16:55:36 +0200
Subject: [PATCH] Unify method for checking system calls and fallback handling.

Signed-off-by: Mike Frysinger <vapier@xxxxxxxxxx>
Signed-off-by: Stepan Kasal <skasal@xxxxxxxxxx>
---
 configure.ac           |   83 +++++++++++++++++++++++++++++++++++++++--------
 schedutils/Makefile.am |   11 +++++-
 schedutils/ionice.c    |   32 ------------------
 3 files changed, 78 insertions(+), 48 deletions(-)

diff --git a/configure.ac b/configure.ac
index e7cfca3..b23395f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -187,24 +187,79 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 ])
 
 
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+dnl UTIL_CHECK_SYSCALL(SYSCALL, FALLBACK, ...)
+dnl Only specify FALLBACK if the SYSCALL
+dnl you're checking for is a "newish" one
+dnl -------------------------------------
+AC_DEFUN([UTIL_CHECK_SYSCALL], [
+  dnl This macro uses host_cpu.
+  AC_REQUIRE([AC_CANONICAL_HOST])
+  AC_CACHE_CHECK([for syscall $1],
+    [util_cv_syscall_$1],
+    [_UTIL_SYSCALL_CHECK_DECL([SYS_$1],
+      [syscall=SYS_$1],
+      [dnl Our libc failed use, so see if we can get the kernel
+      dnl headers to play ball ...
+      _UTIL_SYSCALL_CHECK_DECL([_NR_$1],
+	[syscall=_NR_$1],
+	[
+	  syscall=no
+	  case $host_cpu in
+	    _UTIL_CHECK_SYSCALL_FALLBACK(m4_shift($@))
+	  esac
+        ])
+      ])
+    util_cv_syscall_$1=$syscall
+    ])
+  AM_CONDITIONAL([HAVE_]m4_toupper($1), [test $util_cv_syscall_$1 != no])
+  case $util_cv_syscall_$1 in #(
+  no) AC_MSG_WARN([Unable to detect syscall $1.]) ;;
+  SYS_*) ;;
+  *) AC_DEFINE_UNQUOTED([SYS_$1], [$util_cv_syscall_$1],
+	[Fallback syscall number for $1]) ;;
+  esac
+])
+
+dnl _UTIL_SYSCALL_CHECK_DECL(SYMBOL, ACTION-IF-FOUND, ACTION-IF-NOT-FOUND)
+dnl Check if SYMBOL is declared, using the headers needed for syscall checks.
+dnl -------------------------------------
+m4_define([_UTIL_SYSCALL_CHECK_DECL],
+[AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
 #include <sys/syscall.h>
 #include <unistd.h>
-]], [[
-int test = SYS_pivot_root;
-]])],
-[AM_CONDITIONAL(HAVE_PIVOT_ROOT, true)],
-[AM_CONDITIONAL(HAVE_PIVOT_ROOT, false)])
+]], [[int test = $1;]])],
+[$2], [$3])
+])
 
+dnl _UTIL_CHECK_SYSCALL_FALLBACK(PATTERN, VALUE, ...)
+dnl Helper macro to create the body for the above `case'.
+dnl -------------------------------------
+m4_define([_UTIL_CHECK_SYSCALL_FALLBACK],
+[m4_ifval([$1],
+  [#(
+  $1) syscall="$2" ;;dnl
+  _UTIL_CHECK_SYSCALL_FALLBACK(m4_shiftn(2, $@))])dnl
+])
 
-AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
-#include <sys/syscall.h>
-#include <unistd.h>
-]], [[
-int test = SYS_sched_getaffinity;
-]])],
-[AM_CONDITIONAL(HAVE_SCHED_GETAFFINITY, true)],
-[AM_CONDITIONAL(HAVE_SCHED_GETAFFINITY, false)])
+
+UTIL_CHECK_SYSCALL([pivot_root])
+UTIL_CHECK_SYSCALL([sched_getaffinity])
+UTIL_CHECK_SYSCALL([ioprio_set],
+  [alpha],    [442],
+  [i*86],     [289],
+  [ia64*],    [1274],
+  [powerpc*], [273],
+  [s390*],    [282],
+  [sparc*],   [196],
+  [x86_64*],  [251])
+UTIL_CHECK_SYSCALL([ioprio_get],
+  [alpha],    [443],
+  [i*86],     [290],
+  [ia64*],    [1275],
+  [powerpc*], [274],
+  [s390*],    [283],
+  [sparc*],   [218],
+  [x86_64*],  [252])
 
 
 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
diff --git a/schedutils/Makefile.am b/schedutils/Makefile.am
index e93d31b..81a734e 100644
--- a/schedutils/Makefile.am
+++ b/schedutils/Makefile.am
@@ -2,8 +2,15 @@ include $(top_srcdir)/config/include-Makefile.am
 
 if BUILD_SCHEDUTILS
 
-usrbinexec_PROGRAMS = chrt ionice
-man_MANS = chrt.1 ionice.1
+usrbinexec_PROGRAMS = chrt
+man_MANS = chrt.1
+
+if HAVE_IOPRIO_GET
+if HAVE_IOPRIO_SET
+usrbinexec_PROGRAMS += ionice
+man_MANS += ionice.1
+endif
+endif
 
 if HAVE_SCHED_GETAFFINITY
 usrbinexec_PROGRAMS += taskset
diff --git a/schedutils/ionice.c b/schedutils/ionice.c
index 9eb1387..679014a 100644
--- a/schedutils/ionice.c
+++ b/schedutils/ionice.c
@@ -15,38 +15,6 @@
 #include <sys/syscall.h>
 #include <asm/unistd.h>
 
-#if !defined(SYS_ioprio_get) || !defined(SYS_ioprio_set)
-
-# if defined(__i386__)
-#  define __NR_ioprio_set		289
-#  define __NR_ioprio_get		290
-# elif defined(__powerpc__) || defined(__powerpc64__)
-#  define __NR_ioprio_set		273
-#  define __NR_ioprio_get		274
-# elif defined(__x86_64__)
-#  define __NR_ioprio_set		251
-#  define __NR_ioprio_get		252
-# elif defined(__ia64__)
-#  define __NR_ioprio_set		1274
-#  define __NR_ioprio_get		1275
-# elif defined(__alpha__)
-#  define __NR_ioprio_set		442
-#  define __NR_ioprio_get		443
-# elif defined(__s390x__) || defined(__s390__)
-#  define __NR_ioprio_set		282
-#  define __NR_ioprio_get		283
-# elif defined(__sparc__) || defined(__sparc64__)
-#  define __NR_ioprio_set		196
-#  define __NR_ioprio_get		218
-# else
-#  error "Unsupported arch"
-# endif
-
-# define SYS_ioprio_get		__NR_ioprio_get
-# define SYS_ioprio_set		__NR_ioprio_set
-
-#endif /* !SYS_ioprio_get */
-
 static inline int ioprio_set(int which, int who, int ioprio)
 {
 	return syscall(SYS_ioprio_set, which, who, ioprio);
-- 
1.5.0.6

-
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