From patchwork Fri Jan 25 16:15:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wilco Dijkstra X-Patchwork-Id: 1031174 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-99559-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="kLjWLlc3"; dkim=pass (1024-bit key; unprotected) header.d=armh.onmicrosoft.com header.i=@armh.onmicrosoft.com header.b="GYNerD5q"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43mPKL2Yq3z9s4s for ; Sat, 26 Jan 2019 03:16:22 +1100 (AEDT) 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 :content-type:content-transfer-encoding:mime-version; q=dns; s= default; b=k8X9GJed1R7GW9j9wj+JYXzrx1SGztkCyNFqA23CaoPkmUSLsJdL6 /b8cdPwnsEHxETnu37gt6IcgcHvADzOGXnBp+hjNd12UO7agyo61ZQ0jMHNYO0nu 56/sqhfHqyEHpWMP9tMsYflZGBzLeymirO8knzKZ+eEukV7cBiXSEQ= 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 :content-type:content-transfer-encoding:mime-version; s=default; bh=3wvvWYsAnpbnpacUNxm12i9mLUA=; b=kLjWLlc3a3cnBbz+P4ql2dYxbkdT z8l36U7wTpNANvAftU+TYZZi7yQ/Fwcw8VRq9+yoN784tq+/UOdMXIjW2gYHmNwG qZj37y2OEwmtKoyQOq43eXScqWzFwS0YPQuUmyw+LyeSFtgS26gg3C8tW1yXNMQY ZbCj+OkTWsO8nFo= Received: (qmail 28647 invoked by alias); 25 Jan 2019 16:16:00 -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 28569 invoked by uid 89); 25 Jan 2019 16:15:58 -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 autolearn=ham version=3.3.2 spammy=1000000000, unnecessarily, playing, clock X-HELO: EUR03-VE1-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=qffXOeAdY794EOUeL0DSQ/jWhi+Gwsg8rymnVr2HI1k=; b=GYNerD5qxmTsayB50LVN3fdZlZdh3t/Fy0qqkg8eqGRAGpLrfnhGbTQvMsGv0sTMwJkB7TXLHs5E6rFPh2w2UvEwnj1xuszu3V1ni0VptMajRvDj0turMZi0m3B4/TS/BNfb/iskZ2dEEl5ZtXFktbsadSHLPm14HGqyVhHB1ec= From: Wilco Dijkstra To: 'GNU C Library' CC: nd Subject: [PATCHv2 1/4] Cleanup clock_*time includes Date: Fri, 25 Jan 2019 16:15:50 +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) x-ms-exchange-senderadcheck: 1 MIME-Version: 1.0 (resend patch as part of hp-timing cleanup) Clock_gettime, settime and getres implementations are unnecessarily complex due to using many defines and C file inclusion. Simplify the code by replacing the redundant defines and removing the inclusion, making it much easier to understand. No functional changes. OK for commit (for 2.30)? ChangeLog: 2019-01-14 Wilco Dijkstra * sysdeps/posix/clock_getres.c (__clock_getres): Cleanup. * sysdeps/unix/clock_gettime.c (__clock_gettime): Cleanup. * sysdeps/unix/clock_settime.c (__clock_settime): Cleanup. * sysdeps/unix/sysv/linux/clock_getres.c (__clock_getres): Cleanup. * sysdeps/unix/sysv/linux/clock_gettime.c (__clock_gettime): Cleanup. * sysdeps/unix/sysv/linux/clock_settime.c (__clock_settime): Cleanup. diff --git a/sysdeps/posix/clock_getres.c b/sysdeps/posix/clock_getres.c index f47715ed6b48a54248fb375fbbeb55008b995104..dac4761fcc2c86cb0d53425cab4e88d587696540 100644 --- a/sysdeps/posix/clock_getres.c +++ b/sysdeps/posix/clock_getres.c @@ -82,20 +82,11 @@ __clock_getres (clockid_t clock_id, struct timespec *res) switch (clock_id) { -#ifdef SYSDEP_GETRES - SYSDEP_GETRES; -#endif - -#ifndef HANDLED_REALTIME case CLOCK_REALTIME: retval = realtime_getres (res); break; -#endif /* handled REALTIME */ default: -#ifdef SYSDEP_GETRES_CPU - SYSDEP_GETRES_CPU; -#endif #if HP_TIMING_AVAIL if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1)) == CLOCK_THREAD_CPUTIME_ID) @@ -105,7 +96,7 @@ __clock_getres (clockid_t clock_id, struct timespec *res) __set_errno (EINVAL); break; -#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME +#if HP_TIMING_AVAIL case CLOCK_PROCESS_CPUTIME_ID: case CLOCK_THREAD_CPUTIME_ID: retval = hp_timing_getres (res); diff --git a/sysdeps/unix/clock_gettime.c b/sysdeps/unix/clock_gettime.c index 138991d1bc081cea004e94defe361580dfb022dc..33a1f3335c269eec2b4f01fb927e3836a191b5eb 100644 --- a/sysdeps/unix/clock_gettime.c +++ b/sysdeps/unix/clock_gettime.c @@ -95,11 +95,6 @@ __clock_gettime (clockid_t clock_id, struct timespec *tp) switch (clock_id) { -#ifdef SYSDEP_GETTIME - SYSDEP_GETTIME; -#endif - -#ifndef HANDLED_REALTIME case CLOCK_REALTIME: { struct timeval tv; @@ -108,12 +103,8 @@ __clock_gettime (clockid_t clock_id, struct timespec *tp) TIMEVAL_TO_TIMESPEC (&tv, tp); } break; -#endif default: -#ifdef SYSDEP_GETTIME_CPU - SYSDEP_GETTIME_CPU (clock_id, tp); -#endif #if HP_TIMING_AVAIL if ((clock_id & ((1 << CLOCK_IDFIELD_SIZE) - 1)) == CLOCK_THREAD_CPUTIME_ID) @@ -123,7 +114,7 @@ __clock_gettime (clockid_t clock_id, struct timespec *tp) __set_errno (EINVAL); break; -#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME +#if HP_TIMING_AVAIL case CLOCK_PROCESS_CPUTIME_ID: retval = hp_timing_gettime (clock_id, tp); break; diff --git a/sysdeps/unix/clock_settime.c b/sysdeps/unix/clock_settime.c index b589e875cf2dfb5fc083550e01e774a6f4d0cae6..24d73b048c1b891906dacdf0c199544b85d924d2 100644 --- a/sysdeps/unix/clock_settime.c +++ b/sysdeps/unix/clock_settime.c @@ -21,7 +21,7 @@ #include -#if HP_TIMING_AVAIL && !defined HANDLED_CPUTIME +#if HP_TIMING_AVAIL /* Clock frequency of the processor. We make it a 64-bit variable because some jokers are already playing with processors with more than 4GHz. */ @@ -84,29 +84,15 @@ __clock_settime (clockid_t clock_id, const struct timespec *tp) switch (clock_id) { -#define HANDLE_REALTIME \ - do { \ - struct timeval tv; \ - TIMESPEC_TO_TIMEVAL (&tv, tp); \ - \ - retval = __settimeofday (&tv, NULL); \ - } while (0) - -#ifdef SYSDEP_SETTIME - SYSDEP_SETTIME; -#endif - -#ifndef HANDLED_REALTIME case CLOCK_REALTIME: - HANDLE_REALTIME; + do { + struct timeval tv; + TIMESPEC_TO_TIMEVAL (&tv, tp); + retval = __settimeofday (&tv, NULL); + } while (0); break; -#endif default: -#ifdef SYSDEP_SETTIME_CPU - SYSDEP_SETTIME_CPU; -#endif -#ifndef HANDLED_CPUTIME # if HP_TIMING_AVAIL if (CPUCLOCK_WHICH (clock_id) == CLOCK_PROCESS_CPUTIME_ID || CPUCLOCK_WHICH (clock_id) == CLOCK_THREAD_CPUTIME_ID) @@ -117,7 +103,6 @@ __clock_settime (clockid_t clock_id, const struct timespec *tp) __set_errno (EINVAL); retval = -1; } -#endif break; } diff --git a/sysdeps/unix/sysv/linux/clock_getres.c b/sysdeps/unix/sysv/linux/clock_getres.c index a24532888fd3f3e256f34fb5a7636cee8b0b7904..bb2ee109bd66f916cc790899fbc205c8890098ae 100644 --- a/sysdeps/unix/sysv/linux/clock_getres.c +++ b/sysdeps/unix/sysv/linux/clock_getres.c @@ -26,26 +26,11 @@ #endif #include -#define SYSCALL_GETRES \ - retval = INLINE_VSYSCALL (clock_getres, 2, clock_id, res); \ - break +/* Get resolution of clock. */ +int +__clock_getres (clockid_t clock_id, struct timespec *res) +{ + return INLINE_VSYSCALL (clock_getres, 2, clock_id, res); +} +weak_alias (__clock_getres, clock_getres) -/* The REALTIME and MONOTONIC clock are definitely supported in the - kernel. */ -#define SYSDEP_GETRES \ - SYSDEP_GETRES_CPUTIME \ - case CLOCK_REALTIME: \ - case CLOCK_MONOTONIC: \ - case CLOCK_MONOTONIC_RAW: \ - case CLOCK_REALTIME_COARSE: \ - case CLOCK_MONOTONIC_COARSE: \ - SYSCALL_GETRES - -/* We handled the REALTIME clock here. */ -#define HANDLED_REALTIME 1 -#define HANDLED_CPUTIME 1 - -#define SYSDEP_GETRES_CPU SYSCALL_GETRES -#define SYSDEP_GETRES_CPUTIME /* Default catches them too. */ - -#include diff --git a/sysdeps/unix/sysv/linux/clock_gettime.c b/sysdeps/unix/sysv/linux/clock_gettime.c index 9af806f76ef34ad711a9f94de77599d6e17fe421..2ad7846a4d811635c40daab62bc0eae9d7d3b7ac 100644 --- a/sysdeps/unix/sysv/linux/clock_gettime.c +++ b/sysdeps/unix/sysv/linux/clock_gettime.c @@ -26,22 +26,12 @@ #endif #include -/* The REALTIME and MONOTONIC clock are definitely supported in the - kernel. */ -#define SYSDEP_GETTIME \ - SYSDEP_GETTIME_CPUTIME; \ - case CLOCK_REALTIME: \ - case CLOCK_MONOTONIC: \ - retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); \ - break +/* Get current value of CLOCK and store it in TP. */ +int +__clock_gettime (clockid_t clock_id, struct timespec *tp) +{ + return INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); +} +weak_alias (__clock_gettime, clock_gettime) +libc_hidden_def (__clock_gettime) -/* We handled the REALTIME clock here. */ -#define HANDLED_REALTIME 1 -#define HANDLED_CPUTIME 1 - -#define SYSDEP_GETTIME_CPU(clock_id, tp) \ - retval = INLINE_VSYSCALL (clock_gettime, 2, clock_id, tp); \ - break -#define SYSDEP_GETTIME_CPUTIME /* Default catches them too. */ - -#include diff --git a/sysdeps/unix/sysv/linux/clock_settime.c b/sysdeps/unix/sysv/linux/clock_settime.c index 7e2432b244a40ac620c39010a7e0a556f73a9c79..c5668012e0819059f9bfdd684616e0c9add2b115 100644 --- a/sysdeps/unix/sysv/linux/clock_settime.c +++ b/sysdeps/unix/sysv/linux/clock_settime.c @@ -21,18 +21,18 @@ #include "kernel-posix-cpu-timers.h" +/* Set CLOCK to value TP. */ +int +__clock_settime (clockid_t clock_id, const struct timespec *tp) +{ + /* Make sure the time cvalue is OK. */ + if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000) + { + __set_errno (EINVAL); + return -1; + } + + return INLINE_SYSCALL (clock_settime, 2, clock_id, tp); +} +weak_alias (__clock_settime, clock_settime) -/* The REALTIME clock is definitely supported in the kernel. */ -#define SYSDEP_SETTIME \ - case CLOCK_REALTIME: \ - retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp); \ - break - -/* We handled the REALTIME clock here. */ -#define HANDLED_REALTIME 1 - -#define HANDLED_CPUTIME 1 -#define SYSDEP_SETTIME_CPU \ - retval = INLINE_SYSCALL (clock_settime, 2, clock_id, tp) - -#include