coresight: perf: Add "sinks" group to PMU directory
authorMathieu Poirier <mathieu.poirier@linaro.org>
Tue, 5 Feb 2019 23:24:57 +0000 (16:24 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 8 Feb 2019 11:27:36 +0000 (12:27 +0100)
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.

Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Suzuki K Poulose <suzuki.poulose@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/hwtracing/coresight/coresight-etm-perf.c
drivers/hwtracing/coresight/coresight-etm-perf.h
drivers/hwtracing/coresight/coresight.c
include/linux/coresight.h

index f21eb28b6782bb441eceee5212fe46fe4baf76d7..cdbdb28dc1753400fa8f2507c7637091af4b312e 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/perf_event.h>
 #include <linux/percpu-defs.h>
 #include <linux/slab.h>
+#include <linux/stringhash.h>
 #include <linux/types.h>
 #include <linux/workqueue.h>
 
@@ -43,8 +44,18 @@ static const struct attribute_group etm_pmu_format_group = {
        .attrs  = etm_config_formats_attr,
 };
 
+static struct attribute *etm_config_sinks_attr[] = {
+       NULL,
+};
+
+static const struct attribute_group etm_pmu_sinks_group = {
+       .name   = "sinks",
+       .attrs  = etm_config_sinks_attr,
+};
+
 static const struct attribute_group *etm_pmu_attr_groups[] = {
        &etm_pmu_format_group,
+       &etm_pmu_sinks_group,
        NULL,
 };
 
@@ -479,6 +490,77 @@ int etm_perf_symlink(struct coresight_device *csdev, bool link)
        return 0;
 }
 
