From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C894C636C8 for ; Tue, 20 Jul 2021 17:43:23 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1F02660232 for ; Tue, 20 Jul 2021 17:43:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1F02660232 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XLMObdvWVeqWVfloAcpmm4Rw9X6JRuVf6TLi8kSqJXc=; b=tn25BYn843jZ7J j6QJk+8lMSdUY+sj+KOnJxWKsoJNt1AvrZbhc3g9mei3sK4GpXeIQlI8n5/cP4JySQJ4e0xCnOYfw X3rtqN5OMaMS+9SJtQcaU5yqlI5UDkTxFxFVXihXha+4KJ0Ca0hl/KZql+grN+gH7sABI4K2Jm+va xX0e/GilM8UTluU5dzExXkyOAN5kkjwyX16SKZ6oEaAS8ODZykhX7CSk8hy5KQ+vvg2VubKTNDAgz lu5HSR8nn4RtnpbTSY1kSqi9awDF4YPBlW1U9tyo/jVg8Sy1j0rEdsfFlyjk4EkKp8ENkaOWRMQNm uUFQLGA4F6oJoeRQS7MQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m5tk8-00Dfkb-N7; Tue, 20 Jul 2021 17:41:20 +0000 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m5tk4-00DfkG-OJ for linux-arm-kernel@lists.infradead.org; Tue, 20 Jul 2021 17:41:18 +0000 Received: by mail-pg1-x533.google.com with SMTP id y4so23166330pgl.10 for ; Tue, 20 Jul 2021 10:41:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=EaZqysZ6Sv+JlzCRlutTkWcMMV1RXVzV+oqBMjgghMg=; b=mWQZctZrWqEqgjZ/8xAB/FWpA7QdTCQgUhlUFRqlQqfRAt2fB/gVqfYo6Wk8WZxJz5 6GmWOwAEfKPSOc8qCBLng7btppLLY560rBK8ryYy0cWSsm8VPofBVz1crCBjs5XLBb4h Gq89+JOvbRHbiFvBgLs4qZoSULtZXxPygwMQw+JBHmjolCeFA8Lndz/CPfi2jC74qMIJ F3/7PTZa8eK0I4ep+R/3veTKAehlDKxmOLJIbQIuQmG2EwCl1gB5YmDiZ9hW98prB5EP gObveFPF+a1RsxD+Nq1KTt1ZIyi2cpA+3WzbY66+0udg4vtn4ptaKBId0sHhAdPBjzCQ ldSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=EaZqysZ6Sv+JlzCRlutTkWcMMV1RXVzV+oqBMjgghMg=; b=dwYegORAo97Nfu5twCAl5IecMDI79vHDsRNWuCNoLvpbHSqOpd/AABmU+JuJpu2ZS1 mEFDotNVpF32UoMTZpq1gYBKbiGITh4VgMimR0hyTib6Xt2Kx65IRoKtlNlYWGFF/aFy /urf+3/dhaTwuoclQx4PVqY2Wo6/lhYiUGDF6DX/8135CenP7O5hDU25f+Dfu6RHmAXY xN09TcR66AqtNeBRN/g2UGelfGZQvLO4dZM8HBFe/tybzHCQnrKwvexDqDmK5pAheIoz PFOAv1VV+6PR3KlVLIxyl9BKkNg0OBdUjk2nBxDSYXmPHOIh+4KErF3nEm55qMVb2pYu ymxQ== X-Gm-Message-State: AOAM5314lePYzJclxkq0YU7IyzJX88wf5UP2gr44nq3TR8n7kMa9w1xY niWN+Gq3frTtmp1UF8gm0T12Vw== X-Google-Smtp-Source: ABdhPJxHt8ipu9DkivDBUtk+f75sYH+VJ8ul0qe5ERRxK4wz6TS/ECnvzo/ZJ29MZ4kp3Mcm/w3FuQ== X-Received: by 2002:aa7:81c5:0:b029:2f7:d4e3:78e9 with SMTP id c5-20020aa781c50000b02902f7d4e378e9mr33099744pfn.31.1626802875433; Tue, 20 Jul 2021 10:41:15 -0700 (PDT) Received: from p14s (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id w186sm25146235pfw.106.2021.07.20.10.41.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Jul 2021 10:41:08 -0700 (PDT) Date: Tue, 20 Jul 2021 11:41:06 -0600 From: Mathieu Poirier To: Mike Leach Cc: linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, suzuki.poulose@arm.com, leo.yan@linaro.org, alexander.shishkin@linux.intel.com, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v8 05/10] coresight: syscfg: Add API to activate and enable configurations Message-ID: <20210720174106.GA2301883@p14s> References: <20210707133003.5414-1-mike.leach@linaro.org> <20210707133003.5414-6-mike.leach@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210707133003.5414-6-mike.leach@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210720_104116_883701_F1C328E0 X-CRM114-Status: GOOD ( 44.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Jul 07, 2021 at 02:29:58PM +0100, 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 > Reviewed-by: Mathieu Poirier > --- > .../hwtracing/coresight/coresight-config.h | 2 + > .../hwtracing/coresight/coresight-syscfg.c | 197 ++++++++++++++++++ > .../hwtracing/coresight/coresight-syscfg.h | 8 + > include/linux/coresight.h | 4 + > 4 files changed, 211 insertions(+) > > diff --git a/drivers/hwtracing/coresight/coresight-config.h b/drivers/hwtracing/coresight/coresight-config.h > index 0667581822c1..25eb6c632692 100644 > --- a/drivers/hwtracing/coresight/coresight-config.h > +++ b/drivers/hwtracing/coresight/coresight-config.h > @@ -127,6 +127,7 @@ struct cscfg_feature_desc { > * @nr_total_params: Sum of all parameters declared by used features > * @presets: Array of preset values. > * @event_ea: Extended attribute for perf event value > + * @active_cnt: ref count for activate on this configuration. > * > */ > struct cscfg_config_desc { > @@ -139,6 +140,7 @@ struct cscfg_config_desc { > int nr_total_params; > const u64 *presets; /* nr_presets * nr_total_params */ > 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 b93f2b4a777e..4e9804875a9b 100644 > --- a/drivers/hwtracing/coresight/coresight-syscfg.c > +++ b/drivers/hwtracing/coresight/coresight-syscfg.c > @@ -282,6 +282,7 @@ static int cscfg_load_config(struct cscfg_config_desc *config_desc) > return err; > > list_add(&config_desc->item, &cscfg_mgr->config_desc_list); > + atomic_set(&config_desc->active_cnt, 0); > return 0; > } > > @@ -468,6 +469,201 @@ void cscfg_unregister_csdev(struct coresight_device *csdev) > } > EXPORT_SYMBOL_GPL(cscfg_unregister_csdev); > > +/** > + * cscfg_csdev_reset_feats - reset features for a CoreSight device. > + * > + * Resets all parameters and register values for any features loaded > + * into @csdev to their default values. > + * > + * @csdev: The CoreSight device. > + */ > +void cscfg_csdev_reset_feats(struct coresight_device *csdev) > +{ > + struct cscfg_feature_csdev *feat_csdev; > + unsigned long flags; > + > + spin_lock_irqsave(&csdev->cscfg_csdev_lock, flags); > + if (list_empty(&csdev->feature_csdev_list)) > + goto unlock_exit; > + > + list_for_each_entry(feat_csdev, &csdev->feature_csdev_list, node) > + cscfg_reset_feat(feat_csdev); > + > +unlock_exit: > + spin_unlock_irqrestore(&csdev->cscfg_csdev_lock, flags); > +} > +EXPORT_SYMBOL_GPL(cscfg_csdev_reset_feats); > + > +/** > + * cscfg_activate_config - Mark a configuration descriptor as active. > + * > + * This will be seen when csdev devices are enabled in the system. > + * Only activated configurations can be enabled on individual devices. > + * Activation protects the configuration from alteration or removal while > + * active. > + * > + * 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. > + * > + * Increments the configuration descriptor active count and the global active > + * count. > + * > + * @cfg_hash: Hash value of the selected configuration name. > + */ > +int cscfg_activate_config(unsigned long cfg_hash) > +{ > + struct cscfg_config_desc *config_desc; > + int err = -EINVAL; > + > + mutex_lock(&cscfg_mutex); > + > + list_for_each_entry(config_desc, &cscfg_mgr->config_desc_list, item) { > + if ((unsigned long)config_desc->event_ea->var == cfg_hash) { > + /* > + * increment the global active count - control changes to > + * active configurations > + */ > + atomic_inc(&cscfg_mgr->sys_active_cnt); > + > + /* > + * mark the descriptor as active so enable config on a > + * device instance will use it > + */ > + atomic_inc(&config_desc->active_cnt); > + > + err = 0; > + dev_dbg(cscfg_device(), "Activate config %s.\n", config_desc->name); > + break; > + } > + } > + mutex_unlock(&cscfg_mutex); > + > + return err; > +} > +EXPORT_SYMBOL_GPL(cscfg_activate_config); > + > +/** > + * cscfg_deactivate_config - Mark a config descriptor as inactive. > + * > + * Decrement the configuration and global active counts. > + * > + * @cfg_hash: Hash value of the selected configuration name. > + */ > +void cscfg_deactivate_config(unsigned long cfg_hash) > +{ > + struct cscfg_config_desc *config_desc; > + > + mutex_lock(&cscfg_mutex); > + > + list_for_each_entry(config_desc, &cscfg_mgr->config_desc_list, item) { > + if ((unsigned long)config_desc->event_ea->var == cfg_hash) { > + atomic_dec(&config_desc->active_cnt); > + atomic_dec(&cscfg_mgr->sys_active_cnt); > + dev_dbg(cscfg_device(), "Deactivate config %s.\n", config_desc->name); > + break; > + } > + } > + mutex_unlock(&cscfg_mutex); > +} > +EXPORT_SYMBOL_GPL(cscfg_deactivate_config); > + > +/** > + * cscfg_csdev_enable_active_config - Enable matching active configuration for device. > + * > + * Enables the configuration selected by @cfg_hash if the configuration is supported > + * on the device and has been activated. > + * > + * If active and supported the CoreSight device @csdev will be programmed with the > + * configuration, using @preset parameters. > + * > + * Should be called before driver hardware enable for the requested device, prior to > + * programming and enabling the physical hardware. > + * > + * @csdev: CoreSight device to program. > + * @cfg_hash: Selector for the configuration. > + * @preset: Preset parameter values to use, 0 for current / default values. > + */ > +int cscfg_csdev_enable_active_config(struct coresight_device *csdev, > + unsigned long cfg_hash, int preset) > +{ > + struct cscfg_config_csdev *config_csdev_active = NULL, *config_csdev_item; > + const struct cscfg_config_desc *config_desc; > + unsigned long flags; > + int err = 0; > + > + /* quickly check global count */ > + if (!atomic_read(&cscfg_mgr->sys_active_cnt)) > + return 0; > + > + /* look for matching config - set in_enable flag if found */ > + spin_lock_irqsave(&csdev->cscfg_csdev_lock, flags); > + list_for_each_entry(config_csdev_item, &csdev->config_csdev_list, node) { > + config_desc = config_csdev_item->config_desc; > + if ((atomic_read(&config_desc->active_cnt)) && > + ((unsigned long)config_desc->event_ea->var == cfg_hash)) { > + config_csdev_active = config_csdev_item; > + csdev->cscfg_in_enable = true; > + break; > + } > + } > + spin_unlock_irqrestore(&csdev->cscfg_csdev_lock, flags) In the previous revision the mutex wasn't dropped and cscfg_csdev_enable_config() was called with the mutex held. Any reason for not doing that with the spinlock implemenation? If anything it should be more efficient because the spinlock is on a per csdev basis. It would also keep things simple and avoid adding a new ->cscfg_in_enable field to the coresight_device structure. That last point really concerns me - if holding the spinlock is not possible than a new approach should be considered. Thanks, Mathieu > + > + /* > + * If found, attempt to enable and then set as enabled if no error > + * and in enable flag still set. > + */ > + if (config_csdev_active) { > + /* > + * Call the generic routine that will program up the internal > + * driver structures prior to programming up the hardware. > + * This routine takes the driver spinlock saved in the configs. > + */ > + err = cscfg_csdev_enable_config(config_csdev_active, preset); > + if (!err) { > + /* > + * Successful programming. re-check in_enable flag > + * to avoid potential race with disable config. > + */ > + spin_lock_irqsave(&csdev->cscfg_csdev_lock, flags); > + if (csdev->cscfg_in_enable) > + csdev->active_cscfg_ctxt = (void *)config_csdev_active; > + csdev->cscfg_in_enable = false; > + spin_unlock_irqrestore(&csdev->cscfg_csdev_lock, flags); > + } > + } > + return err; > +} > +EXPORT_SYMBOL_GPL(cscfg_csdev_enable_active_config); > + > +/** > + * cscfg_csdev_disable_active_config - disable an active config on the device. > + * > + * Disables the active configuration on the CoreSight device @csdev. > + * Disable will save the values of any registers marked in the configurations > + * as save on disable. > + * > + * Should be called after driver hardware disable for the requested device, > + * after disabling the physical hardware and reading back registers. > + * > + * @csdev: The CoreSight device. > + */ > +void cscfg_csdev_disable_active_config(struct coresight_device *csdev) > +{ > + struct cscfg_config_csdev *config_csdev; > + unsigned long flags; > + > + spin_lock_irqsave(&csdev->cscfg_csdev_lock, flags); > + csdev->cscfg_in_enable = false; > + config_csdev = (struct cscfg_config_csdev *)csdev->active_cscfg_ctxt; > + csdev->active_cscfg_ctxt = NULL; > + spin_unlock_irqrestore(&csdev->cscfg_csdev_lock, flags); > + > + if (config_csdev) > + cscfg_csdev_disable_config(config_csdev); > +} > +EXPORT_SYMBOL_GPL(cscfg_csdev_disable_active_config); > + > /* Initialise system configuration management device. */ > > struct device *cscfg_device(void) > @@ -536,6 +732,7 @@ int __init cscfg_init(void) > INIT_LIST_HEAD(&cscfg_mgr->csdev_desc_list); > INIT_LIST_HEAD(&cscfg_mgr->feat_desc_list); > INIT_LIST_HEAD(&cscfg_mgr->config_desc_list); > + atomic_set(&cscfg_mgr->sys_active_cnt, 0); > > dev_info(cscfg_device(), "CoreSight Configuration manager initialised"); > return 0; > diff --git a/drivers/hwtracing/coresight/coresight-syscfg.h b/drivers/hwtracing/coresight/coresight-syscfg.h > index 5bcae3b374c6..a52775890670 100644 > --- a/drivers/hwtracing/coresight/coresight-syscfg.h > +++ b/drivers/hwtracing/coresight/coresight-syscfg.h > @@ -24,12 +24,14 @@ > * @csdev_desc_list: List of coresight devices registered with the configuration manager. > * @feat_desc_list: List of feature descriptors to load into registered devices. > * @config_desc_list: List of system configuration descriptors to load into registered devices. > + * @sys_active_cnt: Total number of active config descriptor references. > */ > struct cscfg_manager { > struct device dev; > struct list_head csdev_desc_list; > struct list_head feat_desc_list; > struct list_head config_desc_list; > + atomic_t sys_active_cnt; > }; > > /* get reference to dev in cscfg_manager */ > @@ -61,5 +63,11 @@ int cscfg_load_config_sets(struct cscfg_config_desc **cfg_descs, > int cscfg_register_csdev(struct coresight_device *csdev, u32 match_flags, > 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 cfg_hash, int preset); > +void cscfg_csdev_disable_active_config(struct coresight_device *csdev); > > #endif /* CORESIGHT_SYSCFG_H */ > diff --git a/include/linux/coresight.h b/include/linux/coresight.h > index 16544ae2b532..e66e1a5fd803 100644 > --- a/include/linux/coresight.h > +++ b/include/linux/coresight.h > @@ -223,6 +223,8 @@ struct coresight_sysfs_link { > * @feature_csdev_list: List of complex feature programming added to the device. > * @config_csdev_list: List of system configurations added to the device. > * @cscfg_csdev_lock: Protect the lists of configurations and features. > + * @active_cscfg_ctxt: Context information for current active system configuration. > + * @cscfg_in_enable: Flag to indicate we are in the process of enabling. > */ > struct coresight_device { > struct coresight_platform_data *pdata; > @@ -248,6 +250,8 @@ struct coresight_device { > struct list_head feature_csdev_list; > struct list_head config_csdev_list; > spinlock_t cscfg_csdev_lock; > + void *active_cscfg_ctxt; > + bool cscfg_in_enable; > }; > > /* > -- > 2.17.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel