Skip to content

Commit

Permalink
posix-cpu-timers: Use dedicated flag for CPU timer nanosleep
Browse files Browse the repository at this point in the history
POSIX CPU timer nanosleep creates a k_itimer on stack and uses the sigq
pointer to detect the nanosleep case in the expiry function.

Prepare for embedding sigqueue into struct k_itimer by using a dedicated
flag for nanosleep.

Signed-off-by: Thomas Gleixner <[email protected]>
Reviewed-by: Frederic Weisbecker <[email protected]>
Acked-by: Peter Zijlstra (Intel) <[email protected]>
Link: https://lore.kernel.org/all/[email protected]
  • Loading branch information
KAGA-KOKO committed Nov 7, 2024
1 parent bf63568 commit 4cf7bf2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/linux/posix-timers.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static inline int clockid_to_fd(const clockid_t clk)
* @pid: Pointer to target task PID
* @elist: List head for the expiry list
* @firing: Timer is currently firing
* @nanosleep: Timer is used for nanosleep and is not a regular posix-timer
* @handling: Pointer to the task which handles expiry
*/
struct cpu_timer {
Expand All @@ -50,6 +51,7 @@ struct cpu_timer {
struct pid *pid;
struct list_head elist;
bool firing;
bool nanosleep;
struct task_struct __rcu *handling;
};

Expand Down
3 changes: 2 additions & 1 deletion kernel/time/posix-cpu-timers.c
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ static void cpu_timer_fire(struct k_itimer *timer)

timer->it_status = POSIX_TIMER_DISARMED;

if (unlikely(timer->sigq == NULL)) {
if (unlikely(ctmr->nanosleep)) {
/*
* This a special case for clock_nanosleep,
* not a normal timer from sys_timer_create.
Expand Down Expand Up @@ -1493,6 +1493,7 @@ static int do_cpu_nanosleep(const clockid_t which_clock, int flags,
timer.it_overrun = -1;
error = posix_cpu_timer_create(&timer);
timer.it_process = current;
timer.it.cpu.nanosleep = true;

if (!error) {
static struct itimerspec64 zero_it;
Expand Down

0 comments on commit 4cf7bf2

Please sign in to comment.