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; }