aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYordan Karadzhov (VMware) <y.karadz@gmail.com>2021-04-28 16:47:25 +0300
committerYordan Karadzhov (VMware) <y.karadz@gmail.com>2021-05-11 16:00:02 +0300
commitc7d184c88b026e2beb55a9825114b2572a6c6ef6 (patch)
tree1dfa38edda189d82c810a063c055ed305b92fe81
parente489a3b247aae8a3a556504ce6bf0da37190a99b (diff)
downloadkernel-shark-c7d184c88b026e2beb55a9825114b2572a6c6ef6.tar.gz
kernel-shark: Add cleanup of all plugin contexts
When the macro KS_DEFINE_PLUGIN_CONTEXT is used by the plugin, the final free of the memory is done by calling __close() with a negative stream id. Althow, this was provisioned in the definition of the macro, it was never implemented in the GUI. Link: https://lore.kernel.org/linux-trace-devel/20210428134730.187533-5-y.karadz@gmail.com Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
-rw-r--r--src/libkshark-plugin.c10
-rw-r--r--src/libkshark-plugin.h25
-rw-r--r--src/libkshark.h2
-rw-r--r--src/plugins/sched_events.c28
4 files changed, 41 insertions, 24 deletions
diff --git a/src/libkshark-plugin.c b/src/libkshark-plugin.c
index ebd2579e..09886ce2 100644
--- a/src/libkshark-plugin.c
+++ b/src/libkshark-plugin.c
@@ -117,6 +117,9 @@ int kshark_unregister_event_handler(struct kshark_data_stream *stream,
{
struct kshark_event_proc_handler **last;
+ if (stream->stream_id < 0)
+ return 0;
+
for (last = &stream->event_handlers; *last; last = &(*last)->next) {
if ((*last)->id == event_id &&
(*last)->event_func == evt_func) {
@@ -182,6 +185,9 @@ void kshark_unregister_draw_handler(struct kshark_data_stream *stream,
{
struct kshark_draw_handler **last;
+ if (stream->stream_id < 0)
+ return;
+
for (last = &stream->draw_handlers; *last; last = &(*last)->next) {
if ((*last)->draw_func == draw_func) {
struct kshark_draw_handler *this_handler;
@@ -410,12 +416,16 @@ void kshark_unregister_plugin(struct kshark_context *kshark_ctx,
*/
void kshark_free_plugin_list(struct kshark_plugin_list *plugins)
{
+ struct kshark_data_stream stream;
struct kshark_plugin_list *last;
+ stream.stream_id = KS_PLUGIN_CONTEXT_FREE;
while (plugins) {
last = plugins;
plugins = plugins->next;
+ if (last->process_interface)
+ last->process_interface->close(&stream);
free_plugin(last);
}
}
diff --git a/src/libkshark-plugin.h b/src/libkshark-plugin.h
index 752dbeb2..b259b240 100644
--- a/src/libkshark-plugin.h
+++ b/src/libkshark-plugin.h
@@ -366,6 +366,9 @@ int kshark_handle_all_dpis(struct kshark_data_stream *stream,
__ok; \
}) \
+/** Identifier used to free the plugin context. */
+#define KS_PLUGIN_CONTEXT_FREE -1
+
/**
* General purpose macro defining methods for adding plugin context.
* Do not use this macro in header files.
@@ -393,21 +396,25 @@ __hidden type *__init(int sd) \
__context_handler[sd] = obj; \
return obj; \
} \
+__hidden type *__get_context(int sd) \
+{ \
+ if (sd < 0 || sd >= __n_streams) \
+ return NULL; \
+ return __context_handler[sd]; \
+} \
__hidden void __close(int sd) \
{ \
- if (sd < 0) { \
+ type *obj; \
+ if (sd == KS_PLUGIN_CONTEXT_FREE) { \
free(__context_handler); \
__n_streams = -1; \
return; \
} \
- free(__context_handler[sd]); \
- __context_handler[sd] = NULL; \
-} \
-__hidden type *__get_context(int sd) \
-{ \
- if (sd < 0 || sd >= __n_streams) \
- return NULL; \
- return __context_handler[sd]; \
+ obj = __get_context(sd); \
+ if (obj) { \
+ free(__context_handler[sd]); \
+ __context_handler[sd] = NULL; \
+ } \
} \
/**
diff --git a/src/libkshark.h b/src/libkshark.h
index aa4b3ca7..ee3a1d38 100644
--- a/src/libkshark.h
+++ b/src/libkshark.h
@@ -281,7 +281,7 @@ struct kshark_generic_stream_interface {
/** Structure representing a stream of trace data. */
struct kshark_data_stream {
/** Data stream identifier. */
- uint16_t stream_id;
+ int16_t stream_id;
/** The number of CPUs presented in this data stream. */
int n_cpus;
diff --git a/src/plugins/sched_events.c b/src/plugins/sched_events.c
index 57983225..f3c2c23e 100644
--- a/src/plugins/sched_events.c
+++ b/src/plugins/sched_events.c
@@ -198,26 +198,26 @@ int KSHARK_PLOT_PLUGIN_INITIALIZER(struct kshark_data_stream *stream)
int KSHARK_PLOT_PLUGIN_DEINITIALIZER(struct kshark_data_stream *stream)
{
printf("<-- sched close %i\n", stream->stream_id);
- struct plugin_sched_context *plugin_ctx;
- int sd = stream->stream_id;
+ struct plugin_sched_context *plugin_ctx = __get_context(stream->stream_id);
+ int ret = 0;
- plugin_ctx = __get_context(sd);
- if (!plugin_ctx)
- return 0;
+ if (plugin_ctx) {
+ kshark_unregister_event_handler(stream,
+ plugin_ctx->sched_switch_event->id,
+ plugin_sched_swith_action);
- kshark_unregister_event_handler(stream,
- plugin_ctx->sched_switch_event->id,
- plugin_sched_swith_action);
+ kshark_unregister_event_handler(stream,
+ plugin_ctx->sched_waking_event->id,
+ plugin_sched_wakeup_action);
- kshark_unregister_event_handler(stream,
- plugin_ctx->sched_waking_event->id,
- plugin_sched_wakeup_action);
+ kshark_unregister_draw_handler(stream, plugin_draw);
- kshark_unregister_draw_handler(stream, plugin_draw);
+ ret = 1;
+ }
- __close(sd);
+ __close(stream->stream_id);
- return 1;
+ return ret;
}
/** Initialize the control interface of the plugin. */