lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240813125602.155827-4-maciek@machnikowski.net>
Date: Tue, 13 Aug 2024 12:56:02 +0000
From: Maciek Machnikowski <maciek@...hnikowski.net>
To: maciek@...hnikowski.net
Cc: netdev@...r.kernel.org,
	richardcochran@...il.com,
	jacob.e.keller@...el.com,
	vadfed@...a.com,
	darinzon@...zon.com,
	kuba@...nel.org
Subject: [RFC 3/3] ptp: Add setting esterror and reading timex structure

Implement setting the esterror using clock_adjtime for ptp clocks
and reading the clock setting using timex structure and
clock_adjtime

Signed-off-by: Maciek Machnikowski <maciek@...hnikowski.net>
---
 tools/testing/selftests/ptp/testptp.c | 39 +++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/ptp/testptp.c b/tools/testing/selftests/ptp/testptp.c
index 011252fe238c..38405803b881 100644
--- a/tools/testing/selftests/ptp/testptp.c
+++ b/tools/testing/selftests/ptp/testptp.c
@@ -117,6 +117,7 @@ static void usage(char *progname)
 {
 	fprintf(stderr,
 		"usage: %s [options]\n"
+		" -a val     adjust the estimated error by 'val' ns\n"
 		" -c         query the ptp clock's capabilities\n"
 		" -d name    device to open\n"
 		" -e val     read 'val' external time stamp events\n"
@@ -140,6 +141,7 @@ static void usage(char *progname)
 		" -H val     set output phase to 'val' nanoseconds (requires -p)\n"
 		" -w val     set output pulse width to 'val' nanoseconds (requires -p)\n"
 		" -P val     enable or disable (val=1|0) the system clock PPS\n"
+		" -r         read clock info in the  timex structure using clock_adjtime\n"
 		" -s         set the ptp clock time from the system time\n"
 		" -S         set the system time from the ptp clock time\n"
 		" -t val     shift the ptp clock time by 'val' seconds\n"
@@ -175,12 +177,14 @@ int main(int argc, char *argv[])
 	int adjns = 0;
 	int adjphase = 0;
 	int capabilities = 0;
+	long esterror = 0;
 	int extts = 0;
 	int flagtest = 0;
 	int gettime = 0;
 	int index = 0;
 	int list_pins = 0;
 	int pct_offset = 0;
+	int readclk = 0;
 	int getextended = 0;
 	int getcross = 0;
 	int n_samples = 0;
@@ -198,8 +202,11 @@ 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, "a:cd:e:f:F:ghH:i:k:lL:n:o:p:P:rsSt:T:w:x:Xz"))) {
 		switch (c) {
+		case 'a':
+			esterror = atoi(optarg);
+			break;
 		case 'c':
 			capabilities = 1;
 			break;
@@ -250,6 +257,9 @@ int main(int argc, char *argv[])
 		case 'P':
 			pps = atoi(optarg);
 			break;
+		case 'r':
+			readclk = 1;
+			break;
 		case 's':
 			settime = 1;
 			break;
@@ -290,7 +300,6 @@ int main(int argc, char *argv[])
 			return -1;
 		}
 	}
-
 	fd = open(device, O_RDWR);
 	if (fd < 0) {
 		fprintf(stderr, "opening %s: %s\n", device, strerror(errno));
@@ -621,6 +630,32 @@ int main(int argc, char *argv[])
 		}
 	}
 
+	if (esterror) {
+		memset(&tx, 0, sizeof(tx));
+		tx.modes = ADJ_ESTERROR;
+		tx.esterror = esterror;
+		if (clock_adjtime(clkid, &tx))
+			perror("clock_adjtime");
+		else
+			puts("esterror adjustment okay");
+	}
+
+	if (readclk) {
+		struct timex clk_info = {0};
+
+		memset(&tx, 0, sizeof(tx));
+		if (clock_adjtime(clkid, &tx)) {
+			perror("clock_adjtime");
+		} else {
+			printf("clock_adjtime:\n"
+			       "\tstatus %d,\n"
+			       "\toffset %ld,\n"
+			       "\tfreq %ld,\n"
+			       "\testerror %ld\n",
+			       tx.status, tx.offset, tx.freq, tx.esterror);
+		}
+	}
+
 	close(fd);
 	return 0;
 }
-- 
2.34.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