Factor in kernel object overhead when checking available memory for tests

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
This commit is contained in:
Chris Wilson
2014-05-28 09:01:56 +01:00
parent e4ba3b75e6
commit 321273ff76
5 changed files with 49 additions and 17 deletions
+4
View File
@@ -77,4 +77,8 @@ uint64_t intel_get_avail_ram_mb(void);
uint64_t intel_get_total_ram_mb(void);
uint64_t intel_get_total_swap_mb(void);
bool intel_check_memory(uint32_t count, uint32_t size, unsigned mode);
#define CHECK_RAM 0x1
#define CHECK_SWAP 0x2
#endif /* IGT_AUX_H */
+30
View File
@@ -185,6 +185,36 @@ intel_get_total_swap_mb(void)
return retval / (1024*1024);
}
bool intel_check_memory(uint32_t count, uint32_t size, unsigned mode)
{
/* rough estimate of how many bytes the kernel requires to track each object */
#define KERNEL_BO_OVERHEAD 512
uint64_t required, total;
required = count;
required *= size + KERNEL_BO_OVERHEAD;
required = ALIGN(required, 4096);
total = 0;
if (mode & (CHECK_RAM | CHECK_SWAP))
total += intel_get_avail_ram_mb();
if (mode & CHECK_SWAP)
total += intel_get_total_swap_mb();
total *= 1024 * 1024;
if (total <= required) {
igt_log(IGT_LOG_INFO,
"Estimated that we need %llu bytes for the test, but only have %llu bytes available (%s%s)\n",
(long long)required, (long long)total,
mode & CHECK_RAM ? "RAM" : "",
mode & CHECK_SWAP ? " + swap": "");
return 0;
}
return 1;
}
void
intel_purge_vm_caches(void)
{