Skip to content

Commit bb8e370

Browse files
mathieupoirieracmel
authored andcommitted
coresight: perf: Add "sinks" group to PMU directory
Add a "sinks" directory entry so that users can see all the sinks available in the system in a single place. Individual sink are added as they are registered with the coresight bus. Committer tests: Test built on a ubuntu 18.04 container with a cross build environment to arm64, the new field is there, need to find a machine with this feature to do further testing in the future. root@d15263e5734a:/git/perf# grep CORESIGHT /tmp/build/v5.0-rc2+/.config CONFIG_CORESIGHT=y CONFIG_CORESIGHT_LINKS_AND_SINKS=y CONFIG_CORESIGHT_LINK_AND_SINK_TMC=y CONFIG_CORESIGHT_CATU=y CONFIG_CORESIGHT_SINK_TPIU=y CONFIG_CORESIGHT_SINK_ETBV10=y CONFIG_CORESIGHT_SOURCE_ETM4X=y CONFIG_CORESIGHT_DYNAMIC_REPLICATOR=y CONFIG_CORESIGHT_STM=y CONFIG_CORESIGHT_CPU_DEBUG=m root@d15263e5734a:/git/perf# root@d15263e5734a:/git/perf# file /tmp/build/v5.0-rc2+/drivers/hwtracing/coresight/*.o .../coresight/coresight-catu.o: ELF 64-bit MSB relocatable, ARM aarch64, version 1 (SYSV), not stripped .../coresight/coresight-cpu-debug.mod.o: ELF 64-bit MSB relocatable, ARM aarch64, version 1 (SYSV), not stripped .../coresight/coresight-cpu-debug.o: ELF 64-bit MSB relocatable, ARM aarch64, version 1 (SYSV), not stripped .../coresight/coresight-dynamic-replicator.o: ELF 64-bit MSB relocatable, ARM aarch64, version 1 (SYSV), not stripped .../coresight/coresight-etb10.o: ELF 64-bit MSB relocatable, ARM aarch64, version 1 (SYSV), not stripped .../coresight/coresight-etm-perf.o: ELF 64-bit MSB relocatable, ARM aarch64, version 1 (SYSV), not stripped .../coresight/coresight-etm4x-sysfs.o: ELF 64-bit MSB relocatable, ARM aarch64, version 1 (SYSV), not stripped .../coresight/coresight-etm4x.o: ELF 64-bit MSB relocatable, ARM aarch64, version 1 (SYSV), not stripped .../coresight/coresight-funnel.o: ELF 64-bit MSB relocatable, ARM aarch64, version 1 (SYSV), not stripped .../coresight/coresight-replicator.o: ELF 64-bit MSB relocatable, ARM aarch64, version 1 (SYSV), not stripped .../coresight/coresight-stm.o: ELF 64-bit MSB relocatable, ARM aarch64, version 1 (SYSV), not stripped .../coresight/coresight-tmc-etf.o: ELF 64-bit MSB relocatable, ARM aarch64, version 1 (SYSV), not stripped .../coresight/coresight-tmc-etr.o: ELF 64-bit MSB relocatable, ARM aarch64, version 1 (SYSV), not stripped .../coresight/coresight-tmc.o: ELF 64-bit MSB relocatable, ARM aarch64, version 1 (SYSV), not stripped .../coresight/coresight-tpiu.o: ELF 64-bit MSB relocatable, ARM aarch64, version 1 (SYSV), not stripped .../coresight/coresight.o: ELF 64-bit MSB relocatable, ARM aarch64, version 1 (SYSV), not stripped .../coresight/of_coresight.o: ELF 64-bit MSB relocatable, ARM aarch64, version 1 (SYSV), not stripped root@d15263e5734a:/git/perf# root@d15263e5734a:/git/perf# pahole -C coresight_device /tmp/build/v5.0-rc2+/drivers/hwtracing/coresight/coresight.o struct coresight_device { struct coresight_connection * conns; /* 0 8 */ int nr_inport; /* 8 4 */ int nr_outport; /* 12 4 */ enum coresight_dev_type type; /* 16 4 */ union coresight_dev_subtype subtype; /* 20 8 */ /* XXX 4 bytes hole, try to pack */ const struct coresight_ops * ops; /* 32 8 */ struct device dev; /* 40 1408 */ /* XXX last struct has 7 bytes of padding */ /* --- cacheline 22 boundary (1408 bytes) was 40 bytes ago --- */ atomic_t * refcnt; /* 1448 8 */ bool orphan; /* 1456 1 */ bool enable; /* 1457 1 */ bool activated; /* 1458 1 */ /* XXX 5 bytes hole, try to pack */ struct dev_ext_attribute * ea; /* 1464 8 */ /* size: 1472, cachelines: 23, members: 12 */ /* sum members: 1463, holes: 2, sum holes: 9 */ /* paddings: 1, sum paddings: 7 */ }; root@d15263e5734a:/git/perf# Signed-off-by: Mathieu Poirier <[email protected]> Reviewed-by: Suzuki K Poulose <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Alexei Starovoitov <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Martin Schwidefsky <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Thomas Gleixner <[email protected]> Cc: Will Deacon <[email protected]> Cc: [email protected] Cc: [email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 8400186 commit bb8e370

