From 4e2d1790529a416ea6b28d6f619b33d44625c5fc Mon Sep 17 00:00:00 2001 From: Julian Kunkel Date: Mon, 3 Aug 2020 12:30:21 +0100 Subject: [PATCH] Detection of system features for number of sockets #245 (#246) * Configure checks for architecture-specific functions to detect nr of sockets. #245 --- configure.ac | 24 ++++++++++++++++++++++++ src/ior.c | 3 +-- src/utilities.c | 24 ++++++++++++++++++------ 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/configure.ac b/configure.ac index dc05ee7..1253b51 100755 --- a/configure.ac +++ b/configure.ac @@ -400,6 +400,30 @@ Consider --with-aws4c=, CPPFLAGS, LDFLAGS, etc]) LDFLAGS=$ORIG_LDFLAGS ]) +# Check for existence of the function to detect the CPU socket ID (for multi-socket systems) +AC_COMPILE_IFELSE( + [AC_LANG_SOURCE([[ + int main(){ + unsigned long a,d,c; + __asm__ volatile("rdtscp" : "=a" (a), "=d" (d), "=c" (c)); + return 0; + } + ]])], + AC_DEFINE([HAVE_RDTSCP_ASM], [], [Has ASM to detect CPU socket ID])) + +AC_COMPILE_IFELSE( + [AC_LANG_SOURCE([[ + #define _GNU_SOURCE + #include + #include + unsigned long GetProcessorAndCore(int *chip, int *core){ + return syscall(SYS_getcpu, core, chip, NULL); + } + int main(){ + } + ]])], + AC_DEFINE([HAVE_GETCPU_SYSCALL], [], [Has syscall to detect CPU socket ID])) + # Enable building "IOR", in all capitals AC_ARG_ENABLE([caps], diff --git a/src/ior.c b/src/ior.c index c220ae0..196f6ec 100755 --- a/src/ior.c +++ b/src/ior.c @@ -792,8 +792,7 @@ void GetTestFileName(char *testFileName, IOR_param_t * test) strcpy(initialTestFileName, test->testFileName); if(test->dualMount){ GetProcessorAndCore(&socket, &core); - sprintf(tmpString, "%s%d/%s",initialTestFileName, - socket, "data"); + sprintf(tmpString, "%s%d/%s",initialTestFileName, socket, "data"); strcpy(initialTestFileName, tmpString); } fileNames = ParseFileName(initialTestFileName, &count); diff --git a/src/utilities.c b/src/utilities.c index 5b65e55..36db9c9 100755 --- a/src/utilities.c +++ b/src/utilities.c @@ -16,6 +16,12 @@ # include "config.h" #endif +#ifdef HAVE_GETCPU_SYSCALL +# define _GNU_SOURCE +# include +# include +#endif + #ifdef __linux__ # define _GNU_SOURCE /* Needed for O_DIRECT in fcntl */ #endif /* __linux__ */ @@ -869,17 +875,15 @@ char *HumanReadable(IOR_offset_t value, int base) return valueStr; } -#if defined(__aarch64__) -// TODO: This might be general enough to provide the functionality for any system -// regardless of processor type given we aren't worried about thread/process migration. +#if defined(HAVE_GETCPU_SYSCALL) +// Assume we aren't worried about thread/process migration. // Test on Intel systems and see if we can get rid of the architecture specificity // of the code. unsigned long GetProcessorAndCore(int *chip, int *core){ return syscall(SYS_getcpu, core, chip, NULL); } -// TODO: Add in AMD function -#else -// If we're not on an ARM processor assume we're on an intel processor and use the +#elif defined(HAVE_RDTSCP_ASM) +// We're on an intel processor and use the // rdtscp instruction. unsigned long GetProcessorAndCore(int *chip, int *core){ unsigned long a,d,c; @@ -888,4 +892,12 @@ unsigned long GetProcessorAndCore(int *chip, int *core){ *core = c & 0xFFF; return ((unsigned long)a) | (((unsigned long)d) << 32);; } +#else +// TODO: Add in AMD function +unsigned long GetProcessorAndCore(int *chip, int *core){ +#warning GetProcessorAndCore is implemented as a dummy + *chip = 0; + *core = 0; + return 1; +} #endif