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: 146397 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3738458vqu; Thu, 28 Sep 2023 19:38:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJeYPN9Stod35DLdSgjN3p9j9u63eCcub15kK35U5JO2rcR+RzS6vvv4kvF5etghk9OKM7 X-Received: by 2002:a17:902:e809:b0:1c5:6d04:75ee with SMTP id u9-20020a170902e80900b001c56d0475eemr2999327plg.21.1695955084268; Thu, 28 Sep 2023 19:38:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695955084; cv=none; d=google.com; s=arc-20160816; b=VeEbH1OX3R/ngGQyhbubuDADYQeZxMM03jFvngERCmHJtJWWkYoNLj2jg4BwpeMdzZ TACe4lWprLUsErzWa/jd/A7EnnTJWZNHQCJJHPMw+oUKr3JAAJr3vGiApUUjij5Irzad Trwt6vNEZVT1eGSsZSfn/oWAFG/KFkep7Hp/YKIz8OnlTHKv2XqjEn1BrsMvRugwmizT OKQK7vzkjqDSUtatiCwmEtwN8iF/C3xKXeRJXXToKKJvLS6id+xYp5TE9Y4+zerqdkfO wYoFMhtZMaRQ7fRANGl9bwHeei2fU+2u1CNrmmh0Ob0YlctcuDeBf15sqHjzNDVmnCp8 buMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=iULIiWyEAnuPU2ttI+NrM06ywk49WbVfQ4RXn/AgPAM=; fh=+k6v5Gd7YkIfpyHkdt8+IKxsXqtJvTtVji+AUX4Rj0M=; b=oPyOg7wd961k+GFRhHExJSzp5PionUVO8HprPACF1cSP4Jui9tThwV8EAUczZEvrlT 1cWbZsr7dS6ucSFay8xCsgp+UMXMV6kdwCcfgOsLYzZl7E8d1fYvcmVPt9l6BTdctD2Z s8HAOtldkyQ2RQk9dUBM1yca5+cRsn9N0cS7xq21f70VEpvGMC4oeqe+inn7xvFDCQcZ kluoIrvFvbwp8L1y8h64Q1KuuXeYM+I4MAWGTju7JMhvY+fesYZWc6U/GfEVauNDceul dY5mvTbHBraoEwQyKAZycWj5WOUF+mQMsxSKaZ0vY/nXksFY1HvyL7lvsOsKFumNeQKi 6O+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vFsFeWoJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id km3-20020a17090327c300b001c35864fdbbsi17927415plb.406.2023.09.28.19.38.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 19:38:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=vFsFeWoJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id A0BEB83BE805; Thu, 28 Sep 2023 19:37:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230257AbjI2Chr (ORCPT + 21 others); Thu, 28 Sep 2023 22:37:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229541AbjI2Chm (ORCPT ); Thu, 28 Sep 2023 22:37:42 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1FDC1A3 for ; Thu, 28 Sep 2023 19:37:40 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d85fc6261ffso20430729276.1 for ; Thu, 28 Sep 2023 19:37:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1695955060; x=1696559860; 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=vFsFeWoJZreuLuRPnNzfBGFbw7QPBxRitWxuF/J/pmWEcfCLcryiN8AYKZ2uWDBcmm sFmNiF00AU5Zwn6N4pj3fZBz7HIFV9yojk/6iYuwsaE2NwTDhMwAtVPeN3wnXESsJoWH N3GDqXUEh4qHIJBi4YBCo9vKiqkd4Uipzj9CmkAbtNpylMc6VHOdB0dynDnxfpdHtx/L UuzmWP95AUZaZZbvOlxgc4kMogParp9EKIymf9ir+bqyiVi9ObypLr0TxhnEy4+A7gXn sqDjBs5iXZwU8ntaT09NF9NOU8VGyBIyRV+8Br+rbfjcCy03Gfbv2LRyayapTHV2Yf9p vHcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695955060; x=1696559860; 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=pvmoVc0nHg8TVWpdih6EfqSTHWvJVil7ER6Bdb4qBMttWoOhm8+0BdeEV5zXnBENnX 14rOQ7I+w64g8aC8EdnATMbYQNNaTRuMF6zuN5eMQkF94sBwK4MPiRoAb8bi3NAxwfvk EwGnsIiCsMxWBDAude+Vx6wRYF7YyB5Nb5Mct1YcsClEyGJ5RFiK2pu+HnZHu7byWMb4 eDOya0AQQ1by20gRaM7CfYgDhwIEhiXVrJla5QitW6RAuUm/sOD2qt0iTd8q1QYvRxoC GehmtSxFXPiU/xQER/6UvsPaiL0zogttfmgaTwj7kTtis7LbPFInHObIyPDih2i4sU53 iE5A== X-Gm-Message-State: AOJu0YylcRL/UGQGhUcMDrYtWIJLWv2eRghmavGP4PoiWsNInaDADdax gIav6NVzDCUmZ8B93hQOP55OSGnHpNi4 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 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=-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 groat.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 (groat.vger.email [0.0.0.0]); Thu, 28 Sep 2023 19:37:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778337798008692109 X-GMAIL-MSGID: 1778337798008692109 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: 146412 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3769314vqu; Thu, 28 Sep 2023 21:11:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGA3PP2cmFkgvTnC6oj2THwdquFAnpXERc/lHnyQH03FWQ5Yh0gfpKAtfMwSI2dwsCA/OXb X-Received: by 2002:a05:6358:2794:b0:135:85ec:a080 with SMTP id l20-20020a056358279400b0013585eca080mr3164150rwb.32.1695960699078; Thu, 28 Sep 2023 21:11:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695960699; cv=none; d=google.com; s=arc-20160816; b=y11VaMkbq3/c7d/A52cS4W02/ratTYyJCcknhtjTT+glBs5I1+Nt8ET+aCpMQ+3lja JMcQSQyrVaCwQAjxBWbiys5v/3M0V15uj1kSfS1D7NtzrQABJDsCIGPWERh3EYvhVzVQ APApjJjdo/DHyDsDJeZpk9+Be+z+EFFNCJm7ldKiuO5mI/iuEJ+zhGYjxjD9iDk23H2M YQ0QzyWEK0xiSeVI7mTIGSrfO0wkojltWtdBI4IIMaROFpIsjWUpdgp1M3a/g0q7g/ZR Fhl2+w6w1hFWJBL8Exkz77NdOUXUTKnNP/y3N6GUPBoOra/0J63xXD3qu8tJxaNqR1mi OrEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=nIHaxhAoJd7uqW2IBjHfoZybMFoN9LgbXxplOyXZzn8=; fh=iarKena/8n2PABjKSiA6ahZy/I7+DXKOpLweDXOz6ZE=; b=SZWAa8mDgyKXb7m4SDykdSRUiQSFMnwIPT76vadZH3EBnlgTbuneHfxIRRsXNLtM8Y 8vDmJRLQ2v1+vObpXfujbGyFFzJwAeHDGpjGYyB1y2cCvI3SavZUVw97by6bKb1wBuqQ //AblU8Ma2FnA7T2bNSWI1R1YWIGZJaGtQ0QD1NkblG1Y7PeXm6UOT6ukmHlWVie+mYt jASF9yD3khUefv7H01nyWSgRogk432RgGiKjeHNH6YK3uHF1cNe3JucKPrpB0ckKN26u +NKctbF8AQ0xp1m8YiswFlWDRqb8OK7z2sG/CVxZoswGTokYTdH+ZLPuzll4UlYmH/Ff 915w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=bPuh26LG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id ct27-20020a056a000f9b00b0068fca125aaasi16244750pfb.232.2023.09.28.21.11.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 21:11:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=bPuh26LG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 4D90784AB80B; Thu, 28 Sep 2023 19:38:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232321AbjI2Cht (ORCPT + 21 others); Thu, 28 Sep 2023 22:37:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230320AbjI2Chp (ORCPT ); Thu, 28 Sep 2023 22:37:45 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D01F11A4 for ; Thu, 28 Sep 2023 19:37:43 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d81c02bf2beso20635963276.2 for ; Thu, 28 Sep 2023 19:37:43 -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=dJpG2amSFVhFTU3kC1qI7exBDQa1trap+ZFudtYHdu9kQyaod7XnZAQrF/7e3IuZZ3 tk0mgjOAhqslwmrbiU5ZW6FbIHYIG/1SgCKU3Fe8Q1Lm/ZYBg0/b4e7vrVnr1yGctsE/ jDEsFoqeBToOoHyr1mr5LTzz7a6HDkNqh0OhsTtZ6yLhmwHdFjU0Je5m7GWO198VKKWt EPkfsIwxIqrlggwgJoMajlYv2rCVv9K9HZytWl67FBSXQcm3/S/fRO9AGnlyP1fNvdT5 sK+8bQi3/UZOcyfLn9Bx+tRJ1Jr2YeTrbeEFnWNCtIzmGW40xj40f+uJDXBHsJc7iXxy k8/A== X-Gm-Message-State: AOJu0Ywg/akGbNV9q1ifnaShnKtvRtqjCbT1J3SUVZJnzGRVV8iUGS4m XevvRkWRVD88DiuPpxCSJBSYRDe5jJHI 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 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=-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 pete.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 (pete.vger.email [0.0.0.0]); Thu, 28 Sep 2023 19:38:07 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778343686274562101 X-GMAIL-MSGID: 1778343686274562101 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: 146451 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3861245vqu; Fri, 29 Sep 2023 01:16:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHBe3ADfjgXuOZb/uZRzEeTSMMcVrX/q1dypr39qmvdDmmy4pL7PVQ176C47rsD35JF2K3m X-Received: by 2002:a05:6a20:4422:b0:14b:8b82:867f with SMTP id ce34-20020a056a20442200b0014b8b82867fmr4117005pzb.50.1695975363965; Fri, 29 Sep 2023 01:16:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695975363; cv=none; d=google.com; s=arc-20160816; b=Pj0BkmyLe71nBUrj50V0YvNqSdpJytaMWTq15RQSa/cKm9F0/aH54TSy2h4CJrNqhN RTLxvFFQuxRnqGcfWiolEGVOj4unYLFtGjH5lmoND3MkFo353+VlEM+r9mv99PQwdbPc 6l5IekcZv7w8/tQd7jRBchZfgFL2EMfYkDyyqFX0MCaeh+lZTPNg9SAntoEqUo4Vo4j2 iJ3bCunKcfs2/0PxPDzTySwZb/EYNb+AB1vu5IHIlTKH6gMP+napxnP4FJkrFdI9+ov+ PobtOi92lh59QBy3nurpfTPfAJqgkEqu4AwYaX+NJZiIW+KKJOoujAYylGo1f8yb03Oj 1OCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=lqddVV7lEvzc1PVC4l13jtQo0ILYRjKD+2QyANiZoos=; fh=cLvLkL9HGfZLaTe/GCdTFm7AOHVempMxHhTK0cDjnek=; b=df4rrt50BGm6BTJ5TTwsq5sK8ovF+y86y+7bqMAm6LHzEiATxmfoIfclkpMBhQGxc0 Gcaql+dc3/E3mZgHhqpBMYl/NH7uXmgx/jfQKCVQgRxFLu3p1AdrtK4VzmDCp5ejvas1 GkgdXSYOSJC9KfubaMomQH65SGtyIN2LiwOyKWs6JwQGBTLd1llDNjAv0Fl0sRjrejgV u/OLkIViNsKltzmDAvBSTXc59sPFO2+m1WtiBSJetOfjyK9uZKUBPJn8+KDZx4bQ1arW 4S2nGAx+jHZlNSOf4cAGgjjGohdUaEYr41J3ZLD88zdRmeDmCGvyHHCyWj6voabXzoYx 7CDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ThPgjp8H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id i8-20020a170902c94800b001c724f99800si7653533pla.44.2023.09.29.01.16.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Sep 2023 01:16:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ThPgjp8H; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 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 howler.vger.email (Postfix) with ESMTP id 5D71F80AF829; Thu, 28 Sep 2023 19:37:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232507AbjI2Chx (ORCPT + 21 others); Thu, 28 Sep 2023 22:37:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44180 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231576AbjI2Cht (ORCPT ); Thu, 28 Sep 2023 22:37:49 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A6ED1A3 for ; Thu, 28 Sep 2023 19:37:47 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d84acda47aeso23067111276.3 for ; Thu, 28 Sep 2023 19:37:46 -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=HWLEx54vJZ0Uv/8y4AbkjNCell7UrP1bAAJTgpEXmFP39aW8TF2TM/cJCflxQnUlNF Y5kRlf4uESYrJ4FBOAuKS176hjj9Gr6ICCblJEro11Ll5m2LDbuKjeHQW5KQi4GSSttg 3s5gzlsQM4tzUr+By61HUsWchiXhENdY3ZHceG3WSRpGLzsGZSkyQufbD7J0j5zsKANi PbcymVsQeCXRinsXMNCh1MoeHroFvuX5USlx4Koc8JqeWjKYx87SAN0EW3oAaeyE4MwU k89DdzW2gVJp3qqMq4p/jHK/ah8I0/qSxmqbrF8YXaGKdYT3PpT5zF1B36GTKeWNSR6Y Uz/g== X-Gm-Message-State: AOJu0YzzCoOTl9emDn1LW3qTLOa2PhNx9trtSKWWsmI2q4Crr45KmHMh btDMpigrr3/0OsYYq3TzSqaj46Wgttqa 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 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_BLOCKED,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (howler.vger.email [0.0.0.0]); Thu, 28 Sep 2023 19:37:58 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778359063234677968 X-GMAIL-MSGID: 1778359063234677968 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: 146411 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:cae8:0:b0:403:3b70:6f57 with SMTP id r8csp3767219vqu; Thu, 28 Sep 2023 21:05:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFOL8MYTo02MGeYaSj9jh5GZe0taCHs2DE6eM0o0RDWMDXiaLDgtHq4HGAWIiHXOZSL33oO X-Received: by 2002:a05:6a00:4143:b0:68f:d35d:217e with SMTP id bv3-20020a056a00414300b0068fd35d217emr2794418pfb.2.1695960356128; Thu, 28 Sep 2023 21:05:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695960356; cv=none; d=google.com; s=arc-20160816; b=Y/G9l95pG3Arg4+KuwbXh/hFrw4ayE5MYLwEfaGx7m5hQEfUlS5qN0JiCiVyPkGhsk HsU7q4zmxrS7BG6yRHGrAZRewLQ+g6Kgu+2r/Zq2118VVeqC82eXRPUzV0KlAwvCVKOR TqZUPOkRPId3ITieMn7jXsLAreHNLGvl2cVRcx3gJ00BwIMtUoCY6jUUXXYbPDMwlXKr ygODGnSvueKEdeqFne6EIHqK9pkO2ybGnSoci0LnyEd5bmIIfTVtFnpPPvFmQT5gtP0X FVY67hDX9artT1ONf8J8oW5zTqehsXdRHeIvEUKE2qZN9NQp1LLfLB2P9o/veDCQmKIN SxmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=J1TE309bBWo1Vh5NP1cqOVIYWRTh5KzFt/cUsR9m0tw=; fh=4WQt+vAibU9sb6wTIfNd0Qwv6UzResa4TIgTnC/9glg=; b=vl8jrS9s/vFT2vit60CRxVtJYZLiSDbAU4iKtpP6LH7CxAXnq4eSVV8D6dfmZf5xUZ +yFECb+DL1Fsv5Om55s5hAUIMjEBsaPVQX296O6nSAVIy5Q4GFgyJE8knjRHwhpteFz5 lucjVONTPImEZSp3sJA2rqiDSQROTSzdqj7pQPEWUpdzV/59HuLLP+GAid1J1x4/UOGo prFYM+WbKUZzlcUeL0fr8tVCYd7eGV7q/y1xIuZTWpJtiCfHQnK0C+pLUaNpbIUT/9uj 7BclmZ6nvymB2ECPvs/VTH4dw5HKiI3AzUW+CCZugDMaQhvNplt7gMZcQ02MeuuouRXL F1wQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=mB+37de2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id o2-20020a056a0015c200b0069344f0eda3si5504999pfu.5.2023.09.28.21.05.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Sep 2023 21:05:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=mB+37de2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id BBC6B82EA17A; Thu, 28 Sep 2023 19:38:20 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232648AbjI2CiE (ORCPT + 21 others); Thu, 28 Sep 2023 22:38:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232426AbjI2CiA (ORCPT ); Thu, 28 Sep 2023 22:38:00 -0400 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 2923A1B7 for ; Thu, 28 Sep 2023 19:37:50 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5a23fed55d7so1833587b3.2 for ; Thu, 28 Sep 2023 19:37:50 -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=YZpGMEjQvs+1ZLrH5yOSwoYrXlnV13DG4XVoSOYj5gYo7IFMBZ30WiLTqUYWziDeja gQ/PGc4Oi4Shc3rfEUl4OVIeIeOB0qpA0YWNlA6xjuCgtxR3LRq42vVXe7VpJTNc8FZq ZnW3WAgWMZxoL3PZyBdbDi6INI02evMk12YTZWBR6UV9ID54JLEOhRJToJcCQ5CuxkKD xNBdweBb6C3x8fEDIgpeSWEeid7V6lshHa37EiggaYutjcZCK8GzEN7LjslXFOKh49tt XZ5k9EoOv6SvnieMvgPi2+Oyv59Dz0i7p6vauS5NCiuzZeLlspMUp5myf2DQpcRpxl1A GkUw== X-Gm-Message-State: AOJu0Yym4HdR/N3bgn5FG2c1RJTDwEiK2FFWpd0X42mRx5dgNIJl919P lZd1f2rO20DmdONVCArWqC9WYxF5wHaq 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 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=-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 agentk.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 (agentk.vger.email [0.0.0.0]); Thu, 28 Sep 2023 19:38:20 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1778343326319646254 X-GMAIL-MSGID: 1778343326319646254 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; }