diff mbox

[v8,10/12] drm/i915: add oa_event_min_timer_exponent sysctl

Message ID 20161028021430.2177-11-robert@sixbynine.org (mailing list archive)
State New, archived
Headers show

Commit Message

Robert Bragg Oct. 28, 2016, 2:14 a.m. UTC
The minimal sampling period is now configurable via a
dev.i915.oa_min_timer_exponent sysctl parameter.

Following the precedent set by perf, the default is the minimum that
won't (on its own) exceed the default kernel.perf_event_max_sample_rate
default of 100000 samples/s.

Signed-off-by: Robert Bragg <robert@sixbynine.org>
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
---
 drivers/gpu/drm/i915/i915_perf.c | 42 ++++++++++++++++++++++++++++------------
 1 file changed, 30 insertions(+), 12 deletions(-)

Comments

sourab.gupta@intel.com Nov. 2, 2016, 6:29 a.m. UTC | #1
On Thu, 2016-10-27 at 19:14 -0700, Robert Bragg wrote:
> The minimal sampling period is now configurable via a
> dev.i915.oa_min_timer_exponent sysctl parameter.
> 
> Following the precedent set by perf, the default is the minimum that
> won't (on its own) exceed the default kernel.perf_event_max_sample_rate
> default of 100000 samples/s.
> 
> Signed-off-by: Robert Bragg <robert@sixbynine.org>
> Reviewed-by: Matthew Auld <matthew.auld@intel.com>
> ---
>  drivers/gpu/drm/i915/i915_perf.c | 42 ++++++++++++++++++++++++++++------------
>  1 file changed, 30 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
> index 4e42073..e3c6f51 100644
> --- a/drivers/gpu/drm/i915/i915_perf.c
> +++ b/drivers/gpu/drm/i915/i915_perf.c
> @@ -82,6 +82,22 @@ static u32 i915_perf_stream_paranoid = true;
>  #define INVALID_CTX_ID 0xffffffff
>  
> 
> +/* for sysctl proc_dointvec_minmax of i915_oa_min_timer_exponent */
> +static int oa_exponent_max = OA_EXPONENT_MAX;
> +
> +/* Theoretically we can program the OA unit to sample every 160ns but don't
> + * allow that by default unless root...
> + *
> + * The period is derived from the exponent as:
> + *
> + *   period = 80ns * 2^(exponent + 1)
> + *
> + * Referring to perf's kernel.perf_event_max_sample_rate for a precedent
> + * (100000 by default); with an OA exponent of 6 we get a period of 10.240
> + * microseconds - just under 100000Hz
> + */
> +static u32 i915_oa_min_timer_exponent = 6;

For HSW, the timestamp period is 80ns, so the exponent of 6 translates
to sampling rate of ~100000Hz. But the timestamp period may change for
other platforms, leading to different values of oa_min_timer_exponent
corresponding to sampling rate of ~100000Hz. Do we plan to have this
value platform specific subsequently, or the guidance value of ~100000Hz
min sampling rate needn't be strictly followed?

> +
>  /* XXX: beware if future OA HW adds new report formats that the current
>   * code assumes all reports have a power-of-two size and ~(size - 1) can
>   * be used as a mask to align the OA tail pointer.
> @@ -1353,21 +1369,14 @@ static int read_properties_unlocked(struct drm_i915_private *dev_priv,
>  				return -EINVAL;
>  			}
>  
> -			/* NB: The exponent represents a period as follows:
> -			 *
> -			 *   80ns * 2^(period_exponent + 1)
> -			 *
> -			 * Theoretically we can program the OA unit to sample
> +			/* Theoretically we can program the OA unit to sample
>  			 * every 160ns but don't allow that by default unless
>  			 * root.
> -			 *
> -			 * Referring to perf's
> -			 * kernel.perf_event_max_sample_rate for a precedent
> -			 * (100000 by default); with an OA exponent of 6 we get
> -			 * a period of 10.240 microseconds -just under 100000Hz
>  			 */
> -			if (value < 6 && !capable(CAP_SYS_ADMIN)) {
> -				DRM_ERROR("Minimum OA sampling exponent is 6 without root privileges\n");
> +			if (value < i915_oa_min_timer_exponent &&
> +			    !capable(CAP_SYS_ADMIN)) {
> +				DRM_ERROR("Minimum OA sampling exponent (sysctl dev.i915.oa_min_timer_exponent) is %u without root privileges\n",
> +					  i915_oa_min_timer_exponent);
>  				return -EACCES;
>  			}
>  
> @@ -1475,6 +1484,15 @@ static struct ctl_table oa_table[] = {
>  	 .extra1 = &zero,
>  	 .extra2 = &one,
>  	 },
> +	{
> +	 .procname = "oa_min_timer_exponent",
> +	 .data = &i915_oa_min_timer_exponent,
> +	 .maxlen = sizeof(i915_oa_min_timer_exponent),
> +	 .mode = 0644,
> +	 .proc_handler = proc_dointvec_minmax,
> +	 .extra1 = &zero,
> +	 .extra2 = &oa_exponent_max,
> +	 },
>  	{}
>  };
>
Robert Bragg Nov. 4, 2016, 12:58 a.m. UTC | #2
On Wed, Nov 2, 2016 at 6:29 AM, sourab gupta <sourab.gupta@intel.com> wrote:

