From a353a49028133f57fb395aa06143b1274775be52 Mon Sep 17 00:00:00 2001 From: cpt-harlock Date: Fri, 3 Jan 2025 13:14:46 +0100 Subject: [PATCH] fallback method for cpu freq through register access --- src/tool.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/tool.c b/src/tool.c index ae7b307..1eaa972 100644 --- a/src/tool.c +++ b/src/tool.c @@ -612,6 +612,37 @@ HIDDEN void get_rand_postfix(char *postfix, int size) } #ifdef INTEL +HIDDEN void brandString(int *a) +{ + __asm__("mov $0x80000004 , %eax\n\t"); + __asm__("cpuid\n\t"); + __asm__("mov %%eax, %0\n\t":"=r" (a[0])); + __asm__("mov %%ebx, %0\n\t":"=r" (a[1])); + __asm__("mov %%ecx, %0\n\t":"=r" (a[2])); + __asm__("mov %%edx, %0\n\t":"=r" (a[3])); +} + +HIDDEN float getCpuFreq() +{ + int a[10]; + char *token; + float nom_freq = 0.0; + + __asm__("xor %eax , %eax\n\t"); + __asm__("xor %ebx , %ebx\n\t"); + __asm__("xor %ecx , %ecx\n\t"); + __asm__("xor %edx , %edx\n\t"); + + brandString(a); + + token = strtok((char*)&a[0],"@"); + token = strtok(NULL, "@"); + sscanf(token, "%fGHz", &nom_freq); + nom_freq *= 1000; + + return nom_freq; +} + HIDDEN int read_intel_nom_freq() { FILE *fd; @@ -639,12 +670,8 @@ HIDDEN int read_intel_nom_freq() free(line); fclose(fd); nom_freq *= 1000; - } else { - fprintf(stderr, - "Error: Failed to read file: /proc/cpuinfo\n", - cntd->node.hostname, cntd->rank->world_rank); - PMPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE); - } + } else + nom_freq = getCpuFreq(); } return (int)(nom_freq); }