mirror of
https://github.com/sched-ext/scx.git
synced 2024-11-24 11:50:23 +00:00
Merge pull request #903 from multics69/lavd-issue-897
scx_lavd: update cur_logical_clk atomically
This commit is contained in:
commit
56357a79db
@ -458,14 +458,16 @@ static void update_stat_for_runnable(struct task_struct *p,
|
||||
static void advance_cur_logical_clk(struct task_ctx *taskc)
|
||||
{
|
||||
struct sys_stat *stat_cur = get_sys_stat_cur();
|
||||
u64 vlc, clc;
|
||||
u64 vlc, clc, ret_clc;
|
||||
u64 nr_queued, delta, new_clk;
|
||||
|
||||
vlc = READ_ONCE(taskc->vdeadline_log_clk);
|
||||
clc = READ_ONCE(cur_logical_clk);
|
||||
|
||||
for (int i = 0; i < LAVD_MAX_RETRY; ++i) {
|
||||
/*
|
||||
* The clock should not go backward, so do nothing.
|
||||
*/
|
||||
vlc = READ_ONCE(taskc->vdeadline_log_clk);
|
||||
clc = READ_ONCE(cur_logical_clk);
|
||||
if (vlc <= clc)
|
||||
return;
|
||||
|
||||
@ -477,7 +479,15 @@ static void advance_cur_logical_clk(struct task_ctx *taskc)
|
||||
delta = (vlc - clc) / nr_queued;
|
||||
new_clk = clc + delta;
|
||||
|
||||
WRITE_ONCE(cur_logical_clk, new_clk);
|
||||
ret_clc = __sync_val_compare_and_swap(&cur_logical_clk, clc, new_clk);
|
||||
if (ret_clc == clc) /* CAS success */
|
||||
return;
|
||||
|
||||
/*
|
||||
* Retry with the updated clc
|
||||
*/
|
||||
clc = ret_clc;
|
||||
}
|
||||
}
|
||||
|
||||
static void update_stat_for_running(struct task_struct *p,
|
||||
|
Loading…
Reference in New Issue
Block a user