Skip to contentSkip to conversation

sched_ext: Provides a sysfs 'events' to expose core event counters

PATCH Superseded Changwoo Min 2 participants 5 messages Feb 10, 2025 – Feb 14, 2025 Scheduler

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sched_ext: Provides a sysfs 'events' to expose core event counters

Add a sysfs entry at /sys/kernel/sched_ext/events to expose core event counters through the files system interface. Each line of the file shows the event name and its counter value. In addition, the format of scx_dump_event() is adjusted as the event name gets longer.

---
 kernel/sched/ext.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)
kernel/sched/ext.c +26 -1
index b2378e29f45a..987b88b2f0ed 100644
@@ -1558,7 +1558,7 @@ static DEFINE_PER_CPU(struct scx_event_stats, event_stats_cpu);
  * @kind: a kind of event to dump
  */
 #define scx_dump_event(s, events, kind) do {					\
-	dump_line(&(s), "%30s: %16llu", #kind, (events)->kind);			\
+	dump_line(&(s), "%40s: %16llu", #kind, (events)->kind);			\
 } while (0)
 
 
@@ -4327,12 +4327,37 @@ static ssize_t scx_attr_enable_seq_show(struct kobject *kobj,
 }
 SCX_ATTR(enable_seq);
 
+#define scx_attr_event_show(buf, at, events, kind) ({				\
+	sysfs_emit_at(buf, at, "%40s: %16llu\n", #kind, (events)->kind);	\
+})
+
+static ssize_t scx_attr_events_show(struct kobject *kobj,
+				    struct kobj_attribute *ka, char *buf)
+{
+	struct scx_event_stats events;
+	int at = 0;
+
+	scx_bpf_events(&events, sizeof(events));
+	at += scx_attr_event_show(buf, at, &events, SCX_EV_SELECT_CPU_FALLBACK);
+	at += scx_attr_event_show(buf, at, &events, SCX_EV_DISPATCH_LOCAL_DSQ_OFFLINE);
+	at += scx_attr_event_show(buf, at, &events, SCX_EV_DISPATCH_KEEP_LAST);
+	at += scx_attr_event_show(buf, at, &events, SCX_EV_ENQ_SKIP_EXITING);
+	at += scx_attr_event_show(buf, at, &events, SCX_EV_ENQ_SKIP_MIGRATION_DISABLED);
+	at += scx_attr_event_show(buf, at, &events, SCX_EV_ENQ_SLICE_DFL);
+	at += scx_attr_event_show(buf, at, &events, SCX_EV_BYPASS_DURATION);
+	at += scx_attr_event_show(buf, at, &events, SCX_EV_BYPASS_DISPATCH);
+	at += scx_attr_event_show(buf, at, &events, SCX_EV_BYPASS_ACTIVATE);
+	return at;
+}
+SCX_ATTR(events);
+
 static struct attribute *scx_global_attrs[] = {
 	&scx_attr_state.attr,
 	&scx_attr_switch_all.attr,
 	&scx_attr_nr_rejected.attr,
 	&scx_attr_hotplug_seq.attr,
 	&scx_attr_enable_seq.attr,
+	&scx_attr_events.attr,
 	NULL,
 };
 
Signature · 1 line
2.48.1
#1 lore raw

Hello,

On Mon, Feb 10, 2025 at 11:36:43PM +0900, Changwoo Min wrote:
...

kernel/sched/ext.c static ssize_t scx_attr_enable_seq_show(struct kobject *kobj, · line 4332

Quoted 3 lines
kernel/sched/ext.c +3 -0
+#define scx_attr_event_show(buf, at, events, kind) ({				\
+	sysfs_emit_at(buf, at, "%40s: %16llu\n", #kind, (events)->kind);	\
+})

It's nice to format things in tabular forms but things under /sys lean more towards simpler formatting, so maybe just do "%s %16llu\n"?

