compat: Drop support for missing sched_ext_ops.hotplug_seq

In preparation of upstreaming, let's set the min version requirement at the
released v6.9 kernels. Drop support for missing sched_ext_ops.hotplug_seq.
The open helper macros now check the existence of the field and abort if
missing.
This commit is contained in:
Tejun Heo 2024-06-16 06:32:09 -10:00
parent dde2942125
commit 046bdfd5e0
2 changed files with 19 additions and 21 deletions

View File

@ -162,6 +162,9 @@ macro_rules! unwrap_or_break {
}
pub fn check_min_requirements() -> Result<()> {
if let Ok(false) | Err(_) = struct_has_field("sched_ext_ops", "hotplug_seq") {
bail!("sched_ext_ops.hotplug_seq missing, kernel too old?");
}
if let Ok(false) | Err(_) = ksym_exists("scx_bpf_cpuperf_cap") {
bail!("scx_bpf_cpuperf_*() missing, kernel too old?");
}
@ -204,25 +207,21 @@ macro_rules! scx_ops_open {
};
let ops = skel.struct_ops.[<$ops _mut>]();
let has_field = scx_utils::unwrap_or_break!(
scx_utils::compat::struct_has_field("sched_ext_ops", "hotplug_seq"), 'block);
let path = std::path::Path::new("/sys/kernel/sched_ext/hotplug_seq");
if has_field {
let path = std::path::Path::new("/sys/kernel/sched_ext/hotplug_seq");
let val = match std::fs::read_to_string(&path) {
Ok(val) => val,
Err(_) => {
break 'block Err(anyhow::anyhow!("Failed to open or read file {:?}", path));
}
};
let val = match std::fs::read_to_string(&path) {
Ok(val) => val,
Err(_) => {
break 'block Err(anyhow::anyhow!("Failed to open or read file {:?}", path));
}
};
ops.hotplug_seq = match val.trim().parse::<u64>() {
Ok(parsed) => parsed,
Err(_) => {
break 'block Err(anyhow::anyhow!("Failed to parse hotplug seq {}", val));
}
};
}
ops.hotplug_seq = match val.trim().parse::<u64>() {
Ok(parsed) => parsed,
Err(_) => {
break 'block Err(anyhow::anyhow!("Failed to parse hotplug seq {}", val));
}
};
let result : Result<OpenBpfSkel<'_>, anyhow::Error> = Ok(skel);
result

View File

@ -146,11 +146,12 @@ static inline long scx_hotplug_seq(void)
* - ops.tick(): Ignored on older kernels with a warning.
* - ops.dump*(): Ignored on older kernels with a warning.
* - ops.exit_dump_len: Cleared to zero on older kernels with a warning.
* - ops.hotplug_seq: Ignored on older kernels.
*/
#define SCX_OPS_OPEN(__ops_name, __scx_name) ({ \
struct __scx_name *__skel; \
\
SCX_BUG_ON(!__COMPAT_struct_has_field("sched_ext_ops", "hotplug_seq"), \
"sched_ext_ops.hotplug_seq missing, kernel too old?"); \
SCX_BUG_ON(!__COMPAT_has_ksym("scx_bpf_cpuperf_cap"), \
"scx_bpf_cpuperf_*() missing, kernel too old?"); \
SCX_BUG_ON(!__COMPAT_has_ksym("scx_bpf_nr_cpu_ids"), \
@ -166,9 +167,7 @@ static inline long scx_hotplug_seq(void)
\
__skel = __scx_name##__open(); \
SCX_BUG_ON(!__skel, "Could not open " #__scx_name); \
\
if (__COMPAT_struct_has_field("sched_ext_ops", "hotplug_seq")) \
__skel->struct_ops.__ops_name->hotplug_seq = scx_hotplug_seq(); \
__skel->struct_ops.__ops_name->hotplug_seq = scx_hotplug_seq(); \
__skel; \
})