Skip to content

Commit 7b365f0

Browse files
Jie GanSuzuki K Poulose
authored andcommitted
Coresight: Change to read the trace ID from coresight_path
The source device can directly read the trace ID from the coresight_path which result in etm_read_alloc_trace_id and etm4_read_alloc_trace_id being deleted. 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 d87d76d commit 7b365f0

File tree

10 files changed

+25
-108
lines changed

10 files changed

+25
-108
lines changed

drivers/hwtracing/coresight/coresight-dummy.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ DEFINE_CORESIGHT_DEVLIST(sink_devs, "dummy_sink");
2424

2525
static int dummy_source_enable(struct coresight_device *csdev,
2626
struct perf_event *event, enum cs_mode mode,
27-
__maybe_unused struct coresight_trace_id_map *id_map)
27+
__maybe_unused struct coresight_path *path)
2828
{
2929
if (!coresight_take_mode(csdev, mode))
3030
return -EBUSY;

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ static void etm_event_start(struct perf_event *event, int flags)
461461
struct coresight_device *sink, *csdev = per_cpu(csdev_src, cpu);
462462
struct coresight_path *path;
463463
u64 hw_id;
464-
u8 trace_id;
465464

466465
if (!csdev)
467466
goto fail;
@@ -504,8 +503,7 @@ static void etm_event_start(struct perf_event *event, int flags)
504503
goto fail_end_stop;
505504

506505
/* Finally enable the tracer */
507-
if (source_ops(csdev)->enable(csdev, event, CS_MODE_PERF,
508-
&sink->perf_sink_id_map))
506+
if (source_ops(csdev)->enable(csdev, event, CS_MODE_PERF, path))
509507
goto fail_disable_path;
510508

511509
/*
@@ -515,13 +513,11 @@ static void etm_event_start(struct perf_event *event, int flags)
515513
if (!cpumask_test_cpu(cpu, &event_data->aux_hwid_done)) {
516514
cpumask_set_cpu(cpu, &event_data->aux_hwid_done);
517515

518-
trace_id = coresight_trace_id_read_cpu_id_map(cpu, &sink->perf_sink_id_map);
519-
520516
hw_id = FIELD_PREP(CS_AUX_HW_ID_MAJOR_VERSION_MASK,
521517
CS_AUX_HW_ID_MAJOR_VERSION);
522518
hw_id |= FIELD_PREP(CS_AUX_HW_ID_MINOR_VERSION_MASK,
523519
CS_AUX_HW_ID_MINOR_VERSION);
524-
hw_id |= FIELD_PREP(CS_AUX_HW_ID_TRACE_ID_MASK, trace_id);
520+
hw_id |= FIELD_PREP(CS_AUX_HW_ID_TRACE_ID_MASK, path->trace_id);
525521
hw_id |= FIELD_PREP(CS_AUX_HW_ID_SINK_ID_MASK, coresight_get_sink_id(sink));
526522

527523
perf_report_aux_output_id(event, hw_id);

drivers/hwtracing/coresight/coresight-etm.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,5 @@ extern const struct attribute_group *coresight_etm_groups[];
284284
void etm_set_default(struct etm_config *config);
285285
void etm_config_trace_mode(struct etm_config *config);
286286
struct etm_config *get_etm_config(struct etm_drvdata *drvdata);
287-
int etm_read_alloc_trace_id(struct etm_drvdata *drvdata);
288287
void etm_release_trace_id(struct etm_drvdata *drvdata);
289288
#endif

drivers/hwtracing/coresight/coresight-etm3x-core.c

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -455,76 +455,37 @@ static int etm_cpu_id(struct coresight_device *csdev)
455455
return drvdata->cpu;
456456
}
457457

458-
int etm_read_alloc_trace_id(struct etm_drvdata *drvdata)
459-
{
460-
int trace_id;
461-
462-
/*
463-
* This will allocate a trace ID to the cpu,
464-
* or return the one currently allocated.
465-
*
466-
* trace id function has its own lock
467-
*/
468-
trace_id = coresight_trace_id_get_cpu_id(drvdata->cpu);
469-
if (IS_VALID_CS_TRACE_ID(trace_id))
470-
drvdata->traceid = (u8)trace_id;
471-
else
472-
dev_err(&drvdata->csdev->dev,
473-
"Failed to allocate trace ID for %s on CPU%d\n",
474-
dev_name(&drvdata->csdev->dev), drvdata->cpu);
475-
return trace_id;
476-
}
477-
478458
void etm_release_trace_id(struct etm_drvdata *drvdata)
479459
{
480460
coresight_trace_id_put_cpu_id(drvdata->cpu);
481461
}
482462

