Skip to content

Commit 369373f

Browse files
authored
Merge pull request #2898 from sched-ext/rustland-default-slice
scx_rustland_core: Allow to define a default time slice
2 parents 54f1bf7 + f5a2136 commit 369373f

File tree

8 files changed

+27
-15
lines changed

8 files changed

+27
-15
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/scx_rustland_core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "scx_rustland_core"
3-
version = "2.3.7"
3+
version = "2.4.7"
44
edition = "2021"
55
authors = ["Andrea Righi <[email protected]>"]
66
license = "GPL-2.0-only"

rust/scx_rustland_core/assets/bpf.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ impl<'cb> BpfScheduler<'cb> {
213213
partial: bool,
214214
debug: bool,
215215
builtin_idle: bool,
216+
slice_ns: u64,
216217
name: &str,
217218
) -> Result<Self> {
218219
let shutdown = Arc::new(AtomicBool::new(false));
@@ -263,6 +264,7 @@ impl<'cb> BpfScheduler<'cb> {
263264
skel.maps.rodata_data.as_mut().unwrap().usersched_pid = std::process::id();
264265
skel.maps.rodata_data.as_mut().unwrap().khugepaged_pid = Self::khugepaged_pid();
265266
skel.maps.rodata_data.as_mut().unwrap().builtin_idle = builtin_idle;
267+
skel.maps.rodata_data.as_mut().unwrap().slice_ns = slice_ns;
266268
skel.maps.rodata_data.as_mut().unwrap().debug = debug;
267269
let _ = Self::set_scx_ops_name(&mut skel.struct_ops.rustland_mut().name, name);
268270

rust/scx_rustland_core/assets/bpf/main.bpf.c

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ const volatile u32 khugepaged_pid; /* khugepaged PID */
6868
u64 usersched_last_run_at; /* Timestamp of the last user-space scheduler execution */
6969
static u64 nr_cpu_ids; /* Maximum possible CPU number */
7070

71+
/*
72+
* Default task time slice.
73+
*/
74+
const volatile u64 slice_ns;
75+
7176
/*
7277
* Number of tasks that are queued for scheduling.
7378
*
@@ -587,7 +592,7 @@ s32 BPF_STRUCT_OPS(rustland_select_cpu, struct task_struct *p, s32 prev_cpu,
587592
if (cpu >= 0) {
588593
if (can_direct_dispatch(cpu)) {
589594
scx_bpf_dsq_insert_vtime(p, cpu_to_dsq(cpu),
590-
SCX_SLICE_DFL, p->scx.dsq_vtime, 0);
595+
slice_ns, p->scx.dsq_vtime, 0);
591596
__sync_fetch_and_add(&nr_kernel_dispatches, 1);
592597
}
593598
return cpu;
@@ -695,7 +700,7 @@ void BPF_STRUCT_OPS(rustland_enqueue, struct task_struct *p, u64 enq_flags)
695700
* scheduling action to do.
696701
*/
697702
if (is_usersched_task(p)) {
698-
scx_bpf_dsq_insert(p, SCHED_DSQ, SCX_SLICE_DFL, enq_flags);
703+
scx_bpf_dsq_insert(p, SCHED_DSQ, slice_ns, enq_flags);
699704
goto out_kick;
700705
}
701706

@@ -708,7 +713,7 @@ void BPF_STRUCT_OPS(rustland_enqueue, struct task_struct *p, u64 enq_flags)
708713
*/
709714
if ((is_kthread(p) && p->nr_cpus_allowed == 1) || is_kswapd(p) || is_khugepaged(p)) {
710715
scx_bpf_dsq_insert_vtime(p, cpu_to_dsq(prev_cpu),
711-
SCX_SLICE_DFL, p->scx.dsq_vtime, enq_flags);
716+
slice_ns, p->scx.dsq_vtime, enq_flags);
712717
__sync_fetch_and_add(&nr_kernel_dispatches, 1);
713718
goto out_kick;
714719
}
@@ -738,7 +743,7 @@ void BPF_STRUCT_OPS(rustland_enqueue, struct task_struct *p, u64 enq_flags)
738743

739744
if (can_direct_dispatch(cpu)) {
740745
scx_bpf_dsq_insert_vtime(p, cpu_to_dsq(cpu),
741-
SCX_SLICE_DFL, p->scx.dsq_vtime, enq_flags);
746+
slice_ns, p->scx.dsq_vtime, enq_flags);
742747
__sync_fetch_and_add(&nr_kernel_dispatches, 1);
743748
goto out_kick;
744749
}
@@ -761,7 +766,7 @@ void BPF_STRUCT_OPS(rustland_enqueue, struct task_struct *p, u64 enq_flags)
761766
if (!task) {
762767
sched_congested(p);
763768
scx_bpf_dsq_insert_vtime(p, SHARED_DSQ,
764-
SCX_SLICE_DFL, p->scx.dsq_vtime, enq_flags);
769+
slice_ns, p->scx.dsq_vtime, enq_flags);
765770
__sync_fetch_and_add(&nr_kernel_dispatches, 1);
766771
goto out_kick;
767772
}
@@ -845,7 +850,7 @@ void BPF_STRUCT_OPS(rustland_dispatch, s32 cpu, struct task_struct *prev)
845850
*/
846851
if (prev && is_queued(prev) &&
847852
(!is_usersched_task(prev) || usersched_has_pending_tasks()))
848-
prev->scx.slice = SCX_SLICE_DFL;
853+
prev->scx.slice = slice_ns;
849854
}
850855

