dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: sourab gupta <sourab.gupta@intel.com>
To: Robert Bragg <robert@sixbynine.org>
Cc: "dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	David Airlie <airlied@linux.ie>,
	"intel-gfx@lists.freedesktop.org"
	<intel-gfx@lists.freedesktop.org>,
	"Vetter, Daniel" <daniel.vetter@intel.com>
Subject: Re: [PATCH v8 09/12] drm/i915: Add dev.i915.perf_stream_paranoid sysctl option
Date: Fri, 04 Nov 2016 14:36:48 +0530	[thread overview]
Message-ID: <1478250408.18863.18.camel@sourab-desktop> (raw)
In-Reply-To: <20161028021430.2177-10-robert@sixbynine.org>

On Thu, 2016-10-27 at 19:14 -0700, Robert Bragg wrote:
> Consistent with the kernel.perf_event_paranoid sysctl option that can
> allow non-root users to access system wide cpu metrics, this can
> optionally allow non-root users to access system wide OA counter metrics
> from Gen graphics hardware.
> 
> Signed-off-by: Robert Bragg <robert@sixbynine.org>
> Reviewed-by: Matthew Auld <matthew.auld@intel.com>
> ---
>  drivers/gpu/drm/i915/i915_drv.h  |  1 +
>  drivers/gpu/drm/i915/i915_perf.c | 50 +++++++++++++++++++++++++++++++++++++++-
>  2 files changed, 50 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index 01438fb..a138f86 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -2171,6 +2171,7 @@ struct drm_i915_private {
>  		bool initialized;
>  
>  		struct kobject *metrics_kobj;
> +		struct ctl_table_header *sysctl_header;
>  
>  		struct mutex lock;
>  		struct list_head streams;
> diff --git a/drivers/gpu/drm/i915/i915_perf.c b/drivers/gpu/drm/i915/i915_perf.c
> index 8d07c41..4e42073 100644
> --- a/drivers/gpu/drm/i915/i915_perf.c
> +++ b/drivers/gpu/drm/i915/i915_perf.c
> @@ -64,6 +64,11 @@
>  #define POLL_FREQUENCY 200
>  #define POLL_PERIOD (NSEC_PER_SEC / POLL_FREQUENCY)
>  
> +/* for sysctl proc_dointvec_minmax of dev.i915.perf_stream_paranoid */
> +static int zero;
> +static int one = 1;
> +static u32 i915_perf_stream_paranoid = true;
> +
>  /* The maximum exponent the hardware accepts is 63 (essentially it selects one
>   * of the 64bit timestamp bits to trigger reports from) but there's currently
>   * no known use case for sampling as infrequently as once per 47 thousand years.
> @@ -1207,7 +1212,13 @@ i915_perf_open_ioctl_locked(struct drm_i915_private *dev_priv,
>  		}
>  	}
>  
> -	if (!specific_ctx && !capable(CAP_SYS_ADMIN)) {
> +	/* Similar to perf's kernel.perf_paranoid_cpu sysctl option
> +	 * we check a dev.i915.perf_stream_paranoid sysctl option
> +	 * to determine if it's ok to access system wide OA counters
> +	 * without CAP_SYS_ADMIN privileges.
> +	 */
> +	if (!specific_ctx &&
> +	    i915_perf_stream_paranoid && !capable(CAP_SYS_ADMIN)) {
>  		DRM_ERROR("Insufficient privileges to open system-wide i915 perf stream\n");
>  		ret = -EACCES;
>  		goto err_ctx;
> @@ -1454,6 +1465,39 @@ void i915_perf_unregister(struct drm_i915_private *dev_priv)
>  	dev_priv->perf.metrics_kobj = NULL;
>  }
>  
> +static struct ctl_table oa_table[] = {
> +	{
> +	 .procname = "perf_stream_paranoid",
> +	 .data = &i915_perf_stream_paranoid,
> +	 .maxlen = sizeof(i915_perf_stream_paranoid),
> +	 .mode = 0644,
> +	 .proc_handler = proc_dointvec_minmax,
> +	 .extra1 = &zero,
> +	 .extra2 = &one,
> +	 },
> +	{}
> +};
> +
> +static struct ctl_table i915_root[] = {
> +	{
> +	 .procname = "i915",
> +	 .maxlen = 0,
> +	 .mode = 0555,
> +	 .child = oa_table,
> +	 },
> +	{}
> +};
> +
> +static struct ctl_table dev_root[] = {
> +	{
> +	 .procname = "dev",
> +	 .maxlen = 0,
> +	 .mode = 0555,
> +	 .child = i915_root,
> +	 },
> +	{}
> +};
> +
>  void i915_perf_init(struct drm_i915_private *dev_priv)
>  {
>  	if (!IS_HASWELL(dev_priv))
> @@ -1484,6 +1528,8 @@ void i915_perf_init(struct drm_i915_private *dev_priv)
>  	dev_priv->perf.oa.n_builtin_sets =
>  		i915_oa_n_builtin_metric_sets_hsw;
>  
> +	dev_priv->perf.sysctl_header = register_sysctl_table(dev_root);
> +
>  	dev_priv->perf.initialized = true;
>  }
>  
> @@ -1492,6 +1538,8 @@ void i915_perf_fini(struct drm_i915_private *dev_priv)
>  	if (!dev_priv->perf.initialized)
>  		return;
>  
> +	unregister_sysctl_table(dev_priv->perf.sysctl_header);
> +
>  	memset(&dev_priv->perf.oa.ops, 0, sizeof(dev_priv->perf.oa.ops));
>  	dev_priv->perf.initialized = false;
>  }

