* [RFC PATCH V2] kernel-shark: add plugin for handling xenomai cobalt context switch event
@ 2021-12-13 1:55 Hongzhan Chen
2021-12-13 7:49 ` Jan Kiszka
0 siblings, 1 reply; 4+ messages in thread
From: Hongzhan Chen @ 2021-12-13 1:55 UTC (permalink / raw)
To: xenomai, jan.kiszka
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.
Signed-off-by: Hongzhan Chen <hongzhan.chen@intel.com>
diff --git a/src/libkshark-tepdata.c b/src/libkshark-tepdata.c
index 9740ed9..e933b39 100644
--- a/src/libkshark-tepdata.c
+++ b/src/libkshark-tepdata.c
@@ -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",
};
diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt
index 3e170fa..276eaaa 100644
--- a/src/plugins/CMakeLists.txt
+++ b/src/plugins/CMakeLists.txt
@@ -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)
diff --git a/src/plugins/xenomai_cobalt_switch_events.c b/src/plugins/xenomai_cobalt_switch_events.c
new file mode 100644
index 0000000..4639d24
--- /dev/null
+++ b/src/plugins/xenomai_cobalt_switch_events.c
@@ -0,0 +1,116 @@
+// SPDX-License-Identifier: LGPL-2.1
+
+/*
+ * Copyright (C) 2021 Intel Inc, Hongzhan Chen <hongzhan.chen@intel.com>
+ */
+
+/**
+ * @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;
+}
diff --git a/src/plugins/xenomai_cobalt_switch_events.h b/src/plugins/xenomai_cobalt_switch_events.h
new file mode 100644
index 0000000..4a3bc66
--- /dev/null
+++ b/src/plugins/xenomai_cobalt_switch_events.h
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: LGPL-2.1 */
+
+/*
+ * Copyright (C) 2021 Intel Inc, Hongzhan Chen<hongzhan.chen@intel.com>
+ */
+
+/**
+ * @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;
+
+};
+
+KS_DECLARE_PLUGIN_CONTEXT_METHODS(struct plugin_cobalt_context)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [RFC PATCH V2] kernel-shark: add plugin for handling xenomai cobalt context switch event
2021-12-13 1:55 [RFC PATCH V2] kernel-shark: add plugin for handling xenomai cobalt context switch event Hongzhan Chen
@ 2021-12-13 7:49 ` Jan Kiszka
2021-12-14 2:33 ` Chen, Hongzhan
0 siblings, 1 reply; 4+ messages in thread
From: Jan Kiszka @ 2021-12-13 7:49 UTC (permalink / raw)
To: Hongzhan Chen, xenomai
On 13.12.21 02:55, Hongzhan Chen wrote:
> 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.
>
> Signed-off-by: Hongzhan Chen <hongzhan.chen@intel.com>
>
> diff --git a/src/libkshark-tepdata.c b/src/libkshark-tepdata.c
> index 9740ed9..e933b39 100644
> --- a/src/libkshark-tepdata.c
> +++ b/src/libkshark-tepdata.c
> @@ -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",
> };
> diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt
> index 3e170fa..276eaaa 100644
> --- a/src/plugins/CMakeLists.txt
> +++ b/src/plugins/CMakeLists.txt
> @@ -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)
> diff --git a/src/plugins/xenomai_cobalt_switch_events.c b/src/plugins/xenomai_cobalt_switch_events.c
> new file mode 100644
> index 0000000..4639d24
> --- /dev/null
> +++ b/src/plugins/xenomai_cobalt_switch_events.c
> @@ -0,0 +1,116 @@
> +// SPDX-License-Identifier: LGPL-2.1
> +
> +/*
> + * Copyright (C) 2021 Intel Inc, Hongzhan Chen <hongzhan.chen@intel.com>
> + */
> +
> +/**
> + * @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;
> +}
> diff --git a/src/plugins/xenomai_cobalt_switch_events.h b/src/plugins/xenomai_cobalt_switch_events.h
> new file mode 100644
> index 0000000..4a3bc66
> --- /dev/null
> +++ b/src/plugins/xenomai_cobalt_switch_events.h
> @@ -0,0 +1,45 @@
> +/* SPDX-License-Identifier: LGPL-2.1 */
> +
> +/*
> + * Copyright (C) 2021 Intel Inc, Hongzhan Chen<hongzhan.chen@intel.com>
> + */
> +
> +/**
> + * @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;
> +
> +};
> +
> +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
--
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [RFC PATCH V2] kernel-shark: add plugin for handling xenomai cobalt context switch event
2021-12-13 7:49 ` Jan Kiszka
@ 2021-12-14 2:33 ` Chen, Hongzhan
2021-12-14 6:24 ` Jan Kiszka
0 siblings, 1 reply; 4+ messages in thread
From: Chen, Hongzhan @ 2021-12-14 2:33 UTC (permalink / raw)
To: Kiszka, Jan, xenomai
>-----Original Message-----
>From: Jan Kiszka <jan.kiszka@siemens.com>
>Sent: Monday, December 13, 2021 3:50 PM
>To: Chen, Hongzhan <hongzhan.chen@intel.com>; xenomai@xenomai.org
>Subject: Re: [RFC PATCH V2] kernel-shark: add plugin for handling xenomai cobalt context switch event
>
>On 13.12.21 02:55, Hongzhan Chen wrote:
>> 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.
>>
>> Signed-off-by: Hongzhan Chen <hongzhan.chen@intel.com>
>>
>> diff --git a/src/libkshark-tepdata.c b/src/libkshark-tepdata.c
>> index 9740ed9..e933b39 100644
>> --- a/src/libkshark-tepdata.c
>> +++ b/src/libkshark-tepdata.c
>> @@ -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",
>> };
>> diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt
>> index 3e170fa..276eaaa 100644
>> --- a/src/plugins/CMakeLists.txt
>> +++ b/src/plugins/CMakeLists.txt
>> @@ -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)
>> diff --git a/src/plugins/xenomai_cobalt_switch_events.c b/src/plugins/xenomai_cobalt_switch_events.c
>> new file mode 100644
>> index 0000000..4639d24
>> --- /dev/null
>> +++ b/src/plugins/xenomai_cobalt_switch_events.c
>> @@ -0,0 +1,116 @@
>> +// SPDX-License-Identifier: LGPL-2.1
>> +
>> +/*
>> + * Copyright (C) 2021 Intel Inc, Hongzhan Chen <hongzhan.chen@intel.com>
>> + */
>> +
>> +/**
>> + * @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;
>> +}
>> diff --git a/src/plugins/xenomai_cobalt_switch_events.h b/src/plugins/xenomai_cobalt_switch_events.h
>> new file mode 100644
>> index 0000000..4a3bc66
>> --- /dev/null
>> +++ b/src/plugins/xenomai_cobalt_switch_events.h
>> @@ -0,0 +1,45 @@
>> +/* SPDX-License-Identifier: LGPL-2.1 */
>> +
>> +/*
>> + * Copyright (C) 2021 Intel Inc, Hongzhan Chen<hongzhan.chen@intel.com>
>> + */
>> +
>> +/**
>> + * @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;
>> +
>> +};
>> +
>> +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?
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
>
>Jan
>
>--
>Siemens AG, T RDA IOT
>Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [RFC PATCH V2] kernel-shark: add plugin for handling xenomai cobalt context switch event
2021-12-14 2:33 ` Chen, Hongzhan
@ 2021-12-14 6:24 ` Jan Kiszka
0 siblings, 0 replies; 4+ messages in thread
From: Jan Kiszka @ 2021-12-14 6:24 UTC (permalink / raw)
To: Chen, Hongzhan, xenomai
On 14.12.21 03:33, Chen, Hongzhan wrote:
>
>
>> -----Original Message-----
>> From: Jan Kiszka <jan.kiszka@siemens.com>
>> Sent: Monday, December 13, 2021 3:50 PM
>> To: Chen, Hongzhan <hongzhan.chen@intel.com>; xenomai@xenomai.org
>> Subject: Re: [RFC PATCH V2] kernel-shark: add plugin for handling xenomai cobalt context switch event
>>
>> On 13.12.21 02:55, Hongzhan Chen wrote:
>>> 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.
>>>
>>> Signed-off-by: Hongzhan Chen <hongzhan.chen@intel.com>
>>>
>>> diff --git a/src/libkshark-tepdata.c b/src/libkshark-tepdata.c
>>> index 9740ed9..e933b39 100644
>>> --- a/src/libkshark-tepdata.c
>>> +++ b/src/libkshark-tepdata.c
>>> @@ -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",
>>> };
>>> diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt
>>> index 3e170fa..276eaaa 100644
>>> --- a/src/plugins/CMakeLists.txt
>>> +++ b/src/plugins/CMakeLists.txt
>>> @@ -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)
>>> diff --git a/src/plugins/xenomai_cobalt_switch_events.c b/src/plugins/xenomai_cobalt_switch_events.c
>>> new file mode 100644
>>> index 0000000..4639d24
>>> --- /dev/null
>>> +++ b/src/plugins/xenomai_cobalt_switch_events.c
>>> @@ -0,0 +1,116 @@
>>> +// SPDX-License-Identifier: LGPL-2.1
>>> +
>>> +/*
>>> + * Copyright (C) 2021 Intel Inc, Hongzhan Chen <hongzhan.chen@intel.com>
>>> + */
>>> +
>>> +/**
>>> + * @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;
>>> +}
>>> diff --git a/src/plugins/xenomai_cobalt_switch_events.h b/src/plugins/xenomai_cobalt_switch_events.h
>>> new file mode 100644
>>> index 0000000..4a3bc66
>>> --- /dev/null
>>> +++ b/src/plugins/xenomai_cobalt_switch_events.h
>>> @@ -0,0 +1,45 @@
>>> +/* SPDX-License-Identifier: LGPL-2.1 */
>>> +
>>> +/*
>>> + * Copyright (C) 2021 Intel Inc, Hongzhan Chen<hongzhan.chen@intel.com>
>>> + */
>>> +
>>> +/**
>>> + * @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;
>>> +
>>> +};
>>> +
>>> +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?
>
> 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
--
Siemens AG, T RDA IOT
Corporate Competence Center Embedded Linux
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-12-14 6:24 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-13 1:55 [RFC PATCH V2] kernel-shark: add plugin for handling xenomai cobalt context switch event Hongzhan Chen
2021-12-13 7:49 ` Jan Kiszka
2021-12-14 2:33 ` Chen, Hongzhan
2021-12-14 6:24 ` Jan Kiszka
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.