kernel-shark: add plugin for handling xenomai cobalt context switch event
RFC PATCH v2 1/1 kernel-shark: add plugin for handling xenomai cobalt context switch event
For Xenomai-cobalt enabled system, cobalt_switch_context means that there is context switch in companion core(realtime core), which we may need to do special treatment and take correct action as main kernel sched_switch. We need to update cpu bar regarding cobalt_switch_context event to correct color as switching-in task.
src/libkshark-tepdata.c +1 -0
@@ -1208,6 +1208,7 @@ static void kshark_tep_init_methods(struct kshark_generic_stream_interface *inte/** A list of built in default plugins for FTRACE (trace-cmd) data. */ const char *tep_plugin_names[] = {"sched_events" , +"xenomai_cobalt_switch_events" ,"missed_events" ,"kvm_combo" , };
src/plugins/CMakeLists.txt +4 -0
@@ -44,6 +44,10 @@ if (Qt5Widgets_FOUND AND TT_FONT_FILE) SOURCE sched_events.c SchedEvents.cpp) list(APPEND PLUGIN_LIST "sched_events") + BUILD_GUI_PLUGIN(NAME xenomai_cobalt_switch_events + SOURCE xenomai_cobalt_switch_events.c) + list(APPEND PLUGIN_LIST "xenomai_cobalt_switch_events") + BUILD_GUI_PLUGIN(NAME event_field_plot MOC EventFieldDialog.hpp SOURCE event_field_plot.c EventFieldDialog.cpp EventFieldPlot.cpp)
src/plugins/xenomai_cobalt_switch_events.c new file +116 -0
116 lines not on this page · raw message
src/plugins/xenomai_cobalt_switch_events.h new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
2.17.1
Quoted 199 lines · Hongzhan Chen
For Xenomai-cobalt enabled system,
cobalt_switch_contextmeans that there is context switch in companion core(realtime core), which we may need to do special treatment and take correct action as main kernelsched_switch. We need to update cpu bar regardingcobalt_switch_contextevent to correct color as switching-in task.Signed-off-by Hongzhan Chen <[email protected]>src/libkshark-tepdata.c +1
-0@@ -1208,6 +1208,7 @@ static void kshark_tep_init_methods(struct kshark_generic_stream_interface *inte/** A list of built in default plugins for FTRACE (trace-cmd) data. */ const char *tep_plugin_names[] = {"sched_events" , +"xenomai_cobalt_switch_events" ,"missed_events" ,"kvm_combo" , };src/plugins/CMakeLists.txt +4
-0@@ -44,6 +44,10 @@ if (Qt5Widgets_FOUND AND TT_FONT_FILE) SOURCE sched_events.c SchedEvents.cpp) list(APPEND PLUGIN_LIST "sched_events") + BUILD_GUI_PLUGIN(NAME xenomai_cobalt_switch_events + SOURCE xenomai_cobalt_switch_events.c) + list(APPEND PLUGIN_LIST "xenomai_cobalt_switch_events") + BUILD_GUI_PLUGIN(NAME event_field_plot MOC EventFieldDialog.hpp SOURCE event_field_plot.c EventFieldDialog.cpp EventFieldPlot.cpp)src/plugins/xenomai_cobalt_switch_events.c new file +116
-0@@ -0,0 +1,116 @@ +// SPDX-License-Identifier: LGPL-2.1 + +/* +* Copyright (C) 2021 Intel Inc, Hongzhan Chen <[email protected]> +*/ + +/** +* @file xenomai_cobalt_switch_events.c +* @brief handle xenomai cobalt switch context event +*/ + +// C +#include <stdlib.h> +#include <stdio.h> + +// trace-cmd +#include <trace-cmd.h> + +// KernelShark +#include "plugins/xenomai_cobalt_switch_events.h" +#include "libkshark-tepdata.h" + +/** Plugin context instance. */ + +static void cobalt_free_context (struct plugin_cobalt_context *plugin_ctx) +{ +return ; +} + +/** A general purpose macro is used to define plugin context. */ +KS_DEFINE_PLUGIN_CONTEXT(struct plugin_cobalt_context, cobalt_free_context); + +static bool plugin_cobalt_init_context (struct kshark_data_stream *stream, +struct plugin_cobalt_context *plugin_ctx) +{ +struct tep_event *event; + +if (!kshark_is_tep (stream)) +return false; + + plugin_ctx->tep =kshark_get_tep (stream); + + 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" ); + +return true; +} + +static void plugin_cobalt_switch_action (struct kshark_data_stream *stream, +void *rec,struct kshark_entry *entry) +{ +struct tep_record *record = (struct tep_record *) rec; +struct plugin_cobalt_context *plugin_ctx; +unsigned long long next_pid; +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; +} + +/** Load this plugin. */ +int KSHARK_PLOT_PLUGIN_INITIALIZER (struct kshark_data_stream *stream) +{ +struct plugin_cobalt_context *plugin_ctx; + + plugin_ctx =__init (stream->stream_id); +if (!plugin_ctx || !plugin_cobalt_init_context (stream, plugin_ctx)) { +__close (stream->stream_id); +return 0 ; + } + +if (plugin_ctx->cobalt_switch_event) { +kshark_register_event_handler (stream, + plugin_ctx->cobalt_switch_event->id, + plugin_cobalt_switch_action); + } + +return 1 ; +} + +/** Unload this plugin. */ +int KSHARK_PLOT_PLUGIN_DEINITIALIZER (struct kshark_data_stream *stream) +{ +struct plugin_cobalt_context *plugin_ctx =__get_context (stream->stream_id); +int ret =0 ; + +if (plugin_ctx) { +if (plugin_ctx->cobalt_switch_event) { +kshark_unregister_event_handler (stream, + plugin_ctx->cobalt_switch_event->id, + plugin_cobalt_switch_action); + } + + ret =1 ; + } + +__close (stream->stream_id); + +return ret; +}src/plugins/xenomai_cobalt_switch_events.h new file +35
-0@@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: LGPL-2.1 */ + +/* +* Copyright (C) 2021 Intel Inc, Hongzhan Chen<[email protected]> +*/ + +/** +* @file xenomai_cobalt_switch_events.h +* @brief Plugin for xenomai cobalt switch context event +*/ + +#ifndef _KS_PLUGIN_SHED_H +#define _KS_PLUGIN_SHED_H + +// KernelShark +#include "libkshark.h" +#include "libkshark-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** Structure representing a plugin-specific context. */ +struct plugin_cobalt_context { + /** Page event used to parse the page. */ + struct tep_handle *tep; + + /** 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;
src/plugins/xenomai_cobalt_switch_events.h line 45
Quoted 10 lines
src/plugins/xenomai_cobalt_switch_events.h new file +10
-0+ +}; + +KS_DECLARE_PLUGIN_CONTEXT_METHODS(struct plugin_cobalt_context) + +#ifdef __cplusplus +} +#endif + +#endif
Ah, that looks way more self-contained!
But plugins have to be built in-tree of Kernelshark? Or does the new architecture allow to build them against a "kernelshark-devel" package as well?
Jan
Signature · 2 lines
Siemens AG, T RDA IOT Corporate Competence Center Embedded Linux
Quoted 221 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Monday, December 13, 2021 3:50 PM
To: Chen, Hongzhan <[email protected]>; [email protected]
Subject: Re: [RFC PATCH V2] kernel-shark: add plugin for handling xenomai cobalt context switch eventQuoted 199 lines · Hongzhan Chen
For Xenomai-cobalt enabled system,
cobalt_switch_contextmeans that there is context switch in companion core(realtime core), which we may need to do special treatment and take correct action as main kernelsched_switch. We need to update cpu bar regardingcobalt_switch_contextevent to correct color as switching-in task.Signed-off-by Hongzhan Chen <[email protected]>src/libkshark-tepdata.c +1
-0@@ -1208,6 +1208,7 @@ static void kshark_tep_init_methods(struct kshark_generic_stream_interface *inte/** A list of built in default plugins for FTRACE (trace-cmd) data. */ const char *tep_plugin_names[] = {"sched_events" , +"xenomai_cobalt_switch_events" ,"missed_events" ,"kvm_combo" , };src/plugins/CMakeLists.txt +4
-0@@ -44,6 +44,10 @@ if (Qt5Widgets_FOUND AND TT_FONT_FILE) SOURCE sched_events.c SchedEvents.cpp) list(APPEND PLUGIN_LIST "sched_events") + BUILD_GUI_PLUGIN(NAME xenomai_cobalt_switch_events + SOURCE xenomai_cobalt_switch_events.c) + list(APPEND PLUGIN_LIST "xenomai_cobalt_switch_events") + BUILD_GUI_PLUGIN(NAME event_field_plot MOC EventFieldDialog.hpp SOURCE event_field_plot.c EventFieldDialog.cpp EventFieldPlot.cpp)src/plugins/xenomai_cobalt_switch_events.c new file +116
-0@@ -0,0 +1,116 @@ +// SPDX-License-Identifier: LGPL-2.1 + +/* +* Copyright (C) 2021 Intel Inc, Hongzhan Chen <[email protected]> +*/ + +/** +* @file xenomai_cobalt_switch_events.c +* @brief handle xenomai cobalt switch context event +*/ + +// C +#include <stdlib.h> +#include <stdio.h> + +// trace-cmd +#include <trace-cmd.h> + +// KernelShark +#include "plugins/xenomai_cobalt_switch_events.h" +#include "libkshark-tepdata.h" + +/** Plugin context instance. */ + +static void cobalt_free_context (struct plugin_cobalt_context *plugin_ctx) +{ +return ; +} + +/** A general purpose macro is used to define plugin context. */ +KS_DEFINE_PLUGIN_CONTEXT(struct plugin_cobalt_context, cobalt_free_context); + +static bool plugin_cobalt_init_context (struct kshark_data_stream *stream, +struct plugin_cobalt_context *plugin_ctx) +{ +struct tep_event *event; + +if (!kshark_is_tep (stream)) +return false; + + plugin_ctx->tep =kshark_get_tep (stream); + + 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" ); + +return true; +} + +static void plugin_cobalt_switch_action (struct kshark_data_stream *stream, +void *rec,struct kshark_entry *entry) +{ +struct tep_record *record = (struct tep_record *) rec; +struct plugin_cobalt_context *plugin_ctx; +unsigned long long next_pid; +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; +} + +/** Load this plugin. */ +int KSHARK_PLOT_PLUGIN_INITIALIZER (struct kshark_data_stream *stream) +{ +struct plugin_cobalt_context *plugin_ctx; + + plugin_ctx =__init (stream->stream_id); +if (!plugin_ctx || !plugin_cobalt_init_context (stream, plugin_ctx)) { +__close (stream->stream_id); +return 0 ; + } + +if (plugin_ctx->cobalt_switch_event) { +kshark_register_event_handler (stream, + plugin_ctx->cobalt_switch_event->id, + plugin_cobalt_switch_action); + } + +return 1 ; +} + +/** Unload this plugin. */ +int KSHARK_PLOT_PLUGIN_DEINITIALIZER (struct kshark_data_stream *stream) +{ +struct plugin_cobalt_context *plugin_ctx =__get_context (stream->stream_id); +int ret =0 ; + +if (plugin_ctx) { +if (plugin_ctx->cobalt_switch_event) { +kshark_unregister_event_handler (stream, + plugin_ctx->cobalt_switch_event->id, + plugin_cobalt_switch_action); + } + + ret =1 ; + } + +__close (stream->stream_id); + +return ret; +}src/plugins/xenomai_cobalt_switch_events.h new file +35
-0@@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: LGPL-2.1 */ + +/* +* Copyright (C) 2021 Intel Inc, Hongzhan Chen<[email protected]> +*/ + +/** +* @file xenomai_cobalt_switch_events.h +* @brief Plugin for xenomai cobalt switch context event +*/ + +#ifndef _KS_PLUGIN_SHED_H +#define _KS_PLUGIN_SHED_H + +// KernelShark +#include "libkshark.h" +#include "libkshark-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** Structure representing a plugin-specific context. */ +struct plugin_cobalt_context { + /** Page event used to parse the page. */ + struct tep_handle *tep; + + /** 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;src/plugins/xenomai_cobalt_switch_events.h line 45
Quoted 10 lines
src/plugins/xenomai_cobalt_switch_events.h new file +10
-0+ +}; + +KS_DECLARE_PLUGIN_CONTEXT_METHODS(struct plugin_cobalt_context) + +#ifdef __cplusplus +} +#endif + +#endif Ah, that looks way more self-contained!
Quoted 3 lines
But plugins have to be built in-tree of Kernelshark? Or does the new architecture allow to build them against a "kernelshark-devel" package as well?
Current patch is built in-tree of kernelshark. In readme of kernelshark, it just describe how to build and install kernelshark-devel package, but I do not find how to build plugin against a kernelshark-devel package.
Regards
Hongzhan Chen
Quoted 6 lines
Jan
Signature · 2 lines
Siemens AG, T RDA IOT Corporate Competence Center Embedded Linux
Quoted 221 lines · Hongzhan
Quoted 221 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Monday, December 13, 2021 3:50 PM
To: Chen, Hongzhan <[email protected]>; [email protected]
Subject: Re: [RFC PATCH V2] kernel-shark: add plugin for handling xenomai cobalt context switch eventQuoted 199 lines · Hongzhan Chen
For Xenomai-cobalt enabled system,
cobalt_switch_contextmeans that there is context switch in companion core(realtime core), which we may need to do special treatment and take correct action as main kernelsched_switch. We need to update cpu bar regardingcobalt_switch_contextevent to correct color as switching-in task.Signed-off-by Hongzhan Chen <[email protected]>src/libkshark-tepdata.c +1
-0@@ -1208,6 +1208,7 @@ static void kshark_tep_init_methods(struct kshark_generic_stream_interface *inte/** A list of built in default plugins for FTRACE (trace-cmd) data. */ const char *tep_plugin_names[] = {"sched_events" , +"xenomai_cobalt_switch_events" ,"missed_events" ,"kvm_combo" , };src/plugins/CMakeLists.txt +4
-0@@ -44,6 +44,10 @@ if (Qt5Widgets_FOUND AND TT_FONT_FILE) SOURCE sched_events.c SchedEvents.cpp) list(APPEND PLUGIN_LIST "sched_events") + BUILD_GUI_PLUGIN(NAME xenomai_cobalt_switch_events + SOURCE xenomai_cobalt_switch_events.c) + list(APPEND PLUGIN_LIST "xenomai_cobalt_switch_events") + BUILD_GUI_PLUGIN(NAME event_field_plot MOC EventFieldDialog.hpp SOURCE event_field_plot.c EventFieldDialog.cpp EventFieldPlot.cpp)src/plugins/xenomai_cobalt_switch_events.c new file +116
-0@@ -0,0 +1,116 @@ +// SPDX-License-Identifier: LGPL-2.1 + +/* +* Copyright (C) 2021 Intel Inc, Hongzhan Chen <[email protected]> +*/ + +/** +* @file xenomai_cobalt_switch_events.c +* @brief handle xenomai cobalt switch context event +*/ + +// C +#include <stdlib.h> +#include <stdio.h> + +// trace-cmd +#include <trace-cmd.h> + +// KernelShark +#include "plugins/xenomai_cobalt_switch_events.h" +#include "libkshark-tepdata.h" + +/** Plugin context instance. */ + +static void cobalt_free_context (struct plugin_cobalt_context *plugin_ctx) +{ +return ; +} + +/** A general purpose macro is used to define plugin context. */ +KS_DEFINE_PLUGIN_CONTEXT(struct plugin_cobalt_context, cobalt_free_context); + +static bool plugin_cobalt_init_context (struct kshark_data_stream *stream, +struct plugin_cobalt_context *plugin_ctx) +{ +struct tep_event *event; + +if (!kshark_is_tep (stream)) +return false; + + plugin_ctx->tep =kshark_get_tep (stream); + + 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" ); + +return true; +} + +static void plugin_cobalt_switch_action (struct kshark_data_stream *stream, +void *rec,struct kshark_entry *entry) +{ +struct tep_record *record = (struct tep_record *) rec; +struct plugin_cobalt_context *plugin_ctx; +unsigned long long next_pid; +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; +} + +/** Load this plugin. */ +int KSHARK_PLOT_PLUGIN_INITIALIZER (struct kshark_data_stream *stream) +{ +struct plugin_cobalt_context *plugin_ctx; + + plugin_ctx =__init (stream->stream_id); +if (!plugin_ctx || !plugin_cobalt_init_context (stream, plugin_ctx)) { +__close (stream->stream_id); +return 0 ; + } + +if (plugin_ctx->cobalt_switch_event) { +kshark_register_event_handler (stream, + plugin_ctx->cobalt_switch_event->id, + plugin_cobalt_switch_action); + } + +return 1 ; +} + +/** Unload this plugin. */ +int KSHARK_PLOT_PLUGIN_DEINITIALIZER (struct kshark_data_stream *stream) +{ +struct plugin_cobalt_context *plugin_ctx =__get_context (stream->stream_id); +int ret =0 ; + +if (plugin_ctx) { +if (plugin_ctx->cobalt_switch_event) { +kshark_unregister_event_handler (stream, + plugin_ctx->cobalt_switch_event->id, + plugin_cobalt_switch_action); + } + + ret =1 ; + } + +__close (stream->stream_id); + +return ret; +}src/plugins/xenomai_cobalt_switch_events.h new file +35
-0@@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: LGPL-2.1 */ + +/* +* Copyright (C) 2021 Intel Inc, Hongzhan Chen<[email protected]> +*/ + +/** +* @file xenomai_cobalt_switch_events.h +* @brief Plugin for xenomai cobalt switch context event +*/ + +#ifndef _KS_PLUGIN_SHED_H +#define _KS_PLUGIN_SHED_H + +// KernelShark +#include "libkshark.h" +#include "libkshark-plugin.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** Structure representing a plugin-specific context. */ +struct plugin_cobalt_context { + /** Page event used to parse the page. */ + struct tep_handle *tep; + + /** 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;src/plugins/xenomai_cobalt_switch_events.h line 45
Quoted 10 lines
src/plugins/xenomai_cobalt_switch_events.h new file +10
-0+ +}; + +KS_DECLARE_PLUGIN_CONTEXT_METHODS(struct plugin_cobalt_context) + +#ifdef __cplusplus +} +#endif + +#endif Ah, that looks way more self-contained!
Quoted 8 lines
Quoted 3 lines
But plugins have to be built in-tree of Kernelshark? Or does the new architecture allow to build them against a "kernelshark-devel" package as well?
Current patch is built in-tree of kernelshark. In readme of kernelshark, it just describe how to build and install kernelshark-devel package, but I do not find how to build plugin against a kernelshark-devel package.
Maybe it's now the time to ask their community?
Jan
Signature · 2 lines
Siemens AG, T RDA IOT Corporate Competence Center Embedded Linux