Skip to content

Commit

Permalink
tweaks
Browse files Browse the repository at this point in the history
(cherry picked from commit 0bc2dad)
(cherry picked from commit b050ddd)
  • Loading branch information
likewhatevs committed Feb 3, 2025
1 parent 5fe9179 commit 4512355
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions scheds/rust/scx_layered/src/bpf/main.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ u32 layered_root_tgid = 0;

u32 empty_layer_ids[MAX_LAYERS];
u32 nr_empty_layer_ids;
static u32 do_refresh_layer_cpumasks = 0;

UEI_DEFINE(uei);

Expand Down Expand Up @@ -385,17 +386,26 @@ static void refresh_cpumasks(u32 layer_id)
}
}

/*
* Refreshes all layer cpumasks, this is called via BPF_PROG_RUN from userspace.
*/
SEC("syscall")
int BPF_PROG(refresh_layer_cpumasks)
static bool maybe_refresh_layer_cpumasks()
{
u32 id;

if (!__sync_lock_test_and_set(&do_refresh_layer_cpumasks, 0))
return false;

bpf_for(id, 0, nr_layers)
refresh_cpumasks(id);

return true;
}

/*
* Refreshes all layer cpumasks, this is called via BPF_PROG_RUN from userspace.
*/
SEC("syscall")
__weak s32 BPF_PROG(refresh_layer_cpumasks)
{
__sync_fetch_and_or(&do_refresh_layer_cpumasks, 1);
return 0;
}

Expand Down Expand Up @@ -936,6 +946,7 @@ s32 BPF_STRUCT_OPS(layered_select_cpu, struct task_struct *p, s32 prev_cpu, u64
struct layer *layer;
s32 cpu;

maybe_refresh_layer_cpumasks();
if (!(cpuc = lookup_cpu_ctx(-1)) || !(taskc = lookup_task_ctx(p)))
return prev_cpu;

Expand Down Expand Up @@ -1151,6 +1162,7 @@ void BPF_STRUCT_OPS(layered_enqueue, struct task_struct *p, u64 enq_flags)
u64 queued_runtime;
u64 *lstats;

maybe_refresh_layer_cpumasks();
if (!(cpuc = lookup_cpu_ctx(-1)) ||
!(task_cpuc = lookup_cpu_ctx(task_cpu)) ||
!(taskc = lookup_task_ctx(p)))
Expand Down Expand Up @@ -1602,6 +1614,8 @@ void BPF_STRUCT_OPS(layered_dispatch, s32 cpu, struct task_struct *prev)
u32 nr_ogp_layers = nr_op_layers + nr_gp_layers;
u32 nr_ogn_layers = nr_on_layers + nr_gn_layers;

maybe_refresh_layer_cpumasks();

if (!(cpuc = lookup_cpu_ctx(-1)))
return;

Expand Down

0 comments on commit 4512355

Please sign in to comment.