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#
Unified · Split
| @@ -14,6 +14,7 @@ · 13 unmodified lines | ||
| 14 | 14 | #include <linux/perf_event.h> |
| 15 | 15 | #include <linux/percpu-defs.h> |
| 16 | 16 | #include <linux/slab.h> |
| 17 | +#include <linux/stringhash.h> | |
| 17 | 18 | #include <linux/types.h> |
| 18 | 19 | #include <linux/workqueue.h> |
| 19 | 20 | |
| @@ -43,8 +44,18 @@ static const struct attribute_group etm_pmu_format_group = { · 23 unmodified lines | ||
| 43 | 44 | .attrs = etm_config_formats_attr, |
| 44 | 45 | }; |
| 45 | 46 | |
| 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 | + | |
| 46 | 56 | static const struct attribute_group *etm_pmu_attr_groups[] = { |
| 47 | 57 | &etm_pmu_format_group, |
| 58 | + &etm_pmu_sinks_group, | |
| 48 | 59 | NULL, |
| 49 | 60 | }; |
| 50 | 61 | |
| @@ -479,6 +490,77 @@ int etm_perf_symlink(struct coresight_device *csdev, bool link) · 428 unmodified lines | ||
| 479 | 490 | return 0; |
| 480 | 491 | } |
| 481 | 492 | |
| 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 | + | |
| 482 | 564 | static int __init etm_perf_init(void) |
| 483 | 565 | { |
| 484 | 566 | int ret; |
| @@ -59,6 +59,8 @@ struct etm_event_data { · 58 unmodified lines | ||
| 59 | 59 | |
| 60 | 60 | #ifdef CONFIG_CORESIGHT |
| 61 | 61 | 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); | |
| 62 | 64 | static inline void *etm_perf_sink_config(struct perf_output_handle *handle) |
| 63 | 65 | { |
| 64 | 66 | 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) · 5 unmodified lines | ||
| 70 | 72 | #else |
| 71 | 73 | static inline int etm_perf_symlink(struct coresight_device *csdev, bool link) |
| 72 | 74 | { 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) {} | |
| 74 | 78 | static inline void *etm_perf_sink_config(struct perf_output_handle *handle) |
| 75 | 79 | { |
| 76 | 80 | return NULL; |
| @@ -18,6 +18,7 @@ · 17 unmodified lines | ||
| 18 | 18 | #include <linux/delay.h> |
| 19 | 19 | #include <linux/pm_runtime.h> |
| 20 | 20 | |
| 21 | +#include "coresight-etm-perf.h" | |
| 21 | 22 | #include "coresight-priv.h" |
| 22 | 23 | |
| 23 | 24 | static DEFINE_MUTEX(coresight_mutex); |
| @@ -1167,6 +1168,22 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) · 1143 unmodified lines | ||
| 1167 | 1168 | goto err_out; |
| 1168 | 1169 | } |
| 1169 | 1170 | |
| 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 | + | |
| 1170 | 1187 | mutex_lock(&coresight_mutex); |
| 1171 | 1188 | |
| 1172 | 1189 | coresight_fixup_device_conns(csdev); |
| @@ -1185,6 +1202,7 @@ EXPORT_SYMBOL_GPL(coresight_register); · 12 unmodified lines | ||
| 1185 | 1202 | |
| 1186 | 1203 | void coresight_unregister(struct coresight_device *csdev) |
| 1187 | 1204 | { |
| 1205 | + etm_perf_del_symlink_sink(csdev); | |
| 1188 | 1206 | /* Remove references of that device in the topology */ |
| 1189 | 1207 | coresight_remove_conns(csdev); |
| 1190 | 1208 | device_unregister(&csdev->dev); |
| @@ -154,8 +154,9 @@ struct coresight_connection { · 153 unmodified lines | ||
| 154 | 154 | * @orphan: true if the component has connections that haven't been linked. |
| 155 | 155 | * @enable: 'true' if component is currently part of an active path. |
| 156 | 156 | * @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. | |
| 159 | 160 | */ |
| 160 | 161 | struct coresight_device { |
| 161 | 162 | struct coresight_connection *conns; |
| @@ -168,7 +169,9 @@ struct coresight_device { · 6 unmodified lines | ||
| 168 | 169 | atomic_t *refcnt; |
| 169 | 170 | bool orphan; |
| 170 | 171 | bool enable; /* true only if configured as part of a path */ |
| 172 | + /* sink specific fields */ | |
| 171 | 173 | bool activated; /* true only if a sink is part of a path */ |
| 174 | + struct dev_ext_attribute *ea; | |
| 172 | 175 | }; |
| 173 | 176 | |
| 174 | 177 | #define to_coresight_device(d) container_of(d, struct coresight_device, dev) |