From patchwork Mon Mar 25 21:56:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870085 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EBF5F1708 for ; Mon, 25 Mar 2019 21:56:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1B5C28B59 for ; Mon, 25 Mar 2019 21:56:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BFDA229140; Mon, 25 Mar 2019 21:56:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 568FA28B59 for ; Mon, 25 Mar 2019 21:56:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=Prau8lWBTufRTkcDeWUMLu/ITvmxb37LcyuqEkjUU+U=; b=MOgiJzKI1rBpffdwSOs3NGKLOw twyMeuSkC/FJlDd13yHcHjJJ8hpSoUsFOnmGuvmC2Bv7hdO20Aw7DTQC/A0bfuJhXgvJERznoVSlY BdIkZjc7Qrmzzs2ntSfIttdTJ9VuxciQeEtj3sV1R+GPIjeRZaOEAkD/n1boJmhwZQXAsHoUiZGal +WNs1+JcsXxbBe5dBMRuhOsK6idT7gev39MKnyOT+XfBw785Iduoc9VhkKR+Ygo/x6gttcG1rN/hE hrlh/LWhFJojpJIiH4Q5rDCeVEyFkFeFUM5KOCjePJta3Us2Fva1AvFW3pySt28qHpdnCuO3nTkz7 W6dwnPjQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XaE-0003mS-JY; Mon, 25 Mar 2019 21:56:42 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8Xa9-0003ki-KZ for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:56:40 +0000 Received: by mail-pg1-x542.google.com with SMTP id y3so7205717pgk.12 for ; Mon, 25 Mar 2019 14:56:36 -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=pQJCMdAOcoU1qu2khwRxnoxNDPS67R2CoUeniO+PC88=; b=xhaBC6ydIMYCyLey3kCYXRTceSLU6oAANFb+GCvpJRlAKn+gg45Zn7MW/nY1GFqDmD BmvPshpw7+w8c5lMocvqPgVcLxc/JxmFM5QM1CX1QRGXp2JYcT/pYNEC++ICR5nwirQs fgvSj9epT5Dc8SBB5nviGgnV+o5wQwJGWf8v22k+97t1PAzsJjPpZEantIEUnH2Tc7jp Ir/aep/7bgglKGBsHuHf+etPhPz1QnVocFpukLRG8ujQWMqGfAdea5O7fCK84ZLKpBAP GlQcPIZArVPUTYiaG3RFZhk26hbkrbKqw6hH+rzqbj7f7lw7+idah76fACM2tybJSSqh rXCw== 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=pQJCMdAOcoU1qu2khwRxnoxNDPS67R2CoUeniO+PC88=; b=LCH/rWhm7Kp1CTQTDUzxgKCNW2hTFMsHnkN1x74U64/sxiMi9FSkQb9b0bEQmmGB06 tS95+qcbyk6ud7Oq9A/KHbkGXflMb7EtWp6HlEOWeF2504mCKp+c2v+SR9zWAvSEmg9V Fw17vE3TsfxylMaurAQ+xmsg5VMrYbV3Bf7/kqznpLUnA8CxSJQqG6Mz1nDGZOUQEihj 4uKV5wimC9MiM38OB0oOW5jJ2ZB6dKwLwHe1lfzzfFOLJMo9M3hWtggqW3UZt8fYSwDE q2RiOZEN6I8SDcIZ9BnBYUgQFMZqz7oNO2dBj4yCNgm4y7nyHJ8OWAvh9NSRmOkF4Mqy Up3w== X-Gm-Message-State: APjAAAXTybBrZK2x8TVJvkmzxSGfCOiPqUwZzSuDkWMtDFdezx4jkd4i e34Z0WM+Tyc0td9pmCOtmmLvGi0lmQc= X-Google-Smtp-Source: APXvYqymYsF5pTquxVn0e8tyKd6tVpkZ/MNwxzG3nNIIHe3hDn9TDzV6TM+Nful3JvBXJirAynoppQ== X-Received: by 2002:a63:e845:: with SMTP id a5mr25311500pgk.246.1553550995760; Mon, 25 Mar 2019 14:56:35 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j20sm30645631pfi.27.2019.03.25.14.56.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:35 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 01/16] coresight: pmu: Adding ITRACE property to cs_etm PMU Date: Mon, 25 Mar 2019 15:56:17 -0600 Message-Id: <20190325215632.17013-2-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325215632.17013-1-mathieu.poirier@linaro.org> References: <20190325215632.17013-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_145637_683483_A50A3DF8 X-CRM114-Status: GOOD ( 12.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add to the capabilities the ITRACE property so that ITRACE START events are generated when the PMU is switched on by the core. Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight-etm-perf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index 4d5a2b9f9d6a..25ae56e924bb 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -566,7 +566,8 @@ static int __init etm_perf_init(void) { int ret; - etm_pmu.capabilities = PERF_PMU_CAP_EXCLUSIVE; + etm_pmu.capabilities = (PERF_PMU_CAP_EXCLUSIVE | + PERF_PMU_CAP_ITRACE); etm_pmu.attr_groups = etm_pmu_attr_groups; etm_pmu.task_ctx_nr = perf_sw_context; From patchwork Mon Mar 25 21:56:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870167 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 123841708 for ; Mon, 25 Mar 2019 22:06:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E96682904F for ; Mon, 25 Mar 2019 22:06:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA92F29010; Mon, 25 Mar 2019 22:06:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2E91629010 for ; Mon, 25 Mar 2019 22:06:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=17XwQCLvziA6OJ9NR+6XKwtDZmQTJtJdk+dtriVlIYA=; b=CtXw3a+Y8/+hbpShSa3bSQRhDx S6OfYAWJXZtc4PSHIXTBFq7xNC3WQui6rsSuTm8rgNLLEAvGmDuYaDJHxJFR+cuaLaVWSdblN47nR FcJEEUU5v5TIzvKTxYBZRLPY/IQs+VVMqyuqwMS3VOXTfAU/tyrOHMhnNUMravmDajv2LXTQz+JI7 x6AoD42IBdihb2xeugE2rZ0IoWlhSA+bpvh5oxYIlXTsMKh7wOYKFc4D0pjD9U5el3OFPytGRzAo7 Hy90bpJca0m0IW8QWt1VNdns3EpVXgbkXrGi99MVsU/+M/JvYwB7AeJ+avRZo9KzHNgkJEYfDC8/D L1cPGyKA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8Xk8-0002pU-GY; Mon, 25 Mar 2019 22:06:56 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XaA-0003kl-1Q for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:56:42 +0000 Received: by mail-pg1-x543.google.com with SMTP id a22so7189269pgg.13 for ; Mon, 25 Mar 2019 14:56:37 -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=PWODwCYQDDzzbPW6Achm9IFb7pPJ4tsTqEyeFjus50Q=; b=nwE8NaGpwBGc20tikbLQ3/HOuMzpkaezEBv+UguFXfsQmepBHkaZUYTn38uW7AJqR3 ++haJdh2lWwVprLYrK7WENFpeYP8FDbZiainxd8ITHbH2IsbtpzSx4Uny6TE9/FSDWNK NMz8RuP6Ombx62ty+Qo6PWuN02r5/4Jzm0sJosrSemFIZZI2sbRTWcoy3LpcCro7qLjA vU0OH5+IznZkzQCKRSncpx8itsamQg2aHToDbAvliG501XdBHuY4LUCu7axfk01nOfKR K0UW3WwNSsKwN2dzcQ4bvPxV8vjXaP4VrUVoJf8tNwkyo/+hTfCbkeyVoC8J0xENAHjB m1WQ== 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=PWODwCYQDDzzbPW6Achm9IFb7pPJ4tsTqEyeFjus50Q=; b=tn7OqyfXqh8YTH6ba69Yz3oHSvoMbSvm/NBs2yqJIsFBwmtMXpZHKU6b+om49dSrcO 6A76v6krc6wkT38ylBkfSjNLdaXFZnHrLSJ9EhPmHDTB1a7peq+pLsDNVsGxEAT6Ai9h ESD3uBvk9T0QrVI36CT00Eh+JRA0L6Rll+N8wm5hx2DZokkH8OsAkeF+waIqEkWZQ0i1 CSnAx3ZobD4ZdrDt75elSIly60XmT9qLcLoYYUJ5wD3gxGTgYCoHRGgwsQQt9PiKmJjf z/c5JcrFs5f83+0igDtHMz+8TVz9+PQ9GqUqVcuGqyQvEGYO/6EY6Kvk0xm/0WJ682YT 1sZw== X-Gm-Message-State: APjAAAXij7W8eAGsUsZ3uH++rtvh4mqgaVnYMdMeFPczUc7hIrEvCfLq Rdl40O1RyRDvYdaYhedjJcZrACOLQDc= X-Google-Smtp-Source: APXvYqxluOoHMJcYuewvAx68Ye9ph0p1syzUvzrbWcsYRqES8bMudc/4T4bQNtgWtfeePt34dMI8/Q== X-Received: by 2002:a62:5385:: with SMTP id h127mr25423185pfb.10.1553550996920; Mon, 25 Mar 2019 14:56:36 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j20sm30645631pfi.27.2019.03.25.14.56.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:36 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 02/16] coresight: etm4x: Add kernel configuration for CONTEXTID Date: Mon, 25 Mar 2019 15:56:18 -0600 Message-Id: <20190325215632.17013-3-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325215632.17013-1-mathieu.poirier@linaro.org> References: <20190325215632.17013-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_145638_080136_5C5CD823 X-CRM114-Status: GOOD ( 14.99 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Set the proper bit in the configuration register when contextID tracing has been requested by user space. That way PE_CONTEXT elements are generated by the tracers when a process is installed on a CPU. Signed-off-by: Mathieu Poirier Reviewed-by: Suzuki K Poulose --- drivers/hwtracing/coresight/Kconfig | 1 + drivers/hwtracing/coresight/coresight-etm-perf.c | 2 ++ drivers/hwtracing/coresight/coresight-etm4x.c | 5 +++++ include/linux/coresight-pmu.h | 2 ++ tools/include/linux/coresight-pmu.h | 2 ++ 5 files changed, 12 insertions(+) diff --git a/drivers/hwtracing/coresight/Kconfig b/drivers/hwtracing/coresight/Kconfig index ad34380cac49..44d1650f398e 100644 --- a/drivers/hwtracing/coresight/Kconfig +++ b/drivers/hwtracing/coresight/Kconfig @@ -75,6 +75,7 @@ config CORESIGHT_SOURCE_ETM4X bool "CoreSight Embedded Trace Macrocell 4.x driver" depends on ARM64 select CORESIGHT_LINKS_AND_SINKS + select PID_IN_CONTEXTIDR help This driver provides support for the ETM4.x tracer module, tracing the instructions that a processor is executing. This is primarily useful diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index 25ae56e924bb..bbfed70b3402 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -29,6 +29,7 @@ static DEFINE_PER_CPU(struct coresight_device *, csdev_src); /* ETMv3.5/PTM's ETMCR is 'config' */ PMU_FORMAT_ATTR(cycacc, "config:" __stringify(ETM_OPT_CYCACC)); +PMU_FORMAT_ATTR(contextid, "config:" __stringify(ETM_OPT_CTXTID)); PMU_FORMAT_ATTR(timestamp, "config:" __stringify(ETM_OPT_TS)); PMU_FORMAT_ATTR(retstack, "config:" __stringify(ETM_OPT_RETSTK)); /* Sink ID - same for all ETMs */ @@ -36,6 +37,7 @@ PMU_FORMAT_ATTR(sinkid, "config2:0-31"); static struct attribute *etm_config_formats_attr[] = { &format_attr_cycacc.attr, + &format_attr_contextid.attr, &format_attr_timestamp.attr, &format_attr_retstack.attr, &format_attr_sinkid.attr, diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x.c index 08ce37c9475d..732ae12fca9b 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x.c +++ b/drivers/hwtracing/coresight/coresight-etm4x.c @@ -239,6 +239,11 @@ static int etm4_parse_event_config(struct etmv4_drvdata *drvdata, if (attr->config & BIT(ETM_OPT_TS)) /* bit[11], Global timestamp tracing bit */ config->cfg |= BIT(11); + + if (attr->config & BIT(ETM_OPT_CTXTID)) + /* bit[6], Context ID tracing bit */ + config->cfg |= BIT(ETM4_CFG_BIT_CTXTID); + /* return stack - enable if selected and supported */ if ((attr->config & BIT(ETM_OPT_RETSTK)) && drvdata->retstack) /* bit[12], Return stack enable bit */ diff --git a/include/linux/coresight-pmu.h b/include/linux/coresight-pmu.h index a1a959ba24ff..b0e35eec6499 100644 --- a/include/linux/coresight-pmu.h +++ b/include/linux/coresight-pmu.h @@ -12,11 +12,13 @@ /* ETMv3.5/PTM's ETMCR config bit */ #define ETM_OPT_CYCACC 12 +#define ETM_OPT_CTXTID 14 #define ETM_OPT_TS 28 #define ETM_OPT_RETSTK 29 /* ETMv4 CONFIGR programming bits for the ETM OPTs */ #define ETM4_CFG_BIT_CYCACC 4 +#define ETM4_CFG_BIT_CTXTID 6 #define ETM4_CFG_BIT_TS 11 #define ETM4_CFG_BIT_RETSTK 12 diff --git a/tools/include/linux/coresight-pmu.h b/tools/include/linux/coresight-pmu.h index a1a959ba24ff..b0e35eec6499 100644 --- a/tools/include/linux/coresight-pmu.h +++ b/tools/include/linux/coresight-pmu.h @@ -12,11 +12,13 @@ /* ETMv3.5/PTM's ETMCR config bit */ #define ETM_OPT_CYCACC 12 +#define ETM_OPT_CTXTID 14 #define ETM_OPT_TS 28 #define ETM_OPT_RETSTK 29 /* ETMv4 CONFIGR programming bits for the ETM OPTs */ #define ETM4_CFG_BIT_CYCACC 4 +#define ETM4_CFG_BIT_CTXTID 6 #define ETM4_CFG_BIT_TS 11 #define ETM4_CFG_BIT_RETSTK 12 From patchwork Mon Mar 25 21:56:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870091 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D5521708 for ; Mon, 25 Mar 2019 21:57:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63A3C28B59 for ; Mon, 25 Mar 2019 21:57:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5726C29131; Mon, 25 Mar 2019 21:57:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 95BFA290E9 for ; Mon, 25 Mar 2019 21:57:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=TpUq7E9OneP9beDm4MzuX9AoOlg1Z5WZlaomFbZLiDk=; b=Fxy491l9BStnfpYL3FJf+3TEXx XtJL35n2OA7NBkHN/o2c2WRUafh54kha/J7Bp9rVtDcw1aTA7y7ejwp3VwJ6wnDYAD4saRNLPWlIN 0pkiOsBdOruUTF90w8pwoUrMONH6bmEUvuJhEWHKH4+4MWPA4RkMAJ2G5KEthC6Prz5RBY1oC6TBK /BMSU6fRJJOvisIrJIKHsgpNLKbLqRPVBgCgNI9HttvCpyNhHxiQvKHMpna9+LEUZV4rfpdaePmoo 1SeDt5X5nHBat4o+nGxNBVQTRRiK5eDITZV+p4YSbBfiDj0Gc2SQ830EO3sIs4xqXVoDieBH5AgwN uMQYo1OQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8Xar-0004Rq-8T; Mon, 25 Mar 2019 21:57:21 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XaC-0003lZ-HT for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:56:43 +0000 Received: by mail-pf1-x443.google.com with SMTP id c207so7069543pfc.7 for ; Mon, 25 Mar 2019 14:56:40 -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=Ypl0AhdKIPMYgGvzoEnU/FMcPAGeVg+HOBF000CHgJk=; b=qnWQgRazqrIVslmIsg9QiEhebVfNnImqqxYfL8VoX5/hMeFSjfbRyaxq9t95eqf0Y2 5pi9B0wDlrABMC8YduI85dzugExUq7wpFRFnLVM64Z+wltckywgoo1gujyDjJInaL4ej M9cgCtJWDKIV2p6DvVhVsExX24IV5c5ImmBAiXvSzuR+uENwatMwi4pRA92zUnKnXv56 xRk4MCiFh04VWQwJanykttuiUmev41oWjoIr03fc1T1GciahqkFi8W+aWnGdDFAWmmRs IvUZKrlCJiWNzAH77kEGQThOEYpFueW89eC/sTJ5VLb/OOw4OyK0DMoZqZK8b/QJuFpv hAMQ== 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=Ypl0AhdKIPMYgGvzoEnU/FMcPAGeVg+HOBF000CHgJk=; b=RHPISRjCZV+qfuPI4MIWlDmr+EOH+vnoEO2dOu/HSUINNToiZsQZ53doilaCl67Ruh oVaxCjVjCFcAqcMM+Kr17l49tlDSerqPDbAQH/eTkfwCWQgZ7dlUGiqYwuK7pxD2ODOs N5qSsGptPmdm++VPa62FggJFaIfH+j9mZq7AiWLpdmD9bP5emd++3WncOtF6wr+R5kkx iodP8mCoC90hbwoI6FDa5Oa1cDTmph1KdJ2wqwihonlikpxKUq2UlzHlPpNp+ftMQHAP nbkwpidOi0vNfRisGBMcoApbIhVTZszLedWxqnGnJoN38QVc1J3oEcfZP8mWzEkIfLUK VNCA== X-Gm-Message-State: APjAAAXOECUCaztRFmOcLTc29yWiEbJl8onxYvWRfcQklKYTrrj7TuIN nHoxNBZPLAZ9xKdulxHvw1rLnu1P/Aw= X-Google-Smtp-Source: APXvYqwW8ZxJDhDY5aCuQsog1k376RbT81zxTPVSkIJbI1GtsXGWmkMe1mu40rVxGCqj8XzGOTCWMg== X-Received: by 2002:a62:305:: with SMTP id 5mr4746182pfd.65.1553550998489; Mon, 25 Mar 2019 14:56:38 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j20sm30645631pfi.27.2019.03.25.14.56.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:37 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 03/16] coresight: etm4x: Configure tracers to emit timestamps Date: Mon, 25 Mar 2019 15:56:19 -0600 Message-Id: <20190325215632.17013-4-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325215632.17013-1-mathieu.poirier@linaro.org> References: <20190325215632.17013-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_145640_576455_B815E8BC X-CRM114-Status: GOOD ( 20.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Configure timestamps to be emitted at regular intervals in the trace stream to temporally correlate instructions executed on different CPUs. Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight-etm4x.c | 115 +++++++++++++++++- 1 file changed, 112 insertions(+), 3 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x.c index 732ae12fca9b..45c341a5aa0b 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x.c +++ b/drivers/hwtracing/coresight/coresight-etm4x.c @@ -138,8 +138,11 @@ static int etm4_enable_hw(struct etmv4_drvdata *drvdata) drvdata->base + TRCCNTVRn(i)); } - /* Resource selector pair 0 is always implemented and reserved */ - for (i = 0; i < drvdata->nr_resource * 2; i++) + /* + * Resource selector pair 0 is always implemented and reserved. As + * such start at 2. + */ + for (i = 2; i < drvdata->nr_resource * 2; i++) writel_relaxed(config->res_ctrl[i], drvdata->base + TRCRSCTLRn(i)); @@ -201,6 +204,97 @@ static void etm4_enable_hw_smp_call(void *info) arg->rc = etm4_enable_hw(arg->drvdata); } +/* + * The goal of function etm4_config_timestamp_event() is to configure a + * counter that will tell the tracer to emit a timestamp packet when it + * reaches zero. This is done in order to get a more fine grained idea + * of when instructions are executed so that they can be correlated + * with execution on other CPUs. + * + * To do this the counter itself is configured to self reload and + * TRCRSCTLR1 (always true) used to get the counter to decrement. From + * there a resource selector is configured with the counter and the + * timestamp control register to use the resource selector to trigger the + * event that will insert a timestamp packet in the stream. + */ +static int etm4_config_timestamp_event(struct etmv4_drvdata *drvdata) +{ + int i, ctridx, ret = -EINVAL; + int counter, rselector; + u32 val = 0; + struct etmv4_config *config = &drvdata->config; + + /* No point in trying if we don't have at least one counter */ + if (!drvdata->nr_cntr) + goto out; + + /* Find a counter that hasn't been initialised */ + for (i = 0; i < drvdata->nr_cntr; i++) + if (config->cntr_val[i] == 0) + break; + + /* Remember what counter we used */ + counter = 1 << i; + ctridx = i; + + /* All the counters have been configured already, bail out */ + if (i == drvdata->nr_cntr) { + pr_err("%s: no available counter found\n", __func__); + goto out; + } + + /* + * Initialise original and reload counter value to the smallest + * possible value in order to get as much precision as we can. + */ + config->cntr_val[ctridx] = 1; + config->cntrldvr[ctridx] = 1; + + /* Set the trace counter control register */ + val = 0x1 << 16 | /* Bit 16, reload counter automatically */ + 0x0 << 7 | /* Select single resource selector */ + 0x1; /* Resource selector 1, i.e always true */ + + config->cntr_ctrl[ctridx] = val; + + /* + * Searching for an available resource selector to use, starting at + * '2' since every implementation has at least 2 resource selector. + * ETMIDR4 gives the number of resource selector _pairs_, + * hence multiply by 2. + */ + for (i = 2; i < drvdata->nr_resource * 2; i++) + if (!config->res_ctrl[i]) + break; + + /* Remember what resource selector we used */ + rselector = i; + + if (i == drvdata->nr_resource * 2) { + pr_err("%s: no available resource selector found\n", __func__); + + /* Backout what we did and exit */ + config->cntr_ctrl[ctridx] = 0; + config->cntrldvr[ctridx] = 0; + config->cntr_val[ctridx] = 0; + goto out; + } + + val = 0x2 << 16 | /* Group 0b0010 - Counter and sequencers */ + counter << 0; /* Counter to use */ + + config->res_ctrl[i] = val; + + val = 0x0 << 7 | /* Select single resource selector */ + rselector; /* Resource selector */ + + config->ts_ctrl = val; + + ret = 0; +out: + return ret; +} + static int etm4_parse_event_config(struct etmv4_drvdata *drvdata, struct perf_event *event) { @@ -236,9 +330,24 @@ static int etm4_parse_event_config(struct etmv4_drvdata *drvdata, /* TRM: Must program this for cycacc to work */ config->ccctlr = ETM_CYC_THRESHOLD_DEFAULT; } - if (attr->config & BIT(ETM_OPT_TS)) + if (attr->config & BIT(ETM_OPT_TS)) { + /* + * Configure timestamps to be emitted at regular intervals in + * order to correlate instructions executed on different CPUs + * (CPU-wide trace scenarios). + */ + ret = etm4_config_timestamp_event(drvdata); + + /* + * No need to go further if timestamp intervals can't + * be configured. + */ + if (ret) + goto out; + /* bit[11], Global timestamp tracing bit */ config->cfg |= BIT(11); + } if (attr->config & BIT(ETM_OPT_CTXTID)) /* bit[6], Context ID tracing bit */ From patchwork Mon Mar 25 21:56:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870169 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1769014DE for ; Mon, 25 Mar 2019 22:07:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F136D29010 for ; Mon, 25 Mar 2019 22:06:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E298329055; Mon, 25 Mar 2019 22:06:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6781E29010 for ; Mon, 25 Mar 2019 22:06:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=PsgMqk9XolALmmtcCL4GI6ONKLLsxYff03FDM8Yuspw=; b=rtCB6r6lbIYMfdQZvUDOIIyw9T 7rpxJlUgo5txUV6MoiePOw/Y5cNi8QdOaxMNy24qidhlnNriRNsSCPl3OJLTZSjNOeVvfOyDdcZsm JmuIL4kOJAQmUacrUiW34yqXtDX9J7vb3D+yj3Mmn52TDUYtkO3GUtvloVlwx2AavI56J0cfLn2m5 ic0jusEdxBREImas72ub+jB4HlrH7H3KOIXshDe/9HR1aWByWlWJH73DmnOCbgB+OYgrkS2e3j3zd zO+uk4Z6kcK7oECf2RhcfLnN5zLKSe+RcPtVyBww2w623aEXYkh0Z2Z1igL8QQIp1FRbDt0EL3F5i nNzLPaIw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XkA-0002qr-8Q; Mon, 25 Mar 2019 22:06:58 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XaE-0003la-6i for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:56:49 +0000 Received: by mail-pg1-x544.google.com with SMTP id a22so7189310pgg.13 for ; Mon, 25 Mar 2019 14:56:40 -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=z9vKbNn2Jl5jfIvm+Nbb97M9whfmXlj1Kkby/gw22Uo=; b=jJ39qDWugfgKWdsM23nZi98s6Z2ZSdNslAhrMm7ULLnx15iuw1N08fTgSNb8+5ki+B KCR//cMYS0DX9jtPqwgoBexx1Gt4QGQBh0w1C1fA/wbr2X2oxoCQ+wsvqQm1njwZgIjO WzCWOqRuaB87748NrzL2WxZ0hX5HW0shxiqKKPcHiPpj7Ops1J8E1mBtl2NPFQ6uQUSO QiVdei/3ff6QzHw9NSIk5dfG7Koib0BtHCN1LMK+SwP7JxniVbJVO2N79RiY7R9njpla OyE1EcGfbtkOMDsvh4cyffLTFOsXpQILc7y5XNKqRhIhcOrPl3IEa5YU9b38FNEaJ+pu zPQg== 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=z9vKbNn2Jl5jfIvm+Nbb97M9whfmXlj1Kkby/gw22Uo=; b=ai8ZCF8QLhDvMYYFGE8rFcOHaSza3mXswDvMC2z3J/0KraS192rrySFRTmnK8Bg6oV 1dXeZs83yXKxH3080JGoEmk6vNH3FRX86PobrbA+ADYK1G5bQcTtj83iMb2PC8RWWgOT oh5mxKztxZ1+sppUtQpJOxC3DT0hjS8EaB4hKtqp9jgjkF72W9yFV0lNLGXFFoTfEkam uNJftUrNp/uVwIgTNIVJ4mD7fTYsmm8lD6Pe8fIddfnfC7JA4vVzcL7GIlK+r3+ZtOq4 5wi/UepqIbDAAVpNHXB5IKoGCveZeNwpgpKuQg7PdgsK2d1mFf7NaXkGg1P+1VE59Kys ZETA== X-Gm-Message-State: APjAAAWLxU6V5BBGvo7bWHhrXDlfKlrJrHWNRCzkNqX5ioPHFpzC5veR lCtE++H0nGDH/He1Tn6xW0ASnD2auGY= X-Google-Smtp-Source: APXvYqzVf5y+UQ2XAr6PTD9dJGO9/5+0YS/ZzmnVv6n8AWQ43LAwHQbWhhXka5tVEdRYpdJISdrJ4Q== X-Received: by 2002:a65:65c4:: with SMTP id y4mr25390343pgv.305.1553550999803; Mon, 25 Mar 2019 14:56:39 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j20sm30645631pfi.27.2019.03.25.14.56.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:39 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 04/16] coresight: Adding return code to sink::disable() operation Date: Mon, 25 Mar 2019 15:56:20 -0600 Message-Id: <20190325215632.17013-5-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325215632.17013-1-mathieu.poirier@linaro.org> References: <20190325215632.17013-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_145642_242755_55B3B02A X-CRM114-Status: GOOD ( 16.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In preparation to handle device reference counting inside of the sink drivers, add a return code to the sink::disable() operation so that proper action can be taken if a sink has not been disabled. Signed-off-by: Mathieu Poirier Reviewed-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-etb10.c | 3 ++- drivers/hwtracing/coresight/coresight-tmc-etf.c | 5 +++-- drivers/hwtracing/coresight/coresight-tmc-etr.c | 5 +++-- drivers/hwtracing/coresight/coresight-tpiu.c | 3 ++- drivers/hwtracing/coresight/coresight.c | 6 +++++- include/linux/coresight.h | 2 +- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c index 105782ea64c7..71c2a3cdb866 100644 --- a/drivers/hwtracing/coresight/coresight-etb10.c +++ b/drivers/hwtracing/coresight/coresight-etb10.c @@ -325,7 +325,7 @@ static void etb_disable_hw(struct etb_drvdata *drvdata) coresight_disclaim_device(drvdata->base); } -static void etb_disable(struct coresight_device *csdev) +static int etb_disable(struct coresight_device *csdev) { struct etb_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); unsigned long flags; @@ -340,6 +340,7 @@ static void etb_disable(struct coresight_device *csdev) spin_unlock_irqrestore(&drvdata->spinlock, flags); dev_dbg(drvdata->dev, "ETB disabled\n"); + return 0; } static void *etb_alloc_buffer(struct coresight_device *csdev, int cpu, diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c b/drivers/hwtracing/coresight/coresight-tmc-etf.c index a5f053f2db2c..d4213e7c2c45 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etf.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c @@ -273,7 +273,7 @@ static int tmc_enable_etf_sink(struct coresight_device *csdev, return 0; } -static void tmc_disable_etf_sink(struct coresight_device *csdev) +static int tmc_disable_etf_sink(struct coresight_device *csdev) { unsigned long flags; struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); @@ -281,7 +281,7 @@ static void tmc_disable_etf_sink(struct coresight_device *csdev) spin_lock_irqsave(&drvdata->spinlock, flags); if (drvdata->reading) { spin_unlock_irqrestore(&drvdata->spinlock, flags); - return; + return -EBUSY; } /* Disable the TMC only if it needs to */ @@ -293,6 +293,7 @@ static void tmc_disable_etf_sink(struct coresight_device *csdev) spin_unlock_irqrestore(&drvdata->spinlock, flags); dev_dbg(drvdata->dev, "TMC-ETB/ETF disabled\n"); + return 0; } static int tmc_enable_etf_link(struct coresight_device *csdev, diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index f684283890d3..33501777038a 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1392,7 +1392,7 @@ static int tmc_enable_etr_sink(struct coresight_device *csdev, return -EINVAL; } -static void tmc_disable_etr_sink(struct coresight_device *csdev) +static int tmc_disable_etr_sink(struct coresight_device *csdev) { unsigned long flags; struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); @@ -1400,7 +1400,7 @@ static void tmc_disable_etr_sink(struct coresight_device *csdev) spin_lock_irqsave(&drvdata->spinlock, flags); if (drvdata->reading) { spin_unlock_irqrestore(&drvdata->spinlock, flags); - return; + return -EBUSY; } /* Disable the TMC only if it needs to */ @@ -1412,6 +1412,7 @@ static void tmc_disable_etr_sink(struct coresight_device *csdev) spin_unlock_irqrestore(&drvdata->spinlock, flags); dev_dbg(drvdata->dev, "TMC-ETR disabled\n"); + return 0; } static const struct coresight_ops_sink tmc_etr_sink_ops = { diff --git a/drivers/hwtracing/coresight/coresight-tpiu.c b/drivers/hwtracing/coresight/coresight-tpiu.c index b2f72a1fa402..0d13da1b9df1 100644 --- a/drivers/hwtracing/coresight/coresight-tpiu.c +++ b/drivers/hwtracing/coresight/coresight-tpiu.c @@ -94,13 +94,14 @@ static void tpiu_disable_hw(struct tpiu_drvdata *drvdata) CS_LOCK(drvdata->base); } -static void tpiu_disable(struct coresight_device *csdev) +static int tpiu_disable(struct coresight_device *csdev) { struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); tpiu_disable_hw(drvdata); dev_dbg(drvdata->dev, "TPIU disabled\n"); + return 0; } static const struct coresight_ops_sink tpiu_sink_ops = { diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index 29cef898afba..13eda4693f81 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -239,9 +239,13 @@ static int coresight_enable_sink(struct coresight_device *csdev, static void coresight_disable_sink(struct coresight_device *csdev) { + int ret; + if (atomic_dec_return(csdev->refcnt) == 0) { if (sink_ops(csdev)->disable) { - sink_ops(csdev)->disable(csdev); + ret = sink_ops(csdev)->disable(csdev); + if (ret) + return; csdev->enable = false; } } diff --git a/include/linux/coresight.h b/include/linux/coresight.h index 7b87965f7a65..189cc6ddc92b 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -192,7 +192,7 @@ struct coresight_device { */ struct coresight_ops_sink { int (*enable)(struct coresight_device *csdev, u32 mode, void *data); - void (*disable)(struct coresight_device *csdev); + int (*disable)(struct coresight_device *csdev); void *(*alloc_buffer)(struct coresight_device *csdev, int cpu, void **pages, int nr_pages, bool overwrite); void (*free_buffer)(void *config); From patchwork Mon Mar 25 21:56:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870089 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C5CA1575 for ; Mon, 25 Mar 2019 21:57:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 117AC29131 for ; Mon, 25 Mar 2019 21:57:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F35E728B59; Mon, 25 Mar 2019 21:57:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.0 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 40B1B28B59 for ; Mon, 25 Mar 2019 21:57:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=h+KY9Y0fSZIjDnZta9a9L+wVt9wyxw5ZKLdZFGFc3cc=; b=APlP6OAAMZgKa/ikP0SWOTjoze 4CCOOR4r1uJkU4MeVJQkRzxlgSe+6C6vPN0bUskSc8RLSOwUiISmosEVED9mYTTGGEbXiqwKN3O6Y G4LFwLj/jmFh8E9tsceWnNXPEc/9jwdivvMI+n1Hv9aF7BDfK4PTouWk7Sq7338/n3QH7UhLwNoEj Bd853itF2G2BF2lghEQ+82pW8OSaEE/TNrgrFxS+YVlSV519R/4aOjC6Y4yc7aFUx/kv9oaZfANq4 KylrSPai4jEKGR9MzDal7xV6gZ+PqWY0uXi79v7tNDrKw4bmMjLt/dvoo9vpLufN/RaTYaOGVj9Ng 0hvJShYg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8Xai-0004Js-A5; Mon, 25 Mar 2019 21:57:12 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XaD-0003m0-RL for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:56:43 +0000 Received: by mail-pg1-x542.google.com with SMTP id v12so7246192pgq.1 for ; Mon, 25 Mar 2019 14:56:41 -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=7EURRyYqJSOJSsB3lcmdIjQsqTGnb9D5lxXLvnUUXcY=; b=n25lcH0rAYGqkDq/b+qBiG3gcIaCk6BTgAEHo7tItteAf2+W3GVBoOfaSCM1G2GIww BlAJUoK5DMtdEZ+HXCp10MyJNDnf2UF4NVK2awftSoui6QBx7n0XTQv0OleEtWYAN34E Itlu6sAK4JGNmoYl57Z8vrAzJrIat21fvhHl7HlaRavZmsEGTuGslU0vzpjyZ9/ME62z MIh6K0InFz5kMycFTkTApJgAoG9rqadPkxpgP/p/dViNN2CMkuiKxiPa+4qF/hNKaWOx 6hmjxp0mRqwzDZW2YtwV5KQsY4QkeY9RDMLlfqkKgT5XFqmtme5+NS0/OgFAAoY9RsOw np4w== 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=7EURRyYqJSOJSsB3lcmdIjQsqTGnb9D5lxXLvnUUXcY=; b=uQY3l7xA8gWKcfDNFeT7jM49z0Xxch4nHXhmpjPFYl3c14r596Iokhg9er6ubMLUOT CCZhycEiyXHpxmE8gteuul3uN2Mw250qXRQBL/fNnaQhfXR3+bY51qt6jGTWTcYHAdJi 0ov+RNpuwfg0yfozB8jSfoR3F+NCXCwYpAb6wuE2CXxuJkKxLX95UHA0Kwst2dQTowIj jZ8uFYxNOIe9yGPNGb0S9m/XygZX6Bb5RLnKZWKxz7HlvW8FvzENbKFdGXqhiPwKowFB CowJzqyU2X7JeAkQGCzWpMjF0Ma/Ubv2eoUHtckI4Wdqbsx4sZn91Q2vvrXWu5BxYDgc GeQw== X-Gm-Message-State: APjAAAV8LVxdioCNJnSnzpP8tjvi/yQjuuSP8ddinf9jA8Wh2oE6tiOk HwqRFOdJ0k7t1e5aSw0Sp6ITQQeDJus= X-Google-Smtp-Source: APXvYqwiwAr7BGBZ+D4FRMJrhXhJCCEybIGHNy1NS7KK+7odoY9HXOkvlu8+XPdvsih4N1VF152R/w== X-Received: by 2002:a63:5b64:: with SMTP id l36mr26095592pgm.182.1553551001112; Mon, 25 Mar 2019 14:56:41 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j20sm30645631pfi.27.2019.03.25.14.56.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:40 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 05/16] coresight: Move reference counting inside sink drivers Date: Mon, 25 Mar 2019 15:56:21 -0600 Message-Id: <20190325215632.17013-6-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325215632.17013-1-mathieu.poirier@linaro.org> References: <20190325215632.17013-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_145641_891119_E4A813A2 X-CRM114-Status: GOOD ( 20.12 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP When operating in CPU-wide mode with an N:1 source/sink HW topology, multiple CPUs can access a sink concurrently. As such reference counting needs to happen when the device's spinlock is held to avoid racing with other operations (start(), update(), stop()), such as: session A Session B ----- ------- enable_sink atomic_inc(refcount) = 1 ... atomic_dec(refcount) = 0 enable_sink if (refcount == 0) disable_sink atomic_inc() Signed-off-by: Mathieu Poirier Reviewed-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-etb10.c | 21 ++++++++++---- .../hwtracing/coresight/coresight-tmc-etf.c | 21 +++++++++++--- .../hwtracing/coresight/coresight-tmc-etr.c | 19 +++++++++++-- drivers/hwtracing/coresight/coresight-tpiu.c | 6 +++- drivers/hwtracing/coresight/coresight.c | 28 +++++++++---------- 5 files changed, 66 insertions(+), 29 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c index 71c2a3cdb866..5af50a852e87 100644 --- a/drivers/hwtracing/coresight/coresight-etb10.c +++ b/drivers/hwtracing/coresight/coresight-etb10.c @@ -5,6 +5,7 @@ * Description: CoreSight Embedded Trace Buffer driver */ +#include #include #include #include @@ -159,14 +160,15 @@ static int etb_enable_sysfs(struct coresight_device *csdev) goto out; } - /* Nothing to do, the tracer is already enabled. */ - if (drvdata->mode == CS_MODE_SYSFS) - goto out; + if (drvdata->mode == CS_MODE_DISABLED) { + ret = etb_enable_hw(drvdata); + if (ret) + goto out; - ret = etb_enable_hw(drvdata); - if (!ret) drvdata->mode = CS_MODE_SYSFS; + } + atomic_inc(csdev->refcnt); out: spin_unlock_irqrestore(&drvdata->spinlock, flags); return ret; @@ -196,8 +198,10 @@ static int etb_enable_perf(struct coresight_device *csdev, void *data) goto out; ret = etb_enable_hw(drvdata); - if (!ret) + if (!ret) { drvdata->mode = CS_MODE_PERF; + atomic_inc(csdev->refcnt); + } out: spin_unlock_irqrestore(&drvdata->spinlock, flags); @@ -332,6 +336,11 @@ static int etb_disable(struct coresight_device *csdev) spin_lock_irqsave(&drvdata->spinlock, flags); + if (atomic_dec_return(csdev->refcnt)) { + spin_unlock_irqrestore(&drvdata->spinlock, flags); + return -EBUSY; + } + /* Disable the ETB only if it needs to */ if (drvdata->mode != CS_MODE_DISABLED) { etb_disable_hw(drvdata); diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c b/drivers/hwtracing/coresight/coresight-tmc-etf.c index d4213e7c2c45..d50a608a60f1 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etf.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c @@ -4,6 +4,7 @@ * Author: Mathieu Poirier */ +#include #include #include #include @@ -180,8 +181,10 @@ static int tmc_enable_etf_sink_sysfs(struct coresight_device *csdev) * sink is already enabled no memory is needed and the HW need not be * touched. */ - if (drvdata->mode == CS_MODE_SYSFS) + if (drvdata->mode == CS_MODE_SYSFS) { + atomic_inc(csdev->refcnt); goto out; + } /* * If drvdata::buf isn't NULL, memory was allocated for a previous @@ -200,11 +203,13 @@ static int tmc_enable_etf_sink_sysfs(struct coresight_device *csdev) } ret = tmc_etb_enable_hw(drvdata); - if (!ret) + if (!ret) { drvdata->mode = CS_MODE_SYSFS; - else + atomic_inc(csdev->refcnt); + } else { /* Free up the buffer if we failed to enable */ used = false; + } out: spin_unlock_irqrestore(&drvdata->spinlock, flags); @@ -239,8 +244,10 @@ static int tmc_enable_etf_sink_perf(struct coresight_device *csdev, void *data) if (ret) break; ret = tmc_etb_enable_hw(drvdata); - if (!ret) + if (!ret) { drvdata->mode = CS_MODE_PERF; + atomic_inc(csdev->refcnt); + } } while (0); spin_unlock_irqrestore(&drvdata->spinlock, flags); @@ -279,11 +286,17 @@ static int tmc_disable_etf_sink(struct coresight_device *csdev) struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); spin_lock_irqsave(&drvdata->spinlock, flags); + if (drvdata->reading) { spin_unlock_irqrestore(&drvdata->spinlock, flags); return -EBUSY; } + if (atomic_dec_return(csdev->refcnt)) { + spin_unlock_irqrestore(&drvdata->spinlock, flags); + return -EBUSY; + } + /* Disable the TMC only if it needs to */ if (drvdata->mode != CS_MODE_DISABLED) { tmc_etb_disable_hw(drvdata); diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index 33501777038a..f90bca971367 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -4,6 +4,7 @@ * Author: Mathieu Poirier */ +#include #include #include #include @@ -1124,8 +1125,10 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev) * sink is already enabled no memory is needed and the HW need not be * touched, even if the buffer size has changed. */ - if (drvdata->mode == CS_MODE_SYSFS) + if (drvdata->mode == CS_MODE_SYSFS) { + atomic_inc(csdev->refcnt); goto out; + } /* * If we don't have a buffer or it doesn't match the requested size, @@ -1138,8 +1141,10 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev) } ret = tmc_etr_enable_hw(drvdata, drvdata->sysfs_buf); - if (!ret) + if (!ret) { drvdata->mode = CS_MODE_SYSFS; + atomic_inc(csdev->refcnt); + } out: spin_unlock_irqrestore(&drvdata->spinlock, flags); @@ -1370,8 +1375,10 @@ static int tmc_enable_etr_sink_perf(struct coresight_device *csdev, void *data) etr_perf->head = PERF_IDX2OFF(handle->head, etr_perf); drvdata->perf_data = etr_perf; rc = tmc_etr_enable_hw(drvdata, etr_perf->etr_buf); - if (!rc) + if (!rc) { drvdata->mode = CS_MODE_PERF; + atomic_inc(csdev->refcnt); + } unlock_out: spin_unlock_irqrestore(&drvdata->spinlock, flags); @@ -1398,11 +1405,17 @@ static int tmc_disable_etr_sink(struct coresight_device *csdev) struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); spin_lock_irqsave(&drvdata->spinlock, flags); + if (drvdata->reading) { spin_unlock_irqrestore(&drvdata->spinlock, flags); return -EBUSY; } + if (atomic_dec_return(csdev->refcnt)) { + spin_unlock_irqrestore(&drvdata->spinlock, flags); + return -EBUSY; + } + /* Disable the TMC only if it needs to */ if (drvdata->mode != CS_MODE_DISABLED) { tmc_etr_disable_hw(drvdata); diff --git a/drivers/hwtracing/coresight/coresight-tpiu.c b/drivers/hwtracing/coresight/coresight-tpiu.c index 0d13da1b9df1..7acbeffcc137 100644 --- a/drivers/hwtracing/coresight/coresight-tpiu.c +++ b/drivers/hwtracing/coresight/coresight-tpiu.c @@ -5,6 +5,7 @@ * Description: CoreSight Trace Port Interface Unit driver */ +#include #include #include #include @@ -73,7 +74,7 @@ static int tpiu_enable(struct coresight_device *csdev, u32 mode, void *__unused) struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); tpiu_enable_hw(drvdata); - + atomic_inc(csdev->refcnt); dev_dbg(drvdata->dev, "TPIU enabled\n"); return 0; } @@ -98,6 +99,9 @@ static int tpiu_disable(struct coresight_device *csdev) { struct tpiu_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); + if (atomic_dec_return(csdev->refcnt)) + return -EBUSY; + tpiu_disable_hw(drvdata); dev_dbg(drvdata->dev, "TPIU disabled\n"); diff --git a/drivers/hwtracing/coresight/coresight.c b/drivers/hwtracing/coresight/coresight.c index 13eda4693f81..19ba121d7451 100644 --- a/drivers/hwtracing/coresight/coresight.c +++ b/drivers/hwtracing/coresight/coresight.c @@ -225,14 +225,13 @@ static int coresight_enable_sink(struct coresight_device *csdev, * We need to make sure the "new" session is compatible with the * existing "mode" of operation. */ - if (sink_ops(csdev)->enable) { - ret = sink_ops(csdev)->enable(csdev, mode, data); - if (ret) - return ret; - csdev->enable = true; - } + if (!sink_ops(csdev)->enable) + return -EINVAL; - atomic_inc(csdev->refcnt); + ret = sink_ops(csdev)->enable(csdev, mode, data); + if (ret) + return ret; + csdev->enable = true; return 0; } @@ -241,14 +240,13 @@ static void coresight_disable_sink(struct coresight_device *csdev) { int ret; - if (atomic_dec_return(csdev->refcnt) == 0) { - if (sink_ops(csdev)->disable) { - ret = sink_ops(csdev)->disable(csdev); - if (ret) - return; - csdev->enable = false; - } - } + if (!sink_ops(csdev)->disable) + return; + + ret = sink_ops(csdev)->disable(csdev); + if (ret) + return; + csdev->enable = false; } static int coresight_enable_link(struct coresight_device *csdev, From patchwork Mon Mar 25 21:56:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870093 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 895741575 for ; Mon, 25 Mar 2019 21:57:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 70D5C28B59 for ; Mon, 25 Mar 2019 21:57:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6522329131; Mon, 25 Mar 2019 21:57:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0531628B59 for ; Mon, 25 Mar 2019 21:57:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=IxcoyieEQkenOC69aVZBX5U2HaGtv/8YQmKevVsd95U=; b=PlfrtbHyRwxS9cFPsw6dnc/uum h4JUXunOLbhpaQ7m98K7x3/EcHXe+G8blvwBfZw3K02CIuS++E5sPNhnYScPSr/siQfOux0AK9bKj 3Uy+EpWnJyxAxMP7ZB2uZ4vGp7RRDVQnmGb3SS6hLSE+TQTI+jsF0yXzAKCB4lGLEBuUBkQ8ntJWh o3n9r9x1EKW+dSzb4WbLEooTE0p/NDb2sV7q8glcpbq0i8NnNoVfKGI7yeW8LWMdWpZk8ZGU5NATL xBcInff6iVQUR/V7JVm2aBvPpSPdubLwwvExa4TO4XkTs4LlimG1jrWyLHA1ZJBOQRWcTbfu9S5cH iKDjpFbg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8Xb1-0004ho-Fw; Mon, 25 Mar 2019 21:57:31 +0000 Received: from mail-pl1-x641.google.com ([2607:f8b0:4864:20::641]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XaG-0003mn-Sy for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:56:48 +0000 Received: by mail-pl1-x641.google.com with SMTP id bg8so584753plb.0 for ; Mon, 25 Mar 2019 14:56:43 -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=xiLcmlCMJ/zn0zkvhqy9D58gyT8D1Vy0Vdw39LfItT8=; b=Gn5VrmWUDcTg4YuWl2HtTeza6m3YmImarMCi+wF6CF0pk8izKQqdVeSSi5NcUIbHRo e3NiPacHT3W3/zGJYRos/nOZBtYJ+L+w73MzHMKfWqln139LiKemf5URX1C9L9JeAuqJ jAIrREa45e4NQtCI74OMheRx/aLj0lwrfB0tiOrVLwm/2eLhKGtFy5dovfGX5h7dWqHw DbtJafOJRFvG6QxXq4Pb9LI8Qv41+9AQPAI9i9hkhNhBml//81hV/4TPS04zoNOp7ch1 qWRhB29EH2tJO8aTTbGO7Takqin4XywtCA9JZqESDS5SCnoONnCGq/m6g4+4lFh4/Fsp zFqQ== 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=xiLcmlCMJ/zn0zkvhqy9D58gyT8D1Vy0Vdw39LfItT8=; b=SaOC+WOoIw6OjYCq3yMHf8wXXIHE5W/0OMjlykkkfHV/PdNo3NbgwR/2UXJQnSEgdR QA2CDLN66QOivF4d/4VnzJNNH7NCZ9S1Iob3t5sKkCYVMHvfT9P57wUrHA+qMu0oYM+v 6bYi6JhTxk8SAqOiaWsX91gDbUrOr04gLPi08uQEl2DErPuctif0KPa6fvaHhcR2p43j tmGricIC5X0G7Hl/s1FDybrGDsKBEOWO+udUnKAfWB1Yz1/FDC//wDVNtQyXAv5IMXqP bUay+K+cZAFia7CNkWgW3hamGu2s9fabFJnVY8fCvT7U4V+dXZ4Q9gZ3inbeqattyw9N h4Jg== X-Gm-Message-State: APjAAAUXGrXBXAdomQemdHiwfzhU5UqmCAIWQvyxElG3+jUFAwH5lUFo yog6MywDbx71s7V/QCsiWtcZ84wgKKs= X-Google-Smtp-Source: APXvYqxliW9OH2X9k4+WNEt1VNx//doHtW6A5UiH57kbEalSZV/VlatilnxkVZZMh4W3r1wNSAaXGw== X-Received: by 2002:a17:902:a706:: with SMTP id w6mr3056726plq.91.1553551002435; Mon, 25 Mar 2019 14:56:42 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j20sm30645631pfi.27.2019.03.25.14.56.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:41 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 06/16] coresight: Properly address errors in sink::disable() functions Date: Mon, 25 Mar 2019 15:56:22 -0600 Message-Id: <20190325215632.17013-7-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325215632.17013-1-mathieu.poirier@linaro.org> References: <20190325215632.17013-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_145645_098587_9B4745A2 X-CRM114-Status: GOOD ( 13.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP When disabling a sink the reference counter ensures the operation goes through if nobody else is using it. As such if drvdata::mode is already set do CS_MODE_DISABLED, it is an error and should be reported as such. Signed-off-by: Mathieu Poirier Reviewed-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-etb10.c | 9 ++++----- drivers/hwtracing/coresight/coresight-tmc-etf.c | 9 ++++----- drivers/hwtracing/coresight/coresight-tmc-etr.c | 9 ++++----- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c index 5af50a852e87..52b7d95ab498 100644 --- a/drivers/hwtracing/coresight/coresight-etb10.c +++ b/drivers/hwtracing/coresight/coresight-etb10.c @@ -341,11 +341,10 @@ static int etb_disable(struct coresight_device *csdev) return -EBUSY; } - /* Disable the ETB only if it needs to */ - if (drvdata->mode != CS_MODE_DISABLED) { - etb_disable_hw(drvdata); - drvdata->mode = CS_MODE_DISABLED; - } + /* Complain if we (somehow) got out of sync */ + WARN_ON_ONCE(drvdata->mode == CS_MODE_DISABLED); + etb_disable_hw(drvdata); + drvdata->mode = CS_MODE_DISABLED; spin_unlock_irqrestore(&drvdata->spinlock, flags); dev_dbg(drvdata->dev, "ETB disabled\n"); diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c b/drivers/hwtracing/coresight/coresight-tmc-etf.c index d50a608a60f1..30f868676540 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etf.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c @@ -297,11 +297,10 @@ static int tmc_disable_etf_sink(struct coresight_device *csdev) return -EBUSY; } - /* Disable the TMC only if it needs to */ - if (drvdata->mode != CS_MODE_DISABLED) { - tmc_etb_disable_hw(drvdata); - drvdata->mode = CS_MODE_DISABLED; - } + /* Complain if we (somehow) got out of sync */ + WARN_ON_ONCE(drvdata->mode == CS_MODE_DISABLED); + tmc_etb_disable_hw(drvdata); + drvdata->mode = CS_MODE_DISABLED; spin_unlock_irqrestore(&drvdata->spinlock, flags); diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index f90bca971367..86e748d09dc3 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1416,11 +1416,10 @@ static int tmc_disable_etr_sink(struct coresight_device *csdev) return -EBUSY; } - /* Disable the TMC only if it needs to */ - if (drvdata->mode != CS_MODE_DISABLED) { - tmc_etr_disable_hw(drvdata); - drvdata->mode = CS_MODE_DISABLED; - } + /* Complain if we (somehow) got out of sync */ + WARN_ON_ONCE(drvdata->mode == CS_MODE_DISABLED); + tmc_etr_disable_hw(drvdata); + drvdata->mode = CS_MODE_DISABLED; spin_unlock_irqrestore(&drvdata->spinlock, flags); From patchwork Mon Mar 25 21:56:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870095 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E48781575 for ; Mon, 25 Mar 2019 21:58:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C52C528B59 for ; Mon, 25 Mar 2019 21:58:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B50A629131; Mon, 25 Mar 2019 21:58:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 51C9828B59 for ; Mon, 25 Mar 2019 21:58:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=NtAPz1wflMXe/Bjw5AJJDi2XmKWKoCBe93nFqqVEdVk=; b=LxUG1ZMeHFXAdZdDHlajtLkKrZ m5/eGaTZoStYZT/VOYNjxGuiIg85JqDr1CVv2r+B5LVwps+wlbE9+TK4ccq3xcfk+A3NDsGHzgKi5 C5aUnLmTHLaghRTrkZAoMm8HGYanjNTBPIJIS4dsRrMIs5AFl32jANx+VCgXGTu4YE3wtlkDPMeTs xkuhTHp++md/J02I6/NA+ojyTrw4qbeHQIKtV8EcK1z3w9xYF8gFPDktdZiXnMPKMkJ0LV8u5oxKl IQ/I6diCiF3MLbzl21PRTbXIG8CydhZRHW4fIA3u/5ntOnJ1bp9CdhwJ2rL0DNyasXZ3guTyuBG4i Caf6juiw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XbJ-00057Y-Ru; Mon, 25 Mar 2019 21:57:49 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XaH-0003n9-Fx for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:56:51 +0000 Received: by mail-pl1-x644.google.com with SMTP id k2so584471plt.3 for ; Mon, 25 Mar 2019 14:56:45 -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=Rp82OG+X/1qzhxgu7Opyhu1qYPCsjQeQJx+i+wMOyCE=; b=QMpHv+cQMO5wK9NDGwSbMt1biEtMIBoMhh8zt8GxAtUB5uf/kID5HS0tmCWWSmJW5Q 09X+tGDRgdbT77vpoR5jaQjp8zpAE14WMK+QoPHQi6SjLAWOL+7IDPynXKXSpPbfUxHB LxbU8kMwoo8/b4LYpXvwxqpz+lspPW+L5iAGDU5trJLQOuMWAaXnqPlGmk+B2Vv+M+zg LKBgjBCkJTZJRfaFNrA6lASy8pjEJNYaBzpNjzCJHj7Ykf5faXUf8cnm5DHh+bqlUNDn VE+/gPd3K3sedhsvSbQpBv4hmhMK7ELmijrmd47MKkAo44FomjQ8uPgvHUOTXKLdUyTW 6x9Q== 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=Rp82OG+X/1qzhxgu7Opyhu1qYPCsjQeQJx+i+wMOyCE=; b=Ia/gbYhQouoIzaOQb9aQu/uEj5qbpKVDKzCNECYV/xmtC3NQFr7nQez9w1Lz0zOUUA PcYiEHq75Vz4S2fsa63379jEyZfRzFAMcOSbhk6yEeTeFfTgVeSS6LROOBLuwMpMZPy6 Sj83u3YI155Cg2ZGxybp31etnl0MXIAjE5l4rNfX5wRK8QBCpVzrjDYs4K3FqHfxBKgf 76+xqST4j7pM2zQ5h46llT69vhFDY1WECYYdzBwdHZpLVGwY3iLH85Nfu/lokGYK9mis iMwq2HL5fY7WsWFuXjddPd1fQH4T6wM64kRw5qdZmOnmk3Ak+4cjHHiELt3M7mXDwkPq UPqA== X-Gm-Message-State: APjAAAUzNcJj37mSUkZqtZjNC5eDaYePYqIVliZ7ygDDjSvvz2JKi/x+ FGiPv5FnurwILXxlNvWfVKPcbZjHPv8= X-Google-Smtp-Source: APXvYqxC6m5ND+MEoTLcyhm5eVxckum8V3c+q666/2CtWu907ovQRtV+BPcbu6RcRy8EysHhDm013Q== X-Received: by 2002:a17:902:9306:: with SMTP id bc6mr26808825plb.59.1553551003643; Mon, 25 Mar 2019 14:56:43 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j20sm30645631pfi.27.2019.03.25.14.56.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:43 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 07/16] coresight: Properly address concurrency in sink::update() functions Date: Mon, 25 Mar 2019 15:56:23 -0600 Message-Id: <20190325215632.17013-8-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325215632.17013-1-mathieu.poirier@linaro.org> References: <20190325215632.17013-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_145645_962435_09DD0D10 X-CRM114-Status: GOOD ( 11.42 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP When operating in CPU-wide trace scenarios and working with an N:1 source/sink HW topology, update() functions need to be made atomic in order to avoid racing with start and stop operations. Signed-off-by: Mathieu Poirier Reviewed-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-etb10.c | 4 +++- drivers/hwtracing/coresight/coresight-tmc-etf.c | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c index 52b7d95ab498..6b50e781dc57 100644 --- a/drivers/hwtracing/coresight/coresight-etb10.c +++ b/drivers/hwtracing/coresight/coresight-etb10.c @@ -413,7 +413,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev, const u32 *barrier; u32 read_ptr, write_ptr, capacity; u32 status, read_data; - unsigned long offset, to_read; + unsigned long offset, to_read, flags; struct cs_buffers *buf = sink_config; struct etb_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); @@ -422,6 +422,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev, capacity = drvdata->buffer_depth * ETB_FRAME_SIZE_WORDS; + spin_lock_irqsave(&drvdata->spinlock, flags); __etb_disable_hw(drvdata); CS_UNLOCK(drvdata->base); @@ -532,6 +533,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev, } __etb_enable_hw(drvdata); CS_LOCK(drvdata->base); + spin_unlock_irqrestore(&drvdata->spinlock, flags); return to_read; } diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c b/drivers/hwtracing/coresight/coresight-tmc-etf.c index 30f868676540..a38ad2b0d95a 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etf.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c @@ -413,7 +413,7 @@ static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev, u32 *buf_ptr; u64 read_ptr, write_ptr; u32 status; - unsigned long offset, to_read; + unsigned long offset, to_read, flags; struct cs_buffers *buf = sink_config; struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); @@ -424,6 +424,7 @@ static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev, if (WARN_ON_ONCE(drvdata->mode != CS_MODE_PERF)) return 0; + spin_lock_irqsave(&drvdata->spinlock, flags); CS_UNLOCK(drvdata->base); tmc_flush_and_stop(drvdata); @@ -517,6 +518,7 @@ static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev, to_read = buf->nr_pages << PAGE_SHIFT; } CS_LOCK(drvdata->base); + spin_unlock_irqrestore(&drvdata->spinlock, flags); return to_read; } From patchwork Mon Mar 25 21:56:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870097 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0EF411708 for ; Mon, 25 Mar 2019 21:58:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAA7F28B59 for ; Mon, 25 Mar 2019 21:58:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF37629131; Mon, 25 Mar 2019 21:58:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8080B28B59 for ; Mon, 25 Mar 2019 21:58:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=Xd8z+1w8+J/M7x2NqYiQ8ANmMvdXd/V3EMUsasWvBDw=; b=W1TAd86gCeIg1WQ8jdOyKtZmxo AReoKN3FFvizaXGlJATn3ZOg96gu2esXrbEwAyuss9huMxqVLlNHyOjAUo3fWyA3J9QINA9gunSCG PCHoFpWy06lvlYYXcjHqYMoXTEflQu6g5sJoRtZ2zXcbHj11JuTlTDM3Qi7U22g/LofZlfM8BR6ju 8WyhkHNpX1X7NGTIESArz4e55RaugwV9ONXhK6EMp3TEiJaYwhgqiAAe2AGu0PNG1CvhEQOCCTnlC Qm12jlUBVYvmHyy2FXwc9atD5ORhRPIpfR9sCUKhkvZKbpFKj/M5H0FmBDx2Ixc3WjrPvoByHfF+b TcHyu2oQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XbZ-0005V7-OD; Mon, 25 Mar 2019 21:58:05 +0000 Received: from mail-pg1-x542.google.com ([2607:f8b0:4864:20::542]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XaK-0003qz-EG for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:56:54 +0000 Received: by mail-pg1-x542.google.com with SMTP id r124so7224982pgr.3 for ; Mon, 25 Mar 2019 14:56:48 -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=Rs0Mz9KrYOZgcBXADVGIV6b2w07we0qLU/jBgiUTV9k=; b=Ackc5N/WiULsAIVnlswx5k+iQLXQJFeHsNGEF37EMv6qjWA5Me3ogeHQvs9rndkKlh I5Yly06s0HPAkAgptxJgg2tAnG7sd9flK0SuJCP1wTkObDduPW7o7FM18NojhyIdKd/n 9uhqIa6He6EST8ZJ26jYGSuuTqyrNGnzLtzf2B+75HPHhBZPwTbjaI3qW+se34yF9z6y H2qtKThWfw2qAm2iWWjwpGqkOyYjenPBUxnhqqzLxf1l/FAjMPGpPaIdFUYvastyMz5A 1zxnlP5tB2BcdcdQnbtfqwmZUvqe2uelBML/umt8tklM1IF2cthz5GhZ8U6wxrWeQzcQ pmJA== 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=Rs0Mz9KrYOZgcBXADVGIV6b2w07we0qLU/jBgiUTV9k=; b=XKVSxPPrZ49P+Xx6iyuJltxXDB2IaR7e9R18ISUnK9uj9HOoabUD3P7oPHyD7a8ygO KrUMuTf3ONntBEhCbNvHv1NCn53Pc9VNyILyGEIT9IXCnlrve4rR95ohsvI2+XSlTrzi 0OXzNr06iTJQfnKenMbRkabm8DBYUlkTWxzR59m+m4hyl9oZru2xfYKu1wI7Z/gEKDpF jQHGAxFg5Ot+7yNCOIXh0lN2u0icTzABbcYNeJO60NUw3eqRPw3LUIfbbt9vFPJrHR2k ea5lV7n8ifwcUJyIq4/IfJAmelHEbmijiA64i0cLZxk9v2uyehVcxsKSPKTjOwBV2zbj jewg== X-Gm-Message-State: APjAAAVhcdoBYjqEImPElL3uqU78d4Udt4PkTYm/c8VPYwfSELt4uVxL FEz9xISVts94omqtrAcOKAZTejuCxEo= X-Google-Smtp-Source: APXvYqz3t+LLQ/yvW/eTzhXETYxGsQIY8WnRmmToLKFI5XMr82T+C+8ny7tAHDb8nKwhwfGQK+qEtQ== X-Received: by 2002:a63:ed4f:: with SMTP id m15mr3505951pgk.387.1553551004774; Mon, 25 Mar 2019 14:56:44 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j20sm30645631pfi.27.2019.03.25.14.56.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:44 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 08/16] coresight: perf: Clean up function etm_setup_aux() Date: Mon, 25 Mar 2019 15:56:24 -0600 Message-Id: <20190325215632.17013-9-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325215632.17013-1-mathieu.poirier@linaro.org> References: <20190325215632.17013-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_145648_668512_722C6785 X-CRM114-Status: GOOD ( 13.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP There is no point in allocating sink memory for a trace session if there is not a way to free it once it is no longer needed. As such make sure the sink API function to allocate and free memory have been implemented before moving ahead with the establishment of a trace session. Signed-off-by: Mathieu Poirier Reviewed-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-etm-perf.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index bbfed70b3402..b8ca3800b56b 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -134,8 +134,7 @@ static void free_event_data(struct work_struct *work) if (event_data->snk_config && !WARN_ON(cpumask_empty(mask))) { cpu = cpumask_first(mask); sink = coresight_get_sink(etm_event_cpu_path(event_data, cpu)); - if (sink_ops(sink)->free_buffer) - sink_ops(sink)->free_buffer(event_data->snk_config); + sink_ops(sink)->free_buffer(event_data->snk_config); } for_each_cpu(cpu, mask) { @@ -215,7 +214,7 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, sink = coresight_get_enabled_sink(true); } - if (!sink || !sink_ops(sink)->alloc_buffer) + if (!sink) goto err; mask = &event_data->mask; @@ -261,6 +260,9 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, if (cpu >= nr_cpu_ids) goto err; + if (!sink_ops(sink)->alloc_buffer || !sink_ops(sink)->free_buffer) + goto err; + /* Allocate the sink buffer for this session */ event_data->snk_config = sink_ops(sink)->alloc_buffer(sink, cpu, pages, From patchwork Mon Mar 25 21:56:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870099 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 167B91708 for ; Mon, 25 Mar 2019 21:58:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F1309290E9 for ; Mon, 25 Mar 2019 21:58:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E512D29140; Mon, 25 Mar 2019 21:58:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 934B3290E9 for ; Mon, 25 Mar 2019 21:58:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=/ELPvT3lEdkSrPT3clNvCkuLFT4898hvQ4NwjA50Dm8=; b=o4wNY/PF8WH8I4IE8QsqlQOtQL nd+nnvzbZNfldDSlbwA3uW1ukhvjKIbbyoogMBXcaPOoQZz60SV+awmEKnR72vrcMwM5V+0EGm8kz CmI5/b2hRmbI2ri3bHy5P4U5fTz+ghKA8wGiQBkwWKajKSxWMAVxlCnLKIDG3QjMBNSAnfZwXBgIt LjcqjaKp6Ok9hI9qZqgkpj3mBhvSHHRk84NJ38cmc3jEvkb8j056FES74AWfKA5Dk3y60xvLkMXdL Rpb0CBRIZL4nuWYCMUzDP80j1aBhqAx9GLqi3paH3nf32gffFSpdv7aKcpqm3A1WlT8LA3sjxL7fC 9mZUvTGg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8Xbl-0005j6-2s; Mon, 25 Mar 2019 21:58:17 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XaL-0003qR-OO for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:56:57 +0000 Received: by mail-pf1-x442.google.com with SMTP id b3so5695383pfd.1 for ; Mon, 25 Mar 2019 14:56:49 -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=esdugp3JHWAOdac4n1jt9/v2vNqDI45vct1EVxf3pdY=; b=UUKJYKvz/GzNdKiIlzefw9v+j4w59NKSHAlKfMTC6S6ziPewLVC0mnsZ+x7VpiJw2Z GE2vJyKAL/SDgiaH/iR97ZiZSJ3WNehX/1dl0p2mlOA37MOoGOZSnGdrlfakPxGq+4Ll cKHWN0N/8VT/dk3hXCeAuhvOFlzjxT5DJT8RERTVyvouaJjckIH8q+sUOcYVO7/pYZYw 37iPdkPOoD6Bvm7gRt2hsxOuLGYfBagF3ser2ESFfqAtxjV1y7eL3gzchut80ol8uqbg nzCncU9aSozQq7wSErAmgbJCgJDiiw1NlvG1BMRNA4zaQ/QGTCei/V7IvIDo08e3PZU8 30gw== 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=esdugp3JHWAOdac4n1jt9/v2vNqDI45vct1EVxf3pdY=; b=txFrKJVlO8SERtt220NGFnG8PiFnkWvyfLPVxxBM0SIEWdDNiFk3pwSkHrWfCPRO6U VhgyzfS6WGnk2WLYL80pIH6DAg6TNoOMoY4hO3fvuRPh5FVeSKbCv3n/jDgxtMbVQbWd drPXNGtgJ6aT0TqVO1+J8CYPinxnW/7ov+GlwAePDLVD0zhwij3ww1lQlnHFhx39KEsI Ls3z434gbtMEJO5hsI/Z5UB5PFbOM+/adeAIRI/ypbJRbIMs0RZyXsEWXKFQdNtIvLyj AM9/Vwk4TnFZ/KFHkNENmX0sUD6R3VVAsc/fqXmptIv9MApHKRMxeI5dKKkaN+RFY/DJ 5d4w== X-Gm-Message-State: APjAAAUfzS3TK+Dh+n51YtLm1Sfqh54zoj4ohed1tHRBjK+tcTM5Fo0C mgMMrZeeYqGJdch1/C8PXeFyTzaMlIU= X-Google-Smtp-Source: APXvYqx0DFVXc3G5qKHMURP6/Eu1Wzd0nyE6uzoTzcSATnyOOeLrRhRCmkd8eSJq8mMziZaqEeUI9Q== X-Received: by 2002:aa7:8d01:: with SMTP id j1mr26959847pfe.122.1553551006002; Mon, 25 Mar 2019 14:56:46 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j20sm30645631pfi.27.2019.03.25.14.56.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:45 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 09/16] coresight: perf: Refactor function free_event_data() Date: Mon, 25 Mar 2019 15:56:25 -0600 Message-Id: <20190325215632.17013-10-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325215632.17013-1-mathieu.poirier@linaro.org> References: <20190325215632.17013-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_145650_352781_D34250A3 X-CRM114-Status: GOOD ( 13.11 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Function free_event_data() is already busy and is bound to become worse with the addition of CPU-wide trace scenarios. As such spin off a new function to strickly take care of the sink buffers. Signed-off-by: Mathieu Poirier Reviewed-by: Suzuki K Poulose --- .../hwtracing/coresight/coresight-etm-perf.c | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index b8ca3800b56b..806b3dd5872d 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -120,22 +120,34 @@ static int etm_event_init(struct perf_event *event) return ret; } +static void free_sink_buffer(struct etm_event_data *event_data) +{ + int cpu; + cpumask_t *mask = &event_data->mask; + struct coresight_device *sink; + + if (WARN_ON(cpumask_empty(mask))) + return; + + if (!event_data->snk_config) + return; + + cpu = cpumask_first(mask); + sink = coresight_get_sink(etm_event_cpu_path(event_data, cpu)); + sink_ops(sink)->free_buffer(event_data->snk_config); +} + static void free_event_data(struct work_struct *work) { int cpu; cpumask_t *mask; struct etm_event_data *event_data; - struct coresight_device *sink; event_data = container_of(work, struct etm_event_data, work); mask = &event_data->mask; /* Free the sink buffers, if there are any */ - if (event_data->snk_config && !WARN_ON(cpumask_empty(mask))) { - cpu = cpumask_first(mask); - sink = coresight_get_sink(etm_event_cpu_path(event_data, cpu)); - sink_ops(sink)->free_buffer(event_data->snk_config); - } + free_sink_buffer(event_data); for_each_cpu(cpu, mask) { struct list_head **ppath; From patchwork Mon Mar 25 21:56:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870105 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C31B1708 for ; Mon, 25 Mar 2019 21:58:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53C21290E9 for ; Mon, 25 Mar 2019 21:58:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 482AA29140; Mon, 25 Mar 2019 21:58:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AAD8C290E9 for ; Mon, 25 Mar 2019 21:58:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=GOiqsMq8Zha4McCfIAUjAxNp5WPZkm2zguef1bBdMdo=; b=UEpyjXeLXbtqrDi9JUgVA83OxK NMlWgjIvEnd1tmsXbLSsClj9x0cIDVGFefPiqa/w7ePHBYyqicLjqUuo2hCQGCa02Br/0omQFH06X pDExCTq+2f2kqDoJo5jvuXXCp+fXh1V686xzrgec6e7YJaSJMKzD6VZvQm+PW7Jn8vyE09olBkYYn Ne2gsJiP2AGtQ37NRexV+Fhy8GG4SdCnqa32DrAuxXvOupKFDzRpKaqf2/uvX5jxlVpJsRVb2lX8q OAXLwC0Vi4KI8Stpk0L9nJh6K2KpBVU3zElB2IYG++NEcxLKn+GbG84I0lL2Ys+1/pii9WG0S8c3I 48kRbw6w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8Xc4-0006Bq-Iu; Mon, 25 Mar 2019 21:58:36 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XaM-0003s6-5F for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:56:59 +0000 Received: by mail-pg1-x543.google.com with SMTP id z9so928611pgu.10 for ; Mon, 25 Mar 2019 14:56:49 -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=NQgvJ5++dxoOT2MCQF+eUrWqseEYE59UTgue1O5yRvY=; b=o6R1UIvjI1NlYX8oS+1EU4ihg7LZ8EQpTR4xrFbugueiIqwUxdaZ9SRnLwMCNZIZCL 2g2QhxZl18zjDm6DS62Um7VNKxsrvnHhRaQZ8dqxlT55pva7Iy7u3aXvH4azotS36OUd eN8pq4Z2bwn4BfVlUZ26sZHYt42wWsgWN8nafRclYLcVQBf2Seq/pXCbM5K/jNTgbYUA CMPIbUJkpuhmMwORU4vhKUhAN8xHj4y54n/drecBDWOGelK0vgp776pRp8luJGaBK5x6 ySXQVmb7STJbH/bfmbgfusHl53GMFbPX1VBhnCgqm5b+HLFR+Bn1GFBCJ26v5rfwLzYF kGug== 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=NQgvJ5++dxoOT2MCQF+eUrWqseEYE59UTgue1O5yRvY=; b=rwNfqcWbk8Ja0tLOmnFbs5LWq6bVOB46nmyV7XnKQ0tTziMK546yOHBzwhkl5hhY7v XuVKCjOa2IUP9YG7mHGTuI2ASTWa/QHrX44WFeIci7Z5bepgcjpyZ27lkxLEQQUf3vln vgC1idUi7dN+3df5vPB+NAiY/fRHXv8Qgg8ye9cpwb04S7bDTEkYGdEl8aSb0i9d/ERl oCNo1iLg9kNucf3RkGQ+pja/DTEXwJwL81gM+gyg/SFZTqQjXWu+9+VuuOmNnGhTPGCh ichPCSm4SnokN0CH/b7HjZcO/H2BCfMIsUz3/PG7mrDIAtrNSaeRgVasbqxROb3vW9aU 26fA== X-Gm-Message-State: APjAAAWAwtYrYnKQ5EpUTBN4V7hgc3e5TFstHHfhiYp6zArsp6NMHFP8 2UozbtQ4chRvHnsEUeOlleqkUxN3Jhs= X-Google-Smtp-Source: APXvYqwDTSYsBxp3z0DFWZzck4Mjw8pXb9G1/xiQD3OOP4xlGAnA29zYItbBXsdbs0ikqDI91V6kOQ== X-Received: by 2002:a62:205c:: with SMTP id g89mr25594665pfg.34.1553551007407; Mon, 25 Mar 2019 14:56:47 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j20sm30645631pfi.27.2019.03.25.14.56.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:46 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 10/16] coresight: Communicate perf event to sink buffer allocation function Date: Mon, 25 Mar 2019 15:56:26 -0600 Message-Id: <20190325215632.17013-11-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325215632.17013-1-mathieu.poirier@linaro.org> References: <20190325215632.17013-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_145650_543737_B5E155DB X-CRM114-Status: GOOD ( 13.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Make struct perf_event available to sink buffer allocation functions in order to use the pid they carry to allocate and free buffer memory along with regimenting access to what source a sink can collect data for. Signed-off-by: Mathieu Poirier Reviewed-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-etb10.c | 7 ++++--- drivers/hwtracing/coresight/coresight-etm-perf.c | 2 +- drivers/hwtracing/coresight/coresight-tmc-etf.c | 7 ++++--- drivers/hwtracing/coresight/coresight-tmc-etr.c | 6 ++++-- include/linux/coresight.h | 5 +++-- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c index 6b50e781dc57..7d64c41cd8ac 100644 --- a/drivers/hwtracing/coresight/coresight-etb10.c +++ b/drivers/hwtracing/coresight/coresight-etb10.c @@ -351,10 +351,11 @@ static int etb_disable(struct coresight_device *csdev) return 0; } -static void *etb_alloc_buffer(struct coresight_device *csdev, int cpu, - void **pages, int nr_pages, bool overwrite) +static void *etb_alloc_buffer(struct coresight_device *csdev, + struct perf_event *event, void **pages, + int nr_pages, bool overwrite) { - int node; + int node, cpu = event->cpu; struct cs_buffers *buf; if (cpu == -1) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index 806b3dd5872d..3c6294432748 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -277,7 +277,7 @@ static void *etm_setup_aux(struct perf_event *event, void **pages, /* Allocate the sink buffer for this session */ event_data->snk_config = - sink_ops(sink)->alloc_buffer(sink, cpu, pages, + sink_ops(sink)->alloc_buffer(sink, event, pages, nr_pages, overwrite); if (!event_data->snk_config) goto err; diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c b/drivers/hwtracing/coresight/coresight-tmc-etf.c index a38ad2b0d95a..1df1f8fade71 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etf.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c @@ -350,10 +350,11 @@ static void tmc_disable_etf_link(struct coresight_device *csdev, dev_dbg(drvdata->dev, "TMC-ETF disabled\n"); } -static void *tmc_alloc_etf_buffer(struct coresight_device *csdev, int cpu, - void **pages, int nr_pages, bool overwrite) +static void *tmc_alloc_etf_buffer(struct coresight_device *csdev, + struct perf_event *event, void **pages, + int nr_pages, bool overwrite) { - int node; + int node, cpu = event->cpu; struct cs_buffers *buf; if (cpu == -1) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index 86e748d09dc3..6e2c2aa130d5 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include "coresight-catu.h" #include "coresight-etm-perf.h" @@ -1210,9 +1211,10 @@ tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, int node, int nr_pages, static void *tmc_alloc_etr_buffer(struct coresight_device *csdev, - int cpu, void **pages, int nr_pages, - bool snapshot) + struct perf_event *event, void **pages, + int nr_pages, bool snapshot) { + int cpu = event->cpu; struct etr_perf_buffer *etr_perf; struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); diff --git a/include/linux/coresight.h b/include/linux/coresight.h index 189cc6ddc92b..62a520df8add 100644 --- a/include/linux/coresight.h +++ b/include/linux/coresight.h @@ -193,8 +193,9 @@ struct coresight_device { struct coresight_ops_sink { int (*enable)(struct coresight_device *csdev, u32 mode, void *data); int (*disable)(struct coresight_device *csdev); - void *(*alloc_buffer)(struct coresight_device *csdev, int cpu, - void **pages, int nr_pages, bool overwrite); + void *(*alloc_buffer)(struct coresight_device *csdev, + struct perf_event *event, void **pages, + int nr_pages, bool overwrite); void (*free_buffer)(void *config); unsigned long (*update_buffer)(struct coresight_device *csdev, struct perf_output_handle *handle, From patchwork Mon Mar 25 21:56:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870107 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 972581575 for ; Mon, 25 Mar 2019 21:58:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D83B28B59 for ; Mon, 25 Mar 2019 21:58:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 71CFD29131; Mon, 25 Mar 2019 21:58:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 50D9328B59 for ; Mon, 25 Mar 2019 21:58:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=OYSYs6nQYPUO59Eb6z44YJrEwin54k/rFxtFr68BYkk=; b=A9Ky2hCxMS+nwAQ+VsPsuHAOVT OyviU2kFL6O8wBjdECyw8KnYLzLbGMZ7MBZxWnmd46TgJ8XYRi5CiGXbQO4L59225HNEAcd/Uq69B ShUlECjiKKhah4mHT2FT9LxTseH7SCs/LgttC2mG/kJMuYNFLPE+r3IaMmRiNRSWdnjj6oS4Gtope BcvvYqP0o+Fapkg3U46M3FsS9hCuwv+DzeASIlEYFwrIzBAMUkLl/eWkK1sQlRhsVPt7TTZOooOpq aMwVEMDJNMpgUG0mBj+ILIWtHqHOM5nBokCp4c39sxZWh68AwrkM7LUBOHXJsUzvLc+MLKkCHWlWq wZs8GU9g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XcE-0006S2-Pd; Mon, 25 Mar 2019 21:58:46 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XaN-0003sN-AW for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:56:59 +0000 Received: by mail-pf1-x444.google.com with SMTP id 9so7046973pfj.13 for ; Mon, 25 Mar 2019 14:56:50 -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=mh7Wb1qKFF0hhvZ5dVf5oYM0kEaSjUe3jeowpeQGKzQ=; b=s5KZY8lyP1p5ip+EYvf0eLzP2XHiZj94t0ngPEJMi3Ar9ZdiYNQYBImMAF5LV5bhIj S+hrN0Ua3CyE9cbQY2u2QBw7RiKza1HCT3iuJK78fhKDD9yqY6TNn5PiRQpljISYb14k P/e3QFgK+b/cxv1+CiuwWtoHUngnWnnlV/O1BwRBb0bHWAUqH0NjOsHREf2nmbW2bDoF VEQqt9I6oY9TTLN+umy37TW8m+3yNzueV2m4c6Xlokwi8/W/Bf8Z9w3xRg8dPS6HmAEQ y/vfjEeXCWfh4uyarIrptzUW/ASLeNsh12Dab/PRkGDrNxvel5GDK4wbsceIzfQyD6Mk rCrg== 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=mh7Wb1qKFF0hhvZ5dVf5oYM0kEaSjUe3jeowpeQGKzQ=; b=Vs7Dyw8CK10bqzvY5fZh2i8EK/KBkF5rQ/yWeyRNvP0eaT94sVkrzJjqY7hRWkhW+X Dr0PgtHiWaQosknNI6TwZCHuyoFC+f6PydbCyNty6F5cZg7wWt5Z6C3S1qwxvZoiGx3y NVH0gS2cQT6m1jK3uaJrrNJ79KSH3aPEbPATun3CX3eeVuWrcS1vJ1V1EfHW9rtlZ+9g HfeDIgHifNMqgIR8884D/43UyXCz3KC0d6P+R1vS9CzH7AeKJRHdsy1M1YDUFe8wKkKC qgC6LwqgP1qaGaITF6uwllkF2p32aCNNHQ3oAGTfuepaJPrrSWEmsokoEv72lswMP+Xv c8Nw== X-Gm-Message-State: APjAAAUQ9flNA1XNq9DPHu3lPFZBD8K6I/dBaJnV5yRTyiKUVit6Scuq 1wGO1gh94N6Swl4bvrdMTZd/BPazs4A= X-Google-Smtp-Source: APXvYqy/wUUZeCq0dk9/Rv0Z4FvwDiyfCiqm9XgdrXwBFchEsaAC8AAtYRl89bpFg6yS0JAafO9s8w== X-Received: by 2002:aa7:8c84:: with SMTP id p4mr12858780pfd.164.1553551008607; Mon, 25 Mar 2019 14:56:48 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j20sm30645631pfi.27.2019.03.25.14.56.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:48 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 11/16] coresight: tmc-etr: Refactor function tmc_etr_setup_perf_buf() Date: Mon, 25 Mar 2019 15:56:27 -0600 Message-Id: <20190325215632.17013-12-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325215632.17013-1-mathieu.poirier@linaro.org> References: <20190325215632.17013-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_145651_879589_6AB772CC X-CRM114-Status: GOOD ( 14.91 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Refactoring function tmc_etr_setup_perf_buf() so that it only deals with the high level etr_perf_buffer, and leaving the allocation of the backend buffer (i.e etr_buf) to another function. That way the backend buffer allocation function can decide if it wants to reuse an existing buffer (CPU-wide trace scenarios) or simply create a new one. Signed-off-by: Mathieu Poirier Reviewed-by: Suzuki K Poulose --- .../hwtracing/coresight/coresight-tmc-etr.c | 46 +++++++++++++------ 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index 6e2c2aa130d5..79fee9341446 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1159,25 +1159,13 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev) return ret; } -/* - * tmc_etr_setup_perf_buf: Allocate ETR buffer for use by perf. - * The size of the hardware buffer is dependent on the size configured - * via sysfs and the perf ring buffer size. We prefer to allocate the - * largest possible size, scaling down the size by half until it - * reaches a minimum limit (1M), beyond which we give up. - */ -static struct etr_perf_buffer * -tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, int node, int nr_pages, - void **pages, bool snapshot) +static struct etr_buf * +tmc_etr_get_etr_buf(struct tmc_drvdata *drvdata, int node, + int nr_pages, void **pages) { struct etr_buf *etr_buf; - struct etr_perf_buffer *etr_perf; unsigned long size; - etr_perf = kzalloc_node(sizeof(*etr_perf), GFP_KERNEL, node); - if (!etr_perf) - return ERR_PTR(-ENOMEM); - /* * Try to match the perf ring buffer size if it is larger * than the size requested via sysfs. @@ -1201,6 +1189,34 @@ tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, int node, int nr_pages, size /= 2; } while (size >= TMC_ETR_PERF_MIN_BUF_SIZE); + return ERR_PTR(-ENOMEM); + +done: + return etr_buf; +} + +/* + * tmc_etr_setup_perf_buf: Allocate ETR buffer for use by perf. + * The size of the hardware buffer is dependent on the size configured + * via sysfs and the perf ring buffer size. We prefer to allocate the + * largest possible size, scaling down the size by half until it + * reaches a minimum limit (1M), beyond which we give up. + */ +static struct etr_perf_buffer * +tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, int node, + int nr_pages, void **pages, bool snapshot) +{ + struct etr_buf *etr_buf; + struct etr_perf_buffer *etr_perf; + + etr_perf = kzalloc_node(sizeof(*etr_perf), GFP_KERNEL, node); + if (!etr_perf) + return ERR_PTR(-ENOMEM); + + etr_buf = tmc_etr_get_etr_buf(drvdata, node, nr_pages, pages); + if (!IS_ERR(etr_buf)) + goto done; + kfree(etr_perf); return ERR_PTR(-ENOMEM); From patchwork Mon Mar 25 21:56:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870103 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 97D601708 for ; Mon, 25 Mar 2019 21:58:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7853B28B59 for ; Mon, 25 Mar 2019 21:58:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 693F329149; Mon, 25 Mar 2019 21:58:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ECAA828B59 for ; Mon, 25 Mar 2019 21:58:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=8+N4ANP5HHopOze90Zam0xQhrXNGoVNhxt3epToB30w=; b=kffTMJE8M7fOzFLo/efVWjVlfk onCiXs36DZd2I48BrRBy39P0dZsaFtEF68xFIhzy+KQbDmwbAs0fOWWA63cMS6OrggzEUsEhUJABn x8TmU0guwrjI1zFs1Ibi9H9RReoWqJxC/iqPZMOOWGEv5JqxigfgV8qSNYBRKbwDLKYRVdyoY59VC 6fF1p/xhbdB+8FfaU55/vF0SEOJEPvxZIssyg3lcsQ58XSaaaQsyAe0ZimbpxzKfyAFj7Xr/pXDrV 1dza6nXKKHzBe8GJXVpAzjirW+TOqHi94gUKd/nliw1aJ8X+to+fCwOFRQTKLrDxSXSfNJ3VB0Xey WnV6q13Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8Xbt-0005wi-BD; Mon, 25 Mar 2019 21:58:25 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XaM-0003uA-MX for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:56:57 +0000 Received: by mail-pg1-x543.google.com with SMTP id r124so7225070pgr.3 for ; Mon, 25 Mar 2019 14:56:50 -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=3htge2VRmm5r+nRsT8mJwIBfRVfy6Z61FIF/jDsvIig=; b=qrINl1M+r7kTYAZ62D6IMOEDMddMilbSBTXj3Zr57hADEVRVsBXN0R6QC1KVTyAkEJ obTcSaK/2ExfJ4JMFZqky8ejqsb4pF/kFtEpLdp6D9JxI+n9B6F/ApxrV/WGfvTAuiNl HGobEswT4nutrG6KpBIARJ4khddrkoHPPdG345wXtFRyXxwLV45Ggs076iefFGz+fqI0 6KcJZC61avoHUvRVyoaBW0fgB8BQAqsxRxTjvWu/lRs0VlUXc9P0UwBO/pLGqYxRIYkc fHxdTzTc03668KTMxexpknLIGYxaErUlR/ZgeCSBXVHUeVqAHp8qgsp3BkeXlFlOxKnk 0q9w== 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=3htge2VRmm5r+nRsT8mJwIBfRVfy6Z61FIF/jDsvIig=; b=BXqMpzDBfQrDLh9sySERmVBkcytV0gwkvxOHM8S7uYZ5DisxwVbLxqYWNPly6DRR4e zTqBy9sdIfxxTpcYqGsP9FT7DfSz0pZOPsrS0WYW4Dud7aAcFkaDlnLGj1EXn424/F8w 4CHDrrW6sSMKVeTNywUWSvuuNnLdQTfzKqhCHs12Jrzt7BUEpXtyBqfJBEnuMqOs4UpV CnhHa2HoolVbJoZmQt5SFczaI3q5phL4zQd/UZP1rUEo0idAuHJHiq7tRoiHgnYSet/b G3slL6D4jmBFbTscMVVJn8hAUXyOCUBsmcuh5WiJrOEsFDEbWIg6ZS+7TtPap7tlwhMh WgRQ== X-Gm-Message-State: APjAAAVQDSQ3Slu5la4ouFc/5dCOPAX+pLSh58ft9ncnk3zsZSwWT2Wu HbhwGQsG/telNHmF6kgYMjh/u/0c7y0= X-Google-Smtp-Source: APXvYqxn8iU1EWDxKRW5RuUHWe4QiNsIwRKOKXinKeXxspGQC9VkWeaF5iAXCwDHvrOxHMVjrSguOg== X-Received: by 2002:a62:6ec3:: with SMTP id j186mr26901895pfc.89.1553551009831; Mon, 25 Mar 2019 14:56:49 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j20sm30645631pfi.27.2019.03.25.14.56.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:49 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 12/16] coresight: tmc-etr: Introduce the notion of process ID to ETR devices Date: Mon, 25 Mar 2019 15:56:28 -0600 Message-Id: <20190325215632.17013-13-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325215632.17013-1-mathieu.poirier@linaro.org> References: <20190325215632.17013-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_145651_117404_5CE44343 X-CRM114-Status: GOOD ( 16.70 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP In preparation to support CPU-wide trace scenarios, add the notion of process ID to ETR devices so that memory buffers can be shared between events. Signed-off-by: Mathieu Poirier Reviewed-by: Suzuki K Poulose --- .../hwtracing/coresight/coresight-tmc-etr.c | 22 +++++++++++++++++-- drivers/hwtracing/coresight/coresight-tmc.h | 3 +++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index 79fee9341446..7254fafdf1c2 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -26,6 +26,7 @@ struct etr_flat_buf { /* * etr_perf_buffer - Perf buffer used for ETR * @etr_buf - Actual buffer used by the ETR + * @pid - The PID this etr_perf_buffer belongs to. * @snaphost - Perf session mode * @head - handle->head at the beginning of the session. * @nr_pages - Number of pages in the ring buffer. @@ -33,6 +34,7 @@ struct etr_flat_buf { */ struct etr_perf_buffer { struct etr_buf *etr_buf; + pid_t pid; bool snapshot; unsigned long head; int nr_pages; @@ -1160,8 +1162,8 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev) } static struct etr_buf * -tmc_etr_get_etr_buf(struct tmc_drvdata *drvdata, int node, - int nr_pages, void **pages) +alloc_etr_buf(struct tmc_drvdata *drvdata, int node, + int nr_pages, void **pages) { struct etr_buf *etr_buf; unsigned long size; @@ -1195,6 +1197,20 @@ tmc_etr_get_etr_buf(struct tmc_drvdata *drvdata, int node, return etr_buf; } +static struct etr_buf * +tmc_etr_get_etr_buf(struct tmc_drvdata *drvdata, int node, + int nr_pages, void **pages) +{ + struct etr_buf *etr_buf; + + etr_buf = alloc_etr_buf(drvdata, node, nr_pages, pages); + if (IS_ERR(etr_buf)) + return etr_buf; + + refcount_set(&etr_buf->refcount, 1); + return etr_buf; +} + /* * tmc_etr_setup_perf_buf: Allocate ETR buffer for use by perf. * The size of the hardware buffer is dependent on the size configured @@ -1231,6 +1247,7 @@ static void *tmc_alloc_etr_buffer(struct coresight_device *csdev, int nr_pages, bool snapshot) { int cpu = event->cpu; + pid_t pid = task_pid_nr(event->owner); struct etr_perf_buffer *etr_perf; struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); @@ -1244,6 +1261,7 @@ static void *tmc_alloc_etr_buffer(struct coresight_device *csdev, return NULL; } + etr_perf->pid = pid; etr_perf->snapshot = snapshot; etr_perf->nr_pages = nr_pages; etr_perf->pages = pages; diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h index 487c53701e9c..7675138ff9fc 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.h +++ b/drivers/hwtracing/coresight/coresight-tmc.h @@ -9,6 +9,7 @@ #include #include +#include #define TMC_RSZ 0x004 #define TMC_STS 0x00c @@ -133,6 +134,7 @@ struct etr_buf_operations; /** * struct etr_buf - Details of the buffer used by ETR + * @refcount : Number of sources currently using this etr_buf. * @mode : Mode of the ETR buffer, contiguous, Scatter Gather etc. * @full : Trace data overflow * @size : Size of the buffer. @@ -143,6 +145,7 @@ struct etr_buf_operations; * @private : Backend specific information for the buf */ struct etr_buf { + refcount_t refcount; enum etr_mode mode; bool full; ssize_t size; From patchwork Mon Mar 25 21:56:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870111 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 061981708 for ; Mon, 25 Mar 2019 21:59:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E293928B59 for ; Mon, 25 Mar 2019 21:59:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D672429143; Mon, 25 Mar 2019 21:59:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3562529131 for ; Mon, 25 Mar 2019 21:59:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=PxLtZkJ5UsdluwghPGi+Gu30qNcV0d6KRDMRvNccUkg=; b=kHBQOaqZSzchAaajiD2jAZQ0b6 IOjvR+4ObILU+iXoyVmdbko64D2XEUoQq7qIBmk3ni2yiFr5QjhgW56sIJ4YRJ4iDhQ471iXxdVdL je069HWjCNQD86RPwLODJp64nhsMMys6IDz54GFmC4xV6CvMZck8qD3B9PLMeguGWmL7pz18yGlX4 4kqVJXWifHG7zYHt/017bjfLOgsDRNbagg7h3knGKUaGK8iXIjjr2fiAnwmj+NmhFmlG8/neZBfwQ qKTXnwQ4jPOkVgakJP/MMG19GmsO45sPw8ZJAWvLt+NG6TWfVJJNXhYAttv2meaBbD719NIzCuhN6 5C2G8QMQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XcP-0006kB-Uc; Mon, 25 Mar 2019 21:58:57 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XaO-0003wH-9u for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:57:02 +0000 Received: by mail-pg1-x544.google.com with SMTP id k3so3520357pga.6 for ; Mon, 25 Mar 2019 14:56:52 -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=uiqSAmnkL1HZ4rlEE2wONurqG2AIFCXWVuoL14zUTck=; b=QZnN7r4rykFT3fiH05Hkbip8TNVCH/kWzE8tq69tN98YCVVj27QQjscPrryYida58W 0xTkSJNZvKIpEYxn29xxsdpqMObqCk+7FKVvEcaPjnbcPzAATN1Wtrqab7rllFgvyi1Q ZbHxSeb7rhgoZK4ijdh9RujO2gqNgXT32iLzXo0teEbYvF5de8dysLLGJQLGk6PyvGtX whYnW6RMhB7nr68lfxylmkKDlIbye89bFI27nzeyBVmv0vFUWA7qRZasYufPoWU4mnSX TdFOKlX4ezw116rKSrJdAwA/53VxbtFrHXKkPdNb/Ab8NtrtK/jz3XL5lZ0LbQaDeOLW YRMw== 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=uiqSAmnkL1HZ4rlEE2wONurqG2AIFCXWVuoL14zUTck=; b=IKtpn+UycEbOzaWELtLeaSfn5MbX1sAalVn+yoPZHNZV4fv71QQUvYIjc1jLQ1Kt1r NIvMNXW8RtaSuXdlBuDdAyewe4sUt8JuWhT9fbYvKMlh64WoCe0/xN96oK5l/ylzumKg 9MwvxHPWnr5J4YmSb0toF/VfS0KY2q1FTVTuePk6oCAp85Fkr7lJyaCYMrQI41y0f7iO u4shLnJUAS1Q5lAahRkTvrpKWmoxbvdf0H2s/PZvOmkrXiA72wBwraOnV3199wdOqv/E /k+n7t09SHezBwSIaGr8xaACVJwtIP81asCPZzrK/glQmAUqGeI/36IUVU/MyVF3QrYr xalw== X-Gm-Message-State: APjAAAU+/+q+EKkpfHdcfOKC7Y85nx0M4xW5TNvpsTZmXIQxT5WSKg6n NQHrzP5f7HLDgnfmD503NeGaMqQaInk= X-Google-Smtp-Source: APXvYqwoyMPcydEE8ssHd4xpMG/n8GC8PR2IQdnJ6E/4ega4bZxgpdB7UFNmYasAFiwi+tQUwz4BKw== X-Received: by 2002:a65:6203:: with SMTP id d3mr25615587pgv.109.1553551010994; Mon, 25 Mar 2019 14:56:50 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j20sm30645631pfi.27.2019.03.25.14.56.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:50 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 13/16] coresight: tmc-etr: Allow events to use the same ETR buffer Date: Mon, 25 Mar 2019 15:56:29 -0600 Message-Id: <20190325215632.17013-14-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325215632.17013-1-mathieu.poirier@linaro.org> References: <20190325215632.17013-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_145653_154168_166C08D0 X-CRM114-Status: GOOD ( 19.65 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch uses the pid of the process being traced to aggregate traces coming from different processors in the same sink, something that is required when collecting traces in CPU-wide mode when the CoreSight HW enacts a N:1 source/sink topology. Signed-off-by: Mathieu Poirier --- .../hwtracing/coresight/coresight-tmc-etr.c | 71 +++++++++++++++++-- 1 file changed, 65 insertions(+), 6 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index 7254fafdf1c2..cbabf88bd51d 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -41,6 +42,9 @@ struct etr_perf_buffer { void **pages; }; +static DEFINE_IDR(session_idr); +static DEFINE_MUTEX(session_idr_lock); + /* Convert the perf index to an offset within the ETR buffer */ #define PERF_IDX2OFF(idx, buf) ((idx) % ((buf)->nr_pages << PAGE_SHIFT)) @@ -1198,16 +1202,48 @@ alloc_etr_buf(struct tmc_drvdata *drvdata, int node, } static struct etr_buf * -tmc_etr_get_etr_buf(struct tmc_drvdata *drvdata, int node, +tmc_etr_get_etr_buf(struct tmc_drvdata *drvdata, pid_t pid, int node, int nr_pages, void **pages) { + int ret; struct etr_buf *etr_buf; +retry: + /* See if a buffer has been allocated for this session */ + mutex_lock(&session_idr_lock); + etr_buf = idr_find(&session_idr, pid); + if (etr_buf) { + refcount_inc(&etr_buf->refcount); + mutex_unlock(&session_idr_lock); + return etr_buf; + } + + /* If we made it here no buffer has been allocated, do so now. */ + mutex_unlock(&session_idr_lock); + etr_buf = alloc_etr_buf(drvdata, node, nr_pages, pages); if (IS_ERR(etr_buf)) return etr_buf; refcount_set(&etr_buf->refcount, 1); + + /* Now that we have a buffer, add it to the IDR. */ + mutex_lock(&session_idr_lock); + ret = idr_alloc(&session_idr, etr_buf, pid, pid + 1, GFP_KERNEL); + mutex_unlock(&session_idr_lock); + + /* Another event whith this session ID has allocated this buffer. */ + if (ret == -ENOSPC) { + tmc_free_etr_buf(etr_buf); + goto retry; + } + + /* The IDR can't allocate room for a new session, abandon ship. */ + if (ret == -ENOMEM) { + tmc_free_etr_buf(etr_buf); + return ERR_PTR(ret); + } + return etr_buf; } @@ -1219,7 +1255,7 @@ tmc_etr_get_etr_buf(struct tmc_drvdata *drvdata, int node, * reaches a minimum limit (1M), beyond which we give up. */ static struct etr_perf_buffer * -tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, int node, +tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, pid_t pid, int node, int nr_pages, void **pages, bool snapshot) { struct etr_buf *etr_buf; @@ -1229,7 +1265,7 @@ tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, int node, if (!etr_perf) return ERR_PTR(-ENOMEM); - etr_buf = tmc_etr_get_etr_buf(drvdata, node, nr_pages, pages); + etr_buf = tmc_etr_get_etr_buf(drvdata, pid, node, nr_pages, pages); if (!IS_ERR(etr_buf)) goto done; @@ -1254,7 +1290,7 @@ static void *tmc_alloc_etr_buffer(struct coresight_device *csdev, if (cpu == -1) cpu = smp_processor_id(); - etr_perf = tmc_etr_setup_perf_buf(drvdata, cpu_to_node(cpu), + etr_perf = tmc_etr_setup_perf_buf(drvdata, pid, cpu_to_node(cpu), nr_pages, pages, snapshot); if (IS_ERR(etr_perf)) { dev_dbg(drvdata->dev, "Unable to allocate ETR buffer\n"); @@ -1272,9 +1308,32 @@ static void *tmc_alloc_etr_buffer(struct coresight_device *csdev, static void tmc_free_etr_buffer(void *config) { struct etr_perf_buffer *etr_perf = config; + struct etr_buf *buf, *etr_buf = etr_perf->etr_buf; + + if (!etr_buf) + goto free_etr_perf_buffer; + + mutex_lock(&session_idr_lock); + /* If we are not the last one to use the buffer, don't touch it. */ + if (!refcount_dec_and_test(&etr_buf->refcount)) { + mutex_unlock(&session_idr_lock); + goto free_etr_perf_buffer; + } + + /* We are the last one, remove from the IDR and free the buffer. */ + buf = idr_remove(&session_idr, etr_perf->pid); + mutex_unlock(&session_idr_lock); + + /* + * Something went very wrong if the buffer associated with this ID + * is not the same in the IDR. Leak to avoid use after free. + */ + if (WARN_ON(buf != etr_buf)) + goto free_etr_perf_buffer; + + tmc_free_etr_buf(etr_perf->etr_buf); - if (etr_perf->etr_buf) - tmc_free_etr_buf(etr_perf->etr_buf); +free_etr_perf_buffer: kfree(etr_perf); } From patchwork Mon Mar 25 21:56:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870171 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 15F1214DE for ; Mon, 25 Mar 2019 22:07:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F0FBF29010 for ; Mon, 25 Mar 2019 22:07:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E517829055; Mon, 25 Mar 2019 22:07:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6C95429010 for ; Mon, 25 Mar 2019 22:07:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=yzNozQ7FMvgkOFbpmTjlfwAX7DI2YtfbdVZFiquCg+g=; b=fEvaRBDffPWpjNF7yt6rJKAKQI Ad04rIkKUAiQRr9R3j5Rv7lByJS/yh8HYt4j4jeo0lExJ9zOVc7W4XBmZtj1KGLZDI/e5MqSeqzn8 NdDtegU2doX6m2/G7l4tsQ2DFgJO69KNWCGEq/68HCJvh+NZ8aandoh9F3tWHdTWm/0gyjDHyyiaJ AXSAONmi0GZkFXXGqulHsTizvfUEhxkB9PW9SE29tLNFC8ltZ0YNVQg04dEr2VwGcYa1Ad/fdp4s3 zBgnmdBbei4NYUD0AwU02k6I+tOtWM/JgvLTlPl+KjI/KLpjeIakQrRYVG9LzXm89m1Q6OM45hk6M yqjJ3d0Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XkB-0002u7-TV; Mon, 25 Mar 2019 22:06:59 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XaR-0003y3-C2 for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:57:05 +0000 Received: by mail-pl1-x642.google.com with SMTP id g37so583122plb.5 for ; Mon, 25 Mar 2019 14:56:53 -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=SFlQXWcuCKhiwHaave/9eAIjyboIhncoHRVpAB/VR3A=; b=IkfZe45c0q/BeWLJt6SvirnvhsMHUmdul93MJEUB0VySDNwmHakh0m6XedLWYYfOHH /BQpvSQldnWtynDvIRDHx5CbOB66X+nGlGwEVsasf4wbrHHXoqYitOWPSgvsKEbMPLRi K5/FuwiyzByYULjhu2z0iD5Qi9PG59RYA8EpquunZcIuGUqBQfLJwCbBMkwxRTjliqep bklyqDT7qfLV6Y9d/xxWaovfkTZq7dZWihjHt2fryoJ30eVsHYUGgUy2WTfKGAFKoXK1 OrnQsuMlsXM6LLM2xss0V9dmOn8/X51qJmlt5CX4qEvdQtAFi9I9vjtiC44SQcGD0vam aTsg== 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=SFlQXWcuCKhiwHaave/9eAIjyboIhncoHRVpAB/VR3A=; b=BmUFyg6vwbmgAF1OwZvbVOuQfDiFwRE+x3tNXUyIrdpS6ZPdpiI9mUal+RUPY9l7ez ZzEoyo4whweud/f5ewS/fQhUtFEcwXbSxzXwVxoWPx5LMEYznLGn537i+pZyiFQtsHYb Dc+B0uAlBAw7TKWvgp6zj0wJP2i1rhvSsGhUbctMSrxRYJ6MakKhjsqgaP0HcBajPQjf fgsrvAI/lFqp8qCWSzqPF/wsVRWEgui21ly3Dc7UKeQu89ayc0zQU5vs+61BKq3MfF0W EvQ3YYXd9SiqxgUt+5x2QDRZN0q1vsWxKB/4bKpo40qyOj7PXn9XzD03SWzFtrCaWWLU 528w== X-Gm-Message-State: APjAAAXtV7JH6nZH73O4DqusFr/9Rk3xaQPZm5xtJWDkKpFX8qE5Y7dZ vTH6JC+u403WmUM7SPyBF9STMTXGFrU= X-Google-Smtp-Source: APXvYqzs6wl2KKVebsvp/WinU23aLoyBVfmJY8c/k4jqnJjNwRHyvoM7Wxs3zBngNHNWUex3HFon3w== X-Received: by 2002:a17:902:20e8:: with SMTP id v37mr15105459plg.168.1553551012155; Mon, 25 Mar 2019 14:56:52 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j20sm30645631pfi.27.2019.03.25.14.56.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:51 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 14/16] coresight: tmc-etr: Add support for CPU-wide trace scenarios Date: Mon, 25 Mar 2019 15:56:30 -0600 Message-Id: <20190325215632.17013-15-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325215632.17013-1-mathieu.poirier@linaro.org> References: <20190325215632.17013-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_145655_821911_CE571D65 X-CRM114-Status: GOOD ( 22.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for CPU-wide trace scenarios by making sure that only the sources monitoring the same process have access to a common sink. Because the sink is shared between sources, the first source to use the sink switches it on while the last one does the cleanup. Any attempt to modify the HW is overlooked for as long as more than one source is using a sink. Signed-off-by: Mathieu Poirier --- .../hwtracing/coresight/coresight-tmc-etr.c | 38 ++++++++++++++++--- drivers/hwtracing/coresight/coresight-tmc.c | 2 + drivers/hwtracing/coresight/coresight-tmc.h | 3 ++ 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index cbabf88bd51d..48093605331a 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1408,6 +1408,13 @@ tmc_update_etr_buffer(struct coresight_device *csdev, struct etr_buf *etr_buf = etr_perf->etr_buf; spin_lock_irqsave(&drvdata->spinlock, flags); + + /* Don't do anything if another tracer is using this sink */ + if (atomic_read(csdev->refcnt) != 1) { + spin_unlock_irqrestore(&drvdata->spinlock, flags); + goto out; + } + if (WARN_ON(drvdata->perf_data != etr_perf)) { lost = true; spin_unlock_irqrestore(&drvdata->spinlock, flags); @@ -1447,17 +1454,15 @@ tmc_update_etr_buffer(struct coresight_device *csdev, static int tmc_enable_etr_sink_perf(struct coresight_device *csdev, void *data) { int rc = 0; + pid_t pid; unsigned long flags; struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); struct perf_output_handle *handle = data; struct etr_perf_buffer *etr_perf = etm_perf_sink_config(handle); spin_lock_irqsave(&drvdata->spinlock, flags); - /* - * There can be only one writer per sink in perf mode. If the sink - * is already open in SYSFS mode, we can't use it. - */ - if (drvdata->mode != CS_MODE_DISABLED || WARN_ON(drvdata->perf_data)) { + /* Don't use this sink if it is already claimed by sysFS */ + if (drvdata->mode == CS_MODE_SYSFS) { rc = -EBUSY; goto unlock_out; } @@ -1467,10 +1472,31 @@ static int tmc_enable_etr_sink_perf(struct coresight_device *csdev, void *data) goto unlock_out; } + /* Get a handle on the pid of the process to monitor */ + pid = etr_perf->pid; + + /* Do not proceed if this device is associated with another session */ + if (drvdata->pid != -1 && drvdata->pid != pid) { + rc = -EBUSY; + goto unlock_out; + } + etr_perf->head = PERF_IDX2OFF(handle->head, etr_perf); drvdata->perf_data = etr_perf; + + /* + * No HW configuration is needed if the sink is already in + * use for this session. + */ + if (drvdata->pid == pid) { + atomic_inc(csdev->refcnt); + goto unlock_out; + } + rc = tmc_etr_enable_hw(drvdata, etr_perf->etr_buf); if (!rc) { + /* Associate with monitored process. */ + drvdata->pid = pid; drvdata->mode = CS_MODE_PERF; atomic_inc(csdev->refcnt); } @@ -1514,6 +1540,8 @@ static int tmc_disable_etr_sink(struct coresight_device *csdev) /* Complain if we (somehow) got out of sync */ WARN_ON_ONCE(drvdata->mode == CS_MODE_DISABLED); tmc_etr_disable_hw(drvdata); + /* Dissociate from monitored process. */ + drvdata->pid = -1; drvdata->mode = CS_MODE_DISABLED; spin_unlock_irqrestore(&drvdata->spinlock, flags); diff --git a/drivers/hwtracing/coresight/coresight-tmc.c b/drivers/hwtracing/coresight/coresight-tmc.c index 2a02da3d630f..b01e587f376d 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.c +++ b/drivers/hwtracing/coresight/coresight-tmc.c @@ -415,6 +415,8 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) devid = readl_relaxed(drvdata->base + CORESIGHT_DEVID); drvdata->config_type = BMVAL(devid, 6, 7); drvdata->memwidth = tmc_get_memwidth(devid); + /* This device is not associated with a session */ + drvdata->pid = -1; if (drvdata->config_type == TMC_CONFIG_TYPE_ETR) { if (np) diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h index 7675138ff9fc..c66cbce28bd4 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.h +++ b/drivers/hwtracing/coresight/coresight-tmc.h @@ -163,6 +163,8 @@ struct etr_buf { * @csdev: component vitals needed by the framework. * @miscdev: specifics to handle "/dev/xyz.tmc" entry. * @spinlock: only one at a time pls. + * @pid: Process ID of the process being monitored by the session + * that is using this component. * @buf: Snapshot of the trace data for ETF/ETB. * @etr_buf: details of buffer used in TMC-ETR * @len: size of the available trace for ETF/ETB. @@ -182,6 +184,7 @@ struct tmc_drvdata { struct coresight_device *csdev; struct miscdevice miscdev; spinlock_t spinlock; + pid_t pid; bool reading; union { char *buf; /* TMC ETB */ From patchwork Mon Mar 25 21:56:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870123 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 790421575 for ; Mon, 25 Mar 2019 21:59:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CF5F26E16 for ; Mon, 25 Mar 2019 21:59:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4CD7A284C3; Mon, 25 Mar 2019 21:59:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C67EB26E16 for ; Mon, 25 Mar 2019 21:59:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=2n64817kBFRLbBs7h6JjR4bFTcbm3o2/p+rWVZRKBuM=; b=u4J1r51fNXpS93vXAlP8Z0PChT wVJRrUdQxVSgpIEfU2tRQkFqXKPUAHAaC1rORXpilx/bPQr51Bdsv3viYVeJK9Q/zsOxkF0E7Td1Z CtpwTL47gK1hnve6+wsdeh/0MThaMwvWjEOtvd0bp5RqFeAqDEnmF90LBBIl0TNtSz+kF+OhraxqE V3Ct5IEBRbUuTIxIgQvg12Q/voaZjCi23Yjb8LOkaHXj2tjzL2E0FWtXm8D8I54/kC10huVB5mmG0 GBr9iwRVCymgKw+n6qfB4hBg40N32mcU3HfMaifovdl3+tRHOnQJp9GzOGRn/Ciw74KeMC2SUOiaG zy72xROw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8Xcr-0007PU-TI; Mon, 25 Mar 2019 21:59:25 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XaR-00040F-Bx for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:57:08 +0000 Received: by mail-pl1-x642.google.com with SMTP id b65so587044plb.6 for ; Mon, 25 Mar 2019 14:56:54 -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=sdDt/HRF6MLGkuxtGtaVQsmhDK4+MNWevaRbT+jK8kU=; b=IGClc5M9zhSt/zZtnDHqjJnwdmi73yo7WwX7rK0ctpzRZz7wcrLQreOOTnlLCPKgt/ jbG3K/oLDaSO8zzKaLXFSYEBqQFpEUDqZQYH8eHnBom3FHd0hNp7SvGSmgJ+/tn3iZjq CTW1bWo74G+ean4EntP0UOgvm0zV6XdnyRtTXgiSvDJZzlGWtEaSvD7CfzBKix1MjO5f T59HLnLYrX/XwOZe01r0ZMT7Sq6Sw2av65IUS33iSDwUGVLDGEREkBRWDERqAoJszi7u Ty4PvbRgFzUkka/WLBfOksaNj/hmzVDoHfYS0MuJTlLDKolpC+NBjfZkKFACNy8J4zDG oecw== 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=sdDt/HRF6MLGkuxtGtaVQsmhDK4+MNWevaRbT+jK8kU=; b=LAuxK+ODn5Jh7MAvUhmEWU/x/WFtJnNQQaqL3lcsdJ8t8DiRDK27gipkrhUUzFvcCI DInFX7dPHA9tghrPnWHHUZXQQgWVrJCuA8Za84NMIWMSa3nZIwgFZe4MDWLNC9+PLHxZ AcXpvdYa3YKYV/r1XkFoz77X7o5FWrdH5uc0BwyBKU0qvbX7DROborY9xvppNnfZ1M9B hRnjKp51UR7zNDGGlb7ebRDg2p3x1GF7yRuHXHN2nrx5nwCWcDVLmFnuG8/blPdLj/v5 LVvo93+MJ0DFTY/RbgwyrJgWcDrjmxdGgVPrACgNIqWKk8zTFe0thaKpHcajCXgd80Sr lNGA== X-Gm-Message-State: APjAAAUNmzICfgpZNJSgaqcTtohfh4f10Rr8qc8tv2hzP+T/ld/R045M AKRmwrznl9ZlFNeLFgZMt/+Q4hHtQEk= X-Google-Smtp-Source: APXvYqwYoFrcWKiplK8jsgdHh6wkanoj0E/rlKL6xVTh7z3hgOWJlsLG2UaHA+hpBkm6/MG74bsGIA== X-Received: by 2002:a17:902:8349:: with SMTP id z9mr7851629pln.144.1553551013416; Mon, 25 Mar 2019 14:56:53 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j20sm30645631pfi.27.2019.03.25.14.56.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:52 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 15/16] coresight: tmc-etf: Add support for CPU-wide trace scenarios Date: Mon, 25 Mar 2019 15:56:31 -0600 Message-Id: <20190325215632.17013-16-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325215632.17013-1-mathieu.poirier@linaro.org> References: <20190325215632.17013-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_145655_967672_1A32B8FD X-CRM114-Status: GOOD ( 20.16 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for CPU-wide trace scenarios by making sure that only the sources monitoring the same process have access to a common sink. Because the sink is shared between sources, the first source to use the sink switches it on while the last one does the cleanup. Any attempt to modify the HW is overlooked for as long as more than one source is using a sink. Signed-off-by: Mathieu Poirier --- .../hwtracing/coresight/coresight-tmc-etf.c | 40 ++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etf.c b/drivers/hwtracing/coresight/coresight-tmc-etf.c index 1df1f8fade71..2527b5d3b65e 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etf.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etf.c @@ -223,6 +223,7 @@ static int tmc_enable_etf_sink_sysfs(struct coresight_device *csdev) static int tmc_enable_etf_sink_perf(struct coresight_device *csdev, void *data) { int ret = 0; + pid_t pid; unsigned long flags; struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); struct perf_output_handle *handle = data; @@ -233,18 +234,39 @@ static int tmc_enable_etf_sink_perf(struct coresight_device *csdev, void *data) if (drvdata->reading) break; /* - * In Perf mode there can be only one writer per sink. There - * is also no need to continue if the ETB/ETF is already - * operated from sysFS. + * No need to continue if the ETB/ETF is already operated + * from sysFS. */ - if (drvdata->mode != CS_MODE_DISABLED) + if (drvdata->mode == CS_MODE_SYSFS) { + ret = -EBUSY; break; + } + + /* Get a handle on the pid of the process to monitor */ + pid = task_pid_nr(handle->event->owner); + + if (drvdata->pid != -1 && drvdata->pid != pid) { + ret = -EBUSY; + break; + } ret = tmc_set_etf_buffer(csdev, handle); if (ret) break; + + /* + * No HW configuration is needed if the sink is already in + * use for this session. + */ + if (drvdata->pid == pid) { + atomic_inc(csdev->refcnt); + break; + } + ret = tmc_etb_enable_hw(drvdata); if (!ret) { + /* Associate with monitored process. */ + drvdata->pid = pid; drvdata->mode = CS_MODE_PERF; atomic_inc(csdev->refcnt); } @@ -300,6 +322,8 @@ static int tmc_disable_etf_sink(struct coresight_device *csdev) /* Complain if we (somehow) got out of sync */ WARN_ON_ONCE(drvdata->mode == CS_MODE_DISABLED); tmc_etb_disable_hw(drvdata); + /* Dissociate from monitored process. */ + drvdata->pid = -1; drvdata->mode = CS_MODE_DISABLED; spin_unlock_irqrestore(&drvdata->spinlock, flags); @@ -414,7 +438,7 @@ static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev, u32 *buf_ptr; u64 read_ptr, write_ptr; u32 status; - unsigned long offset, to_read, flags; + unsigned long offset, to_read = 0, flags; struct cs_buffers *buf = sink_config; struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); @@ -426,6 +450,11 @@ static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev, return 0; spin_lock_irqsave(&drvdata->spinlock, flags); + + /* Don't do anything if another tracer is using this sink */ + if (atomic_read(csdev->refcnt) != 1) + goto out; + CS_UNLOCK(drvdata->base); tmc_flush_and_stop(drvdata); @@ -519,6 +548,7 @@ static unsigned long tmc_update_etf_buffer(struct coresight_device *csdev, to_read = buf->nr_pages << PAGE_SHIFT; } CS_LOCK(drvdata->base); +out: spin_unlock_irqrestore(&drvdata->spinlock, flags); return to_read; From patchwork Mon Mar 25 21:56:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870119 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 195261708 for ; Mon, 25 Mar 2019 21:59:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00C6626E16 for ; Mon, 25 Mar 2019 21:59:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E8347284C3; Mon, 25 Mar 2019 21:59:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6C46226E16 for ; Mon, 25 Mar 2019 21:59:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.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=pv8zWJQKoOHpYRTjY7HF6w63gTBgdzk7MI+YfiTEO0I=; b=pxYA9H7vhX2MGHE9YwPUAxf8Cf zsCcTn/NbLIRflCw33569s+rjlqkb+Uyoe/USmJL/MS5O6Dm1ef9w0jJbPj1yywtW3he5lJwKYkuD dLbRGr6HllVvsZnUk5XhgsZzT7dCuBNhND/8KH/1tgoX1IHfsC7eO5fEMuaxnGBRk6Fkk/4bGxc2L 9hL0XYZKc+NLyG/OumFQOCbDnTdLdEwUUTCeB7AtLUJs0CcM/5pImRB4aVzSgLF8mKiRq3iaVCA2M pJrLvuOIOG35mNSBgyvsH4bNCGlUCHLerLii48cixSVLo5hqvlo+yQLyVYiMw6BNnI/30PSWiG8+N 0VKu4vTQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8Xci-0007C9-Mz; Mon, 25 Mar 2019 21:59:16 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XaS-00043G-Tg for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:57:04 +0000 Received: by mail-pg1-x544.google.com with SMTP id r124so7225167pgr.3 for ; Mon, 25 Mar 2019 14:56:56 -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=DXJXs+4knPk/tA7or7zclZmTtg+ioeh357GrnSar9kA=; b=djepXZ6AJNIDtbCLxgLily6ohflcyelSSObFoqvFeYPGTcr/UvHnixruLBLw6BZj0Q /7e4owFROHNufLa3agTFuXrtqdLDqf08xjiBx/xZKycUVRQJoDTU2GjbQo5ez9qzeAsI RXXE/JFWRrxMEd9xbnN6Ss0sztuLcwgKtknL2cI/dtzsaJkuNGwBRE5FOPEB2zG+l2fa /2k9SJGECNc5Q1lWEfROiY/pwYB+lhVPqeheihXcLMRpJxABL2Kf8iKIsWjmDhQlAG0M 9u1J+1mz5+yDBXQRGJCm8eMpryX+LqIRv2Vjs8oPBcgSHdToxXf0mvbwq1GdLlSGhmXs bjXQ== 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=DXJXs+4knPk/tA7or7zclZmTtg+ioeh357GrnSar9kA=; b=pbmpiOA6QZl2HPhwD9pnk73o+Mup6jUfPE3I/oj1BkN+FsXeONDkdEaybHiN+Dr8X+ iKQoHabrHvNF+lwXTc+L2gaXhV4LjlkOAQPtVQRdXcAkjj76NTdmO/qFRQCZ0ZkRz7+T txO8kAYcv9CYS95oXURfOFd89JpijcHlT7gKwmCuNSNaDHVEohNOu2csLHmjjEUZdrhM uT2xC0Br2QmSsfZxW3q532c2PR2hZYGvwU7XLEZr+r7QCZIMUB9bnNKBsK6wxhbtTC1E zNdg0Lb45ffLhQL6W1KD3wte7Vk6u6Kmm7okedDcx/sR23pCERg6k+8IO/6tw5+cre57 +Qcw== X-Gm-Message-State: APjAAAUmbtO8l7iUxLBD2MpRv/KFdp46xmUCBZlI7GGjK/0sDQhE6JuN uMvr//BUH2QIS5/eLmfSt/scbwCOt24= X-Google-Smtp-Source: APXvYqzxDauwRP2coqGxJ0zScXl0rrkdJ1AByjn7L4cPOfUt2UVyV4sI64bG/0IgnJtnhvYkb2qYLw== X-Received: by 2002:a62:5789:: with SMTP id i9mr25604999pfj.75.1553551015199; Mon, 25 Mar 2019 14:56:55 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j20sm30645631pfi.27.2019.03.25.14.56.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:54 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 16/16] coresight: etb10: Add support for CPU-wide trace scenarios Date: Mon, 25 Mar 2019 15:56:32 -0600 Message-Id: <20190325215632.17013-17-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325215632.17013-1-mathieu.poirier@linaro.org> References: <20190325215632.17013-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_145657_711194_ED3062CF X-CRM114-Status: GOOD ( 23.00 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for CPU-wide trace scenarios by making sure that only the sources monitoring the same process have access to a common sink. Because the sink is shared between sources, the first source to use the sink switches it on while the last one does the cleanup. Any attempt to modify the HW is overlooked for as long as more than one source is using a sink. Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight-etb10.c | 43 +++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etb10.c b/drivers/hwtracing/coresight/coresight-etb10.c index 7d64c41cd8ac..a2379c00d635 100644 --- a/drivers/hwtracing/coresight/coresight-etb10.c +++ b/drivers/hwtracing/coresight/coresight-etb10.c @@ -72,6 +72,8 @@ * @miscdev: specifics to handle "/dev/xyz.etb" entry. * @spinlock: only one at a time pls. * @reading: synchronise user space access to etb buffer. + * @pid: Process ID of the process being monitored by the session + * that is using this component. * @buf: area of memory where ETB buffer content gets sent. * @mode: this ETB is being used. * @buffer_depth: size of @buf. @@ -85,6 +87,7 @@ struct etb_drvdata { struct miscdevice miscdev; spinlock_t spinlock; local_t reading; + pid_t pid; u8 *buf; u32 mode; u32 buffer_depth; @@ -177,28 +180,49 @@ static int etb_enable_sysfs(struct coresight_device *csdev) static int etb_enable_perf(struct coresight_device *csdev, void *data) { int ret = 0; + pid_t pid; unsigned long flags; struct etb_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); + struct perf_output_handle *handle = data; spin_lock_irqsave(&drvdata->spinlock, flags); - /* No need to continue if the component is already in use. */ - if (drvdata->mode != CS_MODE_DISABLED) { + /* No need to continue if the component is already in used by sysFS. */ + if (drvdata->mode == CS_MODE_SYSFS) { + ret = -EBUSY; + goto out; + } + + /* Get a handle on the pid of the process to monitor */ + pid = task_pid_nr(handle->event->owner); + + if (drvdata->pid != -1 && drvdata->pid != pid) { ret = -EBUSY; goto out; } + /* + * No HW configuration is needed if the sink is already in + * use for this session. + */ + if (drvdata->pid == pid) { + atomic_inc(csdev->refcnt); + goto out; + } + /* * We don't have an internal state to clean up if we fail to setup * the perf buffer. So we can perform the step before we turn the * ETB on and leave without cleaning up. */ - ret = etb_set_buffer(csdev, (struct perf_output_handle *)data); + ret = etb_set_buffer(csdev, handle); if (ret) goto out; ret = etb_enable_hw(drvdata); if (!ret) { + /* Associate with monitored process. */ + drvdata->pid = pid; drvdata->mode = CS_MODE_PERF; atomic_inc(csdev->refcnt); } @@ -344,6 +368,8 @@ static int etb_disable(struct coresight_device *csdev) /* Complain if we (somehow) got out of sync */ WARN_ON_ONCE(drvdata->mode == CS_MODE_DISABLED); etb_disable_hw(drvdata); + /* Dissociate from monitored process. */ + drvdata->pid = -1; drvdata->mode = CS_MODE_DISABLED; spin_unlock_irqrestore(&drvdata->spinlock, flags); @@ -414,7 +440,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev, const u32 *barrier; u32 read_ptr, write_ptr, capacity; u32 status, read_data; - unsigned long offset, to_read, flags; + unsigned long offset, to_read = 0, flags; struct cs_buffers *buf = sink_config; struct etb_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); @@ -424,6 +450,11 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev, capacity = drvdata->buffer_depth * ETB_FRAME_SIZE_WORDS; spin_lock_irqsave(&drvdata->spinlock, flags); + + /* Don't do anything if another tracer is using this sink */ + if (atomic_read(csdev->refcnt) != 1) + goto out; + __etb_disable_hw(drvdata); CS_UNLOCK(drvdata->base); @@ -534,6 +565,7 @@ static unsigned long etb_update_buffer(struct coresight_device *csdev, } __etb_enable_hw(drvdata); CS_LOCK(drvdata->base); +out: spin_unlock_irqrestore(&drvdata->spinlock, flags); return to_read; @@ -742,6 +774,9 @@ static int etb_probe(struct amba_device *adev, const struct amba_id *id) if (!drvdata->buf) return -ENOMEM; + /* This device is not associated with a session */ + drvdata->pid = -1; + desc.type = CORESIGHT_DEV_TYPE_SINK; desc.subtype.sink_subtype = CORESIGHT_DEV_SUBTYPE_SINK_BUFFER; desc.ops = &etb_cs_ops;