From patchwork Fri Sep 29 02:37:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?TWFoZXNoIEJhbmRld2FyICjgpK7gpLngpYfgpLYg4KSs4KSC4KSh4KWH4KS14KS+4KSwKQ==?= X-Patchwork-Id: 13403621 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17B313C29 for ; Fri, 29 Sep 2023 02:37:43 +0000 (UTC) Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6CDF199 for ; Thu, 28 Sep 2023 19:37:41 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a23ad271d7so6895217b3.1 for ; Thu, 28 Sep 2023 19:37:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695955061; x=1696559861; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=iULIiWyEAnuPU2ttI+NrM06ywk49WbVfQ4RXn/AgPAM=; b=I/vZll7uA9wegcqanJIdqng8EUrnkYnt1GPJQk9KYWu0nQrPVfLJnIJQeL5ihRTOQ2 Bi9U18bswSfQ8qi6PRzovsHzHOUfUXi13ftMHlkuu892LRQ1R5VAxiYWYmwu6/rT3YwS IZuUgqFUHqRYOC6YRwfPHIsUrAcfXxP4yqz1KPN4Ba5S7k92U5M44DZQLs9Q6dO5q/WK 8dvyzihu4CngajBUvBj7HvCZNTu4+IDvvbWP04nkrr6TYL+na1yeC0hUbj8sZkBm2Til 89vLuJZJsm91MQQ0+V++GZ835VN43y5ku5eDKZSuqnefUhDTyOqTGy/U+478ZXQQVrYZ agEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695955061; x=1696559861; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=iULIiWyEAnuPU2ttI+NrM06ywk49WbVfQ4RXn/AgPAM=; b=MUZTCdhUtNh5KNdD/MwslgJDwuyWbFrMr+VTmJDCSGpjUI7u1SzU9F4l2+WNThHxrI 8vU6yltxs6KfyVyEqHjIEO4AIxI1KxrcTyfWUGbOsqTJURrdBSNOkhD+rz6uSXakGC5U dAY46uMMxp90ebwu9VERvFczUqERxChNMlBdN65MCq2UKj7THHOP1OBe/VkJMHYx126F zhDy5OP0fv9k0FePK0HGTiEMi01HwswNcSZS4Xmvowcg+a4wKPkDqVsP9xgX0JHzcuow Yc6CiEdtXkkwTt75IBuvjv8HwwkVaxyGP/2RMK5L+SVrd0nnhiZ1+Ds+if3mAiwBQF/k XUYg== X-Gm-Message-State: AOJu0YypWgZPXP2LU2TvjQGNAqd/ZCOODNRiVz49dce11UmzPMkxxYn9 pCE2myKlrfYS9LyHhPh/6EaCyyf/3s6SWOaboqkEtjMZioCv1lVoo+kZlDRSIf4K6c+TTjlas3s /hLhub2fpC47njjLkIvdL7bN+T+mk4G+7kNPznDr+tPU3beo43k7Wdllm9kA3vBZj X-Google-Smtp-Source: AGHT+IF2UHiH6MYgJLyQsGuGuNbtJkhEi9ISCxSd9hNIt5Rms531nuclGSwkAHF9z6nkcArPAwGZzrrkT3Yr X-Received: from coldfire.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2b7a]) (user=maheshb job=sendgmr) by 2002:a25:6812:0:b0:d13:856b:c10a with SMTP id d18-20020a256812000000b00d13856bc10amr38603ybc.3.1695955060095; Thu, 28 Sep 2023 19:37:40 -0700 (PDT) Date: Thu, 28 Sep 2023 19:37:37 -0700 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog Message-ID: <20230929023737.1610865-1-maheshb@google.com> Subject: [PATCH 1/4] time: add ktime_get_cycles64() api From: Mahesh Bandewar To: Netdev , Linux , David Miller , Jakub Kicinski , Eric Dumazet , Paolo Abeni Cc: Jonathan Corbet , Don Hatchett , Yuliang Li , Mahesh Bandewar , Mahesh Bandewar , John Stultz , Thomas Gleixner , Stephen Boyd , Richard Cochran X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 lindbergh.monkeyblade.net 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 = &tk_core.timekeeper; + unsigned int seq; + u64 now; + + WARN_ON_ONCE(timekeeping_suspended); + + do { + seq = read_seqcount_begin(&tk_core.seq); + now = tk_clock_read(&tk->tkr_mono); + } while (read_seqcount_retry(&tk_core.seq, seq)); + + *ts = ns_to_timespec64(now); +} +EXPORT_SYMBOL_GPL(ktime_get_cycles64); + /** * ktime_get_seconds - Get the seconds portion of CLOCK_MONOTONIC * From patchwork Fri Sep 29 02:37:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?TWFoZXNoIEJhbmRld2FyICjgpK7gpLngpYfgpLYg4KSs4KSC4KSh4KWH4KS14KS+4KSwKQ==?= X-Patchwork-Id: 13403622 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA70D46AE for ; Fri, 29 Sep 2023 02:37:45 +0000 (UTC) Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 260351A5 for ; Thu, 28 Sep 2023 19:37:44 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-59f8188b718so173652337b3.1 for ; Thu, 28 Sep 2023 19:37:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695955063; x=1696559863; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=nIHaxhAoJd7uqW2IBjHfoZybMFoN9LgbXxplOyXZzn8=; b=bPuh26LGYqk1JacugXDz8GvIhf08jQ7HS1VIUdM9HaKGEHRAcpwvsywdpmzStfaU6x 6U3NMhmQbVR/6WqmE6qrnlbNlNz8l5HZuRchJBZe9gkp49ovHKQSDWKiVFjrylUSUBwY 3kN5g1R5VusA3wPQKqWDCyCe33hHn7FPYsN54SxxPYWOxOGvEFitqzhMP5VpWLXq3psy BSmNlhFML0K2KLGEhlAgITBi3fPfyYew+H0Wj7fXKTToF792DZzkKHY7ANTUjQ3WfEZz Ok51cih6JuIJ1bkC7fnmeIvlGOqV79jtaPFBm18iv70t6jVOx53Zeb40nxQwAU0fR1TY xAlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695955063; x=1696559863; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=nIHaxhAoJd7uqW2IBjHfoZybMFoN9LgbXxplOyXZzn8=; b=Mnx2TCvSmD5I4ysCHdauKukq/08ERyYdiyWkURa3DmA0SHGFBmB3OBKeVpzD65n7nq U+ZmRbZGzwaAyIGL96U1El4T5Sreu3HPQziseK0yj4PViscRYFuLlPLLjl3Skwf4YQgK N1NubmJziOLuY/KwfrjvEjsBLY1K4nCCatq7FvlecYoUoZPZYh4ZMalga2Mo+Xq4WEeS nj5uQaf3U6jAfCRpilZ82WoGa/AiicCM0/oSWQ2qQzqQmSZBaGotIReDQ06mH9M4i/pz 4lfBWl6m57G2pcoMJYN3J9rBRFdFLJr5VQHHt/N+ipv4aI0oPupKFogNKGn8aL7uU8aN yH6Q== X-Gm-Message-State: AOJu0YzOg6/NS5IKOggiSAAqHGM1kHa1QK7RzkdTWX/LRIEpgmy7HAj/ v6K1yJ2X+4CaK8fb4bjTSp2/W+GsFs0aWNJuI+pQv73qIm85LBtPq9aNkhImXZoyzLJq4ExTArD PLL31d/M37hu7c9nzJ8hJelWbTzpxTVE5jNPFj6HjNrXpCiSdzLGb4o/ZpqvCH2T1 X-Google-Smtp-Source: AGHT+IEf1Ys0iOiiWuTEzqwmd93QceZy824b+kpoVoMGTZ1j9BHorHAPDC1Gqx1O1ZgwJF04wu+0I4WHCms4 X-Received: from coldfire.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2b7a]) (user=maheshb job=sendgmr) by 2002:a05:6902:136b:b0:d81:4107:7a1 with SMTP id bt11-20020a056902136b00b00d81410707a1mr40041ybb.2.1695955063070; Thu, 28 Sep 2023 19:37:43 -0700 (PDT) Date: Thu, 28 Sep 2023 19:37:40 -0700 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog Message-ID: <20230929023740.1611161-1-maheshb@google.com> Subject: [PATCH 2/4] ptp: add ptp_gettimex64any() support From: Mahesh Bandewar To: Netdev , Linux , David Miller , Jakub Kicinski , Eric Dumazet , Paolo Abeni Cc: Jonathan Corbet , Don Hatchett , Yuliang Li , Mahesh Bandewar , Mahesh Bandewar , Richard Cochran X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 lindbergh.monkeyblade.net add support for TS sandwich of the user preferred timebase. The options supported are PTP_TS_REAL (CLOCK_REALTIME), PTP_TS_MONO (CLOCK_MONOTONIC), PTP_TS_RAW (CLOCK_MONOTONIC_RAW), PTP_TS_CYCLES (raw-cycles) The option PTP_TS_CYCLES will return the cycles in 'struct timespec64' format so something equivalent of timespec64_to_ns() need to be applied to covert back into cycles. Option of PTP_TS_REAL is equivalent of using ptp_gettimex64(). Signed-off-by: Mahesh Bandewar CC: Richard Cochran CC: "David S. Miller" CC: netdev@vger.kernel.org --- include/linux/ptp_clock_kernel.h | 57 ++++++++++++++++++++++++++++++++ include/uapi/linux/ptp_clock.h | 8 +++++ 2 files changed, 65 insertions(+) diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h index 1ef4e0f9bd2a..87e75354d687 100644 --- a/include/linux/ptp_clock_kernel.h +++ b/include/linux/ptp_clock_kernel.h @@ -102,6 +102,15 @@ struct ptp_system_timestamp { * reading the lowest bits of the PHC timestamp and the second * reading immediately follows that. * + * @gettimex64any: Reads the current time from the hardware clock and + optionally also any of the MONO, MONO_RAW, or SYS clock. + * parameter ts: Holds the PHC timestamp. + * parameter sts: If not NULL, it holds a pair of timestamps from + * the clock of choice. The first reading is made right before + * reading the lowest bits of the PHC timestamp and the second + * reading immediately follows that. + * parameter type: any one of the TS opt from ptp_timestamp_types. + * * @getcrosststamp: Reads the current time from the hardware clock and * system clock simultaneously. * parameter cts: Contains timestamp (device,system) pair, @@ -180,6 +189,9 @@ struct ptp_clock_info { int (*gettime64)(struct ptp_clock_info *ptp, struct timespec64 *ts); int (*gettimex64)(struct ptp_clock_info *ptp, struct timespec64 *ts, struct ptp_system_timestamp *sts); + int (*gettimex64any)(struct ptp_clock_info *ptp, struct timespec64 *ts, + struct ptp_system_timestamp *sts, + enum ptp_ts_types type); int (*getcrosststamp)(struct ptp_clock_info *ptp, struct system_device_crosststamp *cts); int (*settime64)(struct ptp_clock_info *p, const struct timespec64 *ts); @@ -464,4 +476,49 @@ static inline void ptp_read_system_postts(struct ptp_system_timestamp *sts) ktime_get_real_ts64(&sts->post_ts); } +static inline void ptp_read_any_prets(struct ptp_system_timestamp *sts, + enum ptp_ts_types type) +{ + if (sts) { + switch (type) { + case PTP_TS_CYCLES: + ktime_get_cycles64(&sts->pre_ts); + break; + case PTP_TS_REAL: + ktime_get_real_ts64(&sts->pre_ts); + break; + case PTP_TS_MONO: + ktime_get_ts64(&sts->pre_ts); + break; + case PTP_TS_RAW: + ktime_get_raw_ts64(&sts->pre_ts); + break; + default: + break; + } + } +} + +static inline void ptp_read_any_postts(struct ptp_system_timestamp *sts, + enum ptp_ts_types type) +{ + if (sts) { + switch (type) { + case PTP_TS_CYCLES: + ktime_get_cycles64(&sts->post_ts); + break; + case PTP_TS_REAL: + ktime_get_real_ts64(&sts->post_ts); + break; + case PTP_TS_MONO: + ktime_get_ts64(&sts->post_ts); + break; + case PTP_TS_RAW: + ktime_get_raw_ts64(&sts->post_ts); + break; + default: + break; + } + } +} #endif diff --git a/include/uapi/linux/ptp_clock.h b/include/uapi/linux/ptp_clock.h index 05cc35fc94ac..1f1e98966cff 100644 --- a/include/uapi/linux/ptp_clock.h +++ b/include/uapi/linux/ptp_clock.h @@ -69,6 +69,14 @@ */ #define PTP_PEROUT_V1_VALID_FLAGS (0) +enum ptp_ts_types { + PTP_TS_CYCLES = 0, + PTP_TS_REAL, + PTP_TS_MONO, + PTP_TS_RAW, + PTP_TS_MAX, +}; + /* * struct ptp_clock_time - represents a time value * From patchwork Fri Sep 29 02:37:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?TWFoZXNoIEJhbmRld2FyICjgpK7gpLngpYfgpLYg4KSs4KSC4KSh4KWH4KS14KS+4KSwKQ==?= X-Patchwork-Id: 13403623 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DC5CE3D67 for ; Fri, 29 Sep 2023 02:37:48 +0000 (UTC) Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C2A91A7 for ; Thu, 28 Sep 2023 19:37:47 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-59f8134ec00so174712717b3.3 for ; Thu, 28 Sep 2023 19:37:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695955066; x=1696559866; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=lqddVV7lEvzc1PVC4l13jtQo0ILYRjKD+2QyANiZoos=; b=ThPgjp8HumPnZygQEdqfj+AMQ7/gwrbgp9JnRffJGAeVrCn2MnH4Ask+NxAgde3Zwf zjUfw4FxmdHLqg2ZNo6F8+kM8pOIHq84nEaVP7f3jq9N1B1Jkkr99J50aydr05WCr7PS SW9jtIugb306IU5p3ljLkIJ5er7tyV2nPD7XYbnYFR2T6/XjM1G4T6/rdwa3keHActIs Abfcjhceco1w1RXYyU973auO1ma6cQ5z6lVs3z7bBC7DPNXsMgJXvHnszrX9XA+1B4tK Ru3DawxuwnCnXpWDF9aLZeW+RyGk4elRoASVDvAKavNc0HXrKisAcN2o2+2+l0hhhMwM azCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695955066; x=1696559866; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=lqddVV7lEvzc1PVC4l13jtQo0ILYRjKD+2QyANiZoos=; b=r4ou2NAy3J/DzEvNpRkQuuGGSj783sCApH10uiHrEzgPqSyny9xtSTYGnez/p626XW LkhniwHemA+Wu4X86JNc9QEsb9seBcn3ynb+Fzgvio6C/HOvm+kE80UDAL7/rOzJdXQq jKCrmUJTjVXiBYrGIqfvfoSc8EGn3QF1aKhsvRZjryfTLssyWbqI7PSyiSK/fIs1TKhT neUGXvWpLb71kEv/23co8+qRaTEfvciS9TIc9azcxdhn+q1cri+T9/JxdVP3pg2xlk9m bYPcHt8nQVVqws6lVCu5IqT/Mf5FUJmuZxWnInMZ2716xxjRADCILw+mGE3SXDD2PHtC maUQ== X-Gm-Message-State: AOJu0YwTHTjZt6BpN4NfuFmuRcCGi6xyd2Czu3lxsHXTBmmeYpWW/IKW 7ICZik7D3ZpCuA6ZRW+PpdTHOzQIzmTPV2yheXE6AZOZHgoKjVp5OI32p5CvY6m9Lf+ECAm91/n 79pQPg9k13mUQAocV+W5MiFc6Xh5PlbTpVWZjciLw6duFlhHaKoRIO6U7QaTmSBbQ X-Google-Smtp-Source: AGHT+IHGbL/PIFGONu27JjSbRgA0yNsOz82qS235Cd/7Is9loYVYaFFROcCTi2MDrziho8IDGG/6gC04f7Yr X-Received: from coldfire.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2b7a]) (user=maheshb job=sendgmr) by 2002:a25:6f54:0:b0:d77:bcce:eb11 with SMTP id k81-20020a256f54000000b00d77bcceeb11mr41975ybc.10.1695955065762; Thu, 28 Sep 2023 19:37:45 -0700 (PDT) Date: Thu, 28 Sep 2023 19:37:43 -0700 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog Message-ID: <20230929023743.1611460-1-maheshb@google.com> Subject: [PATCH 3/4] ptp: add ioctl interface for ptp_gettimex64any() From: Mahesh Bandewar To: Netdev , Linux , David Miller , Jakub Kicinski , Eric Dumazet , Paolo Abeni Cc: Jonathan Corbet , Don Hatchett , Yuliang Li , Mahesh Bandewar , Mahesh Bandewar , Richard Cochran , Rahul Rameshbabu X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, 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 lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org add an ioctl op PTP_SYS_OFFSET_ANY2 to support ptp_gettimex64any() method Signed-off-by: Mahesh Bandewar CC: Richard Cochran CC: Rahul Rameshbabu CC: "David S. Miller" CC: netdev@vger.kernel.org --- drivers/ptp/ptp_chardev.c | 34 ++++++++++++++++++++++++++++++++++ include/uapi/linux/ptp_clock.h | 14 ++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/drivers/ptp/ptp_chardev.c b/drivers/ptp/ptp_chardev.c index 362bf756e6b7..fef1c7e7e6e6 100644 --- a/drivers/ptp/ptp_chardev.c +++ b/drivers/ptp/ptp_chardev.c @@ -110,6 +110,7 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg) { struct ptp_clock *ptp = container_of(pc, struct ptp_clock, clock); struct ptp_sys_offset_extended *extoff = NULL; + struct ptp_sys_offset_any *anyoff = NULL; struct ptp_sys_offset_precise precise_offset; struct system_device_crosststamp xtstamp; struct ptp_clock_info *ops = ptp->info; @@ -324,6 +325,39 @@ long ptp_ioctl(struct posix_clock *pc, unsigned int cmd, unsigned long arg) err = -EFAULT; break; + case PTP_SYS_OFFSET_ANY2: + if (!ptp->info->gettimex64any) { + err = -EOPNOTSUPP; + break; + } + anyoff = memdup_user((void __user *)arg, sizeof(*anyoff)); + if (IS_ERR(anyoff)) { + err = PTR_ERR(anyoff); + anyoff = NULL; + break; + } + if (anyoff->n_samples > PTP_MAX_SAMPLES + || anyoff->ts_type >= PTP_TS_MAX + || anyoff->rsv[0] || anyoff->rsv[1]) { + err = -EINVAL; + break; + } + for (i = 0; i < anyoff->n_samples; i++) { + err = ptp->info->gettimex64any(ptp->info, &ts, &sts, + anyoff->ts_type); + if (err) + goto out; + anyoff->ts[i][0].sec = sts.pre_ts.tv_sec; + anyoff->ts[i][0].nsec = sts.pre_ts.tv_nsec; + anyoff->ts[i][1].sec = ts.tv_sec; + anyoff->ts[i][1].nsec = ts.tv_nsec; + anyoff->ts[i][2].sec = sts.post_ts.tv_sec; + anyoff->ts[i][2].nsec = sts.post_ts.tv_nsec; + } + if (copy_to_user((void __user *)arg, anyoff, sizeof(*anyoff))) + err = -EFAULT; + break; + case PTP_SYS_OFFSET: case PTP_SYS_OFFSET2: sysoff = memdup_user((void __user *)arg, sizeof(*sysoff)); diff --git a/include/uapi/linux/ptp_clock.h b/include/uapi/linux/ptp_clock.h index 1f1e98966cff..73bd17055a37 100644 --- a/include/uapi/linux/ptp_clock.h +++ b/include/uapi/linux/ptp_clock.h @@ -166,6 +166,18 @@ struct ptp_sys_offset_extended { struct ptp_clock_time ts[PTP_MAX_SAMPLES][3]; }; +struct ptp_sys_offset_any { + unsigned int n_samples; /* Desired number of measurements. */ + enum ptp_ts_types ts_type; /* One of the TS types */ + unsigned int rsv[2]; /* Reserved for future use. */ + /* + * Array of [TS, phc, TS] time stamps. The kernel will provide + * 3*n_samples time stamps. + * TS is any of the ts_type requested. + */ + struct ptp_clock_time ts[PTP_MAX_SAMPLES][3]; +}; + struct ptp_sys_offset_precise { struct ptp_clock_time device; struct ptp_clock_time sys_realtime; @@ -232,6 +244,8 @@ struct ptp_pin_desc { _IOWR(PTP_CLK_MAGIC, 17, struct ptp_sys_offset_precise) #define PTP_SYS_OFFSET_EXTENDED2 \ _IOWR(PTP_CLK_MAGIC, 18, struct ptp_sys_offset_extended) +#define PTP_SYS_OFFSET_ANY2 \ + _IOWR(PTP_CLK_MAGIC, 19, struct ptp_sys_offset_any) struct ptp_extts_event { struct ptp_clock_time t; /* Time event occured. */ From patchwork Fri Sep 29 02:37:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?TWFoZXNoIEJhbmRld2FyICjgpK7gpLngpYfgpLYg4KSs4KSC4KSh4KWH4KS14KS+4KSwKQ==?= X-Patchwork-Id: 13403624 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11AD93D86 for ; Fri, 29 Sep 2023 02:37:56 +0000 (UTC) Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E920BCD2 for ; Thu, 28 Sep 2023 19:37:52 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a23fed55d7so1833667b3.2 for ; Thu, 28 Sep 2023 19:37:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695955069; x=1696559869; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=J1TE309bBWo1Vh5NP1cqOVIYWRTh5KzFt/cUsR9m0tw=; b=mB+37de2/joJOed2sCDLZex4lUXV7sJxrfTBMMRkV0jDXW4HrXQ+VpHSDiphDJfdoT qVgZ+ZoH3u9NaByy22KYxUd1GUrHHV6x5ssLcDxBfULjCeZV0+yOVYKB24A+lDKKWkGV uWuuHN7j+GN4ebF9WoVhGuN32wiOCbX1t74CHLIxOkrSb7RRvLYAhDa4zXg9gPrVK0F1 AVw6Q044q4/9WPwz2KQq1n0TZEdSYLtvssyWsnGdO8YtbuGeELVRIZFMLQ+8Utaac/i9 iZv9NPgYf/0apuoJhsZcJrCD5V3VA/HARVMISSz/Cdhf4Q6p3JKUQWwmHi47w6mk1Kz5 WAZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695955069; x=1696559869; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=J1TE309bBWo1Vh5NP1cqOVIYWRTh5KzFt/cUsR9m0tw=; b=gGt8LjWBxO8Ff34yh6OTF2hcSg+crmFoBGqN5qBwJdqxsjGD1XeSzc5nXYStbpBPP4 kYygjK2KdZJLQsm9ZzlYhXIVugkLpxlPwHjLOcwMJkRftn/1LIRoBVJ0akwzpp9bIWSp m4rhdviljxIkThJOW5fuPrAzXsTkMxOYh8Oq3yxfmgiLRnVpHWtTWuKS9qmtQhdjqDGz TbvSKEMW/sf6PfzctXQZylAQyv/VcOs0EHzql8vCf71So3D4WZ9cvl5zgo6bmcQXwvbI 2udJNtD9Yvb4CGR/FJUIzQJzkRt5Ld8BbBMDTRBMSXVezakB7EIJsJk4J1orehKUprKC 9PEQ== X-Gm-Message-State: AOJu0YzoT7WBpn6jlFK6EbdwSj2JKjnvk1RQka7Zu/RWR5WCsO8Ro0YL a9lQKG4EoUafyeKBTMLTyXt9VFY0+fA1HKHdj7P0RhKJbXaEr83NUAusHx7u1QsH0vqH5qoJQY4 rpVx8M4AZxraYYJ0Ao6XKB9g7r73rl4MpLvyLhSjeISB4H2C8N1TXeqK3UWvtyKDo X-Google-Smtp-Source: AGHT+IHVTScoKaSEvfGVXfqeuBbzXllHca9a/wLpi4eQpTpBcasohPTD8HrdbO9WizVnf3ZoPhgt58dQCqjF X-Received: from coldfire.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2b7a]) (user=maheshb job=sendgmr) by 2002:a81:b601:0:b0:59b:e845:4f9e with SMTP id u1-20020a81b601000000b0059be8454f9emr41825ywh.4.1695955069238; Thu, 28 Sep 2023 19:37:49 -0700 (PDT) Date: Thu, 28 Sep 2023 19:37:46 -0700 Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog Message-ID: <20230929023746.1611832-1-maheshb@google.com> Subject: [PATCH 4/4] selftes/ptp: extend test to include ptp_gettimex64any() From: Mahesh Bandewar To: Netdev , Linux , David Miller , Jakub Kicinski , Eric Dumazet , Paolo Abeni Cc: Jonathan Corbet , Don Hatchett , Yuliang Li , Mahesh Bandewar , Mahesh Bandewar , Shuah Khan , Richard Cochran , Rahul Rameshbabu , linux-kselftest@vger.kernel.org X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,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 lindbergh.monkeyblade.net add -y/-Y options to support PTP_SYS_OFFSET_ANY2 op. where -y represents samples to collect while -Y is to choose the timebase from available options of cycles, real, mono, or raw. Signed-off-by: Mahesh Bandewar CC: Shuah Khan CC: Richard Cochran CC: "David S. Miller" CC: Rahul Rameshbabu CC: Jakub Kicinski CC: linux-kselftest@vger.kernel.org CC: netdev@vger.kernel.org --- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/ptp/testptp.c | 79 ++++++++++++++++++++++++++- 2 files changed, 78 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/Makefile b/tools/testing/selftests/Makefile index 42806add0114..c5e59cfc9830 100644 --- a/tools/testing/selftests/Makefile +++ b/tools/testing/selftests/Makefile @@ -66,6 +66,7 @@ TARGETS += powerpc TARGETS += prctl TARGETS += proc TARGETS += pstore +TARGETS += ptp TARGETS += ptrace TARGETS += openat2 TARGETS += resctrl diff --git a/tools/testing/selftests/ptp/testptp.c b/tools/testing/selftests/ptp/testptp.c index c9f6cca4feb4..7000caa39ede 100644 --- a/tools/testing/selftests/ptp/testptp.c +++ b/tools/testing/selftests/ptp/testptp.c @@ -37,6 +37,13 @@ #define NSEC_PER_SEC 1000000000LL +static char *time_base_arr[PTP_TS_MAX] = { + "cycles", + "system time", + "monotonic time", + "raw-monotonic time", +}; + /* clock_adjtime is not available in GLIBC < 2.14 */ #if !__GLIBC_PREREQ(2, 14) #include @@ -145,8 +152,10 @@ static void usage(char *progname) " -T val set the ptp clock time to 'val' seconds\n" " -x val get an extended ptp clock time with the desired number of samples (up to %d)\n" " -X get a ptp clock cross timestamp\n" + " -y val get an extended-any ptp clock time with the desired number of samples (up to %d) with given time-base for sandwich (with -Y opt)\n" + " -Y val sandwich timebase to use {cycles|real|mono|raw}\n" " -z test combinations of rising/falling external time stamp flags\n", - progname, PTP_MAX_SAMPLES); + progname, PTP_MAX_SAMPLES, PTP_MAX_SAMPLES); } int main(int argc, char *argv[]) @@ -162,6 +171,7 @@ int main(int argc, char *argv[]) struct ptp_sys_offset *sysoff; struct ptp_sys_offset_extended *soe; struct ptp_sys_offset_precise *xts; + struct ptp_sys_offset_any *ats; char *progname; unsigned int i; @@ -182,6 +192,8 @@ int main(int argc, char *argv[]) int pct_offset = 0; int getextended = 0; int getcross = 0; + int get_ext_any = 0; + int ext_any_type = -1; int n_samples = 0; int pin_index = -1, pin_func; int pps = -1; @@ -196,7 +208,7 @@ int main(int argc, char *argv[]) progname = strrchr(argv[0], '/'); progname = progname ? 1+progname : argv[0]; - while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:Xz"))) { + while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:Xy:Y:z"))) { switch (c) { case 'c': capabilities = 1; @@ -273,6 +285,31 @@ int main(int argc, char *argv[]) case 'X': getcross = 1; break; + case 'y': + get_ext_any = atoi(optarg); + if (get_ext_any < 1 || get_ext_any > PTP_MAX_SAMPLES) { + fprintf(stderr, + "number of extended-any timestamp samples must be between 1 and %d; was asked for %d\n", + PTP_MAX_SAMPLES, get_ext_any); + return -1; + } + break; + case 'Y': + if (!strcasecmp(optarg, "cycles")) + ext_any_type = PTP_TS_CYCLES; + else if (!strcasecmp(optarg, "real")) + ext_any_type = PTP_TS_REAL; + else if (!strcasecmp(optarg, "mono")) + ext_any_type = PTP_TS_MONO; + else if (!strcasecmp(optarg, "raw")) + ext_any_type = PTP_TS_RAW; + else { + fprintf(stderr, + "type needs to be one of cycles,real,mono,raw only; was given %s\n", + optarg); + return -1; + } + break; case 'z': flagtest = 1; break; @@ -286,6 +323,14 @@ int main(int argc, char *argv[]) } } + /* For ptp_sys_offset_any both options 'y' and 'Y' must be given */ + if (get_ext_any > 0 && ext_any_type == -1) { + fprintf(stderr, + "For extended-any TS both options -y, and -Y are required.\n"); + usage(progname); + return -1; + } + fd = open(device, O_RDWR); if (fd < 0) { fprintf(stderr, "opening %s: %s\n", device, strerror(errno)); @@ -604,6 +649,36 @@ int main(int argc, char *argv[]) free(xts); } + if (get_ext_any) { + ats = calloc(1, sizeof(*ats)); + if (!ats) { + perror("calloc"); + return -1; + } + + ats->n_samples = get_ext_any; + ats->ts_type = ext_any_type; + + if (ioctl(fd, PTP_SYS_OFFSET_ANY2, ats)) { + perror("PTP_SYS_OFFSET_ANY2"); + } else { + printf("extended-any timestamp request returned %d samples\n", + get_ext_any); + + for (i = 0; i < get_ext_any; i++) { + printf("sample #%2d: %s before: %lld.%09u\n", + i, time_base_arr[ext_any_type], + ats->ts[i][0].sec, ats->ts[i][0].nsec); + printf(" phc time: %lld.%09u\n", + ats->ts[i][1].sec, ats->ts[i][1].nsec); + printf(" %s after: %lld.%09u\n", + time_base_arr[ext_any_type], + ats->ts[i][2].sec, ats->ts[i][2].nsec); + } + } + + free(ats); + } close(fd); return 0; }