From patchwork Mon Dec 17 17:21:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 154026 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2716137ljp; Mon, 17 Dec 2018 09:22:06 -0800 (PST) X-Google-Smtp-Source: AFSGD/UprZ4ka1hfupW8C7cdwCdWLFKcDxSuOVYfEmN/XDm8W6c5yJ0u1QhPGiQaTrkd9Hm1Q1qn X-Received: by 2002:a63:9749:: with SMTP id d9mr12510628pgo.415.1545067326078; Mon, 17 Dec 2018 09:22:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1545067326; cv=none; d=google.com; s=arc-20160816; b=TCt3PDRqkneH/+NvprVRr3pacK9Ymj+g694MphQ+Hnl5Xu5sDNjKV7817SwhbLHlSx AWOR3SdqrAwYY5BiwlX//ID9+yZWxJqzZKHMkQZBEukem6wgBolwJmnHDmwaDbrXuk06 Doi9CDL14MvdTE+dVe+9BqfM2KuGzkv/IW39BDfQDFTdPt3VXd2a2vDLsXlU5/DCnA8r 4by/1smgSia4m06NkFRAy6jUCclmswZ25yuPcCfcKYBoTC16jbZOGr3Yz7YdCRXfAAuG N4FdoL7rZ+IDsJEH5+oIjESsy6mJ23CEEvL86HWTCTN1OyaKyOFYrc97Wr2qlVO3Lk1x CwzA== 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=3vpJNza9or+DqAPy2Ouz+IaFpD2uwWIrDBJByTZlu+A=; b=bXkAMsApwkikShF2+RFggRUBQx1OgRQ6TRFdxu+k0AwsZ9etmu1wVDCIAHfJutSOMd +L73Fg3AYW7+lloec2J3W49gvJbOptjs1oEIynM7T31zPLi8+qys5rNN+27iFjASzVN+ p/ZC5XBm6zxdLpQ4PJD8pxXrVfGxmcHDfpHl1Z4H9YpDgrPMi3nATHzPzPIPJg+xbLU9 YaIHkYrf9jztAAC+JNcwK6SJA3IBm9H4XQQeswPHiZ/6KW8HdNFk/E6JZ56g9XI1P0sG ac/vyUwwhA1SQMr9IIi6DnI3U7y/PGMCvZdIojg4jIoPyDby1n8DS8AiFh2OVyfaTNQ6 gKwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WBT0TGuz; 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 a28si11454942pgl.530.2018.12.17.09.22.05; Mon, 17 Dec 2018 09:22:06 -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=WBT0TGuz; 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 S2388388AbeLQRWD (ORCPT + 31 others); Mon, 17 Dec 2018 12:22:03 -0500 Received: from mail-pl1-f196.google.com ([209.85.214.196]:45964 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388299AbeLQRWA (ORCPT ); Mon, 17 Dec 2018 12:22:00 -0500 Received: by mail-pl1-f196.google.com with SMTP id a14so6428730plm.12 for ; Mon, 17 Dec 2018 09:22:00 -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=3vpJNza9or+DqAPy2Ouz+IaFpD2uwWIrDBJByTZlu+A=; b=WBT0TGuzBRScvsuhIEQeJ4p5P/ED7pvZwMP1kvAA1n//d+x1KAuFV92CjrST4/Vzml 25yzhLdHeKYAFk+jZaWo74/5nIrkljnJhwDC1jFUIYhUQ0fpKf/FUzzRyUGlPuGnpcSo WmX62nnHyUDu8zelXpQJOHbYsDzeBAAXBsq0E= 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=3vpJNza9or+DqAPy2Ouz+IaFpD2uwWIrDBJByTZlu+A=; b=V4yfm0rdLHuG5VLmdMfSkXTaacOnIqrsWTk6pioI3tVS4tS95CTD02lb3kBmoxJ3wh STZVCpNG0QY1TEpUk4GCzB5pKr310rCy7qyYR6NI0hnaV2P/FHNCDmqgLd3lGtxMYmO5 r52z9rtdtjUYhD4ZNWt81CjigttoKc25SSTnwWpy5i55gPEVtn2C2/5pyG8m2xVnnufJ vfzAQn4D4bfAsyUp8bCZVE06szb3dxXQZVW8K8NPoI38Ocw8YRTD/+GwN4QPSJmpjny3 micuyFdmYbFp9YX+m6dDILMUXP32x07+cXlqv/+y5F7N2yv83McWPuvhudOiT7cgoR65 rPAw== X-Gm-Message-State: AA+aEWakXC0vDV84P9i2Vkh7culdjm1zfDxFtS7obAq/yaqog/ZM0uvG L3ppmuFg1JlGlW0UOrpU0Oaoqg== X-Received: by 2002:a17:902:4681:: with SMTP id p1mr13799807pld.184.1545067319819; Mon, 17 Dec 2018 09:21:59 -0800 (PST) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j6sm20526648pfg.126.2018.12.17.09.21.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 17 Dec 2018 09:21:59 -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.poulosi@arm.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [RESEND PATCH v5 6/6] perf tools: Use ioctl function to send sink information to kernel Date: Mon, 17 Dec 2018 10:21:46 -0700 Message-Id: <1545067306-31687-7-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545067306-31687-1-git-send-email-mathieu.poirier@linaro.org> References: <1545067306-31687-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The communication of sink information for a trace session doesn't work when more than one CPU is involved in the scenario due to the static nature of sysfs. As such communicate the sink information to each event by using the an ioctl command. The information sent to the kernel is the component's HW address, which is guaranteed to be unique on the CoreSight bus and known to the kernel. Signed-off-by: Mathieu Poirier --- tools/perf/arch/arm/util/cs-etm.c | 66 +++++++++++++++++++++++++++++++++++++-- tools/perf/util/evsel.c | 6 ++++ tools/perf/util/evsel.h | 1 + 3 files changed, 71 insertions(+), 2 deletions(-) -- 2.7.4 diff --git a/tools/perf/arch/arm/util/cs-etm.c b/tools/perf/arch/arm/util/cs-etm.c index d8081c2e6d44..41e394806707 100644 --- a/tools/perf/arch/arm/util/cs-etm.c +++ b/tools/perf/arch/arm/util/cs-etm.c @@ -22,11 +22,13 @@ #include "../../util/thread_map.h" #include "../../util/cs-etm.h" +#include #include #include #define ENABLE_SINK_MAX 128 #define CS_BUS_DEVICE_PATH "/bus/coresight/devices/" +#define AMBA_BUS_DEVICE_PATH "/bus/amba/devices/" struct cs_etm_recording { struct auxtrace_record itr; @@ -619,6 +621,41 @@ static FILE *cs_device__open_file(const char *name) } +static int cs_etm_check_drv_config_term(const char *name, u64 *addr) +{ + char path[PATH_MAX]; + const char *sysfs; + int err; + FILE *file; + u64 start; + + /* CS devices are all found under sysFS */ + sysfs = sysfs__mountpoint(); + if (!sysfs) + return -EINVAL; + + /* The resource file contains the HW start address of this component */ + snprintf(path, PATH_MAX, + "%s" AMBA_BUS_DEVICE_PATH "%s" "/resource", sysfs, name); + + file = fopen(path, "r"); + if (!file) { + pr_debug("Unable to open file: %s\n", path); + return -EINVAL; + } + + /* We just need the first value */ + err = fscanf(file, "%016lx", &start); + if (err != 1) { + pr_debug("Unable to get resource start value for: %s\n", path); + return -EINVAL; + } + + *addr = start; + + return 0; +} + static int __printf(2, 3) cs_device__print_file(const char *name, const char *fmt, ...) { va_list args; @@ -635,7 +672,7 @@ static int __printf(2, 3) cs_device__print_file(const char *name, const char *fm return ret; } -static int cs_etm_set_drv_config_term(struct perf_evsel_config_term *term) +static int cs_etm_set_drv_config_term_sysfs(struct perf_evsel_config_term *term) { int ret; char enable_sink[ENABLE_SINK_MAX]; @@ -650,6 +687,21 @@ static int cs_etm_set_drv_config_term(struct perf_evsel_config_term *term) return 0; } +static int cs_etm_set_drv_config_term_ioctl(struct perf_evsel *evsel, + struct perf_evsel_config_term *term) +{ + u64 addr; + int ret; + + /* First check the input */ + ret = cs_etm_check_drv_config_term(term->val.drv_cfg, &addr); + if (ret) + return ret; + + /* All good, apply configuration */ + return perf_evsel__apply_drv_config(evsel, addr); +} + int cs_etm_set_drv_config(struct perf_evsel *evsel, struct perf_evsel_config_term **err_term) { @@ -660,7 +712,17 @@ int cs_etm_set_drv_config(struct perf_evsel *evsel, if (term->type != PERF_EVSEL__CONFIG_TERM_DRV_CFG) continue; - err = cs_etm_set_drv_config_term(term); + /* First try the new interface, i.e ioctl() */ + err = cs_etm_set_drv_config_term_ioctl(evsel, term); + if (!err) + continue; + + /* + * Something went wrong, we are probably working with an older + * kernel. As such use the sysFS interface, which will only + * work for per-thread scenarios. + */ + err = cs_etm_set_drv_config_term_sysfs(term); if (err) { *err_term = term; break; diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c index 6d187059a373..8aa2b79c3314 100644 --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -1195,6 +1195,12 @@ static int perf_evsel__append_filter(struct perf_evsel *evsel, return -1; } +int perf_evsel__apply_drv_config(struct perf_evsel *evsel, u64 addr) +{ + return perf_evsel__run_ioctl(evsel, + PERF_EVENT_IOC_SET_DRV_CONFIG, &addr); +} + int perf_evsel__append_tp_filter(struct perf_evsel *evsel, const char *filter) { return perf_evsel__append_filter(evsel, "(%s) && (%s)", filter); diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h index 3147ca76c6fc..6be7560bc986 100644 --- a/tools/perf/util/evsel.h +++ b/tools/perf/util/evsel.h @@ -276,6 +276,7 @@ int perf_evsel__append_tp_filter(struct perf_evsel *evsel, const char *filter); int perf_evsel__append_addr_filter(struct perf_evsel *evsel, const char *filter); int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter); +int perf_evsel__apply_drv_config(struct perf_evsel *evsel, u64 addr); int perf_evsel__enable(struct perf_evsel *evsel); int perf_evsel__disable(struct perf_evsel *evsel);