Skip to content

Commit

Permalink
Merge pull request #1262 from etsal/rusty-cpuperf-set
Browse files Browse the repository at this point in the history
scx_rusty: add option for setting scx_bpf_cpuperf_set()
  • Loading branch information
etsal authored Jan 29, 2025
2 parents 2664f03 + 5f792a0 commit cc58696
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
21 changes: 17 additions & 4 deletions scheds/rust/scx_rusty/src/bpf/main.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ const volatile bool direct_greedy_numa;
const volatile bool mempolicy_affinity;
const volatile u32 greedy_threshold;
const volatile u32 greedy_threshold_x_numa;
const volatile u32 rusty_perf_mode;
const volatile u32 debug;

/* base slice duration */
Expand Down Expand Up @@ -1760,6 +1761,7 @@ __weak s32 create_dom(u32 dom_id)
struct bpf_cpumask *dom_mask, *node_mask, *all_mask;
struct lb_domain *lb_domain;
u32 cpu, node_id;
int perf;
s32 ret;

if (dom_id >= MAX_DOMS) {
Expand Down Expand Up @@ -1810,6 +1812,7 @@ __weak s32 create_dom(u32 dom_id)

bpf_for(cpu, 0, MAX_CPUS) {
const volatile u64 *dmask;
bool cpu_in_domain;

dmask = MEMBER_VPTR(dom_cpumasks, [dom_id][cpu / 64]);
if (!dmask) {
Expand All @@ -1818,10 +1821,20 @@ __weak s32 create_dom(u32 dom_id)
break;
}

if (*dmask & (1LLU << (cpu % 64))) {
bpf_cpumask_set_cpu(cpu, dom_mask);
bpf_cpumask_set_cpu(cpu, all_mask);
}
cpu_in_domain = *dmask & (1LLU << (cpu % 64));
if (!cpu_in_domain)
continue;

bpf_cpumask_set_cpu(cpu, dom_mask);
bpf_cpumask_set_cpu(cpu, all_mask);

/*
* Perf has to be within [0, 1024]. Set it regardless
* of value to clean up any previous settings, since
* it persists even after removing the scheduler.
*/
perf = min(SCX_CPUPERF_ONE, rusty_perf_mode);
scx_bpf_cpuperf_set(cpu, perf);
}
bpf_rcu_read_unlock();
if (ret)
Expand Down
7 changes: 7 additions & 0 deletions scheds/rust/scx_rusty/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ struct Opts {
/// Show descriptions for statistics.
#[clap(long)]
help_stats: bool,

/// Tunable for prioritizing CPU performance by configuring the CPU frequency governor.
/// Valid values are [0, 1024]. Higher values prioritize performance, lower values
/// prioritize energy efficiency. When in doubt, use 0 or 1024.
#[clap(long, default_value = "0")]
perf: u32,
}

fn read_cpu_busy_and_total(reader: &procfs::ProcReader) -> Result<(u64, u64)> {
Expand Down Expand Up @@ -441,6 +447,7 @@ impl<'a> Scheduler<'a> {
skel.maps.rodata_data.direct_greedy_numa = opts.direct_greedy_numa;
skel.maps.rodata_data.mempolicy_affinity = opts.mempolicy_affinity;
skel.maps.rodata_data.debug = opts.verbose as u32;
skel.maps.rodata_data.rusty_perf_mode = opts.perf;

// Attach.
let mut skel = scx_ops_load!(skel, rusty, uei)?;
Expand Down

0 comments on commit cc58696

Please sign in to comment.