/* The clockid_t value is a simple computation from the TID. */
- const clockid_t tidclock = MAKE_THREAD_CPUCLOCK (pd->tid, CPUCLOCK_SCHED);
+ const clockid_t tidclock = make_thread_cpuclock (pd->tid, CPUCLOCK_SCHED);
*clockid = tidclock;
return 0;
/* The clockid_t value is a simple computation from the PID.
But we do a clock_getres call to validate it. */
- const clockid_t pidclock = MAKE_PROCESS_CPUCLOCK (pid, CPUCLOCK_SCHED);
+ const clockid_t pidclock = make_process_cpuclock (pid, CPUCLOCK_SCHED);
#ifndef __NR_clock_getres_time64
# define __NR_clock_getres_time64 __NR_clock_getres
if (clock_id == CLOCK_THREAD_CPUTIME_ID)
return EINVAL;
if (clock_id == CLOCK_PROCESS_CPUTIME_ID)
- clock_id = MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED);
+ clock_id = PROCESS_CLOCK;
/* If the call is interrupted by a signal handler or encounters an error,
it returns a positive value similar to errno. */
-/* Parameters for the Linux kernel ABI for CPU clocks. */
+/*
+ Parameters for the Linux kernel ABI for CPU clocks, the bit fields within
+ a clockid:
+
+ - The most significant 29 bits hold either a pid or a file descriptor.
+ - Bit 2 indicates whether a cpu clock refers to a thread or a process.
+ - Bits 1 and 0 give the type: PROF=0, VIRT=1, SCHED=2, or FD=3.
+ - A clockid is invalid if bits 2, 1, and 0 are all set.
+ */
#define CPUCLOCK_PID(clock) ((pid_t) ~((clock) >> 3))
#define CPUCLOCK_PERTHREAD(clock) \
#define CPUCLOCK_SCHED 2
#define CPUCLOCK_MAX 3
-#define MAKE_PROCESS_CPUCLOCK(pid, clock) \
- ((~(clockid_t) (pid) << 3) | (clockid_t) (clock))
-#define MAKE_THREAD_CPUCLOCK(tid, clock) \
- MAKE_PROCESS_CPUCLOCK((tid), (clock) | CPUCLOCK_PERTHREAD_MASK)
+static inline clockid_t
+make_process_cpuclock (unsigned int pid, clockid_t clock)
+{
+ return ((~pid) << 3) | clock;
+}
+
+static inline clockid_t
+make_thread_cpuclock (unsigned int tid, clockid_t clock)
+{
+ return make_process_cpuclock (tid, clock | CPUCLOCK_PERTHREAD_MASK);
+}
+
+#define PROCESS_CLOCK make_process_cpuclock (0, CPUCLOCK_SCHED)
+#define THREAD_CLOCK make_thread_cpuclock (0, CPUCLOCK_SCHED)
{
{
clockid_t syscall_clockid = (clock_id == CLOCK_PROCESS_CPUTIME_ID
- ? MAKE_PROCESS_CPUCLOCK (0, CPUCLOCK_SCHED)
+ ? PROCESS_CLOCK
: clock_id == CLOCK_THREAD_CPUTIME_ID
- ? MAKE_THREAD_CPUCLOCK (0, CPUCLOCK_SCHED)
+ ? THREAD_CLOCK
: clock_id);
/* If the user wants notification via a thread we need to handle