* [PATCH 3/3] Cleanup hp-timing uses
@ 2019-01-15 14:05 Wilco Dijkstra
0 siblings, 0 replies; only message in thread
From: Wilco Dijkstra @ 2019-01-15 14:05 UTC (permalink / raw)
To: 'GNU C Library'; +Cc: nd
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 <wdijkstr@arm.com>
* 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 <hp-timing.h>
-#include <stdint.h>
-#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 <time.h>
-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 <hp-timing.h>
#include <stdint.h>
-#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 <hp-timing.h>
-# 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)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2019-01-15 14:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-15 14:05 [PATCH 3/3] Cleanup hp-timing uses Wilco Dijkstra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).