From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 118720 invoked by alias); 28 Aug 2019 18:49:18 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Received: (qmail 118706 invoked by uid 89); 28 Aug 2019 18:49:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-6.1 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=careful X-HELO: mx1.redhat.com From: Florian Weimer To: Zack Weinberg Cc: GNU C Library , Joseph Myers , Lukasz Majewski , Alistair Francis , Stepan Golosunov , Arnd Bergmann , Adhemerval Zanella , Samuel Thibault Subject: Re: [PATCH v2 05/10] Use clock_gettime to implement time. References: <20190828153236.18229-1-zackw@panix.com> <20190828153236.18229-6-zackw@panix.com> <87muftb1fk.fsf@oldenburg2.str.redhat.com> Date: Wed, 28 Aug 2019 18:49:00 -0000 In-Reply-To: (Zack Weinberg's message of "Wed, 28 Aug 2019 14:36:08 -0400") Message-ID: <87ef15azx4.fsf@oldenburg2.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-SW-Source: 2019-08/txt/msg00748.txt.bz2 * Zack Weinberg: > On Wed, Aug 28, 2019 at 2:16 PM Florian Weimer wrote: >> >> * Zack Weinberg: >> >> > Most ports were using gettimeofday to implement time, or they were >> > making a direct (v)syscall. Unconditionally switch to using >> > clock_gettime instead. All sysdeps implementations of time are >> > removed. >> >> I'm sorry, but this is clearly not advisable because clock_gettime is >> almost an order of magnitude slower than time. > > Hmm. How do we reconcile this with the (Linux) kernel maintainers' > stated intentions to provide only clock_gettime in the future? We > could use CLOCK_REALTIME_COARSE when available, I suppose; can you see > whether that recovers the lost performance, or else send me your > benchmark code so I can try it? I see 4.9 ns with CLOCK_REALTIME_COARSE, compared to 2.2 ns for time. It still looks significantly slower to me. We also have to be careful not to use clocks that don't stay in the vDSO on all supported kernel/hypervisor combinations. Benchmark code is below. Thanks, Florian #include #include #include #include #include int main (int argc, char **argv) { int count; if (argc != 3 || (count = atoi (argv[2])) <= 0) err (1, "usage: %s METHOD ITERATIONS", argv[0]); if (strcmp (argv[1], "time") == 0) for (int i = 0; i < count; ++i) time (NULL); else if (strcmp (argv[1], "gettimeofday") == 0) for (int i = 0; i < count; ++i) { struct timeval tv; gettimeofday (&tv, NULL); } else if (strcmp (argv[1], "realtime") == 0) for (int i = 0; i < count; ++i) { struct timespec tv; clock_gettime (CLOCK_REALTIME, &tv); } else if (strcmp (argv[1], "realtime_coarse") == 0) for (int i = 0; i < count; ++i) { struct timespec tv; clock_gettime (CLOCK_REALTIME_COARSE, &tv); } else if (strcmp (argv[1], "monotonic") == 0) for (int i = 0; i < count; ++i) { struct timespec tv; clock_gettime (CLOCK_MONOTONIC, &tv); } else if (strcmp (argv[1], "monotonic_coarse") == 0) for (int i = 0; i < count; ++i) { struct timespec tv; clock_gettime (CLOCK_MONOTONIC_COARSE, &tv); } else if (strcmp (argv[1], "monotonic_raw") == 0) for (int i = 0; i < count; ++i) { struct timespec tv; clock_gettime (CLOCK_MONOTONIC_RAW, &tv); } else errx (1, "invalid clock: %s", argv[1]); return 0; }