All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH] intel: Delay testing for userptr until first use
Date: Tue, 04 Nov 2014 15:14:04 +0000	[thread overview]
Message-ID: <5458ED3C.6000703@linux.intel.com> (raw)
In-Reply-To: <1415111489-17590-1-git-send-email-chris@chris-wilson.co.uk>


On 11/04/2014 02:31 PM, Chris Wilson wrote:
> Running __mmu_notifier_register() is surprisingly expensive, so let's
> not do that unless we have to.

Affects some program startup or what? What is the cost? I would add some 
notes in the commit for future reference.

> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---
>   intel/intel_bufmgr_gem.c | 114 +++++++++++++++++++++++++++--------------------
>   1 file changed, 65 insertions(+), 49 deletions(-)
>
> diff --git a/intel/intel_bufmgr_gem.c b/intel/intel_bufmgr_gem.c
> index f2f4fea..addf413 100644
> --- a/intel/intel_bufmgr_gem.c
> +++ b/intel/intel_bufmgr_gem.c
> @@ -935,6 +935,70 @@ drm_intel_gem_bo_alloc_userptr(drm_intel_bufmgr *bufmgr,
>   	return &bo_gem->bo;
>   }
>
> +static bool
> +has_userptr(drm_intel_bufmgr_gem *bufmgr_gem)
> +{
> +	int ret;
> +	void *ptr;
> +	long pgsz;
> +	struct drm_i915_gem_userptr userptr;
> +	struct drm_gem_close close_bo;
> +
> +	pgsz = sysconf(_SC_PAGESIZE);
> +	assert(pgsz > 0);
> +
> +	ret = posix_memalign(&ptr, pgsz, pgsz);
> +	if (ret) {
> +		DBG("Failed to get a page (%ld) for userptr detection!\n",
> +			pgsz);
> +		return false;
> +	}
> +
> +	memset(&userptr, 0, sizeof(userptr));
> +	userptr.user_ptr = (__u64)(unsigned long)ptr;
> +	userptr.user_size = pgsz;
> +
> +retry:
> +	ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_I915_GEM_USERPTR, &userptr);
> +	if (ret) {
> +		if (errno == ENODEV && userptr.flags == 0) {
> +			userptr.flags = I915_USERPTR_UNSYNCHRONIZED;
> +			goto retry;
> +		}
> +		free(ptr);
> +		return false;
> +	}
> +
> +	close_bo.handle = userptr.handle;
> +	ret = drmIoctl(bufmgr_gem->fd, DRM_IOCTL_GEM_CLOSE, &close_bo);
> +	free(ptr);
> +	if (ret) {
> +		fprintf(stderr, "Failed to release test userptr object! (%d) "
> +				"i915 kernel driver may not be sane!\n", errno);
> +		return false;
> +	}
> +
> +	return true;
> +}
> +
> +static drm_intel_bo *
> +check_bo_alloc_userptr(drm_intel_bufmgr *bufmgr,
> +		       const char *name,
> +		       void *addr,
> +		       uint32_t tiling_mode,
> +		       uint32_t stride,
> +		       unsigned long size,
> +		       unsigned long flags)
> +{
> +	if (has_userptr((drm_intel_bufmgr_gem *)bufmgr))
> +		bufmgr->bo_alloc_userptr = drm_intel_bo_alloc_userptr;

I wouldn't have spotted this - so retroactively compile tested I assume?

Otherwise,
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>

Regards,

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

  parent reply	other threads:[~2014-11-04 15:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-04 14:31 [PATCH] intel: Delay testing for userptr until first use Chris Wilson
2014-11-04 14:36 ` Chris Wilson
2014-11-04 15:14 ` Tvrtko Ursulin [this message]
2014-11-04 18:44   ` Chris Wilson
2014-11-05 10:07     ` Tvrtko Ursulin

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=5458ED3C.6000703@linux.intel.com \
    --to=tvrtko.ursulin@linux.intel.com \
    --cc=chris@chris-wilson.co.uk \
    --cc=intel-gfx@lists.freedesktop.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.