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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B194BC433F5 for ; Thu, 11 Nov 2021 17:25:03 +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 7E27D61268 for ; Thu, 11 Nov 2021 17:25:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7E27D61268 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=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=ePdexD1ob7TZi4QABVXdkxKrFlHh421+suhESrY/ktk=; b=tC3OYqGMt98drR 4pCnW7HgAm4onpuRF/cI0neeODBTAqFoyWjumpeDcXmP6+DLPjtpoJ+J7Mxl6DLgytx+em6j40bpZ aGqQCA2/ZxtH4FFMpwdkKFlEUEqVit+1ESaDlgyDm5VVd0rPrO942fuWrQXLzdKMTaFuLrxW1Xwhq zto+z4WkIDejao6LYanTdmw2RfKdDmW4364dHkbw8ynibI9G2kBs9ktc5sw31g3VUxf+PVHf07Ryt ZM6YwNSVev8BGXjNHk1UrejcPupLqZ4e9yx95oRBMPYm+mtT5iSttqne8Rd862WuLuTy+iCneWPV9 uu/L7dgmuRnvvNLs+Rsw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mlDng-008U5o-Fe; Thu, 11 Nov 2021 17:23:48 +0000 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mlDnV-008U3s-8F for linux-arm-kernel@lists.infradead.org; Thu, 11 Nov 2021 17:23:40 +0000 Received: by mail-pj1-x1032.google.com with SMTP id j5-20020a17090a318500b001a6c749e697so4420455pjb.1 for ; Thu, 11 Nov 2021 09:23:36 -0800 (PST) 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=Ce5uh+B4rkHwiuobM4ULleIW/E3f5lIRodTTcygfJAU=; b=jkvTOVGh+NMcGsa59FYFySwU+mWD4TR+yhVmOxpVNfA3UkVkgQPPByzSjxH60XoGhI eEMwZkQcRxUJr/ukAISGkkOArHxhk7lKP8FwO0UkS5aq/BRfPPaTL2m+Gzc21KQ52lcr Hj3wlGCDWDogG1qO4YPqaRfNqjIFLoiT7FyX0gvd93kkF8a0R+MpOSZSXFCNHxfMrSCO jYy+XHhtjAtK/S993Xksn3k41X2J93YFmuNTBa3b+ve/GoULA/dMamyrtCglnmE/a7Qv zU/GNKlUoBOWL2bEtcxEn1+2UGaEsU9G655LfJJMXrQr19JSDpPNWRC81tI1FPeqV6ZJ jcww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Ce5uh+B4rkHwiuobM4ULleIW/E3f5lIRodTTcygfJAU=; b=srTu/aRn6+CAirRhZybYJrx3uPG9+GCj1t23Efs4w769RZLWjAFxG5shuWgtG4mGSx m8K+lnpYVUMVI9aph8+BJPuqi3hzrDg6l9qy1p1Ssjhje+NaKgo1wU/wv1caj+bW535e VXwwrPNkdNzxIptho6LtZCSqiYE7HMpwszkhrEVKIyix4dBFFJHhKqSgJ3pa2wAlOafy 6iGIUhDYchmGpMvu3Ao6zKYw7QzusRCvjCA30WbUqSTs7TAP1o26rji2/9bUVsX998eZ 6f35QO1s8uX8zxhD0H54rkRn7gI2B9e2LmPXxlrjiqlD2Ci5x1CDA+kcYdYthUkD9dxq OhRw== X-Gm-Message-State: AOAM531amYfdB4ev8JP9DxEHDfRbjVZyRmRhfv8eqLflLO/lDtAo5ptw +USS5bcK+lVi1+gLQGWvo0GJaXv/ldlCkg== X-Google-Smtp-Source: ABdhPJyuBSuS7vomPDjSfa2qJUNs+m3+9vCncQeH7C/yxmvcX5N7WVOekHSLypIuEKJvhuLtyu3zJw== X-Received: by 2002:a17:902:d703:b0:140:125b:40a5 with SMTP id w3-20020a170902d70300b00140125b40a5mr699803ply.65.1636651415454; Thu, 11 Nov 2021 09:23:35 -0800 (PST) Received: from p14s (S0106889e681aac74.cg.shawcable.net. [68.147.0.187]) by smtp.gmail.com with ESMTPSA id fw21sm8623604pjb.25.2021.11.11.09.23.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Nov 2021 09:23:33 -0800 (PST) Date: Thu, 11 Nov 2021 10:23:31 -0700 From: Mathieu Poirier To: Mike Leach Cc: coresight@lists.linaro.org, linux-arm-kernel@lists.infradead.org, suzuki.poulose@arm.com, leo.yan@linaro.org Subject: Re: [PATCH v2 4/5] coresight: configfs: Allow configfs to activate configuration Message-ID: <20211111172331.GA2123533@p14s> References: <20211019191351.10242-1-mike.leach@linaro.org> <20211019191351.10242-5-mike.leach@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20211019191351.10242-5-mike.leach@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211111_092337_370642_E34B7440 X-CRM114-Status: GOOD ( 42.37 ) 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 Good day Mike, On Tue, Oct 19, 2021 at 08:13:50PM +0100, Mike Leach wrote: > Adds configfs attributes to allow a configuration to be enabled for use > when sysfs is used to control CoreSight. > > perf retains independent enabling of configurations. > > Signed-off-by: Mike Leach > --- > .../coresight/coresight-etm4x-core.c | 11 +- > .../coresight/coresight-syscfg-configfs.c | 67 ++++++++++ > .../coresight/coresight-syscfg-configfs.h | 2 + > .../hwtracing/coresight/coresight-syscfg.c | 126 ++++++++++++++---- > .../hwtracing/coresight/coresight-syscfg.h | 8 +- > 5 files changed, 186 insertions(+), 28 deletions(-) > > diff --git a/drivers/hwtracing/coresight/coresight-etm4x-core.c b/drivers/hwtracing/coresight/coresight-etm4x-core.c > index 86a313857b58..bf18128cf5de 100644 > --- a/drivers/hwtracing/coresight/coresight-etm4x-core.c > +++ b/drivers/hwtracing/coresight/coresight-etm4x-core.c > @@ -722,7 +722,16 @@ static int etm4_enable_sysfs(struct coresight_device *csdev) > { > struct etmv4_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); > struct etm4_enable_arg arg = { }; > - int ret; > + unsigned long cfg_hash; > + int ret, preset; > + > + /* enable any config activated by configfs */ > + cscfg_config_sysfs_get_active_cfg(&cfg_hash, &preset); > + if (cfg_hash) { > + ret = cscfg_csdev_enable_active_config(csdev, cfg_hash, preset); > + if (ret) > + return ret; > + } > > spin_lock(&drvdata->spinlock); > > diff --git a/drivers/hwtracing/coresight/coresight-syscfg-configfs.c b/drivers/hwtracing/coresight/coresight-syscfg-configfs.c > index 345a62f1b728..c388a77a2683 100644 > --- a/drivers/hwtracing/coresight/coresight-syscfg-configfs.c > +++ b/drivers/hwtracing/coresight/coresight-syscfg-configfs.c > @@ -6,6 +6,7 @@ > > #include > > +#include "coresight-config.h" > #include "coresight-syscfg-configfs.h" > > /* create a default ci_type. */ > @@ -87,9 +88,75 @@ static ssize_t cscfg_cfg_values_show(struct config_item *item, char *page) > } > CONFIGFS_ATTR_RO(cscfg_cfg_, values); > > +static ssize_t cscfg_cfg_activate_show(struct config_item *item, char *page) > +{ > + struct cscfg_fs_config *fs_config = container_of(to_config_group(item), > + struct cscfg_fs_config, group); > + > + return scnprintf(page, PAGE_SIZE, "%d\n", fs_config->active); > +} > + > +static ssize_t cscfg_cfg_activate_store(struct config_item *item, > + const char *page, size_t count) > +{ > + struct cscfg_fs_config *fs_config = container_of(to_config_group(item), > + struct cscfg_fs_config, group); > + int err; > + bool val; > + > + err = kstrtobool(page, &val); > + if (!err) > + err = cscfg_config_sysfs_activate(fs_config->config_desc, val); > + if (!err) { > + fs_config->active = val; > + if (val) > + cscfg_config_sysfs_set_preset(fs_config->preset); > + } > + return err ? err : count; > +} > +CONFIGFS_ATTR(cscfg_cfg_, activate); I would call this "enable" to follow what is already done for coresight in sysfs. > + > +static ssize_t cscfg_cfg_active_preset_show(struct config_item *item, char *page) > +{ > + struct cscfg_fs_config *fs_config = container_of(to_config_group(item), > + struct cscfg_fs_config, group); > + > + return scnprintf(page, PAGE_SIZE, "%d\n", fs_config->preset); > +} > + > +static ssize_t cscfg_cfg_active_preset_store(struct config_item *item, > + const char *page, size_t count) > +{ > + struct cscfg_fs_config *fs_config = container_of(to_config_group(item), > + struct cscfg_fs_config, group); > + int preset, err; > + > + err = kstrtoint(page, 0, &preset); > + if (!err) { > + /* > + * presets start at 1, and go up to max (15), > + * but the config may provide fewer. > + */ > + if ((preset < 1) || (preset > fs_config->config_desc->nr_presets)) > + err = -EINVAL; > + } > + > + if (!err) { > + /* set new value */ > + fs_config->preset = preset; > + /* set on system if active */ > + if (fs_config->active) > + cscfg_config_sysfs_set_preset(fs_config->preset); > + } > + return err ? err : count; > +} > +CONFIGFS_ATTR(cscfg_cfg_, active_preset); And I would call this "preset" since this is what is used on the perf cmd line. Please add a new "Using Configurations from configfs" section in [1] to show how "enable" and "preset" should be used. With that: Reviewed-by: Mathieu Poirier [1]. Documentation/trace/coresight/coresight-config.rst > + > static struct configfs_attribute *cscfg_config_view_attrs[] = { > &cscfg_cfg_attr_description, > &cscfg_cfg_attr_feature_refs, > + &cscfg_cfg_attr_activate, > + &cscfg_cfg_attr_active_preset, > NULL, > }; > > diff --git a/drivers/hwtracing/coresight/coresight-syscfg-configfs.h b/drivers/hwtracing/coresight/coresight-syscfg-configfs.h > index ea1e54d29f7f..373d84d43268 100644 > --- a/drivers/hwtracing/coresight/coresight-syscfg-configfs.h > +++ b/drivers/hwtracing/coresight/coresight-syscfg-configfs.h > @@ -15,6 +15,8 @@ > struct cscfg_fs_config { > struct cscfg_config_desc *config_desc; > struct config_group group; > + bool active; > + int preset; > }; > > /* container for feature view */ > diff --git a/drivers/hwtracing/coresight/coresight-syscfg.c b/drivers/hwtracing/coresight/coresight-syscfg.c > index 4b91d8d9bc37..759c32889efd 100644 > --- a/drivers/hwtracing/coresight/coresight-syscfg.c > +++ b/drivers/hwtracing/coresight/coresight-syscfg.c > @@ -744,30 +744,20 @@ void cscfg_csdev_reset_feats(struct coresight_device *csdev) > } > 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. > +/* > + * This activate configuration for either perf or sysfs. Perf can have multiple > + * active configs, selected per event, sysfs is limited to one. > * > * 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) > +static 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) { > /* must ensure that config cannot be unloaded in use */ > @@ -791,6 +781,101 @@ int cscfg_activate_config(unsigned long cfg_hash) > break; > } > } > + return err; > +} > + > +static void _cscfg_deactivate_config(unsigned long cfg_hash) > +{ > + struct cscfg_config_desc *config_desc; > + > + 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); > + cscfg_owner_put(config_desc->load_owner); > + dev_dbg(cscfg_device(), "Deactivate config %s.\n", config_desc->name); > + break; > + } > + } > +} > + > +/* > + * called from configfs to set/clear the active configuration for use when > + * using sysfs to control trace. > + */ > +int cscfg_config_sysfs_activate(struct cscfg_config_desc *config_desc, bool activate) > +{ > + unsigned long cfg_hash; > + int err = 0; > + > + mutex_lock(&cscfg_mutex); > + > + cfg_hash = (unsigned long)config_desc->event_ea->var; > + > + if (activate) { > + /* cannot be a current active value to activate this */ > + if (cscfg_mgr->sysfs_active_config) { > + err = -EBUSY; > + goto exit_unlock; > + } > + err = _cscfg_activate_config(cfg_hash); > + if (!err) > + cscfg_mgr->sysfs_active_config = cfg_hash; > + } else { > + /* disable if matching current value */ > + if (cscfg_mgr->sysfs_active_config == cfg_hash) { > + _cscfg_deactivate_config(cfg_hash); > + cscfg_mgr->sysfs_active_config = 0; > + } else > + err = -EINVAL; > + } > + > +exit_unlock: > + mutex_unlock(&cscfg_mutex); > + return err; > +} > + > +/* set the sysfs preset value */ > +void cscfg_config_sysfs_set_preset(int preset) > +{ > + mutex_lock(&cscfg_mutex); > + cscfg_mgr->sysfs_active_preset = preset; > + mutex_unlock(&cscfg_mutex); > +} > + > +/* > + * Used by a device to get the config and preset selected as active in configfs, > + * when using sysfs to control trace. > + */ > +void cscfg_config_sysfs_get_active_cfg(unsigned long *cfg_hash, int *preset) > +{ > + mutex_lock(&cscfg_mutex); > + *preset = cscfg_mgr->sysfs_active_preset; > + *cfg_hash = cscfg_mgr->sysfs_active_config; > + mutex_unlock(&cscfg_mutex); > +} > +EXPORT_SYMBOL_GPL(cscfg_config_sysfs_get_active_cfg); > + > +/** > + * 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. > + * > + * @cfg_hash: Hash value of the selected configuration name. > + */ > +int cscfg_activate_config(unsigned long cfg_hash) > +{ > + int err = 0; > + > + mutex_lock(&cscfg_mutex); > + err = _cscfg_activate_config(cfg_hash); > mutex_unlock(&cscfg_mutex); > > return err; > @@ -806,19 +891,8 @@ 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); > - cscfg_owner_put(config_desc->load_owner); > - dev_dbg(cscfg_device(), "Deactivate config %s.\n", config_desc->name); > - break; > - } > - } > + _cscfg_deactivate_config(cfg_hash); > mutex_unlock(&cscfg_mutex); > } > EXPORT_SYMBOL_GPL(cscfg_deactivate_config); > diff --git a/drivers/hwtracing/coresight/coresight-syscfg.h b/drivers/hwtracing/coresight/coresight-syscfg.h > index 1da37874f70f..9106ffab4833 100644 > --- a/drivers/hwtracing/coresight/coresight-syscfg.h > +++ b/drivers/hwtracing/coresight/coresight-syscfg.h > @@ -28,6 +28,8 @@ > * @load_order_list: Ordered list of owners for dynamically loaded configurations. > * @sys_active_cnt: Total number of active config descriptor references. > * @cfgfs_subsys: configfs subsystem used to manage configurations. > + * @sysfs_active_config:Active config hash used if CoreSight controlled from sysfs. > + * @sysfs_active_preset:Active preset index used if CoreSight controlled from sysfs. > */ > struct cscfg_manager { > struct device dev; > @@ -37,6 +39,8 @@ struct cscfg_manager { > struct list_head load_order_list; > atomic_t sys_active_cnt; > struct configfs_subsystem cfgfs_subsys; > + u32 sysfs_active_config; > + int sysfs_active_preset; > }; > > /* get reference to dev in cscfg_manager */ > @@ -88,7 +92,8 @@ int cscfg_preload(void *owner_handle); > const struct cscfg_feature_desc *cscfg_get_named_feat_desc(const char *name); > int cscfg_update_feat_param_val(struct cscfg_feature_desc *feat_desc, > int param_idx, u64 value); > - > +int cscfg_config_sysfs_activate(struct cscfg_config_desc *cfg_desc, bool activate); > +void cscfg_config_sysfs_set_preset(int preset); > > /* syscfg manager external API */ > int cscfg_load_config_sets(struct cscfg_config_desc **cfg_descs, > @@ -104,5 +109,6 @@ 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); > +void cscfg_config_sysfs_get_active_cfg(unsigned long *cfg_hash, int *preset); > > #endif /* CORESIGHT_SYSCFG_H */ > -- > 2.17.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel