<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Wed, Oct 17, 2018 at 6:47 PM Rafael Antognolli <<a href="mailto:rafael.antognolli@intel.com">rafael.antognolli@intel.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Wed, Oct 17, 2018 at 06:08:34PM +0300, Danylo Piliaiev wrote:<br>
> Signed-off-by: Danylo Piliaiev <<a href="mailto:danylo.piliaiev@globallogic.com" target="_blank">danylo.piliaiev@globallogic.com</a>><br>
> ---<br>
> src/intel/tools/intel_sanitize_gpu.c | 38 +++++++++++++++-------------<br>
> 1 file changed, 20 insertions(+), 18 deletions(-)<br>
> <br>
> diff --git a/src/intel/tools/intel_sanitize_gpu.c b/src/intel/tools/intel_sanitize_gpu.c<br>
> index 9b49b0bbf2..36c4725a2f 100644<br>
> --- a/src/intel/tools/intel_sanitize_gpu.c<br>
> +++ b/src/intel/tools/intel_sanitize_gpu.c<br>
> @@ -51,14 +51,6 @@ static int (*libc_fcntl)(int fd, int cmd, int param);<br>
> <br>
> #define DRM_MAJOR 226<br>
> <br>
> -/* TODO: we want to make sure that the padding forces<br>
> - * the BO to take another page on the (PP)GTT; 4KB<br>
> - * may or may not be the page size for the BO. Indeed,<br>
> - * depending on GPU, kernel version and GEM size, the<br>
> - * page size can be one of 4KB, 64KB or 2M.<br>
> - */<br>
> -#define PADDING_SIZE 4096<br>
> -<br>
> struct refcnt_hash_table {<br>
> struct hash_table *t;<br>
> int refcnt;<br>
> @@ -80,6 +72,8 @@ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;<br>
> <br>
> static struct hash_table *fds_to_bo_sizes = NULL;<br>
> <br>
> +static long padding_size = 0;<br>
> +<br>
> static inline struct hash_table*<br>
> bo_size_table(int fd)<br>
> {<br>
> @@ -166,7 +160,7 @@ padding_is_good(int fd, uint32_t handle)<br>
> struct drm_i915_gem_mmap mmap_arg = {<br>
> .handle = handle,<br>
> .offset = bo_size(fd, handle),<br>
> - .size = PADDING_SIZE,<br>
> + .size = padding_size,<br>
> .flags = 0,<br>
> };<br>
> <br>
> @@ -189,17 +183,17 @@ padding_is_good(int fd, uint32_t handle)<br>
> * if the bo is not cache coherent we likely need to<br>
> * invalidate the cache lines to get it.<br>
> */<br>
> - gen_invalidate_range(mapped, PADDING_SIZE);<br>
> + gen_invalidate_range(mapped, padding_size);<br>
> <br>
> expected_value = handle & 0xFF;<br>
> - for (uint32_t i = 0; i < PADDING_SIZE; ++i) {<br>
> + for (uint32_t i = 0; i < padding_size; ++i) {<br>
> if (expected_value != mapped[i]) {<br>
> - munmap(mapped, PADDING_SIZE);<br>
> + munmap(mapped, padding_size);<br>
> return false;<br>
> }<br>
> expected_value = next_noise_value(expected_value);<br>
> }<br>
> - munmap(mapped, PADDING_SIZE);<br>
> + munmap(mapped, padding_size);<br>
> <br>
> return true;<br>
> }<br>
> @@ -207,9 +201,9 @@ padding_is_good(int fd, uint32_t handle)<br>
> static int<br>
> create_with_padding(int fd, struct drm_i915_gem_create *create)<br>
> {<br>
> - create->size += PADDING_SIZE;<br>
> + create->size += padding_size;<br>
> int ret = libc_ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, create);<br>
> - create->size -= PADDING_SIZE;<br>
> + create->size -= padding_size;<br>
> <br>
> if (ret != 0)<br>
> return ret;<br>
> @@ -218,7 +212,7 @@ create_with_padding(int fd, struct drm_i915_gem_create *create)<br>
> struct drm_i915_gem_mmap mmap_arg = {<br>
> .handle = create->handle,<br>
> .offset = create->size,<br>
> - .size = PADDING_SIZE,<br>
> + .size = padding_size,<br>
> .flags = 0,<br>
> };<br>
> <br>
> @@ -228,8 +222,8 @@ create_with_padding(int fd, struct drm_i915_gem_create *create)<br>
> <br>
> noise_values = (uint8_t*) (uintptr_t) mmap_arg.addr_ptr;<br>
> fill_noise_buffer(noise_values, create->handle & 0xFF,<br>
> - PADDING_SIZE);<br>
> - munmap(noise_values, PADDING_SIZE);<br>
> + padding_size);<br>
> + munmap(noise_values, padding_size);<br>
> <br>
> _mesa_hash_table_insert(bo_size_table(fd), (void*)(uintptr_t)create->handle,<br>
> (void*)(uintptr_t)create->size);<br>
> @@ -427,4 +421,12 @@ init(void)<br>
> libc_close = dlsym(RTLD_NEXT, "close");<br>
> libc_fcntl = dlsym(RTLD_NEXT, "fcntl");<br>
> libc_ioctl = dlsym(RTLD_NEXT, "ioctl");<br>
> +<br>
> + /* We want to make sure that the padding forces<br>
> + * the BO to take another page on the (PP)GTT.<br>
> + */<br>
> + padding_size = sysconf(_SC_PAGESIZE);<br>
<br>
I don't think this is the page size we want. This is the page size of<br>
CPU/system memory, which might be different from what the GPU is using<br>
to map pages. For instance, even if we are using 64K pages for GPU<br>
mapping, I think this call would still return 4K.<br>
<br>
Though I'm not sure if there's an interface to query the kernel which<br>
page size we are using for the GPU...<br>
<br></blockquote><div><br></div><div>I looked a second time at the kernel code and indeed I somehow missed this,<br>
The page size may be even different between allocation and easily different<br>
from CPU page size. My patch makes no sense, sorry.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> + if (padding_size == -1) {<br>
> + unreachable("Bad page size");<br>
> + }<br>
> }<br>
> -- <br>
> 2.18.0<br>
> <br>
> _______________________________________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
> <a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</blockquote></div></div>