[Mesa-dev] [PATCH 01/15] ralloc: don't memset ralloc_header, clear it manually
Emil Velikov
emil.l.velikov at gmail.com
Fri Oct 14 15:28:58 UTC 2016
On 8 October 2016 at 11:58, Marek Olšák <maraeo at gmail.com> wrote:
> From: Marek Olšák <marek.olsak at amd.com>
>
> time GALLIUM_NOOP=1 ./run shaders/private/alien_isolation/ >/dev/null
>
> Before (2 takes):
>
> real 0m8.734s 0m8.773s
> user 0m34.232s 0m34.348s
> sys 0m0.084s 0m0.056s
>
> After (2 takes):
>
> real 0m8.448s 0m8.463s
> user 0m33.104s 0m33.160s
> sys 0m0.088s 0m0.076s
>
> Average change in "real" time spent: -3.4%
>
> calloc should only do 2 things compared to malloc:
> - check for overflow of "n * size"
> - call memset
>
> I'm not sure if that explains the difference.
The difference is quite interesting indeed.
One small suggestion below.
> ---
> src/util/ralloc.c | 17 ++++++++++++++++-
> 1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/src/util/ralloc.c b/src/util/ralloc.c
> index 9526011..23c89e5 100644
> --- a/src/util/ralloc.c
> +++ b/src/util/ralloc.c
> @@ -91,20 +91,23 @@ get_header(const void *ptr)
> static void
> add_child(ralloc_header *parent, ralloc_header *info)
> {
> if (parent != NULL) {
> info->parent = parent;
> info->next = parent->child;
> parent->child = info;
>
> if (info->next != NULL)
> info->next->prev = info;
> + } else {
> + info->parent = NULL;
> + info->next = NULL;
add_child is used on two occasions - rzalloc_size after memset* and
ralloc_steal after unlink_block. The latter of which already clears
the parent and siblings pointers.
Thus we can move the above two lines...
> }
> }
>
> void *
> ralloc_context(const void *ctx)
> {
> return ralloc_size(ctx, 0);
> }
>
> void *
> @@ -115,27 +118,39 @@ ralloc_size(const void *ctx, size_t size)
> *
> * TODO: Make ralloc_size not zero fill memory, and cleanup any code that
> * should instead be using rzalloc.
> */
> return rzalloc_size(ctx, size);
> }
>
> void *
> rzalloc_size(const void *ctx, size_t size)
> {
> - void *block = calloc(1, size + sizeof(ralloc_header));
> + void *block = malloc(size + sizeof(ralloc_header));
> ralloc_header *info;
> ralloc_header *parent;
>
> if (unlikely(block == NULL))
> return NULL;
> +
> info = (ralloc_header *) block;
> + /* measurements have shown that calloc is slower, so clear things
> + * manually
> + */
> + info->child = NULL;
> + info->prev = NULL;
> + info->destructor = NULL;
> + /* add_child() clears other members */
> +
... here and drop the comment.
Emil
More information about the mesa-dev
mailing list