linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mike Leach <mike.leach@linaro.org>
To: Suzuki K Poulose <suzuki.poulose@arm.com>
Cc: linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	Coresight ML <coresight@lists.linaro.org>,
	Mathieu Poirier <mathieu.poirier@linaro.org>,
	"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
	Yabin Cui <yabinc@google.com>, Jonathan Corbet <corbet@lwn.net>,
	Leo Yan <leo.yan@linaro.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Tingwei Zhang <tingwei@codeaurora.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 05/10] coresight: syscfg: Add API to activate and enable configurations
Date: Thu, 4 Mar 2021 18:15:13 +0000	[thread overview]
Message-ID: <CAJ9a7Vj=WGPM3t2HtfrS-o=+9rntL90E=++8Gsxk1W8Aj=nggQ@mail.gmail.com> (raw)
In-Reply-To: <2ff0fd68-969f-292b-f8d3-5dace8f1a435@arm.com>

Hi Suzuki,

On Thu, 4 Mar 2021 at 16:49, Suzuki K Poulose <suzuki.poulose@arm.com> wrote:
>
> On 1/28/21 5:09 PM, Mike Leach wrote:
> > Configurations are first activated, then when any coresight device is
> > enabled, the active configurations are checked and any matching
> > one is enabled.
> >
> > This patch provides the activation / enable API.
> >
> > Signed-off-by: Mike Leach <mike.leach@linaro.org>
> > ---
> >   .../hwtracing/coresight/coresight-config.h    |   2 +
> >   .../hwtracing/coresight/coresight-syscfg.c    | 127 ++++++++++++++++++
> >   .../hwtracing/coresight/coresight-syscfg.h    |  10 +-
> >   include/linux/coresight.h                     |   2 +
> >   4 files changed, 140 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/hwtracing/coresight/coresight-config.h b/drivers/hwtracing/coresight/coresight-config.h
> > index 98380b496046..26396b70c826 100644
> > --- a/drivers/hwtracing/coresight/coresight-config.h
> > +++ b/drivers/hwtracing/coresight/coresight-config.h
> > @@ -156,6 +156,7 @@ struct cscfg_config_feat_ref {
> >    * @presets:        Array of preset values.
> >    * @id_ea:  Extended attribute for perf configid value
> >    * @event_ea:       Extended attribute for perf event value
> > + * @active_cnt: ref count for activate on this configuration.
> >    */
> >   struct cscfg_config_desc {
> >       const char *name;
> > @@ -168,6 +169,7 @@ struct cscfg_config_desc {
> >       const u64 *presets; /* nr_presets * nr_total_params */
> >       struct dev_ext_attribute *id_ea;
> >       struct dev_ext_attribute *event_ea;
> > +     atomic_t active_cnt;
> >   };
> >
> >   /**
> > diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c
> > index a070f135eca3..d79cf5b36758 100644
> > --- a/drivers/hwtracing/coresight/coresight-syscfg.c
> > +++ b/drivers/hwtracing/coresight/coresight-syscfg.c
> > @@ -298,6 +298,7 @@ static int cscfg_load_config(struct cscfg_config_desc *cfg_desc)
> >               return err;
> >
> >       list_add(&cfg_desc->item, &cscfg_mgr->data.config_desc_list);
> > +     atomic_set(&cfg_desc->active_cnt, 0);
> >       return 0;
> >   }
> >
> > @@ -477,6 +478,131 @@ void cscfg_unregister_csdev(struct coresight_device *csdev)
> >   }
> >   EXPORT_SYMBOL_GPL(cscfg_unregister_csdev);
> >
> > +void cscfg_csdev_reset_feats(struct coresight_device *csdev)
> > +{
> > +     struct cscfg_feature_csdev *feat;
> > +
> > +     mutex_lock(&cscfg_csdev_mutex);
> > +     if (list_empty(&csdev->feature_csdev_list))
> > +             goto unlock_exit;
> > +
> > +     list_for_each_entry(feat, &csdev->feature_csdev_list, node)
> > +             cscfg_reset_feat(feat);
> > +
> > +unlock_exit:
> > +     mutex_unlock(&cscfg_csdev_mutex);
> > +}
> > +EXPORT_SYMBOL_GPL(cscfg_csdev_reset_feats);
> > +
> > +/**
> > + * Mark a config descriptor as active.
> > + * This will be seen when csdev devices are activated in the system.
> > + *
> > + * Selection by hash value - generated from the configuration name when it
> > + * was loaded and added to the cs_etm/configurations file system for selection
> > + * by perf.
> > + *
> > + * @cfg_hash: Hash value of the selected configuration name.
> > + */
> > +int cscfg_activate_config(unsigned long cfg_hash)
> > +{
> > +     struct cscfg_config_desc *curr_item, *match_item = 0;
>
> nit: s/0/NULL
>

OK.

> > +
> > +     mutex_lock(&cscfg_mutex);
> > +
> > +     list_for_each_entry(curr_item, &cscfg_mgr->data.config_desc_list, item) {
> > +             if ((unsigned long)curr_item->id_ea->var == cfg_hash) {
> > +                     match_item = curr_item;
> > +                     atomic_inc(&cscfg_mgr->data.sys_active_cnt);
> > +                     break;
> > +             }
> > +     }
> > +     mutex_unlock(&cscfg_mutex);
> > +
> > +     if (!match_item)
> > +             return -EINVAL;
> > +
> > +     dev_dbg(to_device_cscfg(), "Activate config %s.\n", match_item->name);
> > +
> > +     /* mark the descriptors as active so enable config will use them */
> > +     mutex_lock(&cscfg_csdev_mutex);
> > +     atomic_inc(&match_item->active_cnt);
> > +     mutex_unlock(&cscfg_csdev_mutex);
>
> Is there a guarantee that this item is active and present in the list after
> we dropped the mutex above ? We could certainly nest the mutex as long as
> we follow the order everywhere to prevent such a race.
>

Although removal not supported in this set, the rule is that nothing
can be removed while any configuration is active (count on
sys_active_cnt). - but a comment here could be added.
That said, given this is an atomic, not sure that the mutex is
necessary (I think previous versions did more than just update the
count), & perhaps the increment should be moved to the main
list_for_each loop.

> > +
> > +     return 0;
> > +}
> > +EXPORT_SYMBOL_GPL(cscfg_activate_config);
> > +
> > +void cscfg_deactivate_config(unsigned long cfg_hash)
> > +{
> > +     struct cscfg_config_desc *curr_item, *match_item = 0;
> > +
> > +     mutex_lock(&cscfg_mutex);
> > +
> > +     list_for_each_entry(curr_item, &cscfg_mgr->data.config_desc_list, item) {
> > +             if ((unsigned long)curr_item->id_ea->var == cfg_hash) {
> > +                     match_item = curr_item;
> > +                     break;
> > +             }
> > +     }
> > +     mutex_unlock(&cscfg_mutex);
> > +     if (!match_item)
> > +             return;
> > +
> > +     dev_dbg(to_device_cscfg(), "Deactivate config %s.\n", match_item->name);
> > +
> > +     mutex_lock(&cscfg_csdev_mutex);
> > +     atomic_dec(&match_item->active_cnt);
> > +     mutex_unlock(&cscfg_csdev_mutex);
> > +
> > +     atomic_dec(&cscfg_mgr->data.sys_active_cnt);
> > +}
> > +EXPORT_SYMBOL_GPL(cscfg_deactivate_config);
> > +
> > +/* Find and program any active config for the supplied device.*/
> > +int cscfg_csdev_enable_active_config(struct coresight_device *csdev,
> > +                                  unsigned long id_hash, int preset)
> > +{
> > +     struct cscfg_config_csdev *cfg = NULL, *item;
> > +     const struct cscfg_config_desc *desc;
> > +     int err = 0;
> > +
> > +     /* quickly check global count */
> > +     if (!atomic_read(&cscfg_mgr->data.sys_active_cnt))
> > +             return 0;
> > +
> > +     mutex_lock(&cscfg_csdev_mutex);
> > +     list_for_each_entry(item, &csdev->config_csdev_list, node) {
> > +             desc = item->desc;
> > +             if ((atomic_read(&desc->active_cnt)) &&
> > +                 ((unsigned long)desc->id_ea->var == id_hash)) {
> > +                     cfg = item;
> > +                     break;
> > +             }
> > +     }
> > +     if (cfg) {
> > +             err = cscfg_csdev_enable_config(cfg, preset);
> > +             if (!err)
> > +                     csdev->active_cfg_ctxt = (void *)cfg;
> > +     }
> > +     mutex_unlock(&cscfg_csdev_mutex);
> > +     return err;
> > +}
> > +EXPORT_SYMBOL_GPL(cscfg_csdev_enable_active_config);
> > +
> > +/* save and disable the active config for the device */
> > +void cscfg_csdev_disable_active_config(struct coresight_device *csdev)
> > +{
> > +     struct cscfg_config_csdev *cfg;
> > +
> > +     mutex_lock(&cscfg_csdev_mutex);
> > +     cfg = (struct cscfg_config_csdev *)csdev->active_cfg_ctxt;
> > +     if (cfg)
> > +             cscfg_csdev_disable_config(cfg);
> > +     mutex_unlock(&cscfg_csdev_mutex);
> > +}
> > +EXPORT_SYMBOL_GPL(cscfg_csdev_disable_active_config);
> > +
> >   /* Initialise system configuration management device. */
> >
> >   struct device *to_device_cscfg(void)
> > @@ -546,6 +672,7 @@ int __init cscfg_init(void)
> >       INIT_LIST_HEAD(&cscfg_mgr->data.feat_desc_list);
> >       INIT_LIST_HEAD(&cscfg_mgr->data.config_desc_list);
> >       cscfg_mgr->data.nr_csdev = 0;
> > +     atomic_set(&cscfg_mgr->data.sys_active_cnt, 0);
> >
> >       dev_info(to_device_cscfg(), "CoreSight Configuration manager initialised");
> >       return 0;
> > diff --git a/drivers/hwtracing/coresight/coresight-syscfg.h b/drivers/hwtracing/coresight/coresight-syscfg.h
> > index ebf5e1491d86..301e26e1e98f 100644
> > --- a/drivers/hwtracing/coresight/coresight-syscfg.h
> > +++ b/drivers/hwtracing/coresight/coresight-syscfg.h
> > @@ -17,13 +17,15 @@
> >    * @csdev_list:             List of coresight devices registered with the configuration manager.
> >    * @feat_desc_list: List of feature descriptors to load into registered devices.
>
> nit: Is this aligned ? (It is from Patch 1, though).
>
> >    * @config_desc_list:       List of system configuration descriptors to load into registered devices.
> > - * @nr_csdev:        Number of registered devices with the cscfg system
> > + * @nr_csdev:                Number of registered devices with the cscfg system
>
> Spurious change ?
>

This struct disappears in the v5 respin, so the comments will too.

> > + * @sys_active_cnt:  Total number of active config descriptor references.
> >    */
> >   struct cscfg_api_data {
> >       struct list_head csdev_desc_list;
> >       struct list_head feat_desc_list;
> >       struct list_head config_desc_list;
> >       int nr_csdev;
> > +     atomic_t sys_active_cnt;
> >   };
> >
> >   /**
> > @@ -53,6 +55,12 @@ int cscfg_register_csdev(struct coresight_device *csdev,
> >                        struct cscfg_match_desc *info,
> >                        struct cscfg_csdev_feat_ops *ops);
> >   void cscfg_unregister_csdev(struct coresight_device *csdev);
> > +int cscfg_activate_config(unsigned long cfg_hash);
> > +void cscfg_deactivate_config(unsigned long cfg_hash);
> > +void cscfg_csdev_reset_feats(struct coresight_device *csdev);
> > +int cscfg_csdev_enable_active_config(struct coresight_device *csdev,
> > +                                  unsigned long id_hash, int preset);
> > +void cscfg_csdev_disable_active_config(struct coresight_device *csdev);
> >
> >   /**
> >    * System configuration manager device.
> > diff --git a/include/linux/coresight.h b/include/linux/coresight.h
> > index d0126ed326a6..3941854e8280 100644
> > --- a/include/linux/coresight.h
> > +++ b/include/linux/coresight.h
> > @@ -221,6 +221,7 @@ struct coresight_sysfs_link {
> >    * @has_conns_grp: Have added a "connections" group for sysfs links.
> >    * @feature_csdev_list: List of complex feature programming added to the device.
> >    * @config_csdev_list:  List of system configurations added to the device.
> > + * @active_cfg_ctxt:    Context information for current active congfig.
> >    */
> >   struct coresight_device {
> >       struct coresight_platform_data *pdata;
> > @@ -245,6 +246,7 @@ struct coresight_device {
> >       /* system configuration and feature lists */
> >       struct list_head feature_csdev_list;
> >       struct list_head config_csdev_list;
> > +     void *active_cfg_ctxt;
> >   };
> >
>
> Suzuki
>

Thanks for the review.

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

  reply	other threads:[~2021-03-04 18:16 UTC|newest]

Thread overview: 53+ 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 ` [PATCH v4 01/10] coresight: syscfg: Initial coresight system configuration Mike Leach
2021-02-18 23:52   ` Mathieu Poirier
2021-02-26 19:09     ` Mike Leach
2021-02-22 18:50   ` Mathieu Poirier
2021-02-26 19:10     ` Mike Leach
2021-03-03 10:09   ` Suzuki K Poulose
2021-03-03 15:12     ` Mike Leach
2021-03-03 10:23   ` Suzuki K Poulose
2021-03-04 10:08   ` Suzuki K Poulose
2021-03-04 10:47     ` Mike Leach
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-02-19 18:43   ` Mathieu Poirier
2021-02-26 19:14     ` Mike Leach
2021-02-27 20:52       ` Mathieu Poirier
2021-02-22 17:37   ` Mathieu Poirier
2021-02-26 19:16     ` Mike Leach
2021-02-22 19:05   ` Mathieu Poirier
2021-03-04 10:33   ` Suzuki K Poulose
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-02-22 22:57   ` Mathieu Poirier
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-02-24 18:33   ` Mathieu Poirier
2021-02-26 19:26     ` Mike Leach
2021-03-04 12:13   ` Suzuki K Poulose
2021-03-04 14:19     ` Mike Leach
2021-03-04 14:25       ` Suzuki K Poulose
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-02-25 21:20   ` Mathieu Poirier
2021-02-25 21:46     ` Mathieu Poirier
2021-02-26 20:08     ` Mike Leach
2021-03-04 16:49   ` Suzuki K Poulose
2021-03-04 18:15     ` Mike Leach [this message]
2021-01-28 17:09 ` [PATCH v4 06/10] coresight: etm-perf: Update to activate selected configuration Mike Leach
2021-02-25 21:51   ` Mathieu Poirier
2021-02-26 20:09     ` Mike Leach
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-02-28 23:19   ` Mathieu Poirier
2021-03-05 10:18   ` Suzuki K Poulose
2021-03-17 15:04     ` Mike Leach
2021-01-28 17:09 ` [PATCH v4 08/10] coresight: config: Add preloaded configurations Mike Leach
2021-02-28 23:25   ` Mathieu Poirier
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-03-01  0:02   ` 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-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='CAJ9a7Vj=WGPM3t2HtfrS-o=+9rntL90E=++8Gsxk1W8Aj=nggQ@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).