Skip to content

Commit

Permalink
Merge pull request #239 from hodgesds/cpufreq_helpers
Browse files Browse the repository at this point in the history
Add CPU frequency related helpers and extend scx_layered
  • Loading branch information
htejun authored Apr 24, 2024
2 parents a8daf37 + 32e97bf commit 9a9b4dd
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions scheds/include/scx/common.bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ bool scx_bpf_task_running(const struct task_struct *p) __ksym;
s32 scx_bpf_task_cpu(const struct task_struct *p) __ksym;
struct cgroup *scx_bpf_task_cgroup(struct task_struct *p) __ksym;
u32 scx_bpf_reenqueue_local(void) __ksym;
u32 scx_bpf_cpuperf_cap(s32 cpu) __ksym;
u32 scx_bpf_cpuperf_cur(s32 cpu) __ksym;
void scx_bpf_cpuperf_set(u32 cpu, u32 perf) __ksym;

#define BPF_STRUCT_OPS(name, args...) \
SEC("struct_ops/"#name) \
Expand Down
1 change: 1 addition & 0 deletions scheds/rust/scx_layered/src/bpf/intf.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ struct layer {
unsigned int refresh_cpus;
unsigned char cpus[MAX_CPUS_U8];
unsigned int nr_cpus; // managed from BPF side
unsigned int perf;
};

#endif /* __INTF_H */
8 changes: 7 additions & 1 deletion scheds/rust/scx_layered/src/bpf/main.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,7 @@ void BPF_STRUCT_OPS(layered_running, struct task_struct *p)
struct cpu_ctx *cctx;
struct task_ctx *tctx;
struct layer *layer;
u32 cpu;

if (!(cctx = lookup_cpu_ctx(-1)) || !(tctx = lookup_task_ctx(p)) ||
!(layer = lookup_layer(tctx->layer)))
Expand All @@ -740,12 +741,14 @@ void BPF_STRUCT_OPS(layered_running, struct task_struct *p)
cctx->current_exclusive = layer->exclusive;
tctx->started_running_at = bpf_ktime_get_ns();

cpu = scx_bpf_task_cpu(p);

/*
* If this CPU is transitioning from running an exclusive task to a
* non-exclusive one, the sibling CPU has likely been idle. Wake it up.
*/
if (cctx->prev_exclusive && !cctx->current_exclusive) {
s32 sib = sibling_cpu(scx_bpf_task_cpu(p));
s32 sib = sibling_cpu(cpu);
struct cpu_ctx *sib_cctx;

/*
Expand All @@ -760,6 +763,9 @@ void BPF_STRUCT_OPS(layered_running, struct task_struct *p)
}
}

if (layer->perf > 0)
scx_bpf_cpuperf_set(cpu, layer->perf);

cctx->maybe_idle = false;
}

Expand Down
17 changes: 16 additions & 1 deletion scheds/rust/scx_layered/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ enum LayerKind {
cpus_range: Option<(usize, usize)>,
#[serde(default)]
min_exec_us: u64,
#[serde(default)]
perf: u64,
},
Grouped {
util_range: (f64, f64),
Expand All @@ -331,6 +333,8 @@ enum LayerKind {
preempt: bool,
#[serde(default)]
exclusive: bool,
#[serde(default)]
perf: u64,
},
Open {
#[serde(default)]
Expand All @@ -339,6 +343,8 @@ enum LayerKind {
preempt: bool,
#[serde(default)]
exclusive: bool,
#[serde(default)]
perf: u64,
},
}

Expand Down Expand Up @@ -1286,23 +1292,29 @@ impl<'a> Scheduler<'a> {
layer.nr_match_ors = spec.matches.len() as u32;

match &spec.kind {
LayerKind::Confined { min_exec_us, .. } => layer.min_exec_ns = min_exec_us * 1000,
LayerKind::Confined { min_exec_us, perf, .. } => {
layer.min_exec_ns = min_exec_us * 1000;
layer.perf = u32::try_from(*perf)?;
}
LayerKind::Open {
min_exec_us,
preempt,
exclusive,
perf,
..
}
| LayerKind::Grouped {
min_exec_us,
preempt,
exclusive,
perf,
..
} => {
layer.open.write(true);
layer.min_exec_ns = min_exec_us * 1000;
layer.preempt.write(*preempt);
layer.exclusive.write(*exclusive);
layer.perf = u32::try_from(*perf)?;
}
}
}
Expand Down Expand Up @@ -1769,6 +1781,7 @@ fn write_example_file(path: &str) -> Result<()> {
cpus_range: Some((0, 16)),
util_range: (0.8, 0.9),
min_exec_us: 1000,
perf: 1024,
},
},
LayerSpec {
Expand All @@ -1782,6 +1795,7 @@ fn write_example_file(path: &str) -> Result<()> {
min_exec_us: 100,
preempt: true,
exclusive: true,
perf: 1024,
},
},
LayerSpec {
Expand All @@ -1794,6 +1808,7 @@ fn write_example_file(path: &str) -> Result<()> {
min_exec_us: 200,
preempt: false,
exclusive: false,
perf: 1024,
},
},
],
Expand Down

0 comments on commit 9a9b4dd

Please sign in to comment.