> On Thu, 2016-10-27 at 19:14 -0700, Robert Bragg wrote:
> > The minimal sampling period is now configurable via a
> > dev.i915.oa_min_timer_exponent sysctl parameter.
> >
> > Following the precedent set by perf, the default is the minimum that
> > won't (on its own) exceed the default kernel.perf_event_max_sample_rate
> > default of 100000 samples/s.
> >
> > Signed-off-by: Robert Bragg <robert@sixbynine.org>
> > Reviewed-by: Matthew Auld <matthew.auld@intel.com>
> > ---
> >  drivers/gpu/drm/i915/i915_perf.c | 42 ++++++++++++++++++++++++++++--
> ----------
> >  1 file changed, 30 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/i915/i915_perf.c
> b/drivers/gpu/drm/i915/i915_perf.c
> > index 4e42073..e3c6f51 100644
> > --- a/drivers/gpu/drm/i915/i915_perf.c
> > +++ b/drivers/gpu/drm/i915/i915_perf.c
> > @@ -82,6 +82,22 @@ static u32 i915_perf_stream_paranoid = true;
> >  #define INVALID_CTX_ID 0xffffffff
> >
> >
> > +/* for sysctl proc_dointvec_minmax of i915_oa_min_timer_exponent */
> > +static int oa_exponent_max = OA_EXPONENT_MAX;
> > +
> > +/* Theoretically we can program the OA unit to sample every 160ns but
> don't
> > + * allow that by default unless root...
> > + *
> > + * The period is derived from the exponent as:
> > + *
> > + *   period = 80ns * 2^(exponent + 1)
> > + *
> > + * Referring to perf's kernel.perf_event_max_sample_rate for a
> precedent
> > + * (100000 by default); with an OA exponent of 6 we get a period of
> 10.240
> > + * microseconds - just under 100000Hz
> > + */
> > +static u32 i915_oa_min_timer_exponent = 6;
>
> For HSW, the timestamp period is 80ns, so the exponent of 6 translates
> to sampling rate of ~100000Hz. But the timestamp period may change for
> other platforms, leading to different values of oa_min_timer_exponent
> corresponding to sampling rate of ~100000Hz. Do we plan to have this
> value platform specific subsequently, or the guidance value of ~100000Hz
> min sampling rate needn't be strictly followed?
>

actually it's bothered me a bit that I've been lazy with not having this
adapt for gen9+ in later patches

I think it would probably be better to make this a Hz based threshold for
userspace, otherwise any userspace policy here needs to be adapted for each
system with a different timestamp frequency which isn't great.

I've updated the patch locally to make this an oa_max_sample_rate parameter
in Hz, which I'll aim to test on haswell tomorrow and send out.

Thanks,
- Robert
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
index 4e42073..e3c6f51 100644
--- a/drivers/gpu/drm/i915/i915_perf.c
+++ b/drivers/gpu/drm/i915/i915_perf.c
@@ -82,6 +82,22 @@  static u32 i915_perf_stream_paranoid = true;
 #define INVALID_CTX_ID 0xffffffff
 
 
+/* for sysctl proc_dointvec_minmax of i915_oa_min_timer_exponent */
+static int oa_exponent_max = OA_EXPONENT_MAX;
+
+/* Theoretically we can program the OA unit to sample every 160ns but don't
+ * allow that by default unless root...
+ *
+ * The period is derived from the exponent as:
+ *
+ *   period = 80ns * 2^(exponent + 1)
+ *
+ * Referring to perf's kernel.perf_event_max_sample_rate for a precedent
+ * (100000 by default); with an OA exponent of 6 we get a period of 10.240
+ * microseconds - just under 100000Hz
+ */
+static u32 i915_oa_min_timer_exponent = 6;
+
 /* XXX: beware if future OA HW adds new report formats that the current
  * code assumes all reports have a power-of-two size and ~(size - 1) can
  * be used as a mask to align the OA tail pointer.
@@ -1353,21 +1369,14 @@  static int read_properties_unlocked(struct drm_i915_private *dev_priv,
 				return -EINVAL;
 			}
 
-			/* NB: The exponent represents a period as follows:
-			 *
-			 *   80ns * 2^(period_exponent + 1)
-			 *
-			 * Theoretically we can program the OA unit to sample
+			/* Theoretically we can program the OA unit to sample
 			 * every 160ns but don't allow that by default unless
 			 * root.
-			 *
-			 * Referring to perf's
-			 * kernel.perf_event_max_sample_rate for a precedent
-			 * (100000 by default); with an OA exponent of 6 we get
-			 * a period of 10.240 microseconds -just under 100000Hz
 			 */
-			if (value < 6 && !capable(CAP_SYS_ADMIN)) {
-				DRM_ERROR("Minimum OA sampling exponent is 6 without root privileges\n");
+			if (value < i915_oa_min_timer_exponent &&
+			    !capable(CAP_SYS_ADMIN)) {
+				DRM_ERROR("Minimum OA sampling exponent (sysctl dev.i915.oa_min_timer_exponent) is %u without root privileges\n",
+					  i915_oa_min_timer_exponent);
 				return -EACCES;
 			}
 
@@ -1475,6 +1484,15 @@  static struct ctl_table oa_table[] = {
 	 .extra1 = &zero,
 	 .extra2 = &one,
 	 },
+	{
+	 .procname = "oa_min_timer_exponent",
+	 .data = &i915_oa_min_timer_exponent,
+	 .maxlen = sizeof(i915_oa_min_timer_exponent),
+	 .mode = 0644,
+	 .proc_handler = proc_dointvec_minmax,
+	 .extra1 = &zero,
+	 .extra2 = &oa_exponent_max,
+	 },
 	{}
 };