From patchwork Mon Mar 25 21:56:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 10870091 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D5521708 for ; Mon, 25 Mar 2019 21:57:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 63A3C28B59 for ; Mon, 25 Mar 2019 21:57:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5726C29131; Mon, 25 Mar 2019 21:57:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 95BFA290E9 for ; Mon, 25 Mar 2019 21:57:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=TpUq7E9OneP9beDm4MzuX9AoOlg1Z5WZlaomFbZLiDk=; b=Fxy491l9BStnfpYL3FJf+3TEXx XtJL35n2OA7NBkHN/o2c2WRUafh54kha/J7Bp9rVtDcw1aTA7y7ejwp3VwJ6wnDYAD4saRNLPWlIN 0pkiOsBdOruUTF90w8pwoUrMONH6bmEUvuJhEWHKH4+4MWPA4RkMAJ2G5KEthC6Prz5RBY1oC6TBK /BMSU6fRJJOvisIrJIKHsgpNLKbLqRPVBgCgNI9HttvCpyNhHxiQvKHMpna9+LEUZV4rfpdaePmoo 1SeDt5X5nHBat4o+nGxNBVQTRRiK5eDITZV+p4YSbBfiDj0Gc2SQ830EO3sIs4xqXVoDieBH5AgwN uMQYo1OQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8Xar-0004Rq-8T; Mon, 25 Mar 2019 21:57:21 +0000 Received: from mail-pf1-x443.google.com ([2607:f8b0:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h8XaC-0003lZ-HT for linux-arm-kernel@lists.infradead.org; Mon, 25 Mar 2019 21:56:43 +0000 Received: by mail-pf1-x443.google.com with SMTP id c207so7069543pfc.7 for ; Mon, 25 Mar 2019 14:56:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ypl0AhdKIPMYgGvzoEnU/FMcPAGeVg+HOBF000CHgJk=; b=qnWQgRazqrIVslmIsg9QiEhebVfNnImqqxYfL8VoX5/hMeFSjfbRyaxq9t95eqf0Y2 5pi9B0wDlrABMC8YduI85dzugExUq7wpFRFnLVM64Z+wltckywgoo1gujyDjJInaL4ej M9cgCtJWDKIV2p6DvVhVsExX24IV5c5ImmBAiXvSzuR+uENwatMwi4pRA92zUnKnXv56 xRk4MCiFh04VWQwJanykttuiUmev41oWjoIr03fc1T1GciahqkFi8W+aWnGdDFAWmmRs IvUZKrlCJiWNzAH77kEGQThOEYpFueW89eC/sTJ5VLb/OOw4OyK0DMoZqZK8b/QJuFpv hAMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ypl0AhdKIPMYgGvzoEnU/FMcPAGeVg+HOBF000CHgJk=; b=RHPISRjCZV+qfuPI4MIWlDmr+EOH+vnoEO2dOu/HSUINNToiZsQZ53doilaCl67Ruh oVaxCjVjCFcAqcMM+Kr17l49tlDSerqPDbAQH/eTkfwCWQgZ7dlUGiqYwuK7pxD2ODOs N5qSsGptPmdm++VPa62FggJFaIfH+j9mZq7AiWLpdmD9bP5emd++3WncOtF6wr+R5kkx iodP8mCoC90hbwoI6FDa5Oa1cDTmph1KdJ2wqwihonlikpxKUq2UlzHlPpNp+ftMQHAP nbkwpidOi0vNfRisGBMcoApbIhVTZszLedWxqnGnJoN38QVc1J3oEcfZP8mWzEkIfLUK VNCA== X-Gm-Message-State: APjAAAXOECUCaztRFmOcLTc29yWiEbJl8onxYvWRfcQklKYTrrj7TuIN nHoxNBZPLAZ9xKdulxHvw1rLnu1P/Aw= X-Google-Smtp-Source: APXvYqwW8ZxJDhDY5aCuQsog1k376RbT81zxTPVSkIJbI1GtsXGWmkMe1mu40rVxGCqj8XzGOTCWMg== X-Received: by 2002:a62:305:: with SMTP id 5mr4746182pfd.65.1553550998489; Mon, 25 Mar 2019 14:56:38 -0700 (PDT) Received: from xps15.cg.shawcable.net (S0106002369de4dac.cg.shawcable.net. [68.147.8.254]) by smtp.gmail.com with ESMTPSA id j20sm30645631pfi.27.2019.03.25.14.56.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Mar 2019 14:56:37 -0700 (PDT) From: Mathieu Poirier To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v2 03/16] coresight: etm4x: Configure tracers to emit timestamps Date: Mon, 25 Mar 2019 15:56:19 -0600 Message-Id: <20190325215632.17013-4-mathieu.poirier@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190325215632.17013-1-mathieu.poirier@linaro.org> References: <20190325215632.17013-1-mathieu.poirier@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190325_145640_576455_B815E8BC X-CRM114-Status: GOOD ( 20.79 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, alexander.shishkin@linux.intel.com, coresight@lists.linaro.org, peterz@infradead.org, mike.leach@arm.com, leo.yan@linaro.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Configure timestamps to be emitted at regular intervals in the trace stream to temporally correlate instructions executed on different CPUs. Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight-etm4x.c | 115 +++++++++++++++++- 1 file changed, 112 insertions(+), 3 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-etm4x.c b/drivers/hwtracing/coresight/coresight-etm4x.c index 732ae12fca9b..45c341a5aa0b 100644 --- a/drivers/hwtracing/coresight/coresight-etm4x.c +++ b/drivers/hwtracing/coresight/coresight-etm4x.c @@ -138,8 +138,11 @@ static int etm4_enable_hw(struct etmv4_drvdata *drvdata) drvdata->base + TRCCNTVRn(i)); } - /* Resource selector pair 0 is always implemented and reserved */ - for (i = 0; i < drvdata->nr_resource * 2; i++) + /* + * Resource selector pair 0 is always implemented and reserved. As + * such start at 2. + */ + for (i = 2; i < drvdata->nr_resource * 2; i++) writel_relaxed(config->res_ctrl[i], drvdata->base + TRCRSCTLRn(i)); @@ -201,6 +204,97 @@ static void etm4_enable_hw_smp_call(void *info) arg->rc = etm4_enable_hw(arg->drvdata); } +/* + * The goal of function etm4_config_timestamp_event() is to configure a + * counter that will tell the tracer to emit a timestamp packet when it + * reaches zero. This is done in order to get a more fine grained idea + * of when instructions are executed so that they can be correlated + * with execution on other CPUs. + * + * To do this the counter itself is configured to self reload and + * TRCRSCTLR1 (always true) used to get the counter to decrement. From + * there a resource selector is configured with the counter and the + * timestamp control register to use the resource selector to trigger the + * event that will insert a timestamp packet in the stream. + */ +static int etm4_config_timestamp_event(struct etmv4_drvdata *drvdata) +{ + int i, ctridx, ret = -EINVAL; + int counter, rselector; + u32 val = 0; + struct etmv4_config *config = &drvdata->config; + + /* No point in trying if we don't have at least one counter */ + if (!drvdata->nr_cntr) + goto out; + + /* Find a counter that hasn't been initialised */ + for (i = 0; i < drvdata->nr_cntr; i++) + if (config->cntr_val[i] == 0) + break; + + /* Remember what counter we used */ + counter = 1 << i; + ctridx = i; + + /* All the counters have been configured already, bail out */ + if (i == drvdata->nr_cntr) { + pr_err("%s: no available counter found\n", __func__); + goto out; + } + + /* + * Initialise original and reload counter value to the smallest + * possible value in order to get as much precision as we can. + */ + config->cntr_val[ctridx] = 1; + config->cntrldvr[ctridx] = 1; + + /* Set the trace counter control register */ + val = 0x1 << 16 | /* Bit 16, reload counter automatically */ + 0x0 << 7 | /* Select single resource selector */ + 0x1; /* Resource selector 1, i.e always true */ + + config->cntr_ctrl[ctridx] = val; + + /* + * Searching for an available resource selector to use, starting at + * '2' since every implementation has at least 2 resource selector. + * ETMIDR4 gives the number of resource selector _pairs_, + * hence multiply by 2. + */ + for (i = 2; i < drvdata->nr_resource * 2; i++) + if (!config->res_ctrl[i]) + break; + + /* Remember what resource selector we used */ + rselector = i; + + if (i == drvdata->nr_resource * 2) { + pr_err("%s: no available resource selector found\n", __func__); + + /* Backout what we did and exit */ + config->cntr_ctrl[ctridx] = 0; + config->cntrldvr[ctridx] = 0; + config->cntr_val[ctridx] = 0; + goto out; + } + + val = 0x2 << 16 | /* Group 0b0010 - Counter and sequencers */ + counter << 0; /* Counter to use */ + + config->res_ctrl[i] = val; + + val = 0x0 << 7 | /* Select single resource selector */ + rselector; /* Resource selector */ + + config->ts_ctrl = val; + + ret = 0; +out: + return ret; +} + static int etm4_parse_event_config(struct etmv4_drvdata *drvdata, struct perf_event *event) { @@ -236,9 +330,24 @@ static int etm4_parse_event_config(struct etmv4_drvdata *drvdata, /* TRM: Must program this for cycacc to work */ config->ccctlr = ETM_CYC_THRESHOLD_DEFAULT; } - if (attr->config & BIT(ETM_OPT_TS)) + if (attr->config & BIT(ETM_OPT_TS)) { + /* + * Configure timestamps to be emitted at regular intervals in + * order to correlate instructions executed on different CPUs + * (CPU-wide trace scenarios). + */ + ret = etm4_config_timestamp_event(drvdata); + + /* + * No need to go further if timestamp intervals can't + * be configured. + */ + if (ret) + goto out; + /* bit[11], Global timestamp tracing bit */ config->cfg |= BIT(11); + } if (attr->config & BIT(ETM_OPT_CTXTID)) /* bit[6], Context ID tracing bit */