plugin/sched_event: add cobalt_switch_context event and corresponding action
RFC PATCH 1/1 plugin/sched_event: add cobalt_switch_context event and corresponding action
this patch is for kernelshark to fix issue "visualize task switches correctly in Kernelshark (color in CPU bar is not updating on cobalt_switch_context)" described in https://gitlab.com/Xenomai/xenomai-hacker-space/-/issues/33
For Xenomai cobalt enabled system, cobalt_switch_context means that there is context switch in companion core , which we may need to do special treatment and take correct action as main kenrel sched_switch.
src/plugins/sched_events.c +39 -0
@@ -110,6 +110,21 @@ static bool plugin_sched_init_context(struct kshark_data_stream *stream, plugin_ctx->sched_switch_prev_state_field =tep_find_field (event,"prev_state" ); + event =tep_find_event_by_name (plugin_ctx->tep, +"cobalt_core" ,"cobalt_switch_context" ); + +if (!event) +return false; + + plugin_ctx->cobalt_switch_event = event; + plugin_ctx->cobalt_switch_next_field = +tep_find_any_field (event,"next_pid" ); + + plugin_ctx->cobalt_switch_prev_state_field = +tep_find_field (event,"prev_state" ); + + + wakeup_found =define_wakeup_event (plugin_ctx->tep, &plugin_ctx->sched_waking_event);
@@ -159,6 +174,26 @@ static void plugin_sched_swith_action(struct kshark_data_stream *stream, } } +static void plugin_cobalt_swith_action (struct kshark_data_stream *stream, +void *rec,struct kshark_entry *entry) +{ +struct tep_record *record = (struct tep_record *) rec; +struct plugin_sched_context *plugin_ctx; +unsigned long long next_pid, prev_state; +ks_num_field_t ks_field; +int ret; + + plugin_ctx =__get_context (stream->stream_id); +if (!plugin_ctx) +return ; + + ret =tep_read_number_field (plugin_ctx->cobalt_switch_next_field, + record->data, &next_pid); + +if (ret ==0 && next_pid >=0 ) + entry->pid = next_pid; +} +static void plugin_sched_wakeup_action (struct kshark_data_stream *stream,void *rec,struct kshark_entry *entry) {
@@ -193,6 +228,10 @@ int KSHARK_PLOT_PLUGIN_INITIALIZER(struct kshark_data_stream *stream) plugin_ctx->sched_switch_event->id, plugin_sched_swith_action); +kshark_register_event_handler (stream, + plugin_ctx->cobalt_switch_event->id, + plugin_cobalt_swith_action); +if (plugin_ctx->sched_waking_event) { kshark_register_event_handler(stream, plugin_ctx->sched_waking_event->id,
src/plugins/sched_events.h +9 -0
@@ -37,6 +37,15 @@ struct plugin_sched_context {/** Pointer to the sched_switch_prev_state_field format descriptor. */ struct tep_format_field *sched_switch_prev_state_field; +/** Pointer to the cobalt_switch_event object. */ +struct tep_event *cobalt_switch_event; + +/** Pointer to the cobalt_switch_next_field format descriptor. */ +struct tep_format_field *cobalt_switch_next_field; + +/** Pointer to the cobalt_switch_prev_state_field format descriptor. */ +struct tep_format_field *cobalt_switch_prev_state_field; +/** Pointer to the sched_waking_event object. */ struct tep_event *sched_waking_event;
Signature · 1 line
2.17.1
Quoted 38 lines · Hongzhan Chen
this patch is for kernelshark to fix issue "visualize task switches correctly in Kernelshark (color in CPU bar is not updating on
cobalt_switch_context)" described in https://gitlab.com/Xenomai/xenomai-hacker-space/-/issues/33For Xenomai cobalt enabled system,
cobalt_switch_contextmeans that there is context switch in companion core , which we may need to do special treatment and take correct action as main kenrelsched_switch.Signed-off-by Hongzhan Chen <[email protected]>src/plugins/sched_events.c +15
-0@@ -110,6 +110,21 @@ static bool plugin_sched_init_context(struct kshark_data_stream *stream, plugin_ctx->sched_switch_prev_state_field =tep_find_field (event,"prev_state" ); + event =tep_find_event_by_name (plugin_ctx->tep, +"cobalt_core" ,"cobalt_switch_context" ); + +if (!event) +return false; + + plugin_ctx->cobalt_switch_event = event; + plugin_ctx->cobalt_switch_next_field = +tep_find_any_field (event,"next_pid" ); + + plugin_ctx->cobalt_switch_prev_state_field = +tep_find_field (event,"prev_state" ); + + + wakeup_found =define_wakeup_event (plugin_ctx->tep, &plugin_ctx->sched_waking_event);
src/plugins/sched_events.c static void plugin_sched_swith_action(struct kshark_data_stream *stream, · line 177
Quoted 4 lines
src/plugins/sched_events.c +1
-0@@ -159,6 +174,26 @@ static void plugin_sched_swith_action(struct kshark_data_stream *stream, } } +static void plugin_cobalt_swith_action(struct kshark_data_stream *stream,
typo: switch
Quoted 44 lines
src/plugins/sched_events.c +23
-0+ void *rec, struct kshark_entry *entry) +{ + struct tep_record *record = (struct tep_record *) rec; +struct plugin_sched_context *plugin_ctx; +unsigned long long next_pid, prev_state; +ks_num_field_t ks_field; +int ret; + + plugin_ctx =__get_context (stream->stream_id); +if (!plugin_ctx) +return ; + + ret =tep_read_number_field (plugin_ctx->cobalt_switch_next_field, + record->data, &next_pid); + +if (ret ==0 && next_pid >=0 ) + entry->pid = next_pid; +} +static void plugin_sched_wakeup_action (struct kshark_data_stream *stream,void *rec,struct kshark_entry *entry) {@@ -193,6 +228,10 @@ int KSHARK_PLOT_PLUGIN_INITIALIZER(struct kshark_data_stream *stream) plugin_ctx->sched_switch_event->id, plugin_sched_swith_action); +kshark_register_event_handler (stream, + plugin_ctx->cobalt_switch_event->id, + plugin_cobalt_swith_action); +if (plugin_ctx->sched_waking_event) { kshark_register_event_handler(stream, plugin_ctx->sched_waking_event->id,src/plugins/sched_events.h +2
-0@@ -37,6 +37,15 @@ struct plugin_sched_context {/** Pointer to the sched_switch_prev_state_field format descriptor. */ struct tep_format_field *sched_switch_prev_state_field; +/** Pointer to the cobalt_switch_event object. */ +struct tep_event *cobalt_switch_event;
src/plugins/sched_events.h struct plugin_sched_context { · line 51
Quoted 10 lines
src/plugins/sched_events.h +7
-0+ +/** Pointer to the cobalt_switch_next_field format descriptor. */ +struct tep_format_field *cobalt_switch_next_field; + +/** Pointer to the cobalt_switch_prev_state_field format descriptor. */ +struct tep_format_field *cobalt_switch_prev_state_field; +/** Pointer to the sched_waking_event object. */ struct tep_event *sched_waking_event;
Yep, that goes the same way as I used to go in the past with kernelshark 1.x. Just recalled that I published it:
https://git.kiszka.org/?p=trace-cmd.git;a=commitdiff;h=92b0aaf7eaf7fa4bbc8edde1ffe8206a35214565
However: This is likely not maintainable. We need a real plugin that does not affect the main code and can be handled out-of-tree, or we need to sell such an extension to upstream.
We should sync on that topic again with the kernelshark community and specifically Steven Rostedt. I was discussing our needs a long time ago with him, but I unfortunately forgot the details of the outcome.
Thanks,
Jan
Signature · 2 lines
Siemens AG, T RDA IOT Corporate Competence Center Embedded Linux