-
Notifications
You must be signed in to change notification settings - Fork 1
/
timerlat_load.cc
64 lines (56 loc) · 1.59 KB
/
timerlat_load.cc
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Reimplement linux/tools/tracing/rtla/sample/timerlat_load.py as C++.
#include "timerlat_load.hh"
#include <sched.h>
#include <unistd.h>
#include <cstdint>
#include <cstring>
#include <fstream>
#include <iostream>
using namespace std;
using namespace timerlat_load;
void usage(const std::string &prog) {
cerr << prog << " PRIORITY (<= " << MAX_PRIO << ") CPU (<" << CORES << ")"
<< endl;
}
int main(int argc, char **argv) {
if (geteuid()) {
cerr << argv[0] << " is only runnable as root." << endl;
exit(EXIT_FAILURE);
}
if ((3 > argc) || (4 < argc)) {
usage(argv[0]);
exit(EXIT_FAILURE);
}
const int32_t prio = strtol(argv[1], nullptr, 10);
if (errno || (0 >= prio) || (MAX_PRIO < prio)) {
cerr << "Illegal priority " << argv[1] << endl;
usage(argv[0]);
exit(EXIT_FAILURE);
}
const uint16_t cpu = strtol(argv[2], nullptr, 10);
if (errno || (CORES <= cpu)) {
cerr << "Illegal cpu " << argv[2] << endl;
usage(argv[0]);
exit(EXIT_FAILURE);
}
const pid_t pid = getpid();
if ((set_affinity(pid, cpu)) || set_prio(pid, prio)) {
exit(EXIT_FAILURE);
}
const string tl_path = string{TRACETLD} + to_string(cpu) + "/timerlat_fd"s;
ifstream tlfs(tl_path, ifstream::in);
if (!tlfs.good()) {
cerr << "Unable to open file " << tl_path << endl;
exit(EXIT_FAILURE);
}
const string dev_path = DEVPATH;
ifstream devfs(dev_path, ifstream::in);
if (!devfs.good()) {
cerr << "Unable to open file " << dev_path << endl;
exit(EXIT_FAILURE);
}
read_buffs(tlfs, devfs);
tlfs.close();
devfs.close();
exit(EXIT_SUCCESS);
}