Add a setup_sysfs_buf() callback to gtrace_driver and invoke it from gtrace_enable_sysfs() before the path is started, so the sink can allocate its sysfs trace buffer outside the spinlock held by the core start path.
Signed-off-by: Zane Leung liangzhen@linux.spacemit.com --- drivers/hwtracing/gtrace/gtrace-sysfs.c | 12 ++++++++++++ include/linux/gtrace.h | 2 ++ 2 files changed, 14 insertions(+)
diff --git a/drivers/hwtracing/gtrace/gtrace-sysfs.c b/drivers/hwtracing/gtrace/gtrace-sysfs.c index 5f4f3fcb56a4..23b0a21ef9c0 100644 --- a/drivers/hwtracing/gtrace/gtrace-sysfs.c +++ b/drivers/hwtracing/gtrace/gtrace-sysfs.c @@ -85,6 +85,7 @@ static int gtrace_validate_source_sysfs(struct gtrace_component *comp, int gtrace_enable_sysfs(struct gtrace_component *comp) { struct gtrace_component *sink; + struct gtrace_driver *sinkdrv; struct gtrace_path *path; int ret;
@@ -114,6 +115,17 @@ int gtrace_enable_sysfs(struct gtrace_component *comp)
mutex_lock(>race_mutex);
+ if (!sink) + sink = gtrace_path_sink(path); + sinkdrv = to_gtrace_driver(sink->dev.driver); + if (sinkdrv && sinkdrv->setup_sysfs_buf) { + ret = sinkdrv->setup_sysfs_buf(sink); + if (ret) { + gtrace_destroy_path(path); + goto out; + } + } + ret = gtrace_path_start(path); if (ret) gtrace_destroy_path(path); diff --git a/include/linux/gtrace.h b/include/linux/gtrace.h index a3d125882ec9..0957d0490c57 100644 --- a/include/linux/gtrace.h +++ b/include/linux/gtrace.h @@ -377,6 +377,7 @@ int gtrace_path_copyto_auxbuf(struct gtrace_path *path, /** * struct gtrace_driver - Representation of a trace driver. * @id_table: Table to match components handled by the driver. + * @setup_sysfs_buf: Callback to setup sink-specific sysfs buffer. * @alloc_buf: Callback to alloc sink-specific buffer. * @free_buf: Callback to free sink-specific buffer. * @copyto_auxbuf: Callback to copy data into perf AUX buffer. The driver @@ -394,6 +395,7 @@ int gtrace_path_copyto_auxbuf(struct gtrace_path *path, */ struct gtrace_driver { const struct gtrace_component_id *id_table; + int (*setup_sysfs_buf)(struct gtrace_component *comp); void *(*alloc_buf)(struct gtrace_component *comp, struct perf_event *event, void **pages, int nr_pages, bool overwrite);