lib: add intel_get_total_swap_mb

Test that try to exercise the swap paths need to check whether swap is
available, otherwise they'll just oom.

Signed-Off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
This commit is contained in:
Daniel Vetter 2012-01-22 19:24:48 +01:00
parent 7132d0f977
commit 1a9fa8fd12
2 changed files with 22 additions and 0 deletions

View File

@ -106,3 +106,24 @@ intel_get_total_ram_mb(void)
return retval / (1024*1024);
}
uint64_t
intel_get_total_swap_mb(void)
{
uint64_t retval;
#ifdef HAVE_STRUCT_SYSINFO_TOTALRAM /* Linux */
struct sysinfo sysinf;
int ret;
ret = sysinfo(&sysinf);
assert(ret == 0);
retval = sysinf.totalswap;
retval *= sysinf.mem_unit;
#else
#error "Unknown how to get swap size for this OS"
#endif
return retval / (1024*1024);
}

View File

@ -81,6 +81,7 @@ struct pci_device *intel_get_pci_device(void);
uint32_t intel_get_drm_devid(int fd);
int intel_gen(uint32_t devid);
uint64_t intel_get_total_ram_mb(void);
uint64_t intel_get_total_swap_mb(void);
void intel_map_file(char *);