From patchwork Thu Apr 4 03:35: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: 10884801 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 4C2E513B5 for ; Thu, 4 Apr 2019 03:36:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 320BE2847D for ; Thu, 4 Apr 2019 03:36:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 26458289BF; Thu, 4 Apr 2019 03:36:06 +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 D79C12847D for ; Thu, 4 Apr 2019 03:36:05 +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=IS2tXvZjlFgY4z4DDjjrl1QSp0 dR9FdlYOo9jTcJp56xB4bITBipy4WwD2qAqinKlQyGcJk92WbxRNd45IfHIH003aQmvl49XhZauB0 yTDRsq5fHTba3EEvLzhGqRjVCTOpXICtHM7bNvLBjVWXqoUpekpiuH2xYaXVoe+dGX2gBtfB0MSTd ePp0KzwHZR3+edLvtXWSfB9FH4YvW5Org808K/trYwVASAolYgPnhXMz6UObrByDpcnTT9iq/4wzq TD/CvX0Sm8mkZDmbdRN3fSEdtJuNGSALPwGwpuu5l7gj9FXzzpENMkK2a7RPw/5KEF+KxQTECF+wm URiS4pVQ==; 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 1hBtAV-0002og-Ls; Thu, 04 Apr 2019 03:35:59 +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 1hBtAP-0002fx-EU for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:35:55 +0000 Received: by mail-pf1-x444.google.com with SMTP id 10so624779pfo.5 for ; Wed, 03 Apr 2019 20:35: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=pQJCMdAOcoU1qu2khwRxnoxNDPS67R2CoUeniO+PC88=; b=JG7qosCgIljTpyMPcpMLIF001Mci7KhIhDxzZNrpV/i1kcDTXgjJ6kbJSb2Dvemp3n Ga8GciIaVKWkZBJCrEsTGGKZGocGG4jFQirf7ktsTDhKh3FYLyA80Rs4go2DlpEXZpiz RlZmzMcetNrU1fLoBHkNkWsMIBNmljfmvCH3x45TM9DA6sC+/bAV1wSrp+88U28W6TlM c3vWSTPz15/4FTtdoodb6FlC95ap7dVUKQp79ClVhkuJj2eZCtGvKB/6HnLirkJTX1z4 iL1aw6pnDdpmLvbsWmMyD98wNnyKfyVsYgEtVrje+1TPi2y+sVF6RuyD5wVlnJm23Lff acuw== 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=r6kM0/bKNvxRepKzgLVRpgnXgZ8FGKIXPp7TVtyCqXAyDTXk1dIseU71u9LlFJrcHW Boa5YQnqht8s5FBxRgYBhxJkD83dUiPza2F3BLPjoRrljzj3jlCbysrsA4+sHSNpDyQD l2YkhbpfPqsAnF2Y4dOjaDe9/8+KfKvXQQnE4aZlzehlKUnpxyLfPHbuN5g3bIlqTCKd udddC2fnjLy72Nv8JYwfGvtKpBWJdQgpdsWMjrWGFy73PD0s6yxmTyq0F5sktg+xg9GK I2mijdl6SZnqMQs5gCG4dBc2s9rDaCenzT0pxnrasGY0AMW62kJWb4MAlHQ6uiGj652q 3oZQ== X-Gm-Message-State: APjAAAVHtSAzKpV/e92juFVZxCDvUzt77CodWqwZsE7cbgrRFbFyRb61 /6t2REXylQMoMNL8d8ES4SGwm/Abo3s= X-Google-Smtp-Source: APXvYqzz4PAAhINMsK1jx9DPuPk/EwTYR29ySmoa8sYofrQHiMdlGJVpaVV97IsDP9S/Oc6Hcr7GzQ== X-Received: by 2002:a62:458a:: with SMTP id n10mr3321188pfi.136.1554348952475; Wed, 03 Apr 2019 20:35:52 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.35.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:35:51 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 01/20] coresight: pmu: Adding ITRACE property to cs_etm PMU Date: Wed, 3 Apr 2019 21:35:22 -0600 Message-Id: <20190404033541.14072-2-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190403_203553_517978_58FC3F4D X-CRM114-Status: GOOD ( 12.87 ) 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, linux-kernel@vger.kernel.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 Acked-by: Suzuki K Poulose --- 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 Thu Apr 4 03:35: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: 10884803 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 BA9E013B5 for ; Thu, 4 Apr 2019 03:36:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9FE91289BF for ; Thu, 4 Apr 2019 03:36:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9408728992; Thu, 4 Apr 2019 03:36:20 +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 27E99289BF for ; Thu, 4 Apr 2019 03:36:20 +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=i7zDGaOcRQUiJ324GaieSpQM9C stsYtbwjUMhwI7h133lOwLHCHfbC1iIX2yWEv9PmvfRK/Hox6nmCm+mo5zwkElapkRTOXZryJRIuT hXYYAHWB8mY7ZWeda5ASkQzQw/F0VfVfOg2XFhnHiiSVIAcp1U2qb6mBvgsqJZKflb56zB+bwedYj g4d5khY35TBmQnlHYKMrARxjwwn3V2Mr0V/PmjiAtohqgCyh2wIyC7KbGuz8wgfQmQuTkT5oYpf8S zgMJwctpuPpIgSSfOAIp22HNqjdEp1yiVFugIjlbBNRh/LFpUj6rGdXeVooC+BOwpDP+Ih1djInLF Cllj6Tfg==; 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 1hBtAi-00038G-HG; Thu, 04 Apr 2019 03:36:12 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtAT-0002kr-0t for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:36:01 +0000 Received: by mail-pl1-x643.google.com with SMTP id b65so438047plb.6 for ; Wed, 03 Apr 2019 20:35: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=PWODwCYQDDzzbPW6Achm9IFb7pPJ4tsTqEyeFjus50Q=; b=qiT6ObVVNr3Ag9oPswoT6G7Cx8iqiCsE6UmCVZbRHZCc3e7ACYSYOrZGcSaaXvLaUU UMN7QnaPCcDT+FbETiRyczLquxSHirJorI0xwJym4b+c3ZFBEhJHZnH890/fDF7+MG71 9oHnHCO9KlgT4IzJjJjmPTJO3Tm3YJq9DA07FvpOf+nob8IIlOnXt9zUqb52ef3SMNto 9VqxYGbWcujjNzGK+i7D93Z/BFRxRofteY03vvmlZcjNGC4pcOvRUu/iVO6i4tqQXzw1 +gnrIEf2urnZzYvTdPaoDPakZSK9onlqHI4EaKX8DAx9AOzafZlcyf9jYUiyna0+5BaU yBwQ== 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=fe3rd7FWFAXLmp729BlM/ngrUcK9+XHetMYRnC8/DYQbmjivSFlTxCuFzTvz2sq4QA GM4lMAxQhqsx+e3KqhlwfVVUymZ4ru5d7uMy55QCloI0f3GmBSSyfwVofJbfo02wRsgj V5QIehWwqfnmpHLGMnOjeINXV3wqlTkCqEJeZaCQDODL9GrFAMSjYP+HLa2Ehl8x/TWb RI/0cJ+c4kuOl5g9CCFlBh9j0UHfIFODagopxIzjjJjIlNgqiOMm09Q2EpSkoxnwCc3n jbCIX4n8L2jov8M1lhMguo9Xh8+vDcgMgjGx0LUTkoIsFIsSjhq5S2+GCEstXb6sPb+w 51jA== X-Gm-Message-State: APjAAAUwOQ8InfHN6fUQiphGTG2Y1sh9+VBD/27tlLgjOCzjAx4kj7mT OdaObpwSZMKQdHAfhk/ugwHJMXLWek4= X-Google-Smtp-Source: APXvYqwu63lRmEa4h8K/r7hKbNzwwfCPQBfLCYs9bJZdKe0GKL57Vk1TbmGrLBAaJu66rYgA9yuWnQ== X-Received: by 2002:a17:902:4681:: with SMTP id p1mr3884423pld.42.1554348956257; Wed, 03 Apr 2019 20:35:56 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.35.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:35:55 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 02/20] coresight: etm4x: Add kernel configuration for CONTEXTID Date: Wed, 3 Apr 2019 21:35:23 -0600 Message-Id: <20190404033541.14072-3-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190403_203557_415301_EE93BAAB X-CRM114-Status: GOOD ( 15.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, linux-kernel@vger.kernel.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 Thu Apr 4 03:35: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: 10884805 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 8B0DB13B5 for ; Thu, 4 Apr 2019 03:36:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7111E2847D for ; Thu, 4 Apr 2019 03:36:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 65652289BF; Thu, 4 Apr 2019 03:36:28 +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 13CBF2847D for ; Thu, 4 Apr 2019 03:36:28 +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=Og7HA8VRfrlOAzQgktpnoAFpo79BKNqKz2OG39+xFUI=; b=KYQYPWvt5/FgI5vUOkt7JXym9N WNiZzCP8u3PwG3PpJidJcj2bmN2pJXcbVag8I6RaFPMgcD3hI0WV+dPkiF4qdbwW8/LPSSF7zhcww WL3wmv/Nd9uTokDmXSaCvTIohpaWPKFbAS+4vDJUra4dP09J+NINqxKxGRbFrwyHBwPndc6+TzLui rdf6Y5hDDoRZ2P41aFeV/V99tMRScxp3PwzTsfB+fBrxx0vEh3bFCVTN4vN/fkSAZL/T34DCgtOXt 1jkVhl2DylIBIgDAcG1cO2xaL0CCCdljKZgZHK4+1HIdiGUPYJshbELKufMAMrSmrRmDqx1CMuf5x kRH7D8TA==; 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 1hBtAv-0003P2-J6; Thu, 04 Apr 2019 03:36:25 +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 1hBtAX-0002r5-1C for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:36:06 +0000 Received: by mail-pl1-x641.google.com with SMTP id b65so438109plb.6 for ; Wed, 03 Apr 2019 20:36:00 -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=rHFVznWd3K/zryT+Tds7l4sZTdfDnutsgyti8B8Scew=; b=TRzKh2vOPOa2ZvsJuRkYqzZnXGyMeGuX67tGMNah46Ls86ESxy2T98bYlcFr3XX5Pk DKraZC1Md0//SeUaIhNQnCiQN2gQL4PFWNCaADEOZP4LpbFIACrY3Acn17x1LBbF85uw HJ3Cnm5HyTQErLC5YJqMSvvMdallW1tG/HC4NlV/b49PYn5ywYQ+mjNIGNciTAfGPbzn AdAhdAvw0pcWhT2TwZEbx6PnamyEkghvns7tqXOixdD5VKZRFqFwm1QLStM8JKC1ikfB ayyaufqpk1qc4Zwd7fF977eZdwWMGhCjNXb8jVSHrNQps8slJQw0rHTS7BEzsgZGhcQJ NVeA== 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=rHFVznWd3K/zryT+Tds7l4sZTdfDnutsgyti8B8Scew=; b=eRqx+EyxeCjhubeWe4mQOlzS0XLOrJaKcXwQlinG2yBWokI9kegWyHS9gT0MQym+AS QZdL0CuIhnwW65kRjF7nIODwBHgKbo2DuL2HOHJcMr+Z08J1ywtAogIrMPR92NkQwy71 ELxJzitSnzcFvNwTTLmsotiJq6dTmRTJV1gAKTlnMrhnVODxOagyPJuhTcWsKbWjjB82 73zug1yfwnieJGszGyER4yw6VsBjrNbov6QQGrsDfauxH1LJZaLoKfMiUoK94WRdbK3e qCGwMhAePhCNqdu4kiEBf3svQmmEfmz/QNvqvwmlYjzaEEJ0nnj+4pxMGiAnYoC55vN6 fMPQ== X-Gm-Message-State: APjAAAUAKiVaTvQlAbBRHB3mX6z3QmwhLi0i5Ld0qlIlCkSjaEEzjLqe O2D3wDghf39XEvLDzPy1nH7zMwXk9yw= X-Google-Smtp-Source: APXvYqytpomhj0mjfSVM/ijFF454SAG2sPiKLFlp7k9sL+o0fxnfoV1qjz3gARA+mBuLtY969NEIDQ== X-Received: by 2002:a17:902:403:: with SMTP id 3mr3816530ple.48.1554348960246; Wed, 03 Apr 2019 20:36:00 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.35.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:35:59 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 03/20] coresight: etm4x: Skip selector pair 0 Date: Wed, 3 Apr 2019 21:35:24 -0600 Message-Id: <20190404033541.14072-4-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190403_203601_928039_971E8DF9 X-CRM114-Status: GOOD ( 12.34 ) 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, linux-kernel@vger.kernel.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 Resource selector pair 0 is always implemented and reserved. As such it should not be explicitly programmed. Signed-off-by: Mathieu Poirier Reviewed-by: Suzuki K Poulose --- drivers/hwtracing/coresight/coresight-etm4x.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x.c index 732ae12fca9b..d64192c29860 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)); From patchwork Thu Apr 4 03:35: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: 10884807 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 B521A17E1 for ; Thu, 4 Apr 2019 03:36:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 994582847D for ; Thu, 4 Apr 2019 03:36:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8B586289BF; Thu, 4 Apr 2019 03:36:37 +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 103522847D for ; Thu, 4 Apr 2019 03:36:37 +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=FehhLz5f0cCMdz2GH2JYMxl37wCPKqChJHe+qBmPCK0=; b=ijuXa+6kS04gENhRYIB9ZQCwDB BfTjic2yXjSW6KBpFdtT7boOHSLENbidyBbcatcBlpgyHlnqNbKaXLSJhSRzN+/EAiAfhr3EtOCsb SCbU7y9pbTo1BJY7ozgfWhZRM8+93852U8S+o5/fnXL30g9sBM763RWuLFyToHCjEOEKta5p6ysLo WaBvPSUIUQkAmuyXUgHXOE+ORtijUjGdbkfqVc4CK1E3P7XF7RzJ2NHfxKnnXpWLy2RhFSjqMGfEU n5VBkULp2k4s+Wg4vm1Ny7Bmh58ddVv6rNw4pHAs2UyTdTDuNoF8ooWTVgB9vabgi1Exen6ZGb7Pt OC756oOg==; 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 1hBtB5-0003dz-De; Thu, 04 Apr 2019 03:36:35 +0000 Received: from mail-pf1-x441.google.com ([2607:f8b0:4864:20::441]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtAa-0002xd-QI for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:36:15 +0000 Received: by mail-pf1-x441.google.com with SMTP id i17so623521pfo.6 for ; Wed, 03 Apr 2019 20:36:04 -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=ATVaL0BIcRrddkftI6sh9Xp4gw4NfYBuCJEK93HbLeU=; b=rKmCBzs52IVhUtfKRiHeIOvrwSN/b443hb4GxVRQmBQdIEDSczP2Q8i/Z9UqKG63eq f+AkUX1JO8wwwWmjefJYVhXCBvxle2SUKDNug3pAFoidc0zqfArwoVjeoWo1uYvxAvxK s0zLSmMsqbWESGD0qMDHAk3DcIU1epl4Ba+XlTdpTptsCjHKmZ5vpoioQfRkZDjKPG7S RqyRrExG2rD1XB4ysQj495mB9zV2EuopEO0SAEKw2W8CWDu6nuK3HTGZuiqksGR2phNg QbwwJ5lFEZshA2G/fpvnIxrsScEjvxhUkMnnqoZkMngkCsPvcYS6U8eO5b4g2Vrn9cMW nTNw== 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=ATVaL0BIcRrddkftI6sh9Xp4gw4NfYBuCJEK93HbLeU=; b=KV2FMTheImBmmW4dJ6if7x30yiP1N44VZID9VWAmAu/ypoJxp4jteKEGihos2sBX5/ QYTlvrVHLeQNM/fGCFyDujLShC1GgDvN4gAETCOHsW8xmQkaUI+/Dfr+ozvN9ZTVQxhd jXwWv91mnfZX5Q2+kCjNNs7T5wy3RVWDUPlJ6P3m0rKviMlplVSfHUV2Yh70s8QbUbZa LEFTwcEt7fqJ+lftVzGBu0TFuNE0BxSN+++KyCqTpVJRBmip773R3Z2TcUxJ7z8Nj7/3 xQ3Ncy6tuyFp/95wSau3UyNuF1ePG8zqRzIgeS01rWR/80OaUv5jx6e+DNOInzOl12MR m9dQ== X-Gm-Message-State: APjAAAU87Gr3rL+BVVjaAOb4BuRqjM262KRBpnK5JGxfOfyeH7V64QJS 3ECZGMVVjUTM6zgaOdH88TIOg7jw5mY= X-Google-Smtp-Source: APXvYqzN68UBaaXaeIDhdKpX8QN0NoYx34/CT1JjgNLimmnfq7ag2NudengqscJS7/SVhAEwmwrtfQ== X-Received: by 2002:a62:ab14:: with SMTP id p20mr3334379pff.23.1554348964007; Wed, 03 Apr 2019 20:36:04 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:03 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 04/20] coresight: etm4x: Configure tracers to emit timestamps Date: Wed, 3 Apr 2019 21:35:25 -0600 Message-Id: <20190404033541.14072-5-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190403_203605_523237_9FE1E574 X-CRM114-Status: GOOD ( 20.06 ) 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, linux-kernel@vger.kernel.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 | 101 +++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x.c index d64192c29860..46d337fd8442 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x.c +++ b/drivers/hwtracing/coresight/coresight-etm4x.c @@ -204,6 +204,90 @@ 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 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 (ctridx = 0; ctridx < drvdata->nr_cntr; ctridx++) + if (config->cntr_val[ctridx] == 0) + break; + + /* All the counters have been configured already, bail out */ + if (ctridx == drvdata->nr_cntr) { + pr_debug("%s: no available counter found\n", __func__); + ret = -ENOSPC; + goto out; + } + + /* + * 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 (rselector = 2; rselector < drvdata->nr_resource * 2; rselector++) + if (!config->res_ctrl[rselector]) + break; + + if (rselector == drvdata->nr_resource * 2) { + pr_debug("%s: no available resource selector found\n", __func__); + ret = -ENOSPC; + goto out; + } + + /* Remember what counter we used */ + counter = 1 << ctridx; + + /* + * 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; + + val = 0x2 << 16 | /* Group 0b0010 - Counter and sequencers */ + counter << 0; /* Counter to use */ + + config->res_ctrl[rselector] = 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) { @@ -239,9 +323,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 Thu Apr 4 03:35: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: 10884809 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 71AD913B5 for ; Thu, 4 Apr 2019 03:36:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53ADF2847D for ; Thu, 4 Apr 2019 03:36:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45640289BF; Thu, 4 Apr 2019 03:36:51 +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 A31272847D for ; Thu, 4 Apr 2019 03:36:50 +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=1TI28HQ2KGZUcJrOCDouOWQz+fB3q80L052j/J9WeDw=; b=fYxB9CwaZZNfOY8Mb2x88YAzbe X3XCGdmV23ZSvWnjKNPHiWTvyZuJz0oJeHkixXH0JcR1rrKVCoBXFvVTZsCAJBPypenuDIYkP8NdZ MvKIrHAY44n8kQJtTyFMq5ZfX1DiZ/G7wINXtDa5mWO6rKyW0agPNN8R2CC3vfWbt7PG8D90PV5i9 v6mFezr76ANikhLstz7H1dgMDcTiAa637Y9jZz4E9xVsALYiU0SU6gK0X5QBI5oh4W79Rt4yFDYYf sP1ZEydmH3cpHyQTVVy4jNq9uFocHGq3dRFAX6luC3V4rbe41KGKe8VdJmu/oxOb95gWSgP1cqHQX 5oQwTnJg==; 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 1hBtBI-0003sj-SE; Thu, 04 Apr 2019 03:36:48 +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 1hBtAe-00032t-4b for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:36:21 +0000 Received: by mail-pg1-x544.google.com with SMTP id y3so487471pgk.12 for ; Wed, 03 Apr 2019 20:36:08 -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=4hFRGGNdcU8vlM88cfy2RLP9AZ/aEQhsa4FL81XyY5I=; b=l+4n3AuvD3Zu0v6dF/2m4N149idN+ctNj72fR2SVD7pNTleaAJaUaygiNJaovpDO56 gbmCxBWUIv/f1fdbX9kQWtLRrY8oACjxEE3QQXjNl4t2OXQFQTdk/wjvwInK2u3FOGE7 +Rtc5GmC3vrPKZjXudAyzM3TkIF/ACHkEgioIsTt1di/rqKtZt10l+Y0Rs+94LEaigcC xr4zUMBb6XemdhJN6WcRoX4foZEXOt3trTPxSw0MvBK1QLMLKf4pd7oSwg73nO8o454I 8zLe2fkj/9zOcykPMXa8nUmk15u3nyML4Y2plosYmRsYG/xcYoHZiNKXx3/s1aQGK1o8 FSRw== 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=4hFRGGNdcU8vlM88cfy2RLP9AZ/aEQhsa4FL81XyY5I=; b=H2yMUQ2aHpB3WKvUsf/ruyoARRW/MKi2Z8cfuAOCgJkWoe4lEz0Qpl7W0WF4B55III Mf3F45Si0JpklrqwXj2nVtGrDx/rhn/EtcKu7WQVnAYEz5A4plz7cibuPoRWcgsCpesZ PStea2fJhyyC0/KnH4ESY0PzscSfJ4atwGEEzz9isAS7uVggIR/F1Kf1B+9xAVAKmXkw KhbftfPO2w1GgsOfn4Yv72zr6eF1fTuJYdB62bE3TpGN/Urz3a0f/NT3qY7gEtfSIuq1 Qr6Y+i6zFyWiq0v9ZSsj0s6kVEVie+uRF9bLQ8Zw7WZFoLpdmUpxf4xrcyRHBrE9mrew aNsw== X-Gm-Message-State: APjAAAWfF9xJSk8Q9dHdKHEG2CRt5Qjs58pz0FVG0LDOoOUQTpnff6O3 LxPKU6KY6EeRppsymHYvs4A+7B1nCfw= X-Google-Smtp-Source: APXvYqzdQY3/Duw2Bm4S0BKyQUO6JCiHbsm7nMfwqYmrE7+hMLM5kOEB7LYrrbkTg8WRJv4OzAe8gg== X-Received: by 2002:a62:1215:: with SMTP id a21mr3348668pfj.126.1554348967345; Wed, 03 Apr 2019 20:36:07 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:06 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 05/20] coresight: Adding return code to sink::disable() operation Date: Wed, 3 Apr 2019 21:35:26 -0600 Message-Id: <20190404033541.14072-6-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190403_203608_738191_88648764 X-CRM114-Status: GOOD ( 16.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, linux-kernel@vger.kernel.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 Thu Apr 4 03:35: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: 10884811 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 4FB9D13B5 for ; Thu, 4 Apr 2019 03:37:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 344A7289BF for ; Thu, 4 Apr 2019 03:37:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2801528A1D; Thu, 4 Apr 2019 03:37:08 +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 6A1C8289BF for ; Thu, 4 Apr 2019 03:37:07 +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=6LopivCRDJapR1rxZTwFkZUW3xvdboYoiw6ruN1hHHY=; b=YQETH7SzLoNbYutHy0VUM2PLBm V+ojR74Q8ksfhfBZnJWp4d1aJbaKmrncYZYCQ6JnpX2UHUxqvyvf7PrxeWSvE5c7pkuE+E642w60E ssnFnTfI9d7/MmTnUmHgFvkHkLuEZXjqdtb5o2zR6lE6uo7GIieMVUDt2p2gqux2hipGoqQKJRNsw pQggS8ZG9S1kAZrK6PLCZPXggI/F7V8w3MbiB/hTXpGwgnUvJMwWiKuntbiO3rJL1V9TsD8rDoMe+ X1ed6yYgp7hCovG2YDsu/r1ioKwpp99HE/KziqO23Ud9mg+gGuSpGyztUqxwU9+BW5opzi1T7JAtb Ulb/IQjQ==; 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 1hBtBT-00048J-7M; Thu, 04 Apr 2019 03:36:59 +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 1hBtAh-00038R-Pk for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:36:32 +0000 Received: by mail-pl1-x644.google.com with SMTP id t16so451163plo.0 for ; Wed, 03 Apr 2019 20:36:11 -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=3+2cx7RrzPvZOqOGF36avSO6d1PHCsF4iGdLwbSh4LE=; b=ERgmuMK6xtWdmPD77jb17SIuH6rwSvs2w3Qpv8JWfJPgF88AIpxO8MJ0BXlIqZX56j OPzGJ8StKQORS/ASrMXlTBO4x3Ay/5xn36Wc4OQJEsM+TY9597OYieZIAcK0CmgkDSB7 zdVoLUZ4DIhCWE2K/X5nhhjBnFmYRTLDBvUhvRq+H5JZFScBkkt9ho9x9+tv3xw6L94R Lx5H6/EE9QTFPodzqDrE4Hl+C/1z0+Q1JOQR2hfzL8OG6iwclAh2rWW9IZl/7/cyKzDN d3lQE2YI+Gjffha2gtNdm2xAXtH16nfR2nS0iGrKMp4oM3tj6Pk6KoxlJdE8hkJOzODQ FA3Q== 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=3+2cx7RrzPvZOqOGF36avSO6d1PHCsF4iGdLwbSh4LE=; b=Lq+bZG9GYbOCciXwycCb8NzMGfgGbNo67kCugHhmXb4KamBPe41De6Dlm8IqfQ8g7/ kGm+fkDHfXC2jY4+tr6Alkh62B01+rLtVRimMVOzOpJ9eyK5CVTvrMnFVOu/ZPVDrd4q nuiIUuFIhuv1ww+MpeLYEfWBtZzhgCk4zcrTcUmMmMuVCoa2QPX/52OTebSJ5Ue09nU5 NDDoQQXRxBvkaRBb3VaVaLalDD4i0UZc3QgUwUiXu4OCYh8YpZADkBE0amWHSlesZPdG Vr4wudTBKvyC0VRvVmcL8pK01ZQq+rc/Ql5Od32Low4JIsBS5guPm8xd26zZxVak0ZHV IuBQ== X-Gm-Message-State: APjAAAVVcQBPzP1FrSWJTwIpubX9GmLEtqYOLYS+mJhWH6X0843Kvvc9 2GVaNrmGKisXG00yVvJdUaH5q+8MWC4= X-Google-Smtp-Source: APXvYqxJGYSn60DLijBbjVtqgh2z8TRAgV9KHO48zZwUhsyoq0d7oIQBZehENeaN78hF5nJWCwQp5Q== X-Received: by 2002:a17:902:b407:: with SMTP id x7mr3965336plr.288.1554348971027; Wed, 03 Apr 2019 20:36:11 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:10 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 06/20] coresight: Move reference counting inside sink drivers Date: Wed, 3 Apr 2019 21:35:27 -0600 Message-Id: <20190404033541.14072-7-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190403_203612_146423_7882219E X-CRM114-Status: GOOD ( 20.08 ) 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, linux-kernel@vger.kernel.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 Thu Apr 4 03:35: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: 10884813 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 095EE17E1 for ; Thu, 4 Apr 2019 03:37:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E31E928A26 for ; Thu, 4 Apr 2019 03:37:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6CAC28A28; Thu, 4 Apr 2019 03:37: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 6D32E28A27 for ; Thu, 4 Apr 2019 03:37: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=IxcoyieEQkenOC69aVZBX5U2HaGtv/8YQmKevVsd95U=; b=RRDNllm+iO/5ftwbht1OGVWwwI QfIlANovnuwZPto/tbHmPIcCyYgmSwTclRNpd1Llr+vLOf3ofYqVzcrKBtx1ZW132nG1ujtTsVTlB 4pUuf0Z+JaXiEph0XFnHf6JFVNUIolHUNbc0ohEPs87hpMv4lQ7WMFSUgo/cGaNAZnwB6Fma44E7N oJ3tlqbUKal4BJ4kE8RYlPGA0U6LjnKveESO2b6wAdXUepWtcR7+BBNjdf+Nx+QqGbUH0MFkxbQJG HMrtXufcLWqiHBfHq0HowmeJgBeUXUAUxX7VQnaEZVEd/UZ2p8ezy8qIPaeg0Oncibcoiz23MVvbA LBq/xAJg==; 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 1hBtBf-0004MQ-HF; Thu, 04 Apr 2019 03:37:11 +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 1hBtAk-0003D0-PS for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:36:47 +0000 Received: by mail-pl1-x641.google.com with SMTP id w24so446552plp.2 for ; Wed, 03 Apr 2019 20:36:14 -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=SMDcOjybVXwz7wdBlpqH1BT0/eZjjAPZeypnxqWiRKROmfscHf+iNCaY66vQARxiWa Ibc+l3pFlOKq23HYZrXxCIuEshc9ftWes8AK/YNY0pMTHDxnYf2SMZ8gq5Sx+xyEa4Bm CKgYtizPTT0hA2s3kz+4G10zIdcwJOd60JmdXV8gmwW+5z11y3VkzOgwiHFwnJBYfQMu fKIqJx4kn+oNqruuVZ2eBJZ1z94plzBRWK1o2ejb+vePaDcalOirTw5bbQMkSngSRpst YynmPkGCq2hyozQ7WN3Q3pN+GpwzBDamTlGj3q7Z+R62+cCjTJJSqeGy8/2SxiMupkR6 8NFg== 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=fw7qP3QMSTf785G5ZGCKUHnYZ8dneL6iexGnyy2Wa5xpkwOOf00xNx9ZCmTfhHCNDi Sqm3L3hAViSxcpUEfFJ8km9OkfFLtnTebkroeVyPyfqbnse3pYhWcTEw+sWvpzPlriDp JK9k1dDxcBOPB7/cPpPuOzb39dfZ3Y/chJQIyUZhHPG5dg2iIvz1iIyJHwMCg9LKNTb6 /GsuLZfnknT30IfXve7TB/vk/A17Or9zlAeKDqgEgfhb9NFNnM46eGGjtmV24CR2DmlV TSHuEr0mpPIn1yU4kCQJOSzpQIAVe4es5PBFTsXR1DjQe8fx/3ShN75oQjfeAXkAQQL9 qWxQ== X-Gm-Message-State: APjAAAUuasA7Ng8A9mSPyn57CX0IqL4ZjA9jRvwfD4D1haN34gtjQorW NJA997tvtHnZ6fV5AtHl4bJfU0Q/G7o= X-Google-Smtp-Source: APXvYqxdcioGEwtl0wmEqPe48OV/nikIhd55XEe1yLomC6Q9GNFK9nVQi0i5vzJ3NuXkkoZgqBo6LQ== X-Received: by 2002:a17:902:e684:: with SMTP id cn4mr3754075plb.71.1554348974114; Wed, 03 Apr 2019 20:36:14 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:13 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 07/20] coresight: Properly address errors in sink::disable() functions Date: Wed, 3 Apr 2019 21:35:28 -0600 Message-Id: <20190404033541.14072-8-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190403_203615_411746_1A6C1252 X-CRM114-Status: GOOD ( 13.36 ) 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, linux-kernel@vger.kernel.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 Thu Apr 4 03:35: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: 10884857 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 E86CF13B5 for ; Thu, 4 Apr 2019 03:52:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB17428571 for ; Thu, 4 Apr 2019 03:52:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C8EB428A30; Thu, 4 Apr 2019 03:52: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 699BA28762 for ; Thu, 4 Apr 2019 03:52:58 +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=MMgZGd88kOR4QgOHbHoV0aLwPk /NxU8VvwO/h0gD35GmhNvGA5S3HFj3ZdpzsOO4Xl8oYA/4lJU+45cGDUsmPhOZ5aJIV8gfnjlmFiu FkKuQ0fUnFsF7Vl47BzDtj/r/pCg7Ita/IzRUDk5MDM2aE7W3Bn8KoQ1c16pYqoKFBHW6d/6zzWfs 1Lb1cVMiMiP+JXJ6X0ka74oB/fuVE2t777/lKVd1J+IkX248hbr+rJEtimzj/uXs1j7atzZKe1bcW 1OpU9VowO1nZWZJnDbpsFjLzENu/ggDeNs7HJ077KOekaqzQhlfgYgwWmwIPdwFMldKiOEQs5OZms hOQ7SbkQ==; 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 1hBtQq-0003rV-2U; Thu, 04 Apr 2019 03:52:52 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtQ3-0002DC-Ml for linux-arm-kernel@bombadil.infradead.org; Thu, 04 Apr 2019 03:52:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Rp82OG+X/1qzhxgu7Opyhu1qYPCsjQeQJx+i+wMOyCE=; b=XaJdDK7Tu6ZpOTzzCyG58VTvp emt1Hl6U4e9eZL2oCMx7S3mSDG72xKnoC59vmzw4mjRKZy/kOM65WcQpU/rCDmLna/T9sCyHL/POF 8fslCkHb2Gv/7PEWJjO4rOqJZsBhr2gqrjO0QCfEg9bABa+4r7AX9CKi7/jlDb7W5igoVf37ypcUe U9gVEqoEYvpy18tlLo6eCsHxQ4wzS7r9nNxJUAxl6HTzgjI0b4X7VWaK8WpP9w7gOS+dH4hsOXjB5 tdo0UbsRLyrKMf6lXy3GXMpa+nJBvd2blYjFSsV9NtZOWi0SKYNhAs0pS/GqHTzoQOgTzAVPHZtb3 x9gdFiXMg==; Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtAp-0008F2-OB for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:36:21 +0000 Received: by mail-pl1-x644.google.com with SMTP id m10so426182plt.10 for ; Wed, 03 Apr 2019 20:36:19 -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=uWXgpbR5YVsdh1tkDK3c5M04exY7enShlsPHkKIwIqAg0jQLEPod7MxEbk+H/2YFcz ewWG019xQA/Lf3qtj7FErkvgro8gloYUwKTnLt3zJBa0YkZg3/yTQKVP43a5ex9/trTj JBzE92biGwlCxAdYA4Hhd7E085uqcUxOGhHqXVKLUEl4vxT4Z8zQnRPzaTaP2iyonlxt YDL9xYwgQat52IAFAuTHfzAHEVwNW5QgWQSFHN5IkO1BrKu5PwOwmDA5YIz/O6wOhF8V BMusCcGqe0BdXZ24kQU/tmzfO11fxxnV68luRiypOvVdge7qwRy0Q64yE0uTA+KjOMcO L8Hw== 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=IDM0NpoGS4vY88J4tAwj/YoNfMQyKS73knv7i/bQ8Yla8ob61FOp/2maxxAM4//ovL 7zhzPv5qOfwqqveazU39xNlZRExBQHSq2Iz4/+f5E3Kwa/3UlHtwnPeqGrSUtCDrfofn 64uaJTUAaKABHl/WC1OYusab6+GH41FGJKkkwPv+FALtfkc+2q12aszKlFCpvi+dKYtU BmLgqcxBY3h1Xu6H1slm4Ty9jDzo5cShqEpXj5QEa9fdRd6N2sF1VJcinoN+fJ3eHhE2 oh1UItSJSn8T+vyS+0Xc4fyQ2IMNgxXgVVyvz2CFrMapviDz4eHccf4y4KZVGj019gjj zlbA== X-Gm-Message-State: APjAAAU6+CZyon+u9FQcauGRRa3GVp72YVDVI0VBq0RHok/3rXYCW/gC gemYIcNgXRL5fd/NiXUH7exxj2GILjU= X-Google-Smtp-Source: APXvYqxnprVmjjSF2tnUy4v7IbtEfubrPIrN37Y9gmUqDHLVytF4Jl14psXToYqcyqwcjS/j3syzww== X-Received: by 2002:a17:902:5a2:: with SMTP id f31mr3721169plf.119.1554348977964; Wed, 03 Apr 2019 20:36:17 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:17 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 08/20] coresight: Properly address concurrency in sink::update() functions Date: Wed, 3 Apr 2019 21:35:29 -0600 Message-Id: <20190404033541.14072-9-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190404_043619_878088_B92B767C X-CRM114-Status: GOOD ( 13.23 ) 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, linux-kernel@vger.kernel.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 Thu Apr 4 03:35: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: 10884815 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 1410817E1 for ; Thu, 4 Apr 2019 03:37:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED00828A1D for ; Thu, 4 Apr 2019 03:37:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E10142847D; Thu, 4 Apr 2019 03:37:29 +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 8364F28A1D for ; Thu, 4 Apr 2019 03:37:29 +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=tN3yWdXhMcjmgC0S/9XSnVdLIa hREqrGb/OjZj8W/l+YqNsJsAo9zqfzvr5nCUp3ovQ+RSy4N0HqpVR0x+Di+LKVbggb8dW2/LyyGIk 0lp7NyKDd/wa6BfxEgsZyWDqbLWg3x+40U4nZvPNDfRY91inxSCq5tduWoTUMaRBEI1p0ZpMiPg0d 69F1VXytfl9ufE6nWjOUPguNKxIVTOda+yf2XkJm2j3F+zqpT1sbOagaRjxnJA5SWU2OajgAO5zrc WZCLhAOohSEf7tLII024i4fcxvErovp1khvHU+i3/PlxegtvtTYBC9bqnRkhk0CA+PRyN7y7vzGVD aKwwF0+w==; 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 1hBtBo-0004b1-S1; Thu, 04 Apr 2019 03:37:20 +0000 Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtAs-0003Ng-Du for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:36:59 +0000 Received: by mail-pl1-x643.google.com with SMTP id g37so438569plb.5 for ; Wed, 03 Apr 2019 20:36:22 -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=gdec1QIXZeSLFtCBGpLGPuiGmrxIPSimppb5U9XDlVghC5LgWVcBP9Mfa1xbFdUOOa l1phJ6Y5zBrTHa1fsbSTWLx0aEUcvu+5wuDUvJsKjAQpPDubxp7PS5AckgUnZoy8ZdFr b9akJJhz8tIkZZYpFAKr/D1chofAiyvy2oQrMZzAJ/LLLPYi/6Q229+vkpgY55rW/qbg hFRkQ38/Y9VIQHBOanauk/GszRrMZEkZqKroxY37IkekTpk/BuKy2/ypZ5RjlVgtT74e XW2uePefexh0xccalxM9sn8/l2Qyjwidmxlq1V6meE53dP6Y5ghM3LNtY/7HVREco18R g0Fw== 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=eRP2qgmfmVttAcc4JiO4pSJjduw7bM4WehPdUU5ehdyb4O3J1t8+jd3f4F7h6vkkmC 7oiHjyLVXDdJkzvx8/F6iyr1MpCYt0WzordHCcRpSZcOSYJ0is4NHYzLeECM5+enFTy+ jsT24U4w7Lc3EyrKTIaOSJtLvT2WkF2LUsRz3cUNsQDNWVwOrMoX8Fvoj6mx1AZ0LgX/ cc1+f31r5WTonlwDHghXf4x5Ri5/PyI58M4KtUXA5tngzQxfzfl1YZIxRBAc+f5nOX66 m1nKTyH7xm8A58ycgifmvNl1atxqTDKKrVhCyH+Xe005FvnNR6Re+ufLDZDKKaBCA2cz CMpQ== X-Gm-Message-State: APjAAAUo2SxtM6mOd7Trk5d3csx5vWOCyJgJbFV3OZn+x37mJ2oKibAa TpYMRmUBBGvnRdVP71Jd//VVnVNTf74= X-Google-Smtp-Source: APXvYqxO8ppGN6tZd2HsirjKkIj0LBnPgYXjxD+xI+d/d1vo7t+3KzwBxUeYsaMXrG6VS3UeDb09Qg== X-Received: by 2002:a17:902:f01:: with SMTP id 1mr3828458ply.41.1554348981813; Wed, 03 Apr 2019 20:36:21 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:21 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 09/20] coresight: perf: Clean up function etm_setup_aux() Date: Wed, 3 Apr 2019 21:35:30 -0600 Message-Id: <20190404033541.14072-10-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190403_203622_773308_A62F9ACC X-CRM114-Status: GOOD ( 13.47 ) 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, linux-kernel@vger.kernel.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 Thu Apr 4 03:35: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: 10884855 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 CA4A113B5 for ; Thu, 4 Apr 2019 03:52:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF56828A38 for ; Thu, 4 Apr 2019 03:52:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3505286D5; Thu, 4 Apr 2019 03:52: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 3D13E28A46 for ; Thu, 4 Apr 2019 03:52: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=/5sG7Q7ySucuqyy32JoLCGPSCxOEfHdHfeTSigmkMwQ=; b=esimRZOpcW6/qd9S9Y7pb5FnZS 64w0TgKWMe7jjfw6SmzI+UElErs9eYqUef+4KO/ImDAtdDK2B8eTpgzDE5hkt9lXNCi+GWVdP8/k+ uW+4uLTfDp9Ln8/vLEmcSSjMcQH7HPeAxiSeaocPsMw6A7iCPO1zeArBYZhJBNG3KQe8x88U3tnqv UtBC+XnQMcWHd6Lw80mS1/xA1co7GU/wBsxuCqke1rEP/QZ4+iFlIlVk5fQQ0Y2DGYkNc/t5aR3iC DhOx1hRyd8Ed6LD+bmFqZ2hO691ZPtnZaW4GaltMCfvLGl5Tv3hXtdmuQE0q/chVXiRlnupAMvNqM 76ktiFrA==; 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 1hBtQg-0003d2-FO; Thu, 04 Apr 2019 03:52:42 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtQ2-0002DC-Lf for linux-arm-kernel@bombadil.infradead.org; Thu, 04 Apr 2019 03:52:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Dv9y6a52f07gLfeGg5bt9mu9Q1KVd8oRTBa2/L6JdcE=; b=B09H4JgEG8ZOeBiEEl4lQ6a38 EC8vr+GrfRKSbAV2lPuDpFu22sYe4iYD7gkdYmDppS0rgyHokf8ryWu1iVb2Dn65y5SueOLwVUv8w sepEHAu6wozoKShdcgfKsaIK08IlMbsB4sVvbK+oaC3E2D2Kah70+h2exDGVjIjZN9tZJ4yTCUpHJ WH6iwV0+AEKYQn8J5vvPVwlf04+S/4ScGezu7VWVtSfli8m2vz7d+ZW306Rgxaf0KIDhrDuK9oMbx 5UW2Dd0/n+MnHcjLZIb3VGqsEp4WSxPFdg6NpAD5nW4HprmE9wpWoH8Aja7vLg/gF7l4wdlQsjVdK Y3UtotTVQ==; Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtAx-0008GA-Ck for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:36:29 +0000 Received: by mail-pg1-x544.google.com with SMTP id k3so502950pga.6 for ; Wed, 03 Apr 2019 20:36:27 -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=Dv9y6a52f07gLfeGg5bt9mu9Q1KVd8oRTBa2/L6JdcE=; b=nd7rhGJLp6uakVyfCcVqzS4ysrJlCjbe5qVHJ8WFBTutz45kQj0T1EKbTNqXsJ4Xo1 MXdii2+cyi0GnFyuX1/98yRAyZ81XFHh9Cn5e9yNLFJ+FZnJUsIFz1r5MvKX4LDeJLpl NQGj7G0eT5J/HCL/rF3/hj/YNYFac8nBgUNFebnX5wdf86aZjZ6yqabOO1Xeh8CHikcl 1TH+dgxG4SOYPB5wxYiwoJC26THS5CCeXcyqpeM+Vxk1gwZVsmTJlNOENdWtUyHT7w1O 4JL1IUaXgTJgBCvBxLnEAQRBDyVxzYBvlCx0el9OyYb8y7U4Ft5agX32zwYeEgjMSkiY chjQ== 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=Dv9y6a52f07gLfeGg5bt9mu9Q1KVd8oRTBa2/L6JdcE=; b=U/8onU56cC/NpvE5WH/mZj+g2nP28ifcjE8Ucir8wTio9uxWtes1Wluzt6wly/NZNY bAQXM7EnuIY5Anf25C5k91pQ21mCn+j6Kt0vKaulwKfFFMWuiUUCmr1YnFRirHvZXpXp AFPSpXTXZQLekOzcbEfeSqZyIgaQwtMFOOe+ytnxYH+t+Qz6GPTWkGzyN3AuBVoCyAWb Ayg/MM5nLHxDCtu3RQGPzV63+/xcSqTbFvvMrjkGzxn3sB8a0hlCJkzFDK4/lFmZLmFq zxzDpUJn/tSyLVRIh7VeKg6gYsDlATADUVTbXFZIMRH9MajSvMFX/kpai6wwK0SUPpBW 5b/A== X-Gm-Message-State: APjAAAV7IAVgY8IKT5NFH1a/mQvreCdTxVXrXIF0DcG7pH2c4wlw9CV3 39UL/NMX8Way2sPajkDmsHRwsi7z+qg= X-Google-Smtp-Source: APXvYqzpliniiY03EdRi60SI8VpjM7a1uF2J+7xGVpAyWtDwpNjy1DYHC27iE6NYShR6MMn73heX1Q== X-Received: by 2002:a62:e50a:: with SMTP id n10mr3324246pff.55.1554348985691; Wed, 03 Apr 2019 20:36:25 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:24 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 10/20] coresight: perf: Refactor function free_event_data() Date: Wed, 3 Apr 2019 21:35:31 -0600 Message-Id: <20190404033541.14072-11-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190404_043627_505267_4CE336DE X-CRM114-Status: GOOD ( 14.50 ) 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, linux-kernel@vger.kernel.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 Thu Apr 4 03:35: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: 10884913 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 1365D17E1 for ; Thu, 4 Apr 2019 04:31:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB214289BE for ; Thu, 4 Apr 2019 04:31:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DEF1728A14; Thu, 4 Apr 2019 04:31:23 +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 62CB0289BE for ; Thu, 4 Apr 2019 04:31:23 +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=FX9oanzR0j0E4k3vfiEa1ta71S9eB23UXb+Zzxop0QM=; b=UCcWTEuDZ3BSUOgTUue1y+YwZ9 lLAQ9d7sonmhzD/sXKxqSkIeRfAOODcEWMStwo7gtilflC667z4S8qc6lDdEerFxUlk/0h6hA5th/ lOk6ojzlRannMhlST+LIe5+Dm/NM0spfnqo4T6ptD38r2daL6GIhWl9ycIc39PBMwaK5SJrExbIrg 2vsX5O0ElcjFPvSJbmZhzzpn2fuzeE+DWGKxbFDx3D7drqbubW/1RiB8KVYjnQbtfvaXr7KIsCY4m E4MP94E/+GGCJJFGaeSpcUjh9V3sVfvm2Wl7+CrGGKbfmLEhFvkCtVM3aE2nGghlKONQJmX3i7ZJ4 8DgRHH0Q==; 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 1hBu25-0002UV-54; Thu, 04 Apr 2019 04:31:21 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBu1k-00021j-OO for linux-arm-kernel@bombadil.infradead.org; Thu, 04 Apr 2019 04:31:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ednxYZuT+oA8hxh6HD6VGiDDQ3dBG66DPU7JCj5TchU=; b=0X79zpsD7QXnGdnDLdx6zxHna oKknZQ/JWEf+Gyt+heBnCoCDYEolqkCwmYCCesuHBU0Thrz8IxtaTI+keoLJKIXMI5K9og77LW7by IKRzhFLCyxwlOEAf2kz2Gsa2z8Kdk6/bUs2kPVQPwUTIjzJe3qeRcJ5O06DnTGJ/UTR5ILZeCbCL9 hd8E+OU8/3gHMRfFFcZV+UvPYz8DYZv/hNDHY5KQV2HnkYqaoTlU3eLftFv6DpAvgWJrJx+Lx9teR Bg6Rb/rrX+/t9xBoTfviSPGan5V1AeqqFvr6PuCTNtb17gcax+tgEQkyBRKmO2n0/VGrq1l0mZbB5 vFLnaV6Lw==; Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtB4-0007sK-Kx for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:36:35 +0000 Received: by mail-pg1-x541.google.com with SMTP id y3so487854pgk.12 for ; Wed, 03 Apr 2019 20:36:31 -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=ednxYZuT+oA8hxh6HD6VGiDDQ3dBG66DPU7JCj5TchU=; b=CyJzb0UjFCPMfiNKnar/GdUSuGYeNSF22bfv4yi9xlJKYV8z5MahFDaHXDlOExNlcQ EHps+jWEkCsiIAHi0j9u7oKr7KoOqK5YTAqGcmYsxPLU5wk0xzjfhbPlEqpA3avNcdk4 aI4hKBiD0YTTB3hYeKD/KdFV61/HHq7VyRikeOjxfbocQh3jw4bFWCFJWK6FXb9rOO5k 9O/NZYxgEhOCIfYtecRElXvFs2GoFMzq2yGZKoOH2tdi87lJk8FjDf8pEEe2ja8MAGlr RkYJOee6rvZrrkmg3ZIGeVIAgB0ZLGCTmuGGwTQIUkpqw+EkqalUfRptOoohaUS19epF xX4g== 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=ednxYZuT+oA8hxh6HD6VGiDDQ3dBG66DPU7JCj5TchU=; b=hmYbbw4N1pfj/v0XqGWM3Brtih+OIDnP3zXUJtHPEsWDZzcbhITG7yrWI0WghivOvj 3N7B9Ql4PWCt2Lvlh/yl2OMIGMmQChZKHTfAghNlqxGLJsUZ9cv7avkbEh6H89BabWyf 6ZeMXO8AcuXOlcJDNBHxNL7Bny4UllKe7b6QVhDRDO+FvB5WysVrwvSz11u9g2+/7AyL IEtUM+GRG95uPKjks2P0p3yFmf8QarOudP3CbxtO6bJxMA5GOC0Q5/I86AG2JOUyfWG2 NB6BRNFgjeQxyej9JU92WsKgszUgnRfkLDr9M9hdfQjsNAnvOs+p8Ss3fZOuWf6DnxX9 ERvA== X-Gm-Message-State: APjAAAXTOVqEdBsVruwt6W7LZ/oLucVoaA8t31+qalffDs6f7DNAMgXE YtfCN5LQPh2ANY4fap/A0+iMt/qeHb8= X-Google-Smtp-Source: APXvYqyoyTKLxTOxDTtd37DkxWhasV7mEwSIhAhj7OAPpPdRdAYyAll5Gc50PUcZaLo3kZ8kzRKGBA== X-Received: by 2002:a63:5150:: with SMTP id r16mr3247658pgl.307.1554348989515; Wed, 03 Apr 2019 20:36:29 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:28 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 11/20] coresight: Communicate perf event to sink buffer allocation functions Date: Wed, 3 Apr 2019 21:35:32 -0600 Message-Id: <20190404033541.14072-12-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190403_233634_751268_D519C927 X-CRM114-Status: GOOD ( 16.28 ) 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, linux-kernel@vger.kernel.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 --- drivers/hwtracing/coresight/coresight-etb10.c | 7 ++++--- .../hwtracing/coresight/coresight-etm-perf.c | 2 +- .../hwtracing/coresight/coresight-tmc-etf.c | 7 ++++--- .../hwtracing/coresight/coresight-tmc-etr.c | 18 ++++++++++-------- include/linux/coresight.h | 5 +++-- 5 files changed, 22 insertions(+), 17 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..00db6a6ce23f 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1166,13 +1166,18 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev) * 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) +tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, struct perf_event *event, + int nr_pages, void **pages, bool snapshot) { + int node, cpu = event->cpu; struct etr_buf *etr_buf; struct etr_perf_buffer *etr_perf; unsigned long size; + if (cpu == -1) + cpu = smp_processor_id(); + node = cpu_to_node(cpu); + etr_perf = kzalloc_node(sizeof(*etr_perf), GFP_KERNEL, node); if (!etr_perf) return ERR_PTR(-ENOMEM); @@ -1210,16 +1215,13 @@ 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) { struct etr_perf_buffer *etr_perf; struct tmc_drvdata *drvdata = dev_get_drvdata(csdev->dev.parent); - 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, event, nr_pages, pages, snapshot); if (IS_ERR(etr_perf)) { dev_dbg(drvdata->dev, "Unable to allocate ETR buffer\n"); 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 Thu Apr 4 03:35:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10884817 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 CB56613B5 for ; Thu, 4 Apr 2019 03:37:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AEB5C289BF for ; Thu, 4 Apr 2019 03:37:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A340E28A30; Thu, 4 Apr 2019 03:37:36 +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 44DF528A27 for ; Thu, 4 Apr 2019 03:37:36 +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=ISWBjR8flQvgmqMwJ1RGh1A8v+7TC3p6XWhsPKBFNc8=; b=AvQhzrVZmhgjNlEaWvNu6w1HjQ 6L+UivDVVX/+slpxisqRQimr1p0BZQEyB8EXSnqZgfFpV+SeJiekwck4+G8tjZD7Z9t8nLopYPWYe qqKBXsuWxWSlesz5PqdpWq/Ywbw/pLo1toRmB22Ei2K2fnzHeV0TYTuDPwWV+om4Tnp+cs1bLiwXW Nt26UvSjRc5fC4MoEVDAs3MT+i4oaPOsmqW9eESvnOHOXgaUBOV/MRan58oViAxF7HjTWmK6zRsio hCxPPGwPwqgcIoEYyZeF3/TQ0CdLwJbsRWYAT38OJgihFVALNo5gzUihEUlgzpAbkes1QJofhMZqH g5S9qCTw==; 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 1hBtC1-0004qG-L4; Thu, 04 Apr 2019 03:37:33 +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 1hBtB3-0003cJ-Nt for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:37:03 +0000 Received: by mail-pf1-x444.google.com with SMTP id c207so618955pfc.7 for ; Wed, 03 Apr 2019 20:36:33 -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=dOOzJONg42NBLUevdjidfidJoqrClGTmFfG3kUUzoxQ=; b=qXhOlJqPUARfaFRhk52W+mdWfLOuctMZRZL+W/w7PkoTzwJehVfu/CSbnqE7KuHEbG wEqDswYmao+uuJ55P/SNTWJ2q+VHF7M3zbj5UnFBy2rn8iq/LS2lKxzff5g/qcxYZIw3 qdgM5FuaS/DEGzMCy8RiTbrxYmNRZzKx5Jh/QwJ0GUQQoCRa4YBuph91rmXfm3W2FiZY tW09b3cejjCN2nmCbToB8Gfg0i28XiA6P+IbyAUWekRyrMpimXCB92W44kpgi6+kZFES umLywbqC2ssdNYBrLJseCl3SdmPWBGzZmWZnY1ptvETPAi2wGf1xB7Vwzs1EehjWIHi+ en2g== 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=dOOzJONg42NBLUevdjidfidJoqrClGTmFfG3kUUzoxQ=; b=cTXjyVs6FQHq0ARmx0c/xeZEgwmduYpTFlB6mvhdkthiIt0YJZFZDmYR26H2HxvFcP 8vpWnH/GSVM2g41ONxH4140wQJCQ54DA7vQRdMGsnmcE14Ybp3aFHly41sHOj7MqcKVf mXo8eQPCpfvsWbG400r01DXg3oIxk0rQbRwBb1/bYO5SSadJBUqRWroGJr8cZmjhtzFl 6Tthagj2utjqf+Ay7YK8I4Ke3ksSrj9ElenCVV5+20GqMY3jdOhkAXDMv5wZusCufBQR bimyVKOkh0zeGjqARo6vggKoxU67+YwkYtiDfPLxK0Sga3vg38/rewcFdUGJNVCbYlC5 rtog== X-Gm-Message-State: APjAAAULFmbSE/cSeShh0DLyg+dWpEgTENCVtgGf1KI3mh2mbXcTRxPl XyYgtxzEwTiDGCFYF5WafELVte6qLew= X-Google-Smtp-Source: APXvYqzxpJ20zCtqQ3VxnIub/k1QTL0CDHWGDt+viLS9oCnQwvYmGaU5Drsu/DVa+tv4mjL3A3Q0bA== X-Received: by 2002:a63:8143:: with SMTP id t64mr3341387pgd.301.1554348993093; Wed, 03 Apr 2019 20:36:33 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:32 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 12/20] coresight: tmc-etr: Refactor function tmc_etr_setup_perf_buf() Date: Wed, 3 Apr 2019 21:35:33 -0600 Message-Id: <20190404033541.14072-13-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190403_203634_212706_DDCDA570 X-CRM114-Status: GOOD ( 15.15 ) 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, linux-kernel@vger.kernel.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, 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 --- .../hwtracing/coresight/coresight-tmc-etr.c | 39 ++++++++++++++----- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index 00db6a6ce23f..e9c77009188a 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1159,29 +1159,24 @@ static int tmc_enable_etr_sink_sysfs(struct coresight_device *csdev) } /* - * tmc_etr_setup_perf_buf: Allocate ETR buffer for use by perf. + * alloc_etr_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, struct perf_event *event, - int nr_pages, void **pages, bool snapshot) +static struct etr_buf * +alloc_etr_buf(struct tmc_drvdata *drvdata, struct perf_event *event, + int nr_pages, void **pages, bool snapshot) { int node, cpu = event->cpu; struct etr_buf *etr_buf; - struct etr_perf_buffer *etr_perf; unsigned long size; if (cpu == -1) cpu = smp_processor_id(); node = cpu_to_node(cpu); - 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. @@ -1205,6 +1200,32 @@ tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, struct perf_event *event, size /= 2; } while (size >= TMC_ETR_PERF_MIN_BUF_SIZE); + return ERR_PTR(-ENOMEM); + +done: + return etr_buf; +} + +static struct etr_perf_buffer * +tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, struct perf_event *event, + int nr_pages, void **pages, bool snapshot) +{ + int node, cpu = event->cpu; + struct etr_buf *etr_buf; + struct etr_perf_buffer *etr_perf; + + if (cpu == -1) + cpu = smp_processor_id(); + node = cpu_to_node(cpu); + + etr_perf = kzalloc_node(sizeof(*etr_perf), GFP_KERNEL, node); + if (!etr_perf) + return ERR_PTR(-ENOMEM); + + etr_buf = alloc_etr_buf(drvdata, event, nr_pages, pages, snapshot); + if (!IS_ERR(etr_buf)) + goto done; + kfree(etr_perf); return ERR_PTR(-ENOMEM); From patchwork Thu Apr 4 03:35:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10884911 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 24B5617E0 for ; Thu, 4 Apr 2019 04:31:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07D7C289BE for ; Thu, 4 Apr 2019 04:31:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EFBB228A14; Thu, 4 Apr 2019 04:31:11 +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 8D214289BE for ; Thu, 4 Apr 2019 04:31:11 +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=4+EfBY3QqZwb9I4fMJLgq2J2oizMSpcgJZJUb3okPA8=; b=Dz2XMw91GsCAHT5BRpldDBuT9p NkY91+up6fDPVm94zRMMR6wQKwutsPd3YNZPp7Wp+1rQPE+3QPRuuCvjy64xPoVYwfxRAAdGyBRmB 86Vr0LrskvhM0ggt5Vrfpep28zFFSKmtGYfTws1uj8GI4YLUx4InU9kGQjRSKrWPyerjwWklGrBGv qBaZ2d3hGtDaRMQW37x6N5O/8oXQmQw/sk2MCuHtssHqltWwd2jOWdyI7Hd2UaUWGV5VCdUYfQD0Y LLTfWDK90IdMdLz0xVfSQ+33ASOgzKYagt0bwzKPQ1Z3j+/oEhZDj2wDXkxM+0wZ+iy4g0DHvpQwO Dnf5pCuQ==; 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 1hBu1o-00028L-Uc; Thu, 04 Apr 2019 04:31:04 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBu1j-00021j-A9 for linux-arm-kernel@bombadil.infradead.org; Thu, 04 Apr 2019 04:30:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=3HdOcyQCq9wrU1AdvtM6R2lHiYyKElGkieSf9jn2Q7c=; b=IQiEHYQz3HYhDeH2tSzQEaBdS 3XniNYqBc7uRxGLT1An5iSwnef9rcs59ahbmUWNbyxMuXbG0eZH65pHpqeI6vQdI9AzJVMoJH47Ha qkFYvRjYjw0R35CBSKzFyGfpZqbIUZFVrRjf3Jq9jezMwnoaSrzwZrVnQqAjPjZmOSqyD31X0Hxj/ YyRSczkPkoisgCWzxdH6ytMdJL/iSfp1VZhbbfBfUTq2ERPHYPe9VRDxRcYp14VxUt+gb56ssS2pQ wJuNObDoB+wPHm67klk4P2rDFqJg+ky2DyzpFbDk4+pSqq+OH5nHKast5I+/Ro6rg+R8lZ5aPJjV3 9X8H/Lv5A==; Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtB9-0007t5-7P for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:36:40 +0000 Received: by mail-pg1-x543.google.com with SMTP id j26so506561pgl.5 for ; Wed, 03 Apr 2019 20:36:38 -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=3HdOcyQCq9wrU1AdvtM6R2lHiYyKElGkieSf9jn2Q7c=; b=slFc+tqcLXHYhCkIxgtfmG/A+C0SXJdQV/GnM6Oqifk9ED1Eb60jGCl5ehaz7kum9f /zzsI+zMaS64QEk6OeKJbO9qcb/orb7/xJSHlQTFmSoO32iuFd/gtifKgQiWwjEWAw+6 pa6GUmvQyLt3tUY8/QjNRxSLmNSas0E/Vo+nPOcrBRcyZs+DpdNZqr8OqkDEwiGMwzfI Nt1zrt4RMmEeVYi0JspPGlerBrJ5vgpDHQm5WSpokzXHsTwI0k4oGUWbnJmADATo1Rer zBYu9x1qeJzwAjdBEnorMU8S20jXoX2i/GxSjd69q//Voh0psQhboexDaqx5hpCqCiP2 Hfow== 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=3HdOcyQCq9wrU1AdvtM6R2lHiYyKElGkieSf9jn2Q7c=; b=B8Xxz305CSB/jogxRyD36QnikA1ZakinxtW737dxv6NnniuyRZ9ptNJSSyl96P10Pi lkz//gJ2NlbWLM56XDjMW1/VcRXJHsw6cn3qm3desmNMq20EbKRgd2bmb2iORdoKhLEr fWC1csIDA4VJxMkPZ4+FaW2iZzQW075jecFncUIqbhgXYx7lycbCREKoCXpN+ydDQC7O vgu5SqNXIp7b5BzMgMieDlGiznOFQAmZJeSlMYA0oh8T9pa4U+Tq+eE4ijZpZJ3hES7i gbAg/08159kgCBoRR8sk0CPXAFIrSRBTxxTEx6CTADSAjyuO1YuNSpyaYCTG49VoUQVP x4oA== X-Gm-Message-State: APjAAAVVFg7dDIgDt1dFN96ZlwCUxZ8p4DZa8kqZCES+o//jklcauXob tSDnhp51oMg68XjB3HkIOjoAx7QPkxw= X-Google-Smtp-Source: APXvYqx2Oo18Jx3VkscEBB1oKY6eJLnvphpNd1a9HsVS6sx8AtGlR9ieNrAJIWpUZ8BERwuqvHA5lg== X-Received: by 2002:a63:b64:: with SMTP id a36mr3487712pgl.58.1554348996718; Wed, 03 Apr 2019 20:36:36 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:36 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 13/20] coresight: tmc-etr: Create per-thread buffer allocation function Date: Wed, 3 Apr 2019 21:35:34 -0600 Message-Id: <20190404033541.14072-14-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190403_233639_410094_C84BD9A0 X-CRM114-Status: GOOD ( 13.04 ) 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, linux-kernel@vger.kernel.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 Buffer allocation is different when dealing with per-thread and CPU-wide sessions. In preparation to support CPU-wide trace scenarios simplify things by keeping allocation functions for both type separate. Signed-off-by: Mathieu Poirier --- .../hwtracing/coresight/coresight-tmc-etr.c | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index e9c77009188a..ac1efdfc0d07 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1206,6 +1206,33 @@ alloc_etr_buf(struct tmc_drvdata *drvdata, struct perf_event *event, return etr_buf; } +static struct etr_buf * +get_perf_etr_buf_per_thread(struct tmc_drvdata *drvdata, + struct perf_event *event, int nr_pages, + void **pages, bool snapshot) +{ + struct etr_buf *etr_buf; + + /* + * In per-thread mode the etr_buf isn't shared, so just go ahead + * with memory allocation. + */ + etr_buf = alloc_etr_buf(drvdata, event, nr_pages, pages, snapshot); + + return etr_buf; +} + +static struct etr_buf * +get_perf_etr_buf(struct tmc_drvdata *drvdata, struct perf_event *event, + int nr_pages, void **pages, bool snapshot) +{ + if (event->cpu == -1) + return get_perf_etr_buf_per_thread(drvdata, event, nr_pages, + pages, snapshot); + + return ERR_PTR(-ENOENT); +} + static struct etr_perf_buffer * tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, struct perf_event *event, int nr_pages, void **pages, bool snapshot) @@ -1222,7 +1249,7 @@ tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, struct perf_event *event, if (!etr_perf) return ERR_PTR(-ENOMEM); - etr_buf = alloc_etr_buf(drvdata, event, nr_pages, pages, snapshot); + etr_buf = get_perf_etr_buf(drvdata, event, nr_pages, pages, snapshot); if (!IS_ERR(etr_buf)) goto done; From patchwork Thu Apr 4 03:35:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10884909 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 6FF2717E1 for ; Thu, 4 Apr 2019 04:31:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F04A289BE for ; Thu, 4 Apr 2019 04:31:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3DA1F28A14; Thu, 4 Apr 2019 04:31: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 C7816289BE for ; Thu, 4 Apr 2019 04:31:00 +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=jow417SU7GGqPtWS3P0QpFyRUKeOgLbJfpl5hOx/YCA=; b=Wx9eZHueyUAX2IrIdnM9Jz4BbI Go+aXxRoZRVmjIeTVgB0xBAz1igkuDOZFNdJLWV7r5arJaUr0dq4Y4W0PoNenvUsW9rZV9qLIFUoo VybQ59GZSFV2OYCABNqlIKnb/VCVTSoWwIinVBE8m+U8VnYzDUBaqsoJqtPg8cwdymedDj1+QLHKF cvJBMsWtSWOhtz03rT0RwBd8eK+loVgj2QIG7OxfuT+ds5S0yaL8z9AGtqp0BdfbouG/N1tBfaApZ ggyQ2CYGtaq2KGCE2pEGyhyXxeXIRpCfWFNwDaVCUO83pscMTLORUCHpiAd7Eds5UL6vik2iJxd4v qgOOChzg==; 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 1hBu1j-00021q-4k; Thu, 04 Apr 2019 04:30:59 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBu1h-00021j-QV for linux-arm-kernel@bombadil.infradead.org; Thu, 04 Apr 2019 04:30:57 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=SAt54gusO22M7wlCjXKs+Y6DbEbN3JCXkJVbAiVcyrQ=; b=danWHdBavWOqjf29ggj6D6SWf kd4Q1jegCgvdmBkFq3IV4dRj2ZrakaBPYdS/Rkk+0maj7sXaLD+HoZfdlipm5m/Pl4xGuqumN0KaX q1xvbOzO6GiMUI+4XOxevU/syPD30+mlX+94gYxR6z3TDbnIKSPLsX0DsSRr8/sxA/V1z7VDLYkiJ iwntCq9zHI7VLK43LFF+s1zwuhxxFYkuH3mmE1Da36KFHljMtlssFN8ZIESJvpHaCt8jAFLSHFuDi H6Lug0HsSPFboICoQGB7TqxL/hWi4FUSqckh8JHXUDbz9f2bWaJZaMXnZ+8OLLgBUzrAVFKKBj9QY 9KbiI2lIg==; Received: from mail-pg1-x541.google.com ([2607:f8b0:4864:20::541]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtBC-0007to-JZ for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:36:43 +0000 Received: by mail-pg1-x541.google.com with SMTP id u9so498868pgo.7 for ; Wed, 03 Apr 2019 20:36:42 -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=SAt54gusO22M7wlCjXKs+Y6DbEbN3JCXkJVbAiVcyrQ=; b=U6yFsd+67XoVyLCNbk7v3WHsEiS/WHY2Q0QAP3eQw5q4Nj1vDydwghcUdnSXcFKD38 RxggYHts98UHlCL10HksqlqXIe4c+8+z7B0glU+3RBErEWNesyGDn+fa1v78XXxJ2iZ3 dstj56EHjyn/OSD5i0ukwabyuzCQi2FQQpz7D/kll5ppAGZip54/6D6u1Vcj+sqs7oyG uvezNlgJB1C3X0FT1DD4b6LNI3o+ucEOPhJuPPby42/DCou0ei6L0l3IJFe7Suzut1vh wOXiJgQiDrlHVLH/iFfoqYKeEJChV1bygMSWqLaGLOz6IXrUFX1+8ZQ9XhAnus1KHA8P Wglw== 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=SAt54gusO22M7wlCjXKs+Y6DbEbN3JCXkJVbAiVcyrQ=; b=FhFEQJGU8N1HJUf9NpnInwDL+9id/+0wF0yUkuuBQmQWobahKDJPBajULXqsH6I9wS X7lIsvUtxkt0dBV+eN8hC+Kgh3mSTUmRJ3MNXO7e/8PgSH5vFksnoNgSzSJEdWusPS75 zrKhnNNSEh2msCC8/7B3MU3GS+lT1pVhq9dPQdg8NI5kiFuhmi5bBNEb7qJZFfQ4uVxP gcR20ZAPs0LM7PyZVZvSFQYVcDYCsHhXrn2Eu6uJr0NbtmxBywya9NgBeNq/j0duzMyG 7HW2+tidbrBuZ4i5vYuOlNPgK1Ev4USGcYipWV6cvArPHQdt0bFcmeRgGO8ry9mH+Hwy Hf0A== X-Gm-Message-State: APjAAAVpim6Uc9hWXf1FUHTg00kNLq+ahTOQzycyW6joObLDcjfBbdiX 0bvvbwfTuP+BrXPgv6iol1IN9WPiwPQ= X-Google-Smtp-Source: APXvYqyqLPVOgsJdntpitDgkDe8xtxV8hGaTgnlPVyq9j2/fptKaLJIl4ucuD98Wnki638HBqz6BjA== X-Received: by 2002:a62:ab14:: with SMTP id p20mr3336646pff.23.1554349000298; Wed, 03 Apr 2019 20:36:40 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:39 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 14/20] coresight: tmc-etr: Introduce the notion of process ID to ETR devices Date: Wed, 3 Apr 2019 21:35:35 -0600 Message-Id: <20190404033541.14072-15-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190403_233642_897479_9B155222 X-CRM114-Status: GOOD ( 15.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, linux-kernel@vger.kernel.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, introduce the notion of process ID to ETR devices. That way events monitoring the same process can use the same etr_buf, allowing multiple CPUs to use the same sink. Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight-tmc-etr.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index ac1efdfc0d07..e1774d4bb5f3 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" @@ -25,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. @@ -32,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; @@ -1276,6 +1279,7 @@ static void *tmc_alloc_etr_buffer(struct coresight_device *csdev, return NULL; } + etr_perf->pid = task_pid_nr(event->owner); etr_perf->snapshot = snapshot; etr_perf->nr_pages = nr_pages; etr_perf->pages = pages; From patchwork Thu Apr 4 03:35:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10884853 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 D9F5B1575 for ; Thu, 4 Apr 2019 03:52:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B8045286FF for ; Thu, 4 Apr 2019 03:52:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AD27328A41; Thu, 4 Apr 2019 03:52:34 +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 54025286FF for ; Thu, 4 Apr 2019 03:52: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=udO9F0ff7E+gt4K5ZYuBSIedEqv8T6SaAm4I5uzwgUs=; b=eUg9JRpitnw28xNfHCEWA4kdbr w/O+ce0ORevkIJyFJtna87E2CN3FxmmzWubrwLa9uXRsa2G8vj849xrcvdkXMdMJK3d3OCkP+sSDY ORJNOSoSYBHG4PHyTFsTb+0jQ+ZROoRayWhE5buUDVX9qohZZdwI2HlCIsZ6lyHqPSaGB7o3HDSdt o9uNEmk993u4Zqc7qTyNQvusFXz20HQR9tMidibKw3rv+P8GE+41QnPeaUnvAslMplvAtwPO+RcZ6 aqr/jsU0NE1ZCYmwWxZLUCUfLTaDA/MoIOV7mcG3uhw702TY28IBUDPoM1DoNovjIlH0Mrt59NoWh oMg9HJbA==; 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 1hBtQV-0003O6-Rc; Thu, 04 Apr 2019 03:52:31 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtPy-0002DC-Ac for linux-arm-kernel@bombadil.infradead.org; Thu, 04 Apr 2019 03:51:58 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=H9+OTr1OpfrOYtthYPTeqD/UZckEAYj6DoPWjl6ycEY=; b=ixDjjWhm4WcC9GYIcZHh0RZYG Bre+oEffH4PjX8wp+DA5oFgrhLEDUUrjn20sWpIXax8DjXE4+aMmE5M28r0rRvQymK7ORJ7ZXH1J/ uW87WTRs6D3RPgzA5vXvnh0KDF6jT9NGZNjii8D602K5Iqwuc1wijLXklMFaf/zvhpeq2TKiJBx8s uk4yH/gbBST98wpTHiTw5z6Jocz0Tjj+sgdLwOX33MulQ47m0k6/6eIYmYrz3+hsYM8yKqMhbwpLD ZL5O6Qa3+wrpxQahza6CWEC2mGxPlJ/14z/GkzPNSLzPacqRW1f1Xx0NzG8ppiiO6yIY6+0HaR5Cq GZPGZiqOA==; Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtBF-0008JY-F0 for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:36:47 +0000 Received: by mail-pl1-x644.google.com with SMTP id d1so434251plj.8 for ; Wed, 03 Apr 2019 20:36: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=H9+OTr1OpfrOYtthYPTeqD/UZckEAYj6DoPWjl6ycEY=; b=K68wBhJEME7fnO0jZ2eonmNB3GuHTmOF7iCsl8xEsvaPBFjiqFF+5Nx8BZrytnDPl4 3ozNLTYUVmxGm8C7sKWtJhEIGbZhe66ILZqt6EtA7ZjECx29SvjbtRXGGqJ442bA5G1w BwhJWUbLlnX6r0ICNZfbFN2SPI2NnE78gkpzd1kUmAMVCzEynsjygMDbu3t32CV0Yl2H bTtaXq5um59sufHwsYirJ5SP4nC6Nsmgm5IgRzCjRTgVy3dQiF1qWGETfMRMC27MqUmr 2Xfz3DXGVArX2qERcU4h3xJCG9AmO1yGqUOAqw+rkQLkVf7xlMbf2lP2pMlBrUIjk2tK izsQ== 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=H9+OTr1OpfrOYtthYPTeqD/UZckEAYj6DoPWjl6ycEY=; b=fdKmzozk91Aa8tyjyr6s8NJPXSvJblWerFjWtLHjE89bHiwnK2Mp1X542/c+P3AMj6 D8D7ffsnhJtpeIU07pfZWlS+EEdiKph+eogWStLcajVrGKvmDilEjuGM9pGoD0WXj3At rEcgt+ezqgCyyIwpWoUMb9oky8AtZmuEFCh+0Yh4HKisvIuzvVjyMHtBpEJokgdElP94 +gqTclLC/tMI4PwDljWnHCJBIxudKKC1tsB7PBq5YWXh1eThyUdy/KPma7YrxzKG2gNP sFUJ5qg5PH6Iju2FVqUgkcfYnyAysxV3LldR5sBkE5r+bvCeoQezk7gHl54rrikpUoQt 47UA== X-Gm-Message-State: APjAAAUid6zdw9HadSwVW+CTyRKQd43w+06zBtxCzbWYOfT0BiiTzL6o 9d9Z5Eg6f5CI9sV417dB7OdSam1UZRk= X-Google-Smtp-Source: APXvYqw3tJWWYHJETjByD6pMXcwDX2pb9RX8aFl/XUsX9IvhUHKsvCTjv8Wh/Gx8hl45MnhwXmIS4Q== X-Received: by 2002:a17:902:3283:: with SMTP id z3mr3762736plb.236.1554349003815; Wed, 03 Apr 2019 20:36:43 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:43 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 15/20] coresight: tmc-etr: Introduce the notion of reference counting to ETR devices Date: Wed, 3 Apr 2019 21:35:36 -0600 Message-Id: <20190404033541.14072-16-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190404_043645_516114_A261C2B3 X-CRM114-Status: GOOD ( 14.10 ) 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, linux-kernel@vger.kernel.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 reference counting to struct etr_buf so that, in CPU-wide trace scenarios, shared buffers can be disposed of when no longer used. Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight-tmc-etr.c | 5 +++++ drivers/hwtracing/coresight/coresight-tmc.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index e1774d4bb5f3..1346474ac019 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 @@ -1221,7 +1222,11 @@ get_perf_etr_buf_per_thread(struct tmc_drvdata *drvdata, * with memory allocation. */ etr_buf = alloc_etr_buf(drvdata, event, nr_pages, pages, snapshot); + if (IS_ERR(etr_buf)) + goto out; + refcount_set(&etr_buf->refcount, 1); +out: return etr_buf; } diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h index 487c53701e9c..ee44906dffe8 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 Thu Apr 4 03:35:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10884819 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 AEF5313B5 for ; Thu, 4 Apr 2019 03:37:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 937FB28992 for ; Thu, 4 Apr 2019 03:37:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8740E28A1D; Thu, 4 Apr 2019 03:37: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 1FD1728992 for ; Thu, 4 Apr 2019 03:37: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=jGrPHTCHybkqLovItFwOccT5qnrhPJaA/6qv/NLBH+s=; b=nHhu9CgxtWOlPNIth7CIuMnJEG CAWEK2uqBHrWQPYvzfAHuFv1veD3CRqf90bCSOWQap5+TmAhKQBV//ezPDaUmGmINFLmmFeOcJ9lG S4ak7pcTvJHmPb+sdQEj43P0bnvEzwOrsthmzKW7nS8nuH0Ul14E1sWleFKmVqoJEoUzRDGteA5Jm YS758o+yFnKQKAZ+D7EH8CzB8Ryc73hDSFQXgu1jitqYIHNRurG8N5xQP5eM67iM3QKTutYB95A33 Bo9FZ8DhX/jhUae6fErPqkvu2kZMDpfPGHvQ4nSznWu9+FVeWkuPDtzfu8jj2l330jhGZte5bedm/ qe5Hi/Yw==; 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 1hBtCB-00054U-7M; Thu, 04 Apr 2019 03:37:43 +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 1hBtBI-0003vE-5f for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:37:20 +0000 Received: by mail-pf1-x443.google.com with SMTP id i17so624315pfo.6 for ; Wed, 03 Apr 2019 20:36: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=G1pTCL1CVW1J8+zqGHl3aMQK3cea75KFYLLVGa3aTuo=; b=KIHCnaFtf0a36bnPS1J+zRFSumqsRdPPbVoWXwkeL1HXNwKWYsPasnJusJSH03de+g YrYEb2wJ/Xo+H/vWqEJdTjnFc4lejO+cXoI+Ur4SJwyNlqjDUm26N/hW4Lc7A7IRI8XE lHKqxmC/Fw69ZTS80V/oH5wYXxLlRR0MPw/3FbSQ9ivbTy8Z4M8ymHbgmxsEl+IAQ1Si DMF/oFhJMU8DXvkAC6SIB3Or8Rn+q4B0tTvNwmHYpT9Mx2TGfPWV5EUCbVNwyMyoWydI +XOQuiUO6i0q0zajwu3HaZNsiGLbgW9TWBgLUVMYb6u2i8Su233iQdtMSbCoZOVjHzgL hA8g== 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=G1pTCL1CVW1J8+zqGHl3aMQK3cea75KFYLLVGa3aTuo=; b=Qwi5UmsIIPuY+KMtCaCQ69bv0avLhc3L6wr976fItNDA5ZCH/5ueTOLSDtzMU6f3gH Lh9/1R0316OKBjhkYn4gj1dK0uH3ondrL7BzAGNGx28aYnrMblnd4PvB2YEzrSB1QBJ1 EEEzl9eHyorEtQzWXD/XvGdEi2mHFvuuxsxYydcLPUYR1eU5lFw9ylF8stk7hrwVw8iB 5udteBkdywWsQjOedn67oqcj1qHczX3NwLfW53dSUAroijWTYM1WVc3cu1otWKbSBrzs r4cSjPlOAdNVyuzt7VYZGY6+Y7uoWpz9xYU04jkN4mVvRKnJrgtJ8InpLgT3luzcBUhK EEPw== X-Gm-Message-State: APjAAAU21pUdMkjI6nrS0XuHsBsHV6Y32OXCKNwh14yYhAfnyzzbpCYI wDW6w98T+5uXn7hEM4CQJP6esTilckI= X-Google-Smtp-Source: APXvYqzFdxJ3xAwPfEUpTkK2TeH/4oVjymWP8in/V/cF7jFJ/BFx5E59J7JTl/z8GIOprFgiE01Rig== X-Received: by 2002:a63:c204:: with SMTP id b4mr3346998pgd.335.1554349007439; Wed, 03 Apr 2019 20:36:47 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:46 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 16/20] coresight: tmc-etr: Introduce the notion of IDR to ETR devices Date: Wed, 3 Apr 2019 21:35:37 -0600 Message-Id: <20190404033541.14072-17-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190403_203648_761424_EDD8A28E X-CRM114-Status: GOOD ( 13.04 ) 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, linux-kernel@vger.kernel.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 CPU-wide scenarios with an N:1 source/sink topology, sources share the same sink. In order to reuse the same sink for all sources an IDR is needed to archive events that have already been accounted for. Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight-tmc.c | 4 ++++ drivers/hwtracing/coresight/coresight-tmc.h | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-tmc.c b/drivers/hwtracing/coresight/coresight-tmc.c index 2a02da3d630f..71c86cffc021 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.c +++ b/drivers/hwtracing/coresight/coresight-tmc.c @@ -8,10 +8,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -447,6 +449,8 @@ static int tmc_probe(struct amba_device *adev, const struct amba_id *id) coresight_get_uci_data(id)); if (ret) goto out; + idr_init(&drvdata->idr); + mutex_init(&drvdata->idr_mutex); break; case TMC_CONFIG_TYPE_ETF: desc.type = CORESIGHT_DEV_TYPE_LINKSINK; diff --git a/drivers/hwtracing/coresight/coresight-tmc.h b/drivers/hwtracing/coresight/coresight-tmc.h index ee44906dffe8..c1b1700b2df7 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.h +++ b/drivers/hwtracing/coresight/coresight-tmc.h @@ -8,7 +8,9 @@ #define _CORESIGHT_TMC_H #include +#include #include +#include #include #define TMC_RSZ 0x004 @@ -173,6 +175,8 @@ struct etr_buf { * @trigger_cntr: amount of words to store after a trigger. * @etr_caps: Bitmask of capabilities of the TMC ETR, inferred from the * device configuration register (DEVID) + * @idr: Holds etr_bufs allocated for this ETR. + * @idr_mutex: Access serialisation for idr. * @perf_data: PERF buffer for ETR. * @sysfs_data: SYSFS buffer for ETR. */ @@ -194,6 +198,8 @@ struct tmc_drvdata { enum tmc_mem_intf_width memwidth; u32 trigger_cntr; u32 etr_caps; + struct idr idr; + struct mutex idr_mutex; struct etr_buf *sysfs_buf; void *perf_data; }; From patchwork Thu Apr 4 03:35:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10884851 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 589FC1575 for ; Thu, 4 Apr 2019 03:52:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 35A41286D5 for ; Thu, 4 Apr 2019 03:52:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A08828A45; Thu, 4 Apr 2019 03:52:29 +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 85709286D5 for ; Thu, 4 Apr 2019 03:52:28 +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=pjCT24T8aJha/SF5wN6cnNb4iYv1PrT60+iQA+xNYzg=; b=g6qEVVEoChdbvsKOzVWKD7NVDl 44QMvr/o48UF+MYW77v6jaWotfrE97JZpltzE01NzxpVHAg5QbrP8MtohmfyHCMpedHC9bWlNt/jG a6Tow68ItNjpvIbHPcs7dR5ZI3rAaRDG7OxalKiTqe1s0PE0pA3NcJeHzFrb8oUX5KrTsWv51e1oI L+MKW/w0D2PDqPL5wVlSCq8PFlHUqDFQChFshmfnhMGAojt4fpXHJ6FGU0+9KJ5rToCNdv8EbKoDG M87CZSFkWAqAKWf3K/A9pUSdRDAIK9k8UxrnURehYxpa4rxpgGFeKlK77vLGDTXIVGxWJ6Eo1v7y0 IHz6i8Pg==; 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 1hBtQI-00038H-JA; Thu, 04 Apr 2019 03:52:18 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtPw-0002DC-2S for linux-arm-kernel@bombadil.infradead.org; Thu, 04 Apr 2019 03:51:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=kFYUPXqDT+4NKa1uTQaXULpv7Y+YefzCDvbN138zMnI=; b=ETos6PM+xFmMgyWix9FurwfzL 4hg278yNQcd9fXisacycnhF2XE5UNISmkaVZwpXetm84/YN1atRgLsCY4kVh8cKjkgliFazypEUvp lZWQQrSlN6+Uf1i+wW0XGI1h6sF5XSKgopAg6b5RrF7EczAUjpIGQdvg97p5Dxe/Zz9YLJoQzWimx RbJgQDxcwBhjSAKE0lUYRiGVkhiO/lw44+vgwshflKt+GGqH+Bzv/1NQY1PaSnHD66f9HQZyXQBbz B4WtcgfRbhZkEvTIIasw8LeH3CLHfE/PLddQ/0H3uEiSOZ6GR8PQAF+sJz5s7FgzNmV1yVRp5pas1 R81IFma0w==; Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtBN-0008LR-4x for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:36:56 +0000 Received: by mail-pf1-x444.google.com with SMTP id c8so613571pfd.10 for ; Wed, 03 Apr 2019 20:36: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=kFYUPXqDT+4NKa1uTQaXULpv7Y+YefzCDvbN138zMnI=; b=LTWy3uKHie6dKXq48SuUSLDOFWqCbGplQB45KxnD/vCJcF5L/sa/6SJCsJfosIpCPl vKFmCf6HgO8KQKoD1jtzcVSjz7N+SN/Vumg/EhLmnN98dw6WYr3+RXOJrXl5KlF3LOO/ ggUt2/E4oD0dsHEWIQ8WZTik71totE9jL6xSGHHwC+3bR7dOnPQTVaHHz7PcMHHdAzp8 iHehk1++FQ943S5EtIOSoTJKk6P+ZEKkjpaSMak+FOY7m8refm9ZzDNl+7bnuAwwmmK1 YBNM9mtRz+VTcMmRuCg7nFKbz6ofMXDes8uQJykGMOlO1RKxwfW1K62fR75y1GMZEIrv Oo2Q== 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=kFYUPXqDT+4NKa1uTQaXULpv7Y+YefzCDvbN138zMnI=; b=NCo83piVXPLQ3j8WRvE+XxajoZ7IBIEosfdGer/dGJZ7vn3zjo23MKwreQ9+CAPU/K iS4AbsFobuwj4toR5XlP8scsAgC9EEKCNtWy/uGmdKDCk6rGTdeS9GaKmj3MwB0GBB5/ /C2jcdoXwnPnrKugtSuanuzUUG9d345vDXRxWMU64fjzph4c6KcxsehqCvr6oqGIScPe H83Kv7AwXoSYrU+2hi6tsR89+Q+zfksYmjH+NxATLj/5NzsOzWaV2s4wJYvSVE/uG3Kc dyyzPRtJJn1LXcTQzDA3lDRU++A0US8sVR1pINvyx5acdKzs3LYQeVZ+b+T/Rn4SxP/B BepA== X-Gm-Message-State: APjAAAWy1Z5n+o5pFRBbwG6zbqxktrFdb72S4P8op7gqFVEDFQneiLbQ 6vv9l3UqxWQ6e4N3BfwtoiTlkNIGyJ0= X-Google-Smtp-Source: APXvYqxx/cle2EssAtFjyb90I0PMaH5UqnhmroQOmHt53z8YZ32ZmNf5mj3nCTrCe2iY/q7XgHIcjg== X-Received: by 2002:a63:4e57:: with SMTP id o23mr3467140pgl.368.1554349011296; Wed, 03 Apr 2019 20:36:51 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:50 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 17/20] coresight: tmc-etr: Allocate and free ETR memory buffers for CPU-wide scenarios Date: Wed, 3 Apr 2019 21:35:38 -0600 Message-Id: <20190404033541.14072-18-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190404_043653_300621_961484AE X-CRM114-Status: GOOD ( 28.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, linux-kernel@vger.kernel.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 allocate and free ETR memory buffers for CPU-wide scenarios. The implementation is tailored to handle both N:1 and 1:1 source/sink HW topologies. Signed-off-by: Mathieu Poirier --- .../hwtracing/coresight/coresight-tmc-etr.c | 107 +++++++++++++++++- 1 file changed, 104 insertions(+), 3 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-tmc-etr.c b/drivers/hwtracing/coresight/coresight-tmc-etr.c index 1346474ac019..61110ef41d00 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include #include #include @@ -26,6 +28,7 @@ struct etr_flat_buf { /* * etr_perf_buffer - Perf buffer used for ETR + * @drvdata - The ETR drvdaga this buffer has been allocated for. * @etr_buf - Actual buffer used by the ETR * @pid - The PID this etr_perf_buffer belongs to. * @snaphost - Perf session mode @@ -34,6 +37,7 @@ struct etr_flat_buf { * @pages - Array of Pages in the ring buffer. */ struct etr_perf_buffer { + struct tmc_drvdata *drvdata; struct etr_buf *etr_buf; pid_t pid; bool snapshot; @@ -1210,6 +1214,72 @@ alloc_etr_buf(struct tmc_drvdata *drvdata, struct perf_event *event, return etr_buf; } +static struct etr_buf * +get_perf_etr_buf_cpu_wide(struct tmc_drvdata *drvdata, + struct perf_event *event, int nr_pages, + void **pages, bool snapshot) +{ + int ret; + pid_t pid = task_pid_nr(event->owner); + struct etr_buf *etr_buf; + +retry: + /* + * An etr_perf_buffer is associated with an event and holds a reference + * to the AUX ring buffer that was created for that event. In CPU-wide + * N:1 mode multiple events (one per CPU), each with its own AUX ring + * buffer, share a sink. As such an etr_perf_buffer is created for each + * event but a single etr_buf associated with the ETR is shared between + * them. The last event in a trace session will copy the content of the + * etr_buf to its AUX ring buffer. Ring buffer associated to other + * events are simply not used an freed as events are destoyed. We still + * need to allocate a ring buffer for each event since we don't know + * which event will be last. + */ + + /* + * The first thing to do here is check if an etr_buf has already been + * allocated for this session. If so it is shared with this event, + * otherwise it is created. + */ + mutex_lock(&drvdata->idr_mutex); + etr_buf = idr_find(&drvdata->idr, pid); + if (etr_buf) { + refcount_inc(&etr_buf->refcount); + mutex_unlock(&drvdata->idr_mutex); + return etr_buf; + } + + /* If we made it here no buffer has been allocated, do so now. */ + mutex_unlock(&drvdata->idr_mutex); + + etr_buf = alloc_etr_buf(drvdata, event, nr_pages, pages, snapshot); + 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(&drvdata->idr_mutex); + ret = idr_alloc(&drvdata->idr, etr_buf, pid, pid + 1, GFP_KERNEL); + mutex_unlock(&drvdata->idr_mutex); + + /* Another event with 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; +} + static struct etr_buf * get_perf_etr_buf_per_thread(struct tmc_drvdata *drvdata, struct perf_event *event, int nr_pages, @@ -1238,7 +1308,8 @@ get_perf_etr_buf(struct tmc_drvdata *drvdata, struct perf_event *event, return get_perf_etr_buf_per_thread(drvdata, event, nr_pages, pages, snapshot); - return ERR_PTR(-ENOENT); + return get_perf_etr_buf_cpu_wide(drvdata, event, nr_pages, + pages, snapshot); } static struct etr_perf_buffer * @@ -1265,7 +1336,13 @@ tmc_etr_setup_perf_buf(struct tmc_drvdata *drvdata, struct perf_event *event, return ERR_PTR(-ENOMEM); done: + /* + * Keep a reference to the ETR this buffer has been allocated for + * in order to have access to the IDR in tmc_free_etr_buffer(). + */ + etr_perf->drvdata = drvdata; etr_perf->etr_buf = etr_buf; + return etr_perf; } @@ -1295,9 +1372,33 @@ 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 tmc_drvdata *drvdata = etr_perf->drvdata; + struct etr_buf *buf, *etr_buf = etr_perf->etr_buf; + + if (!etr_buf) + goto free_etr_perf_buffer; + + mutex_lock(&drvdata->idr_mutex); + /* 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(&drvdata->idr_mutex); + goto free_etr_perf_buffer; + } + + /* We are the last one, remove from the IDR and free the buffer. */ + buf = idr_remove(&drvdata->idr, etr_perf->pid); + mutex_unlock(&drvdata->idr_mutex); + + /* + * 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 (buf && 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 Thu Apr 4 03:35:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10884847 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 9C09C1575 for ; Thu, 4 Apr 2019 03:52:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FFAA28A3C for ; Thu, 4 Apr 2019 03:52:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7370A28A29; Thu, 4 Apr 2019 03:52:11 +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 E490F28A39 for ; Thu, 4 Apr 2019 03:52:10 +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=oZpGzbY9KpZ4BRtK8grkMOs1JkbbcGZb/5TJJgaiSCA=; b=msQHyRjDsTm83rciPU3V9F3Plc TBoJpN3anbZeLgr1TVncNSlMF/9MeieRZAURlMReILcQKmP2uR0zB6UybUFzVVZPX+G7bWgGB/SrK INaI8DUE66az2X2QawvRikhvT0nhC3j3uxltXep7CjE88TQP258BbX1OWpuqm5yT+oNqBps4MOQ/l gnkL6p6TDDyECiK1uyx4HdpTeHszSw9DanY7pFl5+8/kSyLKc6ETHX4vY2U+WBSBu0kjLVj1S2BI/ n/UvULUV2m7yNBpvFu7lXlyThvW8RWeeCJlPsxffaq2sMPsmA/fnTNrI4z+88EHyXNqdXUoAq/gGR ASpzTh+Q==; 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 1hBtQ3-0002mx-Pi; Thu, 04 Apr 2019 03:52:03 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtPu-0002HG-Q4 for linux-arm-kernel@bombadil.infradead.org; Thu, 04 Apr 2019 03:51:54 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=LudRC9TQK4HNLvQvknqLAVG3xxx86t5omiW1jcpQn7M=; b=t0HW4099PbGr9TVgYU0HJywyw Az5foYhdXQvu+4de+Pu7KK7yBVz1oAGZvIV9uUFInwHogojou5QUCadnHjLQ+hiCytpqDw7eUBupk GjXIv8G7/vkH3p7Zw0btfSQ+QDPLtj9RpvC0NK5fimSK/DB9TOTpFeCGg8CGRwfdInCs3vWfz/cN5 fT46vKZTiPKs3bPYazti/z0ptyYv4QmTk0sstqRJvdt4R7Nwu5EZeY8VG0yxOlgaQHyyX9I7Wmll+ 4BAxxUYf3M14sXsnw82m9eOi8xRrZIyhvYvCepfP/aNAOH5qitWNushtGrO9Yuh5sUvcyLn3ksO8h Brvgr/h4w==; Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtBQ-0008ME-L8 for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:36:58 +0000 Received: by mail-pf1-x443.google.com with SMTP id i19so637849pfd.0 for ; Wed, 03 Apr 2019 20:36: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=LudRC9TQK4HNLvQvknqLAVG3xxx86t5omiW1jcpQn7M=; b=p5ap4ibaWa2YMJgeLjUNn2YMG/1OP1OdJICTAiBIXN8oy4cPKJ51Jd9kOgaA4wY3/x pp3Du9fIrKogx0dYSHz5wkHkBeWvIOYrNJ54wwWHiCwo2AnCRQjvV5L/oKWlTrL6M06e sxquML1M0yOl5NfRz5fQN0Vn6538pwN+786rBqo2JJfOmVE5vnbYdWrvPE7CEvmdFtQE Y3iyYDLa+rQV5dsqGUtO+VzodR7R6CZVjq+sIlhfMLNwv1HzYaFmkH5KS4WvPROLmDGV IowW/KPSopknMq0CmQGY1mEsq5R+0/V2HD/eFxOSPS/dJWA6bWk/d94S+RwISxwbZp+E yJwg== 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=LudRC9TQK4HNLvQvknqLAVG3xxx86t5omiW1jcpQn7M=; b=MgLRLfkD7MWawGDL+fuxtgLbf/Z05Bgy52kaSODx3oKQkHXXA8QRpgRK5wKabHDIQ9 aUBs76rEuCwPD5zHTbx5m1Tm3chDHrOYYGwbyIXHEOFch5XpXQbY7CXHaJbwY6n98gDv sw4Tiwx+xOSZeSXOt+6T8Sc/6AJjA5QHAqd5MriSjbfT2HlBcf4Y1sugNuN8U7vd1F5z 7hK4ioPfp0hdfP4LXiYZYr2L3/HbJTggHCwnt1yUzo6ea4kXk2HV2PaZ1AhqQ/vIIb7b FJdAUl6X+XLur9/MesJnhYG6Kqoqgd0Sh4tkVqq+n323X4A1q0LbKNqD11Tyebaard8W aqsw== X-Gm-Message-State: APjAAAUXDC1jxdMEEZCn0EU3fOFRBjgGMwP9gtxTKywsxkJgVdLHdO10 538zIYKKPkvhL2OGcDrkbOs7MK7n5iY= X-Google-Smtp-Source: APXvYqyWtaDRUkI7E51SZkIw6nNMwUGRIn9GPjmjSfHKhkdgoSLfqdmkYEa/D81ozG+zhNjzgSH0qA== X-Received: by 2002:a65:47c6:: with SMTP id f6mr3400010pgs.173.1554349014940; Wed, 03 Apr 2019 20:36:54 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:54 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 18/20] coresight: tmc-etr: Add support for CPU-wide trace scenarios Date: Wed, 3 Apr 2019 21:35:39 -0600 Message-Id: <20190404033541.14072-19-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190404_043656_725354_0E3647E8 X-CRM114-Status: GOOD ( 27.83 ) 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, linux-kernel@vger.kernel.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 61110ef41d00..a91c1bc17e2d 100644 --- a/drivers/hwtracing/coresight/coresight-tmc-etr.c +++ b/drivers/hwtracing/coresight/coresight-tmc-etr.c @@ -1473,6 +1473,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); @@ -1512,17 +1519,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; } @@ -1532,10 +1537,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); } @@ -1579,6 +1605,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 71c86cffc021..fd8267fd8e6b 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.c +++ b/drivers/hwtracing/coresight/coresight-tmc.c @@ -417,6 +417,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 c1b1700b2df7..503f1b3a3741 100644 --- a/drivers/hwtracing/coresight/coresight-tmc.h +++ b/drivers/hwtracing/coresight/coresight-tmc.h @@ -165,6 +165,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. @@ -186,6 +188,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 Thu Apr 4 03:35:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10884827 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 8688C1800 for ; Thu, 4 Apr 2019 03:37:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B28628A1D for ; Thu, 4 Apr 2019 03:37:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F55F28A33; Thu, 4 Apr 2019 03:37: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 E3EB828A38 for ; Thu, 4 Apr 2019 03:37: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=2n64817kBFRLbBs7h6JjR4bFTcbm3o2/p+rWVZRKBuM=; b=Fi9Eg/dzApO0Mpr22l+xkmIScb BftagbCxX4bXWi3Dn0QAq76/3jVdlfgBBNoA5eRppO+BEtm8tbr26DaqPcdOoFSD89ayG3rA8At1s yFJaKWmH1IqmH2fU3SuXkf0Miq4l8Ucb9NAVpX50qqFfqw30DBJ122Z2l9OAGgeDERhwIC904jzxb eYmnVI8LRcoTv96b0tUEjd46OeHiyZX/WYoqiz8rfLq6JBeNZXrdTtEr372aMDpA65dH77LaX/XbS LNt/o+d4FQYXxc7mw8GehyJ1iZ+fHHEDlDTRCYWgYVNdE41upsSenxl8n/yUdfTIkzXhJWq6cqvnI miO9qtqQ==; 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 1hBtCN-0005JE-PG; Thu, 04 Apr 2019 03:37:55 +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 1hBtBT-00049H-56 for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:37:28 +0000 Received: by mail-pl1-x644.google.com with SMTP id g12so426841pll.11 for ; Wed, 03 Apr 2019 20:36:59 -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=me0reGUHzjAiArUnM1m+8nwEBbmaHHIkK5QeHwjSxqEanx5sievn47DGQJOzluk7Yz K/wE+zAXLVZX25JzVwlb8I5DF7VoNep4JqOUhiEF6tKVxTglGMTWSx/2kOtKMRZGWWtU rWrGYYloH9wHtFC95pVDFDURHy5sWe5YpMK8noldYig6bHLwrX28/gnwoCfxbTPWKZrV wvLOpaiEh2v2HCbgfAr3HILmumCUA+Ur6oXsqnZO+uqgtmQBQ9+rFGJkjfHkdk6fJUoF LbkT9VmGoSqTCA7EQzoUYilV+6+7HCrBzOEMvWLp0f/vqap4uXJOqY7/b1erSZv/7/jN VgsQ== 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=JNTNer9aG1F6SB4+D/iIIi9lUcqK+PzNXT47GKO7rBYbkMYh0WHCOb62rnSWbmnqDk dvtkJrDoAHkN8ffOh/1K85vWlVKQ/jMgyzsOzSuyodX1Vl7hTvKCSXjRQTpRW3Ksiriv PKcr2Cu7YGB+bVTDMSJduL5VUBKBpbhWwMbTiLp+0jJaHKrlALswZhGUE1ELr/+JkcVH kmfo5xEaYMh6tJZihM5J+1kQztaZqFgXqwFuKEJrxF79GeI8dtPx+i+DIs8q2WRBIrsk 0mNiY0YxaAyIHjHsS2+0wGyHiUKoKSE9HjQAi+4yxrwCeaDmcBWi9A325PByYDyVKFC3 lU1w== X-Gm-Message-State: APjAAAUotvlfu2WnCKuMyLifSJzMR7sgrPSyBfMSe5aSIJRfE40KePPQ CV0bn4IGl7fxZhb5+SzYdeCiLoZRVq8= X-Google-Smtp-Source: APXvYqyK4MW2ELDtAddGQj/FriWe6wE+DJubczgxcSwbaMAob3whBlTlbA1CQ+CxPP+qJ7oQEL41dA== X-Received: by 2002:a17:902:7c8c:: with SMTP id y12mr3808185pll.209.1554349018449; Wed, 03 Apr 2019 20:36:58 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:36:57 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 19/20] coresight: tmc-etf: Add support for CPU-wide trace scenarios Date: Wed, 3 Apr 2019 21:35:40 -0600 Message-Id: <20190404033541.14072-20-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190403_203659_512137_90A98139 X-CRM114-Status: GOOD ( 20.32 ) 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, linux-kernel@vger.kernel.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 Thu Apr 4 03:35:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10884845 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 134CD1575 for ; Thu, 4 Apr 2019 03:51:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ECB1828A44 for ; Thu, 4 Apr 2019 03:51:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E0B3328A45; Thu, 4 Apr 2019 03:51:56 +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 5EB6528A46 for ; Thu, 4 Apr 2019 03:51:56 +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=Y7WllKN4asoScI/7NFkEJcxC2d QouQGZu8DhE+AyWkDv/5RFLLCsrYIIkOdUYLZe9JlgwiPTYYfghtx8tBv/TEtVBR8zsxXXUmTN9ER kI2urxoaf4jYZ1iZ1EdjLxOdV3qATTqRxQy3Q6iXGjum/bp6anZoNB+CyGOf+HohguV1RbEIlpqOC OZVuGz7GE6fWVIL2PEeYd5Jgc7o35ovdzZTmgD36usadYpRpBg2Q+GU9GsJ17hZDv29urTkBMwS1U PsNt5E+9kLoAc2XX44j75KQyGB9nmRPQzCLFvCk/OqnV+Fg76stm1RxEWyj7T7lC2xJuc5tH8YbCf XTMHc3UA==; 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 1hBtPv-0002aq-Gb; Thu, 04 Apr 2019 03:51:55 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtPt-0002HG-KP for linux-arm-kernel@bombadil.infradead.org; Thu, 04 Apr 2019 03:51:53 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=DXJXs+4knPk/tA7or7zclZmTtg+ioeh357GrnSar9kA=; b=t7lTjWt301sXxjjueiDwdMjO/ LfZS/t/YVonjyfIjUHK3Zero3B4gRU6eWbDtv3Ye4EnyGp2hnYSI5W3WpFbtPR2uve4HXwqSR/c5c qKlLdMJzGMOvVRuWbrqK2WvNNU1Y/95+tKXO9ASNzdu/6b2gNscvtIaSmIqn21cSx0QBj+Pgd/TeH ATuYs+lEUb+U+H6aAqfHYeNLStgBpMIEDdlxNxIlkYL04Lc0x2SVDtO5Adonc1R0o5a0zTyFe0sFT XRUhbtj/1peVw8J0cH4yA29W5Bag34Q4TTrV+hh5asV0suBw6UrY8LdMoXDTM/zMM+og3sD5J504B QyqeoHDkw==; Received: from mail-pl1-x643.google.com ([2607:f8b0:4864:20::643]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBtBY-0008Na-0s for linux-arm-kernel@lists.infradead.org; Thu, 04 Apr 2019 03:37:06 +0000 Received: by mail-pl1-x643.google.com with SMTP id w23so441879ply.4 for ; Wed, 03 Apr 2019 20:37:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=DXJXs+4knPk/tA7or7zclZmTtg+ioeh357GrnSar9kA=; b=Ue49eOPxZ/b1NIUrbk6DsAPnbtiZDLB+YR+tD0AKaa/fHQhyekBCugfgGTfQML9J8e MQvFErB7hxKiVViwohCnahFYv8cpLq9Lz4ID9etGYngPzS0j8uPnWnd1HHIDcUM0LIL4 /J/Lcrl1xQ1SgJGqLRlPyiIShR6WlvTD+GTfO3Jhj17F7C7dE5uR/bNv1nr/dA57RRuJ C2w80m9Wi18ElVMtAc6zFUi0+dOg36L0BIt8KueCIMwydRYuqAk70YhtlJrniZ2HANfa qD77URjCiBDYx0o+HpE+jzUk/Vq/SqOgFEb/RhQAwOTo33qo1Sxy62jDoy1cCqQg/LHd 3Jyg== 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=ZtwvqDJ7eyfeKahxHKaBlilfLVgdveli4h0tvUeyidI28NnZjln3cdaOHDCKgmgp7N gKECK+NTRtyOlk05C6/FvKQqXvmQI9+0TUnVsMo9CHucQsr7GddME57KGOer3VAm1+93 rCQmTIKsrLzFyAVTjYND4Pmu0e9bI3MFjCEjZ4HhQV/PO4PFIeUWd696pHrBtgoZ7t16 kdu55v2w8OOhBNpSHETqQb5RCJ9OnsBAhF/1Cy6QLGzxlrrcZzs2SMcxMAur+PeRYWok WLqT2oZd6VXd6V43J7Qb91HRbx1feYPb9IppIBsk6GdsnWFTTtkNq2lyx682TtY22Y7z CPVg== X-Gm-Message-State: APjAAAWOMGMVp1efUoqJDiiPdqprMiEjTdVq/mS88b8W3AprT+O3pWAx yVxsDPojymRnQqIADcG/WzuV7aP/xXw= X-Google-Smtp-Source: APXvYqzSpjfKRSscdhjHCkli33DQ/OnEBY5jyMnQH+ksUW76Ae0Ylq+FgyIgcfygVuFDRBkiWaZGSw== X-Received: by 2002:a17:902:be04:: with SMTP id r4mr3949596pls.218.1554349022282; Wed, 03 Apr 2019 20:37:02 -0700 (PDT) Received: from xps15.imgcgcw.net ([147.50.13.10]) by smtp.gmail.com with ESMTPSA id u5sm12212780pfm.121.2019.04.03.20.36.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 03 Apr 2019 20:37:01 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 20/20] coresight: etb10: Add support for CPU-wide trace scenarios Date: Wed, 3 Apr 2019 21:35:41 -0600 Message-Id: <20190404033541.14072-21-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190404033541.14072-1-mathieu.poirier@linaro.org> References: <20190404033541.14072-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190404_043704_087666_2197D480 X-CRM114-Status: GOOD ( 28.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, linux-kernel@vger.kernel.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;