From ac0c681fb76f498719acd21f6c8910d126a72dd0 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 16 May 2008 02:37:21 +0000 Subject: [PATCH] [SIGAR-102] check kernel version rather than /proc/diskstats to detect nptl --- src/os/linux/linux_sigar.c | 19 +++++++++++++++---- src/os/linux/sigar_os.h | 2 ++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/os/linux/linux_sigar.c b/src/os/linux/linux_sigar.c index 24efe243..e8db44b0 100644 --- a/src/os/linux/linux_sigar.c +++ b/src/os/linux/linux_sigar.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "sigar.h" #include "sigar_private.h" @@ -45,9 +46,6 @@ #define PROC_PARTITIONS PROC_FS_ROOT "partitions" #define PROC_DISKSTATS PROC_FS_ROOT "diskstats" -/* Native POSIX Thread Library 2.6+ kernel */ -#define SIGAR_HAS_NPTL (sigar->iostat == IOSTAT_DISKSTATS) - /* * /proc/self/stat fields: * 1 - pid @@ -157,7 +155,9 @@ static int sigar_boot_time_get(sigar_t *sigar) int sigar_os_open(sigar_t **sigar) { int i, status; + int kernel_rev, has_nptl; struct stat sb; + struct utsname name; *sigar = malloc(sizeof(**sigar)); @@ -199,6 +199,17 @@ int sigar_os_open(sigar_t **sigar) /* hook for using mirrored /proc/net/tcp file */ (*sigar)->proc_net = getenv("SIGAR_PROC_NET"); + uname(&name); + /* 2.X.y.z -> just need X (unless there is ever a kernel version 3!) */ + kernel_rev = atoi(&name.release[2]); + if (kernel_rev >= 6) { + has_nptl = 1; + } + else { + has_nptl = getenv("SIGAR_HAS_NPTL") ? 1 : 0; + } + (*sigar)->has_nptl = has_nptl; + return SIGAR_OK; } @@ -585,7 +596,7 @@ int sigar_os_proc_list_get(sigar_t *sigar, { DIR *dirp = opendir(PROCP_FS_ROOT); struct dirent *ent, dbuf; - register const int threadbadhack = !SIGAR_HAS_NPTL; + register const int threadbadhack = !sigar->has_nptl; if (!dirp) { return errno; diff --git a/src/os/linux/sigar_os.h b/src/os/linux/sigar_os.h index 79f6ed60..f8c65e84 100644 --- a/src/os/linux/sigar_os.h +++ b/src/os/linux/sigar_os.h @@ -67,6 +67,8 @@ struct sigar_t { int lcpu; linux_iostat_e iostat; char *proc_net; + /* Native POSIX Thread Library 2.6+ kernel */ + int has_nptl; }; #define HAVE_STRERROR_R