Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1725741rdb; Mon, 2 Oct 2023 21:17:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFAdtBOfA3K35zlOHCTXqxU3Gcz1hB9y22dVsUkkMPgLO4GvH6Suvn3wvp49dp+hYxllyxa X-Received: by 2002:a05:6122:2177:b0:49d:d91:8b13 with SMTP id j23-20020a056122217700b0049d0d918b13mr7233301vkr.8.1696306654799; Mon, 02 Oct 2023 21:17:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696306654; cv=none; d=google.com; s=arc-20160816; b=h2rakL9R/+shJvPsbOLwqAJ8eMz0NaLOUYZ5sFaMB+9Uh1EPQnFkKV4bQ2xedZ4sdv AQvpQej2sus2urwFtSepzXPl0A6kCJV6HBAsry7uL38utJ+WDrWMVinMKDa1D5lr+qMH XogWjHVIDgr2z5iO2wMNrzbUfWxOuIuGHeDg4bzG4f8rNW1HRO8YsEnvzX0gfvdSRc4s DLNNXJmjaZVG3NmmPrKLJW4SukHXhCeOgowxL4Q5I9xmmnbzr01EmfQPl16yQxCUi889 /hzb8DxcbTwYinlqXd2Rq/OYT8uYWBNsso56uRHTG9SxYNldbrIxiVjr+Cp3LWBib61p 8fUg== 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=xVHKEQiikdMgbU+y27225hg2LnDyDOWoRLfGIfsc16c=; fh=02BoE9IUMwbSc1va0HZXHRK+uDFUfdNNI83HDyu9gWM=; b=HuOO9GbrmFQ0ItMHYry5RNis6e27ZvGRBPfMhZ77KKYr+PzVMw1Vqf/yVW18VxHChH 6gxBLQEwkmjYmABIVnk+fMHJIjrPr7EWwmmlTdKV8pokMOpPt7t3astY413YPC8+aYGR 7K+w3uvLl0l1lOjJ+1H1qbplZApgeaDWhmQpUQj45DWMqseATIA1q3YKVeu3E2HYkDrz sJWt/ejeqPpyTZwLTLoG0rejWiZUxRFBKHiVzljkt/5Hid3bNf+7E+nxCfrF15nlg66y Jge0G7ip2CiDKLc9iwww4iZ9/sZe4UE6yvN7xRi3gmUccSEGTtQ4+/Xq5hK26xWTaw3v jwLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="B9VnI/1U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id d15-20020a17090a7bcf00b0027916d248bbsi535225pjl.162.2023.10.02.21.17.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 21:17:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="B9VnI/1U"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id B7BFC811F92B; Mon, 2 Oct 2023 21:17:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239092AbjJCERX (ORCPT + 99 others); Tue, 3 Oct 2023 00:17:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230142AbjJCERN (ORCPT ); Tue, 3 Oct 2023 00:17:13 -0400 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 5B6A3BB for ; Mon, 2 Oct 2023 21:17:10 -0700 (PDT) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-5a234ffeb90so7691417b3.3 for ; Mon, 02 Oct 2023 21:17:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1696306629; x=1696911429; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=xVHKEQiikdMgbU+y27225hg2LnDyDOWoRLfGIfsc16c=; b=B9VnI/1U+P3xlO4fshby72X1h0LoXSFnHMrojuo6YWrsKx3lPVsRzgBGYUPvKTcBGK FcDjpFGTsF8FMbho+oWi11Zr2vpj/IrIDZm4firEiv0SkSPlnyZKPlvcj/CM9DK976cA xAITZzRrXuR6nGTe6iPkLbJbvGQK1ukPIEOXVVHuDGbPH4G0MICihiBssgdWgPbWzEIW ju0iCM2CC8ow2EIEUNXUFgKh4eSUUS5N6SQyEMz9fyga3VF8Wom/LeWIinyTyLNKHpfy NcHJe67AvH1rq8VVyX/7hA7zZTG1kVWSaO9FezEwWZGi9IoiV8mRia8fsG8Ff+KyzGAY aLXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696306629; x=1696911429; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=xVHKEQiikdMgbU+y27225hg2LnDyDOWoRLfGIfsc16c=; b=tfvRUQm0QvSHLbpKkgNS91LxeDTIt2YJCsWAO8ZdkWiwykMAbBaJU4GfccYcVnhu3u jhpHYFgdlAucA1O2TUGqg1LWy0IO89c820emI5k8G1kdqU/ChcSbTnIDB0wPrj6ZMndD dTeSKWmFJ+EHOfHoBzfjU8MoS6Qe7k13W0xvLMweH4smuKT2hFZ5jXmAkcWky3q3nDWU Y4FbM5DwZKHxDyaxC5UoESo09iyGPQGcz516+QuRweiky3Z5TJ3zROlFepkgCyzN/JCW EIdxqw5AxpPa7tvsLuSKP84bP9F9o4pXmOxOFw80D7TJkAKOsVszuhNbnzs5XbhE6qkU b0fg== X-Gm-Message-State: AOJu0Yyrr0uGMT2IvzsorrkLVpA4zhghKmiNOMhKknb81R1TMHH3BT0c eEtktuzjPBJfO1ITaya+bONO32wrEuuo X-Received: from coldfire.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2b7a]) (user=maheshb job=sendgmr) by 2002:a25:abaf:0:b0:d7b:9830:c172 with SMTP id v44-20020a25abaf000000b00d7b9830c172mr211752ybi.0.1696306629637; Mon, 02 Oct 2023 21:17:09 -0700 (PDT) Date: Mon, 2 Oct 2023 21:17:06 -0700 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.582.g8ccd20d70d-goog Message-ID: <20231003041706.1746634-1-maheshb@google.com> Subject: [PATCHv2 next 3/3] 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 , John Stultz , Don Hatchett , Yuliang Li , Mahesh Bandewar , Mahesh Bandewar , Shuah Khan , Richard Cochran , Rahul Rameshbabu , linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" 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=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 (snail.vger.email [0.0.0.0]); Mon, 02 Oct 2023 21:17:32 -0700 (PDT) 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 | 76 ++++++++++++++++++++++++++- 2 files changed, 75 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..549f0861e897 100644 --- a/tools/testing/selftests/ptp/testptp.c +++ b/tools/testing/selftests/ptp/testptp.c @@ -37,6 +37,12 @@ #define NSEC_PER_SEC 1000000000LL +static char *time_base_arr[PTP_TS_MAX] = { + "system time", + "monotonic time", + "raw-monotonic time", +}; + /* clock_adjtime is not available in GLIBC < 2.14 */ #if !__GLIBC_PREREQ(2, 14) #include @@ -145,8 +151,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 {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 +170,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 +191,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 +207,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 +284,29 @@ 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, "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 real,mono,raw only; was given %s\n", + optarg); + return -1; + } + break; case 'z': flagtest = 1; break; @@ -286,6 +320,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 +646,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; } -- 2.42.0.582.g8ccd20d70d-goog