[patch V3 11/51] posix-cpu-timers: Handle SIGEV_NONE timers correctly in timer_set()

Thomas Gleixner posted 51 patches 1 year, 6 months ago
[patch V3 11/51] posix-cpu-timers: Handle SIGEV_NONE timers correctly in timer_set()
Posted by Thomas Gleixner 1 year, 6 months ago
Expired SIGEV_NONE oneshot timers must return 0 nsec for the expiry time in
timer_get(), but the posix CPU timer implementation returns 1 nsec.

Add the missing conditional.

This will be cleaned up in a follow up patch.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
V2: Split out into new patch to make review simpler - Frederic
---
 kernel/time/posix-cpu-timers.c |   11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -706,7 +706,16 @@ static int posix_cpu_timer_set(struct k_
 				old_expires = exp - val;
 				old->it_value = ns_to_timespec64(old_expires);
 			} else {
-				old->it_value.tv_nsec = 1;
+				/*
+				 * A single shot SIGEV_NONE timer must return 0, when it is
+				 * expired! Timers which have a real signal delivery mode
+				 * must return a remaining time greater than 0 because the
+				 * signal has not yet been delivered.
+				 */
+				if (sigev_none)
+					old->it_value.tv_nsec = 0;
+				else
+					old->it_value.tv_nsec = 1;
 				old->it_value.tv_sec = 0;
 			}
 		}
Re: [patch V3 11/51] posix-cpu-timers: Handle SIGEV_NONE timers correctly in timer_set()
Posted by Frederic Weisbecker 1 year, 6 months ago
Le Mon, Jun 10, 2024 at 06:42:18PM +0200, Thomas Gleixner a écrit :
> Expired SIGEV_NONE oneshot timers must return 0 nsec for the expiry time in
> timer_get(), but the posix CPU timer implementation returns 1 nsec.
> 
> Add the missing conditional.
> 
> This will be cleaned up in a follow up patch.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
> V2: Split out into new patch to make review simpler - Frederic
> ---
>  kernel/time/posix-cpu-timers.c |   11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> --- a/kernel/time/posix-cpu-timers.c
> +++ b/kernel/time/posix-cpu-timers.c
> @@ -706,7 +706,16 @@ static int posix_cpu_timer_set(struct k_
>  				old_expires = exp - val;
>  				old->it_value = ns_to_timespec64(old_expires);
>  			} else {
> -				old->it_value.tv_nsec = 1;
> +				/*
> +				 * A single shot SIGEV_NONE timer must return 0, when it is
> +				 * expired! Timers which have a real signal delivery mode
> +				 * must return a remaining time greater than 0 because the
> +				 * signal has not yet been delivered.
> +				 */
> +				if (sigev_none)

Does this patch build? The sigev_none variable doesn't seem to exist.

Thanks.

> +					old->it_value.tv_nsec = 0;
> +				else
> +					old->it_value.tv_nsec = 1;
>  				old->it_value.tv_sec = 0;
>  			}
>  		}
> 
Re: [patch V3 11/51] posix-cpu-timers: Handle SIGEV_NONE timers correctly in timer_set()
Posted by Thomas Gleixner 1 year, 5 months ago
On Sat, Jun 22 2024 at 16:35, Frederic Weisbecker wrote:
> Le Mon, Jun 10, 2024 at 06:42:18PM +0200, Thomas Gleixner a écrit :
>> +				 */
>> +				if (sigev_none)
>
> Does this patch build? The sigev_none variable doesn't seem to exist.

Bah. I messed that up when splitting it. 13/51 fixes it up.
[patch V3-2 11/51] posix-cpu-timers: Handle SIGEV_NONE timers correctly in timer_set()
Posted by Thomas Gleixner 1 year, 5 months ago
Expired SIGEV_NONE oneshot timers must return 0 nsec for the expiry time in
timer_get(), but the posix CPU timer implementation returns 1 nsec.

Add the missing conditional.

This will be cleaned up in a follow up patch.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
V3-2: Fix the split up fallout - Frederic
V2: Split out into new patch to make review simpler - Frederic
---
 kernel/time/posix-cpu-timers.c |   12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

--- a/kernel/time/posix-cpu-timers.c
+++ b/kernel/time/posix-cpu-timers.c
@@ -623,6 +623,7 @@ static void cpu_timer_fire(struct k_itim
 static int posix_cpu_timer_set(struct k_itimer *timer, int timer_flags,
 			       struct itimerspec64 *new, struct itimerspec64 *old)
 {
+	bool sigev_none = timer->it_sigev_notify == SIGEV_NONE;
 	clockid_t clkid = CPUCLOCK_WHICH(timer->it_clock);
 	u64 old_expires, new_expires, old_incr, val;
 	struct cpu_timer *ctmr = &timer->it.cpu;
@@ -706,7 +707,16 @@ static int posix_cpu_timer_set(struct k_
 				old_expires = exp - val;
 				old->it_value = ns_to_timespec64(old_expires);
 			} else {
-				old->it_value.tv_nsec = 1;
+				/*
+				 * A single shot SIGEV_NONE timer must return 0, when it is
+				 * expired! Timers which have a real signal delivery mode
+				 * must return a remaining time greater than 0 because the
+				 * signal has not yet been delivered.
+				 */
+				if (sigev_none)
+					old->it_value.tv_nsec = 0;
+				else
+					old->it_value.tv_nsec = 1;
 				old->it_value.tv_sec = 0;
 			}
 		}
Re: [patch V3-2 11/51] posix-cpu-timers: Handle SIGEV_NONE timers correctly in timer_set()
Posted by Frederic Weisbecker 1 year, 5 months ago
Le Sun, Jun 23, 2024 at 01:16:02PM +0200, Thomas Gleixner a écrit :
> Expired SIGEV_NONE oneshot timers must return 0 nsec for the expiry time in
> timer_get(), but the posix CPU timer implementation returns 1 nsec.
> 
> Add the missing conditional.
> 
> This will be cleaned up in a follow up patch.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Reviewed-by: Frederic Weisbecker <frederic@kernel.org>