1 | /* |
2 | Parameters for the Linux kernel ABI for CPU clocks, the bit fields within |
3 | a clockid: |
4 | |
5 | - The most significant 29 bits hold either a pid or a file descriptor. |
6 | - Bit 2 indicates whether a cpu clock refers to a thread or a process. |
7 | - Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3. |
8 | - A clockid is invalid if bits 2, 1, and 0 are all set. |
9 | */ |
10 | |
11 | #define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3)) |
12 | #define CPUCLOCK_PERTHREAD(clock) \ |
13 | (((clock) & (clockid_t) CPUCLOCK_PERTHREAD_MASK) != 0) |
14 | #define CPUCLOCK_PID_MASK 7 |
15 | #define CPUCLOCK_PERTHREAD_MASK 4 |
16 | #define CPUCLOCK_WHICH(clock) ((clock) & (clockid_t) CPUCLOCK_CLOCK_MASK) |
17 | #define CPUCLOCK_CLOCK_MASK 3 |
18 | #define CPUCLOCK_PROF 0 |
19 | #define CPUCLOCK_VIRT 1 |
20 | #define CPUCLOCK_SCHED 2 |
21 | #define CPUCLOCK_MAX 3 |
22 | |
23 | static inline clockid_t |
24 | make_process_cpuclock (unsigned int pid, clockid_t clock) |
25 | { |
26 | return ((~pid) << 3) | clock; |
27 | } |
28 | |
29 | static inline clockid_t |
30 | make_thread_cpuclock (unsigned int tid, clockid_t clock) |
31 | { |
32 | return make_process_cpuclock (tid, clock | CPUCLOCK_PERTHREAD_MASK); |
33 | } |
34 | |
35 | #define PROCESS_CLOCK make_process_cpuclock (0, CPUCLOCK_SCHED) |
36 | #define THREAD_CLOCK make_thread_cpuclock (0, CPUCLOCK_SCHED) |
37 | |