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=-13.8 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=ham 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 7DC29C433B4 for ; Thu, 1 Apr 2021 16:44:51 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 C984D6136B for ; Thu, 1 Apr 2021 16:44:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C984D6136B 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=desiato.20200630; 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=t+2kxFhBXCp27+DQOGdgTqE+iI2+/AMdrGEkEAYaZHs=; b=GFj/8VDzzt5MF9uACB1ZSntlm QR6ETA8duH6W3fNgYWSxYhhJpx/DIqTWaUa3O22HS5uZVu/IBuERlDeyh4VLWM8aPCkLBzics7qDz HMp9JY7zqvHTSOqFuW9BnreqaHRXBzNqKs2vuCYUDxyaLSSuOpDoSKFETh6yls7DzcLx/OaZTU+jH u98gbDvJE2vcnXCLlrI0W/JGbogQ4Z6EwBfNpj2jVM1ODzoPmOcP3VtuNQX5N9HLr4utNvNM+vBEP T84+cklSG0TTx4OQrJ3bHodvxY4PmQ2bOCAzDURtLmEjfvRciKTRbua7mtl8x6UurthiO4j45H63D CHQ9YqXcQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lS0Pj-00AMUN-LQ; Thu, 01 Apr 2021 16:43:24 +0000 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lS0Pd-00AMT6-VA for linux-arm-kernel@lists.infradead.org; Thu, 01 Apr 2021 16:43:20 +0000 Received: by mail-pj1-x1031.google.com with SMTP id k23-20020a17090a5917b02901043e35ad4aso3375890pji.3 for ; Thu, 01 Apr 2021 09:43:17 -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=9kXrOvZONIFORzF1gr1KYSrBPGnVSir3zJQM6INvU0c=; b=UYTI2Z+XERu2McjjUV04jXIH/tJEVfD74dnF479gOXCxIwNj89UzCQfJANLtUcSMCo ZfVtPNhQGVPNLtH1nHjnkfyVjL3Vr6yUtivC7fqVxbmgas5Xqr5uZyUX1SR099gSnUBL 186fg3T8c1jJwHEcwtzwkFjYTZRfcu4WZ+fg+yZqTqxMTX+Zp9KFJ5yWxeA2JB3Xa/8s Z+Bj3/sfrmlT7mKQN7b0qD7Ec+hBdi0GuKr5+z4IiqQLk9J+V6tKeEHxzElp0hjBBg/i 4WjOOi+LW9oLjIt7Ck5/pEcg0Mg9/nLjULJUrvqWwN/Lu8lZVFJ34pDJefqfiRj0Plr/ f9DA== 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=9kXrOvZONIFORzF1gr1KYSrBPGnVSir3zJQM6INvU0c=; b=GG1e6FxQk0FsIShPpejny+yX/daEHrnF3RcfylObMn7E4junX+u9VUjl+pjweqODdR VYXiXpD9pNK+vMkFxd1ZcLylgG4QgOzoJEb1XqK4/K73F8gHytGsqvl56zDDmPbN+wfh gLvrsTgZQCo6zo7hULPKnw4xXVB/548C6xbnDO4zYeNfbJOXFAN4CrXx/7IYZJQMECwD XBGPku44rQXcgn5zxIoYM6g//Rh1fKdwhKlBUzpDyW9/p6wgX2b/+rZjGLSyEc1vUU5g tUP8OZ4B7SOwyuK/HW5AeqU+lkq+rMguEgRRcCTlklOyuLVtZJ3Uav3YU0yNOYE+TYqC MfsQ== X-Gm-Message-State: AOAM532lF7FkDpSRimNZlJY+mGdMvBgThkl07ivIDwadHOOG9M8veveE U361pO3QBdM/mmxsJXrdbq4KIg== X-Google-Smtp-Source: ABdhPJzlWF9LMWoYEoTpbDoszDeb2D+rJZVO0dKqePivBWRYnod6rpVFi8kvTiB4De7ZF6XMuAsrEw== X-Received: by 2002:a17:90a:f403:: with SMTP id ch3mr9741454pjb.126.1617295396385; Thu, 01 Apr 2021 09:43:16 -0700 (PDT) Received: from xps15 (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id 205sm6204905pfc.201.2021.04.01.09.43.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Apr 2021 09:43:15 -0700 (PDT) Date: Thu, 1 Apr 2021 10:43:13 -0600 From: Mathieu Poirier To: Mike Leach Cc: linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, linux-doc@vger.kernel.org, suzuki.poulose@arm.com, yabinc@google.com, corbet@lwn.net, leo.yan@linaro.org, alexander.shishkin@linux.intel.com, tingwei@codeaurora.org, gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v5 05/10] coresight: syscfg: Add API to activate and enable configurations Message-ID: <20210401164313.GA145043@xps15> References: <20210316180400.7184-1-mike.leach@linaro.org> <20210316180400.7184-6-mike.leach@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210316180400.7184-6-mike.leach@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210401_174318_139961_D106B47F X-CRM114-Status: GOOD ( 35.42 ) 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 Tue, Mar 16, 2021 at 06:03:55PM +0000, 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 > --- > .../hwtracing/coresight/coresight-config.h | 2 + > .../hwtracing/coresight/coresight-syscfg.c | 122 ++++++++++++++++++ > .../hwtracing/coresight/coresight-syscfg.h | 8 ++ > include/linux/coresight.h | 2 + > 4 files changed, 134 insertions(+) > Reviewed-by: Mathieu Poirier > diff --git a/drivers/hwtracing/coresight/coresight-config.h b/drivers/hwtracing/coresight/coresight-config.h > index 38fd1c71eb05..f1a5957a25c9 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 03014a2142c1..c44746d6cd6d 100644 > --- a/drivers/hwtracing/coresight/coresight-syscfg.c > +++ b/drivers/hwtracing/coresight/coresight-syscfg.c > @@ -284,6 +284,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; > } > > @@ -451,6 +452,126 @@ 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_csdev; > + > + mutex_lock(&cscfg_csdev_mutex); > + 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: > + 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 *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); > + > +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); > + > +/* Find and program any active config for the supplied device.*/ > +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; > + int err = 0; > + > + /* quickly check global count */ > + if (!atomic_read(&cscfg_mgr->sys_active_cnt)) > + return 0; > + > + mutex_lock(&cscfg_csdev_mutex); > + 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; > + break; > + } > + } > + if (config_csdev_active) { > + err = cscfg_csdev_enable_config(config_csdev_active, preset); > + if (!err) > + csdev->active_cscfg_ctxt = (void *)config_csdev_active; > + } > + 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 *config_csdev; > + > + mutex_lock(&cscfg_csdev_mutex); > + config_csdev = (struct cscfg_config_csdev *)csdev->active_cscfg_ctxt; > + if (config_csdev) > + cscfg_csdev_disable_config(config_csdev); > + mutex_unlock(&cscfg_csdev_mutex); > +} > +EXPORT_SYMBOL_GPL(cscfg_csdev_disable_active_config); > + > /* Initialise system configuration management device. */ > > struct device *cscfg_device(void) > @@ -519,6 +640,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 d0126ed326a6..a3b39ce2d6ef 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_cscfg_ctxt: Context information for current active system configuration. > */ > 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_cscfg_ctxt; > }; > > /* > -- > 2.17.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel