The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] sched_ext: Fix incorrect time delta calculation in time_delta()
@ 2025-02-02  3:37 Changwoo Min
  2025-02-02  6:37 ` Andrea Righi
  2025-02-02 17:42 ` Tejun Heo
  0 siblings, 2 replies; 3+ messages in thread
From: Changwoo Min @ 2025-02-02  3:37 UTC (permalink / raw)
  To: tj, void, arighi; +Cc: kernel-dev, linux-kernel, Changwoo Min

When (s64)(after - before) > 0, the code returns the result of
(s64)(after - before) > 0 while the intended result should be
(s64)(after - before). That happens because the middle operand of
the ternary operator was omitted incorrectly, returning the result of
(s64)(after - before) > 0. Thus, add the middle operand
-- (s64)(after - before) -- to return the correct time calculation.

Fixes: d07be814fc71 ("sched_ext: Add time helpers for BPF schedulers")
Signed-off-by: Changwoo Min <changwoo@igalia.com>
---
 tools/sched_ext/include/scx/common.bpf.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/sched_ext/include/scx/common.bpf.h b/tools/sched_ext/include/scx/common.bpf.h
index f254a39b86a5..d72b60a0c582 100644
--- a/tools/sched_ext/include/scx/common.bpf.h
+++ b/tools/sched_ext/include/scx/common.bpf.h
@@ -432,7 +432,7 @@ void bpf_rcu_read_unlock(void) __ksym;
  */
 static inline s64 time_delta(u64 after, u64 before)
 {
-	return (s64)(after - before) > 0 ? : 0;
+	return (s64)(after - before) > 0 ? (s64)(after - before) : 0;
 }
 
 /**
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] sched_ext: Fix incorrect time delta calculation in time_delta()
  2025-02-02  3:37 [PATCH] sched_ext: Fix incorrect time delta calculation in time_delta() Changwoo Min
@ 2025-02-02  6:37 ` Andrea Righi
  2025-02-02 17:42 ` Tejun Heo
  1 sibling, 0 replies; 3+ messages in thread
From: Andrea Righi @ 2025-02-02  6:37 UTC (permalink / raw)
  To: Changwoo Min; +Cc: tj, void, kernel-dev, linux-kernel

On Sun, Feb 02, 2025 at 12:37:48PM +0900, Changwoo Min wrote:
> When (s64)(after - before) > 0, the code returns the result of
> (s64)(after - before) > 0 while the intended result should be
> (s64)(after - before). That happens because the middle operand of
> the ternary operator was omitted incorrectly, returning the result of
> (s64)(after - before) > 0. Thus, add the middle operand
> -- (s64)(after - before) -- to return the corRECT time calculation.
> 
> Fixes: d07be814fc71 ("sched_ext: Add time helpers for BPF schedulers")
> Signed-off-by: Changwoo Min <changwoo@igalia.com>
> ---
>  tools/sched_ext/include/scx/common.bpf.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tools/sched_ext/include/scx/common.bpf.h b/tools/sched_ext/include/scx/common.bpf.h
> index f254a39b86a5..d72b60a0c582 100644
> --- a/tools/sched_ext/include/scx/common.bpf.h
> +++ b/tools/sched_ext/include/scx/common.bpf.h
> @@ -432,7 +432,7 @@ void bpf_rcu_read_unlock(void) __ksym;
>   */
>  static inline s64 time_delta(u64 after, u64 before)
>  {
> -	return (s64)(after - before) > 0 ? : 0;
> +	return (s64)(after - before) > 0 ? (s64)(after - before) : 0;

Ugh.. how did we miss this? Thanks for noticing.

Acked-by: Andrea Righi <arighi@nvidia.com>

-Andrea

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] sched_ext: Fix incorrect time delta calculation in time_delta()
  2025-02-02  3:37 [PATCH] sched_ext: Fix incorrect time delta calculation in time_delta() Changwoo Min
  2025-02-02  6:37 ` Andrea Righi
@ 2025-02-02 17:42 ` Tejun Heo
  1 sibling, 0 replies; 3+ messages in thread
From: Tejun Heo @ 2025-02-02 17:42 UTC (permalink / raw)
  To: Changwoo Min; +Cc: void, arighi, kernel-dev, linux-kernel

On Sun, Feb 02, 2025 at 12:37:48PM +0900, Changwoo Min wrote:
> When (s64)(after - before) > 0, the code returns the result of
> (s64)(after - before) > 0 while the intended result should be
> (s64)(after - before). That happens because the middle operand of
> the ternary operator was omitted incorrectly, returning the result of
> (s64)(after - before) > 0. Thus, add the middle operand
> -- (s64)(after - before) -- to return the correct time calculation.
> 
> Fixes: d07be814fc71 ("sched_ext: Add time helpers for BPF schedulers")
> Signed-off-by: Changwoo Min <changwoo@igalia.com>

Applied to sched_ext/for-6.14-fixes.

Thanks.

-- 
tejun

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-02-02 17:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-02  3:37 [PATCH] sched_ext: Fix incorrect time delta calculation in time_delta() Changwoo Min
2025-02-02  6:37 ` Andrea Righi
2025-02-02 17:42 ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox