Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp3823150rdh; Fri, 29 Sep 2023 03:32:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEUvMcmQ+Tco8H78IaH7EvsKDZjB7lXS4qALdGnjsf9175u8Bt8vEoA+gVv5ZHXO0RThzHf X-Received: by 2002:a17:90a:6c04:b0:274:9121:382 with SMTP id x4-20020a17090a6c0400b0027491210382mr5950296pjj.22.1695983575369; Fri, 29 Sep 2023 03:32:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695983575; cv=none; d=google.com; s=arc-20160816; b=Op2FnnQ+cOuwJJTUWzl6SX46xtGv728cONnA1/nPtgg3w79v79h4NVZi9MFoFCHD+U 8xwX9iJxcA3pNqu/yBp1ZoHoCrTyQmHvIih0TwaJzdgeuCOORSF3INNv248CNEqjUNKb fVZUlsjMa3zYriR40lo6gvTaT8ihOPRdOPQL+RtsMkfH1TvfGdkr3TF5mbqgy0MhG9xK 0Q7QYX7rYiEXaYjNerglMR/FHgfpd42RR3329unv8gow1R4WfbgmXxXvk6MDY+9RkOch YI6AX3hMKHADap4UMgyXlOELBuMh20M2E98QmEM9GCzETtKPJXr2lKUWUSFpMi88aJ2Q ZFJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=efBzdUz4E1mRCTntOxAJpAn2plhV/lB8ZB1zgWlI4Es=; fh=+9K87vgVCwC6h6JJsT5ymgsBoOZHZPEqIXOCmROLrc4=; b=qSIIsZLv1+1qyiGthu3pY6TiLi6c/6btm5aJcY3JBgXAYZ7pXef6QIVHKAbDZMFULo QCOOZUdsCDwiTaFBnHuE4ejbNzpBzRxlNA7gSZiTV85hUu4kNQovMK9b1/cAr3x+j2CM GYGn9dTsaKwjX9Hg17XJ66rn++tPqyHTjRBmXtp5uuZD7YFS4xSOOuMFvIcQ0Orh07LW TsNhHkMFQrx7QVkC5m2q7k+Jt6YpC5bBRM3CH5NHNUMSjIY14BWsCZEcCrg3p9Khejrh EIOEcehd3Qqyj0I1HT+hH8pCNF23LZU4cL5QIpWoFVd5II1mkz9x7pndKNhLDIG+OYrb wF5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="qFZsdQ2/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id a5-20020a17090a854500b00263f3c1bb86si1266504pjw.158.2023.09.29.03.32.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 03:32:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="qFZsdQ2/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 60A8E8363C6B; Thu, 28 Sep 2023 22:18:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232624AbjI2FPt (ORCPT + 99 others); Fri, 29 Sep 2023 01:15:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232601AbjI2FPr (ORCPT ); Fri, 29 Sep 2023 01:15:47 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 57FA51AE for ; Thu, 28 Sep 2023 22:15:42 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-4053f24c900so35305e9.1 for ; Thu, 28 Sep 2023 22:15:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695964541; x=1696569341; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=efBzdUz4E1mRCTntOxAJpAn2plhV/lB8ZB1zgWlI4Es=; b=qFZsdQ2/AJsIWGzh5XHhi3g39MBk/Xnoyz/gYvIk30VzlbI7LT8g1AZBv44DPAGCT6 wceMos8tzUddDYgpdgBtapeGs6yU+V+MBtQm367Cg7Vw71FQsWpdFQ6chNVmhkjuVuwg bp+VWfZBk1pzbKWVvRvzRu2GxK1ltWv9ZoYGhtEvjBSwEjaYa2wcUiH18va7FlPZjFlK BTxY+esuFz8Q9Lbg8564RlMbovuXrp/7KRrNpQH4CWBQ9Q2hXtaHpC6ngQOYedBEtbax s2/j6Jtaob2BWMjF365ocfscZ8YSDi9g6UYkWlW9LmYaOC+kHIdkKymRQzynGTtEalrt byOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695964541; x=1696569341; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=efBzdUz4E1mRCTntOxAJpAn2plhV/lB8ZB1zgWlI4Es=; b=rjlzzZF+ZOuCDBQT8/BsT0v0qZlNM+YxrDkAoqGsqiTAza+u8pLHrNPL8u54nq4WNq oltCCit/SBex63ctgWr2NB4PzIIp+zUOLMBQxSHfAc/3gO1QYiTsJ73yQ6EcqU9MmukO v5c24/wTW7DYaYgb9KXhyXlzQvPdp6aWaUrAZfBZ6kAuRYKdXpNDnbSy3PWOTvtVhRpV 8aSrJfkg3qLOnC/+r0HgTzHRyzzm/ZxRKj7lUdk5ojBDwM3ekoNQmyvvEBYgFrGMvWzr 9vNYGjpN+mkpp14K8A/YpiA6Ioer8gMh9BdKFP2Jwv0WnM++1/R6lkTgw+pv801yKFZ9 HMEA== X-Gm-Message-State: AOJu0YxlMVU/KLjAZiLkQ1NI+rX/exzj+vKVjCrO9iV7fy1yzPSOGRxG BtHdGDuGywNSrfvUGCbQKXZrlm+37IIfGrFhV5AK X-Received: by 2002:a7b:c445:0:b0:400:46db:1bf2 with SMTP id l5-20020a7bc445000000b0040046db1bf2mr431969wmi.2.1695964540632; Thu, 28 Sep 2023 22:15:40 -0700 (PDT) MIME-Version: 1.0 References: <20230929023737.1610865-1-maheshb@google.com> In-Reply-To: <20230929023737.1610865-1-maheshb@google.com> From: John Stultz Date: Thu, 28 Sep 2023 22:15:27 -0700 Message-ID: Subject: Re: [PATCH 1/4] time: add ktime_get_cycles64() api To: Mahesh Bandewar Cc: Netdev , Linux , David Miller , Jakub Kicinski , Eric Dumazet , Paolo Abeni , Jonathan Corbet , Don Hatchett , Yuliang Li , Mahesh Bandewar , Thomas Gleixner , Stephen Boyd , Richard Cochran Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Thu, 28 Sep 2023 22:18:20 -0700 (PDT) On Thu, Sep 28, 2023 at 7:37=E2=80=AFPM Mahesh Bandewar wrote: > > add a method to retrieve raw cycles in the same fashion as there are > ktime_get_* methods available for supported time-bases. The method > continues using the 'struct timespec64' since the UAPI uses 'struct > ptp_clock_time'. > > The caller can perform operation equivalent of timespec64_to_ns() to > retrieve raw-cycles value. The precision loss because of this conversion > should be none for 64 bit cycle counters and nominal at 96 bit counters > (considering UAPI of s64 + u32 of 'struct ptp_clock_time). > > Signed-off-by: Mahesh Bandewar > CC: John Stultz > CC: Thomas Gleixner > CC: Stephen Boyd > CC: Richard Cochran > CC: netdev@vger.kernel.org > CC: linux-kernel@vger.kernel.org > --- > include/linux/timekeeping.h | 1 + > kernel/time/timekeeping.c | 24 ++++++++++++++++++++++++ > 2 files changed, 25 insertions(+) > > diff --git a/include/linux/timekeeping.h b/include/linux/timekeeping.h > index fe1e467ba046..5537700ad113 100644 > --- a/include/linux/timekeeping.h > +++ b/include/linux/timekeeping.h > @@ -43,6 +43,7 @@ extern void ktime_get_ts64(struct timespec64 *ts); > extern void ktime_get_real_ts64(struct timespec64 *tv); > extern void ktime_get_coarse_ts64(struct timespec64 *ts); > extern void ktime_get_coarse_real_ts64(struct timespec64 *ts); > +extern void ktime_get_cycles64(struct timespec64 *ts); > > void getboottime64(struct timespec64 *ts); > > diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c > index 266d02809dbb..35d603d21bd5 100644 > --- a/kernel/time/timekeeping.c > +++ b/kernel/time/timekeeping.c > @@ -989,6 +989,30 @@ void ktime_get_ts64(struct timespec64 *ts) > } > EXPORT_SYMBOL_GPL(ktime_get_ts64); > > +/** > + * ktime_get_cycles64 - get the raw clock cycles in timespec64 format > + * @ts: pointer to timespec variable > + * > + * This function converts the raw clock cycles into timespce64 format > + * in the varibale pointed to by @ts > + */ > +void ktime_get_cycles64(struct timespec64 *ts) > +{ > + struct timekeeper *tk =3D &tk_core.timekeeper; > + unsigned int seq; > + u64 now; > + > + WARN_ON_ONCE(timekeeping_suspended); > + > + do { > + seq =3D read_seqcount_begin(&tk_core.seq); > + now =3D tk_clock_read(&tk->tkr_mono); > + } while (read_seqcount_retry(&tk_core.seq, seq)); > + > + *ts =3D ns_to_timespec64(now); > +} Hey Mahesh, Thanks for sending this out. Unfortunately, I'm a bit confused by this. It might be helpful to further explain what this would be used for in more detail? Some aspects that are particularly unclear: 1) You seem to be trying to stuff cycle values into a timespec64, which is not very intuitive (and a type error of sorts). It's not clear /why/ that type is useful. 2) Depending on your clocksource, this would have very strange wrapping behavior, so I'm not sure it is generally safe to use. 3) Nit: The interface is called ktime_get_cycles64 (timespec64 returning interfaces usually are postfixed with ts64). I guess could you clarify why you need this instead of using CLOCK_MONOTONIC_RAW which tries to abstract raw cycles in a way that is safe and avoids wrapping across various clocksources? thanks -john