Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
tools/sched_ext: Sync from the scx repo (b6ebdc635acf450e9c2e71717500…
Browse files Browse the repository at this point in the history
…556cd3cf67a1)
  • Loading branch information
htejun committed Jun 17, 2024
1 parent d76f33f commit e1f6f96
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 144 deletions.
7 changes: 5 additions & 2 deletions tools/sched_ext/include/scx/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ typedef int64_t s64;

#define SCX_BUG(__fmt, ...) \
do { \
fprintf(stderr, "%s:%d [scx panic]: %s\n", __FILE__, __LINE__, \
strerror(errno)); \
fprintf(stderr, "[SCX_BUG] %s:%d", __FILE__, __LINE__); \
if (errno) \
fprintf(stderr, " (%s)\n", strerror(errno)); \
else \
fprintf(stderr, "\n"); \
fprintf(stderr, __fmt __VA_OPT__(,) __VA_ARGS__); \
fprintf(stderr, "\n"); \
\
Expand Down
77 changes: 0 additions & 77 deletions tools/sched_ext/include/scx/compat.bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,83 +15,6 @@
__ret; \
})

/*
* %SCX_KICK_IDLE is a later addition. To support both before and after, use
* %__COMPAT_SCX_KICK_IDLE which becomes 0 on kernels which don't support it.
* Users can use %SCX_KICK_IDLE directly in the future.
*/
#define __COMPAT_SCX_KICK_IDLE \
__COMPAT_ENUM_OR_ZERO(enum scx_kick_flags, SCX_KICK_IDLE)

/*
* scx_switch_all() was replaced by %SCX_OPS_SWITCH_PARTIAL. See
* %__COMPAT_SCX_OPS_SWITCH_PARTIAL in compat.h. This can be dropped in the
* future.
*/
void scx_bpf_switch_all(void) __ksym __weak;

static inline void __COMPAT_scx_bpf_switch_all(void)
{
if (!bpf_core_enum_value_exists(enum scx_ops_flags, SCX_OPS_SWITCH_PARTIAL))
scx_bpf_switch_all();
}

