Skip to content

Commit 029b6ce

Browse files
Changwoo Minhtejun
authored andcommitted
sched_ext: Fix incorrect time delta calculation in time_delta()
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: d07be81 ("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>
1 parent 1626e5e commit 029b6ce

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tools/sched_ext/include/scx/common.bpf.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ void bpf_rcu_read_unlock(void) __ksym;
432432
*/
433433
static inline s64 time_delta(u64 after, u64 before)
434434
{
435-
return (s64)(after - before) > 0 ? : 0;
435+
return (s64)(after - before) > 0 ? (s64)(after - before) : 0;
436436
}
437437

438438
/**

0 commit comments

Comments
 (0)