From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, intel-gfx@lists.freedesktop.org
Subject: Re: [PATCH 2/3] igt/gem_userptr_blits: Shared memory allocations
Date: Fri, 11 Jul 2014 11:30:54 +0100 [thread overview]
Message-ID: <53BFBCDE.6070009@linux.intel.com> (raw)
In-Reply-To: <1405071640-29692-2-git-send-email-chris@chris-wilson.co.uk>
On 07/11/2014 10:40 AM, Chris Wilson wrote:
> The forked tests allocate the bo (and thus for userptr, the memory) in
> the parent and pass them to all children. The difference for userptr is
> that we allocate system memory which the kernel then copies into each
> child. As the children need to access the memory for their checks, it
> does need to be shared - so allocate the userptr from shared memory!
>
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=80208
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---
> tests/gem_userptr_blits.c | 39 ++++++++++++++++++++++++++++++---------
> 1 file changed, 30 insertions(+), 9 deletions(-)
>
> diff --git a/tests/gem_userptr_blits.c b/tests/gem_userptr_blits.c
> index 14efdda..9cf681b 100644
> --- a/tests/gem_userptr_blits.c
> +++ b/tests/gem_userptr_blits.c
> @@ -321,17 +321,32 @@ create_userptr(int fd, uint32_t val, uint32_t *ptr)
> }
>
> static void **handle_ptr_map;
> -static unsigned int num_handle_ptr_map;
> +static int *handle_size_map;
> +static unsigned int num_handle_map;
>
> -static void add_handle_ptr(uint32_t handle, void *ptr)
> +static void reset_handle_ptr(void)
> {
> - if (handle >= num_handle_ptr_map) {
> + free(handle_ptr_map);
> + free(handle_size_map);
> + num_handle_map = 0;
> +}
> +
> +static void add_handle_ptr(uint32_t handle, void *ptr, int size)
> +{
> + if (handle >= num_handle_map) {
> handle_ptr_map = realloc(handle_ptr_map,
> (handle + 1000) * sizeof(void*));
> - num_handle_ptr_map = handle + 1000;
> + igt_assert(handle_ptr_map);
> +
> + handle_size_map = realloc(handle_size_map,
> + (handle + 1000) * sizeof(int));
> + igt_assert(handle_size_map);
> +
> + num_handle_map = handle + 1000;
> }
>
> handle_ptr_map[handle] = ptr;
> + handle_size_map[handle] = size;
> }
>
> static void *get_handle_ptr(uint32_t handle)
> @@ -341,10 +356,10 @@ static void *get_handle_ptr(uint32_t handle)
>
> static void free_handle_ptr(uint32_t handle)
> {
> - igt_assert(handle < num_handle_ptr_map);
> + igt_assert(handle < num_handle_map);
> igt_assert(handle_ptr_map[handle]);
>
> - free(handle_ptr_map[handle]);
> + munmap(handle_ptr_map[handle], handle_size_map[handle]);
> handle_ptr_map[handle] = NULL;
> }
>
> @@ -354,12 +369,15 @@ static uint32_t create_userptr_bo(int fd, int size)
> uint32_t handle;
> int ret;
>
> - ret = posix_memalign(&ptr, PAGE_SIZE, size);
> - igt_assert(ret == 0);
> + ptr = mmap(NULL, size,
> + PROT_READ | PROT_WRITE,
> + MAP_ANONYMOUS | MAP_SHARED,
> + -1, 0);
> + igt_assert(ptr != MAP_FAILED);
I wasn't sure about this straight away, but man page says "...on Linux,
the mapping will be created at a nearby page boundary..." so it's fine.
> ret = gem_userptr(fd, (uint32_t *)ptr, size, 0, &handle);
> igt_assert(ret == 0);
> - add_handle_ptr(handle, ptr);
> + add_handle_ptr(handle, ptr, size);
>
> return handle;
> }
> @@ -641,6 +659,7 @@ static void sigbus(int sig, siginfo_t *info, void *param)
> MAP_ANONYMOUS | MAP_PRIVATE | MAP_FIXED, -1, 0);
> if ((unsigned long)addr == ptr) {
> memset(addr, counter, sizeof(linear));
> + munmap(addr, sizeof(linear));
> return;
> }
> }
> @@ -708,6 +727,8 @@ static int test_dmabuf(void)
> close(fd1);
> close(fd2);
>
> + reset_handle_ptr();
> +
> return 0;
> }
>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
next prev parent reply other threads:[~2014-07-11 10:31 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-11 9:40 [PATCH 1/3] Wait for any pid in order to reap failure quicker Chris Wilson
2014-07-11 9:40 ` [PATCH 2/3] igt/gem_userptr_blits: Shared memory allocations Chris Wilson
2014-07-11 10:30 ` Tvrtko Ursulin [this message]
2014-07-11 9:40 ` [PATCH 3/3] igt/gem_userptr_blits: Verify that userptr bo work on unshared memory Chris Wilson
2014-07-11 10:45 ` Tvrtko Ursulin
2014-07-11 11:56 ` [PATCH 1/3] Wait for any pid in order to reap failure quicker 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=53BFBCDE.6070009@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.