All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Hellstrom <thomas@shipmail.org>
To: Jerome Glisse <jglisse@redhat.com>
Cc: dri-devel@lists.sf.net
Subject: Re: [PATCH] drm/ttm: ttm_fault callback to allow driver to handle bo placement V3
Date: Wed, 24 Mar 2010 19:27:57 +0100	[thread overview]
Message-ID: <4BAA59AD.7060102@shipmail.org> (raw)
In-Reply-To: <1269444350-20154-6-git-send-email-jglisse@redhat.com>

Jerome Glisse wrote:
> On fault the driver is given the opportunity to perform any operation
> it sees fit in order to place the buffer into a CPU visible area of
> memory. This patch doesn't break TTM users, nouveau, vmwgfx and radeon
> should keep working properly. Future patch will take advantage of this
> infrastructure and remove the old path from TTM once driver are
> converted.
>
> V2 return VM_FAULT_NOPAGE if callback return -EBUSY or -ERESTARTSYS
> V3 balance io_mem_reserve and io_mem_free call, fault_reserve_notify
>    is responsible to perform any necessary task for mapping to succeed
>
> Signed-off-by: Jerome Glisse <jglisse@redhat.com>
> ---
>  drivers/gpu/drm/ttm/ttm_bo.c      |    7 ++-
>  drivers/gpu/drm/ttm/ttm_bo_util.c |   95 ++++++++++++++++++-------------------
>  drivers/gpu/drm/ttm/ttm_bo_vm.c   |   46 ++++++++----------
>  include/drm/ttm/ttm_bo_api.h      |   21 ++++++++
>  include/drm/ttm/ttm_bo_driver.h   |   16 ++++++-
>  5 files changed, 108 insertions(+), 77 deletions(-)
>
> @@ -1588,8 +1591,8 @@ void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo)
>  
>  	if (!bdev->dev_mapping)
>  		return;
> -
>   

Still a lot of these. Please remove.
>  
> +int ttm_mem_io_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem)
> +{
> +	int ret;
> +
> +	if (bdev->driver->io_mem_reserve) {
> +		if (!atomic_xchg(&mem->bus.use_count, 1)) {
> +			ret = bdev->driver->io_mem_reserve(bdev, mem);
> +			if (unlikely(ret != 0))
> +				return ret;
> +		}
> +	} else {
> +		ret = ttm_bo_pci_offset(bdev, mem, &mem->bus.base, &mem->bus.offset, &mem->bus.size);
> +		if (unlikely(ret != 0))
> +			return ret;
> +		mem->bus.is_iomem = (mem->bus.size > 0) ? 1 : 0;
> +	}
> +	return 0;
> +}
> +
> +void ttm_mem_io_free(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem)
> +{
> +	if (bdev->driver->io_mem_reserve) {
> +		atomic_set(&mem->bus.use_count, 0);
>   

Shouldn't there be a test for zero before calling this?
> +		bdev->driver->io_mem_free(bdev, mem);
> +	}
> +}
> +
>   

Hmm. I don't get the logic of the above refcounting. First, the kernel 
can preempt between refcounting and driver calls:

Thread a sets use_count to 1 and preempts.
Thread b sees use_count 1 and calls ttm_bo_pci_offset(), but we haven't 
yet done an io_mem_reserve??

Otoh, from the last section it seems we always will hold bo::reserved 
around these calls, so instead we could make use_count a non-atomic 
variable.

Then, for the rest please consider the following use cases:

1) We want to temporarily map a bo within the kernel. We do:
reserve_bo().
make_mappable().
kmap().
kunmap().
free_mappable_resources().  // This is just a hint. When the bo is 
unreserved, the manager is free to evict the mappable region.
unreserve_bo().

2) We want to permanently map a bo within the kernel (kernel map for fbdev).
We do (bo is not reserved).
pin_mappable().
kmap().
access
kunmap().
unpin_mappable().

