Tests for verifying the old and extended GEM_CREATE ioctl
v3 cover Tests for verifying the old and extended GEM_CREATE ioctl
From: Ankitprasad Sharma <[email protected]>
This new set of tests verifies the old and the new extended GEM_CREATE ioctl gem_stolen tries to verify the new extended GEM_CREATE ioctl, which tries to create an object backed by stolen memory and performs basic operations on it. It verifies the creation as well as the purging of an object when it is no longer needed, copying contents of a stolen backed object to another, doing a pread/pwrite on the object and verifying its contents.
We also try to pread/pwrite a stolen backed object multiple times to get the pread/pwrite speed, as well as pread speed when there is a page fault while accessing userspace buffer.
There is a new test gem_create to do a sanity check for creating both stolen/shmem backed objects with valid and invalid parameters.
v2: Rebased to the latest and added IGT_TEST_DESCRIPTION
v3: Addressed comments by Tvrtko and Dave, added one more testcase for verifying extended gem_create ioctl
Ankitprasad Sharma (3):
igt/gem_stolen: Verifying extended gem_create ioctl igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj igt/gem_create: Test to validate parameters for GEM_CREATE ioctl
lib/ioctl_wrappers.c | 74 ++++++++++ lib/ioctl_wrappers.h | 13 ++ tests/Makefile.sources | 2 + tests/gem_create.c | 170 +++++++++++++++++++++++ tests/gem_pread.c | 106 ++++++++++++++- tests/gem_pwrite.c | 54 +++++++- tests/gem_stolen.c | 363 +++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 771 insertions(+), 11 deletions(-) create mode 100644 tests/gem_create.c create mode 100644 tests/gem_stolen.c
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v3 1/3 igt/gem_stolen: Verifying extended gem_create ioctl
From: Ankitprasad Sharma <[email protected]>
This patch adds the testcases for verifying the new extended gem_create ioctl. By means of this extended ioctl, memory placement of the GEM object can be specified, i.e. either shmem or stolen memory.
These testcases include functional tests and interface tests for testing the gem_create ioctl call for stolen memory placement
v2: Testing pread/pwrite functionality for stolen backed objects, added local struct for extended gem_create and gem_get_aperture, until headers catch up (Chris)
v3: Removed get_aperture related functions, extended gem_pread to compare speeds for user pages with and without page faults, unexposed local_gem_create struct, changed gem_create_stolen usage (Chris)
v4: Splitting patch to remove changes from gem_pread/gem_pwrite to another patch (Ankit)
v5: Fixed Rebase conflicts (Ankit)
Added IGT_TEST_DESCRIPTION (Thomas Wood)
v6: Added __gem_create_stolen for allowing error handling by User, updated gem_create_stolen to align with gem_create function, corrected fill_purge test (out of bound access), added testcase to validate allocating of more than 32 bit sized buffers (Tvrtko)
--- lib/ioctl_wrappers.c | 74 ++++++++++ lib/ioctl_wrappers.h | 13 ++ tests/Makefile.sources | 1 + tests/gem_stolen.c | 363 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 451 insertions(+) create mode 100644 tests/gem_stolen.c
lib/ioctl_wrappers.c +74 -0
@@ -389,6 +389,80 @@ void gem_sync(int fd, uint32_t handle) I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT); } +bool gem_create__has_stolen_support (int fd) +{ +static int has_stolen_support =-1 ; +struct drm_i915_getparam gp; +int val =-1 ; + +if (has_stolen_support <0 ) { +memset (&gp,0 ,sizeof (gp)); + gp.param =36 ;/* CREATE_VERSION */ + gp.value = &val; + +/* Do we have the extended gem_create_ioctl? */ +ioctl (fd,DRM_IOCTL_I915_GETPARAM , &gp); + has_stolen_support = val >=2 ; + } + +return has_stolen_support; +} + +struct local_i915_gem_create_v2 { +uint64_t size; +uint32_t handle; +uint32_t pad; +#define I915_CREATE_PLACEMENT_STOLEN (1<<0) +uint32_t flags; +}; + +#define LOCAL_IOCTL_I915_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_CREATE, struct local_i915_gem_create_v2) +uint32_t __gem_create_stolen (int fd,uint64_t size) +{ +struct local_i915_gem_create_v2 create; +int ret; + +memset (&create,0 ,sizeof (create)); + create.handle =0 ; + create.size = size; + create.flags =I915_CREATE_PLACEMENT_STOLEN ; + ret =drmIoctl (fd,LOCAL_IOCTL_I915_GEM_CREATE , &create); + +if (ret <0 ) +return 0 ; + + errno =0 ; +return create.handle; +} + +/** +* gem_create_stolen: +* @fd: open i915 drm file descriptor +* @size: desired size of the buffer +* @flags: desired placement i.e. stolen or shmem +* +* This wraps the new GEM_CREATE ioctl, which allocates a +* new gem buffer object of @size and placement based on @flags. +* +* Returns: The file-private handle of the created buffer object +*/ + +uint32_t gem_create_stolen (int fd,uint64_t size) +{ +struct local_i915_gem_create_v2 create; +int ret; + +memset (&create,0 ,sizeof (create)); + create.handle =0 ; + create.size = size; + create.flags =I915_CREATE_PLACEMENT_STOLEN ; +do_ioctl (fd,LOCAL_IOCTL_I915_GEM_CREATE , &create); +igt_assert (create.handle); + +return create.handle; +} + +uint32_t __gem_create (int fd,int size) {struct drm_i915_gem_create create;
lib/ioctl_wrappers.h +13 -0
@@ -56,6 +56,9 @@ void gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t lengvoid gem_set_domain (int fd,uint32_t handle,uint32_t read_domains,uint32_t write_domain);void gem_sync (int fd,uint32_t handle); +bool gem_create__has_stolen_support (int fd); +uint32_t __gem_create_stolen (int fd,uint64_t size); +uint32_t gem_create_stolen (int fd,uint64_t size);uint32_t __gem_create (int fd,int size);uint32_t gem_create (int fd,uint64_t size);void gem_execbuf (int fd,struct drm_i915_gem_execbuffer2 *execbuf);
@@ -67,6 +70,16 @@ bool gem_mmap__has_wc(int fd);void *gem_mmap__wc (int fd,uint32_t handle,uint64_t offset,uint64_t size,unsigned prot);/** +* gem_require_stolen_support: +* @fd: open i915 drm file descriptor +* +* Test macro to query whether support for allocating objects from stolen +* memory is available. Automatically skips through igt_require() if not. +*/ +#define gem_require_stolen_support (fd) \ + igt_require(gem_create__has_stolen_support(fd)) + +/** * gem_require_mmap_wc: * @fd: open i915 drm file descriptor *
tests/Makefile.sources +1 -0
@@ -55,6 +55,7 @@ TESTS_progs_M = \ gem_reset_stats \ gem_ringfill \ gem_set_tiling_vs_blt \ + gem_stolen \ gem_storedw_batches_loop \ gem_streaming_writes \ gem_tiled_blits \
tests/gem_stolen.c new file +363 -0
363 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 1/3] igt/gem_stolen: Verifying extended gem_create ioctl
Hi,
Quoted 87 lines · On 07/22/2015 02:45 PM, [email protected] wrote:
From: Ankitprasad Sharma <[email protected]>
This patch adds the testcases for verifying the new extended
gem_createioctl. By means of this extended ioctl, memory placement of the GEM object can be specified, i.e. either shmem or stolen memory.
These testcases include functional tests and interface tests for testing thegem_createioctl call for stolen memory placementv2: Testing pread/pwrite functionality for stolen backed objects, added local struct for extended
gem_createandgem_get_aperture, until headers catch up (Chris)v3: Removed
get_aperturerelated functions, extendedgem_preadto compare speeds for user pages with and without page faults, unexposedlocal_gem_createstruct, changedgem_create_stolenusage (Chris)v4: Splitting patch to remove changes from gem_pread/gem_pwrite to another patch (Ankit)
v5: Fixed Rebase conflicts (Ankit)
AddedIGT_TEST_DESCRIPTION(Thomas Wood)v6: Added
__gem_create_stolenfor allowing error handling by User, updatedgem_create_stolento align withgem_createfunction, correctedfill_purgetest (out of bound access), added testcase to validate allocating of more than 32 bit sized buffers (Tvrtko)Signed-off-by Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>--- lib/ioctl_wrappers.c | 74 ++++++++++ lib/ioctl_wrappers.h | 13 ++ tests/Makefile.sources | 1 + tests/gem_stolen.c | 363 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 451 insertions(+)create mode 100644
tests/gem_stolen.clib/ioctl_wrappers.c +41
-0@@ -389,6 +389,80 @@ void gem_sync(int fd, uint32_t handle) I915_GEM_DOMAIN_GTT, I915_GEM_DOMAIN_GTT); } +bool gem_create__has_stolen_support (int fd) +{ +static int has_stolen_support =-1 ; +struct drm_i915_getparam gp; +int val =-1 ; + +if (has_stolen_support <0 ) { +memset (&gp,0 ,sizeof (gp)); + gp.param =36 ;/* CREATE_VERSION */ + gp.value = &val; + +/* Do we have the extended gem_create_ioctl? */ +ioctl (fd,DRM_IOCTL_I915_GETPARAM , &gp); + has_stolen_support = val >=2 ; + } + +return has_stolen_support; +} + +struct local_i915_gem_create_v2 { +uint64_t size; +uint32_t handle; +uint32_t pad; +#define I915_CREATE_PLACEMENT_STOLEN (1<<0) +uint32_t flags; +}; + +#define LOCAL_IOCTL_I915_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_CREATE, struct local_i915_gem_create_v2) +uint32_t __gem_create_stolen (int fd,uint64_t size) +{ +struct local_i915_gem_create_v2 create; +int ret; + +memset (&create,0 ,sizeof (create)); + create.handle =0 ; + create.size = size; + create.flags =I915_CREATE_PLACEMENT_STOLEN ; + ret =drmIoctl (fd,LOCAL_IOCTL_I915_GEM_CREATE , &create); + +if (ret <0 ) +return 0 ;
lib/ioctl_wrappers.c void gem_sync(int fd, uint32_t handle) · line 442
Quoted 10 lines
lib/ioctl_wrappers.c +10
-0+ + errno =0 ; +return create.handle; +} + +/** +* gem_create_stolen: +* @fd: open i915 drm file descriptor +* @size: desired size of the buffer +* @flags: desired placement i.e. stolen or shmem
There are no flags in the function prototype. :)
Quoted 156 lines
lib/ioctl_wrappers.c +23
-0+* +* This wraps the new GEM_CREATE ioctl, which allocates a +* new gem buffer object of @size and placement based on @flags. +* +* Returns: The file-private handle of the created buffer object +*/ + +uint32_t gem_create_stolen (int fd,uint64_t size) +{ +struct local_i915_gem_create_v2 create; +int ret; + +memset (&create,0 ,sizeof (create)); + create.handle =0 ; + create.size = size; + create.flags =I915_CREATE_PLACEMENT_STOLEN ; +do_ioctl (fd,LOCAL_IOCTL_I915_GEM_CREATE , &create); +igt_assert (create.handle); + +return create.handle; +} + +uint32_t __gem_create (int fd,int size) {struct drm_i915_gem_create create;lib/ioctl_wrappers.h +13
-0@@ -56,6 +56,9 @@ void gem_read(int fd, uint32_t handle, uint64_t offset, void *buf, uint64_t lengvoid gem_set_domain (int fd,uint32_t handle,uint32_t read_domains,uint32_t write_domain);void gem_sync (int fd,uint32_t handle); +bool gem_create__has_stolen_support (int fd); +uint32_t __gem_create_stolen (int fd,uint64_t size); +uint32_t gem_create_stolen (int fd,uint64_t size);uint32_t __gem_create (int fd,int size);uint32_t gem_create (int fd,uint64_t size);void gem_execbuf (int fd,struct drm_i915_gem_execbuffer2 *execbuf);@@ -67,6 +70,16 @@ bool gem_mmap__has_wc(int fd);void *gem_mmap__wc (int fd,uint32_t handle,uint64_t offset,uint64_t size,unsigned prot);/** +* gem_require_stolen_support: +* @fd: open i915 drm file descriptor +* +* Test macro to query whether support for allocating objects from stolen +* memory is available. Automatically skips through igt_require() if not. +*/ +#define gem_require_stolen_support (fd) \ + igt_require(gem_create__has_stolen_support(fd)) + +/** * gem_require_mmap_wc: * @fd: open i915 drm file descriptor * tests/Makefile.sources +1
-0@@ -55,6 +55,7 @@ TESTS_progs_M = \ gem_reset_stats \ gem_ringfill \ gem_set_tiling_vs_blt \ + gem_stolen \ gem_storedw_batches_loop \ gem_streaming_writes \ gem_tiled_blits \tests/gem_stolen.c new file +81
-0@@ -0,0 +1,363 @@ +/* +* Copyright © 2015 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +* IN THE SOFTWARE. +* +* Authors: +* Ankitprasad Sharma <ankitprasad.r.sharma at intel.com> +* +*/ + +/** @file gem_create_stolen.c +* +* This is a test for the extended gem_create ioctl, that includes allocation +* of object from stolen memory. +* +* The goal is to simply ensure the basics work, and invalid input combinations +* are rejected. +*/ + +#include <stdlib.h> +#include <sys/ioctl.h> +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <inttypes.h> +#include <errno.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <getopt.h> + +#include <drm.h> + +#include "ioctl_wrappers.h" +#include "intel_bufmgr.h" +#include "intel_batchbuffer.h" +#include "intel_io.h" +#include "intel_chipset.h" +#include "igt_aux.h" +#include "drmtest.h" +#include "drm.h" +#include "i915_drm.h" + +IGT_TEST_DESCRIPTION ("This test verifies the exetended gem_create ioctl," +" that includes allocation of obj from stolen region" ); +#define CLEAR (s) memset(&s, 0, sizeof(s)) +#define SIZE 1024*1024 +#define DWORD_SIZE 4 +#define DATA 0xdead +#define LARGE_SIZE 8*1024*1024*1024 +#define MAX_OBJECTS 100 + +static struct drm_intel_bufmgr *bufmgr; +static struct intel_batchbuffer *batch; + +static void verify_copy_op (drm_intel_bo *src,drm_intel_bo *dest) +{ +uint32_t *virt, i, ret; +/* Fill the src BO with dwords */ + ret =drm_intel_gem_bo_map_gtt (src); +igt_assert (!ret); + + virt = src->virtual; +for (i =0 ; i <SIZE /DWORD_SIZE ; i++) + virt[i] = i;
tests/gem_stolen.c line 91
Quoted 10 lines
tests/gem_stolen.c new file +10
-0+ +intel_copy_bo (batch, dest, src,SIZE ); + + ret =drm_intel_gem_bo_map_gtt (dest); +igt_assert (!ret); + + virt = dest->virtual; +/* verify */ +for (i =0 ; i <SIZE /DWORD_SIZE ; i++) +igt_assert (virt[i] == i);
You did not like suggestion to use igt_assert_eq?
Quoted 4 lines
tests/gem_stolen.c new file +4
-0+ +drm_intel_bo_unmap (src); +drm_intel_bo_unmap (dest); +}
tests/gem_stolen.c line 105
Quoted 10 lines
tests/gem_stolen.c new file +10
-0+ +static void stolen_pwrite (int fd) +{ +drm_intel_bo *bo; +uint32_t buf[SIZE /DWORD_SIZE ]; +uint32_t handle =0 ; +uint32_t *virt; +int i, ret =0 ; + +for (i =0 ; i <SIZE /DWORD_SIZE ; i ++)
Stray space remains. :)
Quoted 107 lines
tests/gem_stolen.c new file +107
-0+ buf[i] =DATA ; + +gem_require_stolen_support (fd); + + handle =gem_create_stolen (fd,SIZE ); + +gem_write (fd, handle,0 , buf,SIZE ); + bo =gem_handle_to_libdrm_bo (bufmgr, fd,"bo" , handle); + + ret =drm_intel_gem_bo_map_gtt (bo); +igt_assert (!ret); + + virt = bo->virtual; + +for (i =0 ; i <SIZE /DWORD_SIZE ; i ++) +igt_assert (virt[i] ==DATA ); + +drm_intel_bo_unmap (bo); +drm_intel_bo_unreference (bo); +gem_close (fd, handle); +} + +static void stolen_pread (int fd) +{ +drm_intel_bo *bo; +uint32_t buf[SIZE /DWORD_SIZE ]; +uint32_t handle =0 ; +uint32_t *virt; +int i, ret =0 ; + +CLEAR (buf); + +gem_require_stolen_support (fd); + + handle =gem_create_stolen (fd,SIZE ); + + bo =gem_handle_to_libdrm_bo (bufmgr, fd,"bo" , handle); + + ret =drm_intel_gem_bo_map_gtt (bo); +igt_assert (!ret); + + virt = bo->virtual; + +for (i =0 ; i <SIZE /DWORD_SIZE ; i ++) + virt[i] =DATA ; + +drm_intel_bo_unmap (bo); +drm_intel_bo_unreference (bo); + +gem_read (fd, handle,0 , buf,SIZE ); + +for (i =0 ; i <SIZE /DWORD_SIZE ; i ++) +igt_assert (buf[i] ==DATA ); + +gem_close (fd, handle); +} + +static void copy_test (int fd) +{ +drm_intel_bo *src, *dest; +uint32_t src_handle =0 , dest_handle =0 ; +int ret =0 ; + +gem_require_stolen_support (fd); + + src_handle =gem_create_stolen (fd,SIZE ); + dest_handle =gem_create_stolen (fd,SIZE ); + + src =gem_handle_to_libdrm_bo (bufmgr, fd,"src_bo" , src_handle); + dest =gem_handle_to_libdrm_bo (bufmgr, fd,"dst_bo" , dest_handle); + +igt_assert (src !=NULL ); +igt_assert (dest !=NULL ); + +verify_copy_op (src, dest); + +drm_intel_bo_unreference (src); +drm_intel_bo_unreference (dest); +gem_close (fd, src_handle); +gem_close (fd, dest_handle); +} + +static void verify_object_clear (int fd) +{ +drm_intel_bo *bo; +uint32_t handle =0 ; +uint32_t *virt; +int i, ret =0 ; + +gem_require_stolen_support (fd); + + handle =gem_create_stolen (fd,SIZE ); + + bo =gem_handle_to_libdrm_bo (bufmgr, fd,"verify_bo" , handle); +igt_assert (bo !=NULL ); + + ret =drm_intel_gem_bo_map_gtt (bo); +igt_assert (ret ==0 ); + +/* Verify if the BO is zeroed */ + virt = bo->virtual; +for (i =0 ; i <SIZE /DWORD_SIZE ; i++) +igt_assert (virt[i] ==0 ); + +drm_intel_bo_unmap (bo); +drm_intel_bo_unreference (bo); +gem_close (fd, handle);
tests/gem_stolen.c line 222
Quoted 10 lines
tests/gem_stolen.c new file +10
-0+} + +static void stolen_large_obj_alloc (int fd) +{ +uint32_t handle =0 ; + +gem_require_stolen_support (fd); + handle =__gem_create_stolen (fd,LARGE_SIZE ); +igt_assert (handle ==0 ); +}
I think we need one more subtest, which will overflow the 32-bit size by say one page. This would expose the bug in the kernel patch "[PATCH 2/4] drm/i915: Support for creating Stolen memory backed objects".
tests/gem_stolen.c line 227
Quoted 4 lines
tests/gem_stolen.c new file +4
-0+static void stolen_fill_purge_test (int fd) +{ +drm_intel_bo *bo; +int mret =0 , ret =0 , obj_count =0 , i =0 ;
mret and ret unused?
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v3 2/3 igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj
In reply to [email protected]From: Ankitprasad Sharma <[email protected]>
This patch adds support to verify pread/pwrite for non-shmem backed objects. It also shows the pread/pwrite speed.
It also tests speeds for pread with and without user side page faults
v2: Fixed Rebase conflicts (Ankit)
v3: Precalculating values to avoid redundant function calls (Dave) Replaced igt_subtest by igt_subtest_f, added asserts for mmap, corrected indentation (Tvrtko)
--- tests/gem_pread.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++--- tests/gem_pwrite.c | 54 ++++++++++++++++++++++++--- 2 files changed, 149 insertions(+), 11 deletions(-)
tests/gem_pread.c +100 -6
@@ -41,6 +41,10 @@#include "drmtest.h" #define OBJECT_SIZE 16384 +#define LARGE_OBJECT_SIZE 1024 * 1024 +#define KGRN "\x1B[32m" +#define KRED "\x1B[31m" +#define KNRM "\x1B[0m"static void do_gem_read (int fd,uint32_t handle,void *buf,int len,int loops) {
@@ -76,12 +80,16 @@ static const char *bytes_per_sec(char *buf, double v)uint32_t *src, dst; +uint32_t *dst_user, src_stolen, large_stolen; +uint32_t *stolen_pf_user, *stolen_nopf_user;int fd, count;int main (int argc,char **argv) {int object_size =0 ; +double usecs;uint32_t buf[20 ]; +char * bps; const struct { int level; const char *name;
@@ -106,6 +114,8 @@ int main(int argc, char **argv) dst =gem_create (fd, object_size); src =malloc (object_size); + src_stolen =gem_create_stolen (fd, object_size); + dst_user =malloc (object_size); } igt_subtest("normal") {
@@ -115,10 +125,10 @@ int main(int argc, char **argv)gettimeofday (&start,NULL );do_gem_read (fd, dst, src, object_size, count);gettimeofday (&end,NULL ); + usecs =elapsed (&start, &end, count); + bps =bytes_per_sec ((char *)buf, object_size/usecs*1e6 );igt_info ("Time to pread %d bytes x %6d: %7.3fµs, %s\n" , - object_size, count, -elapsed (&start, &end, count), -bytes_per_sec ((char *)buf, object_size/elapsed (&start, &end, count)*1e6 )); + object_size, count, usecs, bps);fflush (stdout); } }
@@ -133,18 +143,102 @@ int main(int argc, char **argv)gettimeofday (&start,NULL );do_gem_read (fd, dst, src, object_size, count);gettimeofday (&end,NULL ); + usecs =elapsed (&start, &end, count); + bps =bytes_per_sec ((char *)buf, object_size/usecs*1e6 );igt_info ("Time to %s pread %d bytes x %6d: %7.3fµs, %s\n" , - c->name, object_size, count, -elapsed (&start, &end, count), -bytes_per_sec ((char *)buf, object_size/elapsed (&start, &end, count)*1e6 )); + c->name, object_size, count, usecs, bps);fflush (stdout); } } } + igt_subtest("stolen-normal") { +for (count =1 ; count <=1 <<17 ; count <<=1 ) { +struct timeval start, end; + +gettimeofday (&start,NULL ); +do_gem_read (fd, src_stolen, dst_user, object_size, count); +gettimeofday (&end,NULL ); + usecs =elapsed (&start, &end, count); + bps =bytes_per_sec ((char *)buf, object_size/usecs*1e6 ); +igt_info ("Time to pread %d bytes x %6d: %7.3fµs, %s\n" , + object_size, count, usecs, bps); +fflush (stdout); + } + } +for (c = cache; c->level !=-1 ; c++) { + igt_subtest_f("stolen-%s", c->name) { +gem_set_caching (fd, src_stolen, c->level); + +for (count =1 ; count <=1 <<17 ; count <<=1 ) { +struct timeval start, end; + +gettimeofday (&start,NULL ); +do_gem_read (fd, src_stolen, dst_user, + object_size, count); +gettimeofday (&end,NULL ); + usecs =elapsed (&start, &end, count); + bps =bytes_per_sec ((char *)buf, object_size/usecs*1e6 ); +igt_info ("Time to stolen-%s pread %d bytes x %6d: %7.3fµs, %s\n" , + c->name, object_size, count, usecs, bps); +fflush (stdout); + } + } + } + +/* List the time taken in pread operation for stolen objects, with +* and without the overhead of page fault handling on accessing the +* user space buffer +*/ + igt_subtest("pagefault-pread") { + large_stolen =gem_create_stolen (fd,LARGE_OBJECT_SIZE ); + stolen_nopf_user = (uint32_t *)mmap (NULL ,LARGE_OBJECT_SIZE , +PROT_WRITE , +MAP_ANONYMOUS |MAP_PRIVATE , +-1 ,0 ); +igt_assert (stolen_nopf_user); + +for (count =1 ; count <=10 ; count ++) { +struct timeval start, end; +double t_elapsed =0 ; + +gettimeofday (&start,NULL ); +do_gem_read (fd, large_stolen, stolen_nopf_user, +LARGE_OBJECT_SIZE ,1 ); +gettimeofday (&end,NULL ); + t_elapsed =elapsed (&start, &end,1 ); + bps =bytes_per_sec ((char *)buf, object_size/t_elapsed*1e6 ); +igt_info ("Pagefault-N - Time to pread %d bytes: %7.3fµs, %s\n" , +LARGE_OBJECT_SIZE , t_elapsed, bps); + + stolen_pf_user = (uint32_t *)mmap (NULL ,LARGE_OBJECT_SIZE , +PROT_WRITE , +MAP_ANONYMOUS |MAP_PRIVATE , +-1 ,0 ); +igt_assert (stolen_pf_user); + +gettimeofday (&start,NULL ); +do_gem_read (fd, large_stolen, stolen_pf_user, +LARGE_OBJECT_SIZE ,1 ); +gettimeofday (&end,NULL ); + usecs =elapsed (&start, &end, count); + bps =bytes_per_sec ((char *)buf, object_size/usecs*1e6 ); +igt_info ("Pagefault-Y - Time to pread %d bytes: %7.3fµs, %s%s%s\n" , +LARGE_OBJECT_SIZE , usecs, + t_elapsed < usecs ?KGRN :KRED , bps,KNRM ); +fflush (stdout); +munmap (stolen_pf_user,LARGE_OBJECT_SIZE ); + } +munmap (stolen_nopf_user,LARGE_OBJECT_SIZE ); +gem_close (fd, large_stolen); + } + + igt_fixture {free (src);gem_close (fd, dst); +free (dst_user); +gem_close (fd, src_stolen);close (fd); }
tests/gem_pwrite.c +49 -5
98 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 2/3] igt/gem_pread: Support to verify pread/pwrite for non-shmem backed obj
Hi,
Quoted 36 lines · On 07/22/2015 02:45 PM, [email protected] wrote:
From: Ankitprasad Sharma <[email protected]>
This patch adds support to verify pread/pwrite for non-shmem backed objects. It also shows the pread/pwrite speed.
It also tests speeds for pread with and without user side page faultsv2: Fixed Rebase conflicts (Ankit)
v3: Precalculating values to avoid redundant function calls (Dave) Replaced
igt_subtestbyigt_subtest_f, added asserts for mmap, corrected indentation (Tvrtko)Signed-off-by Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>--- tests/gem_pread.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++--- tests/gem_pwrite.c | 54 ++++++++++++++++++++++++--- 2 files changed, 149 insertions(+), 11 deletions(-)tests/gem_pread.c +4
-0@@ -41,6 +41,10 @@#include "drmtest.h" #define OBJECT_SIZE 16384 +#define LARGE_OBJECT_SIZE 1024 * 1024 +#define KGRN "\x1B[32m" +#define KRED "\x1B[31m" +#define KNRM "\x1B[0m"static void do_gem_read (int fd,uint32_t handle,void *buf,int len,int loops) {@@ -76,12 +80,16 @@ static const char *bytes_per_sec(char *buf, double v)
tests/gem_pread.c static const char *bytes_per_sec(char *buf, double v) · line 91
Quoted 10 lines
tests/gem_pread.c +3
-0uint32_t *src, dst; +uint32_t *dst_user, src_stolen, large_stolen; +uint32_t *stolen_pf_user, *stolen_nopf_user;int fd, count;int main (int argc,char **argv) {int object_size =0 ; +double usecs;uint32_t buf[20 ];
Well you could have changed this to char buf[something big], all the users do (char *)buf and you have touched all (or at least a lot of) lines which do that...
Quoted 153 lines
tests/gem_pread.c +93
-6+char * bps; const struct { int level; const char *name;@@ -106,6 +114,8 @@ int main(int argc, char **argv) dst =gem_create (fd, object_size); src =malloc (object_size); + src_stolen =gem_create_stolen (fd, object_size); + dst_user =malloc (object_size); } igt_subtest("normal") {@@ -115,10 +125,10 @@ int main(int argc, char **argv)gettimeofday (&start,NULL );do_gem_read (fd, dst, src, object_size, count);gettimeofday (&end,NULL ); + usecs =elapsed (&start, &end, count); + bps =bytes_per_sec ((char *)buf, object_size/usecs*1e6 );igt_info ("Time to pread %d bytes x %6d: %7.3fµs, %s\n" , - object_size, count, -elapsed (&start, &end, count), -bytes_per_sec ((char *)buf, object_size/elapsed (&start, &end, count)*1e6 )); + object_size, count, usecs, bps);fflush (stdout); } }@@ -133,18 +143,102 @@ int main(int argc, char **argv)gettimeofday (&start,NULL );do_gem_read (fd, dst, src, object_size, count);gettimeofday (&end,NULL ); + usecs =elapsed (&start, &end, count); + bps =bytes_per_sec ((char *)buf, object_size/usecs*1e6 );igt_info ("Time to %s pread %d bytes x %6d: %7.3fµs, %s\n" , - c->name, object_size, count, -elapsed (&start, &end, count), -bytes_per_sec ((char *)buf, object_size/elapsed (&start, &end, count)*1e6 )); + c->name, object_size, count, usecs, bps);fflush (stdout); } } } + igt_subtest("stolen-normal") { +for (count =1 ; count <=1 <<17 ; count <<=1 ) { +struct timeval start, end; + +gettimeofday (&start,NULL ); +do_gem_read (fd, src_stolen, dst_user, object_size, count); +gettimeofday (&end,NULL ); + usecs =elapsed (&start, &end, count); + bps =bytes_per_sec ((char *)buf, object_size/usecs*1e6 ); +igt_info ("Time to pread %d bytes x %6d: %7.3fµs, %s\n" , + object_size, count, usecs, bps); +fflush (stdout); + } + } +for (c = cache; c->level !=-1 ; c++) { + igt_subtest_f("stolen-%s", c->name) { +gem_set_caching (fd, src_stolen, c->level); + +for (count =1 ; count <=1 <<17 ; count <<=1 ) { +struct timeval start, end; + +gettimeofday (&start,NULL ); +do_gem_read (fd, src_stolen, dst_user, + object_size, count); +gettimeofday (&end,NULL ); + usecs =elapsed (&start, &end, count); + bps =bytes_per_sec ((char *)buf, object_size/usecs*1e6 ); +igt_info ("Time to stolen-%s pread %d bytes x %6d: %7.3fµs, %s\n" , + c->name, object_size, count, usecs, bps); +fflush (stdout); + } + } + } + +/* List the time taken in pread operation for stolen objects, with +* and without the overhead of page fault handling on accessing the +* user space buffer +*/ + igt_subtest("pagefault-pread") { + large_stolen =gem_create_stolen (fd,LARGE_OBJECT_SIZE ); + stolen_nopf_user = (uint32_t *)mmap (NULL ,LARGE_OBJECT_SIZE , +PROT_WRITE , +MAP_ANONYMOUS |MAP_PRIVATE , +-1 ,0 ); +igt_assert (stolen_nopf_user); + +for (count =1 ; count <=10 ; count ++) { +struct timeval start, end; +double t_elapsed =0 ; + +gettimeofday (&start,NULL ); +do_gem_read (fd, large_stolen, stolen_nopf_user, +LARGE_OBJECT_SIZE ,1 ); +gettimeofday (&end,NULL ); + t_elapsed =elapsed (&start, &end,1 ); + bps =bytes_per_sec ((char *)buf, object_size/t_elapsed*1e6 ); +igt_info ("Pagefault-N - Time to pread %d bytes: %7.3fµs, %s\n" , +LARGE_OBJECT_SIZE , t_elapsed, bps); + + stolen_pf_user = (uint32_t *)mmap (NULL ,LARGE_OBJECT_SIZE , +PROT_WRITE , +MAP_ANONYMOUS |MAP_PRIVATE , +-1 ,0 ); +igt_assert (stolen_pf_user); + +gettimeofday (&start,NULL ); +do_gem_read (fd, large_stolen, stolen_pf_user, +LARGE_OBJECT_SIZE ,1 ); +gettimeofday (&end,NULL ); + usecs =elapsed (&start, &end, count); + bps =bytes_per_sec ((char *)buf, object_size/usecs*1e6 ); +igt_info ("Pagefault-Y - Time to pread %d bytes: %7.3fµs, %s%s%s\n" , +LARGE_OBJECT_SIZE , usecs, + t_elapsed < usecs ?KGRN :KRED , bps,KNRM ); +fflush (stdout); +munmap (stolen_pf_user,LARGE_OBJECT_SIZE ); + } +munmap (stolen_nopf_user,LARGE_OBJECT_SIZE ); +gem_close (fd, large_stolen); + } + + igt_fixture {free (src);gem_close (fd, dst); +free (dst_user); +gem_close (fd, src_stolen);close (fd); }tests/gem_pwrite.c +3
-0@@ -135,11 +135,14 @@ static void test_big_gtt(int fd, int scale) }uint32_t *src, dst; +uint32_t *src_user, dst_stolen;int fd;int main (int argc,char **argv) {int object_size =0 ; +double usecs; +char * bps;uint32_t buf[20 ];int count; const struct {
tests/gem_pwrite.c int main(int argc, char **argv) · line 158
Quoted 6 lines
tests/gem_pwrite.c +3
-0@@ -150,6 +153,9 @@ int main(int argc, char **argv) { 1, "snoop" }, { 2, "display" }, { -1 }, + { -1, "stolen-uncached"}, + { -1, "stolen-snoop"}, + { -1, "stolen-display"},
Oh you kept this hack and corresponding "c + 4" here. ;(
Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v3 3/3 igt/gem_create: Test to validate parameters for GEM_CREATE ioctl
In reply to [email protected]From: Ankitprasad Sharma <[email protected]>
This test validates the two parameters (size and flags) GEM_CREATE ioctl.
v2: Added IGT_TEST_DESCRIPTION (Thomas Wood)
v3: Removed use of hard coded values, updated comments (Tvrtko)
--- tests/Makefile.sources | 1 + tests/gem_create.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 171 insertions(+) create mode 100644 tests/gem_create.c
tests/Makefile.sources +1 -0
@@ -15,6 +15,7 @@ TESTS_progs_M = \ gem_close_race \ gem_concurrent_blit \ gem_concurrent_all \ + gem_create \ gem_cs_tlb \ gem_ctx_param_basic \ gem_ctx_bad_exec \
tests/gem_create.c new file +170 -0
170 lines not on this page · raw message
Signature · 6 lines
1.9.1 _______________________________________________ Intel-gfx mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Re: [PATCH 3/3] igt/gem_create: Test to validate parameters for GEM_CREATE ioctl
Hi,
Quoted 139 lines · On 07/22/2015 02:45 PM, [email protected] wrote:
From: Ankitprasad Sharma <[email protected]>
This test validates the two parameters (size and flags)
GEM_CREATEioctl.v2: Added
IGT_TEST_DESCRIPTION(Thomas Wood)v3: Removed use of hard coded values, updated comments (Tvrtko)
Signed-off-by Ankitprasad Sharma <ankitprasad.r.sharma at intel.com>--- tests/Makefile.sources | 1 + tests/gem_create.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 171 insertions(+)create mode 100644
tests/gem_create.ctests/Makefile.sources +1
-0@@ -15,6 +15,7 @@ TESTS_progs_M = \ gem_close_race \ gem_concurrent_blit \ gem_concurrent_all \ + gem_create \ gem_cs_tlb \ gem_ctx_param_basic \ gem_ctx_bad_exec \tests/gem_create.c new file +106
-0@@ -0,0 +1,170 @@ +/* +* Copyright © 2015 Intel Corporation +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +* IN THE SOFTWARE. +* +* Authors: +* Ankitprasad Sharma <ankitprasad.r.sharma at intel.com> +* +*/ + +/** @file gem_create.c +* +* This is a test for the extended and old gem_create ioctl, that +* includes allocation of object from stolen memory and shmem. +* +* The goal is to simply ensure that basics work and invalid input +* combinations are rejected. +*/ + +#include <stdlib.h> +#include <sys/ioctl.h> +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <inttypes.h> +#include <errno.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <getopt.h> + +#include <drm.h> + +#include "ioctl_wrappers.h" +#include "intel_bufmgr.h" +#include "intel_batchbuffer.h" +#include "intel_io.h" +#include "intel_chipset.h" +#include "igt_aux.h" +#include "drmtest.h" +#include "drm.h" +#include "i915_drm.h" + +IGT_TEST_DESCRIPTION ("This is a test for the extended & old gem_create ioctl," +" that includes allocation of object from stolen memory" +" and shmem" ); + +#define CLEAR (s) memset(&s, 0, sizeof(s)) +#define UNALIGNED_SIZE (PAGE_SIZE - (2*1024)) +#define VALID_OFFSET (PAGE_SIZE - 1024) +#define INVALID_OFFSET (PAGE_SIZE + 1024) +#define LENGTH 256 +#define DWORD_SIZE 4 + +struct local_i915_gem_create_v2 { +uint64_t size; +uint32_t handle; +uint32_t pad; +#define I915_CREATE_PLACEMENT_STOLEN (1<<0) +uint32_t flags; +} create; + +#define LOCAL_IOCTL_I915_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_I915_GEM_CREATE, struct local_i915_gem_create_v2) + +static void invalid_flag_test (int fd) +{ +int ret; + +gem_require_stolen_support (fd); + + create.handle =0 ; + create.size =PAGE_SIZE ; + create.flags = ~I915_CREATE_PLACEMENT_STOLEN ; + ret =drmIoctl (fd,LOCAL_IOCTL_I915_GEM_CREATE , &create); + +igt_assert (ret <=0 ); + + create.flags = ~0 ; + ret =drmIoctl (fd,LOCAL_IOCTL_I915_GEM_CREATE , &create); + +igt_assert (ret <=0 ); +} + +static void invalid_size_test (int fd) +{ +int handle; + + handle =__gem_create (fd,0 ); +igt_assert (handle ==0 ); +}
tests/gem_create.c line 116
Quoted 10 lines
tests/gem_create.c new file +10
-0+ +/* +* Creating an object with non-aligned size and trying to access it with an +* offset, which is greater than the requested size but smaller than the +* object's last page boundary. pwrite here must be successful. +*/ +static void valid_nonaligned_size (int fd) +{ +int handle, i; +uint32_t buf[PAGE_SIZE /DWORD_SIZE ];
char buf[PAGE_SIZE] and then don't need DWORD_SIZE?
tests/gem_create.c line 121
Quoted 5 lines
tests/gem_create.c new file +4
-0+ + handle =gem_create (fd,UNALIGNED_SIZE ); +igt_assert (handle !=0 ); +gem_write (fd, handle,VALID_OFFSET , buf,LENGTH );
In general this is a bit unreadable since you a lot of macros and reader must jump up and down to figure out what is happening.
Would something simpler just as below be as good and much more readable?
static void ...
{
char buf[PAGE_SIZE];
handle = gem_create(fd, PAGE_SIZE / 2);
igt_assert(handle);
gem_write(fd, handle, 0, buf, PAGE_SIZE);
// or
gem_write(fd, handle, PAGE_SIZE / 2, buf, PAGE_SIZE / 2);
// or even both
gem_close(handle);
}Quoted 12 lines
tests/gem_create.c new file +12
-0+gem_close (fd, handle); +} + +/* +* Creating an object with non-aligned size and trying to access it with an +* offset, which is greater than the requested size and larger than the +* object's last page boundary. pwrite here must fail. +*/ +static void invalid_nonaligned_size (int fd) +{ +int handle, i; +uint32_t buf[PAGE_SIZE /DWORD_SIZE ];
tests/gem_create.c line 144
Quoted 10 lines
tests/gem_create.c new file +10
-0+struct drm_i915_gem_pwrite gem_pwrite; + + handle =gem_create (fd,UNALIGNED_SIZE ); + +CLEAR (gem_pwrite); + gem_pwrite.handle = handle; + gem_pwrite.offset =INVALID_OFFSET ; + gem_pwrite.size =LENGTH ; + gem_pwrite.data_ptr = (uintptr_t )buf; +igt_assert (drmIoctl (fd,DRM_IOCTL_I915_GEM_PWRITE , &gem_pwrite) !=0 );
Not sure if you should check for a specific errno here. Wouldn't harm I suppose. Plus again (just in principle, not exact code):
static void ...
{
char buf[PAGE_SIZE];
handle = gem_create(fd, PAGE_SIZE / 2);
igt_assert(handle);
// assert all fails
gem_write(fd, handle, PAGE_SIZE, buf, 1);
gem_write(fd, handle, PAGE_SIZE / 2, buf, PAGE_SIZE / 2 + 1);
gem_close(handle);
}Regards,
Tvrtko
_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx