From patchwork Thu Sep 15 02:23:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Emilio Cota X-Patchwork-Id: 9332775 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1B3B860231 for ; Thu, 15 Sep 2016 03:11:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A77D29075 for ; Thu, 15 Sep 2016 03:11:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EEC5829084; Thu, 15 Sep 2016 03:11:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2B46729075 for ; Thu, 15 Sep 2016 03:11:01 +0000 (UTC) Received: from localhost ([::1]:59529 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkN4m-0005py-2J for patchwork-qemu-devel@patchwork.kernel.org; Wed, 14 Sep 2016 23:11:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34409) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkN28-0004CI-Sl for qemu-devel@nongnu.org; Wed, 14 Sep 2016 23:08:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bkN24-0000v6-SA for qemu-devel@nongnu.org; Wed, 14 Sep 2016 23:08:16 -0400 Received: from out4-smtp.messagingengine.com ([66.111.4.28]:60736) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bkN22-0000sM-Eq for qemu-devel@nongnu.org; Wed, 14 Sep 2016 23:08:12 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 46219205BC; Wed, 14 Sep 2016 22:23:48 -0400 (EDT) Received: from frontend2 ([10.202.2.161]) by compute1.internal (MEProxy); Wed, 14 Sep 2016 22:23:48 -0400 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=braap.org; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=lfYL0Y2eA5T8efYoHT9fbz174Uw=; b=F1Ge7P SykD+RkOHgWnmMJQH5kqQtSO0gJBLMi4Ea6JbrwvmbcruHfvO2jsKxevABOdYrLV oyAME0iXqhwXYhfBe0DmeY94wc7D65oo2YgvuPIWbDcaHw+ouEvMAnULv0NzxbQ4 cXKUisOMRtzTIHw6scYGH9OjHgukdsJfz7PTc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=lfYL0Y2eA5T8efY oHT9fbz174Uw=; b=NoUMGue3ygVgDpKs3Fnox8O3gqox+I3ZysUi+gJl600A8UA sDG1/h6FwspqXjAuzGAnq9/tgvfnUb/ibqppYiiRJe//TIfW8+EjL8+5mawgPJ+I Mv2z+c5wer4AzjWz3IsJeQdaOoHYIKvgRIINpXx7/e2mAcUc4/zUnPZ+RTKY= X-Sasl-enc: 9TCsOTHKm/kqNY8usfnkdvJ1VR8nGAmdUDgUCVm+6sFU 1473906227 Received: from localhost (flamenco.cs.columbia.edu [128.59.20.216]) by mail.messagingengine.com (Postfix) with ESMTPA id E5E15CCE9A; Wed, 14 Sep 2016 22:23:47 -0400 (EDT) Date: Wed, 14 Sep 2016 22:23:47 -0400 From: "Emilio G. Cota" To: Alex =?iso-8859-1?Q?Benn=E9e?= Message-ID: <20160915022347.GA2831@flamenco> References: <1472935202-3342-1-git-send-email-rth@twiddle.net> <1472935202-3342-26-git-send-email-rth@twiddle.net> <87vaxyio51.fsf@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <87vaxyio51.fsf@linaro.org> User-Agent: Mutt/1.5.23 (2014-03-12) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 66.111.4.28 Subject: Re: [Qemu-devel] [PATCH v3 25/34] tests: add atomic_add-bench X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-devel@nongnu.org, Richard Henderson Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Wed, Sep 14, 2016 at 14:53:14 +0100, Alex Bennée wrote: > Richard Henderson writes: > > From: "Emilio G. Cota" > > QEMU_CFLAGS += -I$(SRC_PATH)/tests > > @@ -465,6 +466,7 @@ tests/test-qdist$(EXESUF): tests/test-qdist.o $(test-util-obj-y) > > tests/test-qht$(EXESUF): tests/test-qht.o $(test-util-obj-y) > > tests/test-qht-par$(EXESUF): tests/test-qht-par.o tests/qht-bench$(EXESUF) $(test-util-obj-y) > > tests/qht-bench$(EXESUF): tests/qht-bench.o $(test-util-obj-y) > > +tests/atomic_add-bench$(EXESUF): tests/atomic_add-bench.o > > $(test-util-obj-y) > > This probably more properly lives in tests/tcg/generic or some such but > that needs the tcg/tests being rehabilitated into the build system so at > least here it gets built. I didn't know where to put it; tests/ was easy enough :-) > > tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \ > > hw/core/qdev.o hw/core/qdev-properties.o hw/core/hotplug.o\ > > diff --git a/tests/atomic_add-bench.c b/tests/atomic_add-bench.c > > new file mode 100644 > > index 0000000..5bbecf6 > > --- /dev/null > > +++ b/tests/atomic_add-bench.c > > I wonder if this would be worth making atomic-bench and adding the other > atomic operations into the benchmark? I know given the current helper > overhead its unlikely to show much difference between the ops but if we > move to backend support for the tcg atomics it would be a useful tool to > have. I'd rather add more ops later if necessary, but if you insist I can do it. (snip) > > +static void create_threads(void) > > +{ > > + unsigned int i; > > + > > + threads = g_new(QemuThread, n_threads); > > + th_info = g_new(struct thread_info, n_threads); > > + counts = qemu_memalign(64, sizeof(*counts) * range); > > This fails on my setup as AFAICT qemu_memalign doesn't give you zeroed > memory. I added a memset after to zero it out. Yes I fixed this more than a month ago, among other things in this program, e.g., running for -d seconds instead of -n operations (much easier way to fairly measure throughput). Obviously forgot to tell anyone about it :/ sorry for making you waste time. I'm appending the appropriate delta -- just checked it applies cleanly over rth's atomic-3 branch on github. Thanks, Emilio From f4a1a6fe2ffcf9572353f0b85a21ed27cd1765e1 Mon Sep 17 00:00:00 2001 From: "Emilio G. Cota" Date: Tue, 9 Aug 2016 23:14:13 -0400 Subject: [PATCH] tests: fix atomic_add_bench Signed-off-by: Emilio G. Cota --- tests/atomic_add-bench.c | 51 ++++++++++++++++-------------------------------- 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/tests/atomic_add-bench.c b/tests/atomic_add-bench.c index 06300ba..dc97441 100644 --- a/tests/atomic_add-bench.c +++ b/tests/atomic_add-bench.c @@ -17,14 +17,14 @@ static struct thread_info *th_info; static unsigned int n_threads = 1; static unsigned int n_ready_threads; static struct count *counts; -static unsigned long n_ops = 10000; -static double duration; -static unsigned int range = 1; +static unsigned int duration = 1; +static unsigned int range = 1024; static bool test_start; +static bool test_stop; static const char commands_string[] = " -n = number of threads\n" - " -o = number of ops per thread\n" + " -d = duration in seconds\n" " -r = range (will be rounded up to pow2)"; static void usage_complete(char *argv[]) @@ -49,14 +49,13 @@ static uint64_t xorshift64star(uint64_t x) static void *thread_func(void *arg) { struct thread_info *info = arg; - unsigned long i; atomic_inc(&n_ready_threads); while (!atomic_mb_read(&test_start)) { cpu_relax(); } - for (i = 0; i < n_ops; i++) { + while (!atomic_read(&test_stop)) { unsigned int index; info->r = xorshift64star(info->r); @@ -66,32 +65,23 @@ static void *thread_func(void *arg) return NULL; } -static inline -uint64_t ts_subtract(const struct timespec *a, const struct timespec *b) -{ - uint64_t ns; - - ns = (b->tv_sec - a->tv_sec) * 1000000000ULL; - ns += (b->tv_nsec - a->tv_nsec); - return ns; -} - static void run_test(void) { + unsigned int remaining; unsigned int i; - struct timespec ts_start, ts_end; while (atomic_read(&n_ready_threads) != n_threads) { cpu_relax(); } atomic_mb_set(&test_start, true); + do { + remaining = sleep(duration); + } while (remaining); + atomic_mb_set(&test_stop, true); - clock_gettime(CLOCK_MONOTONIC, &ts_start); for (i = 0; i < n_threads; i++) { qemu_thread_join(&threads[i]); } - clock_gettime(CLOCK_MONOTONIC, &ts_end); - duration = ts_subtract(&ts_start, &ts_end) / 1e9; } static void create_threads(void) @@ -101,6 +91,7 @@ static void create_threads(void) threads = g_new(QemuThread, n_threads); th_info = g_new(struct thread_info, n_threads); counts = qemu_memalign(64, sizeof(*counts) * range); + memset(counts, 0, sizeof(*counts) * range); for (i = 0; i < n_threads; i++) { struct thread_info *info = &th_info[i]; @@ -115,7 +106,7 @@ static void pr_params(void) { printf("Parameters:\n"); printf(" # of threads: %u\n", n_threads); - printf(" n_ops: %lu\n", n_ops); + printf(" duration: %u\n", duration); printf(" ops' range: %u\n", range); } @@ -128,22 +119,20 @@ static void pr_stats(void) for (i = 0; i < range; i++) { val += counts[i].val; } - assert(val == n_threads * n_ops); tx = val / duration / 1e6; printf("Results:\n"); - printf("Duration: %.2f s\n", duration); + printf("Duration: %u s\n", duration); printf(" Throughput: %.2f Mops/s\n", tx); printf(" Throughput/thread: %.2f Mops/s/thread\n", tx / n_threads); } static void parse_args(int argc, char *argv[]) { - unsigned long long n_ops_ull; int c; for (;;) { - c = getopt(argc, argv, "hn:o:r:"); + c = getopt(argc, argv, "hd:n:r:"); if (c < 0) { break; } @@ -151,18 +140,12 @@ static void parse_args(int argc, char *argv[]) case 'h': usage_complete(argv); exit(0); + case 'd': + duration = atoi(optarg); + break; case 'n': n_threads = atoi(optarg); break; - case 'o': - n_ops_ull = atoll(optarg); - if (n_ops_ull > ULONG_MAX) { - fprintf(stderr, - "fatal: -o cannot be greater than %lu\n", ULONG_MAX); - exit(1); - } - n_ops = n_ops_ull; - break; case 'r': range = pow2ceil(atoi(optarg)); break;