Looks fine.
Reviewed-by: Sourab Gupta <sourab.gupta@intel.com> 


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

  reply	other threads:[~2016-11-04  9:06 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-28  2:14 [PATCH v8 00/12] Enable i915 perf stream for Haswell OA unit Robert Bragg
2016-10-28  2:14 ` [PATCH v8 01/12] ctx-pin placeholder from chris Robert Bragg
2016-10-28  2:14 ` [PATCH v8 02/12] drm/i915: Add i915 perf infrastructure Robert Bragg
2016-10-28 14:27   ` Matthew Auld
2016-10-31 16:27     ` Robert Bragg
2016-10-31 17:13       ` Matthew Auld
2016-10-31 18:54         ` Robert Bragg
2016-11-04  8:59   ` sourab gupta
2016-11-04 13:19     ` Robert Bragg
2016-11-07  8:40       ` sourab gupta
2016-10-28  2:14 ` [PATCH v8 03/12] drm/i915: rename OACONTROL GEN7_OACONTROL Robert Bragg
2016-11-02  6:35   ` sourab gupta
2016-10-28  2:14 ` [PATCH v8 04/12] drm/i915: return EACCES for check_cmd() failures Robert Bragg
2016-11-04  5:18   ` sourab gupta
2016-10-28  2:14 ` [PATCH v8 05/12] drm/i915: don't whitelist oacontrol in cmd parser Robert Bragg
2016-11-04  9:17   ` sourab gupta
2016-10-28  2:14 ` [PATCH v8 06/12] drm/i915: Add 'render basic' Haswell OA unit config Robert Bragg
2016-10-28  2:14 ` [PATCH v8 07/12] drm/i915: Enable i915 perf stream for Haswell OA unit Robert Bragg
2016-10-31 21:44   ` Matthew Auld
2016-10-28  2:14 ` [PATCH v8 08/12] drm/i915: advertise available metrics via sysfs Robert Bragg
2016-11-04  9:01   ` sourab gupta
2016-10-28  2:14 ` [PATCH v8 09/12] drm/i915: Add dev.i915.perf_stream_paranoid sysctl option Robert Bragg
2016-11-04  9:06   ` sourab gupta [this message]
2016-10-28  2:14 ` [PATCH v8 10/12] drm/i915: add oa_event_min_timer_exponent sysctl Robert Bragg
2016-11-02  6:29   ` sourab gupta
2016-11-04  0:58     ` Robert Bragg
2016-10-28  2:14 ` [PATCH v8 11/12] drm/i915: Add more Haswell OA metric sets Robert Bragg
2016-11-01 14:57   ` Chris Wilson
2016-11-01 16:53     ` Robert Bragg
2016-10-28  2:14 ` [PATCH v8 12/12] drm/i915: Add a kerneldoc summary for i915_perf.c Robert Bragg

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=1478250408.18863.18.camel@sourab-desktop \
    --to=sourab.gupta@intel.com \
    --cc=airlied@linux.ie \
    --cc=daniel.vetter@intel.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=robert@sixbynine.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).