Skip to content

Commit

Permalink
fallback method for cpu freq through register access
Browse files Browse the repository at this point in the history
  • Loading branch information
cpt-harlock committed Jan 3, 2025
1 parent 5e94e26 commit a353a49
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions src/tool.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -639,12 +670,8 @@ HIDDEN int read_intel_nom_freq()
free(line);
fclose(fd);
nom_freq *= 1000;
} else {
fprintf(stderr,
"Error: <COUNTDOWN-node:%s-rank:%d> 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);
}
Expand Down

0 comments on commit a353a49

Please sign in to comment.