From patchwork Fri Sep 1 15:56:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rogozhkin, Dmitry V" X-Patchwork-Id: 9935399 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 94095602BC for ; Fri, 1 Sep 2017 23:59:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 874182841D for ; Fri, 1 Sep 2017 23:59:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BB3628550; Fri, 1 Sep 2017 23:59: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=-2.7 required=2.0 tests=BAYES_00, DATE_IN_PAST_06_12, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7A68D28541 for ; Fri, 1 Sep 2017 23:59:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 927316E8DB; Fri, 1 Sep 2017 23:58:49 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id D68686E8BF for ; Fri, 1 Sep 2017 23:58:47 +0000 (UTC) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 01 Sep 2017 16:58:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.41,459,1498546800"; d="scan'208";a="130893857" Received: from dvrscl.jf.intel.com ([10.54.70.8]) by orsmga002.jf.intel.com with ESMTP; 01 Sep 2017 16:58:45 -0700 From: Dmitry Rogozhkin To: intel-gfx@lists.freedesktop.org Date: Fri, 1 Sep 2017 08:56:32 -0700 Message-Id: <1504281392-9095-6-git-send-email-dmitry.v.rogozhkin@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1504281392-9095-1-git-send-email-dmitry.v.rogozhkin@intel.com> References: <1504281392-9095-1-git-send-email-dmitry.v.rogozhkin@intel.com> Cc: Peter Zijlstra Subject: [Intel-gfx] [RFC v4 5/5] drm/i915/pmu: deny perf driver level sampling of i915 PMU X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP This patch should probably be squashed with Tvrtko's PMU enabling patch... As per discussion with Peter, i915 PMU is an example of uncore PMU which are prohibited to support perf driver level sampling. This patch removes hrtimer which we expose to perf core and denies events creation with non-zero event->attr.sampling_period. Mind that this patch does _not_ remove i915 PMU _internal_ sampling timer. So, sampling metrics are still gathered, but can be accessed only by explicit request to get metric counter, i.e. by sys_read(). Change-Id: I33f345f679f0a5a8ecc9867f9e7c1bfb357e708d Signed-off-by: Dmitry Rogozhkin Cc: Tvrtko Ursulin Cc: Chris Wilson Cc: Peter Zijlstra --- drivers/gpu/drm/i915/i915_pmu.c | 89 ++--------------------------------------- 1 file changed, 4 insertions(+), 85 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_pmu.c b/drivers/gpu/drm/i915/i915_pmu.c index 5f32356..b1327ac 100644 --- a/drivers/gpu/drm/i915/i915_pmu.c +++ b/drivers/gpu/drm/i915/i915_pmu.c @@ -254,50 +254,6 @@ static int engine_event_init(struct perf_event *event) return 0; } -static DEFINE_PER_CPU(struct pt_regs, i915_pmu_pt_regs); - -static enum hrtimer_restart hrtimer_sample(struct hrtimer *hrtimer) -{ - struct pt_regs *regs = this_cpu_ptr(&i915_pmu_pt_regs); - struct perf_sample_data data; - struct perf_event *event; - u64 period; - - event = container_of(hrtimer, struct perf_event, hw.hrtimer); - if (event->state != PERF_EVENT_STATE_ACTIVE) - return HRTIMER_NORESTART; - - event->pmu->read(event); - - perf_sample_data_init(&data, 0, event->hw.last_period); - perf_event_overflow(event, &data, regs); - - period = max_t(u64, 10000, event->hw.sample_period); - hrtimer_forward_now(hrtimer, ns_to_ktime(period)); - return HRTIMER_RESTART; -} - -static void init_hrtimer(struct perf_event *event) -{ - struct hw_perf_event *hwc = &event->hw; - - if (!is_sampling_event(event)) - return; - - hrtimer_init(&hwc->hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); - hwc->hrtimer.function = hrtimer_sample; - - if (event->attr.freq) { - long freq = event->attr.sample_freq; - - event->attr.sample_period = NSEC_PER_SEC / freq; - hwc->sample_period = event->attr.sample_period; - local64_set(&hwc->period_left, hwc->sample_period); - hwc->last_period = hwc->sample_period; - event->attr.freq = 0; - } -} - static int i915_pmu_event_init(struct perf_event *event) { struct drm_i915_private *i915 = @@ -308,6 +264,10 @@ static int i915_pmu_event_init(struct perf_event *event) if (event->attr.type != event->pmu->type) return -ENOENT; + /* unsupported modes and filters */ + if (event->attr.sample_period) /* no sampling */ + return -EINVAL; + if (has_branch_stack(event)) return -EOPNOTSUPP; @@ -343,46 +303,9 @@ static int i915_pmu_event_init(struct perf_event *event) if (!event->parent) event->destroy = i915_pmu_event_destroy; - init_hrtimer(event); - return 0; } -static void i915_pmu_timer_start(struct perf_event *event) -{ - struct hw_perf_event *hwc = &event->hw; - s64 period; - - if (!is_sampling_event(event)) - return; - - period = local64_read(&hwc->period_left); - if (period) { - if (period < 0) - period = 10000; - - local64_set(&hwc->period_left, 0); - } else { - period = max_t(u64, 10000, hwc->sample_period); - } - - hrtimer_start_range_ns(&hwc->hrtimer, - ns_to_ktime(period), 0, - HRTIMER_MODE_REL_PINNED); -} - -static void i915_pmu_timer_cancel(struct perf_event *event) -{ - struct hw_perf_event *hwc = &event->hw; - - if (!is_sampling_event(event)) - return; - - local64_set(&hwc->period_left, - ktime_to_ns(hrtimer_get_remaining(&hwc->hrtimer))); - hrtimer_cancel(&hwc->hrtimer); -} - static bool engine_needs_busy_stats(struct intel_engine_cs *engine) { return supports_busy_stats() && @@ -512,8 +435,6 @@ static void i915_pmu_enable(struct perf_event *event) } spin_unlock_irqrestore(&i915->pmu.lock, flags); - - i915_pmu_timer_start(event); } static void i915_pmu_disable(struct perf_event *event) @@ -566,8 +487,6 @@ static void i915_pmu_disable(struct perf_event *event) i915->pmu.timer_enabled &= pmu_needs_timer(i915, true); spin_unlock_irqrestore(&i915->pmu.lock, flags); - - i915_pmu_timer_cancel(event); } static void i915_pmu_event_start(struct perf_event *event, int flags)