get cpu clock
authorLaurent MAZET <laurent.mazet@thalesgroup.com>
Thu, 16 Oct 2025 17:31:48 +0000 (19:31 +0200)
committerLaurent MAZET <laurent.mazet@thalesgroup.com>
Thu, 16 Oct 2025 17:31:48 +0000 (19:31 +0200)
getinfo.sh
load.c

index 6886ac82aadb0bd7499601d7505a685e8f7b847a..520c156880ec7f6c1e774d8bf47dd917f47bb6b3 100755 (executable)
@@ -4,7 +4,7 @@ echo OS: $(uname -a 2>/dev/null || cat /proc/version)
 echo "Model: $(cat /proc/cpuinfo | awk -F: '/[mM]odel/ {print $2; exit}')"
 cat /proc/cpuinfo | awk '/Features/ { sub(/\t/, ""); print; exit }'
 echo Nb cores: $(grep -c processor /proc/cpuinfo)
-echo Core frequency: unknown
+./load -c
 cat /proc/meminfo | awk '/MemTotal/ { printf "Memory: %dGB\n", ($2+2^20-1)/2^20 }'
 echo Mem frequency: unknown
 
diff --git a/load.c b/load.c
index 6a10751598d012dca3072b8f605ff697232ae992..b1062f1f269d000c62d9adedd4e0706a6251a4b7 100644 (file)
--- a/load.c
+++ b/load.c
@@ -2,6 +2,7 @@
 /* cflags: */
 /* linker: mtime.o -lpthread */
 
+#define _GNU_SOURCE
 #include <assert.h>
 //#include <math.h>
 #include <pthread.h>
@@ -297,6 +298,13 @@ int main (int argc, char *argv[])
     /* main process */
 
     if (mode)  {
+        cpu_set_t cpu_mask;
+        CPU_ZERO (&cpu_mask);
+        CPU_SET (0, &cpu_mask);
+        if (pthread_setaffinity_np (pthread_self (), sizeof (cpu_set_t), &cpu_mask) != 0) {
+            fprintf (stderr, "error: pthread_setaffinity_np\n");
+            return 1;
+        }
         while (mode--) {
             printf ("\r");
             printf ("Tics clock: %.0fMHz", estimate_tics_clock () / 1e6);