All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mike Leach <mike.leach@linaro.org>
To: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	Coresight ML <coresight@lists.linaro.org>,
	"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
	"Suzuki K. Poulose" <suzuki.poulose@arm.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Yabin Cui <yabinc@google.com>, Jonathan Corbet <corbet@lwn.net>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Tingwei Zhang <tingwei@codeaurora.org>,
	Leo Yan <leo.yan@linaro.org>
Subject: Re: [PATCH v4 04/10] coresight: etm-perf: update to handle configuration selection
Date: Fri, 26 Feb 2021 19:26:23 +0000	[thread overview]
Message-ID: <CAJ9a7VhgmTN+t80_Dd0UsNwwJo8MLR5qYHu40HmNaFRNDrP34A@mail.gmail.com> (raw)
In-Reply-To: <20210224183313.GC3237327@xps15>

HI Mathieu.

On Wed, 24 Feb 2021 at 18:33, Mathieu Poirier
<mathieu.poirier@linaro.org> wrote:
>
> On Thu, Jan 28, 2021 at 05:09:30PM +0000, Mike Leach wrote:
> > Loaded coresight configurations are registered in the cs_etm\cs_config sub
> > directory. This extends the etm-perf code to handle these registrations,
> > and the cs_syscfg driver to perform the registration on load.
> >
> > Signed-off-by: Mike Leach <mike.leach@linaro.org>
> > ---
> >  .../hwtracing/coresight/coresight-config.h    |   5 +-
> >  .../hwtracing/coresight/coresight-etm-perf.c  | 164 +++++++++++++++---
> >  .../hwtracing/coresight/coresight-etm-perf.h  |   8 +
> >  .../hwtracing/coresight/coresight-syscfg.c    |  13 +-
> >  4 files changed, 166 insertions(+), 24 deletions(-)
> >
> > diff --git a/drivers/hwtracing/coresight/coresight-config.h b/drivers/hwtracing/coresight/coresight-config.h
> > index 9d66e0071f38..98380b496046 100644
> > --- a/drivers/hwtracing/coresight/coresight-config.h
> > +++ b/drivers/hwtracing/coresight/coresight-config.h
> > @@ -154,7 +154,8 @@ struct cscfg_config_feat_ref {
> >   * @nr_presets:      Number of sets of presets supplied by this configuration.
> >   * @nr_total_params: Sum of all parameters declared by used features
> >   * @presets: Array of preset values.
> > - *
> > + * @id_ea:   Extended attribute for perf configid value
> > + * @event_ea:        Extended attribute for perf event value
> >   */
> >  struct cscfg_config_desc {
> >       const char *name;
> > @@ -165,6 +166,8 @@ struct cscfg_config_desc {
> >       int nr_presets;
> >       int nr_total_params;
> >       const u64 *presets; /* nr_presets * nr_total_params */
> > +     struct dev_ext_attribute *id_ea;
> > +     struct dev_ext_attribute *event_ea;
> >  };
> >
> >  /**
> > diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c
> > index a608081bd446..e270bb1e0f7d 100644
> > --- a/drivers/hwtracing/coresight/coresight-etm-perf.c
> > +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
> > @@ -18,8 +18,10 @@
> >  #include <linux/types.h>
> >  #include <linux/workqueue.h>
> >
> > +#include "coresight-config.h"
> >  #include "coresight-etm-perf.h"
> >  #include "coresight-priv.h"
> > +#include "coresight-syscfg.h"
> >
> >  static struct pmu etm_pmu;
> >  static bool etm_perf_up;
> > @@ -32,8 +34,13 @@ PMU_FORMAT_ATTR(cycacc,            "config:" __stringify(ETM_OPT_CYCACC));
> >  PMU_FORMAT_ATTR(contextid,   "config:" __stringify(ETM_OPT_CTXTID));
> >  PMU_FORMAT_ATTR(timestamp,   "config:" __stringify(ETM_OPT_TS));
> >  PMU_FORMAT_ATTR(retstack,    "config:" __stringify(ETM_OPT_RETSTK));
> > +/* preset - if sink ID is used as a configuration selector */
> > +PMU_FORMAT_ATTR(preset,              "config:0-3");
> >  /* Sink ID - same for all ETMs */
> >  PMU_FORMAT_ATTR(sinkid,              "config2:0-31");
> > +/* config ID - set if a system configuration is selected */
> > +PMU_FORMAT_ATTR(configid,    "config2:32-63");
> > +
> >
> >  static struct attribute *etm_config_formats_attr[] = {
> >       &format_attr_cycacc.attr,
> > @@ -41,6 +48,8 @@ static struct attribute *etm_config_formats_attr[] = {
> >       &format_attr_timestamp.attr,
> >       &format_attr_retstack.attr,
> >       &format_attr_sinkid.attr,
> > +     &format_attr_preset.attr,
> > +     &format_attr_configid.attr,
> >       NULL,
> >  };
> >
> > @@ -58,9 +67,29 @@ static const struct attribute_group etm_pmu_sinks_group = {
> >       .attrs  = etm_config_sinks_attr,
> >  };
> >
> > +static struct attribute *etm_config_cscfg_attr[] = {
> > +     NULL,
> > +};
> > +
> > +static const struct attribute_group etm_pmu_cscfg_group = {
> > +     .name   = "configurations",
> > +     .attrs  = etm_config_cscfg_attr,
> > +};
> > +
> > +static struct attribute *etm_config_events_attr[] = {
> > +     NULL,
> > +};
> > +
> > +static const struct attribute_group etm_pmu_events_group = {
> > +     .name   = "events",
> > +     .attrs  = etm_config_events_attr,
> > +};
> > +
> >  static const struct attribute_group *etm_pmu_attr_groups[] = {
> >       &etm_pmu_format_group,
> >       &etm_pmu_sinks_group,
> > +     &etm_pmu_cscfg_group,
> > +     &etm_pmu_events_group,
> >       NULL,
> >  };
> >
> > @@ -219,7 +248,7 @@ static void *etm_setup_aux(struct perf_event *event, void **pages,
> >       INIT_WORK(&event_data->work, free_event_data);
> >
> >       /* First get the selected sink from user space. */
> > -     if (event->attr.config2) {
> > +     if (event->attr.config2 & GENMASK_ULL(31, 0)) {
> >               id = (u32)event->attr.config2;
> >               sink = coresight_get_sink_by_id(id);
> >       }
> > @@ -537,21 +566,17 @@ static ssize_t etm_perf_sink_name_show(struct device *dev,
>
> I would rename this to etm_perf_name_show() so that it doesn't look bizarre when
> finding it in etm_perf_add_symlink_group().
>
OK.

> >       return scnprintf(buf, PAGE_SIZE, "0x%lx\n", (unsigned long)(ea->var));
> >  }
> >
> > -int etm_perf_add_symlink_sink(struct coresight_device *csdev)
> > +int etm_perf_add_symlink_group(struct device *dev,
> > +                            struct dev_ext_attribute **ext_attr,
> > +                            const char *name,
> > +                            const char *group_name)
> >  {
> > -     int ret;
> > +     struct dev_ext_attribute *ea;
> >       unsigned long hash;
> > -     const char *name;
> > +     int ret;
> >       struct device *pmu_dev = etm_pmu.dev;
> > -     struct device *dev = &csdev->dev;
> > -     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;
> > +     *ext_attr = NULL;
> >
> >       if (!etm_perf_up)
> >               return -EPROBE_DEFER;
> > @@ -560,7 +585,6 @@ int etm_perf_add_symlink_sink(struct coresight_device *csdev)
> >       if (!ea)
> >               return -ENOMEM;
> >
> > -     name = dev_name(dev);
> >       /* See function coresight_get_sink_by_id() to know where this is used */
>
> I would also update this comment.  If @name is a sink then the hash will be
> used in coresight_get_sink_by_id(), and if it is a configuration it will be used
> in etm_perf_add_cscfg_event() and cscfg_activate_config().
>

OK.

> >       hash = hashlen_hash(hashlen_string(NULL, name));
> >
> > @@ -574,31 +598,127 @@ int etm_perf_add_symlink_sink(struct coresight_device *csdev)
> >       ea->var = (unsigned long *)hash;
> >
> >       ret = sysfs_add_file_to_group(&pmu_dev->kobj,
> > -                                   &ea->attr.attr, "sinks");
> > -
> > +                                   &ea->attr.attr, group_name);
> >       if (!ret)
> > -             csdev->ea = ea;
> > -
> > +             *ext_attr = ea;
> >       return ret;
> >  }
> >
> > -void etm_perf_del_symlink_sink(struct coresight_device *csdev)
> > +int etm_perf_add_symlink_sink(struct coresight_device *csdev)
> > +{
> > +     const char *name;
> > +     struct device *dev = &csdev->dev;
> > +
> > +     if (csdev->type != CORESIGHT_DEV_TYPE_SINK &&
> > +         csdev->type != CORESIGHT_DEV_TYPE_LINKSINK)
> > +             return -EINVAL;
> > +
> > +     if (csdev->ea != NULL)
> > +             return -EINVAL;
> > +
> > +     name = dev_name(dev);
> > +     return etm_perf_add_symlink_group(dev, &csdev->ea, name, "sinks");
> > +}
> > +
> > +void etm_perf_del_symlink_group(struct dev_ext_attribute *ea, const char *group_name)
> >  {
> >       struct device *pmu_dev = etm_pmu.dev;
> > -     struct dev_ext_attribute *ea = csdev->ea;
> >
> > +     sysfs_remove_file_from_group(&pmu_dev->kobj,
> > +                                  &ea->attr.attr, group_name);
> > +}
> > +
> > +void etm_perf_del_symlink_sink(struct coresight_device *csdev)
> > +{
> >       if (csdev->type != CORESIGHT_DEV_TYPE_SINK &&
> >           csdev->type != CORESIGHT_DEV_TYPE_LINKSINK)
> >               return;
> >
> > -     if (!ea)
> > +     if (!csdev->ea)
> >               return;
> >
> > -     sysfs_remove_file_from_group(&pmu_dev->kobj,
> > -                                  &ea->attr.attr, "sinks");
> > +     etm_perf_del_symlink_group(csdev->ea, "sinks");
> >       csdev->ea = NULL;
> >  }
> >
> > +/* string to contain the attribute value */
> > +#define CSCFG_EVENT_STR_SIZE 32
> > +
> > +static ssize_t etm_perf_cscfg_event_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, "%s\n", (const char *)(ea->var));
> > +}
> > +
> > +static int etm_perf_add_cscfg_event(struct device *dev, struct cscfg_config_desc *cs_cfg)
> > +{
> > +     struct dev_ext_attribute *ea;
> > +     unsigned long hash;
> > +     int ret;
> > +     struct device *pmu_dev = etm_pmu.dev;
> > +
> > +     ea = devm_kzalloc(dev, sizeof(*ea), GFP_KERNEL);
> > +     if (!ea)
> > +             return -ENOMEM;
> > +
> > +     hash = (unsigned long)cs_cfg->id_ea->var;
> > +
> > +     sysfs_attr_init(&ea->attr.attr);
> > +     ea->attr.attr.name = devm_kstrdup(dev, cs_cfg->name, GFP_KERNEL);
> > +     if (!ea->attr.attr.name)
> > +             return -ENOMEM;
> > +
> > +     /*
> > +      * attribute value is "configid=<hash>".
> > +      * this will be what perf evaluates when the config name is used
> > +      * on the command line.
> > +      */
> > +     ea->var = devm_kzalloc(dev, CSCFG_EVENT_STR_SIZE, GFP_KERNEL);
> > +     if (!ea->var)
> > +             return -ENOMEM;
> > +
> > +     scnprintf(ea->var, CSCFG_EVENT_STR_SIZE, "configid=0x%lx", hash);
> > +     ea->attr.attr.mode = 0444;
> > +     ea->attr.show = etm_perf_cscfg_event_show;
> > +
> > +     ret = sysfs_add_file_to_group(&pmu_dev->kobj,
> > +                                   &ea->attr.attr, "events");
> > +     if (!ret)
> > +             cs_cfg->event_ea = ea;
> > +     return ret;
> > +}
> > +
> > +int etm_perf_add_symlink_cscfg(struct device *dev, struct cscfg_config_desc *cs_cfg)
> > +{
> > +     int err;
> > +
> > +     if (cs_cfg->id_ea != NULL)
> > +             return 0;
> > +
> > +     err = etm_perf_add_symlink_group(dev, &cs_cfg->id_ea,
> > +                                      cs_cfg->name, "configurations");
>
> Do we need configurations to be advertised under
> /sys/bus/event_source/devices/cs_etm given that they are already found in
> /sys/kernel/config/coresight-syscfg?  And the events already carry the hash if
> someone is really keen using the "configid=" syntax.
>
> In my opinion we can get by with what is in configfs and do away with the
> "configurations" directory here.
>

Agreed - since stuff is now in events then this does become redundant.

> > +
> > +     if (!err)
> > +             err = etm_perf_add_cscfg_event(dev, cs_cfg);
> > +
>
> That we definitely need.
>
> Thanks,
> Mathieu
>
> > +     return err;
> > +}
> > +
> > +void etm_perf_del_symlink_cscfg(struct cscfg_config_desc *cs_cfg)
> > +{
> > +     if (!cs_cfg->id_ea)
> > +             return;
> > +
> > +     etm_perf_del_symlink_group(cs_cfg->id_ea, "configurations");
> > +     etm_perf_del_symlink_group(cs_cfg->event_ea, "events");
> > +     cs_cfg->id_ea = NULL;
> > +     cs_cfg->event_ea = NULL;
> > +}
> > +
> >  int __init etm_perf_init(void)
> >  {
> >       int ret;
> > diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.h b/drivers/hwtracing/coresight/coresight-etm-perf.h
> > index 29d90dfeba31..3646a3837a0b 100644
> > --- a/drivers/hwtracing/coresight/coresight-etm-perf.h
> > +++ b/drivers/hwtracing/coresight/coresight-etm-perf.h
> > @@ -11,6 +11,7 @@
> >  #include "coresight-priv.h"
> >
> >  struct coresight_device;
> > +struct cscfg_config_desc;
> >
> >  /*
> >   * 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)
> >               return data->snk_config;
> >       return NULL;
> >  }
> > +int etm_perf_add_symlink_cscfg(struct device *dev,
> > +                            struct cscfg_config_desc *cscfg_desc);
> > +void etm_perf_del_symlink_cscfg(struct cscfg_config_desc *cscfg_desc);
> >  #else
> >  static inline int etm_perf_symlink(struct coresight_device *csdev, bool link)
> >  { return -EINVAL; }
> > @@ -79,6 +83,10 @@ static inline void *etm_perf_sink_config(struct perf_output_handle *handle)
> >  {
> >       return NULL;
> >  }
> > +int etm_perf_add_symlink_cscfg(struct device *dev,
> > +                            struct cscfg_config_desc *cscfg_desc)
> > +{ return -EINVAL; }
> > +void etm_perf_del_symlink_cscfg(struct cscfg_config_desc *cscfg_desc) {}
> >
> >  #endif /* CONFIG_CORESIGHT */
> >
> > diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c
> > index 4b8e4e35e3e7..a070f135eca3 100644
> > --- a/drivers/hwtracing/coresight/coresight-syscfg.c
> > +++ b/drivers/hwtracing/coresight/coresight-syscfg.c
> > @@ -7,6 +7,7 @@
> >  #include <linux/platform_device.h>
> >
> >  #include "coresight-config.h"
> > +#include "coresight-etm-perf.h"
> >  #include "coresight-syscfg.h"
> >
> >  /*
> > @@ -100,6 +101,7 @@ static int cscfg_add_csdev_cfg(struct coresight_device *csdev,
> >                       dev_cfg->feats[dev_cfg->nr_feat++] = feat;
> >               }
> >       }
> > +
> >       /* if matched features, add config to device.*/
> >       if (dev_cfg) {
> >               mutex_lock(&cscfg_csdev_mutex);
> > @@ -290,8 +292,12 @@ static int cscfg_load_config(struct cscfg_config_desc *cfg_desc)
> >       if (err)
> >               return err;
> >
> > -     list_add(&cfg_desc->item, &cscfg_mgr->data.config_desc_list);
> > +     /* add config to perf fs to allow selection */
> > +     err = etm_perf_add_symlink_cscfg(to_device_cscfg(), cfg_desc);
> > +     if (err)
> > +             return err;
> >
> > +     list_add(&cfg_desc->item, &cscfg_mgr->data.config_desc_list);
> >       return 0;
> >  }
> >
> > @@ -517,7 +523,12 @@ int cscfg_create_device(void)
> >
> >  void cscfg_clear_device(void)
> >  {
> > +     struct cscfg_config_desc *cfg_desc;
> > +
> >       mutex_lock(&cscfg_mutex);
> > +     list_for_each_entry(cfg_desc, &cscfg_mgr->data.config_desc_list, item) {
> > +             etm_perf_del_symlink_cscfg(cfg_desc);
> > +     }
> >       device_unregister(to_device_cscfg());
> >       mutex_unlock(&cscfg_mutex);
> >  }
> > --
> > 2.17.1
> >
> >
> > _______________________________________________
> > linux-arm-kernel mailing list
> > linux-arm-kernel@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Thanks

Mike

-- 
Mike Leach
Principal Engineer, ARM Ltd.
Manchester Design Centre. UK

WARNING: multiple messages have this Message-ID (diff)
From: Mike Leach <mike.leach@linaro.org>
To: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: Jonathan Corbet <corbet@lwn.net>,
	"Suzuki K. Poulose" <suzuki.poulose@arm.com>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Coresight ML <coresight@lists.linaro.org>,
	"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Tingwei Zhang <tingwei@codeaurora.org>,
	Yabin Cui <yabinc@google.com>, Leo Yan <leo.yan@linaro.org>,
	linux-arm-kernel <linux-arm-kernel@lists.infradead.org>
Subject: Re: [PATCH v4 04/10] coresight: etm-perf: update to handle configuration selection
Date: Fri, 26 Feb 2021 19:26:23 +0000	[thread overview]
Message-ID: <CAJ9a7VhgmTN+t80_Dd0UsNwwJo8MLR5qYHu40HmNaFRNDrP34A@mail.gmail.com> (raw)
In-Reply-To: <20210224183313.GC3237327@xps15>

HI Mathieu.

On Wed, 24 Feb 2021 at 18:33, Mathieu Poirier
<mathieu.poirier@linaro.org> wrote:
>
> On Thu, Jan 28, 2021 at 05:09:30PM +0000, Mike Leach wrote:
> > Loaded coresight configurations are registered in the cs_etm\cs_config sub
> > directory. This extends the etm-perf code to handle these registrations,
> > and the cs_syscfg driver to perform the registration on load.
> >
> > Signed-off-by: Mike Leach <mike.leach@linaro.org>
> > ---
> >  .../hwtracing/coresight/coresight-config.h    |   5 +-
> >  .../hwtracing/coresight/coresight-etm-perf.c  | 164 +++++++++++++++---
> >  .../hwtracing/coresight/coresight-etm-perf.h  |   8 +
> >  .../hwtracing/coresight/coresight-syscfg.c    |  13 +-
> >  4 files changed, 166 insertions(+), 24 deletions(-)
> >
> > diff --git a/drivers/hwtracing/coresight/coresight-config.h b/drivers/hwtracing/coresight/coresight-config.h
> > index 9d66e0071f38..98380b496046 100644
> > --- a/drivers/hwtracing/coresight/coresight-config.h
> > +++ b/drivers/hwtracing/coresight/coresight-config.h
> > @@ -154,7 +154,8 @@ struct cscfg_config_feat_ref {
> >   * @nr_presets:      Number of sets of presets supplied by this configuration.
> >   * @nr_total_params: Sum of all parameters declared by used features
> >   * @presets: Array of preset values.
> > - *
> > + * @id_ea:   Extended attribute for perf configid value
> > + * @event_ea:        Extended attribute for perf event value
> >   */
> >  struct cscfg_config_desc {
> >       const char *name;
> > @@ -165,6 +166,8 @@ struct cscfg_config_desc {
> >       int nr_presets;
> >       int nr_total_params;
> >       const u64 *presets; /* nr_presets * nr_total_params */
> > +     struct dev_ext_attribute *id_ea;
> > +     struct dev_ext_attribute *event_ea;
> >  };
> >
> >  /**
> > diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c
> > index a608081bd446..e270bb1e0f7d 100644
> > --- a/drivers/hwtracing/coresight/coresight-etm-perf.c
> > +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c
> > @@ -18,8 +18,10 @@
> >  #include <linux/types.h>
> >  #include <linux/workqueue.h>
> >
> > +#include "coresight-config.h"
> >  #include "coresight-etm-perf.h"
> >  #include "coresight-priv.h"
> > +#include "coresight-syscfg.h"
> >
> >  static struct pmu etm_pmu;
> >  static bool etm_perf_up;
> > @@ -32,8 +34,13 @@ PMU_FORMAT_ATTR(cycacc,            "config:" __stringify(ETM_OPT_CYCACC));
> >  PMU_FORMAT_ATTR(contextid,   "config:" __stringify(ETM_OPT_CTXTID));
> >  PMU_FORMAT_ATTR(timestamp,   "config:" __stringify(ETM_OPT_TS));
> >  PMU_FORMAT_ATTR(retstack,    "config:" __stringify(ETM_OPT_RETSTK));
> > +/* preset - if sink ID is used as a configuration selector */
> > +PMU_FORMAT_ATTR(preset,              "config:0-3");
> >  /* Sink ID - same for all ETMs */
> >  PMU_FORMAT_ATTR(sinkid,              "config2:0-31");
> > +/* config ID - set if a system configuration is selected */
> > +PMU_FORMAT_ATTR(configid,    "config2:32-63");
> > +
> >
> >  static struct attribute *etm_config_formats_attr[] = {
> >       &format_attr_cycacc.attr,
> > @@ -41,6 +48,8 @@ static struct attribute *etm_config_formats_attr[] = {
> >       &format_attr_timestamp.attr,
> >       &format_attr_retstack.attr,
> >       &format_attr_sinkid.attr,
> > +     &format_attr_preset.attr,
> > +     &format_attr_configid.attr,
> >       NULL,
> >  };
> >
> > @@ -58,9 +67,29 @@ static const struct attribute_group etm_pmu_sinks_group = {
> >       .attrs  = etm_config_sinks_attr,
> >  };
> >
> > +static struct attribute *etm_config_cscfg_attr[] = {
> > +     NULL,
> > +};
> > +
> > +static const struct attribute_group etm_pmu_cscfg_group = {
> > +     .name   = "configurations",
> > +     .attrs  = etm_config_cscfg_attr,
> > +};
> > +
> > +static struct attribute *etm_config_events_attr[] = {
> > +     NULL,
> > +};
> > +
> > +static const struct attribute_group etm_pmu_events_group = {
> > +     .name   = "events",
> > +     .attrs  = etm_config_events_attr,
> > +};
> > +
> >  static const struct attribute_group *etm_pmu_attr_groups[] = {
> >       &etm_pmu_format_group,
> >       &etm_pmu_sinks_group,
> > +     &etm_pmu_cscfg_group,
> > +     &etm_pmu_events_group,
> >       NULL,
> >  };
> >
> > @@ -219,7 +248,7 @@ static void *etm_setup_aux(struct perf_event *event, void **pages,
> >       INIT_WORK(&event_data->work, free_event_data);
> >
> >       /* First get the selected sink from user space. */
> > -     if (event->attr.config2) {
> > +     if (event->attr.config2 & GENMASK_ULL(31, 0)) {
> >               id = (u32)event->attr.config2;
> >               sink = coresight_get_sink_by_id(id);
> >       }
> > @@ -537,21 +566,17 @@ static ssize_t etm_perf_sink_name_show(struct device *dev,
>
> I would rename this to etm_perf_name_show() so that it doesn't look bizarre when
> finding it in etm_perf_add_symlink_group().
>
OK.

> >       return scnprintf(buf, PAGE_SIZE, "0x%lx\n", (unsigned long)(ea->var));
> >  }
> >
> > -int etm_perf_add_symlink_sink(struct coresight_device *csdev)
> > +int etm_perf_add_symlink_group(struct device *dev,
> > +                            struct dev_ext_attribute **ext_attr,
> > +                            const char *name,
> > +                            const char *group_name)
> >  {
> > -     int ret;
> > +     struct dev_ext_attribute *ea;
> >       unsigned long hash;
> > -     const char *name;
> > +     int ret;
> >       struct device *pmu_dev = etm_pmu.dev;
> > -     struct device *dev = &csdev->dev;
> > -     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;
> > +     *ext_attr = NULL;
> >
> >       if (!etm_perf_up)
> >               return -EPROBE_DEFER;
> > @@ -560,7 +585,6 @@ int etm_perf_add_symlink_sink(struct coresight_device *csdev)
> >       if (!ea)
> >               return -ENOMEM;
> >
> > -     name = dev_name(dev);
> >       /* See function coresight_get_sink_by_id() to know where this is used */
>
> I would also update this comment.  If @name is a sink then the hash will be
> used in coresight_get_sink_by_id(), and if it is a configuration it will be used
> in etm_perf_add_cscfg_event() and cscfg_activate_config().
>

OK.

> >       hash = hashlen_hash(hashlen_string(NULL, name));
> >
> > @@ -574,31 +598,127 @@ int etm_perf_add_symlink_sink(struct coresight_device *csdev)
> >       ea->var = (unsigned long *)hash;
> >
> >       ret = sysfs_add_file_to_group(&pmu_dev->kobj,
> > -                                   &ea->attr.attr, "sinks");
> > -
> > +                                   &ea->attr.attr, group_name);
> >       if (!ret)
> > -             csdev->ea = ea;
> > -
> > +             *ext_attr = ea;
> >       return ret;
> >  }
> >
> > -void etm_perf_del_symlink_sink(struct coresight_device *csdev)
> > +int etm_perf_add_symlink_sink(struct coresight_device *csdev)
> > +{
> > +     const char *name;
> > +     struct device *dev = &csdev->dev;
> > +
> > +     if (csdev->type != CORESIGHT_DEV_TYPE_SINK &&
> > +         csdev->type != CORESIGHT_DEV_TYPE_LINKSINK)
> > +             return -EINVAL;
> > +
> > +     if (csdev->ea != NULL)
> > +             return -EINVAL;
> > +
> > +     name = dev_name(dev);
> > +     return etm_perf_add_symlink_group(dev, &csdev->ea, name, "sinks");
> > +}
> > +
> > +void etm_perf_del_symlink_group(struct dev_ext_attribute *ea, const char *group_name)
> >  {
> >       struct device *pmu_dev = etm_pmu.dev;
> > -     struct dev_ext_attribute *ea = csdev->ea;
> >
> > +     sysfs_remove_file_from_group(&pmu_dev->kobj,
> > +                                  &ea->attr.attr, group_name);
> > +}
> > +
> > +void etm_perf_del_symlink_sink(struct coresight_device *csdev)
> > +{
> >       if (csdev->type != CORESIGHT_DEV_TYPE_SINK &&
> >           csdev->type != CORESIGHT_DEV_TYPE_LINKSINK)
> >               return;
> >
> > -     if (!ea)
> > +     if (!csdev->ea)
> >               return;
> >
> > -     sysfs_remove_file_from_group(&pmu_dev->kobj,
> > -                                  &ea->attr.attr, "sinks");
> > +     etm_perf_del_symlink_group(csdev->ea, "sinks");
> >       csdev->ea = NULL;
> >  }
> >
> > +/* string to contain the attribute value */
> > +#define CSCFG_EVENT_STR_SIZE 32
> > +
> > +static ssize_t etm_perf_cscfg_event_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, "%s\n", (const char *)(ea->var));
> > +}
> > +
> > +static int etm_perf_add_cscfg_event(struct device *dev, struct cscfg_config_desc *cs_cfg)
> > +{
> > +     struct dev_ext_attribute *ea;
> > +     unsigned long hash;
> > +     int ret;
> > +     struct device *pmu_dev = etm_pmu.dev;
> > +
> > +     ea = devm_kzalloc(dev, sizeof(*ea), GFP_KERNEL);
> > +     if (!ea)
> > +             return -ENOMEM;
> > +
> > +     hash = (unsigned long)cs_cfg->id_ea->var;
> > +
> > +     sysfs_attr_init(&ea->attr.attr);
> > +     ea->attr.attr.name = devm_kstrdup(dev, cs_cfg->name, GFP_KERNEL);
> > +     if (!ea->attr.attr.name)
> > +             return -ENOMEM;
> > +
> > +     /*
> > +      * attribute value is "configid=<hash>".
> > +      * this will be what perf evaluates when the config name is used
> > +      * on the command line.
> > +      */
> > +     ea->var = devm_kzalloc(dev, CSCFG_EVENT_STR_SIZE, GFP_KERNEL);
> > +     if (!ea->var)
> > +             return -ENOMEM;
> > +
> > +     scnprintf(ea->var, CSCFG_EVENT_STR_SIZE, "configid=0x%lx", hash);
> > +     ea->attr.attr.mode = 0444;
> > +     ea->attr.show = etm_perf_cscfg_event_show;
> > +
> > +     ret = sysfs_add_file_to_group(&pmu_dev->kobj,
> > +                                   &ea->attr.attr, "events");
> > +     if (!ret)
> > +             cs_cfg->event_ea = ea;
> > +     return ret;
> > +}
> > +
> > +int etm_perf_add_symlink_cscfg(struct device *dev, struct cscfg_config_desc *cs_cfg)
> > +{
> > +     int err;
> > +
> > +     if (cs_cfg->id_ea != NULL)
> > +             return 0;
> > +
> > +     err = etm_perf_add_symlink_group(dev, &cs_cfg->id_ea,
> > +                                      cs_cfg->name, "configurations");
>
> Do we need configurations to be advertised under
> /sys/bus/event_source/devices/cs_etm given that they are already found in
> /sys/kernel/config/coresight-syscfg?  And the events already carry the hash if
> someone is really keen using the "configid=" syntax.
>
> In my opinion we can get by with what is in configfs and do away with the
> "configurations" directory here.
>

Agreed - since stuff is now in events then this does become redundant.

> > +
> > +     if (!err)
> > +             err = etm_perf_add_cscfg_event(dev, cs_cfg);
> > +
>
> That we definitely need.
>
> Thanks,
> Mathieu
>
> > +     return err;
> > +}
> > +
> > +void etm_perf_del_symlink_cscfg(struct cscfg_config_desc *cs_cfg)
> > +{
> > +     if (!cs_cfg->id_ea)
> > +             return;
> > +
> > +     etm_perf_del_symlink_group(cs_cfg->id_ea, "configurations");
> > +     etm_perf_del_symlink_group(cs_cfg->event_ea, "events");
> > +     cs_cfg->id_ea = NULL;
> > +     cs_cfg->event_ea = NULL;
> > +}
> > +
> >  int __init etm_perf_init(void)
> >  {
> >       int ret;
> > diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.h b/drivers/hwtracing/coresight/coresight-etm-perf.h
> > index 29d90dfeba31..3646a3837a0b 100644
> > --- a/drivers/hwtracing/coresight/coresight-etm-perf.h
> > +++ b/drivers/hwtracing/coresight/coresight-etm-perf.h
> > @@ -11,6 +11,7 @@
> >  #include "coresight-priv.h"
> >
> >  struct coresight_device;
> > +struct cscfg_config_desc;
> >
> >  /*
> >   * 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)
> >               return data->snk_config;
> >       return NULL;
> >  }
> > +int etm_perf_add_symlink_cscfg(struct device *dev,
> > +                            struct cscfg_config_desc *cscfg_desc);
> > +void etm_perf_del_symlink_cscfg(struct cscfg_config_desc *cscfg_desc);
> >  #else
> >  static inline int etm_perf_symlink(struct coresight_device *csdev, bool link)
> >  { return -EINVAL; }
> > @@ -79,6 +83,10 @@ static inline void *etm_perf_sink_config(struct perf_output_handle *handle)
> >  {
> >       return NULL;
> >  }
> > +int etm_perf_add_symlink_cscfg(struct device *dev,
> > +                            struct cscfg_config_desc *cscfg_desc)
> > +{ return -EINVAL; }
> > +void etm_perf_del_symlink_cscfg(struct cscfg_config_desc *cscfg_desc) {}
> >
> >  #endif /* CONFIG_CORESIGHT */
> >
> > diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c
> > index 4b8e4e35e3e7..a070f135eca3 100644
> > --- a/drivers/hwtracing/coresight/coresight-syscfg.c
> > +++ b/drivers/hwtracing/coresight/coresight-syscfg.c
> > @@ -7,6 +7,7 @@
> >  #include <linux/platform_device.h>
> >
> >  #include "coresight-config.h"
> > +#include "coresight-etm-perf.h"
> >  #include "coresight-syscfg.h"
> >
> >  /*
> > @@ -100,6 +101,7 @@ static int cscfg_add_csdev_cfg(struct coresight_device *csdev,
> >                       dev_cfg->feats[dev_cfg->nr_feat++] = feat;
> >               }
> >       }
> > +
> >       /* if matched features, add config to device.*/
> >       if (dev_cfg) {
> >               mutex_lock(&cscfg_csdev_mutex);
> > @@ -290,8 +292,12 @@ static int cscfg_load_config(struct cscfg_config_desc *cfg_desc)
> >       if (err)
> >               return err;
> >
> > -     list_add(&cfg_desc->item, &cscfg_mgr->data.config_desc_list);
> > +     /* add config to perf fs to allow selection */
> > +     err = etm_perf_add_symlink_cscfg(to_device_cscfg(), cfg_desc);
> > +     if (err)
> > +             return err;
> >
> > +     list_add(&cfg_desc->item, &cscfg_mgr->data.config_desc_list);
> >       return 0;
> >  }
> >
> > @@ -517,7 +523,12 @@ int cscfg_create_device(void)
> >
> >  void cscfg_clear_device(void)
> >  {
> > +     struct cscfg_config_desc *cfg_desc;
> > +
> >       mutex_lock(&cscfg_mutex);
> > +     list_for_each_entry(cfg_desc, &cscfg_mgr->data.config_desc_list, item) {
> > +             etm_perf_del_symlink_cscfg(cfg_desc);
> > +     }
> >       device_unregister(to_device_cscfg());
> >       mutex_unlock(&cscfg_mutex);
> >  }
> > --
> > 2.17.1
> >
> >
> > _______________________________________________
> > linux-arm-kernel mailing list
> > linux-arm-kernel@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

Thanks

Mike

-- 
Mike Leach
Principal Engineer, ARM Ltd.
Manchester Design Centre. UK

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2021-02-26 19:27 UTC|newest]

Thread overview: 106+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-28 17:09 [PATCH v4 00/10] CoreSight configuration management; ETM strobing Mike Leach
2021-01-28 17:09 ` Mike Leach
2021-01-28 17:09 ` [PATCH v4 01/10] coresight: syscfg: Initial coresight system configuration Mike Leach
2021-01-28 17:09   ` Mike Leach
2021-02-18 23:52   ` Mathieu Poirier
2021-02-18 23:52     ` Mathieu Poirier
2021-02-26 19:09     ` Mike Leach
2021-02-26 19:09       ` Mike Leach
2021-02-22 18:50   ` Mathieu Poirier
2021-02-22 18:50     ` Mathieu Poirier
2021-02-26 19:10     ` Mike Leach
2021-02-26 19:10       ` Mike Leach
2021-03-03 10:09   ` Suzuki K Poulose
2021-03-03 10:09     ` Suzuki K Poulose
2021-03-03 15:12     ` Mike Leach
2021-03-03 15:12       ` Mike Leach
2021-03-03 10:23   ` Suzuki K Poulose
2021-03-03 10:23     ` Suzuki K Poulose
2021-03-04 10:08   ` Suzuki K Poulose
2021-03-04 10:08     ` Suzuki K Poulose
2021-03-04 10:47     ` Mike Leach
2021-03-04 10:47       ` Mike Leach
2021-03-04 10:48   ` Suzuki K Poulose
2021-03-04 10:48     ` Suzuki K Poulose
2021-01-28 17:09 ` [PATCH v4 02/10] coresight: syscfg: Add registration and feature loading for cs devices Mike Leach
2021-01-28 17:09   ` Mike Leach
2021-02-19 18:43   ` Mathieu Poirier
2021-02-19 18:43     ` Mathieu Poirier
2021-02-26 19:14     ` Mike Leach
2021-02-26 19:14       ` Mike Leach
2021-02-27 20:52       ` Mathieu Poirier
2021-02-27 20:52         ` Mathieu Poirier
2021-02-22 17:37   ` Mathieu Poirier
2021-02-22 17:37     ` Mathieu Poirier
2021-02-26 19:16     ` Mike Leach
2021-02-26 19:16       ` Mike Leach
2021-02-22 19:05   ` Mathieu Poirier
2021-02-22 19:05     ` Mathieu Poirier
2021-03-04 10:33   ` Suzuki K Poulose
2021-03-04 10:33     ` Suzuki K Poulose
2021-03-16 18:00     ` Mike Leach
2021-03-16 18:00       ` Mike Leach
2021-01-28 17:09 ` [PATCH v4 03/10] coresight: config: Add configuration and feature generic functions Mike Leach
2021-01-28 17:09   ` Mike Leach
2021-02-22 22:57   ` Mathieu Poirier
2021-02-22 22:57     ` Mathieu Poirier
2021-03-04 11:25   ` Suzuki K Poulose
2021-03-04 11:25     ` Suzuki K Poulose
2021-01-28 17:09 ` [PATCH v4 04/10] coresight: etm-perf: update to handle configuration selection Mike Leach
2021-01-28 17:09   ` Mike Leach
2021-02-24 18:33   ` Mathieu Poirier
2021-02-24 18:33     ` Mathieu Poirier
2021-02-26 19:26     ` Mike Leach [this message]
2021-02-26 19:26       ` Mike Leach
2021-03-04 12:13   ` Suzuki K Poulose
2021-03-04 12:13     ` Suzuki K Poulose
2021-03-04 14:19     ` Mike Leach
2021-03-04 14:19       ` Mike Leach
2021-03-04 14:25       ` Suzuki K Poulose
2021-03-04 14:25         ` Suzuki K Poulose
2021-03-04 14:46         ` Mike Leach
2021-03-04 14:46           ` Mike Leach
2021-01-28 17:09 ` [PATCH v4 05/10] coresight: syscfg: Add API to activate and enable configurations Mike Leach
2021-01-28 17:09   ` Mike Leach
2021-02-25 21:20   ` Mathieu Poirier
2021-02-25 21:20     ` Mathieu Poirier
2021-02-25 21:46     ` Mathieu Poirier
2021-02-25 21:46       ` Mathieu Poirier
2021-02-26 20:08     ` Mike Leach
2021-02-26 20:08       ` Mike Leach
2021-03-04 16:49   ` Suzuki K Poulose
2021-03-04 16:49     ` Suzuki K Poulose
2021-03-04 18:15     ` Mike Leach
2021-03-04 18:15       ` Mike Leach
2021-01-28 17:09 ` [PATCH v4 06/10] coresight: etm-perf: Update to activate selected configuration Mike Leach
2021-01-28 17:09   ` Mike Leach
2021-02-25 21:51   ` Mathieu Poirier
2021-02-25 21:51     ` Mathieu Poirier
2021-02-26 20:09     ` Mike Leach
2021-02-26 20:09       ` Mike Leach
2021-03-04 16:50   ` Suzuki K Poulose
2021-03-04 16:50     ` Suzuki K Poulose
2021-01-28 17:09 ` [PATCH v4 07/10] coresight: etm4x: Add complex configuration handlers to etmv4 Mike Leach
2021-01-28 17:09   ` Mike Leach
2021-02-28 23:19   ` Mathieu Poirier
2021-02-28 23:19     ` Mathieu Poirier
2021-03-05 10:18   ` Suzuki K Poulose
2021-03-05 10:18     ` Suzuki K Poulose
2021-03-17 15:04     ` Mike Leach
2021-03-17 15:04       ` Mike Leach
2021-01-28 17:09 ` [PATCH v4 08/10] coresight: config: Add preloaded configurations Mike Leach
2021-01-28 17:09   ` Mike Leach
2021-02-28 23:25   ` Mathieu Poirier
2021-02-28 23:25     ` Mathieu Poirier
2021-03-05 13:39   ` Suzuki K Poulose
2021-03-05 13:39     ` Suzuki K Poulose
2021-01-28 17:09 ` [PATCH v4 09/10] coresight: syscfg: Add initial configfs support Mike Leach
2021-01-28 17:09   ` Mike Leach
2021-03-01  0:02   ` Mathieu Poirier
2021-03-01  0:02     ` Mathieu Poirier
2021-03-01  0:04     ` Mathieu Poirier
2021-03-01  0:04       ` Mathieu Poirier
2021-01-28 17:09 ` [PATCH v4 10/10] coresight: docs: Add documentation for CoreSight config Mike Leach
2021-01-28 17:09   ` Mike Leach
2021-02-18 21:28   ` Mathieu Poirier
2021-02-18 21:28     ` Mathieu Poirier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAJ9a7VhgmTN+t80_Dd0UsNwwJo8MLR5qYHu40HmNaFRNDrP34A@mail.gmail.com \
    --to=mike.leach@linaro.org \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=corbet@lwn.net \
    --cc=coresight@lists.linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=leo.yan@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.poirier@linaro.org \
    --cc=suzuki.poulose@arm.com \
    --cc=tingwei@codeaurora.org \
    --cc=yabinc@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.