aboutsummaryrefslogtreecommitdiff
path: root/sysdeps/unix/sysv/linux/kernel-posix-cpu-timers.h
diff options
context:
space:
mode:
authorAdhemerval Zanella <adhemerval.zanella@linaro.org>2022-08-30 09:08:02 -0300
committerAdhemerval Zanella <adhemerval.zanella@linaro.org>2022-10-20 10:19:08 -0300
commit9b5e138f2bbd032da858a4ad5bb51ed99d6f89b6 (patch)
treed61137c94c8088bde747b0b6c741c35e0ed22f1a /sysdeps/unix/sysv/linux/kernel-posix-cpu-timers.h
parent643a2d01399188192e0da234581034f77c892054 (diff)
downloadglibc-9b5e138f2bbd032da858a4ad5bb51ed99d6f89b6.tar
glibc-9b5e138f2bbd032da858a4ad5bb51ed99d6f89b6.tar.gz
glibc-9b5e138f2bbd032da858a4ad5bb51ed99d6f89b6.tar.bz2
glibc-9b5e138f2bbd032da858a4ad5bb51ed99d6f89b6.zip
linux: Avoid shifting a negative signed on POSIX timer interface
The current macros uses pid as signed value, which triggers a compiler warning for process and thread timers. Replace MAKE_PROCESS_CPUCLOCK with static inline function that expects the pid as unsigned. These are similar to what Linux does internally. Checked on x86_64-linux-gnu. Reviewed-by: Arjun Shankar <arjun@redhat.com>
Diffstat (limited to 'sysdeps/unix/sysv/linux/kernel-posix-cpu-timers.h')
-rw-r--r--sysdeps/unix/sysv/linux/kernel-posix-cpu-timers.h28
1 files changed, 23 insertions, 5 deletions
diff --git a/sysdeps/unix/sysv/linux/kernel-posix-cpu-timers.h b/sysdeps/unix/sysv/linux/kernel-posix-cpu-timers.h
index 164a90ddeb..bea1e0e62d 100644
--- a/sysdeps/unix/sysv/linux/kernel-posix-cpu-timers.h
+++ b/sysdeps/unix/sysv/linux/kernel-posix-cpu-timers.h
@@ -1,4 +1,12 @@
-/* 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) \
@@ -12,7 +20,17 @@
#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)