-
Notifications
You must be signed in to change notification settings - Fork 40
/
pmqos.c
47 lines (39 loc) · 898 Bytes
/
pmqos.c
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
47
/*
* Disable power management: similar to ``processor.max_cstate=1 idle=poll``
* in kernel arguments, check https://access.redhat.com/articles/65410
*/
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
static int pm_qos_fd = -1;
void start_low_latency(void)
{
int target = 0;
if (pm_qos_fd >= 0)
return;
pm_qos_fd = open("/dev/cpu_dma_latency", O_RDWR);
if (pm_qos_fd < 0) {
fprintf(stderr, "Failed to open PM QOS file: %s\n", strerror(errno));
exit(errno);
}
write(pm_qos_fd, &target, sizeof(target));
}
void stop_low_latency(void)
{
if (pm_qos_fd >= 0) {
close(pm_qos_fd);
}
}
int main(int argc, char **argv)
{
start_low_latency();
pause();
stop_low_latency();
return 0;
}