aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/sysinfo/cpuclock/cpuclock_sysctl.c
blob: 9ea049f40db43e5c3b687d4f978e70da334cad38 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <stdlib.h>

#if defined(__FreeBSD__) || defined(__DragonFly__)
# include <sys/sysctl.h>
#endif

#if defined(__OpenBSD__)
# include <sys/param.h>
# include <sys/resource.h>
# include <sys/sysctl.h>
#endif

#if defined(__OpenBSD__)
int
_cpuclock_sysctl_frequency(int new_perf)
{
   int mib[] = {CTL_HW, HW_SETPERF};
   size_t len = sizeof(new_perf);

   if (sysctl(mib, 2, NULL, 0, &new_perf, len) == -1)
     return 1;

   return 0;
}

#elif defined(__FreeBSD__) || defined(__DragonFly__)
int
_cpuclock_sysctl_frequency(int new_perf)
{
   if (sysctlbyname("dev.cpu.0.freq", NULL, NULL, &new_perf, sizeof(new_perf)) == -1)
     return 1;

   return 0;
}
#endif

#if defined(__FreeBSD__) || defined(__DragonFly__) || defined(__OpenBSD__)
int main(int argc, char **argv)
{
   if (argc != 2)
     exit(1 << 0);

   return _cpuclock_sysctl_frequency(atoi(argv[1]));
}
#endif