483463
static int etm_enable_perf(struct coresight_device *csdev,
484464
struct perf_event *event,
485-
struct coresight_trace_id_map *id_map)
465+
struct coresight_path *path)
486466
{
487467
struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
488-
int trace_id;
489468

490469
if (WARN_ON_ONCE(drvdata->cpu != smp_processor_id()))
491470
return -EINVAL;
492471

493472
/* Configure the tracer based on the session's specifics */
494473
etm_parse_event_config(drvdata, event);
495-
496-
/*
497-
* perf allocates cpu ids as part of _setup_aux() - device needs to use
498-
* the allocated ID. This reads the current version without allocation.
499-
*
500-
* This does not use the trace id lock to prevent lock_dep issues
501-
* with perf locks - we know the ID cannot change until perf shuts down
502-
* the session
503-
*/
504-
trace_id = coresight_trace_id_read_cpu_id_map(drvdata->cpu, id_map);
505-
if (!IS_VALID_CS_TRACE_ID(trace_id)) {
506-
dev_err(&drvdata->csdev->dev, "Failed to set trace ID for %s on CPU%d\n",
507-
dev_name(&drvdata->csdev->dev), drvdata->cpu);
508-
return -EINVAL;
509-
}
510-
drvdata->traceid = (u8)trace_id;
474+
drvdata->traceid = path->trace_id;
511475

512476
/* And enable it */
513477
return etm_enable_hw(drvdata);
514478
}
515479

