Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions scheds/rust/scx_p2dq/src/bpf/main.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ char _license[] SEC("license") = "GPL";

UEI_DEFINE(uei);


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Stray line?

#define dbg(fmt, args...) do { if (debug) bpf_printk(fmt, ##args); } while (0)
#define trace(fmt, args...) do { if (debug > 1) bpf_printk(fmt, ##args); } while (0)

Expand Down Expand Up @@ -984,6 +985,8 @@ void BPF_STRUCT_OPS(p2dq_stopping, struct task_struct *p, bool runnable)
__sync_fetch_and_add(&llcx->dsq_max_vtime[dsq_index], scaled_used);
__sync_fetch_and_add(&llcx->dsq_load[dsq_index], used);
__sync_fetch_and_add(&llcx->load, used);
if (!taskc->all_cpus)
__sync_fetch_and_add(&llcx->affin_load, used);


trace("%s weight %d slice %llu used %llu scaled %llu",
Expand Down Expand Up @@ -1462,6 +1465,7 @@ static bool load_balance_timer(void)
return false;

llcx->load = 0;
llcx->non_scx_load = 0;
llcx->last_period_ns = scx_bpf_now();
bpf_for(j, 0, nr_dsqs_per_llc) {
llcx->dsq_load[j] = 0;
Expand Down Expand Up @@ -1669,6 +1673,32 @@ void BPF_STRUCT_OPS(p2dq_running, struct task_struct *p)
p2dq_running_impl(p);
}

void BPF_STRUCT_OPS(p2dq_cpu_acquire, s32 cpu,
struct scx_cpu_acquire_args *args)
{
struct cpu_ctx *cpuc;
struct llc_ctx *llcx;

if (!(cpuc = lookup_cpu_ctx(cpu)) ||
!(llcx = lookup_llc_ctx(cpuc->llc_id)))
return;

u64 now = scx_bpf_now();
llcx->non_scx_load += now - cpuc->last_acquired;
}

void BPF_STRUCT_OPS(p2dq_cpu_release, s32 cpu,
struct scx_cpu_release_args *args)
{
struct cpu_ctx *cpuc;

if (!(cpuc = lookup_cpu_ctx(cpu)))
return;

u64 now = scx_bpf_now();
cpuc->last_acquired = now;
}

void BPF_STRUCT_OPS(p2dq_enqueue, struct task_struct *p __arg_trusted, u64 enq_flags)
{
struct enqueue_promise pro;
Expand Down Expand Up @@ -1698,6 +1728,8 @@ SCX_OPS_DEFINE(p2dq,
.dispatch = (void *)p2dq_dispatch,
.running = (void *)p2dq_running,
.stopping = (void *)p2dq_stopping,
.cpu_acquire = (void *)p2dq_cpu_acquire,
.cpu_release = (void *)p2dq_cpu_release,
.set_cpumask = (void *)p2dq_set_cpumask,
.init_task = (void *)p2dq_init_task,
.exit_task = (void *)p2dq_exit_task,
Expand Down
4 changes: 4 additions & 0 deletions scheds/rust/scx_p2dq/src/bpf/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ struct cpu_ctx {
u32 perf;
bool interactive;
bool is_big;
bool idle;
u64 ran_for;
u64 last_acquired;
u64 dsqs[MAX_DSQS_PER_LLC];
u64 max_load_dsq;
};
Expand All @@ -27,6 +29,8 @@ struct llc_ctx {
u64 vtime;
u64 last_period_ns;
u64 load;
u64 affin_load;
u64 non_scx_load;
bool all_big;
u64 dsqs[MAX_DSQS_PER_LLC];
u64 dsq_max_vtime[MAX_DSQS_PER_LLC];
Expand Down