/*
* scx_bpf_exit() is a new addition. Fall back to scx_bpf_error() if
* unavailable. Users can use scx_bpf_exit() directly in the future.
*/
#define __COMPAT_scx_bpf_exit(code, fmt, args...) \
({ \
if (bpf_ksym_exists(scx_bpf_exit_bstr)) \
scx_bpf_exit((code), fmt, ##args); \
else \
scx_bpf_error(fmt, ##args); \
})

/*
* scx_bpf_dump() is a new addition. Ignore if unavailable. Users can use
* scx_bpf_dump() directly in the future.
*/
#define __COMPAT_scx_bpf_dump(fmt, args...) \
({ \
if (bpf_ksym_exists(scx_bpf_dump_bstr)) \
scx_bpf_dump(fmt, ##args); \
})

/*
* scx_bpf_nr_cpu_ids(), scx_bpf_get_possible/online_cpumask() are new. No good
* way to noop these kfuncs. Provide a test macro. Users can assume existence in
* the future.
*/
#define __COMPAT_HAS_CPUMASKS \
bpf_ksym_exists(scx_bpf_nr_cpu_ids)

/*
* cpuperf is new. The followings become noop on older kernels. Callers can be
* updated to call cpuperf kfuncs directly in the future.
*/
static inline u32 __COMPAT_scx_bpf_cpuperf_cap(s32 cpu)
{
if (bpf_ksym_exists(scx_bpf_cpuperf_cap))
return scx_bpf_cpuperf_cap(cpu);
else
return 1024;
}

static inline u32 __COMPAT_scx_bpf_cpuperf_cur(s32 cpu)
{
if (bpf_ksym_exists(scx_bpf_cpuperf_cur))
return scx_bpf_cpuperf_cur(cpu);
else
return 1024;
}

static inline void __COMPAT_scx_bpf_cpuperf_set(s32 cpu, u32 perf)
{
if (bpf_ksym_exists(scx_bpf_cpuperf_set))
return scx_bpf_cpuperf_set(cpu, perf);
}

/*
* Iteration and scx_bpf_consume_task() are new. The following become noop on
* older kernels. The users can switch to bpf_for_each(scx_dsq) and directly
Expand Down
48 changes: 7 additions & 41 deletions tools/sched_ext/include/scx/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,23 +106,9 @@ static inline bool __COMPAT_struct_has_field(const char *type, const char *field
return false;
}

/*
* An ops flag, %SCX_OPS_SWITCH_PARTIAL, replaced scx_bpf_switch_all() which had
* to be called from ops.init(). To support both before and after, use both
* %__COMPAT_SCX_OPS_SWITCH_PARTIAL and %__COMPAT_scx_bpf_switch_all() defined
* in compat.bpf.h. Users can switch to directly using %SCX_OPS_SWITCH_PARTIAL
* in the future.
*/
#define __COMPAT_SCX_OPS_SWITCH_PARTIAL \
#define SCX_OPS_SWITCH_PARTIAL \
__COMPAT_ENUM_OR_ZERO("scx_ops_flags", "SCX_OPS_SWITCH_PARTIAL")

/*
* scx_bpf_nr_cpu_ids(), scx_bpf_get_possible/online_cpumask() are new. Users
* will be able to assume existence in the future.
*/
#define __COMPAT_HAS_CPUMASKS \
__COMPAT_has_ksym("scx_bpf_nr_cpu_ids")

/*
* DSQ iterator is new. Users will be able to assume existence in the future.
*/
Expand Down Expand Up @@ -157,43 +143,23 @@ static inline long scx_hotplug_seq(void)
* and attach it, backward compatibility is automatically maintained where
* reasonable.
*
* - 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.
* ec7e3b0463e1 ("implement-ops") in https://github.com/sched-ext/sched_ext is
* the current minimum required kernel version.
*/
#define SCX_OPS_OPEN(__ops_name, __scx_name) ({ \
struct __scx_name *__skel; \
\
SCX_BUG_ON(!__COMPAT_struct_has_field("sched_ext_ops", "dump"), \
"sched_ext_ops.dump() missing, kernel too old?"); \
\
__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; \
})

#define SCX_OPS_LOAD(__skel, __ops_name, __scx_name, __uei_name) ({ \
UEI_SET_SIZE(__skel, __ops_name, __uei_name); \
if (!__COMPAT_struct_has_field("sched_ext_ops", "exit_dump_len") && \
(__skel)->struct_ops.__ops_name->exit_dump_len) { \
fprintf(stderr, "WARNING: kernel doesn't support setting exit dump len\n"); \
(__skel)->struct_ops.__ops_name->exit_dump_len = 0; \
} \
if (!__COMPAT_struct_has_field("sched_ext_ops", "tick") && \
(__skel)->struct_ops.__ops_name->tick) { \
fprintf(stderr, "WARNING: kernel doesn't support ops.tick()\n"); \
(__skel)->struct_ops.__ops_name->tick = NULL; \
} \
if (!__COMPAT_struct_has_field("sched_ext_ops", "dump") && \
((__skel)->struct_ops.__ops_name->dump || \
(__skel)->struct_ops.__ops_name->dump_cpu || \
(__skel)->struct_ops.__ops_name->dump_task)) { \
fprintf(stderr, "WARNING: kernel doesn't support ops.dump*()\n"); \
(__skel)->struct_ops.__ops_name->dump = NULL; \
(__skel)->struct_ops.__ops_name->dump_cpu = NULL; \
(__skel)->struct_ops.__ops_name->dump_task = NULL; \
} \
SCX_BUG_ON(__scx_name##__load((__skel)), "Failed to load skel"); \
})

Expand Down
3 changes: 1 addition & 2 deletions tools/sched_ext/scx_central.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ static bool dispatch_to_cpu(s32 cpu)
scx_bpf_dispatch(p, SCX_DSQ_LOCAL_ON | cpu, SCX_SLICE_INF, 0);

if (cpu != central_cpu)
scx_bpf_kick_cpu(cpu, __COMPAT_SCX_KICK_IDLE);
scx_bpf_kick_cpu(cpu, SCX_KICK_IDLE);

bpf_task_release(p);
return true;
Expand Down Expand Up @@ -305,7 +305,6 @@ int BPF_STRUCT_OPS_SLEEPABLE(central_init)
struct bpf_timer *timer;
int ret;

__COMPAT_scx_bpf_switch_all();
ret = scx_bpf_create_dsq(FALLBACK_DSQ_ID, -1);
if (ret)
return ret;
Expand Down
28 changes: 9 additions & 19 deletions tools/sched_ext/scx_qmap.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ const volatile bool print_shared_dsq;
const volatile char exp_prefix[17];
const volatile s32 disallow_tgid;
const volatile bool suppress_dump;
const volatile bool switch_partial;

u32 test_error_cnt;

