Skip to content

Commit d87d76d

Browse files
Jie GanSuzuki K Poulose
authored andcommitted
Coresight: Allocate trace ID after building the path
The trace_id will be stored in coresight_path instead of being declared everywhere and allocated after building the path. Co-developed-by: James Clark <[email protected]> Signed-off-by: James Clark <[email protected]> Signed-off-by: Jie Gan <[email protected]> Signed-off-by: Suzuki K Poulose <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 3c03c49 commit d87d76d

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

drivers/hwtracing/coresight/coresight-core.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,50 @@ static void coresight_drop_device(struct coresight_device *csdev)
655655
}
656656
}
657657

658+
/*
659+
* coresight device will read their existing or alloc a trace ID, if their trace_id
660+
* callback is set.
661+
*
662+
* Return 0 if the trace_id callback is not set.
663+
* Return the result of the trace_id callback if it is set. The return value
664+
* will be the trace_id if successful, and an error number if it fails.
665+
*/
666+
static int coresight_get_trace_id(struct coresight_device *csdev,
667+
enum cs_mode mode,
668+
struct coresight_device *sink)
669+
{
670+
if (coresight_ops(csdev)->trace_id)
671+
return coresight_ops(csdev)->trace_id(csdev, mode, sink);
672+
673+
return 0;
674+
}
675+
676+
/*
677+
* Call this after creating the path and before enabling it. This leaves
678+
* the trace ID set on the path, or it remains 0 if it couldn't be assigned.
679+
*/
680+
void coresight_path_assign_trace_id(struct coresight_path *path,
681+
enum cs_mode mode)
682+
{
683+
struct coresight_device *sink = coresight_get_sink(&path->path_list);
684+
struct coresight_node *nd;
685+
int trace_id;
686+
687+
list_for_each_entry(nd, &path->path_list, link) {
688+
/* Assign a trace ID to the path for the first device that wants to do it */
689+
trace_id = coresight_get_trace_id(nd->csdev, mode, sink);
690+
691+
/*
692+
* 0 in this context is that it didn't want to assign so keep searching.
693+
* Non 0 is either success or fail.
694+
*/
695+
if (trace_id != 0) {
696+
path->trace_id = trace_id;
697+
return;
698+
}
699+
}
700+
}
701+
658702
/**
659703
* _coresight_build_path - recursively build a path from a @csdev to a sink.
660704
* @csdev: The device to start from.

drivers/hwtracing/coresight/coresight-etm-perf.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ static void *etm_setup_aux(struct perf_event *event, void **pages,
319319
{
320320
u32 id, cfg_hash;
321321
int cpu = event->cpu;
322-
int trace_id;
323322
cpumask_t *mask;
324323
struct coresight_device *sink = NULL;
325324
struct coresight_device *user_sink = NULL, *last_sink = NULL;
@@ -409,8 +408,8 @@ static void *etm_setup_aux(struct perf_event *event, void **pages,
409408
}
410409

411410
/* ensure we can allocate a trace ID for this CPU */
412-
trace_id = coresight_trace_id_get_cpu_id_map(cpu, &sink->perf_sink_id_map);
413-
if (!IS_VALID_CS_TRACE_ID(trace_id)) {
411+
coresight_path_assign_trace_id(path, CS_MODE_PERF);
412+
if (!IS_VALID_CS_TRACE_ID(path->trace_id)) {
414413
cpumask_clear_cpu(cpu, mask);
415414
coresight_release_path(path);
416415
continue;

drivers/hwtracing/coresight/coresight-priv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ int coresight_make_links(struct coresight_device *orig,
152152
void coresight_remove_links(struct coresight_device *orig,
153153
struct coresight_connection *conn);
154154
u32 coresight_get_sink_id(struct coresight_device *csdev);
155+
void coresight_path_assign_trace_id(struct coresight_path *path,
156+
enum cs_mode mode);
155157

156158
#if IS_ENABLED(CONFIG_CORESIGHT_SOURCE_ETM3X)
157159
extern int etm_readl_cp14(u32 off, unsigned int *val);

drivers/hwtracing/coresight/coresight-sysfs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,10 @@ int coresight_enable_sysfs(struct coresight_device *csdev)
209209
goto out;
210210
}
211211

212+
coresight_path_assign_trace_id(path, CS_MODE_SYSFS);
213+
if (!IS_VALID_CS_TRACE_ID(path->trace_id))
214+
goto err_path;
215+
212216
ret = coresight_enable_path(&path->path_list, CS_MODE_SYSFS, NULL);
213217
if (ret)
214218
goto err_path;

0 commit comments

Comments
 (0)