Skip to content

Commit b5390f4

Browse files
mathieupoiriergregkh
authored andcommitted
coresight: Use event attributes for sink selection
This patch uses the information conveyed by perf_event::attr::config2 to select a sink to use for the session. That way a sink can easily be selected to be used by more than one source, something that isn't currently possible with the sysfs implementation. Signed-off-by: Mathieu Poirier <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Reviewed-by: Suzuki K Poulose <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 988036f commit b5390f4

File tree

3 files changed

+55
-12
lines changed

3 files changed

+55
-12
lines changed

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ static DEFINE_PER_CPU(struct coresight_device *, csdev_src);
3131
PMU_FORMAT_ATTR(cycacc, "config:" __stringify(ETM_OPT_CYCACC));
3232
PMU_FORMAT_ATTR(timestamp, "config:" __stringify(ETM_OPT_TS));
3333
PMU_FORMAT_ATTR(retstack, "config:" __stringify(ETM_OPT_RETSTK));
34+
/* Sink ID - same for all ETMs */
35+
PMU_FORMAT_ATTR(sinkid, "config2:0-31");
3436

3537
static struct attribute *etm_config_formats_attr[] = {
3638
&format_attr_cycacc.attr,
3739
&format_attr_timestamp.attr,
3840
&format_attr_retstack.attr,
41+
&format_attr_sinkid.attr,
3942
NULL,
4043
};
4144

@@ -191,6 +194,7 @@ static void etm_free_aux(void *data)
191194
static void *etm_setup_aux(struct perf_event *event, void **pages,
192195
int nr_pages, bool overwrite)
193196
{
197+
u32 id;
194198
int cpu = event->cpu;
195199
cpumask_t *mask;
196200
struct coresight_device *sink;
@@ -201,18 +205,14 @@ static void *etm_setup_aux(struct perf_event *event, void **pages,
201205
return NULL;
202206
INIT_WORK(&event_data->work, free_event_data);
203207

204-
/*
205-
* In theory nothing prevent tracers in a trace session from being
206-
* associated with different sinks, nor having a sink per tracer. But
207-
* until we have HW with this kind of topology we need to assume tracers
208-
* in a trace session are using the same sink. Therefore go through
209-
* the coresight bus and pick the first enabled sink.
210-
*
211-
* When operated from sysFS users are responsible to enable the sink
212-
* while from perf, the perf tools will do it based on the choice made
213-
* on the cmd line. As such the "enable_sink" flag in sysFS is reset.
214-
*/
215-
sink = coresight_get_enabled_sink(true);
208+
/* First get the selected sink from user space. */
209+
if (event->attr.config2) {
210+
id = (u32)event->attr.config2;
211+
sink = coresight_get_sink_by_id(id);
212+
} else {
213+
sink = coresight_get_enabled_sink(true);
214+
}
215+
216216
if (!sink || !sink_ops(sink)->alloc_buffer)
217217
goto err;
218218

drivers/hwtracing/coresight/coresight-priv.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ void coresight_disable_path(struct list_head *path);
147147
int coresight_enable_path(struct list_head *path, u32 mode, void *sink_data);
148148
struct coresight_device *coresight_get_sink(struct list_head *path);
149149
struct coresight_device *coresight_get_enabled_sink(bool reset);
150+
struct coresight_device *coresight_get_sink_by_id(u32 id);
150151
struct list_head *coresight_build_path(struct coresight_device *csdev,
151152
struct coresight_device *sink);
152153
void coresight_release_path(struct list_head *path);

drivers/hwtracing/coresight/coresight.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <linux/err.h>
1212
#include <linux/export.h>
1313
#include <linux/slab.h>
14+
#include <linux/stringhash.h>
1415
#include <linux/mutex.h>
1516
#include <linux/clk.h>
1617
#include <linux/coresight.h>
@@ -541,6 +542,47 @@ struct coresight_device *coresight_get_enabled_sink(bool deactivate)
541542
return dev ? to_coresight_device(dev) : NULL;
542543
}
543544

545+
static int coresight_sink_by_id(struct device *dev, void *data)
546+
{
547+
struct coresight_device *csdev = to_coresight_device(dev);
548+
unsigned long hash;
549+
550+
if (csdev->type == CORESIGHT_DEV_TYPE_SINK ||
551+
csdev->type == CORESIGHT_DEV_TYPE_LINKSINK) {
552+
553+
if (!csdev->ea)
554+
return 0;
555+
/*
556+
* See function etm_perf_add_symlink_sink() to know where
557+
* this comes from.
558+
*/
559+
hash = (unsigned long)csdev->ea->var;
560+
561+
if ((u32)hash == *(u32 *)data)
562+
return 1;
563+
}
564+
565+
return 0;
566+
}
567+
568+
/**
569+
* coresight_get_sink_by_id - returns the sink that matches the id
570+
* @id: Id of the sink to match
571+
*
572+
* The name of a sink is unique, whether it is found on the AMBA bus or
573+
* otherwise. As such the hash of that name can easily be used to identify
574+
* a sink.
575+
*/
576+
struct coresight_device *coresight_get_sink_by_id(u32 id)
577+
{
578+
struct device *dev = NULL;
579+
580+
dev = bus_find_device(&coresight_bustype, NULL, &id,
581+
coresight_sink_by_id);
582+
583+
return dev ? to_coresight_device(dev) : NULL;
584+
}
585+
544586
/*
545587
* coresight_grab_device - Power up this device and any of the helper
546588
* devices connected to it for trace operation. Since the helper devices

0 commit comments

Comments
 (0)