Xinqi Bao's Git

cpu: OS split
[slstatus.git] / components / OpenBSD / cpu.c
1 /* See LICENSE file for copyright and license details. */
2 #include <errno.h>
3 #include <stdio.h>
4 #include <string.h>
5 #include <sys/sysctl.h>
6
7 #include "../../util.h"
8
9 const char *
10 cpu_freq(void)
11 {
12 int freq, mib[2];
13 size_t size;
14
15 mib[0] = CTL_HW;
16 mib[1] = HW_CPUSPEED;
17
18 size = sizeof(freq);
19
20 if (sysctl(mib, 2, &freq, &size, NULL, 0) == -1) {
21 fprintf(stderr, "sysctl 'HW_CPUSPEED': %s\n", strerror(errno));
22 return NULL;
23 }
24
25 return bprintf("%d", freq);
26 }