dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: j.glisse@gmail.com
Cc: thellstrom@vmware.com, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 10/14] drm/ttm: provide dma aware ttm page pool code V8
Date: Wed, 16 Nov 2011 10:50:01 -0500	[thread overview]
Message-ID: <20111116155001.GB3952@phenom.dumpdata.com> (raw)
In-Reply-To: <1321051669-16675-11-git-send-email-j.glisse@gmail.com>

> +int ttm_dma_populate(struct ttm_tt *ttm, struct device *dev)
> +{
.. snip..

> +	for (i = 0; i < ttm->num_pages; ++i) {
> +		ret = ttm_dma_pool_get_pages(pool, ttm, i);
> +		if (ret != 0) {
> +			ttm_dma_unpopulate(ttm, dev);
> +			return -ENOMEM;
> +		}
> +
> +		ret = ttm_mem_global_alloc_page(mem_glob, ttm->pages[i],
> +						false, false);

Ok, so we increment it here..

.. snip..
> +void ttm_dma_unpopulate(struct ttm_tt *ttm, struct device *dev)
> +{
> +	struct dma_pool *pool;
> +	struct dma_page *d_page;
> +	enum pool_type type;
> +	bool is_cached = false;
> +	unsigned count = 0, i;
> +	unsigned long irq_flags;
> +
> +	type = ttm_to_type(ttm->page_flags, ttm->caching_state);
> +	pool = ttm_dma_find_pool(dev, type);
> +	if (!pool) {
> +		WARN_ON(!pool);
> +		return;
> +	}
> +	is_cached = (ttm_dma_find_pool(pool->dev,
> +		     ttm_to_type(ttm->page_flags, tt_cached)) == pool);
> +
> +	/* make sure pages array match list and count number of pages */
> +	list_for_each_entry(d_page, &ttm->alloc_list, page_list) {
> +		ttm->pages[count] = d_page->p;
> +		count++;
> +	}
> +
> +	spin_lock_irqsave(&pool->lock, irq_flags);
> +	pool->npages_in_use -= count;
> +	if (is_cached) {
> +		pool->nfrees += count;
> +	} else {
> +		pool->npages_free += count;
> +		list_splice(&ttm->alloc_list, &pool->free_list);
> +		if (pool->npages_free > _manager->options.max_size) {
> +			count = pool->npages_free - _manager->options.max_size;
> +		}
> +	}
> +	spin_unlock_irqrestore(&pool->lock, irq_flags);

But we don't do it here.  I think you need:

	for (i = 0; i < ttm->num_pages; i++) {
		ttm_mem_global_free_page(mem_glob, ttm->pages[i]);

And it has to be done before ttm_dma_pages_put as at that point the
pages are truly gone.

Could actually be done in the '/* make sure pages array match list .."


> +
> +	if (is_cached) {
> +		ttm_dma_pages_put(pool, &ttm->alloc_list,
> +				  ttm->pages, count);
> +	}
> +
> +	INIT_LIST_HEAD(&ttm->alloc_list);
> +	for (i = 0; i < ttm->num_pages; i++) {
> +		ttm->pages[i] = NULL;
> +		ttm->dma_address[i] = 0;
> +	}

  reply	other threads:[~2011-11-16 15:50 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-11 22:47 ttm: merge ttm_backend & ttm_tt, introduce ttm dma allocator V5 j.glisse
2011-11-11 22:47 ` [PATCH 01/14] swiotlb: Expose swiotlb_nr_tlb function to modules j.glisse
2011-11-11 22:47 ` [PATCH 02/14] drm/ttm: remove userspace backed ttm object support j.glisse
2011-11-11 22:47 ` [PATCH 03/14] drm/ttm: remove split btw highmen and lowmem page j.glisse
2011-11-11 22:47 ` [PATCH 04/14] drm/ttm: remove unused backend flags field j.glisse
2011-11-11 22:47 ` [PATCH 05/14] drm/ttm: use ttm put pages function to properly restore cache attribute j.glisse
2011-11-11 22:47 ` [PATCH 06/14] drm/ttm: test for dma_address array allocation failure j.glisse
2011-11-11 22:47 ` [PATCH 07/14] drm/ttm: page allocation use page array instead of list j.glisse
2011-11-11 22:47 ` [PATCH 08/14] drm/ttm: merge ttm_backend and ttm_tt V5 j.glisse
2011-11-11 22:47 ` [PATCH 09/14] drm/ttm: introduce callback for ttm_tt populate & unpopulate V4 j.glisse
2011-11-11 22:47 ` [PATCH 10/14] drm/ttm: provide dma aware ttm page pool code V8 j.glisse
2011-11-16 15:50   ` Konrad Rzeszutek Wilk [this message]
2011-11-16 16:04     ` Jerome Glisse
2011-11-11 22:47 ` [PATCH 11/14] drm/radeon/kms: enable the ttm dma pool if swiotlb is on V3 j.glisse
2011-11-16 15:46   ` Konrad Rzeszutek Wilk
2011-11-16 16:05     ` Jerome Glisse
2011-11-11 22:47 ` [PATCH 12/14] drm/nouveau: enable the ttm dma pool when swiotlb is active V3 j.glisse
2011-11-11 22:47 ` [PATCH 13/14] drm/ttm: isolate dma data from ttm_tt V3 j.glisse
2011-11-15 21:07   ` Konrad Rzeszutek Wilk
2011-11-15 21:47     ` Jerome Glisse
2011-11-16  0:35     ` Jerome Glisse
2011-11-16 17:21       ` Konrad Rzeszutek Wilk
2011-11-11 22:47 ` [PATCH 14/14] drm/ttm: simplify memory accounting for ttm user j.glisse
2011-11-14 14:49 ` ttm: merge ttm_backend & ttm_tt, introduce ttm dma allocator V5 Thomas Hellstrom
2011-11-14 16:02   ` Jerome Glisse
2011-11-14 16:06     ` Thomas Hellstrom
2011-11-14 18:54       ` Jerome Glisse
2011-11-14 19:25         ` Thomas Hellstrom
2011-11-16 15:15         ` Konrad Rzeszutek Wilk
2011-11-16 15:31           ` Jerome Glisse
2011-11-16 15:53             ` Konrad Rzeszutek Wilk

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=20111116155001.GB3952@phenom.dumpdata.com \
    --to=konrad.wilk@oracle.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=j.glisse@gmail.com \
    --cc=thellstrom@vmware.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox