From patchwork Mon Jun 19 22:20:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yonggang Luo X-Patchwork-Id: 1796831 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=MbG2W9YP; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QlPQB3RdYz20XS for ; Tue, 20 Jun 2023 08:22:10 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7D27C3858C20 for ; Mon, 19 Jun 2023 22:22:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7D27C3858C20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1687213328; bh=k3BixMHLo7LzJwvT1q8leN3fcc67w4TzeV3EBk9N9Bk=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=MbG2W9YPhO+5twRFxnV5GZdgnQ7kV3hGdGdhBnyK5ToNXPBXRcrZ00Wcj1qvXKKT2 PLX9yiY4B9yQ6LnoSk4egs+e9qNmWGr2HzfqhMlFhDXG4O9pifbO30jJqLaHs0pDsz tzarVl8ibMgVur7BIp38ucOVYuJGED3iNppnJn6E= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id B77793858C27 for ; Mon, 19 Jun 2023 22:21:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B77793858C27 Received: by mail-ot1-x335.google.com with SMTP id 46e09a7af769-6b5915d0816so215375a34.1 for ; Mon, 19 Jun 2023 15:21:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687213271; x=1689805271; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k3BixMHLo7LzJwvT1q8leN3fcc67w4TzeV3EBk9N9Bk=; b=Tk5J9gNotcIJGD7o3XF0pVXD6jop0vEI+rzOu2ofOtZjvyx4d0f2FQgxaNKJzaDSsH pOcdLFY4uEsfcOQszSQqbSb1KpDU/MaZV4cEywM1ofPfIiADYm1zY0utrCUZmpX/TC/E x3QWo71Gc1eNMvhNAx5ueCYHtQfn/5FFBvwVuIo4zSTH5Ase056Iif4lIkJVLuwZ2CcI 6dlWMzjEhZIOgzuu5q9hkFgY8pOvcaQJhcU/ACZuqLUw6WOdi1r/zxPEZ39sLkKnHI+p SRbi6LVkQfaLefMLX62OwMRuwiMZ7Gejo8tcLBf5EgSRI/XcEyEwcRTX9moTe0pVsKeR jXvg== X-Gm-Message-State: AC+VfDwEVLNQ3X+r+0IJ1ttKX9dmFIcj1wPFTZ2vyBMC9D2rrXs0Wvpu YB05E5YNWFh7BzJuqn77LRw= X-Google-Smtp-Source: ACHHUZ5lC++h4K992VtiYVVvceRh9SkXKmZ48tqWuWOGGqIrjN5wqkZEybGaGc9QMAK5+Gauzd1I8g== X-Received: by 2002:a05:6830:200f:b0:6b4:5721:18e2 with SMTP id e15-20020a056830200f00b006b4572118e2mr8599908otp.23.1687213271000; Mon, 19 Jun 2023 15:21:11 -0700 (PDT) Received: from localhost.localdomain ([103.94.185.75]) by smtp.googlemail.com with ESMTPSA id y17-20020a63e251000000b0050a0227a4bcsm161387pgj.57.2023.06.19.15.21.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Jun 2023 15:21:10 -0700 (PDT) To: Jens Gustedt , libc-alpha@sourceware.org Cc: Yonggang Luo Subject: [PATCH 2/5] time: Implement c23 timespec_get base Date: Tue, 20 Jun 2023 06:20:49 +0800 Message-Id: <20230619222052.682-3-luoyonggang@gmail.com> X-Mailer: git-send-email 2.39.0.windows.1 In-Reply-To: <20230619222052.682-1-luoyonggang@gmail.com> References: <20230619222052.682-1-luoyonggang@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Yonggang Luo via Libc-alpha From: Yonggang Luo Reply-To: Yonggang Luo Errors-To: libc-alpha-bounces+incoming=patchwork.ozlabs.org@sourceware.org Sender: "Libc-alpha" These newly implement base are: #define TIME_MONOTONIC 2 #define TIME_PROCESS_CPUTIME_ID 3 #define TIME_THREAD_CPUTIME_ID 4 #define TIME_MONOTONIC_RAW 5 #define TIME_REALTIME_COARSE 6 #define TIME_MONOTONIC_COARSE 7 #define TIME_BOOTTIME 8 #define TIME_REALTIME_ALARM 9 #define TIME_BOOTTIME_ALARM 10 #define TIME_SGI_CYCLE 11 #define TIME_TAI 12 Signed-off-by: Yonggang Luo --- time/time.h | 13 ++++++++++++ time/timespec_get.c | 48 ++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 3 deletions(-) diff --git a/time/time.h b/time/time.h index 368f4dc588..189a560199 100644 --- a/time/time.h +++ b/time/time.h @@ -64,6 +64,19 @@ typedef __pid_t pid_t; /* Time base values for timespec_get. */ # define TIME_UTC 1 #endif +#ifdef __GLIBC_USE_ISOC23 +#define TIME_MONOTONIC 2 +#define TIME_PROCESS_CPUTIME_ID 3 +#define TIME_THREAD_CPUTIME_ID 4 +#define TIME_MONOTONIC_RAW 5 +#define TIME_REALTIME_COARSE 6 +#define TIME_MONOTONIC_COARSE 7 +#define TIME_BOOTTIME 8 +#define TIME_REALTIME_ALARM 9 +#define TIME_BOOTTIME_ALARM 10 +#define TIME_SGI_CYCLE 11 +#define TIME_TAI 12 +#endif __BEGIN_DECLS diff --git a/time/timespec_get.c b/time/timespec_get.c index 9b1d4f22ed..a57b1ee0b8 100644 --- a/time/timespec_get.c +++ b/time/timespec_get.c @@ -22,10 +22,52 @@ int timespec_get (struct timespec *ts, int base) { - if (base == TIME_UTC) + clockid_t clockid = -1; + switch (base) { + default: + break; + case TIME_UTC: + clockid = CLOCK_REALTIME; + break; + case TIME_MONOTONIC: + clockid = CLOCK_MONOTONIC; + break; + case TIME_PROCESS_CPUTIME_ID: + clockid = CLOCK_PROCESS_CPUTIME_ID; + break; + case TIME_THREAD_CPUTIME_ID: + clockid = CLOCK_THREAD_CPUTIME_ID; + break; + case TIME_MONOTONIC_RAW: + clockid = CLOCK_MONOTONIC_RAW; + break; + case TIME_REALTIME_COARSE: + clockid = CLOCK_REALTIME_COARSE; + break; + case TIME_MONOTONIC_COARSE: + clockid = CLOCK_MONOTONIC_COARSE; + break; + case TIME_BOOTTIME: + clockid = CLOCK_BOOTTIME; + break; + case TIME_REALTIME_ALARM: + clockid = CLOCK_REALTIME_ALARM; + break; + case TIME_BOOTTIME_ALARM: + clockid = CLOCK_BOOTTIME_ALARM; + break; + case TIME_SGI_CYCLE: + clockid = CLOCK_SGI_CYCLE; + break; + case TIME_TAI: + clockid = CLOCK_TAI; + break; + } + if (clockid >= 0) { - __clock_gettime (CLOCK_REALTIME, ts); - return base; + if (__clock_gettime (clockid, ts) >= 0) { + return base; + } } return 0; }