[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] core-count: A new program to count the number of cpu cores
From: |
Bruno Haible |
Subject: |
Re: [PATCH] core-count: A new program to count the number of cpu cores |
Date: |
Mon, 2 Nov 2009 02:11:59 +0100 |
User-agent: |
KMail/1.9.9 |
Pádraig Brady wrote:
> > + while (*envvalue != '\0' && c_isspace (*envvalue))
> > + envvalue++;
>
> A pedantic comment. Could one instead assume strtoul() skips leading
> whitespace?
But then strtoul would also skip a sign, and a value of, say, "+4" is not
allowed by the OpenMP spec.
> > + #if HAVE_PTHREAD_AFFINITY_NP && defined __GLIBC__ && 0
>
> > + #elif HAVE_PTHREAD_AFFINITY_NP && defined __NetBSD__ && 0
>
> If you put the "0" first then vim at least will highlight
> the section as a comment.
Same for kate. But the '&& 0' is the last modification that one does to
the code, to enable or disable it, that's why it is at the end. The same
style is also used in lib/fts.c and lib/wait-process.c.
> > *** m4/nproc.m4.orig 2009-11-01 14:55:37.000000000 +0100
> > --- m4/nproc.m4 2009-11-01 14:31:13.000000000 +0100
> > ! AC_CHECK_FUNCS([sched_getaffinity sched_getaffinity_np \
> > ! pstat_getdynamic sysmp sysctl])
> > ])
>
> Will this result in a compile failure on glibc-2.3.[23]
> where sched_getaffinity() has a different prototype?
> If so it might be nice to not define HAVE_SCHED_GETAFFINITY
> in that case
Good point. I'll use HAVE_SCHED_GETAFFINITY_LIKE_GLIBC instead of
HAVE_SCHED_GETAFFINITY, defined as follows:
--- m4/nproc.m4.orig 2009-11-02 02:09:26.000000000 +0100
+++ m4/nproc.m4 2009-11-02 02:07:29.000000000 +0100
@@ -1,4 +1,4 @@
-# nproc.m4 serial 3
+# nproc.m4 serial 4
dnl Copyright (C) 2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -12,6 +12,9 @@
# Prerequisites of lib/nproc.c.
AC_DEFUN([gl_PREREQ_NPROC],
[
+ dnl Persuade glibc <sched.h> to declare CPU_SETSIZE, CPU_ISSET etc.
+ AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
AC_CHECK_HEADERS([sys/pstat.h sys/sysmp.h sys/param.h],,,
[AC_INCLUDES_DEFAULT])
dnl <sys/sysctl.h> requires <sys/param.h> on OpenBSD 4.0.
@@ -21,5 +24,30 @@
# include <sys/param.h>
#endif
])
- AC_CHECK_FUNCS([pstat_getdynamic sysmp sysctl])
+
+ AC_CHECK_FUNCS([sched_getaffinity sched_getaffinity_np \
+ pstat_getdynamic sysmp sysctl])
+
+ dnl Test whether sched_getaffinity has the expected declaration.
+ dnl glibc 2.3.[0-2]:
+ dnl int sched_getaffinity (pid_t, unsigned int, unsigned long int *);
+ dnl glibc 2.3.3:
+ dnl int sched_getaffinity (pid_t, cpu_set_t *);
+ dnl glibc >= 2.3.4:
+ dnl int sched_getaffinity (pid_t, size_t, cpu_set_t *);
+ if test $ac_cv_func_sched_getaffinity = yes; then
+ AC_CACHE_CHECK([for glibc compatible sched_getaffinity],
+ [gl_cv_func_sched_getaffinity3],
+ [AC_COMPILE_IFELSE(
+ [AC_LANG_PROGRAM(
+ [[#include <sched.h>]],
+ [[sched_getaffinity (0, 0, (cpu_set_t *) 0);]])],
+ [gl_cv_func_sched_getaffinity3=yes],
+ [gl_cv_func_sched_getaffinity3=no])
+ ])
+ if test $gl_cv_func_sched_getaffinity3 = yes; then
+ AC_DEFINE([HAVE_SCHED_GETAFFINITY_LIKE_GLIBC], [1],
+ [Define to 1 if sched_getaffinity has a glibc compatible declaration.])
+ fi
+ fi
])
- Re: [PATCH] core-count: A new program to count the number of cpu cores, Pádraig Brady, 2009/11/01
- Re: [PATCH] core-count: A new program to count the number of cpu cores, Bruno Haible, 2009/11/01
- Re: [PATCH] core-count: A new program to count the number of cpu cores, Pádraig Brady, 2009/11/01
- Re: [PATCH] core-count: A new program to count the number of cpu cores,
Bruno Haible <=
- Re: [PATCH] core-count: A new program to count the number of cpu cores, Bruno Haible, 2009/11/04
- Re: [PATCH] core-count: A new program to count the number of cpu cores, Giuseppe Scrivano, 2009/11/04
- Re: [PATCH] core-count: A new program to count the number of cpu cores, Paolo Bonzini, 2009/11/04
- Re: [PATCH] core-count: A new program to count the number of cpu cores, Pádraig Brady, 2009/11/04
- Re: [PATCH] core-count: A new program to count the number of cpu cores, Giuseppe Scrivano, 2009/11/04
- Re: [PATCH] core-count: A new program to count the number of cpu cores, Pádraig Brady, 2009/11/05
- Re: [PATCH] core-count: A new program to count the number of cpu cores, Giuseppe Scrivano, 2009/11/05
- Re: [PATCH] core-count: A new program to count the number of cpu cores, Pádraig Brady, 2009/11/05
- Re: [PATCH] core-count: A new program to count the number of cpu cores, Erik Auerswald, 2009/11/05
- Re: [PATCH] core-count: A new program to count the number of cpu cores, Giuseppe Scrivano, 2009/11/05