3) Fault.
reserve_bo().
make_mappable().
set_up user_space_map().
unreserve_bo().

/// Here the manager is free to evict the mappable range by reserving 
and then calling ttm_bo_unmap_virtual().

4) Unmap Virtual. (Called reserved).
unmap_user_space_mappings().
free_mappable_resources().

It looks to me like you've implemented make_mappable() = 
ttm_mem_io_reserve() and free_mappable_resources() = ttm_mem_io_free(), 
and from the above use cases we can see that they always will be called 
when the bo is reserved. Hence no need for an atomic variable and we can 
ignore the race scenarios above.

but what about pin_mappable() and unpin_mappable()? A general mapping 
manager must be able to perform these operations. Perhaps



Finally, consider a very simple mapping manager that uses the two ttm 
regions VRAM and VRAM_MAPPABLE. We'd implement the driver operations as 
follows, assuming we add io_mem_pin and io_mem_unpin:

io_mem_reserve:
ttm_bo_validate(VRAM_MAPPABLE); (Evicting as needed).

io_mem_unreserve:
noop().

io_mem_pin:
ttm_bo_reserve()
if (pin_count++ == 0)
   ttm_bo_validate(VRAM_MAPPABLE | NO_EVICT);
ttm_bo_unreserve()

io_mem_unpin:
ttm_bo_reserve()
if (--pin_count == 0)
   ttm_bo_validate(VRAM_MAPPABLE);
ttm_bo_unreserve()

This simple mapping manager would need a struct ttm_buffer_object as an 
argument. Not just the mem argument.

/Thomas




------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
--

  parent reply	other threads:[~2010-03-24 18:27 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-24 15:25 unmappable vram V5 Jerome Glisse
2010-03-24 15:25 ` [PATCH 01/14] drm/ttm: split no_wait argument in 2 GPU or reserve wait Jerome Glisse
2010-03-24 15:25   ` [PATCH 02/14] drm/radeon/kms: update to TTM no_wait splitted argument Jerome Glisse
2010-03-24 15:25     ` [PATCH 03/14] drm/nouveau: " Jerome Glisse
2010-03-24 15:25       ` [PATCH 04/14] drm/vmwgfx: " Jerome Glisse
     [not found]         ` <1269444350-20154-6-git-send-email-jglisse@redhat.com>
2010-03-24 15:25           ` [PATCH 06/14] drm/radeon/kms: add support for new fault callback V5 Jerome Glisse
2010-03-24 15:25             ` [PATCH 07/14] drm/nouveau/kms: add support for new TTM fault callback V3 Jerome Glisse
2010-03-24 15:25               ` [PATCH 08/14] drm/vmwgfx: " Jerome Glisse
2010-03-24 15:25                 ` [PATCH 09/14] drm/radeon/kms: don't initialize TTM io memory manager field Jerome Glisse
2010-03-24 15:25                   ` [PATCH 10/14] drm/nouveau/kms: " Jerome Glisse
2010-03-24 15:25                     ` [PATCH 11/14] drm/vmwgfx: " Jerome Glisse
2010-03-24 15:25                       ` [PATCH 12/14] drm/ttm: remove io_ field from TTM V3 Jerome Glisse
2010-03-24 15:25                         ` [PATCH 13/14] drm/radeon/kms: enable use of unmappable VRAM V2 Jerome Glisse
2010-03-24 18:27           ` Thomas Hellstrom [this message]
2010-03-24 19:36             ` [PATCH] drm/ttm: ttm_fault callback to allow driver to handle bo placement V3 Jerome Glisse
2010-03-24 20:08               ` Thomas Hellstrom
2010-03-24 20:45                 ` Jerome Glisse
  -- strict thread matches above, loose matches on Subject: below --
2010-03-24 15:35 Jerome Glisse

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=4BAA59AD.7060102@shipmail.org \
    --to=thomas@shipmail.org \
    --cc=dri-devel@lists.sf.net \
    --cc=jglisse@redhat.com \
    /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.