]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/plr/server/src/logging.cc
update
[l4.git] / l4 / pkg / plr / server / src / logging.cc
1 #include "log"
2 #include <l4/plr/measurements.h>
3 #include <pthread-l4.h>
4 #include <l4/util/rdtsc.h>
5 #include <l4/sys/debugger.h>
6 #include <l4/sys/kdebug.h>
7 #include <l4/sys/scheduler>
8 #include <l4/re/env>
9 #include <l4/re/error_helper>
10
11 using L4Re::chksys;
12
13 struct timerArgs
14 {
15         unsigned cpu;
16         l4_addr_t timer;
17 };
18
19
20 static timerArgs global_arg;
21
22 void *timerThread(void *argp)
23 {
24         char const *name = "Romain::timer";
25         L4::Cap<L4::Thread> self(pthread_getl4cap(pthread_self()));
26         l4_debugger_set_object_name(self.cap(), name);
27
28         l4_sched_param_t sp = l4_sched_param(2);
29         sp.affinity = l4_sched_cpu_set(global_arg.cpu, 0);
30         chksys(L4Re::Env::env()->scheduler()->run_thread(self, sp));
31
32         INFO() << "Timer thread. CPU " << global_arg.cpu << ". Timestamp @ 0x" << std::hex << global_arg.timer;
33
34         while (1) {
35                 *((volatile l4_uint64_t*)global_arg.timer) = l4_rdtsc();
36         }
37
38         enter_kdebug("timer returned");
39
40         return 0;
41 }
42
43 void
44 Measurements::EventBuf::launchTimerThread(l4_addr_t timer, unsigned CPU)
45 {
46         pthread_t tmr;
47
48         global_arg.timer = timer;
49         global_arg.cpu   = CPU;
50
51         int err = pthread_create(&tmr, 0, timerThread, (void*)&global_arg);
52         if (err) {
53                 ERROR() << "Error creating timer thread: " << err;
54                 enter_kdebug();
55         }
56 }