From patchwork Tue Jan 15 14:05:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 31066 Received: (qmail 129777 invoked by alias); 15 Jan 2019 14:05:36 -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 129757 invoked by uid 89); 15 Jan 2019 14:05:35 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.7 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LOTSOFHASH, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 spammy=accuracy X-HELO: EUR02-AM5-obe.outbound.protection.outlook.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=armh.onmicrosoft.com; s=selector1-arm-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zAnbmqjOjN+CBbaLIrLoY6t9kCE0F1d5v8KFvjKqg3k=; b=YcQPTEJLe88DOwQ1NtarkZHArSNXQgqbey5Z9Zz3LSTVr5SxNRamHuRN6m0uNJy5OwGHJ2CpR2RXUS3waBaDDZcqGrpEiWqaJGKa3da4sq9uwaK8QY5Dlib+FDnb3vLzyyV3qOLz5gr8QvX02IjDQdeLlqFBsjL/mZJS+w8f3YM= From: Wilco Dijkstra To: 'GNU C Library' CC: nd Subject: [PATCH 3/3] Cleanup hp-timing uses Date: Tue, 15 Jan 2019 14:05:24 +0000 Message-ID: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco.Dijkstra@arm.com; received-spf: None (protection.outlook.com: arm.com does not designate permitted sender hosts) MIME-Version: 1.0 Now we have a generic hp-timing implementation, use it by default for benchmarking and a few cases where random bits are required (given the default CLOCK_MONOTONIC has an unspecified starting time and nano-second accuracy, its randomness is significantly better than using gettimeofday). ChangeLog: 2019-01-15 Wilco Dijkstra * benchtests/Makefile (USE_CLOCK_GETTIME) Remove. * benchtests/README: Update description. * benchtests/bench-timing.h: Default to hp-timing. * resolv/res_mkquery.c: Likewise. * resolv/res_send.c: Likewise. * sysdeps/posix/tempname.c: Likewise. diff --git a/benchtests/Makefile b/benchtests/Makefile index eef13bf1d1791d00fc3692af883cc9bbd092a5d0..12036b1935dc7ea84b421f024d6fe3190ae35a6e 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 aaf0b659e2b25627230a7280cd858a29f5532392..c4f03fd872de8c5ec0c805e94a2a13e4b0adfa78 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 41b7324527b9deed67b3479cb1308fbd291bc5ca..42f907e850d1ff901b0a5cdcedf00c4c44a8829f 100644 --- a/benchtests/bench-timing.h +++ b/benchtests/bench-timing.h @@ -18,49 +18,18 @@ #undef attribute_hidden #define attribute_hidden +#define __clock_gettime clock_gettime #include -#include -#if HP_TIMING_AVAIL && !defined USE_CLOCK_GETTIME # define GL(x) _##x # define GLRO(x) _##x typedef hp_timing_t timing_t; # define TIMING_TYPE "hp_timing" - # 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_PRINT_MEAN(d_total_s, d_iters) \ printf ("\t%g", (d_total_s) / (d_iters)) diff --git a/resolv/res_mkquery.c b/resolv/res_mkquery.c index 19b8b402c44a4ac5cff6e0cefac9f054b4fd3081..4d5ef9dced9ec7180031760c6620958fcd1bc937 100644 --- a/resolv/res_mkquery.c +++ b/resolv/res_mkquery.c @@ -95,9 +95,6 @@ #include #include -#if HP_TIMING_AVAIL -# define RANDOM_BITS(Var) { uint64_t v64; HP_TIMING_NOW (v64); Var = v64; } -#endif int __res_context_mkquery (struct resolv_context *ctx, int op, const char *dname, @@ -120,14 +117,8 @@ __res_context_mkquery (struct resolv_context *ctx, int op, const char *dname, /* We randomize the IDs every time. The old code just incremented by one after the initial randomization which still predictable if the application does multiple requests. */ - int randombits; -#ifdef RANDOM_BITS - RANDOM_BITS (randombits); -#else - struct timeval tv; - __gettimeofday (&tv, NULL); - randombits = (tv.tv_sec << 8) ^ tv.tv_usec; -#endif + hp_timing_t randombits; + HP_TIMING_NOW (randombits); hp->id = randombits; hp->opcode = op; diff --git a/resolv/res_send.c b/resolv/res_send.c index fa040c1198fadce5ae9b2d8c373bfb4c0489f6c4..7152527f57975618a0723a92e0a134ea18436491 100644 --- a/resolv/res_send.c +++ b/resolv/res_send.c @@ -309,15 +309,9 @@ nameserver_offset (struct __res_state *statp) if ((offset & 1) == 0) { /* Initialization is required. */ -#if HP_TIMING_AVAIL - uint64_t ticks; + hp_timing_t ticks; HP_TIMING_NOW (ticks); offset = ticks; -#else - struct timeval tv; - __gettimeofday (&tv, NULL); - offset = ((tv.tv_sec << 8) ^ tv.tv_usec); -#endif /* The lowest bit is the most random. Preserve it. */ offset <<= 1; diff --git a/sysdeps/posix/tempname.c b/sysdeps/posix/tempname.c index 2ed39d1a42989417c159bdd199bcfd9473592177..f8a4ff0aab099a9fe8c62230a86bc820012d3d61 100644 --- a/sysdeps/posix/tempname.c +++ b/sysdeps/posix/tempname.c @@ -72,21 +72,6 @@ #ifdef _LIBC # include -# if HP_TIMING_AVAIL -# define RANDOM_BITS(Var) \ - if (__glibc_unlikely (value == UINT64_C (0))) \ - { \ - /* If this is the first time this function is used initialize \ - the variable we accumulate the value in to some somewhat \ - random value. If we'd not do this programs at startup time \ - might have a reduced set of possible names, at least on slow \ - machines. */ \ - struct timeval tv; \ - __gettimeofday (&tv, NULL); \ - value = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec; \ - } \ - HP_TIMING_NOW (Var) -# endif #endif /* Use the widest available unsigned type if uint64_t is not @@ -194,7 +179,7 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind) int len; char *XXXXXX; static uint64_t value; - uint64_t random_time_bits; + hp_timing_t random_time_bits; unsigned int count; int fd = -1; int save_errno = errno; @@ -227,15 +212,7 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind) XXXXXX = &tmpl[len - 6 - suffixlen]; /* Get some more or less random data. */ -#ifdef RANDOM_BITS - RANDOM_BITS (random_time_bits); -#else - { - struct timeval tv; - __gettimeofday (&tv, NULL); - random_time_bits = ((uint64_t) tv.tv_usec << 16) ^ tv.tv_sec; - } -#endif + HP_TIMING_NOW (random_time_bits); value += random_time_bits ^ __getpid (); for (count = 0; count < attempts; value += 7777, ++count)