516-
static int etm_enable_sysfs(struct coresight_device *csdev)
480+
static int etm_enable_sysfs(struct coresight_device *csdev, struct coresight_path *path)
517481
{
518482
struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
519483
struct etm_enable_arg arg = { };
520484
int ret;
521485

522486
spin_lock(&drvdata->spinlock);
523487

524-
/* sysfs needs to allocate and set a trace ID */
525-
ret = etm_read_alloc_trace_id(drvdata);
526-
if (ret < 0)
527-
goto unlock_enable_sysfs;
488+
drvdata->traceid = path->trace_id;
528489

529490
/*
530491
* Configure the ETM only if the CPU is online. If it isn't online
@@ -545,7 +506,6 @@ static int etm_enable_sysfs(struct coresight_device *csdev)
545506
if (ret)
546507
etm_release_trace_id(drvdata);
547508

548-
unlock_enable_sysfs:
549509
spin_unlock(&drvdata->spinlock);
550510

551511
if (!ret)
@@ -554,7 +514,7 @@ static int etm_enable_sysfs(struct coresight_device *csdev)
554514
}
555515

556516
static int etm_enable(struct coresight_device *csdev, struct perf_event *event,
557-
enum cs_mode mode, struct coresight_trace_id_map *id_map)
517+
enum cs_mode mode, struct coresight_path *path)
558518
{
559519
int ret;
560520
struct etm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
@@ -566,10 +526,10 @@ static int etm_enable(struct coresight_device *csdev, struct perf_event *event,
566526

567527
switch (mode) {
568528
case CS_MODE_SYSFS:
569-
ret = etm_enable_sysfs(csdev);
529+
ret = etm_enable_sysfs(csdev, path);
570530
break;
571531
case CS_MODE_PERF:
572-
ret = etm_enable_perf(csdev, event, id_map);
532+
ret = etm_enable_perf(csdev, event, path);
573533
break;
574534
default:
575535
ret = -EINVAL;

drivers/hwtracing/coresight/coresight-etm4x-core.c

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -232,25 +232,6 @@ static int etm4_cpu_id(struct coresight_device *csdev)
232232
return drvdata->cpu;
233233
}
234234

235-
int etm4_read_alloc_trace_id(struct etmv4_drvdata *drvdata)
236-
{
237-
int trace_id;
238-
239-
/*
240-
* This will allocate a trace ID to the cpu,
241-
* or return the one currently allocated.
242-
* The trace id function has its own lock
243-
*/
244-
trace_id = coresight_trace_id_get_cpu_id(drvdata->cpu);
245-
if (IS_VALID_CS_TRACE_ID(trace_id))
246-
drvdata->trcid = (u8)trace_id;
247-
else
248-
dev_err(&drvdata->csdev->dev,
249-
"Failed to allocate trace ID for %s on CPU%d\n",
250-
dev_name(&drvdata->csdev->dev), drvdata->cpu);
251-
return trace_id;
252-
}
253-
254235
void etm4_release_trace_id(struct etmv4_drvdata *drvdata)
255236
{
256237
coresight_trace_id_put_cpu_id(drvdata->cpu);
@@ -810,9 +791,9 @@ static int etm4_parse_event_config(struct coresight_device *csdev,
810791

811792
static int etm4_enable_perf(struct coresight_device *csdev,
812793
struct perf_event *event,
813-
struct coresight_trace_id_map *id_map)
794+
struct coresight_path *path)
814795
{
815-
int ret = 0, trace_id;
796+
int ret = 0;
816797
struct etmv4_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
817798

818799
if (WARN_ON_ONCE(drvdata->cpu != smp_processor_id())) {
@@ -825,22 +806,7 @@ static int etm4_enable_perf(struct coresight_device *csdev,
825806
if (ret)
826807
goto out;
827808

828-
/*
829-
* perf allocates cpu ids as part of _setup_aux() - device needs to use
830-
* the allocated ID. This reads the current version without allocation.
831-
*
832-
* This does not use the trace id lock to prevent lock_dep issues
833-
* with perf locks - we know the ID cannot change until perf shuts down
834-
* the session
835-
*/
836-
trace_id = coresight_trace_id_read_cpu_id_map(drvdata->cpu, id_map);
837-
if (!IS_VALID_CS_TRACE_ID(trace_id)) {
838-
dev_err(&drvdata->csdev->dev, "Failed to set trace ID for %s on CPU%d\n",
839-
dev_name(&drvdata->csdev->dev), drvdata->cpu);
840-
ret = -EINVAL;
841-
goto out;
842-
}
843-
drvdata->trcid = (u8)trace_id;
809+
drvdata->trcid = path->trace_id;
844810

845811
/* And enable it */
846812
ret = etm4_enable_hw(drvdata);
@@ -849,7 +815,7 @@ static int etm4_enable_perf(struct coresight_device *csdev,
849815
return ret;
850816
}
851817

852-
static int etm4_enable_sysfs(struct coresight_device *csdev)
818+
static int etm4_enable_sysfs(struct coresight_device *csdev, struct coresight_path *path)
853819
{
854820
struct etmv4_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
855821
struct etm4_enable_arg arg = { };
@@ -866,10 +832,7 @@ static int etm4_enable_sysfs(struct coresight_device *csdev)
866832

867833
spin_lock(&drvdata->spinlock);
868834

869-
/* sysfs needs to read and allocate a trace ID */
870-
ret = etm4_read_alloc_trace_id(drvdata);
871-
if (ret < 0)
872-
goto unlock_sysfs_enable;
835+
drvdata->trcid = path->trace_id;
873836

874837
/*
875838
* Executing etm4_enable_hw on the cpu whose ETM is being enabled
@@ -886,7 +849,6 @@ static int etm4_enable_sysfs(struct coresight_device *csdev)
886849
if (ret)
887850
etm4_release_trace_id(drvdata);
888851

889-
unlock_sysfs_enable:
890852
spin_unlock(&drvdata->spinlock);
891853

892854
if (!ret)
@@ -895,7 +857,7 @@ static int etm4_enable_sysfs(struct coresight_device *csdev)
895857
}
896858

897859
static int etm4_enable(struct coresight_device *csdev, struct perf_event *event,
898-
enum cs_mode mode, struct coresight_trace_id_map *id_map)
860+
enum cs_mode mode, struct coresight_path *path)
899861
{
900862
int ret;
901863

@@ -906,10 +868,10 @@ static int etm4_enable(struct coresight_device *csdev, struct perf_event *event,
906868

907869
switch (mode) {
908870
case CS_MODE_SYSFS:
909-
ret = etm4_enable_sysfs(csdev);
871+
ret = etm4_enable_sysfs(csdev, path);
910872
break;
911873
case CS_MODE_PERF:
912-
ret = etm4_enable_perf(csdev, event, id_map);
874+
ret = etm4_enable_perf(csdev, event, path);
913875
break;
914876
default:
915877
ret = -EINVAL;

drivers/hwtracing/coresight/coresight-etm4x.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,5 @@ static inline bool etm4x_is_ete(struct etmv4_drvdata *drvdata)
10661066
return drvdata->arch >= ETM_ARCH_ETE;
10671067
}
10681068

1069-
int etm4_read_alloc_trace_id(struct etmv4_drvdata *drvdata);
10701069
void etm4_release_trace_id(struct etmv4_drvdata *drvdata);
10711070
#endif

drivers/hwtracing/coresight/coresight-stm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ static void stm_enable_hw(struct stm_drvdata *drvdata)
195195

196196
static int stm_enable(struct coresight_device *csdev, struct perf_event *event,
197197
enum cs_mode mode,
198-
__maybe_unused struct coresight_trace_id_map *trace_id)
198+
__maybe_unused struct coresight_path *path)
199199
{
200200
struct stm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
201201

drivers/hwtracing/coresight/coresight-sysfs.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ ssize_t coresight_simple_show32(struct device *_dev,
5353
EXPORT_SYMBOL_GPL(coresight_simple_show32);
5454

5555
static int coresight_enable_source_sysfs(struct coresight_device *csdev,
56-
enum cs_mode mode, void *data)
56+
enum cs_mode mode,
57+
struct coresight_path *path)
5758
{
5859
int ret;
5960

@@ -64,7 +65,7 @@ static int coresight_enable_source_sysfs(struct coresight_device *csdev,
6465
*/
6566
lockdep_assert_held(&coresight_mutex);
6667
if (coresight_get_mode(csdev) != CS_MODE_SYSFS) {
67-
ret = source_ops(csdev)->enable(csdev, data, mode, NULL);
68+
ret = source_ops(csdev)->enable(csdev, NULL, mode, path);
6869
if (ret)
6970
return ret;
7071
}
@@ -217,7 +218,7 @@ int coresight_enable_sysfs(struct coresight_device *csdev)
217218
if (ret)
218219
goto err_path;
219220

220-
ret = coresight_enable_source_sysfs(csdev, CS_MODE_SYSFS, NULL);
221+
ret = coresight_enable_source_sysfs(csdev, CS_MODE_SYSFS, path);
221222
if (ret)
222223
goto err_source;
223224

drivers/hwtracing/coresight/coresight-tpdm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ static void __tpdm_enable(struct tpdm_drvdata *drvdata)
480480

481481
static int tpdm_enable(struct coresight_device *csdev, struct perf_event *event,
482482
enum cs_mode mode,
483-
__maybe_unused struct coresight_trace_id_map *id_map)
483+
__maybe_unused struct coresight_path *path)
484484
{
485485
struct tpdm_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent);
486486

include/linux/coresight.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ struct coresight_ops_link {
401401
struct coresight_ops_source {
402402
int (*cpu_id)(struct coresight_device *csdev);
403403
int (*enable)(struct coresight_device *csdev, struct perf_event *event,
404-
enum cs_mode mode, struct coresight_trace_id_map *id_map);
404+
enum cs_mode mode, struct coresight_path *path);
405405
void (*disable)(struct coresight_device *csdev,
406406
struct perf_event *event);
407407
};

0 commit comments

Comments
 (0)