Skip to content

Commit 3a9a9a6

Browse files
Binary-Eaterdavem330
authored andcommitted
testptp: Add support for testing ptp_clock_info .adjphase callback
Invoke clock_adjtime syscall with tx.modes set with ADJ_OFFSET when testptp is invoked with a phase adjustment offset value. Support seconds and nanoseconds for the offset value. Cc: Jakub Kicinski <[email protected]> Cc: Shuah Khan <[email protected]> Cc: Richard Cochran <[email protected]> Cc: Maciek Machnikowski <[email protected]> Signed-off-by: Rahul Rameshbabu <[email protected]> Acked-by: Richard Cochran <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 048f6d9 commit 3a9a9a6

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

tools/testing/selftests/ptp/testptp.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ static void usage(char *progname)
134134
" 1 - external time stamp\n"
135135
" 2 - periodic output\n"
136136
" -n val shift the ptp clock time by 'val' nanoseconds\n"
137+
" -o val phase offset (in nanoseconds) to be provided to the PHC servo\n"
137138
" -p val enable output with a period of 'val' nanoseconds\n"
138139
" -H val set output phase to 'val' nanoseconds (requires -p)\n"
139140
" -w val set output pulse width to 'val' nanoseconds (requires -p)\n"
@@ -167,6 +168,7 @@ int main(int argc, char *argv[])
167168
int adjfreq = 0x7fffffff;
168169
int adjtime = 0;
169170
int adjns = 0;
171+
int adjphase = 0;
170172
int capabilities = 0;
171173
int extts = 0;
172174
int flagtest = 0;
@@ -188,7 +190,7 @@ int main(int argc, char *argv[])
188190

189191
progname = strrchr(argv[0], '/');
190192
progname = progname ? 1+progname : argv[0];
191-
while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:p:P:sSt:T:w:z"))) {
193+
while (EOF != (c = getopt(argc, argv, "cd:e:f:ghH:i:k:lL:n:o:p:P:sSt:T:w:z"))) {
192194
switch (c) {
193195
case 'c':
194196
capabilities = 1;
@@ -228,6 +230,9 @@ int main(int argc, char *argv[])
228230
case 'n':
229231
adjns = atoi(optarg);
230232
break;
233+
case 'o':
234+
adjphase = atoi(optarg);
235+
break;
231236
case 'p':
232237
perout = atoll(optarg);
233238
break;
@@ -327,6 +332,18 @@ int main(int argc, char *argv[])
327332
}
328333
}
329334

335+
if (adjphase) {
336+
memset(&tx, 0, sizeof(tx));
337+
tx.modes = ADJ_OFFSET | ADJ_NANO;
338+
tx.offset = adjphase;
339+
340+
if (clock_adjtime(clkid, &tx) < 0) {
341+
perror("clock_adjtime");
342+
} else {
343+
puts("phase adjustment okay");
344+
}
345+
}
346+
330347
if (gettime) {
331348
if (clock_gettime(clkid, &ts)) {
332349
perror("clock_gettime");

0 commit comments

Comments
 (0)