From patchwork Tue Feb 5 23:24:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 157541 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp5755222jaa; Tue, 5 Feb 2019 15:25:16 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib18OK3vxXk+cwBkzqBS7mtj6vlqwfRBaGXLLbdnOCtnChaF6NJuEeWdW6BwoiIn76BMyHZ X-Received: by 2002:a63:4706:: with SMTP id u6mr6535457pga.95.1549409116839; Tue, 05 Feb 2019 15:25:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549409116; cv=none; d=google.com; s=arc-20160816; b=swQjoFjo88GIPh7QuoLwSkQXugj6q5XnvSz/GsFzUAsZDhHMH6+zl1TXxUMM6+1d7t BfuTVOIEztO8DT+0egp3URbVa/6IDUqtIsktQAfX+9QG4O/iIcuCYh2hvXqXmUzcI20p POJGpYfXgl6bFoIvEN1wnXvLuNP1VYHvjmn+jOhJJRDhAvKDqB3eAs3LdUO2z7lGgKgA ZeJg2xwGezOZvZGjztFPp1SUF5Gmw6826qFIuLAxVl9bwsozNX1iJ8l4MjXmo03qCitM UHdISLH8q9Mf+ZGLGZuT/lIIqHXDeXSd+GrcVyYKtMSZaEck3mxsDlNQYmXjsQr2HrdX dFKQ== 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=T/vUeT1ORrN3V6Xm/Q75X5Mtmayi18DWRftVV4tUDww=; b=N1DZzlgJulIqI8RSdXQNzLjWSr4XLg+kZ70I0tU69uX8Z0YLJ4TxQOZLR2pC3lqwmc MBdihBZxOXfSKVCghkVLvhILZhnAsxQ5yqX9HQh6udIwdFsfbffWLQpumcYZ43CRmWiM Ewweoi2n4IcZBNuUsx7kKgD+S+sHNqgoj9LPKgvOyUrRS4SanZ+GYp3sNe2/cnvE5AiD NQAcDx0BG2fj8wTTAhFVVvj7wxNtat6kncSUFgdf+ZYHkAMINK6RXENmwstRUWgEC3Va Pc4Hyp34Ja2jluf5n6I4Sx8b0xWHmkCy+7+lEpcAX+637z5sHzlQLXuEMefjN625GfoM mn5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bstSTAmY; 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 u9si785164plq.430.2019.02.05.15.25.16; Tue, 05 Feb 2019 15:25:16 -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=bstSTAmY; 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 S1729214AbfBEXZP (ORCPT + 31 others); Tue, 5 Feb 2019 18:25:15 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:38052 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728791AbfBEXZH (ORCPT ); Tue, 5 Feb 2019 18:25:07 -0500 Received: by mail-pl1-f193.google.com with SMTP id e5so2231841plb.5 for ; Tue, 05 Feb 2019 15:25:06 -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=T/vUeT1ORrN3V6Xm/Q75X5Mtmayi18DWRftVV4tUDww=; b=bstSTAmYg287/AN83sioCCQF3lwhhf2bu3omT1q2J+R9zhS3UM3KxeLXvMV1ruuCeP QDB9q6pw561Z7x5cOmJmYEb66TIF0mE95NJIcjM6rvXIEWJvmi+v5vvWga45nhDzPjpk pGeIBVREElGP5np/UgeHvUFPUWjv0zt6X9g/khfZUbJ8HInsukkb3ytF6L7BcJIT3VLP lq6UsgdG7zTZZIWczE/p2Wm9kJ5DIHTSSUGZHGPbMxWTDdXU0LH3MR18OOlb2GZcAqMB zVxXOQH1ezUo3rMGCoqA8Pi4YSRsOLbStwXI4+kgSAKu36hzx3DNICh+HDzeQ/WK1WU8 1gLQ== 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=T/vUeT1ORrN3V6Xm/Q75X5Mtmayi18DWRftVV4tUDww=; b=c19z85AZsJr56CxnZ6m6b3aAGEzgZX0uQuQcgCBYI0sDhdurL9pjq31TPwWLYcqbYj ZI/aWSBNuYdyNhLbGfoeRcqH4kfl4UzY51xvBtOKrL2ob6Pz/oIFeuXeVmnwKAIj0A9N h2XP7X0y8LlqUWPr33nI8OvfqkbNSWjNSWqeK7p3DLntT28maPaGtdC98vOH0wLTnUQY F6um8uIcVSKffosCFN0A74/uFRPQCRNpgYNXZbc+CR0HGtWfRm+5zbXdAEtrpTRLkcKv Hw9BkYNkhK/0VtfJothGRydU0XYaYOYltjg45gb21lv+cvoyW4zDyOoUheB8hVSq7u9e 8fOg== X-Gm-Message-State: AHQUAubvU71LAeQ02AKK66N/m6ePmuBs9vnTpJuT+SvuVgZe4TfyzmFu pRsAHltyYEx2+0oeipEnwKXtmBtF9PoWuQ== X-Received: by 2002:a17:902:4025:: with SMTP id b34mr7698243pld.181.1549409105757; Tue, 05 Feb 2019 15:25:05 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id g136sm5926917pfb.154.2019.02.05.15.25.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Feb 2019 15:25:05 -0800 (PST) From: Mathieu Poirier To: gregkh@linuxfoundation.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 5/6] coresight: perf: Add "sinks" group to PMU directory Date: Tue, 5 Feb 2019 16:24:57 -0700 Message-Id: <20190205232458.7074-6-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190205232458.7074-1-mathieu.poirier@linaro.org> References: <20190205232458.7074-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 Acked-by: Peter Zijlstra (Intel) Reviewed-by: Suzuki K Poulose --- .../hwtracing/coresight/coresight-etm-perf.c | 82 +++++++++++++++++++ .../hwtracing/coresight/coresight-etm-perf.h | 6 +- drivers/hwtracing/coresight/coresight.c | 18 ++++ include/linux/coresight.h | 7 +- 4 files changed, 110 insertions(+), 3 deletions(-) -- 2.17.1 diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index f21eb28b6782..cdbdb28dc175 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,77 @@ 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) +{ + struct dev_ext_attribute *ea; + + ea = container_of(dattr, struct dev_ext_attribute, attr); + return scnprintf(buf, PAGE_SIZE, "0x%lx\n", (unsigned long)(ea->var)); +} + +int etm_perf_add_symlink_sink(struct coresight_device *csdev) +{ + int ret; + unsigned long hash; + const char *name; + struct device *pmu_dev = etm_pmu.dev; + struct device *pdev = csdev->dev.parent; + 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; + + if (!etm_perf_up) + return -EPROBE_DEFER; + + ea = devm_kzalloc(pdev, sizeof(*ea), GFP_KERNEL); + if (!ea) + return -ENOMEM; + + name = dev_name(pdev); + /* See function coresight_get_sink_by_id() to know where this is used */ + hash = hashlen_hash(hashlen_string(NULL, name)); + + ea->attr.attr.name = devm_kstrdup(pdev, name, GFP_KERNEL); + if (!ea->attr.attr.name) + return -ENOMEM; + + ea->attr.attr.mode = 0444; + ea->attr.show = etm_perf_sink_name_show; + ea->var = (unsigned long *)hash; + + ret = sysfs_add_file_to_group(&pmu_dev->kobj, + &ea->attr.attr, "sinks"); + + if (!ret) + csdev->ea = ea; + + return ret; +} + +void etm_perf_del_symlink_sink(struct coresight_device *csdev) +{ + struct device *pmu_dev = etm_pmu.dev; + struct dev_ext_attribute *ea = csdev->ea; + + if (csdev->type != CORESIGHT_DEV_TYPE_SINK && + csdev->type != CORESIGHT_DEV_TYPE_LINKSINK) + return; + + if (!ea) + return; + + sysfs_remove_file_from_group(&pmu_dev->kobj, + &ea->attr.attr, "sinks"); + csdev->ea = NULL; +} + 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..015213abe00a 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.h +++ b/drivers/hwtracing/coresight/coresight-etm-perf.h @@ -59,6 +59,8 @@ struct etm_event_data { #ifdef CONFIG_CORESIGHT int etm_perf_symlink(struct coresight_device *csdev, bool link); +int etm_perf_add_symlink_sink(struct coresight_device *csdev); +void etm_perf_del_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); @@ -70,7 +72,9 @@ static inline void *etm_perf_sink_config(struct perf_output_handle *handle) #else static inline int etm_perf_symlink(struct coresight_device *csdev, bool link) { return -EINVAL; } - +int etm_perf_add_symlink_sink(struct coresight_device *csdev) +{ return -EINVAL; } +void etm_perf_del_symlink_sink(struct coresight_device *csdev) {} static inline void *etm_perf_sink_config(struct perf_output_handle *handle) { return NULL; diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index 2b0df1a0a8df..d7fa90be6f42 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_add_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); @@ -1185,6 +1202,7 @@ EXPORT_SYMBOL_GPL(coresight_register); void coresight_unregister(struct coresight_device *csdev) { + etm_perf_del_symlink_sink(csdev); /* Remove references of that device in the topology */ coresight_remove_conns(csdev); device_unregister(&csdev->dev); diff --git a/include/linux/coresight.h b/include/linux/coresight.h index 46c67a764877..7b87965f7a65 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -154,8 +154,9 @@ struct coresight_connection { * @orphan: true if the component has connections that haven't been linked. * @enable: 'true' if component is currently part of an active path. * @activated: 'true' only if a _sink_ has been activated. A sink can be - activated but not yet enabled. Enabling for a _sink_ - happens when a source has been selected for that it. + * activated but not yet enabled. Enabling for a _sink_ + * appens when a source has been selected for that it. + * @ea: Device attribute for sink representation under PMU directory. */ struct coresight_device { struct coresight_connection *conns; @@ -168,7 +169,9 @@ struct coresight_device { atomic_t *refcnt; bool orphan; bool enable; /* true only if configured as part of a path */ + /* sink specific fields */ bool activated; /* true only if a sink is part of a path */ + struct dev_ext_attribute *ea; }; #define to_coresight_device(d) container_of(d, struct coresight_device, dev)