]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
sched_ext: Fix incorrect time delta calculation in time_delta()
authorChangwoo Min <changwoo@igalia.com>
Sun, 2 Feb 2025 03:37:48 +0000 (12:37 +0900)
committerTejun Heo <tj@kernel.org>
Sun, 2 Feb 2025 17:40:35 +0000 (07:40 -1000)
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>
Acked-by: Andrea Righi <arighi@nvidia.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
tools/sched_ext/include/scx/common.bpf.h

index f254a39b86a5887581af7aed455adb075b37f674..d72b60a0c582c6695fbb86b033a790323d656ad5 100644 (file)
@@ -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;
 }
 
 /**