From patchwork Mon Feb 18 21:11:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 158653 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp2939122jaa; Mon, 18 Feb 2019 13:12:49 -0800 (PST) X-Google-Smtp-Source: AHgI3IbSiTw20icyZxCJ/BF3THrkTD8mWtZJZu7e9d2ij0DhNX7rq37XgYJ778jt4tsdltB4nBri X-Received: by 2002:a17:902:9689:: with SMTP id n9mr27390780plp.8.1550524369333; Mon, 18 Feb 2019 13:12:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550524369; cv=none; d=google.com; s=arc-20160816; b=mYYOqCzRDIMxbPy5pJwx/i3SYnTKq8q2i0LtY+j3SM+qVSYqeENoq1A9r6OajlCQtP mHrVcuqtaPuN5mREVJmSO3ltrE4JP90hmHzruA66ALZxnqmehVzSfPPX+KrEaPdmIvST zBZJAIhJ/oODYoZoAb82dAsT69jvLk3vMm3wygQ7qhEMOPBHmQSpZOXBNMlGq/LMpXk1 4nLd25SFeK39/n/VJLD/zag1m6gRfbkp7V9/XyJ1Rwl8c1dvPF3f7+OlVM49ETPHQYZ7 Msz6qnYzmxnYMCP06YxepQUfxx+45C3yNy8AxAYhQktTli/xuEAb3quuwOqNv/7pmwSP zaOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:delivered-to:sender:list-help:list-post:list-archive :list-subscribe:list-unsubscribe:list-id:precedence:mailing-list :dkim-signature:domainkey-signature; bh=ae7tinx+9uU2fL6OqdPq77k0Et4cg5MzskL5mv7tIak=; b=fdobIPEmQT7NvDnEa8GZ8OqT9HhzVRtYsRrJhP1Cy2mNtBGU9bQV59pnVok/VYLMZV YsKWITuSzVYUwZX/02jHkbL+ZE5CTZN8cNzNQCfXL1yTGd3NZcdRjK+fYXVggEQkc/uB xOGDwsnFuSWiw6Vycnc2BZbDnjxXTXf/jYfTW5AFoQkRJlTzKwBr6MKNmRcOoKTE37Pk eJIVtHdWGFOU4lhHInNfWIFn021/uaDftMan5vmJHTPrRPR8YLsX7VUHIJ6imSbG+eJw IpsGHdG29bfXTCToS4ADZpXPhyLivcJV3xy3QyOI4P1AL0GzbeOki8PnA2cZ39yfl6Ts b89A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=BUoPTcWT; dkim=pass header.i=@linaro.org header.s=google header.b=n2MHxoyy; spf=pass (google.com: domain of libc-alpha-return-100128-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-100128-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id 31si15161981plh.274.2019.02.18.13.12.49 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Feb 2019 13:12:49 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-100128-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=BUoPTcWT; dkim=pass header.i=@linaro.org header.s=google header.b=n2MHxoyy; spf=pass (google.com: domain of libc-alpha-return-100128-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-100128-patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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:date:message-id:in-reply-to :references; q=dns; s=default; b=by9Yvh5os6CUpKd77pEqiYD9XV2FUb9 hjD0BwJB00VouNZX1a86HLxJTE/7Qb1QtR+r2/MkznzpRf7KsLzs4L7kCuKkDw1K 8elie2b9LyMfRgwpJoVI4zC0DG5lqQSR3auSzXXklHgy6i9yk76JpkEsPA0/XQAe JPeYwivkIdnA= 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:date:message-id:in-reply-to :references; s=default; bh=OnwgENVgHFA5S7gEfVAv6PZjcgM=; b=BUoPT cWTXL1Iybca0vREz5xztNFyiIZIRyaslYCqdLF+GhSh2VZidIPVIPYXF3776gjXX oLKgS3VSTppX31o95XS0AXXARrcjWav64PxBdx5kjsTfLMLrElUTRHJX/wUydnmS OG/XklQ+jCumCw4oadJyCPhxBKJP8nvl47/H2k= Received: (qmail 61824 invoked by alias); 18 Feb 2019 21:11:47 -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 Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 61690 invoked by uid 89); 18 Feb 2019 21:11:46 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=wilcodijkstraarmcom, sk:wilcod, sk:WilcoD, sk:wilco.d X-HELO: mail-qt1-f194.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ae7tinx+9uU2fL6OqdPq77k0Et4cg5MzskL5mv7tIak=; b=n2MHxoyy4pSnjsrzAzGw0girQlpr5705/XScTc2TR4fzSLtgQDbNCmCN9PtNvGIunU 4TBQFPGjibsQrFRWnqG+zyWyv4bns+eyxXc7vWvBugGGg/I9j74bA/QPSTklZ1Nh54U9 PLpgxVNpArfrYPKzZHHxOxmXM5FemAnAejhiCWp+HTQsQQ50/0D1X8bw0b/ldAGdAfzn wZ1I4ilIDKmbiDIp7U8f9Rwk05LfneyTR8HPlmsJSiiC/c56v4Ny0JCYsu8V6/no0DNf tSHVNVr3w91GLvZ/MJKtNPzUR/gT28iymds6YSthw3XbO8vva23sDPUTibndwsYQEwy6 ZAgw== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Cc: Wilco Dijkstra Subject: [PATCH v2 6/6] Add generic hp-timing support Date: Mon, 18 Feb 2019 18:11:28 -0300 Message-Id: <20190218211128.1869-6-adhemerval.zanella@linaro.org> In-Reply-To: <20190218211128.1869-1-adhemerval.zanella@linaro.org> References: <20190218211128.1869-1-adhemerval.zanella@linaro.org> From: Wilco Dijkstra Add missing generic hp_timing support. It uses clock_gettime (CLOCK_MONOTONIC) which has unspecified starting time, nano-second accuracy, and should faster on architectures that implementes the symbol as vDSO. Checked on aarch64-linux-gnu, x86_64-linux-gnu, and i686-linux-gnu. I also checked the builds for all afected ABIs. * benchtests/Makefile (USE_CLOCK_GETTIME) Remove. * benchtests/README: Update description. * benchtests/bench-timing.h: Default to hp-timing. * sysdeps/generic/hp-timing.h (HP_TIMING_DIFF, HP_TIMING_ACCUM_NT, HP_TIMING_PRINT): Remove. (HP_TIMING_NOW): Add generic implementation. (hp_timing_t): Change to uint64_t. --- benchtests/Makefile | 6 ----- benchtests/README | 7 +----- benchtests/bench-timing.h | 44 +++++++------------------------------ sysdeps/generic/hp-timing.h | 25 +++++++++++++-------- 4 files changed, 25 insertions(+), 57 deletions(-) -- 2.17.1 diff --git a/benchtests/Makefile b/benchtests/Makefile index d00993eca4..cdc89488d6 100644 --- a/benchtests/Makefile +++ b/benchtests/Makefile @@ -127,17 +127,11 @@ endif CPPFLAGS-nonlib += -DDURATION=$(BENCH_DURATION) -D_ISOMAC -# Use clock_gettime to measure performance of functions. The default is to use -# HP_TIMING if it is available. -ifdef USE_CLOCK_GETTIME -CPPFLAGS-nonlib += -DUSE_CLOCK_GETTIME -else # On x86 processors, use RDTSCP, instead of RDTSC, to measure performance # of functions. All x86 processors since 2010 support RDTSCP instruction. ifdef USE_RDTSCP CPPFLAGS-nonlib += -DUSE_RDTSCP endif -endif DETAILED_OPT := diff --git a/benchtests/README b/benchtests/README index aaf0b659e2..c4f03fd872 100644 --- a/benchtests/README +++ b/benchtests/README @@ -27,12 +27,7 @@ BENCH_DURATION. The benchmark suite does function call measurements using architecture-specific high precision timing instructions whenever available. When such support is -not available, it uses clock_gettime (CLOCK_PROCESS_CPUTIME_ID). One can force -the benchmark to use clock_gettime by invoking make as follows: - - $ make USE_CLOCK_GETTIME=1 bench - -Again, one must run `make bench-clean' before changing the measurement method. +not available, it uses clock_gettime (CLOCK_MONOTONIC). On x86 processors, RDTSCP instruction provides more precise timing data than RDTSC instruction. All x86 processors since 2010 support RDTSCP diff --git a/benchtests/bench-timing.h b/benchtests/bench-timing.h index 93fe379f99..e213dec3fd 100644 --- a/benchtests/bench-timing.h +++ b/benchtests/bench-timing.h @@ -18,49 +18,21 @@ #undef attribute_hidden #define attribute_hidden +#define __clock_gettime clock_gettime #include #include -#if HP_TIMING_INLINE && !defined USE_CLOCK_GETTIME -# define GL(x) _##x -# define GLRO(x) _##x +#define GL(x) _##x +#define GLRO(x) _##x typedef hp_timing_t timing_t; -# define TIMING_TYPE "hp_timing" +#define TIMING_TYPE "hp_timing" -# define TIMING_INIT(res) ({ (res) = 1; }) +#define TIMING_INIT(res) ({ (res) = 1; }) -# define TIMING_NOW(var) HP_TIMING_NOW (var) -# define TIMING_DIFF(diff, start, end) HP_TIMING_DIFF ((diff), (start), (end)) -# define TIMING_ACCUM(sum, diff) HP_TIMING_ACCUM_NT ((sum), (diff)) - -#else - -#include -typedef uint64_t timing_t; - -# define TIMING_TYPE "clock_gettime" - -/* Measure the resolution of the clock so we can scale the number of - benchmark iterations by this value. */ -# define TIMING_INIT(res) \ -({ \ - struct timespec start; \ - clock_getres (CLOCK_PROCESS_CPUTIME_ID, &start); \ - (res) = start.tv_nsec; \ -}) - -# define TIMING_NOW(var) \ -({ \ - struct timespec tv; \ - clock_gettime (CLOCK_PROCESS_CPUTIME_ID, &tv); \ - (var) = (uint64_t) (tv.tv_nsec + (uint64_t) 1000000000 * tv.tv_sec); \ -}) - -# define TIMING_DIFF(diff, start, end) (diff) = (end) - (start) -# define TIMING_ACCUM(sum, diff) (sum) += (diff) - -#endif +#define TIMING_NOW(var) HP_TIMING_NOW (var) +#define TIMING_DIFF(diff, start, end) HP_TIMING_DIFF ((diff), (start), (end)) +#define TIMING_ACCUM(sum, diff) HP_TIMING_ACCUM_NT ((sum), (diff)) #define TIMING_PRINT_MEAN(d_total_s, d_iters) \ printf ("\t%g", (d_total_s) / (d_iters)) diff --git a/sysdeps/generic/hp-timing.h b/sysdeps/generic/hp-timing.h index 278998d2c2..2528279558 100644 --- a/sysdeps/generic/hp-timing.h +++ b/sysdeps/generic/hp-timing.h @@ -20,16 +20,23 @@ #ifndef _HP_TIMING_H #define _HP_TIMING_H 1 -/* There are no generic definitions for the times. We could write something - using the `gettimeofday' system call where available but the overhead of - the system call might be too high. */ +#include +#include +#include -/* Provide dummy definitions. */ +/* It should not be used for ld.so. */ #define HP_TIMING_INLINE (0) -typedef int hp_timing_t; -#define HP_TIMING_NOW(var) -#define HP_TIMING_DIFF(Diff, Start, End) -#define HP_TIMING_ACCUM_NT(Sum, Diff) -#define HP_TIMING_PRINT(Buf, Len, Val) + +typedef uint64_t hp_timing_t; + +/* The clock_gettime (CLOCK_MONOTONIC) has unspecified starting time, + nano-second accuracy, and for some architectues is implemented as + vDSO symbol. */ +#define HP_TIMING_NOW(var) \ +({ \ + struct timespec tv; \ + __clock_gettime (CLOCK_MONOTONIC, &tv); \ + (var) = (tv.tv_nsec + UINT64_C(1000000000) * tv.tv_sec); \ +}) #endif /* hp-timing.h */