[Mesa-dev] [PATCH 05/14] anv: use POSIX sysconf to get memory info on non-glibc systems

Emil Velikov emil.l.velikov at gmail.com
Thu Jan 18 17:23:06 UTC 2018


On 31 December 2017 at 16:55, Greg V <greg at unrelenting.technology> wrote:
> ---
>  src/intel/vulkan/anv_device.c | 7 +++++++
>  1 file changed, 7 insertions(+)
>
> diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
> index 6f77d33f93..2d3062d103 100644
> --- a/src/intel/vulkan/anv_device.c
> +++ b/src/intel/vulkan/anv_device.c
> @@ -25,7 +25,9 @@
>  #include <stdbool.h>
>  #include <string.h>
>  #include <sys/mman.h>
> +#ifdef __GLIBC__
>  #include <sys/sysinfo.h>
> +#endif
>  #include <unistd.h>
>  #include <fcntl.h>
>  #include <xf86drm.h>
> @@ -79,10 +81,15 @@ anv_compute_heap_size(int fd, uint64_t *heap_size)
>     }
>
>     /* Query the total ram from the system */
> +#ifdef __GLIBC__
>     struct sysinfo info;
>     sysinfo(&info);
>
>     uint64_t total_ram = (uint64_t)info.totalram * (uint64_t)info.mem_unit;
> +#else
> +   uint64_t total_ram = sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGE_SIZE);
> +#endif
> +
Hmm we seems to be having this type of code in a new places already.
Can I interest you in making a (static inline) helper in src/util and
folding all the duplicated get_total_phys_memory implementations?

The instance in os_misc.c seems to be the most complete one.

-Emil


More information about the mesa-dev mailing list