[Intel-gfx] [PATCH i-g-t 2/5] gem_wsim: Round mmap to page size

Tvrtko Ursulin tvrtko.ursulin at linux.intel.com
Thu Feb 28 14:18:25 UTC 2019


From: Tvrtko Ursulin <tvrtko.ursulin at intel.com>

mmap(2) mandates size is page aligned.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
---
 benchmarks/gem_wsim.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/benchmarks/gem_wsim.c b/benchmarks/gem_wsim.c
index 0a5abc08d8c2..57ceb983cf82 100644
--- a/benchmarks/gem_wsim.c
+++ b/benchmarks/gem_wsim.c
@@ -737,6 +737,7 @@ init_bb(struct w_step *w, unsigned int flags)
 {
 	const unsigned int arb_period =
 			get_bb_sz(w->preempt_us) / sizeof(uint32_t);
+	const unsigned int mmap_len = ALIGN(w->bb_sz, 4096);
 	unsigned int i;
 	uint32_t *ptr;
 
@@ -746,12 +747,12 @@ init_bb(struct w_step *w, unsigned int flags)
 	gem_set_domain(fd, w->bb_handle,
 		       I915_GEM_DOMAIN_WC, I915_GEM_DOMAIN_WC);
 
-	ptr = gem_mmap__wc(fd, w->bb_handle, 0, w->bb_sz, PROT_WRITE);
+	ptr = gem_mmap__wc(fd, w->bb_handle, 0, mmap_len, PROT_WRITE);
 
 	for (i = arb_period; i < w->bb_sz / sizeof(uint32_t); i += arb_period)
 		ptr[i] = 0x5 << 23; /* MI_ARB_CHK */
 
-	munmap(ptr, w->bb_sz);
+	munmap(ptr, mmap_len);
 }
 
 static void
@@ -771,7 +772,7 @@ terminate_bb(struct w_step *w, unsigned int flags)
 		batch_start -= 12 * sizeof(uint32_t);
 
 	mmap_start = rounddown(batch_start, PAGE_SIZE);
-	mmap_len = w->bb_sz - mmap_start;
+	mmap_len = ALIGN(w->bb_sz - mmap_start, PAGE_SIZE);
 
 	gem_set_domain(fd, w->bb_handle,
 		       I915_GEM_DOMAIN_WC, I915_GEM_DOMAIN_WC);
-- 
2.19.1



More information about the Intel-gfx mailing list