From patchwork Fri Sep 18 16:26:30 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Poirier X-Patchwork-Id: 53924 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f71.google.com (mail-la0-f71.google.com [209.85.215.71]) by patches.linaro.org (Postfix) with ESMTPS id 7AF87218E3 for ; Fri, 18 Sep 2015 16:27:41 +0000 (UTC) Received: by lanb10 with SMTP id b10sf20778278lan.3 for ; Fri, 18 Sep 2015 09:27:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=QiHJhXk47wK7meMSPpbHC1a7jJUKwYiXVe2XK2VHQIU=; b=B1lkq0W+natuvh1WTGuQpHMaqowvxcGBV7QDqo8Y1c+BEk0sLn7zI1Bbkg6mvePKz4 K9Il7V1+YEjB+imlQWDfLWM5fd1MhGUVRx6tjh3HwJuvoJnA3+cgBie0zkCEAyZKwr94 yMTuW9q4ZB1O5gN6PDtcluC1JjRRo0D30nMVB1RDQgI9wY+JkFjQmthL2s+9pfCPDSuv 6VYyT22pW/0bvD267ebypKFlVGGbqXjTjX5z9C+RPuGolh2Mz9MrqCUFbvrzLBqK9kcW NLstUhnlQTulwBIwTMJQRStPZDBs8J2DuhbROSLZMZMTjsQdB9CyLPa9ZnVxVP6CO4fo PPIQ== X-Gm-Message-State: ALoCoQlFWT7wlrqNXkazlhCqJmnOueDEfWpo6JHRmds3bGjzKho57j+49o8bXMH9GjMUqyTNZsFn X-Received: by 10.152.26.5 with SMTP id h5mr1070225lag.5.1442593660470; Fri, 18 Sep 2015 09:27:40 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.103 with SMTP id a7ls197713lah.7.gmail; Fri, 18 Sep 2015 09:27:40 -0700 (PDT) X-Received: by 10.112.162.2 with SMTP id xw2mr3529362lbb.98.1442593660308; Fri, 18 Sep 2015 09:27:40 -0700 (PDT) Received: from mail-lb0-f176.google.com (mail-lb0-f176.google.com. [209.85.217.176]) by mx.google.com with ESMTPS id w9si6742693lad.28.2015.09.18.09.27.40 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Sep 2015 09:27:40 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) client-ip=209.85.217.176; Received: by lbbmp1 with SMTP id mp1so27824426lbb.1 for ; Fri, 18 Sep 2015 09:27:40 -0700 (PDT) X-Received: by 10.112.146.104 with SMTP id tb8mr3599865lbb.35.1442593660149; Fri, 18 Sep 2015 09:27:40 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp401653lbq; Fri, 18 Sep 2015 09:27:39 -0700 (PDT) X-Received: by 10.50.25.195 with SMTP id e3mr35789386igg.0.1442593658390; Fri, 18 Sep 2015 09:27:38 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m10si7520404igx.40.2015.09.18.09.27.38; Fri, 18 Sep 2015 09:27:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754889AbbIRQ1c (ORCPT + 30 others); Fri, 18 Sep 2015 12:27:32 -0400 Received: from mail-pa0-f53.google.com ([209.85.220.53]:34910 "EHLO mail-pa0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754771AbbIRQ1Z (ORCPT ); Fri, 18 Sep 2015 12:27:25 -0400 Received: by pacfv12 with SMTP id fv12so56043994pac.2 for ; Fri, 18 Sep 2015 09:27:24 -0700 (PDT) X-Received: by 10.66.65.234 with SMTP id a10mr8228136pat.2.1442593644261; Fri, 18 Sep 2015 09:27:24 -0700 (PDT) Received: from t430.cg.shawcable.net ([184.64.168.246]) by smtp.gmail.com with ESMTPSA id la4sm9847027pbc.76.2015.09.18.09.27.22 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 18 Sep 2015 09:27:23 -0700 (PDT) From: Mathieu Poirier To: gregkh@linuxfoundation.org, a.p.zijlstra@chello.nl, alexander.shishkin@linux.intel.com, acme@kernel.org, mingo@redhat.com, corbet@lwn.net Cc: adrian.hunter@intel.com, zhang.chunyan@linaro.org, mike.leach@arm.com, tor@ti.com, al.grant@arm.com, pawel.moll@arm.com, linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 16/20] coresight: etm-perf: implementing trace related APIs Date: Fri, 18 Sep 2015 10:26:30 -0600 Message-Id: <1442593594-10665-17-git-send-email-mathieu.poirier@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1442593594-10665-1-git-send-email-mathieu.poirier@linaro.org> References: <1442593594-10665-1-git-send-email-mathieu.poirier@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: mathieu.poirier@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.176 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Implementing the API that connect trace control, i.e initiation and termination, to the Perf core. That way trace collection can be started when the process it is associated to is executed by a CPU, and stopped when yanked away. Signed-off-by: Mathieu Poirier --- drivers/hwtracing/coresight/coresight-etm-perf.c | 97 ++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/drivers/hwtracing/coresight/coresight-etm-perf.c b/drivers/hwtracing/coresight/coresight-etm-perf.c index 3aeb4215bb22..edacf4b1d0bc 100644 --- a/drivers/hwtracing/coresight/coresight-etm-perf.c +++ b/drivers/hwtracing/coresight/coresight-etm-perf.c @@ -30,6 +30,7 @@ static struct pmu etm_pmu; +static DEFINE_PER_CPU(struct perf_output_handle, ctx_handle); static DEFINE_PER_CPU(struct coresight_device *, csdev_src); static DEFINE_PER_CPU(struct coresight_device *, csdev_sink); @@ -248,6 +249,98 @@ static void etm_free_aux(void *data) kfree(data); } +static void etm_event_stop(struct perf_event *event, int mode) +{ + int cpu = smp_processor_id(); + struct coresight_device *src = per_cpu(csdev_src, cpu); + struct coresight_device *sink = per_cpu(csdev_sink, cpu); + + if (event->hw.state == PERF_HES_STOPPED) + return; + + if (!src || !sink) + return; + + /* stop tracer */ + if (source_ops(src)->trace_enable(src, false)) + return; + + /* tell the core */ + event->hw.state = PERF_HES_STOPPED; + + + if (mode & PERF_EF_UPDATE) { + struct perf_output_handle *handle = this_cpu_ptr(&ctx_handle); + + if (WARN_ON_ONCE(handle->event != event)) + return; + + /* update trace information */ + sink_ops(sink)->update_buffer(sink, handle); + } +} + +static void etm_event_start(struct perf_event *event, int flags) +{ + int cpu = smp_processor_id(); + struct coresight_device *csdev = per_cpu(csdev_src, cpu); + + if (!csdev) + goto fail; + + /* tell the perf core the event is alive */ + event->hw.state = 0; + + if (source_ops(csdev)->trace_enable(csdev, true)) + goto fail; + + return; + +fail: + event->hw.state = PERF_HES_STOPPED; +} + +static void etm_event_del(struct perf_event *event, int mode) +{ + int cpu = smp_processor_id(); + struct perf_output_handle *handle = this_cpu_ptr(&ctx_handle); + struct coresight_device *csdev = per_cpu(csdev_sink, cpu); + + if (!csdev) + return; + + etm_event_stop(event, PERF_EF_UPDATE); + sink_ops(csdev)->unset_buffer(csdev, handle); +} + +static int etm_event_add(struct perf_event *event, int mode) +{ + int ret, cpu = smp_processor_id(); + struct perf_output_handle *handle = this_cpu_ptr(&ctx_handle); + struct hw_perf_event *hwc = &event->hw; + struct coresight_device *csdev = per_cpu(csdev_sink, cpu); + + if (!csdev) + return -EINVAL; + + if (handle->event) + return -EBUSY; + + ret = sink_ops(csdev)->set_buffer(csdev, event, handle); + if (ret) + return ret; + + if (mode & PERF_EF_START) { + etm_event_start(event, 0); + if (hwc->state & PERF_HES_STOPPED) { + etm_event_del(event, 0); + return -EBUSY; + } + } + + return 0; +} + static int __init etm_perf_init(void) { etm_pmu.capabilities = PERF_PMU_CAP_EXCLUSIVE; @@ -258,6 +351,10 @@ static int __init etm_perf_init(void) etm_pmu.event_init = etm_event_init; etm_pmu.setup_aux = etm_setup_aux; etm_pmu.free_aux = etm_free_aux; + etm_pmu.stop = etm_event_stop; + etm_pmu.start = etm_event_start; + etm_pmu.del = etm_event_del; + etm_pmu.add = etm_event_add; return perf_pmu_register(&etm_pmu, CORESIGHT_ETM_PMU_NAME, -1); }