mirror of
				https://github.com/tiagovignatti/intel-gpu-tools.git
				synced 2025-11-04 12:07:12 +00:00 
			
		
		
		
	lib: add a function to lock memory into RAM
Add a function to lock memory into RAM and use it in the
gem_tiled_swapping test to reduce the amount of allocated memory
required to force swapping. This also reduces the amount of time
required for the test to complete, since the data set is smaller.
The following durations were recorded with gem_tiled_swapping on a
haswell system before the change:
  Subtest non-threaded: SUCCESS (55.889s)
  Subtest threaded: SUCCESS (810.532s)
and after:
  Subtest non-threaded: SUCCESS (11.804s)
  Subtest threaded: SUCCESS (268.336s)
v2: add various assertions and requirements and make sure
    gem_tiled_swapping works on systems with less RAM (Daniel Vetter)
v3: fix allocation size calculation
Signed-off-by: Thomas Wood <thomas.wood@intel.com>
			
			
This commit is contained in:
		
							parent
							
								
									5fe9c88bda
								
							
						
					
					
						commit
						42b02c284e
					
				@ -601,3 +601,61 @@ struct type_name connector_type_names[] = {
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
type_name_fn(connector_type)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * igt_lock_mem:
 | 
			
		||||
 * @size: the amount of memory to lock into RAM, in MB
 | 
			
		||||
 *
 | 
			
		||||
 * Allocate @size MB of memory and lock it into RAM. This releases any
 | 
			
		||||
 * previously locked memory.
 | 
			
		||||
 *
 | 
			
		||||
 * Use #igt_unlock_mem to release the currently locked memory.
 | 
			
		||||
 */
 | 
			
		||||
static char *locked_mem;
 | 
			
		||||
static size_t locked_size;
 | 
			
		||||
 | 
			
		||||
void igt_lock_mem(size_t size)
 | 
			
		||||
{
 | 
			
		||||
	long pagesize = sysconf(_SC_PAGESIZE);
 | 
			
		||||
	size_t i;
 | 
			
		||||
	int ret;
 | 
			
		||||
 | 
			
		||||
	if (size == 0) {
 | 
			
		||||
		return;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (locked_mem) {
 | 
			
		||||
		igt_unlock_mem();
 | 
			
		||||
		igt_warn("Unlocking previously locked memory.\n");
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	locked_size = size * 1024 * 1024;
 | 
			
		||||
 | 
			
		||||
	locked_mem = malloc(locked_size);
 | 
			
		||||
	igt_require_f(locked_mem,
 | 
			
		||||
		      "Could not allocate enough memory to lock.\n");
 | 
			
		||||
 | 
			
		||||
	/* write into each page to ensure it is allocated */
 | 
			
		||||
	for (i = 0; i < locked_size; i += pagesize)
 | 
			
		||||
		locked_mem[i] = i;
 | 
			
		||||
 | 
			
		||||
	ret = mlock(locked_mem, locked_size);
 | 
			
		||||
	igt_assert_f(ret == 0, "Could not lock memory into RAM.\n");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * igt_unlock_mem:
 | 
			
		||||
 *
 | 
			
		||||
 * Release and free the RAM used by #igt_lock_mem.
 | 
			
		||||
 */
 | 
			
		||||
void igt_unlock_mem(void)
 | 
			
		||||
{
 | 
			
		||||
	if (!locked_mem)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	munlock(locked_mem, locked_size);
 | 
			
		||||
 | 
			
		||||
	free(locked_mem);
 | 
			
		||||
	locked_mem = NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -96,4 +96,7 @@ void intel_require_memory(uint32_t count, uint32_t size, unsigned mode);
 | 
			
		||||
	(b) = _tmp;		\
 | 
			
		||||
} while (0)
 | 
			
		||||
 | 
			
		||||
void igt_lock_mem(size_t size);
 | 
			
		||||
void igt_unlock_mem(void);
 | 
			
		||||
 | 
			
		||||
#endif /* IGT_AUX_H */
 | 
			
		||||
 | 
			
		||||
@ -70,6 +70,7 @@ IGT_TEST_DESCRIPTION("Exercise swizzle code for swapping.");
 | 
			
		||||
static uint32_t current_tiling_mode;
 | 
			
		||||
 | 
			
		||||
#define PAGE_SIZE 4096
 | 
			
		||||
#define AVAIL_RAM 512
 | 
			
		||||
 | 
			
		||||
static uint32_t
 | 
			
		||||
create_bo_and_fill(int fd)
 | 
			
		||||
@ -151,13 +152,20 @@ igt_main
 | 
			
		||||
	int fd, n, count, num_threads;
 | 
			
		||||
 | 
			
		||||
	igt_fixture {
 | 
			
		||||
		size_t lock_size;
 | 
			
		||||
 | 
			
		||||
		current_tiling_mode = I915_TILING_X;
 | 
			
		||||
 | 
			
		||||
		intel_purge_vm_caches();
 | 
			
		||||
 | 
			
		||||
		fd = drm_open_any();
 | 
			
		||||
 | 
			
		||||
		/* lock RAM, leaving only 512MB available */
 | 
			
		||||
		lock_size = max(0, intel_get_total_ram_mb() - AVAIL_RAM);
 | 
			
		||||
		igt_lock_mem(lock_size);
 | 
			
		||||
 | 
			
		||||
		/* need slightly more than available memory */
 | 
			
		||||
		count = intel_get_total_ram_mb() + intel_get_total_swap_mb() / 4;
 | 
			
		||||
		count = min(intel_get_total_ram_mb(), AVAIL_RAM) * 1.25;
 | 
			
		||||
		bo_handles = calloc(count, sizeof(uint32_t));
 | 
			
		||||
		igt_assert(bo_handles);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user