Rodrigo Vivi <rodrigo.v...@intel.com> writes:

> From: Chris Wilson <ch...@chris-wilson.co.uk>
>
> Sometimes we wish to tweak how an individual context behaves. Since we
> always create a context for every filp, this means that individual
> processes can fine tune their behaviour even if they do not explicitly
> create a context.
>
> The first example parameter here is to enable multi-process GPU testing,
> but the interface should be able to cope with passing arbitrarily complex
> parameters.
>
> Signed-off-by: Chris Wilson <ch...@chris-wilson.co.uk>
> Signed-off-by: Rodrigo Vivi <rodrigo.v...@intel.com>

Reviewed-by: Mika Kuoppala <mika.kuopp...@intel.com>

> ---
>  drivers/gpu/drm/i915/i915_dma.c         |  2 +
>  drivers/gpu/drm/i915/i915_drv.h         |  4 ++
>  drivers/gpu/drm/i915/i915_gem_context.c | 69 
> +++++++++++++++++++++++++++++++++
>  include/uapi/drm/i915_drm.h             | 12 ++++++
>  4 files changed, 87 insertions(+)
>
> diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
> index 126a36f..3c3f33f 100644
> --- a/drivers/gpu/drm/i915/i915_dma.c
> +++ b/drivers/gpu/drm/i915/i915_dma.c
> @@ -1066,6 +1066,8 @@ const struct drm_ioctl_desc i915_ioctls[] = {
>       DRM_IOCTL_DEF_DRV(I915_REG_READ, i915_reg_read_ioctl, 
> DRM_UNLOCKED|DRM_RENDER_ALLOW),
>       DRM_IOCTL_DEF_DRV(I915_GET_RESET_STATS, i915_get_reset_stats_ioctl, 
> DRM_UNLOCKED|DRM_RENDER_ALLOW),
>       DRM_IOCTL_DEF_DRV(I915_GEM_USERPTR, i915_gem_userptr_ioctl, 
> DRM_UNLOCKED|DRM_RENDER_ALLOW),
> +     DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_GETPARAM, 
> i915_gem_context_getparam_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
> +     DRM_IOCTL_DEF_DRV(I915_GEM_CONTEXT_SETPARAM, 
> i915_gem_context_setparam_ioctl, DRM_UNLOCKED|DRM_RENDER_ALLOW),
>  };
>  
>  int i915_max_ioctl = ARRAY_SIZE(i915_ioctls);
> diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
> index 3749415..9ae515e 100644
> --- a/drivers/gpu/drm/i915/i915_drv.h
> +++ b/drivers/gpu/drm/i915/i915_drv.h
> @@ -2898,6 +2898,10 @@ int i915_gem_context_create_ioctl(struct drm_device 
> *dev, void *data,
>                                 struct drm_file *file);
>  int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
>                                  struct drm_file *file);
> +int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,
> +                                 struct drm_file *file_priv);
> +int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data,
> +                                 struct drm_file *file_priv);
>  
>  /* i915_gem_evict.c */
>  int __must_check i915_gem_evict_something(struct drm_device *dev,
> diff --git a/drivers/gpu/drm/i915/i915_gem_context.c 
> b/drivers/gpu/drm/i915/i915_gem_context.c
> index bf9778e..8603bf4 100644
> --- a/drivers/gpu/drm/i915/i915_gem_context.c
> +++ b/drivers/gpu/drm/i915/i915_gem_context.c
> @@ -794,3 +794,72 @@ int i915_gem_context_destroy_ioctl(struct drm_device 
> *dev, void *data,
>       DRM_DEBUG_DRIVER("HW context %d destroyed\n", args->ctx_id);
>       return 0;
>  }
> +
> +int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,
> +                                 struct drm_file *file)
> +{
> +     struct drm_i915_file_private *file_priv = file->driver_priv;
> +     struct drm_i915_gem_context_param *args = data;
> +     struct intel_context *ctx;
> +     int ret;
> +
> +     ret = i915_mutex_lock_interruptible(dev);
> +     if (ret)
> +             return ret;
> +
> +     ctx = i915_gem_context_get(file_priv, args->ctx_id);
> +     if (IS_ERR(ctx)) {
> +             mutex_unlock(&dev->struct_mutex);
> +             return PTR_ERR(ctx);
> +     }
> +
> +     args->size = 0;
> +     switch (args->param) {
> +     case I915_CONTEXT_PARAM_BAN_PERIOD:
> +             args->value = ctx->hang_stats.ban_period_seconds;
> +             break;
> +     default:
> +             ret = -EINVAL;
> +             break;
> +     }
> +     mutex_unlock(&dev->struct_mutex);
> +
> +     return ret;
> +}
> +
> +int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data,
> +                                 struct drm_file *file)
> +{
> +     struct drm_i915_file_private *file_priv = file->driver_priv;
> +     struct drm_i915_gem_context_param *args = data;
> +     struct intel_context *ctx;
> +     int ret;
> +
> +     ret = i915_mutex_lock_interruptible(dev);
> +     if (ret)
> +             return ret;
> +
> +     ctx = i915_gem_context_get(file_priv, args->ctx_id);
> +     if (IS_ERR(ctx)) {
> +             mutex_unlock(&dev->struct_mutex);
> +             return PTR_ERR(ctx);
> +     }
> +
> +     switch (args->param) {
> +     case I915_CONTEXT_PARAM_BAN_PERIOD:
> +             if (args->size)
> +                     ret = -EINVAL;
> +             else if (args->value < ctx->hang_stats.ban_period_seconds &&
> +                      !capable(CAP_SYS_ADMIN))
> +                     ret = -EPERM;
> +             else
> +                     ctx->hang_stats.ban_period_seconds = args->value;
> +             break;
> +     default:
> +             ret = -EINVAL;
> +             break;
> +     }
> +     mutex_unlock(&dev->struct_mutex);
> +
> +     return ret;
> +}
> diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h
> index fa99129..d253c85 100644
> --- a/include/uapi/drm/i915_drm.h
> +++ b/include/uapi/drm/i915_drm.h
> @@ -224,6 +224,8 @@ typedef struct _drm_i915_sarea {
>  #define DRM_I915_REG_READ            0x31
>  #define DRM_I915_GET_RESET_STATS     0x32
>  #define DRM_I915_GEM_USERPTR         0x33
> +#define DRM_I915_GEM_CONTEXT_GETPARAM        0x34
> +#define DRM_I915_GEM_CONTEXT_SETPARAM        0x35
>  
>  #define DRM_IOCTL_I915_INIT          DRM_IOW( DRM_COMMAND_BASE + 
> DRM_I915_INIT, drm_i915_init_t)
>  #define DRM_IOCTL_I915_FLUSH         DRM_IO ( DRM_COMMAND_BASE + 
> DRM_I915_FLUSH)
> @@ -275,6 +277,8 @@ typedef struct _drm_i915_sarea {
>  #define DRM_IOCTL_I915_REG_READ                      DRM_IOWR 
> (DRM_COMMAND_BASE + DRM_I915_REG_READ, struct drm_i915_reg_read)
>  #define DRM_IOCTL_I915_GET_RESET_STATS               DRM_IOWR 
> (DRM_COMMAND_BASE + DRM_I915_GET_RESET_STATS, struct drm_i915_reset_stats)
>  #define DRM_IOCTL_I915_GEM_USERPTR                   DRM_IOWR 
> (DRM_COMMAND_BASE + DRM_I915_GEM_USERPTR, struct drm_i915_gem_userptr)
> +#define DRM_IOCTL_I915_GEM_CONTEXT_GETPARAM  DRM_IOWR (DRM_COMMAND_BASE + 
> DRM_I915_GEM_CONTEXT_GETPARAM, struct drm_i915_gem_context_param)
> +#define DRM_IOCTL_I915_GEM_CONTEXT_SETPARAM  DRM_IOWR (DRM_COMMAND_BASE + 
> DRM_I915_GEM_CONTEXT_SETPARAM, struct drm_i915_gem_context_param)
>  
>  /* Allow drivers to submit batchbuffers directly to hardware, relying
>   * on the security mechanisms provided by hardware.
> @@ -1080,4 +1084,12 @@ struct drm_i915_gem_userptr {
>       __u32 handle;
>  };
>  
> +struct drm_i915_gem_context_param {
> +     __u32 ctx_id;
> +     __u32 size;
> +     __u64 param;
> +#define I915_CONTEXT_PARAM_BAN_PERIOD 0x1
> +     __u64 value;
> +};
> +
>  #endif /* _UAPI_I915_DRM_H_ */
> -- 
> 1.9.3
>
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reply via email to