851856
void BPF_STRUCT_OPS(rustland_runnable, struct task_struct *p, u64 enq_flags)
@@ -922,7 +927,7 @@ void BPF_STRUCT_OPS(rustland_stopping, struct task_struct *p, bool runnable)
922927
void BPF_STRUCT_OPS(rustland_enable, struct task_struct *p)
923928
{
924929
p->scx.dsq_vtime = 0;
925-
p->scx.slice = SCX_SLICE_DFL;
930+
p->scx.slice = slice_ns;
926931
}
927932

928933
/*

scheds/rust/scx_rlfifo/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ ctrlc = { version = "3.1", features = ["termination"] }
1414
libbpf-rs = "=0.26.0-beta.1"
1515
libc = "0.2.175"
1616
scx_utils = { path = "../../../rust/scx_utils", version = "1.0.22" }
17-
scx_rustland_core = { path = "../../../rust/scx_rustland_core", version = "2.3.7" }
17+
scx_rustland_core = { path = "../../../rust/scx_rustland_core", version = "2.4.7" }
1818

1919
[build-dependencies]
2020
scx_cargo = { path = "../../../rust/scx_cargo", version = "1.0.22" }
21-
scx_rustland_core = { path = "../../../rust/scx_rustland_core", version = "2.3.7" }
21+
scx_rustland_core = { path = "../../../rust/scx_rustland_core", version = "2.4.7" }
2222

2323
[features]
2424
enable_backtrace = []

scheds/rust/scx_rlfifo/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ impl<'a> Scheduler<'a> {
116116
false, // partial (false = include all tasks)
117117
false, // debug (false = debug mode off)
118118
true, // builtin_idle (true = allow BPF to use idle CPUs if available)
119+
SLICE_NS, // default time slice (for tasks automatically dispatched by the backend)
119120
"rlfifo", // name of the scx ops
120121
)?;
121122
Ok(Self { bpf })

scheds/rust/scx_rustland/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ serde = { version = "1.0.215", features = ["derive"] }
2020
scx_stats = { path = "../../../rust/scx_stats", version = "1.0.17" }
2121
scx_stats_derive = { path = "../../../rust/scx_stats/scx_stats_derive", version = "1.0.17" }
2222
scx_utils = { path = "../../../rust/scx_utils", version = "1.0.22" }
23-
scx_rustland_core = { path = "../../../rust/scx_rustland_core", version = "2.3.7" }
23+
scx_rustland_core = { path = "../../../rust/scx_rustland_core", version = "2.4.7" }
2424
simplelog = "0.12"
2525

2626
[build-dependencies]
2727
scx_cargo = { path = "../../../rust/scx_cargo", version = "1.0.22" }
28-
scx_rustland_core = { path = "../../../rust/scx_rustland_core", version = "2.3.7" }
28+
scx_rustland_core = { path = "../../../rust/scx_rustland_core", version = "2.4.7" }
2929

3030
[features]
3131
enable_backtrace = []

scheds/rust/scx_rustland/src/main.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ impl<'a> Scheduler<'a> {
163163
fn init(opts: &'a Opts, open_object: &'a mut MaybeUninit<OpenObject>) -> Result<Self> {
164164
let stats_server = StatsServer::new(stats::server_data()).launch()?;
165165

166+
let slice_ns = opts.slice_us * NSEC_PER_USEC;
167+
let slice_ns_min = opts.slice_us_min * NSEC_PER_USEC;
168+
166169
// Low-level BPF connector.
167170
let bpf = BpfScheduler::init(
168171
open_object,
@@ -171,6 +174,7 @@ impl<'a> Scheduler<'a> {
171174
opts.partial,
172175
opts.verbose,
173176
true, // Enable built-in idle CPU selection policy
177+
slice_ns_min,
174178
"rustland",
175179
)?;
176180

@@ -189,8 +193,8 @@ impl<'a> Scheduler<'a> {
189193
tasks: BTreeSet::new(),
190194
vruntime_now: 0,
191195
init_page_faults: 0,
192-
slice_ns: opts.slice_us * NSEC_PER_USEC,
193-
slice_ns_min: opts.slice_us_min * NSEC_PER_USEC,
196+
slice_ns,
197+
slice_ns_min,
194198
})
195199
}
196200

0 commit comments

Comments
 (0)