All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: ankitprasad.r.sharma@intel.com
Cc: intel-gfx@lists.freedesktop.org, akash.goel@intel.com,
	shashidhar.hiremath@intel.com
Subject: Re: [PATCH 8/9] drm/i915: Migrate stolen objects before hibernation
Date: Mon, 14 Dec 2015 10:31:05 +0000	[thread overview]
Message-ID: <20151214103105.GI24300@nuc-i3427.alporthouse.com> (raw)
In-Reply-To: <1450071971-30321-9-git-send-email-ankitprasad.r.sharma@intel.com>

On Mon, Dec 14, 2015 at 11:16:10AM +0530, ankitprasad.r.sharma@intel.com wrote:
> +static int
> +copy_content(struct drm_i915_gem_object *obj,
> +		struct drm_i915_private *i915,
> +		struct address_space *mapping)
> +{
> +	struct drm_mm_node node;
> +	int ret, i;
> +
> +	/* stolen objects are already pinned to prevent shrinkage */
> +	memset(&node, 0, sizeof(node));
> +	ret = i915_gem_insert_node_in_range(i915, &node, 4096, 0,
> +					    0, i915->gtt.mappable_end);
> +	if (ret)
> +		return ret;
> +
> +	for (i = 0; i < obj->base.size / PAGE_SIZE; i++) {
> +		struct page *page;
> +		void *__iomem src;
> +		void *dst;
> +
> +		wmb();
> +		i915->gtt.base.insert_page(&i915->gtt.base,
> +					   i915_gem_object_get_dma_address(obj, i),
> +					   node.start,
> +					   I915_CACHE_NONE,
> +					   0);
> +		wmb();
> +
> +		page = shmem_read_mapping_page(mapping, i);
> +		if (IS_ERR(page)) {
> +			ret = PTR_ERR(page);
> +			break;
> +		}
> +
> +		src = io_mapping_map_atomic_wc(i915->gtt.mappable, node.start);
> +		dst = kmap_atomic(page);

The wmb() barriers are here...
> +		memcpy_fromio(dst, src, PAGE_SIZE);
...and here.

> +		kunmap_atomic(dst);
> +		io_mapping_unmap_atomic(src);
> +
> +		page_cache_release(page);
> +	}
> +
> +	wmb();
> +	i915->gtt.base.clear_range(&i915->gtt.base,
> +				   node.start, node.size,
> +				   true);
> +	drm_mm_remove_node(&node);
> +	return ret;
> +}
> +
> +/**
> + * i915_gem_object_migrate_stolen_to_shmemfs() - migrates a stolen backed
> + * object to shmemfs
> + * @obj: stolen backed object to be migrated
> + *
> + * Returns: 0 on successful migration, errno on failure
> + */
> +
> +static int
> +i915_gem_object_migrate_stolen_to_shmemfs(struct drm_i915_gem_object *obj)
> +{
> +	struct drm_i915_private *i915 = to_i915(obj->base.dev);
> +	struct i915_vma *vma, *vn;
> +	struct file *file;
> +	struct address_space *mapping;
> +	struct sg_table *stolen_pages, *shmemfs_pages;
> +	int ret;
> +
> +	if (WARN_ON_ONCE(i915_gem_object_needs_bit17_swizzle(obj)))
> +		return -EINVAL;
> +
> +	ret = i915_gem_object_set_to_gtt_domain(obj, false);
> +	if (ret)
> +		return ret;

This should be in copy_content.

> +	file = shmem_file_setup("drm mm object", obj->base.size, VM_NORESERVE);
> +	if (IS_ERR(file))
> +		return PTR_ERR(file);
> +	mapping = i915_gem_set_inode_gfp(obj->base.dev, file);
> +
> +	list_for_each_entry_safe(vma, vn, &obj->vma_list, vma_link)
> +		if (i915_vma_unbind(vma))
> +			continue;
> +
> +	if (obj->madv != I915_MADV_WILLNEED && list_empty(&obj->vma_list)) {
> +		/* Discard the stolen reservation, and replace with
> +		 * an unpopulated shmemfs object.
> +		 */
> +		obj->madv = __I915_MADV_PURGED;
> +		goto swap_pages;

A goto over one line? else?

> +	}
> +
> +	ret = copy_content(obj, i915, mapping);
> +	if (ret)
> +		goto err_file;
> +
> +swap_pages:
> +	stolen_pages = obj->pages;
> +	obj->pages = NULL;
> +
> +	obj->base.filp = file;
> +	obj->base.read_domains = I915_GEM_DOMAIN_CPU;
> +	obj->base.write_domain = I915_GEM_DOMAIN_CPU;

Again, these domains are a result of copy_content.

> +
> +	/* Recreate any pinned binding with pointers to the new storage */
> +	if (!list_empty(&obj->vma_list)) {
> +		ret = i915_gem_object_get_pages_gtt(obj);
> +		if (ret) {
> +			obj->pages = stolen_pages;
> +			goto err_file;
> +		}
> +
> +		ret = i915_gem_object_set_to_gtt_domain(obj, true);

Why? The pages are allocated, the domain is irrelevant (just so long as
it is accurate, see above).

> +		obj->get_page.sg = obj->pages->sgl;
> +		obj->get_page.last = 0;
> +
> +		list_for_each_entry(vma, &obj->vma_list, vma_link) {
> +			if (!drm_mm_node_allocated(&vma->node))
> +				continue;
> +
> +			WARN_ON(i915_vma_bind(vma,
> +					      obj->cache_level,
> +					      PIN_UPDATE));
> +		}
> +	} else
> +		list_del(&obj->global_list);

This is very confusing (and wrong). This should only be a result of
setting PURGED above.

> +	/* drop the stolen pin and backing */
> +	shmemfs_pages = obj->pages;
> +	obj->pages = stolen_pages;
> +
> +	i915_gem_object_unpin_pages(obj);
> +	obj->ops->put_pages(obj);
> +	if (obj->ops->release)
> +		obj->ops->release(obj);
> +
> +	obj->ops = &i915_gem_object_ops;
> +	obj->pages = shmemfs_pages;
> +
> +	return 0;
> +
> +err_file:
> +	fput(file);
> +	obj->base.filp = NULL;
> +	return ret;
> +}
> +
> +int
> +i915_gem_freeze(struct drm_device *dev)
> +{
> +	/* Called before i915_gem_suspend() when hibernating */
> +	struct drm_i915_private *i915 = to_i915(dev);
> +	struct drm_i915_gem_object *obj, *tmp;
> +	struct list_head *phase[] = {
> +		&i915->mm.unbound_list, &i915->mm.bound_list, NULL
> +	}, **p;
> +	int ret;
> +
> +	ret = i915_mutex_lock_interruptible(dev);
> +	if (ret)
> +		return ret;

Whitespace.
-Chris

> +	/* Across hibernation, the stolen area is not preserved.
> +	 * Anything inside stolen must copied back to normal
> +	 * memory if we wish to preserve it.
> +	 */

-- 
Chris Wilson, Intel Open Source Technology Centre
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

  reply	other threads:[~2015-12-14 10:31 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-14  5:46 [PATCH v11 0/9] Support for creating/using Stolen memory backed objects ankitprasad.r.sharma
2015-12-14  5:46 ` [PATCH 1/9] drm/i915: Allow use of get_dma_address for stolen " ankitprasad.r.sharma
2015-12-17 10:20   ` Tvrtko Ursulin
2015-12-14  5:46 ` [PATCH 2/9] drm/i915: Use insert_page for pwrite_fast ankitprasad.r.sharma
2015-12-14  9:54   ` Chris Wilson
2015-12-14 10:48     ` Chris Wilson
2015-12-14 11:22       ` Chris Wilson
2015-12-17 10:45   ` Tvrtko Ursulin
2015-12-17 11:19     ` Chris Wilson
2015-12-14  5:46 ` [PATCH 3/9] drm/i915: Clearing buffer objects via CPU/GTT ankitprasad.r.sharma
2015-12-14  9:48   ` Chris Wilson
2015-12-17 10:27   ` Tvrtko Ursulin
2015-12-14  5:46 ` [PATCH 4/9] drm/i915: Support for creating Stolen memory backed objects ankitprasad.r.sharma
2015-12-14 10:05   ` Chris Wilson
2015-12-15  6:10     ` Ankitprasad Sharma
2015-12-14  5:46 ` [PATCH 5/9] drm/i915: Propagating correct error codes to the userspace ankitprasad.r.sharma
2015-12-14 10:10   ` Chris Wilson
2015-12-14  5:46 ` [PATCH 6/9] drm/i915: Add support for stealing purgable stolen pages ankitprasad.r.sharma
2015-12-14 10:13   ` Chris Wilson
2015-12-17 10:51   ` Tvrtko Ursulin
2015-12-14  5:46 ` [PATCH 7/9] drm/i915: Support for pread/pwrite from/to non shmem backed objects ankitprasad.r.sharma
2015-12-14  9:43   ` Chris Wilson
2015-12-14  5:46 ` [PATCH 8/9] drm/i915: Migrate stolen objects before hibernation ankitprasad.r.sharma
2015-12-14 10:31   ` Chris Wilson [this message]
2015-12-14  5:46 ` [PATCH 9/9] drm/i915: Fail the execbuff using stolen objects as batchbuffers ankitprasad.r.sharma
2015-12-14  9:44   ` Chris Wilson
2015-12-15 14:41   ` Dave Gordon
2015-12-15 14:54     ` Chris Wilson
2015-12-15 17:50       ` Dave Gordon
2015-12-16 12:35         ` Chris Wilson

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=20151214103105.GI24300@nuc-i3427.alporthouse.com \
    --to=chris@chris-wilson.co.uk \
    --cc=akash.goel@intel.com \
    --cc=ankitprasad.r.sharma@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=shashidhar.hiremath@intel.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.