From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS31976 209.132.180.0/23 X-Spam-Status: No, score=-4.1 required=3.0 tests=AWL,BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id F23071F453 for ; Fri, 8 Feb 2019 19:34:59 +0000 (UTC) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:in-reply-to:date:message-id :mime-version:content-type; q=dns; s=default; b=OB7pXFXhueQseBx8 cZBAbkJnTsM7DCD7y4y86bJLljIXyRWtiouuvlDvZagIWHGewF0wUyuQHDF41a77 grB+dBL1jTqfa1JG6iiAIoZ5yj0Si63Y1aWTC1sJaEcaj+Z7FR9tQUR/oNOHa+C7 mI6hmBkJ/REE8pq6tYPYt9mPEFY= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:in-reply-to:date:message-id :mime-version:content-type; s=default; bh=N8z6O9kiz9TtySJQcjRKay SEbm0=; b=rjmt22SgstYi+VJDqkCdyileEzht8AVAvlRERya66DPOakeTMI/mFe Qrkt7wFskRJzjFemDQRcuMoyPkquG/cHFcER+plG2Fx+y2htbGJwv7Stx+0uLhA8 CAf+E7BHDouVsHN1r6ZmQLysqgM/1Gm6p9+xZuEp2cZ0PYtDrzL+k= Received: (qmail 77216 invoked by alias); 8 Feb 2019 19:34:57 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 77203 invoked by uid 89); 8 Feb 2019 19:34:56 -0000 Authentication-Results: sourceware.org; auth=none X-HELO: mx1.redhat.com From: DJ Delorie To: Wilco Dijkstra Cc: libc-alpha@sourceware.org, nd@arm.com Subject: Re: [PATCH] Add malloc micro benchmark In-Reply-To: (message from Wilco Dijkstra on Fri, 1 Feb 2019 16:27:34 +0000) Date: Fri, 08 Feb 2019 14:37:18 -0500 Message-ID: MIME-Version: 1.0 Content-Type: text/plain Looks good to me, although I'd like some additional comments in the test code. Wilco Dijkstra writes: > -bench-malloc := malloc-thread > +bench-malloc := malloc-thread malloc-simple Adding a test, ok > -$(objpfx)bench-malloc-thread: $(shared-thread-library) > +$(addprefix $(objpfx)bench-,$(bench-malloc)): $(shared-thread-library) Accepting a list of tests, ok > - malloc-thread > + malloc-thread malloc-simple Adding a test, ok > bench-malloc: $(binaries-bench-malloc) > for run in $^; do \ > + echo "$${run}"; \ > + if [ `basename $${run}` = "bench-malloc-thread" ]; then \ > for thr in 1 8 16 32; do \ > echo "Running $${run} $${thr}"; \ > - $(run-bench) $${thr} > $${run}-$${thr}.out; \ > - done;\ > + $(run-bench) $${thr} > $${run}-$${thr}.out; \ > + done;\ > + else \ > + for thr in 8 16 32 64 128 256 512 1024 2048 4096; do \ > + echo "Running $${run} $${thr}"; \ > + $(run-bench) $${thr} > $${run}-$${thr}.out; \ > + done;\ > + fi;\ > done I wonder if this could be done more elegantly, but I'm OK with a simple approach for now. If we end up adding many more such tests we might need to revisit this part. > +/* Benchmark malloc and free functions. > + Copyright (C) 2018 Free Software Foundation, Inc. 2019 > + > +#include I would like to see a comment block somewhere in this code that describes, to the casual future reader, what this test is looking for and why it's different than other tests. I won't hold up my OK for it, though. > +#define NUM_ITERS 1000000 > +#define NUM_ALLOCS 4 > +#define MAX_ALLOCS 1600 How long does this test take to run, on average, compared to other tests? Do we have to worry about increasing timeouts for slow hosts? > +static void > +do_benchmark (malloc_args *args, int **arr) > +{ > + timing_t start, stop; > + size_t iters = args->iters; > + size_t size = args->size; > + int n = args->n; > + > + TIMING_NOW (start); > + > + for (int j = 0; j < iters; j++) > + { > + for (int i = 0; i < n; i++) > + arr[i] = malloc (size); > + > + for (int i = 0; i < n; i++) > + free (arr[i]); > + } > + > + TIMING_NOW (stop); > + > + TIMING_DIFF (args->elapsed, start, stop); > +} Simple loop, but doesn't test for malloc returning NULL. > + /* Run benchmark single threaded in main_arena. */ > + for (int i = 0; i < NUM_ALLOCS; i++) > + do_benchmark (&tests[0][i], arr); > + > + /* Run benchmark in a thread_arena. */ > + pthread_t t; > + pthread_create (&t, NULL, thread_test, (void*)arr); > + pthread_join (t, NULL); > + > + /* Repeat benchmark in main_arena with SINGLE_THREAD_P == false. */ > + for (int i = 0; i < NUM_ALLOCS; i++) > + do_benchmark (&tests[1][i], arr); So we repeat the "main thread" case but now the heap is "messy" from the now-joined thread... ok.