<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Nov 9, 2016 at 7:52 PM, Matthew Auld <span dir="ltr"><<a href="mailto:matthew.william.auld@gmail.com" target="_blank">matthew.william.auld@gmail.<wbr>com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="m_-6573997344553263611HOEnZb"><div class="m_-6573997344553263611h5">On 7 November 2016 at 19:49, Robert Bragg <<a href="mailto:robert@sixbynine.org" target="_blank">robert@sixbynine.org</a>> wrote:<br>
> The maximum OA sampling frequency is now configurable via a<br>
> dev.i915.oa_max_sample_rate sysctl parameter.<br>
><br>
> Following the precedent set by perf's similar<br>
> kernel.perf_event_max_sample_r<wbr>ate the default maximum rate is 100000Hz<br>
><br>
> Signed-off-by: Robert Bragg <<a href="mailto:robert@sixbynine.org" target="_blank">robert@sixbynine.org</a>><br>
> ---<br>
>  drivers/gpu/drm/i915/i915_perf<wbr>.c | 61 ++++++++++++++++++++++++++++++<wbr>++--------<br>
>  1 file changed, 50 insertions(+), 11 deletions(-)<br>
><br>
> diff --git a/drivers/gpu/drm/i915/i915_pe<wbr>rf.c b/drivers/gpu/drm/i915/i915_pe<wbr>rf.c<br>
> index e51c1d8..1a87fe9 100644<br>
> --- a/drivers/gpu/drm/i915/i915_pe<wbr>rf.c<br>
> +++ b/drivers/gpu/drm/i915/i915_pe<wbr>rf.c<br>
> @@ -82,6 +82,21 @@ static u32 i915_perf_stream_paranoid = true;<br>
>  #define INVALID_CTX_ID 0xffffffff<br>
><br>
><br>
> +/* For sysctl proc_dointvec_minmax of i915_oa_max_sample_rate<br>
> + *<br>
> + * 160ns is the smallest sampling period we can theoretically program the OA<br>
> + * unit with on Haswell, corresponding to 6.25MHz.<br>
> + */<br>
> +static int oa_sample_rate_hard_limit = 6250000;<br>
> +<br>
> +/* Theoretically we can program the OA unit to sample every 160ns but don't<br>
> + * allow that by default unless root...<br>
> + *<br>
> + * The default threshold of 100000Hz is based on perf's similar<br>
> + * kernel.perf_event_max_sample_r<wbr>ate sysctl parameter.<br>
> + */<br>
> +static u32 i915_oa_max_sample_rate = 100000;<br>
> +<br>
>  /* XXX: beware if future OA HW adds new report formats that the current<br>
>   * code assumes all reports have a power-of-two size and ~(size - 1) can<br>
>   * be used as a mask to align the OA tail pointer.<br>
> @@ -1314,6 +1329,7 @@ static int read_properties_unlocked(struc<wbr>t drm_i915_private *dev_priv,<br>
>         }<br>
><br>
>         for (i = 0; i < n_props; i++) {<br>
> +               u64 oa_period, oa_freq_hz;<br>
>                 u64 id, value;<br>
>                 int ret;<br>
><br>
> @@ -1359,21 +1375,35 @@ static int read_properties_unlocked(struc<wbr>t drm_i915_private *dev_priv,<br>
>                                 return -EINVAL;<br>
>                         }<br>
><br>
> -                       /* NB: The exponent represents a period as follows:<br>
> -                        *<br>
> -                        *   80ns * 2^(period_exponent + 1)<br>
> -                        *<br>
> -                        * Theoretically we can program the OA unit to sample<br>
> +                       /* Theoretically we can program the OA unit to sample<br>
>                          * every 160ns but don't allow that by default unless<br>
>                          * root.<br>
>                          *<br>
> -                        * Referring to perf's<br>
> -                        * kernel.perf_event_max_sample_r<wbr>ate for a precedent<br>
> -                        * (100000 by default); with an OA exponent of 6 we get<br>
> -                        * a period of 10.240 microseconds -just under 100000Hz<br>
> +                        * On Haswell the period is derived from the exponent<br>
> +                        * as:<br>
> +                        *<br>
> +                        *   period = 80ns * 2^(exponent + 1)<br>
> +                        */<br>
> +                       BUILD_BUG_ON(sizeof(oa_<wbr>period) != 8);<br>
> +                       oa_period = 80ull * (2ull << value);<br>
> +<br>
> +                       /* This check is primarily to ensure that oa_period <=<br>
> +                        * UINT32_MAX (before passing to do_div which only<br>
> +                        * accepts a u32 denominator), but we can also skip<br>
> +                        * checking anything < 1Hz which implicitly can't be<br>
> +                        * limited via an integer oa_max_sample_rate.<br>
>                          */<br>
> -                       if (value < 6 && !capable(CAP_SYS_ADMIN)) {<br>
> -                               DRM_ERROR("Minimum OA sampling exponent is 6 without root privileges\n");<br>
> +                       if (oa_period <= NSEC_PER_SEC) {<br>
> +                               u64 tmp = NSEC_PER_SEC;<br>
> +                               do_div(tmp, oa_period);<br>
> +                               oa_freq_hz = tmp;<br>
> +                       } else<br>
> +                               oa_freq_hz = 0;<br>
> +<br>
> +                       if (oa_freq_hz > i915_oa_max_sample_rate &&<br>
> +                           !capable(CAP_SYS_ADMIN)) {<br>
> +                               DRM_ERROR("OA exponent would exceed the max sampling frequency (sysctl dev.i915.oa_max_sample_rate) %uHz without root privileges\n",<br>
</div></div>This line is getting a little too long.<br></blockquote><div> </div><div>yeah, though the coding style has the exception for string constants so they remain grepable which can be useful too. Could maybe remove the bracketed naming of the corresponding sysctl parameter, though it does seem like pertinent/useful info if someone were to hit this limit.<br><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Reviewed-by: Matthew Auld <<a href="mailto:matthew.auld@intel.com" target="_blank">matthew.auld@intel.com</a>><br>
</blockquote></div><br>thanks<br></div></div>