kernel-shark related patches
cover kernel-shark related patches
1. Add kernel-shark plugin to visualize OOB state of xenomai realtime thread.
2. Add libtraceevent plugin to parse xenomai_schedparams correctly.
With the help of Yordan Karadzhov <[email protected]>, we finally create xenomai plugin and can build standalone. Thanks for his help again.
Hongzhan Chen (2):
Add xenomai_cobalt_switch_events plugin for kernel-shark Add xenomai_schedparams plugin for libtraceevent
kernel-shark/CobaltSwitchEvents.cpp | 156 +++++++++++++++ kernel-shark/Makefile | 20 ++ kernel-shark/README | 81 ++++++++ kernel-shark/xenomai_cobalt_switch_events.c | 174 +++++++++++++++++ kernel-shark/xenomai_cobalt_switch_events.h | 58 ++++++ libtraceevent/Makefile | 31 +++ libtraceevent/README | 30 +++ libtraceevent/plugin_xenomai_schedparams.c | 201 ++++++++++++++++++++ 8 files changed, 751 insertions(+) create mode 100644 kernel-shark/CobaltSwitchEvents.cpp create mode 100644 kernel-shark/Makefile create mode 100644 kernel-shark/README create mode 100644 kernel-shark/xenomai_cobalt_switch_events.c create mode 100644 kernel-shark/xenomai_cobalt_switch_events.h create mode 100644 libtraceevent/Makefile create mode 100644 libtraceevent/README create mode 100644 libtraceevent/plugin_xenomai_schedparams.c
Signature · 1 line
2.17.1
PATCH 1/2 Add xenomai_cobalt_switch_events plugin for kernel-shark
For Xenomai-cobalt enabled system, cobalt_switch_context means that there is schedule and context switch in companion core(realtime core), which we may need to do special treatment and take correct action as main kernel sched_switch to visualize out-of-band state of realtime tasks running in cobalt core. To achive our target, we implement following:
1. store corresponding cobalt_switch_context events into container data.
2. modify pid stored in entry to be equal to next_pid to show correct color in cpu bar when cobalt_switch_context event happen.
3. show blue hollow box to mark out-of-band state according to cobalt_switch_context events.
4. clickable cobalt_switch_context plugin shapes.
--- kernel-shark/CobaltSwitchEvents.cpp | 156 ++++++++++++++++++ kernel-shark/Makefile | 20 +++ kernel-shark/README | 81 +++++++++ kernel-shark/xenomai_cobalt_switch_events.c | 174 ++++++++++++++++++++ kernel-shark/xenomai_cobalt_switch_events.h | 58 +++++++ 5 files changed, 489 insertions(+) create mode 100644 kernel-shark/CobaltSwitchEvents.cpp create mode 100644 kernel-shark/Makefile create mode 100644 kernel-shark/README create mode 100644 kernel-shark/xenomai_cobalt_switch_events.c create mode 100644 kernel-shark/xenomai_cobalt_switch_events.h
kernel-shark/CobaltSwitchEvents.cpp new file +156 -0
@@ -0,0 +1,156 @@ +// SPDX-License-Identifier: LGPL-2.1 + +/* + * Copyright (C) 2021 Intel Inc, Hongzhan Chen <[email protected]> + */ + +/** + * @file CobaltSwitchEvents.cpp + * @brief Defines a callback function for Xenomai Cobalt context switch + * events used to plot in cobalt blue the out-of-band state of + * the task + */ + +// KernelShark +#include "libkshark.h" +#include "libkshark-plugin.h" +#include "xenomai_cobalt_switch_events.h" +#include "KsPlotTools.hpp" +#include "KsPlugins.hpp" +#include "KsPluginsGUI.hpp" + +static void *ks4xenomai_ptr; + +/** + * @brief Provide the plugin with a pointer to the KsMainWindow object (the GUI + * itself) such that the plugin can manipulate the GUI. + */ +__hidden void *plugin_set_gui_ptr(void *gui_ptr) +{ + ks4xenomai_ptr = gui_ptr; + return nullptr; +} + +/** + * This class represents the graphical element visualizing OOB state between + * two cobalt_switch_context events. + */ +class XenomaiSwitchBox : public LatencyBox +{ + /** On double click do. */ + void _doubleClick() const override + { + markEntryB(ks4xenomai_ptr, _data[1]->entry); + markEntryA(ks4xenomai_ptr, _data[0]->entry); + } +}; + +/* + * Ideally, the cobalt_switch_context has to be the last trace event recorded before + * the task is preempted. Because of this, when the data is loaded (the first pass), + * the "pid" field of the cobalt_switch_context entries gets edited by this plugin + * to be equal to the "next pid" of the cobalt_switch_context event. However, in + * reality the cobalt_switch_context event may be followed by some trailing events + * from the same task (printk events for example). This has the effect of extending + * the graph of the task outside of the actual duration of the task. The "second + * pass" over the data is used to fix this problem. It takes advantage of the + * "next" field of the entry (this field is set during the first pass) to search + * for trailing events after the "cobalt_switch_context". In addition, when + * we find that it try to switch in-band because next-pid is zero, we prefer to + * skip this event because it try to leave oob not enterring. + */ +static void secondPass(plugin_cobalt_context *plugin_ctx) +{ + kshark_data_container *cSS; + kshark_entry *e; + int pid_rec, switch_inband; + + cSS = plugin_ctx->cs_data; + for (ssize_t i = 0; i < cSS->size; ++i) { + switch_inband = plugin_cobalt_check_switch_inband( + cSS->data[i]->field); + + /* we skip cobalt_switch_context that try to + * switch into in-band state because we just handle + * out-of-band + */ + if (switch_inband) + continue; + pid_rec = plugin_sched_get_pid(cSS->data[i]->field); + e = cSS->data[i]->entry; + if (!e->next || e->pid == 0 || + e->event_id == e->next->event_id || + pid_rec != e->next->pid) + continue; + + e = e->next; + /* Find all trailing events. */ + for (; e->next; e = e->next) { + if (e->pid == plugin_sched_get_pid( + cSS->data[i]->field)) { + /* + * Change the "pid" to be equal to the "next + * pid" of the cobalt_switch_context event + * and leave a sign that you edited this + * entry. + */ + e->pid = cSS->data[i]->entry->pid; + e->visible &= ~KS_PLUGIN_UNTOUCHED_MASK; + + /* This is the last trailing event, we finish + * this round. + */ + if (e->next->pid != plugin_sched_get_pid( + cSS->data[i]->field)) + break; + } + } + } +} + +/** + * @brief Plugin's draw function. + * + * @param argv_c: A C pointer to be converted to KsCppArgV (C++ struct). + * @param sd: Data stream identifier. + * @param pid: Process Id. + * @param draw_action: Draw action identifier. + */ +__hidden void plugin_cobalt_draw(kshark_cpp_argv *argv_c, + int sd, int pid, int draw_action) +{ + plugin_cobalt_context *plugin_ctx; + + if (!(draw_action & KSHARK_TASK_DRAW) || pid == 0) + return; + + plugin_ctx = __get_context(sd); + if (!plugin_ctx) + return; + + KsCppArgV *argvCpp = KS_ARGV_TO_CPP(argv_c); + + if (!plugin_ctx->second_pass_done) { + /* The second pass is not done yet. */ + secondPass(plugin_ctx); + plugin_ctx->second_pass_done = true; + } + + IsApplicableFunc checkFieldCS = [=] (kshark_data_container *d, + ssize_t i) { + return !(plugin_cobalt_check_switch_inband(d->data[i]->field)) && + d->data[i]->entry->pid == pid; + }; + + IsApplicableFunc checkEntryPid = [=] (kshark_data_container *d, + ssize_t i) { + return plugin_sched_get_pid(d->data[i]->field) == pid; + }; + + eventFieldIntervalPlot(argvCpp, + plugin_ctx->cs_data, checkFieldCS, + plugin_ctx->cs_data, checkEntryPid, + makeLatencyBox<XenomaiSwitchBox>, + {0, 71, 171}, // Cobalt Blue + -1); // Default size +}
kernel-shark/Makefile new file +20 -0
@@ -0,0 +1,20 @@ +KS_INCLUDS ?= /usr/local/include/kernelshark +TRACECMD_INCLUDS ?= /usr/local/include/trace-cmd +TRACEFS_INCLUDS ?= /usr/local/include/tracefs +TRACEEVENR_INCLUDS ?= /usr/local/include/traceevent + +INCLUDES = -I $(KS_INCLUDS) -I $(TRACECMD_INCLUDS) -I $(TRACEFS_INCLUDS) -I $(TRACEEVENR_INCLUDS) + +all: plugin-xenomai_cobalt_switch_events.so + +xenomai_cobalt_switch_events.o: xenomai_cobalt_switch_events.c + gcc -g -c $^ $(INCLUDES) -fPIC + +CobaltSwitchEvents.o: CobaltSwitchEvents.cpp + g++ -g -c $^ $(INCLUDES) -fPIC + +plugin-xenomai_cobalt_switch_events.so: xenomai_cobalt_switch_events.o CobaltSwitchEvents.o + g++ -g -shared $^ -o $@ + +clean: + $(RM) *.o *~ *.a *.so
kernel-shark/README new file +81 -0
81 lines not on this page · raw message
kernel-shark/xenomai_cobalt_switch_events.c new file +174 -0
174 lines not on this page · raw message
kernel-shark/xenomai_cobalt_switch_events.h new file +58 -0
58 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 2/2 Add xenomai_schedparams plugin for libtraceevent
In reply to Hongzhan ChenFor cobalt thread, there is special struct param_ex data stored in data record, we need to parse and print its content out correctly to hint user.
--- libtraceevent/Makefile | 31 ++++ libtraceevent/README | 30 +++ libtraceevent/plugin_xenomai_schedparams.c | 201 +++++++++++++++++++++ 3 files changed, 262 insertions(+) create mode 100644 libtraceevent/Makefile create mode 100644 libtraceevent/README create mode 100644 libtraceevent/plugin_xenomai_schedparams.c
libtraceevent/Makefile new file +31 -0
@@ -0,0 +1,31 @@ +TRACEEVENR_INCLUDS ?= /usr/local/include/traceevent + +LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1) +ifeq ($(LP64), 1) + libdir_relative_temp = lib64 +else + libdir_relative_temp = lib +endif + +plugin_dir ?= /usr/local/$(libdir_relative_temp)/traceevent/plugins/ + +PLUGIN_TARGET ?= plugin_xenomai_schedparams.so + +INCLUDES = -I $(TRACEEVENR_INCLUDS) + +all: $(PLUGIN_TARGET) + +plugin_xenomai_schedparams.o: plugin_xenomai_schedparams.c + gcc -g -c $^ $(INCLUDES) -fPIC + +plugin_xenomai_schedparams.so: plugin_xenomai_schedparams.o + gcc -g -shared $^ -o $@ + +install: plugin_xenomai_schedparams.so + install -m 644 $(PLUGIN_TARGET) $(plugin_dir) + +uninstall: + rm -f $(plugin_dir)/$(PLUGIN_TARGET) + +clean: + $(RM) *.o *~ *.a *.so
libtraceevent/README new file +30 -0
@@ -0,0 +1,30 @@ + +What is it? +============= + + It is Xenomai plugin on libtracevent to parse struct param_ex + out correctly for trace log. + +How to compile? +================================ + +Preparation: + + - GIT clone: + + https://git.kernel.org/pub/scm/libs/libtrace/libtraceevent.git + + - build and install libtraceevent: + + make; + sudo make install + +Build and Install Xenomai plugin: + + goto your_xenonai/libtraceevent folder + make; + sudo make install + + When libtracevent and its plugins is installed correctly, the plugins + would be loaded automatically by other module such as libtracecmd after + kernel-shark run.
libtraceevent/plugin_xenomai_schedparams.c new file +201 -0
201 lines not on this page · raw message
Signature · 1 line
2.17.1
Quoted 8 lines · Hongzhan Chen
1. Add kernel-shark plugin to visualize OOB state of xenomai realtime thread.
2. Add libtraceevent plugin to parsexenomai_schedparamscorrectly.With the help of Yordan Karadzhov <[email protected]>, we finally create xenomai plugin and can build standalone. Thanks for his help again.
So these build targets can basically live "anywhere" and are not connected with our autoconf/automake build system of Xenomai. Intentionally due to the more complex preparation steps?
Jan
Quoted 22 lines
Hongzhan Chen (2):
Addxenomai_cobalt_switch_eventsplugin for kernel-shark Addxenomai_schedparamsplugin for libtraceeventkernel-shark/CobaltSwitchEvents.cpp | 156 +++++++++++++++ kernel-shark/Makefile | 20 ++ kernel-shark/README | 81 ++++++++ kernel-shark/xenomai_cobalt_switch_events.c | 174 +++++++++++++++++ kernel-shark/xenomai_cobalt_switch_events.h | 58 ++++++ libtraceevent/Makefile | 31 +++ libtraceevent/README | 30 +++ libtraceevent/plugin_xenomai_schedparams.c | 201 ++++++++++++++++++++ 8 files changed, 751 insertions(+) create mode 100644 kernel-shark/CobaltSwitchEvents.cpp create mode 100644 kernel-shark/Makefile create mode 100644 kernel-shark/README create mode 100644 kernel-shark/xenomai_cobalt_switch_events.c create mode 100644 kernel-shark/xenomai_cobalt_switch_events.h create mode 100644 libtraceevent/Makefile create mode 100644 libtraceevent/README create mode 100644 libtraceevent/plugin_xenomai_schedparams.c
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
Quoted 13 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Wednesday, February 23, 2022 2:51 PM
To: Chen, Hongzhan <[email protected]>; [email protected]
Cc: [email protected]
Subject: Re: [PATCH 0/2] kernel-shark related patchesQuoted 4 lines · Hongzhan Chen
1. Add kernel-shark plugin to visualize OOB state of xenomai realtime thread.
2. Add libtraceevent plugin to parsexenomai_schedparamscorrectly.
Quoted 8 lines
Quoted 4 lines
With the help of Yordan Karadzhov <[email protected]>, we finally create xenomai plugin and can build standalone. Thanks for his help again.
So these build targets can basically live "anywhere" and are not connected with our autoconf/automake build system of Xenomai. Intentionally due to the more complex preparation steps?
The plugin actually depends on libkshark-devel and libtraceevent dev which we may have to get updated kernel-shark and libtraceevent code and build and install them before build the plugins. I am wondering the better way is to integrate all these tools with our plugin patches and maintain them
in our xenomai-image?
Regards
Hongzhan Chen
Quoted 29 lines
Jan
Quoted 22 lines
Hongzhan Chen (2):
Addxenomai_cobalt_switch_eventsplugin for kernel-shark Addxenomai_schedparamsplugin for libtraceeventkernel-shark/CobaltSwitchEvents.cpp | 156 +++++++++++++++ kernel-shark/Makefile | 20 ++ kernel-shark/README | 81 ++++++++ kernel-shark/xenomai_cobalt_switch_events.c | 174 +++++++++++++++++ kernel-shark/xenomai_cobalt_switch_events.h | 58 ++++++ libtraceevent/Makefile | 31 +++ libtraceevent/README | 30 +++ libtraceevent/plugin_xenomai_schedparams.c | 201 ++++++++++++++++++++ 8 files changed, 751 insertions(+) create mode 100644 kernel-shark/CobaltSwitchEvents.cpp create mode 100644 kernel-shark/Makefile create mode 100644 kernel-shark/README create mode 100644 kernel-shark/xenomai_cobalt_switch_events.c create mode 100644 kernel-shark/xenomai_cobalt_switch_events.h create mode 100644 libtraceevent/Makefile create mode 100644 libtraceevent/README create mode 100644 libtraceevent/plugin_xenomai_schedparams.cSignature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux
Quoted 18 lines · Hongzhan
Quoted 18 lines
-----Original Message-----
From: Jan Kiszka <[email protected]>
Sent: Wednesday, February 23, 2022 2:51 PM
To: Chen, Hongzhan <[email protected]>; [email protected]
Cc: [email protected]
Subject: Re: [PATCH 0/2] kernel-shark related patchesQuoted 8 lines · Hongzhan Chen
1. Add kernel-shark plugin to visualize OOB state of xenomai realtime thread.
2. Add libtraceevent plugin to parsexenomai_schedparamscorrectly.With the help of Yordan Karadzhov <[email protected]>, we finally create xenomai plugin and can build standalone. Thanks for his help again.
Quoted 8 lines
Quoted 3 lines
So these build targets can basically live "anywhere" and are not connected with our autoconf/automake build system of Xenomai. Intentionally due to the more complex preparation steps?
The plugin actually depends on libkshark-devel and libtraceevent dev which we may have to get updated kernel-shark and libtraceevent code and build and install them before build the plugins. I am wondering the better way is to integrate all these tools with our plugin patches and maintain them
in our xenomai-image?
Actually, xenomai-image would only be a bonus, and it will not address the use case of running graphical kernelshark. For now, I'm thinking of something like ./configure --with-kernelshark ... for the Xenomai userland build. That would not change what is built, just how it's accessible. We will still need READMEs for what is currently needed as special dependencies.
Jan
Signature · 2 lines
Siemens AG, Technology Competence Center Embedded Linux