All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rogozhkin, Dmitry V" <dmitry.v.rogozhkin@intel.com>
To: "intel-gfx@lists.freedesktop.org"
	<intel-gfx@lists.freedesktop.org>,
	"chris@chris-wilson.co.uk" <chris@chris-wilson.co.uk>
Cc: "peterz@infradead.org" <peterz@infradead.org>
Subject: Re: [RFC v2 3/3] drm/i915/pmu: deny perf driver level sampling of i915 PMU
Date: Wed, 23 Aug 2017 23:43:13 +0000	[thread overview]
Message-ID: <1503502868.6588.11.camel@intel.com> (raw)
In-Reply-To: <1503501963-24136-4-git-send-email-dmitry.v.rogozhkin@intel.com>

Hi Chris,

Why we had event->hw->hrtimer in i915 PMU? Was there any particular
reason? You had some use case which did not work?

According to Peter we should not expose the timer out of our pmu, and I
do not see the reason why we need it at the first place. So, I went
forward and wiped it out and prohibited events to be intialized with the
sampling_period. I don't see what will be broken. From my perspective
nothing because internal sampling timer still remains.

Could you, please, comment?

Dmitry.

On Wed, 2017-08-23 at 08:26 -0700, Dmitry Rogozhkin wrote:
> 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 <dmitry.v.rogozhkin@intel.com>
> Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
> Cc: Chris Wilson <chris@chris-wilson.co.uk>
> Cc: Peter Zijlstra <peterz@infradead.org>
> ---
>  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 c551d64..311aeeb 100644
> --- a/drivers/gpu/drm/i915/i915_pmu.c
> +++ b/drivers/gpu/drm/i915/i915_pmu.c
> @@ -239,50 +239,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 =
> @@ -293,6 +249,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;
>  
> @@ -328,46 +288,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() &&
> @@ -493,8 +416,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)
> @@ -534,8 +455,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)

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2017-08-23 23:43 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-23 15:26 [RFC v2 0/3] Support perf stat with i915 PMU Dmitry Rogozhkin
2017-08-23 15:26 ` [RFC v2 1/3] drm/i915/pmu: reorder function to suite next patch Dmitry Rogozhkin
2017-08-23 15:26 ` [RFC v2 2/3] drm/i915/pmu: serve global events and support perf stat Dmitry Rogozhkin
2017-08-23 23:38   ` Rogozhkin, Dmitry V
2017-08-28 22:45     ` Rogozhkin, Dmitry V
2017-08-29  9:28     ` Peter Zijlstra
2017-08-30 17:24       ` Rogozhkin, Dmitry V
2017-08-30 20:03         ` Peter Zijlstra
2017-08-30 20:05         ` Peter Zijlstra
2017-08-23 15:26 ` [RFC v2 3/3] drm/i915/pmu: deny perf driver level sampling of i915 PMU Dmitry Rogozhkin
2017-08-23 23:43   ` Rogozhkin, Dmitry V [this message]
     [not found]     ` <3EDB40B547243546A1017B798F8C1AA8847FC002@ORSMSX114.amr.corp.intel.com>
     [not found]       ` <150368515309.27971.17522435118048475155@mail.alporthouse.com>
2017-08-25 19:01         ` Rogozhkin, Dmitry V
2017-08-31  7:41     ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1503502868.6588.11.camel@intel.com \
    --to=dmitry.v.rogozhkin@intel.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.