Create a new hooks for the controlflow
[lttv.git] / doc / developer / lttng-synthetic-tsc-msb.txt
CommitLineData
11904fb6 1
2LTTng synthetic TSC MSB
3
4Mathieu Desnoyers, Mars 1, 2006
5
6A problem found on some architectures is that the TSC is limited to 32 bits,
7which induces a wrap-around every 8 seconds or so.
8
9The wraps arounds are detectable by the use of a heartbeat timer, which
10generates an event in each trace at periodic interval. It makes reading the
11trace sequentially possible.
12
13What causes problem is fast time seek in the trace : it uses the buffer
14boundary timestamps (64 bits) to seek to the right block in O(log(n)). It
15cannot, however, read the trace sequentially.
16
17So the problem posed is the following : we want to generate a per cpu 64 bits
18TSC from the available 32 bits with the 32 MSB generated synthetically. I should
19be readable by the buffer switch event.
20
21The idea is the following : we keep a 32 bits previous_tsc value per cpu. It
22helps detect the wrap around. Each time a heartbeat fires or a buffer switch
23happens, the previous_tsc is read, and then written to the new value. If a wrap
24around is detected, the msb_tsc for the cpu is atomically incremented.
25
26We are sure that there is only one heartbeat at a given time because they are
27fired at fixed interval : typically 10 times per 32bit TSC wrap around. Even
28better, as they are launched by a worker thread, it can only be queued once in
29the worker queue.
30
31Now with buffer switch vs heartbeat concurrency. Worse case : a heartbeat is
32happenning : one CPU is in process context (worker thread), the other ones are
33in interrupt context (IPI). On one CPU in IPI, we have an NMI triggered that
34generates a buffer switch.
35
36What is sure is that the heartbeat needs to read and write the previous_tsc. It
37also needs to increment atomically the msb_tsc. However, the buffer switch only
38needs to read the previous_tsc, compare it to the current tsc and read the
39msb_tsc.
40
41Another race case is that the buffer switch can be interrupted by the heartbeat.
42
43So what we need is to have an atomic write. As the architecture does not support
4464 bits cmpxchg, we will need this little data structure to overcome this
45problem :
46
47An array of two 64 bits elements. Elements are updated in two memory writes, but
48the element switch (current element) is made atomically. As there is only one
49writer, this has no locking problem.
50
1e3e9a0a 51We make sure the synthetic tcs reader does not sleep by disabling preemption. We
52do the same for the writer.
This page took 0.061534 seconds and 4 git commands to generate.