MCPcopy Create free account
hub / github.com/coreboot/coreboot / arch_tick_frequency

Function arch_tick_frequency

util/cbmem/cbmem.c:43–77  ·  view source on GitHub ↗

* read CPU frequency from a sysfs file, return an frequency in Megahertz as * an int or exit on any error. */

Source from the content-addressed store, hash-verified

41 * an int or exit on any error.
42 */
43static unsigned long arch_tick_frequency(void)
44{
45 FILE *cpuf;
46 char freqs[100];
47 int size;
48 char *endp;
49 uint64_t rv;
50
51 const char* freq_file =
52 "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq";
53
54 cpuf = fopen(freq_file, "r");
55 if (!cpuf) {
56 fprintf(stderr, "Could not open %s: %s\n",
57 freq_file, strerror(errno));
58 exit(1);
59 }
60
61 memset(freqs, 0, sizeof(freqs));
62 size = fread(freqs, 1, sizeof(freqs), cpuf);
63 if (!size || (size == sizeof(freqs))) {
64 fprintf(stderr, "Wrong number of bytes(%d) read from %s\n",
65 size, freq_file);
66 exit(1);
67 }
68 fclose(cpuf);
69 rv = strtoull(freqs, &endp, 10);
70
71 if (*endp == '\0' || *endp == '\n')
72 /* cpuinfo_max_freq is in kHz. Convert it to MHz. */
73 return rv / 1000;
74 fprintf(stderr, "Wrong formatted value ^%s^ read from %s\n",
75 freqs, freq_file);
76 exit(1);
77}
78#elif defined(__OpenBSD__) && (defined(__i386__) || defined(__x86_64__))
79static unsigned long arch_tick_frequency(void)
80{

Callers 1

timestamp_set_tick_freqFunction · 0.85

Calls 8

fopenFunction · 0.85
fprintfFunction · 0.85
strerrorFunction · 0.85
exitFunction · 0.85
freadFunction · 0.85
fcloseFunction · 0.85
memsetFunction · 0.50
strtoullFunction · 0.50

Tested by

no test coverage detected