Skip to content

Commit a079650

Browse files
committed
layered: actually get slice_ns and max_exec_ns from CO:RE
Layered previously hardcoded the defaults for slice_ns and max_exec_us. This was changed in a recent PR to get these from CO:RE in the running kernel. This change doesn't work because the old values are still set a few lines below. Check for the presence of the CLI options and default to the CO:RE values otherwise. Remove setting the layer struct's slice_ns as we check if it's equal to 0 anyway and default to the global in the BPF code. Test plan: - CI
1 parent 596268e commit a079650

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

scheds/rust/scx_layered/src/main.rs

+13-17
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,15 @@ lazy_static! {
401401
#[command(verbatim_doc_comment)]
402402
struct Opts {
403403
/// Scheduling slice duration in microseconds.
404-
#[clap(short = 's', long, default_value = "20000")]
405-
slice_us: u64,
404+
#[clap(short = 's', long)]
405+
slice_us: Option<u64>,
406406

407407
/// Maximum consecutive execution time in microseconds. A task may be
408408
/// allowed to keep executing on a CPU for this long. Note that this is
409409
/// the upper limit and a task may have to moved off the CPU earlier. 0
410410
/// indicates default - 20 * slice_us.
411-
#[clap(short = 'M', long, default_value = "0")]
412-
max_exec_us: u64,
411+
#[clap(short = 'M', long)]
412+
max_exec_us: Option<u64>,
413413

414414
/// Scheduling interval in seconds.
415415
#[clap(short = 'i', long, default_value = "0.1")]
@@ -1165,11 +1165,7 @@ impl<'a> Scheduler<'a> {
11651165
..
11661166
} = spec.kind.common();
11671167

1168-
layer.slice_ns = if *slice_us > 0 {
1169-
*slice_us * 1000
1170-
} else {
1171-
opts.slice_us * 1000
1172-
};
1168+
layer.slice_ns = *slice_us * 1000;
11731169
layer.min_exec_ns = min_exec_us * 1000;
11741170
layer.yield_step_ns = if *yield_ignore > 0.999 {
11751171
0
@@ -1552,8 +1548,6 @@ impl<'a> Scheduler<'a> {
15521548
skel_builder.obj_builder.debug(opts.verbose > 1);
15531549
init_libbpf_logging(None);
15541550
let mut skel = scx_ops_open!(skel_builder, open_object, layered)?;
1555-
skel.maps.rodata_data.slice_ns = scx_enums.SCX_SLICE_DFL;
1556-
skel.maps.rodata_data.max_exec_ns = 20 * scx_enums.SCX_SLICE_DFL;
15571551

15581552
// Initialize skel according to @opts.
15591553
skel.struct_ops.layered_mut().exit_dump_len = opts.exit_dump_len;
@@ -1562,12 +1556,14 @@ impl<'a> Scheduler<'a> {
15621556
// Running scx_layered inside a PID namespace would break the
15631557
// following.
15641558
skel.maps.rodata_data.layered_tgid = std::process::id() as i32;
1565-
skel.maps.rodata_data.slice_ns = opts.slice_us * 1000;
1566-
skel.maps.rodata_data.max_exec_ns = if opts.max_exec_us > 0 {
1567-
opts.max_exec_us * 1000
1568-
} else {
1569-
opts.slice_us * 1000 * 20
1570-
};
1559+
1560+
let slice_ns = opts
1561+
.slice_us
1562+
.map(|us| us * 1000)
1563+
.unwrap_or(scx_enums.SCX_SLICE_DFL);
1564+
skel.maps.rodata_data.slice_ns = slice_ns;
1565+
skel.maps.rodata_data.max_exec_ns = opts.max_exec_ns.unwrap_or(20 * slice_ns);
1566+
15711567
skel.maps.rodata_data.nr_possible_cpus = *NR_CPUS_POSSIBLE as u32;
15721568
skel.maps.rodata_data.smt_enabled = cpu_pool.nr_cpus > cpu_pool.nr_cores;
15731569
skel.maps.rodata_data.has_little_cores = topo.has_little_cores();

0 commit comments

Comments
 (0)