From patchwork Fri Oct 30 17:56:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 11870447 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=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 0C623C4741F for ; Fri, 30 Oct 2020 17:58:05 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 5872520724 for ; Fri, 30 Oct 2020 17:58:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="vIKOmIjz"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="b4ekQa26" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5872520724 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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:References:In-Reply-To:Message-Id:Date:Subject:To: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=pLuc/XtM9qATXexyUfrM2G5h4Lrpmp3xmDX4YwDwBU0=; b=vIKOmIjzTvbmEJhufIe0EFqxny X11vH6Fp0PGUi0JvZGfyx6YFzdvTUCDal+eS3V2RPfUCWUWPKOtJmoouKF2/kGFlZ06X+21vrYDlh nYMXQUZTDAM6RQdFPR4qdKcvJWnvEj0sV8P+ix/X7JIHTmEdiKGlTiaZVSfe+UU48hI9wUnyCFlX3 g7SmawqHjp21AmkBLKuppZ/XL/ZUsweOM7h2jUUygfBu0PawNc8SznJxOk3kqYuz2gAhDkAuHsCK3 OzJJ5vqgSZpzy1+1JZyLUSLDGCVyt+mzwcRd+A296acufTXQGPtFKXg0K3U3VPQZtxK2xMu0AmuBf atTFodaA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kYYeV-0003qq-05; Fri, 30 Oct 2020 17:57:27 +0000 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kYYe7-0003lT-M9 for linux-arm-kernel@lists.infradead.org; Fri, 30 Oct 2020 17:57:10 +0000 Received: by mail-wr1-x444.google.com with SMTP id w1so7426979wrm.4 for ; Fri, 30 Oct 2020 10:57:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fnhKKm1kNyGRocxXWeA8x5GkuNBQ4iZFdMaD+sZUm08=; b=b4ekQa26168ms1s0PZDo6WIXR8wLU6LaCOdJ+1+/bsuNxb6x8QYwhtJyJURskwsNrK t+iD4TojwX03sulwXK7uferGHZTdfcp/D6MXygcyEpFRD/KVffKgDuL+akEUwcbdfi1C UbK0XHJjZ9KwNDy0pCdIp64q3FCqeyh4+72uo+ulG0jaLFcj9IPi98fQI8xTciwDsx8P N0dSu8mEVOaN8svd7fhwlcqS1BJAknQXue6+0FD0PMnfZs3waIz2ztj6QXJtTcRUyVgK WcLqeIUkiYacRJyrwjlUzr4S/i2DbjBCDQJuIS4ur4pb3hYwmPmO8JF9xngKu3vtsRFF DX4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fnhKKm1kNyGRocxXWeA8x5GkuNBQ4iZFdMaD+sZUm08=; b=ZVCWrOPVgQLZNf0gm9GvyKkJtaNIszIyFtgB72WCcneIjzt7WYO/rRB7789Mrna4li Ojflkk6yJwhRcMx7s1PJomvy/igBysNVLBAjloUinuww1RiRG1ZuXr8z3Zyt5XADF7cC 7lsIYzyOKXxNFYqG6FUXeiwjW2DV3xZc04Knb+c8TKUvrtopOrYx4qoBIMXMS6smmXv2 NqQ8JzwT0qv8/2YBqQ+oe27wLNFkj+XioL1iVcDj+/6ud4qTd2m9TEeYkY7SpL3/Mznz pVQgYJsjVh6uS1mpZhs4rd1Wcp8ztSCznyO+e+pr2oHaz2iJqS+jJhQEPhqus9SuHKw+ Ftfg== X-Gm-Message-State: AOAM530SAgPeyE7psPtbfo7QhQRnOiMxJmR/OhPHV6KmAXgx/4l8ta17 RaNLh1YBIphHjpq03fHyL5Kx/tffu1bBXg== X-Google-Smtp-Source: ABdhPJzIsc5buJ66Xp/38o6rd17yrUwyQ5gpd0AkmtWja4cnH1xYdXQ0ANwr0lFN0ECFYYeZCYf0jg== X-Received: by 2002:adf:9507:: with SMTP id 7mr4651947wrs.365.1604080622319; Fri, 30 Oct 2020 10:57:02 -0700 (PDT) Received: from linaro.org ([2a00:23c5:6801:1801:4964:83f8:d2e7:f2c9]) by smtp.gmail.com with ESMTPSA id o129sm5615563wmb.25.2020.10.30.10.57.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Oct 2020 10:57:01 -0700 (PDT) From: Mike Leach To: linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org, mathieu.poirier@linaro.org Subject: [RFC PATCH v3 4/9] coresight: etm-perf: update to handle configuration selection Date: Fri, 30 Oct 2020 17:56:50 +0000 Message-Id: <20201030175655.30126-5-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201030175655.30126-1-mike.leach@linaro.org> References: <20201030175655.30126-1-mike.leach@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201030_135703_837096_18DCC554 X-CRM114-Status: GOOD ( 33.05 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: yabinc@google.com, Mike Leach , suzuki.poulose@arm.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org 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 --- .../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 | 23 ++- 4 files changed, 172 insertions(+), 28 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-config.h b/drivers/hwtracing/coresight/coresight-config.h index a3d374ebb70f..372f29a59688 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..8a87984195ed 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -20,6 +20,8 @@ #include "coresight-etm-perf.h" #include "coresight-priv.h" +#include "coresight-config.h" +#include "coresight-syscfg.h" static struct pmu etm_pmu; static bool etm_perf_up; @@ -34,6 +36,11 @@ PMU_FORMAT_ATTR(timestamp, "config:" __stringify(ETM_OPT_TS)); PMU_FORMAT_ATTR(retstack, "config:" __stringify(ETM_OPT_RETSTK)); /* Sink ID - same for all ETMs */ PMU_FORMAT_ATTR(sinkid, "config2:0-31"); +/* preset - if sink ID is used as a configuration selector */ +PMU_FORMAT_ATTR(preset, "config:0-3"); +/* 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, 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 */ 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=". + * 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"); + + if (!err) + err = etm_perf_add_cscfg_event(dev, cs_cfg); + + 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 98ee78e3412a..8d52580daf04 100644 --- a/drivers/hwtracing/coresight/coresight-syscfg.c +++ b/drivers/hwtracing/coresight/coresight-syscfg.c @@ -7,6 +7,7 @@ #include #include "coresight-config.h" +#include "coresight-etm-perf.h" #include "coresight-syscfg.h" /* @@ -85,7 +86,7 @@ static int cscfg_add_csdev_cfg(struct coresight_device *csdev, struct cscfg_config_csdev *dev_cfg = NULL; struct cscfg_config_feat_ref *feat_ref; struct cscfg_feature_csdev *feat; - int checked; + int checked, err; /* look at each required feature and see if it matches any feature on the device */ for (checked = 0; checked < cfg_desc->nr_refs; checked++) { @@ -97,16 +98,22 @@ static int cscfg_add_csdev_cfg(struct coresight_device *csdev, return -EINVAL; if (!dev_cfg) { dev_cfg = cscfg_alloc_csdev_cfg(csdev, cfg_desc->nr_refs); - if (!dev_cfg) - return -ENOMEM; dev_cfg->desc = cfg_desc; + dev_cfg->id_hash = (unsigned long)cfg_desc->id_ea->var; } dev_cfg->feats[dev_cfg->nr_feat++] = feat; } } + /* if matched features, add config to device.*/ - if (dev_cfg) + if (dev_cfg) { + /* add config name to perf event directory if this is valid source */ + if (match_info->match_flags & CS_CFG_MATCH_CLASS_SRC_ALL) + err = etm_perf_add_symlink_cscfg(&csdev->dev, cfg_desc); + if (err) + return err; list_add(&dev_cfg->node, &csdev->syscfg_list); + } return 0; } @@ -282,8 +289,9 @@ static int cscfg_load_config(struct cscfg_config_desc *cfg_desc) return err; list_add(&cfg_desc->item, &cscfg_data.config_list); + err = etm_perf_add_symlink_cscfg(to_device_cscfg(), cfg_desc); - return 0; + return err; } /* @@ -532,7 +540,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_data.config_list, item) { + etm_perf_del_symlink_cscfg(cfg_desc); + } device_unregister(to_device_cscfg()); mutex_unlock(&cscfg_mutex); }