[Pixman] [PATCH 2/3] utils.[ch]: add fence_get_page_size()

Oded Gabbay oded.gabbay at gmail.com
Tue Sep 8 07:03:05 PDT 2015


On Tue, Sep 8, 2015 at 10:27 AM, Pekka Paalanen <ppaalanen at gmail.com> wrote:
> From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
>
> Add a function to get the page size used for memory fence purposes, and
> use it everywhere where getpagesize() was used.
>
> This offers a single point in code to override the page size, in case
> one wants to experiment how the tests work with a higher page size than
> what the developer's machine has.
>
> This also offers a clean API, without adding #ifdefs, to tests for
> checking the page size.
>
> Signed-off-by: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
> ---
>  test/utils.c | 21 ++++++++++++++++++---
>  test/utils.h |  4 ++++
>  2 files changed, 22 insertions(+), 3 deletions(-)
>
> diff --git a/test/utils.c b/test/utils.c
> index 9089ffc..222d4d5 100644
> --- a/test/utils.c
> +++ b/test/utils.c
> @@ -382,6 +382,15 @@ typedef struct
>
>  #if FENCE_MALLOC_ACTIVE
>
> +unsigned long
> +fence_get_page_size ()
> +{
> +    /* You can fake a page size here, if you want to test e.g. 64 kB
> +     * pages on a 4 kB page system. Just put a multiplier below.
> +     */
> +    return getpagesize ();
> +}
> +
>  /* This is apparently necessary on at least OS X */
>  #ifndef MAP_ANONYMOUS
>  #define MAP_ANONYMOUS MAP_ANON
> @@ -390,7 +399,7 @@ typedef struct
>  void *
>  fence_malloc (int64_t len)
>  {
> -    unsigned long page_size = getpagesize();
> +    unsigned long page_size = fence_get_page_size ();
>      unsigned long page_mask = page_size - 1;
>      uint32_t n_payload_bytes = (len + page_mask) & ~page_mask;
>      uint32_t n_bytes =
> @@ -439,7 +448,7 @@ fence_malloc (int64_t len)
>  void
>  fence_free (void *data)
>  {
> -    uint32_t page_size = getpagesize();
> +    uint32_t page_size = fence_get_page_size ();
>      uint8_t *payload = data;
>      uint8_t *leading_protected = payload - N_LEADING_PROTECTED * page_size;
>      uint8_t *initial_page = leading_protected - page_size;
> @@ -472,7 +481,7 @@ fence_image_create_bits (pixman_format_code_t format,
>                           int height,
>                           pixman_bool_t stride_fence)
>  {
> -    unsigned page_size = getpagesize();
> +    unsigned page_size = fence_get_page_size ();
>      unsigned page_mask = page_size - 1;
>      unsigned bitspp = PIXMAN_FORMAT_BPP (format);
>      unsigned bits_boundary;
> @@ -565,6 +574,12 @@ fence_image_create_bits (pixman_format_code_t format,
>       */
>  }
>
> +unsigned long
> +fence_get_page_size ()
> +{
> +    return 0;
> +}
> +
>  #endif /* FENCE_MALLOC_ACTIVE */
>
>  uint8_t *
> diff --git a/test/utils.h b/test/utils.h
> index 5aae554..e299d1d 100644
> --- a/test/utils.h
> +++ b/test/utils.h
> @@ -112,6 +112,10 @@ fence_image_create_bits (pixman_format_code_t format,
>                           int height,
>                           pixman_bool_t stride_fence);
>
> +/* Return the page size if FENCE_MALLOC_ACTIVE, or zero otherwise */
> +unsigned long
> +fence_get_page_size ();
> +
>  /* Generate n_bytes random bytes in fence_malloced memory */
>  uint8_t *
>  make_random_bytes (int n_bytes);
> --
> 2.4.6
>
> _______________________________________________
> Pixman mailing list
> Pixman at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/pixman

Reviewed-by: Oded Gabbay <oded.gabbay at gmail.com>


More information about the Pixman mailing list