File tree

4 files changed

+110
-3
lines changed

4 files changed

+110
-3
lines changed

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

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/perf_event.h>
1515
#include <linux/percpu-defs.h>
1616
#include <linux/slab.h>
17+
#include <linux/stringhash.h>
1718
#include <linux/types.h>
1819
#include <linux/workqueue.h>
1920

@@ -43,8 +44,18 @@ static const struct attribute_group etm_pmu_format_group = {
4344
.attrs = etm_config_formats_attr,
4445
};
4546

47+
static struct attribute *etm_config_sinks_attr[] = {
48+
NULL,
49+
};
50+
51+
static const struct attribute_group etm_pmu_sinks_group = {
52+
.name = "sinks",
53+
.attrs = etm_config_sinks_attr,
54+
};
55+
4656
static const struct attribute_group *etm_pmu_attr_groups[] = {
4757
&etm_pmu_format_group,
58+
&etm_pmu_sinks_group,
4859
NULL,
4960
};
5061

@@ -479,6 +490,77 @@ int etm_perf_symlink(struct coresight_device *csdev, bool link)
479490
return 0;
480491
}
481492

493+
static ssize_t etm_perf_sink_name_show(struct device *dev,
494+
struct device_attribute *dattr,
495+
char *buf)
496+
{
497+
struct dev_ext_attribute *ea;
498+
499+
ea = container_of(dattr, struct dev_ext_attribute, attr);
500+
return scnprintf(buf, PAGE_SIZE, "0x%lx\n", (unsigned long)(ea->var));
501+
}
502+
503+
int etm_perf_add_symlink_sink(struct coresight_device *csdev)
504+
{
505+
int ret;
506+
unsigned long hash;
507+
const char *name;
508+
struct device *pmu_dev = etm_pmu.dev;
509+
struct device *pdev = csdev->dev.parent;
510+
struct dev_ext_attribute *ea;
511+
512+
if (csdev->type != CORESIGHT_DEV_TYPE_SINK &&
513+
csdev->type != CORESIGHT_DEV_TYPE_LINKSINK)
514+
return -EINVAL;
515+
516+
if (csdev->ea != NULL)
517+
return -EINVAL;
518+
519+
if (!etm_perf_up)
520+
return -EPROBE_DEFER;
521+
522+
ea = devm_kzalloc(pdev, sizeof(*ea), GFP_KERNEL);
523+
if (!ea)
524+
return -ENOMEM;
525+
526+
name = dev_name(pdev);
527+
/* See function coresight_get_sink_by_id() to know where this is used */
528+
hash = hashlen_hash(hashlen_string(NULL, name));
529+
530+
ea->attr.attr.name = devm_kstrdup(pdev, name, GFP_KERNEL);
531+
if (!ea->attr.attr.name)
532+
return -ENOMEM;
533+
534+
ea->attr.attr.mode = 0444;
535+
ea->attr.show = etm_perf_sink_name_show;
536+
ea->var = (unsigned long *)hash;
537+
538+
ret = sysfs_add_file_to_group(&pmu_dev->kobj,
539+
&ea->attr.attr, "sinks");
540+
541+
if (!ret)
542+
csdev->ea = ea;
543+
544+
return ret;
545+
}
546+
547+
void etm_perf_del_symlink_sink(struct coresight_device *csdev)
548+
{
549+
struct device *pmu_dev = etm_pmu.dev;
550+
struct dev_ext_attribute *ea = csdev->ea;
551+
552+
if (csdev->type != CORESIGHT_DEV_TYPE_SINK &&
553+
csdev->type != CORESIGHT_DEV_TYPE_LINKSINK)
554+
return;
555+
556+
if (!ea)
557+
return;
558+
559+
sysfs_remove_file_from_group(&pmu_dev->kobj,
560+
&ea->attr.attr, "sinks");
561+
csdev->ea = NULL;
562+
}
563+
482564
static int __init etm_perf_init(void)
483565
{
484566
int ret;

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ struct etm_event_data {
5959

6060
#ifdef CONFIG_CORESIGHT
6161
int etm_perf_symlink(struct coresight_device *csdev, bool link);
62+
int etm_perf_add_symlink_sink(struct coresight_device *csdev);
63+
void etm_perf_del_symlink_sink(struct coresight_device *csdev);
6264
static inline void *etm_perf_sink_config(struct perf_output_handle *handle)
6365
{
6466
struct etm_event_data *data = perf_get_aux(handle);
@@ -70,7 +72,9 @@ static inline void *etm_perf_sink_config(struct perf_output_handle *handle)
7072
#else
7173
static inline int etm_perf_symlink(struct coresight_device *csdev, bool link)
7274
{ return -EINVAL; }
73-
75+
int etm_perf_add_symlink_sink(struct coresight_device *csdev)
76+
{ return -EINVAL; }
77+
void etm_perf_del_symlink_sink(struct coresight_device *csdev) {}
7478
static inline void *etm_perf_sink_config(struct perf_output_handle *handle)
7579
{
7680
return NULL;

drivers/hwtracing/coresight/coresight.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/delay.h>
1919
#include <linux/pm_runtime.h>
2020

21+
#include "coresight-etm-perf.h"
2122
#include "coresight-priv.h"
2223

2324
static DEFINE_MUTEX(coresight_mutex);
@@ -1167,6 +1168,22 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
11671168
goto err_out;
11681169
}
11691170

1171+
if (csdev->type == CORESIGHT_DEV_TYPE_SINK ||
1172+
csdev->type == CORESIGHT_DEV_TYPE_LINKSINK) {
1173+
ret = etm_perf_add_symlink_sink(csdev);
1174+
1175+
if (ret) {
1176+
device_unregister(&csdev->dev);
1177+
/*
1178+
* As with the above, all resources are free'd
1179+
* explicitly via coresight_device_release() triggered
1180+
* from put_device(), which is in turn called from
1181+
* function device_unregister().
1182+
*/
1183+
goto err_out;
1184+
}
1185+
}
1186+
11701187
mutex_lock(&coresight_mutex);
11711188

11721189
coresight_fixup_device_conns(csdev);
@@ -1185,6 +1202,7 @@ EXPORT_SYMBOL_GPL(coresight_register);
11851202

11861203
void coresight_unregister(struct coresight_device *csdev)
11871204
{
1205+
etm_perf_del_symlink_sink(csdev);
11881206
/* Remove references of that device in the topology */
11891207
coresight_remove_conns(csdev);
11901208
device_unregister(&csdev->dev);

include/linux/coresight.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,9 @@ struct coresight_connection {
154154
* @orphan: true if the component has connections that haven't been linked.
155155
* @enable: 'true' if component is currently part of an active path.
156156
* @activated: 'true' only if a _sink_ has been activated. A sink can be
157-
activated but not yet enabled. Enabling for a _sink_
158-
happens when a source has been selected for that it.
157+
* activated but not yet enabled. Enabling for a _sink_
158+
* appens when a source has been selected for that it.
159+
* @ea: Device attribute for sink representation under PMU directory.
159160
*/
160161
struct coresight_device {
161162
struct coresight_connection *conns;
@@ -168,7 +169,9 @@ struct coresight_device {
168169
atomic_t *refcnt;
169170
bool orphan;
170171
bool enable; /* true only if configured as part of a path */
172+
/* sink specific fields */
171173
bool activated; /* true only if a sink is part of a path */
174+
struct dev_ext_attribute *ea;
172175
};
173176

174177
#define to_coresight_device(d) container_of(d, struct coresight_device, dev)

0 commit comments

Comments
 (0)