Expand Down Expand Up @@ -222,7 +221,7 @@ void BPF_STRUCT_OPS(qmap_enqueue, struct task_struct *p, u64 enq_flags)
scx_bpf_dispatch(p, SHARED_DSQ, 0, enq_flags);
cpu = scx_bpf_pick_idle_cpu(p->cpus_ptr, 0);
if (cpu >= 0)
scx_bpf_kick_cpu(cpu, __COMPAT_SCX_KICK_IDLE);
scx_bpf_kick_cpu(cpu, SCX_KICK_IDLE);
return;
}

Expand Down Expand Up @@ -476,13 +475,13 @@ void BPF_STRUCT_OPS(qmap_dump, struct scx_dump_ctx *dctx)
if (!(fifo = bpf_map_lookup_elem(&queue_arr, &i)))
return;

__COMPAT_scx_bpf_dump("QMAP FIFO[%d]:", i);
scx_bpf_dump("QMAP FIFO[%d]:", i);
bpf_repeat(4096) {
if (bpf_map_pop_elem(fifo, &pid))
break;
__COMPAT_scx_bpf_dump(" %d", pid);
scx_bpf_dump(" %d", pid);
}
__COMPAT_scx_bpf_dump("\n");
scx_bpf_dump("\n");
}
}

Expand All @@ -496,9 +495,9 @@ void BPF_STRUCT_OPS(qmap_dump_cpu, struct scx_dump_ctx *dctx, s32 cpu, bool idle
if (!(cpuc = bpf_map_lookup_percpu_elem(&cpu_ctx_stor, &zero, cpu)))
return;

__COMPAT_scx_bpf_dump("QMAP: dsp_idx=%llu dsp_cnt=%llu avg_weight=%u cpuperf_target=%u",
cpuc->dsp_idx, cpuc->dsp_cnt, cpuc->avg_weight,
cpuc->cpuperf_target);
scx_bpf_dump("QMAP: dsp_idx=%llu dsp_cnt=%llu avg_weight=%u cpuperf_target=%u",
cpuc->dsp_idx, cpuc->dsp_cnt, cpuc->avg_weight,
cpuc->cpuperf_target);
}

void BPF_STRUCT_OPS(qmap_dump_task, struct scx_dump_ctx *dctx, struct task_struct *p)
Expand All @@ -510,8 +509,8 @@ void BPF_STRUCT_OPS(qmap_dump_task, struct scx_dump_ctx *dctx, struct task_struc
if (!(taskc = bpf_task_storage_get(&task_ctx_stor, p, 0, 0)))
return;

__COMPAT_scx_bpf_dump("QMAP: force_local=%d core_sched_seq=%llu",
taskc->force_local, taskc->core_sched_seq);
scx_bpf_dump("QMAP: force_local=%d core_sched_seq=%llu",
taskc->force_local, taskc->core_sched_seq);
}

/*
Expand All @@ -525,9 +524,6 @@ static void print_cpus(void)
char buf[128] = "", *p;
int idx;

if (!__COMPAT_HAS_CPUMASKS)
return;

possible = scx_bpf_get_possible_cpumask();
online = scx_bpf_get_online_cpumask();

Expand Down Expand Up @@ -593,9 +589,6 @@ static void monitor_cpuperf(void)
const struct cpumask *online;
int i, nr_online_cpus = 0;

if (!__COMPAT_HAS_CPUMASKS)
return;

nr_cpu_ids = scx_bpf_nr_cpu_ids();
online = scx_bpf_get_online_cpumask();

Expand Down Expand Up @@ -683,9 +676,6 @@ s32 BPF_STRUCT_OPS_SLEEPABLE(qmap_init)
struct bpf_timer *timer;
s32 ret;

if (!switch_partial)
__COMPAT_scx_bpf_switch_all();

print_cpus();

ret = scx_bpf_create_dsq(SHARED_DSQ, -1);
Expand Down
3 changes: 1 addition & 2 deletions tools/sched_ext/scx_qmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ int main(int argc, char **argv)
skel->rodata->suppress_dump = true;
break;
case 'p':
skel->rodata->switch_partial = true;
skel->struct_ops.qmap_ops->flags |= __COMPAT_SCX_OPS_SWITCH_PARTIAL;
skel->struct_ops.qmap_ops->flags |= SCX_OPS_SWITCH_PARTIAL;
break;
case 'v':
verbose = true;
Expand Down
1 change: 0 additions & 1 deletion tools/sched_ext/scx_simple.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ void BPF_STRUCT_OPS(simple_enable, struct task_struct *p)

s32 BPF_STRUCT_OPS_SLEEPABLE(simple_init)
{
__COMPAT_scx_bpf_switch_all();
return scx_bpf_create_dsq(SHARED_DSQ, -1);
}

Expand Down

0 comments on commit e1f6f96

Please sign in to comment.