From patchwork Thu Jan 4 21:24:42 2024 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: 185149 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp5879070dyb; Thu, 4 Jan 2024 13:25:52 -0800 (PST) X-Google-Smtp-Source: AGHT+IENhL5gDQIUqwRSfdKBt2zNgT7MVJJcH/Lv7q+kysFkiNl+Rub0JAlkyb/C9/mnE4UV5icE X-Received: by 2002:a50:d011:0:b0:557:1c28:ca81 with SMTP id j17-20020a50d011000000b005571c28ca81mr192863edf.75.1704403552343; Thu, 04 Jan 2024 13:25:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704403552; cv=none; d=google.com; s=arc-20160816; b=yTS/MynJYyWPmlyPSc/MJtNI8dWHlxRLvQM3sqrEtYshqMt1/NTUMxr+rxlkd5OvJX sAhKSvQd8s9r+m1Mif+eHaAZsmb3MBj84HmZZCIW3HCgE65czDQmKae1+v+mkeNMUrib llztEAtfvX/q7pUaMBvGMIeTU5YbbfzS0QAbkoB/eZhjK7PAJvetRrZpDdvFTr/p6jMF RoL/HKNREZbIYQNV0ODkrWq+kLiE870Ef+hoEYC3/GCsuVq4bKJFW3zoFk593CboXfPg w80cTMlZH/0iZsbc02fukF1rMGxsfrYXEnSXY7HPencZctokLox3BYepqeaKY/lDDP28 52pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:dkim-signature; bh=xENgso4n4fwY8PEdZvKR4PshgcWGW2WWHOQxmwL55XE=; fh=YVf8dvbOFTeo8oPGAsDfYfWFMCtVV2RMShOveFVmuYQ=; b=WR+lirfyPpOJ0qBm9l9Wzr3wUjG02gLgh7qpkqbVt89EDPBzdDvHnt+m9Cx+wroGOp gPMFHvpdeUDIvH53G/sJ3MdQrUBW2+ULysEZFXVQrrn/oTvEquZPUSjSd2qw96P8newD DUTtMfRwL4ae+7QmfKldukN77tunK0FAh7AofZwCyW3R71dwGk5BNYkaWRbSN+KvBvVR txwgKTceCvQJ6PaQEHyBEvtW8/anwRt11+BNFhYTSJswVgbXljx2zBMlRzb/jDHL+Ja3 I4D/Y6o5+YFrAdHjrl0FMxgAgvM1zaSmJryKTOQ2YjZupIXZH6QdcRZXqWpivHGGDmWT RqGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RhwXOTh4; spf=pass (google.com: domain of linux-kernel+bounces-17237-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17237-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id n2-20020a5099c2000000b00554de459315si102695edb.284.2024.01.04.13.25.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 13:25:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-17237-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=RhwXOTh4; spf=pass (google.com: domain of linux-kernel+bounces-17237-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-17237-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id D3ECD1F2557D for ; Thu, 4 Jan 2024 21:25:51 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7E0862C6AE; Thu, 4 Jan 2024 21:24:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="RhwXOTh4" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 62E082D040 for ; Thu, 4 Jan 2024 21:24:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--maheshb.bounces.google.com Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5efb07ddb0fso15213697b3.0 for ; Thu, 04 Jan 2024 13:24:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704403485; x=1705008285; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=xENgso4n4fwY8PEdZvKR4PshgcWGW2WWHOQxmwL55XE=; b=RhwXOTh4OY7SZ5jAZ7pJ8OlxR54FOn2ymG4/SAY5qUum+8C5PPEPwbPiSFZv3lecBr ZoeaxigfJ6z6jfcOh9/ha5W92Kt3Ws9Rf5081MIM1g27iwzlztmr9iXLli2KMYgxZqv6 J5x3dyrnROefuig2qclji6EntxBflTc7Hln9zd6v6V4tSzRXYgJX6Lpi/orhaFRhPnf3 LfNQBcvQcllO95nsLmL2AAtLFlqcwPoieCFV6f1x9GhHH/sH/G/4iWMTPcucmVag2oce 7bkxzaQwRc+wNI6GellgSWeGCdKOg2RAz1NdUbfNZJm7b5bbrS13Tr2sQvz3/xPEgSvC 6gcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704403485; x=1705008285; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=xENgso4n4fwY8PEdZvKR4PshgcWGW2WWHOQxmwL55XE=; b=D2wltdNaL2AaVrFX4UwwQZfxJ70zb4y4qKXfYoIforSXuLP29UeDDo1VT5+h94P74c IU8Ao5nBx0xnSNXqn9ZWWwD81ZnxMz+W9Ld1ALo7L72XyZzO0Q09OOyJ1LsmV7xjFS+I iPNSYoFIjwCbw7vCuuRDj4uB4MAcSkogW2FaGrCLvfaeZTMgdr7UJMWFb2whOqwoMjB8 OuVHxM3kEvfMJ1d36EWJXjRxct0OwDV8Joyu6tn1YJS06BlGwnEZMSjWgaf05M63RqF9 mKgNysgAK2t7mnjmbUy60F6zYZ7vtZ7QAAA6XppKaS56mJXnThLnru0JslgrK5fnzKMV L9uQ== X-Gm-Message-State: AOJu0YzYtKUAn/z/gqG9r2gIDNzyqov2RQnV44WEpgR6Zo3vIwLEEvis IBPKtzAw1yQGbjhOz/y1/wYuQSt1hp2310g3HgI= X-Received: from coldfire.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:2b7a]) (user=maheshb job=sendgmr) by 2002:a05:690c:303:b0:5d3:b449:e58e with SMTP id bg3-20020a05690c030300b005d3b449e58emr494691ywb.6.1704403485511; Thu, 04 Jan 2024 13:24:45 -0800 (PST) Date: Thu, 4 Jan 2024 13:24:42 -0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.43.0.195.gebba966016-goog Message-ID: <20240104212442.3276812-1-maheshb@google.com> Subject: [PATCHv3 net-next 3/3] selftest/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 , Richard Cochran , Willem de Bruijn , linux-kselftest@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787196659739447684 X-GMAIL-MSGID: 1787196659739447684 Update testptp.c to exercise the new ptp method gettimex64any(). When only -x option is given the PTP_SYS_OFFSET_EXTENDED or gettimex64() method is exercised while presence of -x with -y will exercise PTP_SYS_OFFSET_ANY or gettimex64any() method. -y option is to choose the timebase from available options of real, mono, or raw. Signed-off-by: Mahesh Bandewar CC: Richard Cochran CC: "David S. Miller" CC: John Stultz CC: Jakub Kicinski CC: "Willem de Bruijn" CC: linux-kselftest@vger.kernel.org CC: netdev@vger.kernel.org --- tools/testing/selftests/ptp/testptp.c | 96 ++++++++++++++++++++++++++- 1 file changed, 94 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/ptp/testptp.c b/tools/testing/selftests/ptp/testptp.c index 011252fe238c..dd390062b883 100644 --- a/tools/testing/selftests/ptp/testptp.c +++ b/tools/testing/selftests/ptp/testptp.c @@ -146,8 +146,9 @@ 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 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[]) @@ -163,6 +164,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; @@ -183,6 +185,8 @@ int main(int argc, char *argv[]) int pct_offset = 0; int getextended = 0; int getcross = 0; + int get_ext_any = 0; + clockid_t ext_any_clkid = -1; int n_samples = 0; int pin_index = -1, pin_func; int pps = -1; @@ -198,7 +202,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:F:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:Xz"))) { + while (EOF != (c = getopt(argc, argv, "cd:e:f:F:ghH:i:k:lL:n:o:p:P:sSt:T:w:x:Xy:z"))) { switch (c) { case 'c': capabilities = 1; @@ -278,6 +282,20 @@ int main(int argc, char *argv[]) case 'X': getcross = 1; break; + case 'y': + if (!strcasecmp(optarg, "real")) + ext_any_clkid = CLOCK_REALTIME; + else if (!strcasecmp(optarg, "mono")) + ext_any_clkid = CLOCK_MONOTONIC; + else if (!strcasecmp(optarg, "raw")) + ext_any_clkid = CLOCK_MONOTONIC_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; @@ -291,6 +309,18 @@ int main(int argc, char *argv[]) } } + /* For ptp_sys_offset_any both options 'x', 'y' must be given */ + if (ext_any_clkid > -1) { + if (getextended == 0) { + fprintf(stderr, + "For extended-any TS both options -x, and -y are required.\n"); + usage(progname); + return -1; + } + get_ext_any = getextended; + getextended = 0; + } + fd = open(device, O_RDWR); if (fd < 0) { fprintf(stderr, "opening %s: %s\n", device, strerror(errno)); @@ -621,6 +651,68 @@ int main(int argc, char *argv[]) } } + if (get_ext_any) { + ats = calloc(1, sizeof(*ats)); + if (!ats) { + perror("calloc"); + return -1; + } + + ats->n_samples = get_ext_any; + ats->clockid = ext_any_clkid; + + if (ioctl(fd, PTP_SYS_OFFSET_ANY, ats)) { + perror("PTP_SYS_OFFSET_ANY"); + } else { + printf("extended-any timestamp request returned %d samples\n", + get_ext_any); + + for (i = 0; i < get_ext_any; i++) { + switch (ext_any_clkid) { + case CLOCK_REALTIME: + printf("sample #%2d: system time before: %lld.%09u\n", + i, ats->ts[i][0].sec, + ats->ts[i][0].nsec); + break; + case CLOCK_MONOTONIC: + printf("sample #%2d: monotonic time before: %lld.%09u\n", + i, ats->ts[i][0].sec, + ats->ts[i][0].nsec); + break; + case CLOCK_MONOTONIC_RAW: + printf("sample #%2d: raw-monotonic time before: %lld.%09u\n", + i, ats->ts[i][0].sec, + ats->ts[i][0].nsec); + break; + default: + break; + } + printf(" phc time: %lld.%09u\n", + ats->ts[i][1].sec, ats->ts[i][1].nsec); + switch (ext_any_clkid) { + case CLOCK_REALTIME: + printf(" system time after: %lld.%09u\n", + ats->ts[i][2].sec, + ats->ts[i][2].nsec); + break; + case CLOCK_MONOTONIC: + printf(" monotonic time after: %lld.%09u\n", + ats->ts[i][2].sec, + ats->ts[i][2].nsec); + break; + case CLOCK_MONOTONIC_RAW: + printf(" raw-monotonic time after: %lld.%09u\n", + ats->ts[i][2].sec, + ats->ts[i][2].nsec); + break; + default: + break; + } + } + } + + free(ats); + } close(fd); return 0; }