From patchwork Tue Jan 15 23:07:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 155683 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5455124jaa; Tue, 15 Jan 2019 15:08:32 -0800 (PST) X-Google-Smtp-Source: ALg8bN6u8wVI1b5ATqX1xIXvn4LKXjhxmjVA91+FmL2K5rKrnh14oHgJLIhiqEJDZj44/w924tRo X-Received: by 2002:aa7:810c:: with SMTP id b12mr6503592pfi.44.1547593711942; Tue, 15 Jan 2019 15:08:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547593711; cv=none; d=google.com; s=arc-20160816; b=oKQbNLHVYWb84Kg7evQiQGiJMOSb466Zz1/yEVA3zADwH+91Px/oOmzrrFJfe6LB0F 08ctsAgjt3AQ9CMiflVUVZe5jYZhQ/bO9rjJCshlQv8ptMwSyTPj0Zr9iE1Xk+7fv5sN oy8db9NqdXt8oW4FbwwAkNo1b6ecmC5NAP0sZgHC2rHM5S98CdlRjx6kb1khmo8RPUoQ vFfBunLMlS766Acx1RRD0ulSXqB95CKZmIf0hguq+brZxnAljZprUkhndcPaLfrAnqLB gJNi/JQd8rrvShjnGAPf79eP7hhycyXM4N7F9jr7ip3v99eJ+3VY0Cc14VzY6jiE8Ir8 TI2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=XDWNDjej1vaQghEKuWRObLfufBBUVnZJNWEVf/9UfwU=; b=Tpd6N/+kt5+7Sk/PTY7/cn0o0dy8KY5x7079K7faRf63mhHTrXOT2fnFjD8EySAUe5 4Yo7wm4Xs0eEUIbghzyqtlCWzSmnD4ALvwYUUUNh+KlgcX76DhrzS7A/LlXnqit3sQT0 +mEoV6zoYpi4W0kF2sUW8jhNAJrbqlO43VG6kM6lj90N1pjMynPEDzsJv7tYmCibI0ET iCnIeAp4kYfX4peTIR7iKzzkd9WTZryxp0HhIqOJQGTjVj48za91hkMawZorMIXyl0eo CExyXR1GHuKXFRuIrz6CzM3eQHk5GUzPeEPXRj7ELLUqyscZVuEVOSnpx+ce5O4xwQQU tLjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b84Jmktb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c10si4437322pll.271.2019.01.15.15.08.31; Tue, 15 Jan 2019 15:08:31 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=b84Jmktb; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391386AbfAOXIa (ORCPT + 31 others); Tue, 15 Jan 2019 18:08:30 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:44025 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387748AbfAOXHu (ORCPT ); Tue, 15 Jan 2019 18:07:50 -0500 Received: by mail-pl1-f196.google.com with SMTP id gn14so1989144plb.10 for ; Tue, 15 Jan 2019 15:07:50 -0800 (PST) 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=XDWNDjej1vaQghEKuWRObLfufBBUVnZJNWEVf/9UfwU=; b=b84JmktbH4LgEz2UKivbHhzC09x3UMXzJaMj8si6l+upZCirCs1QoNgBzprVBbDy9w FBzU4OKP2qSRSptbvbFV2QWDV8g/43fxihmkXRshEECSB0uW5kShD9zVMOAupagb+fO0 6GZki9k1wHHPDcr8WnLZ05pU620ghVn4IrqLY= 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=XDWNDjej1vaQghEKuWRObLfufBBUVnZJNWEVf/9UfwU=; b=cnjTvaq7D/0yj5zFe5HM+udZSIRrMr0yGeZerfQgL1eixlxOdNwEdwxq9ug7mLTd9y wUY7kWuDrg8JFTp2ArvxKmD2hE2XAN4aQIOwiwihXUop64cPhwqtjM3J2Vdtg8SxFiko nXKiKoz/HFq7DivSCTuHHiBxqAIzqLenmjjbhJPVac5rrls/WdHh4Md4VzEFQncmBrAb cUysK6NAc5+0PW7yfsQUqEX90LGLqldQ7z6zhInaJDgj3MbTwf22COngfVMBtgHgUnDK D3iSaCMQS9jWsJHP569C0H0cnMcuHiOqyyWf7zj5aFPPQof/zJHWCo8uxu7AAGINreTD 7Ogg== X-Gm-Message-State: AJcUukeGT3LWODMEwLjs8IHhL0Ng60tO07k8h8sjyV23jziTjhuKV4er k3cA7oXw5KNqX/d487yHt268FA== X-Received: by 2002:a17:902:6b87:: with SMTP id p7mr6690582plk.282.1547593669668; Tue, 15 Jan 2019 15:07:49 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id h19sm4985928pfn.114.2019.01.15.15.07.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Jan 2019 15:07:48 -0800 (PST) From: Mathieu Poirier To: acme@kernel.org, peterz@infradead.org, gregkh@linuxfoundation.org Cc: mingo@redhat.com, tglx@linutronix.de, alexander.shishkin@linux.intel.com, schwidefsky@de.ibm.com, heiko.carstens@de.ibm.com, will.deacon@arm.com, mark.rutland@arm.com, jolsa@redhat.com, namhyung@kernel.org, adrian.hunter@intel.com, ast@kernel.org, hpa@zytor.com, suzuki.poulose@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/7] coresight: perf: Add "sinks" group to PMU directory Date: Tue, 15 Jan 2019 16:07:37 -0700 Message-Id: <20190115230742.13730-3-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190115230742.13730-1-mathieu.poirier@linaro.org> References: <20190115230742.13730-1-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a "sinks" directory entry so that users can see all the sinks available in the system in a single place. Individual sink are added as they are registered with the coresight bus. Signed-off-by: Mathieu Poirier --- .../hwtracing/coresight/coresight-etm-perf.c | 43 +++++++++++++++++++ .../hwtracing/coresight/coresight-etm-perf.h | 1 + drivers/hwtracing/coresight/coresight.c | 17 ++++++++ 3 files changed, 61 insertions(+) -- 2.17.1 diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index f21eb28b6782..292bd409a68c 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include @@ -43,8 +44,18 @@ static const struct attribute_group etm_pmu_format_group = { .attrs = etm_config_formats_attr, }; +static struct attribute *etm_config_sinks_attr[] = { + NULL, +}; + +static const struct attribute_group etm_pmu_sinks_group = { + .name = "sinks", + .attrs = etm_config_sinks_attr, +}; + static const struct attribute_group *etm_pmu_attr_groups[] = { &etm_pmu_format_group, + &etm_pmu_sinks_group, NULL, }; @@ -479,6 +490,38 @@ int etm_perf_symlink(struct coresight_device *csdev, bool link) return 0; } +static ssize_t etm_perf_sink_name_show(struct device *dev, + struct device_attribute *dattr, + char *buf) +{ + /* See function coresight_sink_by_id() to know where this is used */ + u32 hash = hashlen_hash(hashlen_string(NULL, dattr->attr.name)); + + return scnprintf(buf, PAGE_SIZE, "%x\n", hash); +} + +int etm_perf_symlink_sink(struct coresight_device *csdev) +{ + struct device *pmu_dev = etm_pmu.dev; + struct device *pdev = csdev->dev.parent; + struct device_attribute *dev_attr; + + if (csdev->type != CORESIGHT_DEV_TYPE_SINK && + csdev->type != CORESIGHT_DEV_TYPE_LINKSINK) + return -EINVAL; + + if (!etm_perf_up) + return -EPROBE_DEFER; + + dev_attr = kzalloc(sizeof(*dev_attr), GFP_KERNEL); + dev_attr->attr.name = kstrdup(dev_name(pdev), GFP_KERNEL); + dev_attr->attr.mode = 0444; + dev_attr->show = etm_perf_sink_name_show; + + return sysfs_add_file_to_group(&pmu_dev->kobj, + &dev_attr->attr, "sinks"); +} + static 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 da7d9336a15c..529a47285c0f 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.h +++ b/drivers/hwtracing/coresight/coresight-etm-perf.h @@ -59,6 +59,7 @@ struct etm_event_data { #ifdef CONFIG_CORESIGHT int etm_perf_symlink(struct coresight_device *csdev, bool link); +int etm_perf_symlink_sink(struct coresight_device *csdev); static inline void *etm_perf_sink_config(struct perf_output_handle *handle) { struct etm_event_data *data = perf_get_aux(handle); diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index 2b0df1a0a8df..526f122a38ee 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -18,6 +18,7 @@ #include #include +#include "coresight-etm-perf.h" #include "coresight-priv.h" static DEFINE_MUTEX(coresight_mutex); @@ -1167,6 +1168,22 @@ struct coresight_device *coresight_register(struct coresight_desc *desc) goto err_out; } + if (csdev->type == CORESIGHT_DEV_TYPE_SINK || + csdev->type == CORESIGHT_DEV_TYPE_LINKSINK) { + ret = etm_perf_symlink_sink(csdev); + + if (ret) { + device_unregister(&csdev->dev); + /* + * As with the above, all resources are free'd + * explicitly via coresight_device_release() triggered + * from put_device(), which is in turn called from + * function device_unregister(). + */ + goto err_out; + } + } + mutex_lock(&coresight_mutex); coresight_fixup_device_conns(csdev);