kernel/sched/ext.c static ssize_t scx_attr_enable_seq_show(struct kobject *kobj, · line 4360

Quoted 7 lines

static struct attribute *scx_global_attrs[] = {

kernel/sched/ext.c +1 -0
 	&scx_attr_state.attr,
 	&scx_attr_switch_all.attr,
 	&scx_attr_nr_rejected.attr,
 	&scx_attr_hotplug_seq.attr,
 	&scx_attr_enable_seq.attr,
+	&scx_attr_events.attr,

This probably should belong to the root/ subdir as we'd probably want to keep the event counter separate per scheduler instance in the multi-scheduler future.

Thanks.

Signature · 1 line
tejun
#2 lore raw

Hello,

Thank you for the review!

Quoted 10 lines · Tejun Heo

Hello,

On Mon, Feb 10, 2025 at 11:36:43PM +0900, Changwoo Min wrote:
...

kernel/sched/ext.c static ssize_t scx_attr_enable_seq_show(struct kobject *kobj, · line 4332

Quoted 3 lines
kernel/sched/ext.c +3 -0
+#define scx_attr_event_show(buf, at, events, kind) ({				\
+	sysfs_emit_at(buf, at, "%40s: %16llu\n", #kind, (events)->kind);	\
+})

It's nice to format things in tabular forms but things under /sys lean more towards simpler formatting, so maybe just do "%s %16llu\n"?

Sure, I will change it to the simplest form, "%s %llu\n".

Quoted 12 lines

kernel/sched/ext.c static ssize_t scx_attr_enable_seq_show(struct kobject *kobj, · line 4360

Quoted 8 lines
  static struct attribute *scx_global_attrs[] = {
  	&scx_attr_state.attr,
  	&scx_attr_switch_all.attr,
  	&scx_attr_nr_rejected.attr,
  	&scx_attr_hotplug_seq.attr,
  	&scx_attr_enable_seq.attr,
kernel/sched/ext.c +1 -0
+	&scx_attr_events.attr,

This probably should belong to the root/ subdir as we'd probably want to keep the event counter separate per scheduler instance in the multi-scheduler future.

I feel this is a bit contradictory to the need to access the core event counters even after an scx scheduler is unloaded. In the current implementation, root/ subdir appears and disappears when an scx scheduler is loaded and unloaded.

We may change the scx_ktype to something similar to scx_global_attr_group in order to keep root/ subdir. We then show an empty file for root/ops when no scx scheduler is loaded while keep the root/events file intact. I am not sure if this is what we want.

What do you think?

Regards,
Changwoo Min

#3 lore raw

Hello, sorry about the late reply.

Quoted 9 lines · Changwoo Min
Quoted 3 lines

This probably should belong to the root/ subdir as we'd probably want to keep the event counter separate per scheduler instance in the multi-scheduler future.

I feel this is a bit contradictory to the need to access the core event counters even after an scx scheduler is unloaded. In the current implementation, root/ subdir appears and disappears when an scx scheduler is loaded and unloaded.

Quoted 7 lines

We may change the scx_ktype to something similar to scx_global_attr_group in order to keep root/ subdir. We then show an empty file for root/ops when no scx scheduler is loaded while keep the root/events file intact. I am not sure if this is what we want.

What do you think?

Hmm... I don't think we can keep the directory for counters of schedulers that have been unloaded. Looks like the right thing to do is giving up on the idea of being able to access the counters after the scheduler is unloaded. The counters are dumped on error exits, so hopefully this isn't too big a loss. What do you think?

Thanks.

Signature · 1 line
tejun
#4 lore raw

Hello Tejun,

Thank you for the review!

Quoted 18 lines · Tejun Heo

Hello, sorry about the late reply.

Quoted 15 lines · Changwoo Min
Quoted 3 lines

This probably should belong to the root/ subdir as we'd probably want to keep the event counter separate per scheduler instance in the multi-scheduler future.

I feel this is a bit contradictory to the need to access the core event counters even after an scx scheduler is unloaded. In the current implementation, root/ subdir appears and disappears when an scx scheduler is loaded and unloaded.

We may change the scx_ktype to something similar to scx_global_attr_group in order to keep root/ subdir. We then show an empty file for root/ops when no scx scheduler is loaded while keep the root/events file intact. I am not sure if this is what we want.

Quoted 7 lines
Quoted 1 line

What do you think?

Hmm... I don't think we can keep the directory for counters of schedulers that have been unloaded. Looks like the right thing to do is giving up on the idea of being able to access the counters after the scheduler is unloaded. The counters are dumped on error exits, so hopefully this isn't too big a loss. What do you think?

Yes, dumping the event counters is a part of scx_dump_state(). I agree. That's a reasonable choice. I will move 'events' under the root/ subdir and send out a new version.

Regards,
Changwoo Min