+static ssize_t etm_perf_sink_name_show(struct device *dev,
+                                      struct device_attribute *dattr,
+                                      char *buf)
+{
+       struct dev_ext_attribute *ea;
+
+       ea = container_of(dattr, struct dev_ext_attribute, attr);
+       return scnprintf(buf, PAGE_SIZE, "0x%lx\n", (unsigned long)(ea->var));
+}
+
+int etm_perf_add_symlink_sink(struct coresight_device *csdev)
+{
+       int ret;
+       unsigned long hash;
+       const char *name;
+       struct device *pmu_dev = etm_pmu.dev;
+       struct device *pdev = csdev->dev.parent;
+       struct dev_ext_attribute *ea;
+
+       if (csdev->type != CORESIGHT_DEV_TYPE_SINK &&
+           csdev->type != CORESIGHT_DEV_TYPE_LINKSINK)
+               return -EINVAL;
+
+       if (csdev->ea != NULL)
+               return -EINVAL;
+
+       if (!etm_perf_up)
+               return -EPROBE_DEFER;
+
+       ea = devm_kzalloc(pdev, sizeof(*ea), GFP_KERNEL);
+       if (!ea)
+               return -ENOMEM;
+
+       name = dev_name(pdev);
+       /* See function coresight_get_sink_by_id() to know where this is used */
+       hash = hashlen_hash(hashlen_string(NULL, name));
+
+       ea->attr.attr.name = devm_kstrdup(pdev, name, GFP_KERNEL);
+       if (!ea->attr.attr.name)
+               return -ENOMEM;
+
+       ea->attr.attr.mode = 0444;
+       ea->attr.show = etm_perf_sink_name_show;
+       ea->var = (unsigned long *)hash;
+
+       ret = sysfs_add_file_to_group(&pmu_dev->kobj,
+                                     &ea->attr.attr, "sinks");
+
+       if (!ret)
+               csdev->ea = ea;
+
+       return ret;
+}
+
+void etm_perf_del_symlink_sink(struct coresight_device *csdev)
+{
+       struct device *pmu_dev = etm_pmu.dev;
+       struct dev_ext_attribute *ea = csdev->ea;
+
+       if (csdev->type != CORESIGHT_DEV_TYPE_SINK &&
+           csdev->type != CORESIGHT_DEV_TYPE_LINKSINK)
+               return;
+
+       if (!ea)
+               return;
+
+       sysfs_remove_file_from_group(&pmu_dev->kobj,
+                                    &ea->attr.attr, "sinks");
+       csdev->ea = NULL;
+}
+
 static int __init etm_perf_init(void)
 {
        int ret;
index da7d9336a15c5b7b133e9e81513ce98c95e88180..015213abe00a716b08142c7780658d8f6ce23989 100644 (file)
@@ -59,6 +59,8 @@ struct etm_event_data {
 
 #ifdef CONFIG_CORESIGHT
 int etm_perf_symlink(struct coresight_device *csdev, bool link);
+int etm_perf_add_symlink_sink(struct coresight_device *csdev);
+void etm_perf_del_symlink_sink(struct coresight_device *csdev);
 static inline void *etm_perf_sink_config(struct perf_output_handle *handle)
 {
        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)
 #else
 static inline int etm_perf_symlink(struct coresight_device *csdev, bool link)
 { return -EINVAL; }
-
+int etm_perf_add_symlink_sink(struct coresight_device *csdev)
+{ return -EINVAL; }
+void etm_perf_del_symlink_sink(struct coresight_device *csdev) {}
 static inline void *etm_perf_sink_config(struct perf_output_handle *handle)
 {
        return NULL;
index 2b0df1a0a8df4c8c463e8169fa73b5e279330b60..d7fa90be6f42e53d19f576c36714aba5f1c5aa51 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/delay.h>
 #include <linux/pm_runtime.h>
 
+#include "coresight-etm-perf.h"
 #include "coresight-priv.h"
 
 static DEFINE_MUTEX(coresight_mutex);
@@ -1167,6 +1168,22 @@ struct coresight_device *coresight_register(struct coresight_desc *desc)
                goto err_out;
        }
 
+       if (csdev->type == CORESIGHT_DEV_TYPE_SINK ||
+           csdev->type == CORESIGHT_DEV_TYPE_LINKSINK) {
+               ret = etm_perf_add_symlink_sink(csdev);
+
+               if (ret) {
+                       device_unregister(&csdev->dev);
+                       /*
+                        * As with the above, all resources are free'd
+                        * explicitly via coresight_device_release() triggered
+                        * from put_device(), which is in turn called from
+                        * function device_unregister().
+                        */
+                       goto err_out;
+               }
+       }
+
        mutex_lock(&coresight_mutex);
 
        coresight_fixup_device_conns(csdev);
@@ -1185,6 +1202,7 @@ EXPORT_SYMBOL_GPL(coresight_register);
 
 void coresight_unregister(struct coresight_device *csdev)
 {
+       etm_perf_del_symlink_sink(csdev);
        /* Remove references of that device in the topology */
        coresight_remove_conns(csdev);
        device_unregister(&csdev->dev);
index 46c67a7648778d8e7e1b0793bd8683567d132fce..7b87965f7a65c90d8e98f11b14ab5b5b1f967abb 100644 (file)
@@ -154,8 +154,9 @@ struct coresight_connection {
  * @orphan:    true if the component has connections that haven't been linked.
  * @enable:    'true' if component is currently part of an active path.
  * @activated: 'true' only if a _sink_ has been activated.  A sink can be
-               activated but not yet enabled.  Enabling for a _sink_
-               happens when a source has been selected for that it.
+ *             activated but not yet enabled.  Enabling for a _sink_
+ *             appens when a source has been selected for that it.
+ * @ea:                Device attribute for sink representation under PMU directory.
  */
 struct coresight_device {
        struct coresight_connection *conns;
@@ -168,7 +169,9 @@ struct coresight_device {
        atomic_t *refcnt;
        bool orphan;
        bool enable;    /* true only if configured as part of a path */
+       /* sink specific fields */
        bool activated; /* true only if a sink is part of a path */
+       struct dev_ext_attribute *ea;
 };
 
 #define to_coresight_device(d) container_of(d, struct coresight_device, dev)