Permalink
Browse files

Improve portability of ticks per second calculations

Recent Linux versions define the start time from /proc/*/stat
as sysconf(_SC_CLK_TCK) instead of jiffies.

The Hurd docs also suggest using sysconf(_SC_CLK_TCK) instead of HZ.

See-also: https://www.gnu.org/software/hurd/hurd/porting/guidelines.html
  • Loading branch information...
pabs3 committed Mar 27, 2018
1 parent 2725189 commit 43e243ee0a7e5d552399ed80123891cecee7cd53
Showing with 17 additions and 4 deletions.
  1. +1 −0 configure.ac
  2. +16 −4 src/proc_plugin.c
@@ -89,6 +89,7 @@ AC_CHECK_FUNCS([regcomp])
AC_CHECK_FUNCS([strchr])
AC_CHECK_FUNCS([strncasecmp])
AC_CHECK_FUNCS([strrchr])
AC_CHECK_FUNCS([sysconf])
AC_MSG_CHECKING([whether select() modifies the time value])
AC_RUN_IFELSE([AC_LANG_SOURCE([[#include <sys/types.h>
@@ -10,12 +10,24 @@
#include "pluglib.h"
#include "whowatch.h"
#if defined(HAVE_ASM_PARAM_H)
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#if !defined(HZ) && defined(HAVE_SYSCONF) && defined(_SC_CLK_TCK)
#define HZ sysconf(_SC_CLK_TCK)
#endif
#if !defined(HZ) && defined(HAVE_ASM_PARAM_H)
#include <asm/param.h>
#elif defined(__FreeBSD_kernel__) || defined(__FreeBSD__)
#endif
#if !defined(HZ) && (defined(__FreeBSD_kernel__) || defined(__FreeBSD__))
#define HZ 100
#else
#error HZ not implemented on this platform
#endif
#ifndef HZ
#error Could not determine ticks per second
#endif
#if defined(HAVE_LIBKVM) && defined(HAVE_STDINT_H) && defined(HAVE_KVM_H)

0 comments on commit 43e243e

Please sign in to comment.