Skip to content

Commit 94d2bac

Browse files
mikel-armbbgregkh
authored andcommitted
coresight: etm-perf: Update to handle configuration selection
Loaded coresight configurations are registered in the cs_etm\events sub directory. This extends the etm-perf code to handle these registrations, and the cs_syscfg driver to perform the registration on load. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mike Leach <[email protected]> Signed-off-by: Mathieu Poirier <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent f53e93a commit 94d2bac

File tree

4 files changed

+127
-28
lines changed

4 files changed

+127
-28
lines changed

drivers/hwtracing/coresight/coresight-config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ struct cscfg_feature_desc {
126126
* @nr_presets: Number of sets of presets supplied by this configuration.
127127
* @nr_total_params: Sum of all parameters declared by used features
128128
* @presets: Array of preset values.
129+
* @event_ea: Extended attribute for perf event value
129130
*
130131
*/
131132
struct cscfg_config_desc {
@@ -137,6 +138,7 @@ struct cscfg_config_desc {
137138
int nr_presets;
138139
int nr_total_params;
139140
const u64 *presets; /* nr_presets * nr_total_params */
141+
struct dev_ext_attribute *event_ea;
140142
};
141143

142144
/**

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

Lines changed: 106 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
#include <linux/types.h>
1919
#include <linux/workqueue.h>
2020

21+
#include "coresight-config.h"
2122
#include "coresight-etm-perf.h"
2223
#include "coresight-priv.h"
24+
#include "coresight-syscfg.h"
2325

2426
static struct pmu etm_pmu;
2527
static bool etm_perf_up;
@@ -57,8 +59,13 @@ PMU_FORMAT_ATTR(contextid1, "config:" __stringify(ETM_OPT_CTXTID));
5759
PMU_FORMAT_ATTR(contextid2, "config:" __stringify(ETM_OPT_CTXTID2));
5860
PMU_FORMAT_ATTR(timestamp, "config:" __stringify(ETM_OPT_TS));
5961
PMU_FORMAT_ATTR(retstack, "config:" __stringify(ETM_OPT_RETSTK));
62+
/* preset - if sink ID is used as a configuration selector */
63+
PMU_FORMAT_ATTR(preset, "config:0-3");
6064
/* Sink ID - same for all ETMs */
6165
PMU_FORMAT_ATTR(sinkid, "config2:0-31");
66+
/* config ID - set if a system configuration is selected */
67+
PMU_FORMAT_ATTR(configid, "config2:32-63");
68+
6269

6370
/*
6471
* contextid always traces the "PID". The PID is in CONTEXTIDR_EL1
@@ -88,6 +95,8 @@ static struct attribute *etm_config_formats_attr[] = {
8895
&format_attr_timestamp.attr,
8996
&format_attr_retstack.attr,
9097
&format_attr_sinkid.attr,
98+
&format_attr_preset.attr,
99+
&format_attr_configid.attr,
91100
NULL,
92101
};
93102

@@ -105,9 +114,19 @@ static const struct attribute_group etm_pmu_sinks_group = {
105114
.attrs = etm_config_sinks_attr,
106115
};
107116

117+
static struct attribute *etm_config_events_attr[] = {
118+
NULL,
119+
};
120+
121+
static const struct attribute_group etm_pmu_events_group = {
122+
.name = "events",
123+
.attrs = etm_config_events_attr,
124+
};
125+
108126
static const struct attribute_group *etm_pmu_attr_groups[] = {
109127
&etm_pmu_format_group,
110128
&etm_pmu_sinks_group,
129+
&etm_pmu_events_group,
111130
NULL,
112131
};
113132

@@ -286,7 +305,7 @@ static void *etm_setup_aux(struct perf_event *event, void **pages,
286305
INIT_WORK(&event_data->work, free_event_data);
287306

288307
/* First get the selected sink from user space. */
289-
if (event->attr.config2) {
308+
if (event->attr.config2 & GENMASK_ULL(31, 0)) {
290309
id = (u32)event->attr.config2;
291310
sink = user_sink = coresight_get_sink_by_id(id);
292311
}
@@ -658,68 +677,127 @@ static ssize_t etm_perf_sink_name_show(struct device *dev,
658677
return scnprintf(buf, PAGE_SIZE, "0x%lx\n", (unsigned long)(ea->var));
659678
}
660679

661-
int etm_perf_add_symlink_sink(struct coresight_device *csdev)
680+
static struct dev_ext_attribute *
681+
etm_perf_add_symlink_group(struct device *dev, const char *name, const char *group_name)
662682
{
663-
int ret;
683+
struct dev_ext_attribute *ea;
664684
unsigned long hash;
665-
const char *name;
685+
int ret;
666686
struct device *pmu_dev = etm_pmu.dev;
667-
struct device *dev = &csdev->dev;
668-
struct dev_ext_attribute *ea;
669-
670-
if (csdev->type != CORESIGHT_DEV_TYPE_SINK &&
671-
csdev->type != CORESIGHT_DEV_TYPE_LINKSINK)
672-
return -EINVAL;
673-
674-
if (csdev->ea != NULL)
675-
return -EINVAL;
676687

677688
if (!etm_perf_up)
678-
return -EPROBE_DEFER;
689+
return ERR_PTR(-EPROBE_DEFER);
679690

680691
ea = devm_kzalloc(dev, sizeof(*ea), GFP_KERNEL);
681692
if (!ea)
682-
return -ENOMEM;
693+
return ERR_PTR(-ENOMEM);
683694

684-
name = dev_name(dev);
685-
/* See function coresight_get_sink_by_id() to know where this is used */
695+
/*
696+
* If this function is called adding a sink then the hash is used for
697+
* sink selection - see function coresight_get_sink_by_id().
698+
* If adding a configuration then the hash is used for selection in
699+
* cscfg_activate_config()
700+
*/
686701
hash = hashlen_hash(hashlen_string(NULL, name));
687702

688703
sysfs_attr_init(&ea->attr.attr);
689704
ea->attr.attr.name = devm_kstrdup(dev, name, GFP_KERNEL);
690705
if (!ea->attr.attr.name)
691-
return -ENOMEM;
706+
return ERR_PTR(-ENOMEM);
692707

693708
ea->attr.attr.mode = 0444;
694-
ea->attr.show = etm_perf_sink_name_show;
695709
ea->var = (unsigned long *)hash;
696710

697711
ret = sysfs_add_file_to_group(&pmu_dev->kobj,
698-
&ea->attr.attr, "sinks");
712+
&ea->attr.attr, group_name);
699713

700-
if (!ret)
701-
csdev->ea = ea;
714+
return ret ? ERR_PTR(ret) : ea;
715+
}
702716

703-
return ret;
717+
int etm_perf_add_symlink_sink(struct coresight_device *csdev)
718+
{
719+
const char *name;
720+
struct device *dev = &csdev->dev;
721+
int err = 0;
722+
723+
if (csdev->type != CORESIGHT_DEV_TYPE_SINK &&
724+
csdev->type != CORESIGHT_DEV_TYPE_LINKSINK)
725+
return -EINVAL;
726+
727+
if (csdev->ea != NULL)
728+
return -EINVAL;
729+
730+
name = dev_name(dev);
731+
csdev->ea = etm_perf_add_symlink_group(dev, name, "sinks");
732+
if (IS_ERR(csdev->ea)) {
733+
err = PTR_ERR(csdev->ea);
734+
csdev->ea = NULL;
735+
} else
736+
csdev->ea->attr.show = etm_perf_sink_name_show;
737+
738+
return err;
704739
}
705740

706-
void etm_perf_del_symlink_sink(struct coresight_device *csdev)
741+
static void etm_perf_del_symlink_group(struct dev_ext_attribute *ea, const char *group_name)
707742
{
708743
struct device *pmu_dev = etm_pmu.dev;
709-
struct dev_ext_attribute *ea = csdev->ea;
710744

745+
sysfs_remove_file_from_group(&pmu_dev->kobj,
746+
&ea->attr.attr, group_name);
747+
}
748+
749+
void etm_perf_del_symlink_sink(struct coresight_device *csdev)
750+
{
711751
if (csdev->type != CORESIGHT_DEV_TYPE_SINK &&
712752
csdev->type != CORESIGHT_DEV_TYPE_LINKSINK)
713753
return;
714754

715-
if (!ea)
755+
if (!csdev->ea)
716756
return;
717757

718-
sysfs_remove_file_from_group(&pmu_dev->kobj,
719-
&ea->attr.attr, "sinks");
758+
etm_perf_del_symlink_group(csdev->ea, "sinks");
720759
csdev->ea = NULL;
721760
}
722761

762+
static ssize_t etm_perf_cscfg_event_show(struct device *dev,
763+
struct device_attribute *dattr,
764+
char *buf)
765+
{
766+
struct dev_ext_attribute *ea;
767+
768+
ea = container_of(dattr, struct dev_ext_attribute, attr);
769+
return scnprintf(buf, PAGE_SIZE, "configid=0x%lx\n", (unsigned long)(ea->var));
770+
}
771+
772+
int etm_perf_add_symlink_cscfg(struct device *dev, struct cscfg_config_desc *config_desc)
773+
{
774+
int err = 0;
775+
776+
if (config_desc->event_ea != NULL)
777+
return 0;
778+
779+
config_desc->event_ea = etm_perf_add_symlink_group(dev, config_desc->name, "events");
780+
781+
/* set the show function to the custom cscfg event */
782+
if (!IS_ERR(config_desc->event_ea))
783+
config_desc->event_ea->attr.show = etm_perf_cscfg_event_show;
784+
else {
785+
err = PTR_ERR(config_desc->event_ea);
786+
config_desc->event_ea = NULL;
787+
}
788+
789+
return err;
790+
}
791+
792+
void etm_perf_del_symlink_cscfg(struct cscfg_config_desc *config_desc)
793+
{
794+
if (!config_desc->event_ea)
795+
return;
796+
797+
etm_perf_del_symlink_group(config_desc->event_ea, "events");
798+
config_desc->event_ea = NULL;
799+
}
800+
723801
int __init etm_perf_init(void)
724802
{
725803
int ret;

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "coresight-priv.h"
1212

1313
struct coresight_device;
14+
struct cscfg_config_desc;
1415

1516
/*
1617
* In both ETMv3 and v4 the maximum number of address comparator implentable
@@ -69,6 +70,9 @@ static inline void *etm_perf_sink_config(struct perf_output_handle *handle)
6970
return data->snk_config;
7071
return NULL;
7172
}
73+
int etm_perf_add_symlink_cscfg(struct device *dev,
74+
struct cscfg_config_desc *config_desc);
75+
void etm_perf_del_symlink_cscfg(struct cscfg_config_desc *config_desc);
7276
#else
7377
static inline int etm_perf_symlink(struct coresight_device *csdev, bool link)
7478
{ return -EINVAL; }
@@ -79,6 +83,10 @@ static inline void *etm_perf_sink_config(struct perf_output_handle *handle)
7983
{
8084
return NULL;
8185
}
86+
int etm_perf_add_symlink_cscfg(struct device *dev,
87+
struct cscfg_config_desc *config_desc)
88+
{ return -EINVAL; }
89+
void etm_perf_del_symlink_cscfg(struct cscfg_config_desc *config_desc) {}
8290

8391
#endif /* CONFIG_CORESIGHT */
8492

drivers/hwtracing/coresight/coresight-syscfg.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/platform_device.h>
88

99
#include "coresight-config.h"
10+
#include "coresight-etm-perf.h"
1011
#include "coresight-syscfg.h"
1112

1213
/*
@@ -275,6 +276,11 @@ static int cscfg_load_config(struct cscfg_config_desc *config_desc)
275276
if (err)
276277
return err;
277278

279+
/* add config to perf fs to allow selection */
280+
err = etm_perf_add_symlink_cscfg(cscfg_device(), config_desc);
281+
if (err)
282+
return err;
283+
278284
list_add(&config_desc->item, &cscfg_mgr->config_desc_list);
279285
return 0;
280286
}
@@ -508,7 +514,12 @@ static int cscfg_create_device(void)
508514

509515
static void cscfg_clear_device(void)
510516
{
517+
struct cscfg_config_desc *cfg_desc;
518+
511519
mutex_lock(&cscfg_mutex);
520+
list_for_each_entry(cfg_desc, &cscfg_mgr->config_desc_list, item) {
521+
etm_perf_del_symlink_cscfg(cfg_desc);
522+
}
512523
device_unregister(cscfg_device());
513524
mutex_unlock(&cscfg_mutex);
514525
}

0 commit comments

Comments
 (0)