Re: [Linuxptp-devel] [PATCH v1 4/4] phc_ctl: Use util.h NSEC_PER_SEC macro instead of local macro

2023-12-04 Thread Rahul Rameshbabu via Linuxptp-devel
On Sat, 02 Dec, 2023 13:56:50 -0800 Richard Cochran  
wrote:
> On Wed, Nov 22, 2023 at 09:36:36AM -0800, Rahul Rameshbabu via Linuxptp-devel 
> wrote:
>> Use the common NSEC_PER_SEC macro in phc_ctl.
>> 
>> Signed-off-by: Rahul Rameshbabu 
>
> Series applied, but I fixed up one more NSEC2SEC that was added into
> phc_ctl.c since this series was posted.
>

Thanks for doing that. Will try to be more careful going forward to
account for the latest state of the tree when needing to send out
revisions to the list.

--
Thanks,

Rahul Rameshbabu


___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH v1 3/4] servo: Use util.h NSEC_PER_SEC macro instead of local macro

2023-11-22 Thread Rahul Rameshbabu via Linuxptp-devel
Use the common NSEC_PER_SEC macro in servo source code.

Signed-off-by: Rahul Rameshbabu 
---
 servo.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/servo.c b/servo.c
index ea171cd..6d6753e 100644
--- a/servo.c
+++ b/servo.c
@@ -26,11 +26,10 @@
 #include "pi.h"
 #include "refclock_sock.h"
 #include "servo_private.h"
+#include "util.h"
 
 #include "print.h"
 
-#define NSEC_PER_SEC 10
-
 struct servo *servo_create(struct config *cfg, enum servo_type type,
   double fadj, int max_ppb, int sw_ts)
 {
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH v1 1/4] util: Introduce NSEC_PER_SEC macro

2023-11-22 Thread Rahul Rameshbabu via Linuxptp-devel
NSEC_PER_SEC conversion is used throughout the linuxptp source code.
Introduce a common macro that can be used throughout the linuxptp codebase
for this purpose.

Signed-off-by: Rahul Rameshbabu 
---
 util.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/util.h b/util.h
index 2bbde71..1cbd9b6 100644
--- a/util.h
+++ b/util.h
@@ -33,6 +33,8 @@
 #define MAX_PRINT_BYTES 16
 #define BIN_BUF_SIZE (MAX_PRINT_BYTES * 3 + 1)
 
+#define NSEC_PER_SEC 10LL
+
 /**
  * Table of human readable strings, one for each port state.
  */
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH v1 2/4] port: Use util.h NSEC_PER_SEC macro instead of local macro

2023-11-22 Thread Rahul Rameshbabu via Linuxptp-devel
Use the common NSEC_PER_SEC macro in port-related source code.

Signed-off-by: Rahul Rameshbabu 
---
 port.c | 14 +++---
 port_private.h |  3 +--
 tc.c   |  9 -
 3 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/port.c b/port.c
index 5803cd3..79f3702 100644
--- a/port.c
+++ b/port.c
@@ -138,17 +138,17 @@ static int msg_current(struct ptp_message *m, struct 
timespec now)
 {
int64_t t1, t2, tmo;
 
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
if (m->header.logMessageInterval <= -31) {
tmo = 0;
} else if (m->header.logMessageInterval >= 31) {
tmo = INT64_MAX;
} else if (m->header.logMessageInterval < 0) {
-   tmo = 4LL * NSEC2SEC / (1 << -m->header.logMessageInterval);
+   tmo = 4LL * NSEC_PER_SEC / (1 << -m->header.logMessageInterval);
} else {
-   tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC2SEC;
+   tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC_PER_SEC;
}
 
return t2 - t1 < tmo;
@@ -340,10 +340,10 @@ static void fc_prune(struct foreign_clock *fc)
 
 static int delay_req_current(struct ptp_message *m, struct timespec now)
 {
-   int64_t t1, t2, tmo = 5 * NSEC2SEC;
+   int64_t t1, t2, tmo = 5 * NSEC_PER_SEC;
 
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
return t2 - t1 < tmo;
 }
diff --git a/port_private.h b/port_private.h
index 3b02d2f..d922a3d 100644
--- a/port_private.h
+++ b/port_private.h
@@ -28,8 +28,7 @@
 #include "msg.h"
 #include "power_profile.h"
 #include "tmv.h"
-
-#define NSEC2SEC 10LL
+#include "util.h"
 
 enum syfu_state {
SF_EMPTY,
diff --git a/tc.c b/tc.c
index 1847041..20717c1 100644
--- a/tc.c
+++ b/tc.c
@@ -254,13 +254,12 @@ static void tc_complete(struct port *q, struct port *p,
 
 static int tc_current(struct ptp_message *m, struct timespec now)
 {
-   int64_t t1, t2, tmo;
+   int64_t t1, t2;
 
-   tmo = 1LL * NSEC2SEC;
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
-   return t2 - t1 < tmo;
+   return t2 - t1 < NSEC_PER_SEC;
 }
 
 static int tc_fwd_event(struct port *q, struct ptp_message *msg)
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH v1 4/4] phc_ctl: Use util.h NSEC_PER_SEC macro instead of local macro

2023-11-22 Thread Rahul Rameshbabu via Linuxptp-devel
Use the common NSEC_PER_SEC macro in phc_ctl.

Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.c | 8 +++-
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index 893d87d..c5d16ae 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -48,8 +48,6 @@
 #include "util.h"
 #include "version.h"
 
-#define NSEC2SEC 10.0
-
 /* trap the alarm signal so that pause() will wake up on receipt */
 static void handle_alarm(int s)
 {
@@ -68,7 +66,7 @@ static void double_to_timespec(double d, struct timespec *ts)
 * value by our fractional component. This results in a correct
 * timespec from the double representing seconds.
 */
-   ts->tv_nsec = (long)(NSEC2SEC * fraction);
+   ts->tv_nsec = (long)(NSEC_PER_SEC * fraction);
 }
 
 static int install_handler(int signum, void(*handler)(int))
@@ -231,7 +229,7 @@ static int do_adj(clockid_t clkid, int cmdc, char *cmdv[])
return -2;
}
 
-   nsecs = (int64_t)(NSEC2SEC * time_arg);
+   nsecs = (int64_t)(NSEC_PER_SEC * time_arg);
 
clockadj_init(clkid);
clockadj_step(clkid, nsecs);
@@ -258,7 +256,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
}
 
/* parse the double ppb argument */
-   r = get_ranged_double(cmdv[0], &ppb, -NSEC2SEC, NSEC2SEC);
+   r = get_ranged_double(cmdv[0], &ppb, -NSEC_PER_SEC, NSEC_PER_SEC);
switch (r) {
case PARSED_OK:
break;
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


Re: [Linuxptp-devel] [PATCH v3 1/5] Rename NSEC2SEC as NSEC_PER_SEC and refactor to util.h

2023-11-09 Thread Rahul Rameshbabu via Linuxptp-devel
On Thu, 09 Nov, 2023 21:17:03 -0800 Richard Cochran  
wrote:
> On Mon, Sep 25, 2023 at 10:03:09AM -0700, Rahul Rameshbabu via Linuxptp-devel 
> wrote:
>> The name NSEC2SEC implies converting nanoseconds to seconds, but the value
>> used for the macro converts seconds to nanoseconds. NSEC_PER_SEC is the
>> accurate name for this macro. Move macro to common location in util.h.
>
> This patch really has nothing to do with the topic as stated in the
> cover letter.  I agree that the existing macro is poorly named, but
> the change really needs its own patch series.
>
> If you feel like making the change, then please make a patch series,
> starting with adding the new macro, and then converting the modules
> one by one to the new macro.  That way a) the review is easier, and
> b) reverts are easier in case of regression in one module.

Ack. I do want to make this change and agree with this feedback. I'll
send out a patch series for this next week.

--
Thanks,

Rahul Rameshbabu


___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


Re: [Linuxptp-devel] [PATCH 1/2] include string.h for strncpy()

2023-10-20 Thread Rahul Rameshbabu via Linuxptp-devel
On Fri, 20 Oct, 2023 12:47:39 -0700 Richard Cochran  
wrote:
> On Thu, Oct 19, 2023 at 03:50:20PM +0100, Luca Fancellu wrote:
>> From: Khem Raj 
>> 
>> Signed-off-by: Khem Raj 
>> ---
>>  interface.c | 1 +
>>  1 file changed, 1 insertion(+)
>> 
>> diff --git a/interface.c b/interface.c
>> index 29229ad6f53d..9a83c36933e7 100644
>> --- a/interface.c
>> +++ b/interface.c
>> @@ -5,6 +5,7 @@
>>   * @note SPDX-License-Identifier: GPL-2.0+
>>   */
>>  #include 
>> +#include 
>>  #include "interface.h"
>
> What problem does this fix?

Isn't this resolving the issue that string.h is the c library standard
include for strncpy?

In section 7.26.2.5 of the C standard draft N3047, it is shown the you
must include string.h as the proper header including the declaration for
strncpy. With some toolchains, not explicitly including the header may
work, but it's not a guarantee by the standard from my understanding.

* https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3047.pdf
* https://godbolt.org/z/7YG7KGab8

--
Thanks,

Rahul Rameshbabu


___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH v3 4/5] phc_ctl: Use pr_notice instead of pr_err for displaying adjusted frequency

2023-09-25 Thread Rahul Rameshbabu via Linuxptp-devel
Adjusted frequency value displayed by do_freq is not an error, but a
notication to the user. pr_err should not be used for providing notices
with information about successful operations.

Fixes: bdb6a35883b0 ("linuxptp: add phc_ctl program to help debug PHC devices")
Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index a814648..34d9e0c 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -249,7 +249,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
 
if (cmdc < 1 || name_is_a_command(cmdv[0])) {
ppb = clockadj_get_freq(clkid);
-   pr_err("clock frequency offset is %lfppb", ppb);
+   pr_notice("clock frequency offset is %lfppb", ppb);
 
/* no argument was used */
return 0;
@@ -272,7 +272,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
}
 
clockadj_set_freq(clkid, ppb);
-   pr_err("adjusted clock frequency offset to %lfppb", ppb);
+   pr_notice("adjusted clock frequency offset to %lfppb", ppb);
 
/* consumed one argument to determine the frequency adjustment value */
return 1;
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH v3 0/5] General improvements for linuxptp focused around phase adjustment

2023-09-25 Thread Rahul Rameshbabu via Linuxptp-devel
The main focus of this submission is adding support for testing ADJ_OFFSET with
phc_ctl and querying the maximum supported ADJ_OFFSET adjustment that a device
is capable of. Some other minor cleanups are also included in the submission.

The patch that introduces support for querying the maximum offset supported by
ADJ_OFFSET depends on a kernel patch series (linked below) that is targeted for
kernel 6.5. Previously, sent this series out as an RFC to inquire feedback early
on. Have incorporated that feedback into this submission.

Changes:

  patch 1:
v2->v3:
  - Eliminate unnecessary tmo variable due to refactor in tc.c.
  patch 5:
v1->v2:
  - Accounted for conditional formatting changes suggested by Erez.
  - Added pre-emptive return on error since clockadj_step prints an error
message as suggested by Erez.

Link: https://sourceforge.net/p/linuxptp/mailman/message/38267194/
Link: https://sourceforge.net/p/linuxptp/mailman/message/37871081/
Link: https://sourceforge.net/p/linuxptp/mailman/message/37860292/
Link: https://sourceforge.net/p/linuxptp/mailman/message/37854603/
Link: 
https://lore.kernel.org/netdev/20230612211500.309075-1-rrameshb...@nvidia.com/

Rahul Rameshbabu (5):
  Rename NSEC2SEC as NSEC_PER_SEC and refactor to util.h
  phc_ctl: Add phase command to support ADJ_OFFSET
  phc_ctl: Add maximum offset capability
  phc_ctl: Use pr_notice instead of pr_err for displaying adjusted
frequency
  phc_ctl: Handle errors returned by various clockadj helpers

 missing.h  |  9 +++---
 phc_ctl.8  |  4 +++
 phc_ctl.c  | 79 ++
 port.c | 14 -
 port_private.h |  3 +-
 servo.c|  3 +-
 tc.c   |  9 +++---
 util.h |  2 ++
 8 files changed, 85 insertions(+), 38 deletions(-)

-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH v3 2/5] phc_ctl: Add phase command to support ADJ_OFFSET

2023-09-25 Thread Rahul Rameshbabu via Linuxptp-devel
Take double precision floating point representation of an offset value in
seconds. Feed this value to the PHC's phase control keyword.

Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.8 |  4 
 phc_ctl.c | 55 ---
 2 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/phc_ctl.8 b/phc_ctl.8
index 650e661..b10566e 100644
--- a/phc_ctl.8
+++ b/phc_ctl.8
@@ -62,6 +62,10 @@ Adjust the frequency of the PHC clock by the specified parts 
per billion. If no
 argument is provided, it will attempt to read the current frequency and report
 it.
 .TP
+.BI phase " seconds"
+Pass an amount in seconds to the PHC clock's phase control keyword. This
+argument is required.
+.TP
 .BI cmp
 Compare the PHC clock device to CLOCK_REALTIME, using the best method 
available.
 .TP
diff --git a/phc_ctl.c b/phc_ctl.c
index db89f01..c5430d8 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -106,13 +106,14 @@ static void usage(const char *progname)
" specify commands with arguments. Can specify multiple\n"
" commands to be executed in order. Seconds are read as\n"
" double precision floating point values.\n"
-   "  set  [seconds]  set PHC time (defaults to time on 
CLOCK_REALTIME)\n"
-   "  get get PHC time\n"
-   "  adjadjust PHC time by offset\n"
-   "  freq [ppb]  adjust PHC frequency (default returns 
current offset)\n"
-   "  cmp compare PHC offset to CLOCK_REALTIME\n"
-   "  capsdisplay device capabilities (default if no 
command given)\n"
-   "  wait   pause between commands\n"
+   "  set   [seconds]  set PHC time (defaults to time on 
CLOCK_REALTIME)\n"
+   "  get  get PHC time\n"
+   "  adj adjust PHC time by offset\n"
+   "  freq  [ppb]  adjust PHC frequency (default returns 
current offset)\n"
+   "  phase   pass offset to PHC phase control keyword\n"
+   "  cmp  compare PHC offset to CLOCK_REALTIME\n"
+   "  caps display device capabilities (default if no 
command given)\n"
+   "  waitpause between commands\n"
"\n",
progname);
 }
@@ -277,6 +278,45 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
return 1;
 }
 
+static int do_phase(clockid_t clkid, int cmdc, char *cmdv[])
+{
+   double offset_arg;
+   long nsecs;
+   enum parser_result r;
+
+   if (cmdc < 1 || name_is_a_command(cmdv[0])) {
+   pr_err("phase: missing required time argument");
+   return -2;
+   }
+
+   /* parse the double time offset argument */
+   r = get_ranged_double(cmdv[0], &offset_arg, -DBL_MAX, DBL_MAX);
+   switch (r) {
+   case PARSED_OK:
+   break;
+   case MALFORMED:
+   pr_err("phase: '%s' is not a valid double", cmdv[0]);
+   return -2;
+   case OUT_OF_RANGE:
+   pr_err("phase: '%s' is out of range.", cmdv[0]);
+   return -2;
+   default:
+   pr_err("phase: couldn't process '%s'", cmdv[0]);
+   return -2;
+   }
+
+   nsecs = (long)(NSEC_PER_SEC * offset_arg);
+
+   clockadj_init(clkid);
+   clockadj_set_phase(clkid, nsecs);
+
+   pr_notice("offset of %lf seconds provided to PHC phase control keyword",
+ offset_arg);
+
+   /* phase offset always consumes one argument */
+   return 1;
+}
+
 static int do_caps(clockid_t clkid, int cmdc, char *cmdv[])
 {
struct ptp_clock_caps caps;
@@ -399,6 +439,7 @@ static const struct cmd_t all_commands[] = {
{ "get", &do_get },
{ "adj", &do_adj },
{ "freq", &do_freq },
+   { "phase", &do_phase },
{ "cmp", &do_cmp },
{ "caps", &do_caps },
{ "wait", &do_wait },
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH v3 5/5] phc_ctl: Handle errors returned by various clockadj helpers

2023-09-25 Thread Rahul Rameshbabu via Linuxptp-devel
Do not print success notices if clockadj operation fails using return
values provided by the clockadj helpers.

Signed-off-by: Rahul Rameshbabu 
---

Notes:
Changes:

  v1->v2:
- Accounted for conditional formatting changes suggested by Erez.
- Added pre-emptive return on error since clockadj_step prints an error
  message as suggested by Erez.

 phc_ctl.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index 34d9e0c..47fea8f 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -232,9 +232,10 @@ static int do_adj(clockid_t clkid, int cmdc, char *cmdv[])
nsecs = (int64_t)(NSEC_PER_SEC * time_arg);
 
clockadj_init(clkid);
-   clockadj_step(clkid, nsecs);
-
-   pr_notice("adjusted clock by %lf seconds", time_arg);
+   if (clockadj_step(clkid, nsecs) == 0)
+   pr_notice("adjusted clock by %lf seconds", time_arg);
+   else
+   return -2;
 
/* adjustment always consumes one argument */
return 1;
@@ -271,8 +272,8 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
return -2;
}
 
-   clockadj_set_freq(clkid, ppb);
-   pr_notice("adjusted clock frequency offset to %lfppb", ppb);
+   if (clockadj_set_freq(clkid, ppb) == 0)
+   pr_notice("adjusted clock frequency offset to %lfppb", ppb);
 
/* consumed one argument to determine the frequency adjustment value */
return 1;
@@ -308,10 +309,9 @@ static int do_phase(clockid_t clkid, int cmdc, char 
*cmdv[])
nsecs = (long)(NSEC_PER_SEC * offset_arg);
 
clockadj_init(clkid);
-   clockadj_set_phase(clkid, nsecs);
-
-   pr_notice("offset of %lf seconds provided to PHC phase control keyword",
- offset_arg);
+   if (clockadj_set_phase(clkid, nsecs) == 0)
+   pr_notice("offset of %lf seconds provided to PHC phase control 
keyword",
+ offset_arg);
 
/* phase offset always consumes one argument */
return 1;
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH v3 1/5] Rename NSEC2SEC as NSEC_PER_SEC and refactor to util.h

2023-09-25 Thread Rahul Rameshbabu via Linuxptp-devel
The name NSEC2SEC implies converting nanoseconds to seconds, but the value
used for the macro converts seconds to nanoseconds. NSEC_PER_SEC is the
accurate name for this macro. Move macro to common location in util.h.

Signed-off-by: Rahul Rameshbabu 
---

Notes:
Changes:

  v2->v3:
- Eliminate unnecessary tmo variable due to refactor in tc.c.

 phc_ctl.c  |  8 +++-
 port.c | 14 +++---
 port_private.h |  3 +--
 servo.c|  3 +--
 tc.c   |  9 -
 util.h |  2 ++
 6 files changed, 18 insertions(+), 21 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index 92e597c..db89f01 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -48,8 +48,6 @@
 #include "util.h"
 #include "version.h"
 
-#define NSEC2SEC 10.0
-
 /* trap the alarm signal so that pause() will wake up on receipt */
 static void handle_alarm(int s)
 {
@@ -68,7 +66,7 @@ static void double_to_timespec(double d, struct timespec *ts)
 * value by our fractional component. This results in a correct
 * timespec from the double representing seconds.
 */
-   ts->tv_nsec = (long)(NSEC2SEC * fraction);
+   ts->tv_nsec = (long)(NSEC_PER_SEC * fraction);
 }
 
 static int install_handler(int signum, void(*handler)(int))
@@ -230,7 +228,7 @@ static int do_adj(clockid_t clkid, int cmdc, char *cmdv[])
return -2;
}
 
-   nsecs = (int64_t)(NSEC2SEC * time_arg);
+   nsecs = (int64_t)(NSEC_PER_SEC * time_arg);
 
clockadj_init(clkid);
clockadj_step(clkid, nsecs);
@@ -257,7 +255,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
}
 
/* parse the double ppb argument */
-   r = get_ranged_double(cmdv[0], &ppb, -NSEC2SEC, NSEC2SEC);
+   r = get_ranged_double(cmdv[0], &ppb, -NSEC_PER_SEC, NSEC_PER_SEC);
switch (r) {
case PARSED_OK:
break;
diff --git a/port.c b/port.c
index d551bef..b75f850 100644
--- a/port.c
+++ b/port.c
@@ -138,17 +138,17 @@ static int msg_current(struct ptp_message *m, struct 
timespec now)
 {
int64_t t1, t2, tmo;
 
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
if (m->header.logMessageInterval <= -31) {
tmo = 0;
} else if (m->header.logMessageInterval >= 31) {
tmo = INT64_MAX;
} else if (m->header.logMessageInterval < 0) {
-   tmo = 4LL * NSEC2SEC / (1 << -m->header.logMessageInterval);
+   tmo = 4LL * NSEC_PER_SEC / (1 << -m->header.logMessageInterval);
} else {
-   tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC2SEC;
+   tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC_PER_SEC;
}
 
return t2 - t1 < tmo;
@@ -340,10 +340,10 @@ static void fc_prune(struct foreign_clock *fc)
 
 static int delay_req_current(struct ptp_message *m, struct timespec now)
 {
-   int64_t t1, t2, tmo = 5 * NSEC2SEC;
+   int64_t t1, t2, tmo = 5 * NSEC_PER_SEC;
 
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
return t2 - t1 < tmo;
 }
diff --git a/port_private.h b/port_private.h
index 3b02d2f..d922a3d 100644
--- a/port_private.h
+++ b/port_private.h
@@ -28,8 +28,7 @@
 #include "msg.h"
 #include "power_profile.h"
 #include "tmv.h"
-
-#define NSEC2SEC 10LL
+#include "util.h"
 
 enum syfu_state {
SF_EMPTY,
diff --git a/servo.c b/servo.c
index daaa41c..a68c04a 100644
--- a/servo.c
+++ b/servo.c
@@ -26,11 +26,10 @@
 #include "pi.h"
 #include "refclock_sock.h"
 #include "servo_private.h"
+#include "util.h"
 
 #include "print.h"
 
-#define NSEC_PER_SEC 10
-
 struct servo *servo_create(struct config *cfg, enum servo_type type,
   double fadj, int max_ppb, int sw_ts)
 {
diff --git a/tc.c b/tc.c
index 1847041..20717c1 100644
--- a/tc.c
+++ b/tc.c
@@ -254,13 +254,12 @@ static void tc_complete(struct port *q, struct port *p,
 
 static int tc_current(struct ptp_message *m, struct timespec now)
 {
-   int64_t t1, t2, tmo;
+   int64_t t1, t2;
 
-   tmo = 1LL * NSEC2SEC;
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
-   return t2 - t1 < tmo;
+   return t2 - t1 < NSEC_PER_SEC;
 }
 
 static int tc_fwd_event(struct port *q, struct ptp_message *msg)
diff --git a/util.h b/util.h
index 2bbde71..1cbd9b6 100644
--- a/util.h
+++ b/util.h
@@ -33,6 +33,8 @@
 #define MAX_PRINT_BYTES 16
 #define BIN_BUF_SIZE (

[Linuxptp-devel] [PATCH v3 3/5] phc_ctl: Add maximum offset capability

2023-09-25 Thread Rahul Rameshbabu via Linuxptp-devel
Advertise the maximum offset that can be fed to the PHC phase control
keyword.

Signed-off-by: Rahul Rameshbabu 
---
 missing.h | 9 +
 phc_ctl.c | 4 
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/missing.h b/missing.h
index 79a87d4..165a297 100644
--- a/missing.h
+++ b/missing.h
@@ -98,9 +98,9 @@ enum {
 #define PTP_PEROUT_REQUEST2 PTP_PEROUT_REQUEST
 #endif
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(6,5,0)
 
-/* from upcoming Linux kernel version 5.8 */
+/* from upcoming Linux kernel version 6.5 */
 struct compat_ptp_clock_caps {
int max_adj;   /* Maximum frequency adjustment in parts per billon. */
int n_alarm;   /* Number of programmable alarms. */
@@ -112,12 +112,13 @@ struct compat_ptp_clock_caps {
int cross_timestamping;
/* Whether the clock supports adjust phase */
int adjust_phase;
-   int rsv[12];   /* Reserved for future use. */
+   int max_phase_adj;
+   int rsv[11];   /* Reserved for future use. */
 };
 
 #define ptp_clock_caps compat_ptp_clock_caps
 
-#endif /*LINUX_VERSION_CODE < 5.8*/
+#endif /*LINUX_VERSION_CODE < 6.5*/
 
 /*
  * Bits of the ptp_perout_request.flags field:
diff --git a/phc_ctl.c b/phc_ctl.c
index c5430d8..a814648 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -355,6 +355,10 @@ static int do_caps(clockid_t clkid, int cmdc, char *cmdv[])
"no information regarding"
#endif
);
+
+   if (caps.max_phase_adj)
+   pr_notice("  %d maximum offset adjustment (ns)\n", 
caps.max_phase_adj);
+
return 0;
 }
 
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


Re: [Linuxptp-devel] [PATCH v2 1/5] Rename NSEC2SEC as NSEC_PER_SEC and refactor to util.h

2023-09-22 Thread Rahul Rameshbabu via Linuxptp-devel
On Fri, 22 Sep, 2023 15:47:15 +0200 Przemek Kitszel 
 wrote:
> On 9/21/23 23:25, Rahul Rameshbabu via Linuxptp-devel wrote:
>> The name NSEC2SEC implies converting nanoseconds to seconds, but the value
>> used for the macro converts seconds to nanoseconds. NSEC_PER_SEC is the
>> accurate name for this macro. Move macro to common location in util.h.
>> Signed-off-by: Rahul Rameshbabu 
>> ---
>>   phc_ctl.c  |  8 +++-
>>   port.c | 14 +++---
>>   port_private.h |  3 +--
>>   servo.c|  3 +--
>>   tc.c   |  6 +++---
>>   util.h |  2 ++
>>   6 files changed, 17 insertions(+), 19 deletions(-)
>> diff --git a/phc_ctl.c b/phc_ctl.c
>> index 6a5c2f4..fa522eb 100644
>> --- a/phc_ctl.c
>> +++ b/phc_ctl.c
>> @@ -48,8 +48,6 @@
>>   #include "util.h"
>>   #include "version.h"
>>   -#define NSEC2SEC 10.0
>> -
>>   /* trap the alarm signal so that pause() will wake up on receipt */
>>   static void handle_alarm(int s)
>>   {
>> @@ -68,7 +66,7 @@ static void double_to_timespec(double d, struct timespec 
>> *ts)
>>   * value by our fractional component. This results in a correct
>>   * timespec from the double representing seconds.
>>   */
>> -ts->tv_nsec = (long)(NSEC2SEC * fraction);
>> +ts->tv_nsec = (long)(NSEC_PER_SEC * fraction);
>>   }
>> static int install_handler(int signum, void(*handler)(int))
>> @@ -230,7 +228,7 @@ static int do_adj(clockid_t clkid, int cmdc, char 
>> *cmdv[])
>>  return -2;
>>  }
>>   -  nsecs = (int64_t)(NSEC2SEC * time_arg);
>> +nsecs = (int64_t)(NSEC_PER_SEC * time_arg);
>>  clockadj_init(clkid);
>>  clockadj_step(clkid, nsecs);
>> @@ -257,7 +255,7 @@ static int do_freq(clockid_t clkid, int cmdc, char 
>> *cmdv[])
>>  }
>>  /* parse the double ppb argument */
>> -r = get_ranged_double(cmdv[0], &ppb, -NSEC2SEC, NSEC2SEC);
>> +r = get_ranged_double(cmdv[0], &ppb, -NSEC_PER_SEC, NSEC_PER_SEC);
>>  switch (r) {
>>  case PARSED_OK:
>>  break;
>> diff --git a/port.c b/port.c
>> index 5803cd3..79f3702 100644
>> --- a/port.c
>> +++ b/port.c
>> @@ -138,17 +138,17 @@ static int msg_current(struct ptp_message *m, struct 
>> timespec now)
>>   {
>>  int64_t t1, t2, tmo;
>>   -  t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
>> -t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
>> +t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
>> +t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
>>  if (m->header.logMessageInterval <= -31) {
>>  tmo = 0;
>>  } else if (m->header.logMessageInterval >= 31) {
>>  tmo = INT64_MAX;
>>  } else if (m->header.logMessageInterval < 0) {
>> -tmo = 4LL * NSEC2SEC / (1 << -m->header.logMessageInterval);
>> +tmo = 4LL * NSEC_PER_SEC / (1 << -m->header.logMessageInterval);
>>  } else {
>> -tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC2SEC;
>> +tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC_PER_SEC;
>>  }
>>  return t2 - t1 < tmo;
>> @@ -340,10 +340,10 @@ static void fc_prune(struct foreign_clock *fc)
>> static int delay_req_current(struct ptp_message *m, struct timespec now)
>>   {
>> -int64_t t1, t2, tmo = 5 * NSEC2SEC;
>> +int64_t t1, t2, tmo = 5 * NSEC_PER_SEC;
>>   -  t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
>> -t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
>> +t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
>> +t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
>>  return t2 - t1 < tmo;
>>   }
>> diff --git a/port_private.h b/port_private.h
>> index 3b02d2f..d922a3d 100644
>> --- a/port_private.h
>> +++ b/port_private.h
>> @@ -28,8 +28,7 @@
>>   #include "msg.h"
>>   #include "power_profile.h"
>>   #include "tmv.h"
>> -
>> -#define NSEC2SEC 10LL
>> +#include "util.h"
>> enum syfu_state {
>>  SF_EMPTY,
>> diff --git a/servo.c b/servo.c
>> index ea171cd..6d6753e 100644
>> --- a/servo.c
>> +++ b/servo.c
>> @@ -26,11 +26,10 @@
>>   #include "pi.h"
>>   #include "refclock_sock.h"
>>   #include "servo_private.h"
>> +#inc

[Linuxptp-devel] [PATCH v2 5/5] phc_ctl: Handle errors returned by various clockadj helpers

2023-09-21 Thread Rahul Rameshbabu via Linuxptp-devel
Do not print success notices if clockadj operation fails using return
values provided by the clockadj helpers.

Signed-off-by: Rahul Rameshbabu 
---

Notes:
Changes:

  v1->v2:
- Accounted for conditional formatting changes suggested by Erez.
- Added pre-emptive return on error since clockadj_step prints an error
  message as suggested by Erez.

 phc_ctl.c | 18 +-
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index 53b26e1..416c33f 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -232,9 +232,10 @@ static int do_adj(clockid_t clkid, int cmdc, char *cmdv[])
nsecs = (int64_t)(NSEC_PER_SEC * time_arg);
 
clockadj_init(clkid);
-   clockadj_step(clkid, nsecs);
-
-   pr_notice("adjusted clock by %lf seconds", time_arg);
+   if (clockadj_step(clkid, nsecs) == 0)
+   pr_notice("adjusted clock by %lf seconds", time_arg);
+   else
+   return -2;
 
/* adjustment always consumes one argument */
return 1;
@@ -271,8 +272,8 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
return -2;
}
 
-   clockadj_set_freq(clkid, ppb);
-   pr_notice("adjusted clock frequency offset to %lfppb", ppb);
+   if (clockadj_set_freq(clkid, ppb) == 0)
+   pr_notice("adjusted clock frequency offset to %lfppb", ppb);
 
/* consumed one argument to determine the frequency adjustment value */
return 1;
@@ -308,10 +309,9 @@ static int do_phase(clockid_t clkid, int cmdc, char 
*cmdv[])
nsecs = (long)(NSEC_PER_SEC * offset_arg);
 
clockadj_init(clkid);
-   clockadj_set_phase(clkid, nsecs);
-
-   pr_notice("offset of %lf seconds provided to PHC phase control keyword",
- offset_arg);
+   if (clockadj_set_phase(clkid, nsecs) == 0)
+   pr_notice("offset of %lf seconds provided to PHC phase control 
keyword",
+ offset_arg);
 
/* phase offset always consumes one argument */
return 1;
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH v2 2/5] phc_ctl: Add phase command to support ADJ_OFFSET

2023-09-21 Thread Rahul Rameshbabu via Linuxptp-devel
Take double precision floating point representation of an offset value in
seconds. Feed this value to the PHC's phase control keyword.

Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.8 |  4 
 phc_ctl.c | 55 ---
 2 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/phc_ctl.8 b/phc_ctl.8
index 650e661..b10566e 100644
--- a/phc_ctl.8
+++ b/phc_ctl.8
@@ -62,6 +62,10 @@ Adjust the frequency of the PHC clock by the specified parts 
per billion. If no
 argument is provided, it will attempt to read the current frequency and report
 it.
 .TP
+.BI phase " seconds"
+Pass an amount in seconds to the PHC clock's phase control keyword. This
+argument is required.
+.TP
 .BI cmp
 Compare the PHC clock device to CLOCK_REALTIME, using the best method 
available.
 .TP
diff --git a/phc_ctl.c b/phc_ctl.c
index fa522eb..fc6f7b3 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -106,13 +106,14 @@ static void usage(const char *progname)
" specify commands with arguments. Can specify multiple\n"
" commands to be executed in order. Seconds are read as\n"
" double precision floating point values.\n"
-   "  set  [seconds]  set PHC time (defaults to time on 
CLOCK_REALTIME)\n"
-   "  get get PHC time\n"
-   "  adjadjust PHC time by offset\n"
-   "  freq [ppb]  adjust PHC frequency (default returns 
current offset)\n"
-   "  cmp compare PHC offset to CLOCK_REALTIME\n"
-   "  capsdisplay device capabilities (default if no 
command given)\n"
-   "  wait   pause between commands\n"
+   "  set   [seconds]  set PHC time (defaults to time on 
CLOCK_REALTIME)\n"
+   "  get  get PHC time\n"
+   "  adj adjust PHC time by offset\n"
+   "  freq  [ppb]  adjust PHC frequency (default returns 
current offset)\n"
+   "  phase   pass offset to PHC phase control keyword\n"
+   "  cmp  compare PHC offset to CLOCK_REALTIME\n"
+   "  caps display device capabilities (default if no 
command given)\n"
+   "  waitpause between commands\n"
"\n",
progname);
 }
@@ -277,6 +278,45 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
return 1;
 }
 
+static int do_phase(clockid_t clkid, int cmdc, char *cmdv[])
+{
+   double offset_arg;
+   long nsecs;
+   enum parser_result r;
+
+   if (cmdc < 1 || name_is_a_command(cmdv[0])) {
+   pr_err("phase: missing required time argument");
+   return -2;
+   }
+
+   /* parse the double time offset argument */
+   r = get_ranged_double(cmdv[0], &offset_arg, -DBL_MAX, DBL_MAX);
+   switch (r) {
+   case PARSED_OK:
+   break;
+   case MALFORMED:
+   pr_err("phase: '%s' is not a valid double", cmdv[0]);
+   return -2;
+   case OUT_OF_RANGE:
+   pr_err("phase: '%s' is out of range.", cmdv[0]);
+   return -2;
+   default:
+   pr_err("phase: couldn't process '%s'", cmdv[0]);
+   return -2;
+   }
+
+   nsecs = (long)(NSEC_PER_SEC * offset_arg);
+
+   clockadj_init(clkid);
+   clockadj_set_phase(clkid, nsecs);
+
+   pr_notice("offset of %lf seconds provided to PHC phase control keyword",
+ offset_arg);
+
+   /* phase offset always consumes one argument */
+   return 1;
+}
+
 static int do_caps(clockid_t clkid, int cmdc, char *cmdv[])
 {
struct ptp_clock_caps caps;
@@ -399,6 +439,7 @@ static const struct cmd_t all_commands[] = {
{ "get", &do_get },
{ "adj", &do_adj },
{ "freq", &do_freq },
+   { "phase", &do_phase },
{ "cmp", &do_cmp },
{ "caps", &do_caps },
{ "wait", &do_wait },
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH v2 3/5] phc_ctl: Add maximum offset capability

2023-09-21 Thread Rahul Rameshbabu via Linuxptp-devel
Advertise the maximum offset that can be fed to the PHC phase control
keyword.

Signed-off-by: Rahul Rameshbabu 
---
 missing.h | 9 +
 phc_ctl.c | 4 
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/missing.h b/missing.h
index 79a87d4..165a297 100644
--- a/missing.h
+++ b/missing.h
@@ -98,9 +98,9 @@ enum {
 #define PTP_PEROUT_REQUEST2 PTP_PEROUT_REQUEST
 #endif
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(6,5,0)
 
-/* from upcoming Linux kernel version 5.8 */
+/* from upcoming Linux kernel version 6.5 */
 struct compat_ptp_clock_caps {
int max_adj;   /* Maximum frequency adjustment in parts per billon. */
int n_alarm;   /* Number of programmable alarms. */
@@ -112,12 +112,13 @@ struct compat_ptp_clock_caps {
int cross_timestamping;
/* Whether the clock supports adjust phase */
int adjust_phase;
-   int rsv[12];   /* Reserved for future use. */
+   int max_phase_adj;
+   int rsv[11];   /* Reserved for future use. */
 };
 
 #define ptp_clock_caps compat_ptp_clock_caps
 
-#endif /*LINUX_VERSION_CODE < 5.8*/
+#endif /*LINUX_VERSION_CODE < 6.5*/
 
 /*
  * Bits of the ptp_perout_request.flags field:
diff --git a/phc_ctl.c b/phc_ctl.c
index fc6f7b3..ddc0b9d 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -355,6 +355,10 @@ static int do_caps(clockid_t clkid, int cmdc, char *cmdv[])
"no information regarding"
#endif
);
+
+   if (caps.max_phase_adj)
+   pr_notice("  %d maximum offset adjustment (ns)\n", 
caps.max_phase_adj);
+
return 0;
 }
 
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH v2 4/5] phc_ctl: Use pr_notice instead of pr_err for displaying adjusted frequency

2023-09-21 Thread Rahul Rameshbabu via Linuxptp-devel
Adjusted frequency value displayed by do_freq is not an error, but a
notication to the user. pr_err should not be used for providing notices
with information about successful operations.

Fixes: bdb6a35883b0 ("linuxptp: add phc_ctl program to help debug PHC devices")
Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index ddc0b9d..53b26e1 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -249,7 +249,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
 
if (cmdc < 1 || name_is_a_command(cmdv[0])) {
ppb = clockadj_get_freq(clkid);
-   pr_err("clock frequency offset is %lfppb", ppb);
+   pr_notice("clock frequency offset is %lfppb", ppb);
 
/* no argument was used */
return 0;
@@ -272,7 +272,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
}
 
clockadj_set_freq(clkid, ppb);
-   pr_err("adjusted clock frequency offset to %lfppb", ppb);
+   pr_notice("adjusted clock frequency offset to %lfppb", ppb);
 
/* consumed one argument to determine the frequency adjustment value */
return 1;
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH v2 0/5] General improvements for linuxptp focused around phase adjustment

2023-09-21 Thread Rahul Rameshbabu via Linuxptp-devel
The main focus of this submission is adding support for testing ADJ_OFFSET with
phc_ctl and querying the maximum supported ADJ_OFFSET adjustment that a device
is capable of. Some other minor cleanups are also included in the submission.

The patch that introduces support for querying the maximum offset supported by
ADJ_OFFSET depends on a kernel patch series (linked below) that is targeted for
kernel 6.5. Previously, sent this series out as an RFC to inquire feedback early
on. Have incorporated that feedback into this submission.

Changes:

  patch 5:
v1->v2:
  - Accounted for conditional formatting changes suggested by Erez.
  - Added pre-emptive return on error since clockadj_step prints an error
message as suggested by Erez.

Link: https://sourceforge.net/p/linuxptp/mailman/message/37871081/
Link: https://sourceforge.net/p/linuxptp/mailman/message/37860292/
Link: https://sourceforge.net/p/linuxptp/mailman/message/37854603/
Link: 
https://lore.kernel.org/netdev/20230612211500.309075-1-rrameshb...@nvidia.com/


Rahul Rameshbabu (5):
  Rename NSEC2SEC as NSEC_PER_SEC and refactor to util.h
  phc_ctl: Add phase command to support ADJ_OFFSET
  phc_ctl: Add maximum offset capability
  phc_ctl: Use pr_notice instead of pr_err for displaying adjusted
frequency
  phc_ctl: Handle errors returned by various clockadj helpers

 missing.h  |  9 +++---
 phc_ctl.8  |  4 +++
 phc_ctl.c  | 79 ++
 port.c | 14 -
 port_private.h |  3 +-
 servo.c|  3 +-
 tc.c   |  6 ++--
 util.h |  2 ++
 8 files changed, 84 insertions(+), 36 deletions(-)

-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH v2 1/5] Rename NSEC2SEC as NSEC_PER_SEC and refactor to util.h

2023-09-21 Thread Rahul Rameshbabu via Linuxptp-devel
The name NSEC2SEC implies converting nanoseconds to seconds, but the value
used for the macro converts seconds to nanoseconds. NSEC_PER_SEC is the
accurate name for this macro. Move macro to common location in util.h.

Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.c  |  8 +++-
 port.c | 14 +++---
 port_private.h |  3 +--
 servo.c|  3 +--
 tc.c   |  6 +++---
 util.h |  2 ++
 6 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index 6a5c2f4..fa522eb 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -48,8 +48,6 @@
 #include "util.h"
 #include "version.h"
 
-#define NSEC2SEC 10.0
-
 /* trap the alarm signal so that pause() will wake up on receipt */
 static void handle_alarm(int s)
 {
@@ -68,7 +66,7 @@ static void double_to_timespec(double d, struct timespec *ts)
 * value by our fractional component. This results in a correct
 * timespec from the double representing seconds.
 */
-   ts->tv_nsec = (long)(NSEC2SEC * fraction);
+   ts->tv_nsec = (long)(NSEC_PER_SEC * fraction);
 }
 
 static int install_handler(int signum, void(*handler)(int))
@@ -230,7 +228,7 @@ static int do_adj(clockid_t clkid, int cmdc, char *cmdv[])
return -2;
}
 
-   nsecs = (int64_t)(NSEC2SEC * time_arg);
+   nsecs = (int64_t)(NSEC_PER_SEC * time_arg);
 
clockadj_init(clkid);
clockadj_step(clkid, nsecs);
@@ -257,7 +255,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
}
 
/* parse the double ppb argument */
-   r = get_ranged_double(cmdv[0], &ppb, -NSEC2SEC, NSEC2SEC);
+   r = get_ranged_double(cmdv[0], &ppb, -NSEC_PER_SEC, NSEC_PER_SEC);
switch (r) {
case PARSED_OK:
break;
diff --git a/port.c b/port.c
index 5803cd3..79f3702 100644
--- a/port.c
+++ b/port.c
@@ -138,17 +138,17 @@ static int msg_current(struct ptp_message *m, struct 
timespec now)
 {
int64_t t1, t2, tmo;
 
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
if (m->header.logMessageInterval <= -31) {
tmo = 0;
} else if (m->header.logMessageInterval >= 31) {
tmo = INT64_MAX;
} else if (m->header.logMessageInterval < 0) {
-   tmo = 4LL * NSEC2SEC / (1 << -m->header.logMessageInterval);
+   tmo = 4LL * NSEC_PER_SEC / (1 << -m->header.logMessageInterval);
} else {
-   tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC2SEC;
+   tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC_PER_SEC;
}
 
return t2 - t1 < tmo;
@@ -340,10 +340,10 @@ static void fc_prune(struct foreign_clock *fc)
 
 static int delay_req_current(struct ptp_message *m, struct timespec now)
 {
-   int64_t t1, t2, tmo = 5 * NSEC2SEC;
+   int64_t t1, t2, tmo = 5 * NSEC_PER_SEC;
 
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
return t2 - t1 < tmo;
 }
diff --git a/port_private.h b/port_private.h
index 3b02d2f..d922a3d 100644
--- a/port_private.h
+++ b/port_private.h
@@ -28,8 +28,7 @@
 #include "msg.h"
 #include "power_profile.h"
 #include "tmv.h"
-
-#define NSEC2SEC 10LL
+#include "util.h"
 
 enum syfu_state {
SF_EMPTY,
diff --git a/servo.c b/servo.c
index ea171cd..6d6753e 100644
--- a/servo.c
+++ b/servo.c
@@ -26,11 +26,10 @@
 #include "pi.h"
 #include "refclock_sock.h"
 #include "servo_private.h"
+#include "util.h"
 
 #include "print.h"
 
-#define NSEC_PER_SEC 10
-
 struct servo *servo_create(struct config *cfg, enum servo_type type,
   double fadj, int max_ppb, int sw_ts)
 {
diff --git a/tc.c b/tc.c
index 1847041..7d1394c 100644
--- a/tc.c
+++ b/tc.c
@@ -256,9 +256,9 @@ static int tc_current(struct ptp_message *m, struct 
timespec now)
 {
int64_t t1, t2, tmo;
 
-   tmo = 1LL * NSEC2SEC;
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   tmo = 1LL * NSEC_PER_SEC;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
return t2 - t1 < tmo;
 }
diff --git a/util.h b/util.h
index 2bbde71..1cbd9b6 100644
--- a/util.h
+++ b/util.h
@@ -33,6 +33,8 @@
 #define MAX_PRINT_BYTES 16
 #define BIN_BUF_SIZE (MAX_PRINT_BYTES * 3 + 1)
 
+#define NSEC_PER_SEC 10LL
+
 /**
  * Table of human readable strings, one for each port state.
  */
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://

Re: [Linuxptp-devel] [PATCH RESEND v1 3/5] phc_ctl: Add maximum offset capability

2023-09-18 Thread Rahul Rameshbabu via Linuxptp-devel
Hi Erez,

On Tue, 05 Sep, 2023 22:15:47 +0200 Erez  wrote:
> On Tue, 5 Sept 2023 at 21:56, Rahul Rameshbabu via Linuxptp-devel 
>  wrote:
>
>  Advertise the maximum offset that can be fed to the PHC phase control
>  keyword.
>
> Someone already sent this patch, a few months ago.
> But now we can find it in the official kernel. :-)
> https://elixir.bootlin.com/linux/v6.5/source/include/uapi/linux/ptp_clock.h#L204

That someone on the mailing list was me. I also authored the kernel
patches, so I expected it to land in kernel 6.5 (which is why I was
confident in the kernel version). That said, it is definitely nice to
see the change in the official tag.

-- Rahul Rameshbabu

>
> Erez 
>
>  
>  
>  Signed-off-by: Rahul Rameshbabu 
>  ---
>   missing.h | 9 +
>   phc_ctl.c | 4 
>   2 files changed, 9 insertions(+), 4 deletions(-)
>
>  diff --git a/missing.h b/missing.h
>  index 79a87d4..165a297 100644
>  --- a/missing.h
>  +++ b/missing.h
>  @@ -98,9 +98,9 @@ enum {
>   #define PTP_PEROUT_REQUEST2 PTP_PEROUT_REQUEST
>   #endif
>
>  -#if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0)
>  +#if LINUX_VERSION_CODE < KERNEL_VERSION(6,5,0)
>
>  -/* from upcoming Linux kernel version 5.8 */
>  +/* from upcoming Linux kernel version 6.5 */
>   struct compat_ptp_clock_caps {
>  int max_adj;   /* Maximum frequency adjustment in parts per billon. 
> */
>  int n_alarm;   /* Number of programmable alarms. */
>  @@ -112,12 +112,13 @@ struct compat_ptp_clock_caps {
>  int cross_timestamping;
>  /* Whether the clock supports adjust phase */
>  int adjust_phase;
>  -   int rsv[12];   /* Reserved for future use. */
>  +   int max_phase_adj;
>  +   int rsv[11];   /* Reserved for future use. */
>   };
>
>   #define ptp_clock_caps compat_ptp_clock_caps
>
>  -#endif /*LINUX_VERSION_CODE < 5.8*/
>  +#endif /*LINUX_VERSION_CODE < 6.5*/
>
>   /*
>* Bits of the ptp_perout_request.flags field:
>  diff --git a/phc_ctl.c b/phc_ctl.c
>  index c5430d8..a814648 100644
>  --- a/phc_ctl.c
>  +++ b/phc_ctl.c
>  @@ -355,6 +355,10 @@ static int do_caps(clockid_t clkid, int cmdc, char 
> *cmdv[])
>  "no information regarding"
>  #endif
>  );
>  +
>  +   if (caps.max_phase_adj)
>  +   pr_notice("  %d maximum offset adjustment (ns)\n", 
> caps.max_phase_adj);
>  +
>  return 0;
>   }
>
>  -- 
>  2.40.1
>
>  ___
>  Linuxptp-devel mailing list
>  Linuxptp-devel@lists.sourceforge.net
>  https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


Re: [Linuxptp-devel] [PATCH RESEND v1 2/5] phc_ctl: Add phase command to support ADJ_OFFSET

2023-09-18 Thread Rahul Rameshbabu via Linuxptp-devel
Hi Erez,

On Wed, 06 Sep, 2023 23:05:12 +0200 Erez  wrote:
> On Wed, 6 Sept 2023 at 00:56, Rahul Rameshbabu via Linuxptp-devel 
>  wrote:
>
>  Take double precision floating point representation of an offset value in
>  seconds. Feed this value to the PHC's phase control keyword.
>
>  Signed-off-by: Rahul Rameshbabu 
>  ---
>   phc_ctl.8 |  4 
>   phc_ctl.c | 55 ---
>   2 files changed, 52 insertions(+), 7 deletions(-)
>
>  diff --git a/phc_ctl.8 b/phc_ctl.8
>  index 650e661..b10566e 100644
>  --- a/phc_ctl.8
>  +++ b/phc_ctl.8
>  @@ -62,6 +62,10 @@ Adjust the frequency of the PHC clock by the specified 
> parts per billion. If no
>   argument is provided, it will attempt to read the current frequency and 
> report
>   it.
>   .TP
>  +.BI phase " seconds"
>  +Pass an amount in seconds to the PHC clock's phase control keyword. This
>  +argument is required.
>  +.TP
>   .BI cmp
>   Compare the PHC clock device to CLOCK_REALTIME, using the best method 
> available.
>   .TP
>  diff --git a/phc_ctl.c b/phc_ctl.c
>  index db89f01..c5430d8 100644
>  --- a/phc_ctl.c
>  +++ b/phc_ctl.c
>  @@ -106,13 +106,14 @@ static void usage(const char *progname)
>  " specify commands with arguments. Can specify multiple\n"
>  " commands to be executed in order. Seconds are read as\n"
>  " double precision floating point values.\n"
>  -   "  set  [seconds]  set PHC time (defaults to time on 
> CLOCK_REALTIME)\n"
>  -   "  get get PHC time\n"
>  -   "  adjadjust PHC time by offset\n"
>  -   "  freq [ppb]  adjust PHC frequency (default returns 
> current offset)\n"
>  -   "  cmp compare PHC offset to CLOCK_REALTIME\n"
>  -   "  capsdisplay device capabilities (default if 
> no command given)\n"
>  -   "  wait   pause between commands\n"
>  +   "  set   [seconds]  set PHC time (defaults to time on 
> CLOCK_REALTIME)\n"
>  +   "  get  get PHC time\n"
>  +   "  adj adjust PHC time by offset\n"
>  +   "  freq  [ppb]  adjust PHC frequency (default returns 
> current offset)\n"
>  +   "  phase   pass offset to PHC phase control 
> keyword\n"
>  +   "  cmp  compare PHC offset to CLOCK_REALTIME\n"
>  +   "  caps display device capabilities (default if 
> no command given)\n"
>  +   "  waitpause between commands\n"
>  "\n",
>  progname);
>   }
>  @@ -277,6 +278,45 @@ static int do_freq(clockid_t clkid, int cmdc, char 
> *cmdv[])
>  return 1;
>   }
>
>  +static int do_phase(clockid_t clkid, int cmdc, char *cmdv[])
>  +{
>  +   double offset_arg;
>  +   long nsecs;
>  +   enum parser_result r;
>  +
>  +   if (cmdc < 1 || name_is_a_command(cmdv[0])) {
>  +   pr_err("phase: missing required time argument");
>  +   return -2;
>  +   }
>  +
>  +   /* parse the double time offset argument */
>  +   r = get_ranged_double(cmdv[0], &offset_arg, -DBL_MAX, DBL_MAX);
>  +   switch (r) {
>  +   case PARSED_OK:
>  +   break;
>  +   case MALFORMED:
>  +   pr_err("phase: '%s' is not a valid double", cmdv[0]);
>  +   return -2;
>  +   case OUT_OF_RANGE:
>  +   pr_err("phase: '%s' is out of range.", cmdv[0]);
>  +   return -2;
>  +   default:
>  +   pr_err("phase: couldn't process '%s'", cmdv[0]);
>  +   return -2;
>  +   }
>  +
>  +   nsecs = (long)(NSEC_PER_SEC * offset_arg);
>  +
>  +   clockadj_init(clkid);
>  +   clockadj_set_phase(clkid, nsecs);
>
> In the other patch, you test for error here and avoid the following 
> 'pr_notice'.
> Why not do the same here?

I do this as part of the refactor to phc_ctl in patch 5/5 in this
series. I think this patch as-is makes sense, so phc_ctl stays
consistent no matter what reverts may occur in the history. Feel free to
let me know if you think this should be handled differently.

https://sourceforge.net/p/linuxptp/mailman/message/37892473/

-- Rahul Rameshbabu

>
> Erez
>  
>  +
>  +   

[Linuxptp-devel] [PATCH RESEND v1 4/5] phc_ctl: Use pr_notice instead of pr_err for displaying adjusted frequency

2023-09-05 Thread Rahul Rameshbabu via Linuxptp-devel
Adjusted frequency value displayed by do_freq is not an error, but a
notication to the user. pr_err should not be used for providing notices
with information about successful operations.

Fixes: bdb6a35883b0 ("linuxptp: add phc_ctl program to help debug PHC devices")
Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index a814648..34d9e0c 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -249,7 +249,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
 
if (cmdc < 1 || name_is_a_command(cmdv[0])) {
ppb = clockadj_get_freq(clkid);
-   pr_err("clock frequency offset is %lfppb", ppb);
+   pr_notice("clock frequency offset is %lfppb", ppb);
 
/* no argument was used */
return 0;
@@ -272,7 +272,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
}
 
clockadj_set_freq(clkid, ppb);
-   pr_err("adjusted clock frequency offset to %lfppb", ppb);
+   pr_notice("adjusted clock frequency offset to %lfppb", ppb);
 
/* consumed one argument to determine the frequency adjustment value */
return 1;
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH RESEND v1 2/5] phc_ctl: Add phase command to support ADJ_OFFSET

2023-09-05 Thread Rahul Rameshbabu via Linuxptp-devel
Take double precision floating point representation of an offset value in
seconds. Feed this value to the PHC's phase control keyword.

Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.8 |  4 
 phc_ctl.c | 55 ---
 2 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/phc_ctl.8 b/phc_ctl.8
index 650e661..b10566e 100644
--- a/phc_ctl.8
+++ b/phc_ctl.8
@@ -62,6 +62,10 @@ Adjust the frequency of the PHC clock by the specified parts 
per billion. If no
 argument is provided, it will attempt to read the current frequency and report
 it.
 .TP
+.BI phase " seconds"
+Pass an amount in seconds to the PHC clock's phase control keyword. This
+argument is required.
+.TP
 .BI cmp
 Compare the PHC clock device to CLOCK_REALTIME, using the best method 
available.
 .TP
diff --git a/phc_ctl.c b/phc_ctl.c
index db89f01..c5430d8 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -106,13 +106,14 @@ static void usage(const char *progname)
" specify commands with arguments. Can specify multiple\n"
" commands to be executed in order. Seconds are read as\n"
" double precision floating point values.\n"
-   "  set  [seconds]  set PHC time (defaults to time on 
CLOCK_REALTIME)\n"
-   "  get get PHC time\n"
-   "  adjadjust PHC time by offset\n"
-   "  freq [ppb]  adjust PHC frequency (default returns 
current offset)\n"
-   "  cmp compare PHC offset to CLOCK_REALTIME\n"
-   "  capsdisplay device capabilities (default if no 
command given)\n"
-   "  wait   pause between commands\n"
+   "  set   [seconds]  set PHC time (defaults to time on 
CLOCK_REALTIME)\n"
+   "  get  get PHC time\n"
+   "  adj adjust PHC time by offset\n"
+   "  freq  [ppb]  adjust PHC frequency (default returns 
current offset)\n"
+   "  phase   pass offset to PHC phase control keyword\n"
+   "  cmp  compare PHC offset to CLOCK_REALTIME\n"
+   "  caps display device capabilities (default if no 
command given)\n"
+   "  waitpause between commands\n"
"\n",
progname);
 }
@@ -277,6 +278,45 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
return 1;
 }
 
+static int do_phase(clockid_t clkid, int cmdc, char *cmdv[])
+{
+   double offset_arg;
+   long nsecs;
+   enum parser_result r;
+
+   if (cmdc < 1 || name_is_a_command(cmdv[0])) {
+   pr_err("phase: missing required time argument");
+   return -2;
+   }
+
+   /* parse the double time offset argument */
+   r = get_ranged_double(cmdv[0], &offset_arg, -DBL_MAX, DBL_MAX);
+   switch (r) {
+   case PARSED_OK:
+   break;
+   case MALFORMED:
+   pr_err("phase: '%s' is not a valid double", cmdv[0]);
+   return -2;
+   case OUT_OF_RANGE:
+   pr_err("phase: '%s' is out of range.", cmdv[0]);
+   return -2;
+   default:
+   pr_err("phase: couldn't process '%s'", cmdv[0]);
+   return -2;
+   }
+
+   nsecs = (long)(NSEC_PER_SEC * offset_arg);
+
+   clockadj_init(clkid);
+   clockadj_set_phase(clkid, nsecs);
+
+   pr_notice("offset of %lf seconds provided to PHC phase control keyword",
+ offset_arg);
+
+   /* phase offset always consumes one argument */
+   return 1;
+}
+
 static int do_caps(clockid_t clkid, int cmdc, char *cmdv[])
 {
struct ptp_clock_caps caps;
@@ -399,6 +439,7 @@ static const struct cmd_t all_commands[] = {
{ "get", &do_get },
{ "adj", &do_adj },
{ "freq", &do_freq },
+   { "phase", &do_phase },
{ "cmp", &do_cmp },
{ "caps", &do_caps },
{ "wait", &do_wait },
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH RESEND v1 1/5] Rename NSEC2SEC as NSEC_PER_SEC and refactor to util.h

2023-09-05 Thread Rahul Rameshbabu via Linuxptp-devel
The name NSEC2SEC implies converting nanoseconds to seconds, but the value
used for the macro converts seconds to nanoseconds. NSEC_PER_SEC is the
accurate name for this macro. Move macro to common location in util.h.

Signed-off-by: Rahul Rameshbabu 
---

Notes:
Changes since RFC:

  * Refactored macro to live in util.h.
+ Noticed that float usage in phc_ctl.c does not need an explicit cast

 phc_ctl.c  |  8 +++-
 port.c | 14 +++---
 port_private.h |  3 +--
 servo.c|  3 +--
 tc.c   |  6 +++---
 util.h |  2 ++
 6 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index 92e597c..db89f01 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -48,8 +48,6 @@
 #include "util.h"
 #include "version.h"
 
-#define NSEC2SEC 10.0
-
 /* trap the alarm signal so that pause() will wake up on receipt */
 static void handle_alarm(int s)
 {
@@ -68,7 +66,7 @@ static void double_to_timespec(double d, struct timespec *ts)
 * value by our fractional component. This results in a correct
 * timespec from the double representing seconds.
 */
-   ts->tv_nsec = (long)(NSEC2SEC * fraction);
+   ts->tv_nsec = (long)(NSEC_PER_SEC * fraction);
 }
 
 static int install_handler(int signum, void(*handler)(int))
@@ -230,7 +228,7 @@ static int do_adj(clockid_t clkid, int cmdc, char *cmdv[])
return -2;
}
 
-   nsecs = (int64_t)(NSEC2SEC * time_arg);
+   nsecs = (int64_t)(NSEC_PER_SEC * time_arg);
 
clockadj_init(clkid);
clockadj_step(clkid, nsecs);
@@ -257,7 +255,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
}
 
/* parse the double ppb argument */
-   r = get_ranged_double(cmdv[0], &ppb, -NSEC2SEC, NSEC2SEC);
+   r = get_ranged_double(cmdv[0], &ppb, -NSEC_PER_SEC, NSEC_PER_SEC);
switch (r) {
case PARSED_OK:
break;
diff --git a/port.c b/port.c
index d551bef..b75f850 100644
--- a/port.c
+++ b/port.c
@@ -138,17 +138,17 @@ static int msg_current(struct ptp_message *m, struct 
timespec now)
 {
int64_t t1, t2, tmo;
 
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
if (m->header.logMessageInterval <= -31) {
tmo = 0;
} else if (m->header.logMessageInterval >= 31) {
tmo = INT64_MAX;
} else if (m->header.logMessageInterval < 0) {
-   tmo = 4LL * NSEC2SEC / (1 << -m->header.logMessageInterval);
+   tmo = 4LL * NSEC_PER_SEC / (1 << -m->header.logMessageInterval);
} else {
-   tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC2SEC;
+   tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC_PER_SEC;
}
 
return t2 - t1 < tmo;
@@ -340,10 +340,10 @@ static void fc_prune(struct foreign_clock *fc)
 
 static int delay_req_current(struct ptp_message *m, struct timespec now)
 {
-   int64_t t1, t2, tmo = 5 * NSEC2SEC;
+   int64_t t1, t2, tmo = 5 * NSEC_PER_SEC;
 
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
return t2 - t1 < tmo;
 }
diff --git a/port_private.h b/port_private.h
index 3b02d2f..d922a3d 100644
--- a/port_private.h
+++ b/port_private.h
@@ -28,8 +28,7 @@
 #include "msg.h"
 #include "power_profile.h"
 #include "tmv.h"
-
-#define NSEC2SEC 10LL
+#include "util.h"
 
 enum syfu_state {
SF_EMPTY,
diff --git a/servo.c b/servo.c
index daaa41c..a68c04a 100644
--- a/servo.c
+++ b/servo.c
@@ -26,11 +26,10 @@
 #include "pi.h"
 #include "refclock_sock.h"
 #include "servo_private.h"
+#include "util.h"
 
 #include "print.h"
 
-#define NSEC_PER_SEC 10
-
 struct servo *servo_create(struct config *cfg, enum servo_type type,
   double fadj, int max_ppb, int sw_ts)
 {
diff --git a/tc.c b/tc.c
index 1847041..7d1394c 100644
--- a/tc.c
+++ b/tc.c
@@ -256,9 +256,9 @@ static int tc_current(struct ptp_message *m, struct 
timespec now)
 {
int64_t t1, t2, tmo;
 
-   tmo = 1LL * NSEC2SEC;
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   tmo = 1LL * NSEC_PER_SEC;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
return t2 - t1 < tmo;
 }
diff --git a/util.h b/util.h
index 2bbde71..1cbd9b6 100644
--- a/util.h
+++ b/util.h
@@ -33,6 +33,8 @@
 #define MAX_PRINT_BYTES 16
 #define BIN_BUF_SIZE (MAX_PRINT_BYTES * 3 + 1)
 
+#define NSEC_PER_SEC 10LL
+
 /**
  * Table of human readable strings, one f

[Linuxptp-devel] [PATCH RESEND v1 0/5] General improvements for linuxptp focused around phase adjustment

2023-09-05 Thread Rahul Rameshbabu via Linuxptp-devel
The main focus of this submission is adding support for testing ADJ_OFFSET with
phc_ctl and querying the maximum supported ADJ_OFFSET adjustment that a device
is capable of. Some other minor cleanups are also included in the submission.

The patch that introduces support for querying the maximum offset supported by
ADJ_OFFSET depends on a kernel patch series (linked below) that is targeted for
kernel 6.5. Previously, sent this series out as an RFC to inquire feedback early
on. Have incorporated that feedback into this submission.

Link: https://sourceforge.net/p/linuxptp/mailman/message/37860292/
Link: https://sourceforge.net/p/linuxptp/mailman/message/37854603/
Link: 
https://lore.kernel.org/netdev/20230612211500.309075-1-rrameshb...@nvidia.com/

Rahul Rameshbabu (5):
  Rename NSEC2SEC as NSEC_PER_SEC and refactor to util.h
  phc_ctl: Add phase command to support ADJ_OFFSET
  phc_ctl: Add maximum offset capability
  phc_ctl: Use pr_notice instead of pr_err for displaying adjusted
frequency
  phc_ctl: Handle errors returned by various clockadj helpers

 missing.h  |  9 +++---
 phc_ctl.8  |  4 +++
 phc_ctl.c  | 77 ++
 port.c | 14 -
 port_private.h |  3 +-
 servo.c|  3 +-
 tc.c   |  6 ++--
 util.h |  2 ++
 8 files changed, 82 insertions(+), 36 deletions(-)

-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH RESEND v1 3/5] phc_ctl: Add maximum offset capability

2023-09-05 Thread Rahul Rameshbabu via Linuxptp-devel
Advertise the maximum offset that can be fed to the PHC phase control
keyword.

Signed-off-by: Rahul Rameshbabu 
---
 missing.h | 9 +
 phc_ctl.c | 4 
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/missing.h b/missing.h
index 79a87d4..165a297 100644
--- a/missing.h
+++ b/missing.h
@@ -98,9 +98,9 @@ enum {
 #define PTP_PEROUT_REQUEST2 PTP_PEROUT_REQUEST
 #endif
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(6,5,0)
 
-/* from upcoming Linux kernel version 5.8 */
+/* from upcoming Linux kernel version 6.5 */
 struct compat_ptp_clock_caps {
int max_adj;   /* Maximum frequency adjustment in parts per billon. */
int n_alarm;   /* Number of programmable alarms. */
@@ -112,12 +112,13 @@ struct compat_ptp_clock_caps {
int cross_timestamping;
/* Whether the clock supports adjust phase */
int adjust_phase;
-   int rsv[12];   /* Reserved for future use. */
+   int max_phase_adj;
+   int rsv[11];   /* Reserved for future use. */
 };
 
 #define ptp_clock_caps compat_ptp_clock_caps
 
-#endif /*LINUX_VERSION_CODE < 5.8*/
+#endif /*LINUX_VERSION_CODE < 6.5*/
 
 /*
  * Bits of the ptp_perout_request.flags field:
diff --git a/phc_ctl.c b/phc_ctl.c
index c5430d8..a814648 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -355,6 +355,10 @@ static int do_caps(clockid_t clkid, int cmdc, char *cmdv[])
"no information regarding"
#endif
);
+
+   if (caps.max_phase_adj)
+   pr_notice("  %d maximum offset adjustment (ns)\n", 
caps.max_phase_adj);
+
return 0;
 }
 
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH RESEND v1 5/5] phc_ctl: Handle errors returned by various clockadj helpers

2023-09-05 Thread Rahul Rameshbabu via Linuxptp-devel
Do not print success notices if clockadj operation fails using return
values provided by the clockadj helpers.

Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index 34d9e0c..e174189 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -232,9 +232,8 @@ static int do_adj(clockid_t clkid, int cmdc, char *cmdv[])
nsecs = (int64_t)(NSEC_PER_SEC * time_arg);
 
clockadj_init(clkid);
-   clockadj_step(clkid, nsecs);
-
-   pr_notice("adjusted clock by %lf seconds", time_arg);
+   if (!clockadj_step(clkid, nsecs))
+   pr_notice("adjusted clock by %lf seconds", time_arg);
 
/* adjustment always consumes one argument */
return 1;
@@ -271,8 +270,8 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
return -2;
}
 
-   clockadj_set_freq(clkid, ppb);
-   pr_notice("adjusted clock frequency offset to %lfppb", ppb);
+   if (!clockadj_set_freq(clkid, ppb))
+   pr_notice("adjusted clock frequency offset to %lfppb", ppb);
 
/* consumed one argument to determine the frequency adjustment value */
return 1;
@@ -308,10 +307,9 @@ static int do_phase(clockid_t clkid, int cmdc, char 
*cmdv[])
nsecs = (long)(NSEC_PER_SEC * offset_arg);
 
clockadj_init(clkid);
-   clockadj_set_phase(clkid, nsecs);
-
-   pr_notice("offset of %lf seconds provided to PHC phase control keyword",
- offset_arg);
+   if (!clockadj_set_phase(clkid, nsecs))
+   pr_notice("offset of %lf seconds provided to PHC phase control 
keyword",
+ offset_arg);
 
/* phase offset always consumes one argument */
return 1;
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH RESEND v1 3/5] phc_ctl: Add maximum offset capability

2023-07-14 Thread Rahul Rameshbabu via Linuxptp-devel
Advertise the maximum offset that can be fed to the PHC phase control
keyword.

Signed-off-by: Rahul Rameshbabu 
---
 missing.h | 9 +
 phc_ctl.c | 4 
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/missing.h b/missing.h
index 79a87d4..165a297 100644
--- a/missing.h
+++ b/missing.h
@@ -98,9 +98,9 @@ enum {
 #define PTP_PEROUT_REQUEST2 PTP_PEROUT_REQUEST
 #endif
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(6,5,0)
 
-/* from upcoming Linux kernel version 5.8 */
+/* from upcoming Linux kernel version 6.5 */
 struct compat_ptp_clock_caps {
int max_adj;   /* Maximum frequency adjustment in parts per billon. */
int n_alarm;   /* Number of programmable alarms. */
@@ -112,12 +112,13 @@ struct compat_ptp_clock_caps {
int cross_timestamping;
/* Whether the clock supports adjust phase */
int adjust_phase;
-   int rsv[12];   /* Reserved for future use. */
+   int max_phase_adj;
+   int rsv[11];   /* Reserved for future use. */
 };
 
 #define ptp_clock_caps compat_ptp_clock_caps
 
-#endif /*LINUX_VERSION_CODE < 5.8*/
+#endif /*LINUX_VERSION_CODE < 6.5*/
 
 /*
  * Bits of the ptp_perout_request.flags field:
diff --git a/phc_ctl.c b/phc_ctl.c
index c5430d8..a814648 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -355,6 +355,10 @@ static int do_caps(clockid_t clkid, int cmdc, char *cmdv[])
"no information regarding"
#endif
);
+
+   if (caps.max_phase_adj)
+   pr_notice("  %d maximum offset adjustment (ns)\n", 
caps.max_phase_adj);
+
return 0;
 }
 
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH RESEND v1 2/5] phc_ctl: Add phase command to support ADJ_OFFSET

2023-07-14 Thread Rahul Rameshbabu via Linuxptp-devel
Take double precision floating point representation of an offset value in
seconds. Feed this value to the PHC's phase control keyword.

Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.8 |  4 
 phc_ctl.c | 55 ---
 2 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/phc_ctl.8 b/phc_ctl.8
index 650e661..b10566e 100644
--- a/phc_ctl.8
+++ b/phc_ctl.8
@@ -62,6 +62,10 @@ Adjust the frequency of the PHC clock by the specified parts 
per billion. If no
 argument is provided, it will attempt to read the current frequency and report
 it.
 .TP
+.BI phase " seconds"
+Pass an amount in seconds to the PHC clock's phase control keyword. This
+argument is required.
+.TP
 .BI cmp
 Compare the PHC clock device to CLOCK_REALTIME, using the best method 
available.
 .TP
diff --git a/phc_ctl.c b/phc_ctl.c
index db89f01..c5430d8 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -106,13 +106,14 @@ static void usage(const char *progname)
" specify commands with arguments. Can specify multiple\n"
" commands to be executed in order. Seconds are read as\n"
" double precision floating point values.\n"
-   "  set  [seconds]  set PHC time (defaults to time on 
CLOCK_REALTIME)\n"
-   "  get get PHC time\n"
-   "  adjadjust PHC time by offset\n"
-   "  freq [ppb]  adjust PHC frequency (default returns 
current offset)\n"
-   "  cmp compare PHC offset to CLOCK_REALTIME\n"
-   "  capsdisplay device capabilities (default if no 
command given)\n"
-   "  wait   pause between commands\n"
+   "  set   [seconds]  set PHC time (defaults to time on 
CLOCK_REALTIME)\n"
+   "  get  get PHC time\n"
+   "  adj adjust PHC time by offset\n"
+   "  freq  [ppb]  adjust PHC frequency (default returns 
current offset)\n"
+   "  phase   pass offset to PHC phase control keyword\n"
+   "  cmp  compare PHC offset to CLOCK_REALTIME\n"
+   "  caps display device capabilities (default if no 
command given)\n"
+   "  waitpause between commands\n"
"\n",
progname);
 }
@@ -277,6 +278,45 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
return 1;
 }
 
+static int do_phase(clockid_t clkid, int cmdc, char *cmdv[])
+{
+   double offset_arg;
+   long nsecs;
+   enum parser_result r;
+
+   if (cmdc < 1 || name_is_a_command(cmdv[0])) {
+   pr_err("phase: missing required time argument");
+   return -2;
+   }
+
+   /* parse the double time offset argument */
+   r = get_ranged_double(cmdv[0], &offset_arg, -DBL_MAX, DBL_MAX);
+   switch (r) {
+   case PARSED_OK:
+   break;
+   case MALFORMED:
+   pr_err("phase: '%s' is not a valid double", cmdv[0]);
+   return -2;
+   case OUT_OF_RANGE:
+   pr_err("phase: '%s' is out of range.", cmdv[0]);
+   return -2;
+   default:
+   pr_err("phase: couldn't process '%s'", cmdv[0]);
+   return -2;
+   }
+
+   nsecs = (long)(NSEC_PER_SEC * offset_arg);
+
+   clockadj_init(clkid);
+   clockadj_set_phase(clkid, nsecs);
+
+   pr_notice("offset of %lf seconds provided to PHC phase control keyword",
+ offset_arg);
+
+   /* phase offset always consumes one argument */
+   return 1;
+}
+
 static int do_caps(clockid_t clkid, int cmdc, char *cmdv[])
 {
struct ptp_clock_caps caps;
@@ -399,6 +439,7 @@ static const struct cmd_t all_commands[] = {
{ "get", &do_get },
{ "adj", &do_adj },
{ "freq", &do_freq },
+   { "phase", &do_phase },
{ "cmp", &do_cmp },
{ "caps", &do_caps },
{ "wait", &do_wait },
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH RESEND v1 1/5] Rename NSEC2SEC as NSEC_PER_SEC and refactor to util.h

2023-07-14 Thread Rahul Rameshbabu via Linuxptp-devel
The name NSEC2SEC implies converting nanoseconds to seconds, but the value
used for the macro converts seconds to nanoseconds. NSEC_PER_SEC is the
accurate name for this macro. Move macro to common location in util.h.

Signed-off-by: Rahul Rameshbabu 
---

Notes:
Changes since RFC:

  * Refactored macro to live in util.h.
+ Noticed that float usage in phc_ctl.c does not need an explicit cast

 phc_ctl.c  |  8 +++-
 port.c | 14 +++---
 port_private.h |  3 +--
 servo.c|  3 +--
 tc.c   |  6 +++---
 util.h |  2 ++
 6 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index 92e597c..db89f01 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -48,8 +48,6 @@
 #include "util.h"
 #include "version.h"
 
-#define NSEC2SEC 10.0
-
 /* trap the alarm signal so that pause() will wake up on receipt */
 static void handle_alarm(int s)
 {
@@ -68,7 +66,7 @@ static void double_to_timespec(double d, struct timespec *ts)
 * value by our fractional component. This results in a correct
 * timespec from the double representing seconds.
 */
-   ts->tv_nsec = (long)(NSEC2SEC * fraction);
+   ts->tv_nsec = (long)(NSEC_PER_SEC * fraction);
 }
 
 static int install_handler(int signum, void(*handler)(int))
@@ -230,7 +228,7 @@ static int do_adj(clockid_t clkid, int cmdc, char *cmdv[])
return -2;
}
 
-   nsecs = (int64_t)(NSEC2SEC * time_arg);
+   nsecs = (int64_t)(NSEC_PER_SEC * time_arg);
 
clockadj_init(clkid);
clockadj_step(clkid, nsecs);
@@ -257,7 +255,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
}
 
/* parse the double ppb argument */
-   r = get_ranged_double(cmdv[0], &ppb, -NSEC2SEC, NSEC2SEC);
+   r = get_ranged_double(cmdv[0], &ppb, -NSEC_PER_SEC, NSEC_PER_SEC);
switch (r) {
case PARSED_OK:
break;
diff --git a/port.c b/port.c
index d551bef..b75f850 100644
--- a/port.c
+++ b/port.c
@@ -138,17 +138,17 @@ static int msg_current(struct ptp_message *m, struct 
timespec now)
 {
int64_t t1, t2, tmo;
 
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
if (m->header.logMessageInterval <= -31) {
tmo = 0;
} else if (m->header.logMessageInterval >= 31) {
tmo = INT64_MAX;
} else if (m->header.logMessageInterval < 0) {
-   tmo = 4LL * NSEC2SEC / (1 << -m->header.logMessageInterval);
+   tmo = 4LL * NSEC_PER_SEC / (1 << -m->header.logMessageInterval);
} else {
-   tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC2SEC;
+   tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC_PER_SEC;
}
 
return t2 - t1 < tmo;
@@ -340,10 +340,10 @@ static void fc_prune(struct foreign_clock *fc)
 
 static int delay_req_current(struct ptp_message *m, struct timespec now)
 {
-   int64_t t1, t2, tmo = 5 * NSEC2SEC;
+   int64_t t1, t2, tmo = 5 * NSEC_PER_SEC;
 
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
return t2 - t1 < tmo;
 }
diff --git a/port_private.h b/port_private.h
index 3b02d2f..d922a3d 100644
--- a/port_private.h
+++ b/port_private.h
@@ -28,8 +28,7 @@
 #include "msg.h"
 #include "power_profile.h"
 #include "tmv.h"
-
-#define NSEC2SEC 10LL
+#include "util.h"
 
 enum syfu_state {
SF_EMPTY,
diff --git a/servo.c b/servo.c
index daaa41c..a68c04a 100644
--- a/servo.c
+++ b/servo.c
@@ -26,11 +26,10 @@
 #include "pi.h"
 #include "refclock_sock.h"
 #include "servo_private.h"
+#include "util.h"
 
 #include "print.h"
 
-#define NSEC_PER_SEC 10
-
 struct servo *servo_create(struct config *cfg, enum servo_type type,
   double fadj, int max_ppb, int sw_ts)
 {
diff --git a/tc.c b/tc.c
index 1847041..7d1394c 100644
--- a/tc.c
+++ b/tc.c
@@ -256,9 +256,9 @@ static int tc_current(struct ptp_message *m, struct 
timespec now)
 {
int64_t t1, t2, tmo;
 
-   tmo = 1LL * NSEC2SEC;
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   tmo = 1LL * NSEC_PER_SEC;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
return t2 - t1 < tmo;
 }
diff --git a/util.h b/util.h
index 2bbde71..1cbd9b6 100644
--- a/util.h
+++ b/util.h
@@ -33,6 +33,8 @@
 #define MAX_PRINT_BYTES 16
 #define BIN_BUF_SIZE (MAX_PRINT_BYTES * 3 + 1)
 
+#define NSEC_PER_SEC 10LL
+
 /**
  * Table of human readable strings, one f

[Linuxptp-devel] [PATCH RESEND v1 5/5] phc_ctl: Handle errors returned by various clockadj helpers

2023-07-14 Thread Rahul Rameshbabu via Linuxptp-devel
Do not print success notices if clockadj operation fails using return
values provided by the clockadj helpers.

Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index 34d9e0c..e174189 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -232,9 +232,8 @@ static int do_adj(clockid_t clkid, int cmdc, char *cmdv[])
nsecs = (int64_t)(NSEC_PER_SEC * time_arg);
 
clockadj_init(clkid);
-   clockadj_step(clkid, nsecs);
-
-   pr_notice("adjusted clock by %lf seconds", time_arg);
+   if (!clockadj_step(clkid, nsecs))
+   pr_notice("adjusted clock by %lf seconds", time_arg);
 
/* adjustment always consumes one argument */
return 1;
@@ -271,8 +270,8 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
return -2;
}
 
-   clockadj_set_freq(clkid, ppb);
-   pr_notice("adjusted clock frequency offset to %lfppb", ppb);
+   if (!clockadj_set_freq(clkid, ppb))
+   pr_notice("adjusted clock frequency offset to %lfppb", ppb);
 
/* consumed one argument to determine the frequency adjustment value */
return 1;
@@ -308,10 +307,9 @@ static int do_phase(clockid_t clkid, int cmdc, char 
*cmdv[])
nsecs = (long)(NSEC_PER_SEC * offset_arg);
 
clockadj_init(clkid);
-   clockadj_set_phase(clkid, nsecs);
-
-   pr_notice("offset of %lf seconds provided to PHC phase control keyword",
- offset_arg);
+   if (!clockadj_set_phase(clkid, nsecs))
+   pr_notice("offset of %lf seconds provided to PHC phase control 
keyword",
+ offset_arg);
 
/* phase offset always consumes one argument */
return 1;
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH RESEND v1 0/5] General improvements for linuxptp focused around phase adjustment

2023-07-14 Thread Rahul Rameshbabu via Linuxptp-devel
The main focus of this submission is adding support for testing ADJ_OFFSET with
phc_ctl and querying the maximum supported ADJ_OFFSET adjustment that a device
is capable of. Some other minor cleanups are also included in the submission.

The patch that introduces support for querying the maximum offset supported by
ADJ_OFFSET depends on a kernel patch series (linked below) that is targeted for
kernel 6.5. Previously, sent this series out as an RFC to inquire feedback early
on. Have incorporated that feedback into this submission.

Link: https://sourceforge.net/p/linuxptp/mailman/message/37860292/
Link: https://sourceforge.net/p/linuxptp/mailman/message/37854603/
Link: 
https://lore.kernel.org/netdev/20230612211500.309075-1-rrameshb...@nvidia.com/

Rahul Rameshbabu (5):
  Rename NSEC2SEC as NSEC_PER_SEC and refactor to util.h
  phc_ctl: Add phase command to support ADJ_OFFSET
  phc_ctl: Add maximum offset capability
  phc_ctl: Use pr_notice instead of pr_err for displaying adjusted
frequency
  phc_ctl: Handle errors returned by various clockadj helpers

 missing.h  |  9 +++---
 phc_ctl.8  |  4 +++
 phc_ctl.c  | 77 ++
 port.c | 14 -
 port_private.h |  3 +-
 servo.c|  3 +-
 tc.c   |  6 ++--
 util.h |  2 ++
 8 files changed, 82 insertions(+), 36 deletions(-)

-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH RESEND v1 4/5] phc_ctl: Use pr_notice instead of pr_err for displaying adjusted frequency

2023-07-14 Thread Rahul Rameshbabu via Linuxptp-devel
Adjusted frequency value displayed by do_freq is not an error, but a
notication to the user. pr_err should not be used for providing notices
with information about successful operations.

Fixes: bdb6a35883b0 ("linuxptp: add phc_ctl program to help debug PHC devices")
Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index a814648..34d9e0c 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -249,7 +249,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
 
if (cmdc < 1 || name_is_a_command(cmdv[0])) {
ppb = clockadj_get_freq(clkid);
-   pr_err("clock frequency offset is %lfppb", ppb);
+   pr_notice("clock frequency offset is %lfppb", ppb);
 
/* no argument was used */
return 0;
@@ -272,7 +272,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
}
 
clockadj_set_freq(clkid, ppb);
-   pr_err("adjusted clock frequency offset to %lfppb", ppb);
+   pr_notice("adjusted clock frequency offset to %lfppb", ppb);
 
/* consumed one argument to determine the frequency adjustment value */
return 1;
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


Re: [Linuxptp-devel] [PATCH 0/5] General improvements for linuxptp focused around phase adjustment

2023-06-22 Thread Rahul Rameshbabu via Linuxptp-devel
On Thu, 22 Jun, 2023 12:11:05 +0200 Erez  wrote:
> On Wed, 21 Jun 2023 at 01:13, Rahul Rameshbabu  wrote:
>
>  Hi Erez,
>
>  On Wed, 21 Jun, 2023 00:33:28 +0200 Erez  wrote:
>  > Hi,
>  >
>  > You already submitted the patch seria.
>  > Has it changed?
>
>  Yes, I took feedback from the RFC (request for comments) I sent out and
>  applied it in this submission. In the git notes field in the first patch
>  of the series, I document the change made since the RFC. Since the first
>  submission was an RFC, I did not treat it as a formal submission, so I
>  did not consider it a v1 but rather a draft. I submitted as an RFC due
>  to pending kernel side changes.
>
>  > If so, please mark it with version 2. "git format-patch -v 2".
>
>  I agree with this if a formal v1 was submitted. However since my
>  previous submission was an RFC, is the practice still to increment the
>  official submission as v2?
>
> Rahul, all patches are for review.
> Do not make our life too much sophisticated.

Ack.

> Just add a version tag, please. Whether you add an RFC or not.
> If you really must , you can add a note in the cover letter for Richard.

Noted for future submissions. Thanks for the clarification.

Thanks,

Rahul


___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


Re: [Linuxptp-devel] [PATCH 0/5] General improvements for linuxptp focused around phase adjustment

2023-06-20 Thread Rahul Rameshbabu via Linuxptp-devel
Hi Erez,

On Wed, 21 Jun, 2023 00:33:28 +0200 Erez  wrote:
> Hi,
>
> You already submitted the patch seria.
> Has it changed?

Yes, I took feedback from the RFC (request for comments) I sent out and
applied it in this submission. In the git notes field in the first patch
of the series, I document the change made since the RFC. Since the first
submission was an RFC, I did not treat it as a formal submission, so I
did not consider it a v1 but rather a draft. I submitted as an RFC due
to pending kernel side changes.

> If so, please mark it with version 2. "git format-patch -v 2".

I agree with this if a formal v1 was submitted. However since my
previous submission was an RFC, is the practice still to increment the
official submission as v2?

> If not, why do you send it again?

Ignoring the fact that I applied changes based on feedback from the RFC
submission, isn't the normal practice to submit an RFC as a normal
submission to the mailing list to indicate readiness for applying the
patches onto the target?

> I think Richard wanted to close version 4 first.

Sure, that makes sense. I am hoping RFC patches are not considered for
merging into releases or the default branch of the project. At the time,
the needed kernel side changes were not merged into net-next of the
linux netdev tree.

Apologize in advance if we are implementing the practice of closing
submissions during release windows (similar to what net-next does in the
linux netdev tree). I did not see a mention of that on the mailing list.
Might have missed it.

Thanks,

Rahul Rameshbabu

>
> Erez
>
> On Tue, 20 Jun 2023 at 19:39, Rahul Rameshbabu via Linuxptp-devel 
>  wrote:
>
>  The main focus of this submission is adding support for testing ADJ_OFFSET 
> with
>  phc_ctl and querying the maximum supported ADJ_OFFSET adjustment that a 
> device
>  is capable of. Some other minor cleanups are also included in the submission.
>
>  That patch the introduces support for querying the maximum offset supported 
> by
>  ADJ_OFFSET depends on a kernel patch series (linked below) that is targeted 
> for
>  kernel 6.5. Previously, sent this series out as an RFC to inquire feedback 
> early
>  on. Have incorporated that feedback into this submission.
>
>  Link: https://sourceforge.net/p/linuxptp/mailman/message/37854603/
>  Link: 
> https://lore.kernel.org/netdev/20230612211500.309075-1-rrameshb...@nvidia.com/
>
>  Rahul Rameshbabu (5):
>Rename NSEC2SEC as NSEC_PER_SEC and refactor to util.h
>phc_ctl: Add phase command to support ADJ_OFFSET
>phc_ctl: Add maximum offset capability
>phc_ctl: Use pr_notice instead of pr_err for displaying adjusted
>  frequency
>phc_ctl: Handle errors returned by various clockadj helpers
>
>   missing.h  |  9 +++---
>   phc_ctl.8  |  4 +++
>   phc_ctl.c  | 77 ++
>   port.c | 14 -
>   port_private.h |  3 +-
>   servo.c|  3 +-
>   tc.c   |  6 ++--
>   util.h |  2 ++
>   8 files changed, 82 insertions(+), 36 deletions(-)
>
>  -- 
>  2.40.1
>
>  ___
>  Linuxptp-devel mailing list
>  Linuxptp-devel@lists.sourceforge.net
>  https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH 5/5] phc_ctl: Handle errors returned by various clockadj helpers

2023-06-20 Thread Rahul Rameshbabu via Linuxptp-devel
Do not print success notices if clockadj operation fails using return
values provided by the clockadj helpers.

Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index 34d9e0c..e174189 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -232,9 +232,8 @@ static int do_adj(clockid_t clkid, int cmdc, char *cmdv[])
nsecs = (int64_t)(NSEC_PER_SEC * time_arg);
 
clockadj_init(clkid);
-   clockadj_step(clkid, nsecs);
-
-   pr_notice("adjusted clock by %lf seconds", time_arg);
+   if (!clockadj_step(clkid, nsecs))
+   pr_notice("adjusted clock by %lf seconds", time_arg);
 
/* adjustment always consumes one argument */
return 1;
@@ -271,8 +270,8 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
return -2;
}
 
-   clockadj_set_freq(clkid, ppb);
-   pr_notice("adjusted clock frequency offset to %lfppb", ppb);
+   if (!clockadj_set_freq(clkid, ppb))
+   pr_notice("adjusted clock frequency offset to %lfppb", ppb);
 
/* consumed one argument to determine the frequency adjustment value */
return 1;
@@ -308,10 +307,9 @@ static int do_phase(clockid_t clkid, int cmdc, char 
*cmdv[])
nsecs = (long)(NSEC_PER_SEC * offset_arg);
 
clockadj_init(clkid);
-   clockadj_set_phase(clkid, nsecs);
-
-   pr_notice("offset of %lf seconds provided to PHC phase control keyword",
- offset_arg);
+   if (!clockadj_set_phase(clkid, nsecs))
+   pr_notice("offset of %lf seconds provided to PHC phase control 
keyword",
+ offset_arg);
 
/* phase offset always consumes one argument */
return 1;
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH 1/5] Rename NSEC2SEC as NSEC_PER_SEC and refactor to util.h

2023-06-20 Thread Rahul Rameshbabu via Linuxptp-devel
The name NSEC2SEC implies converting nanoseconds to seconds, but the value
used for the macro converts seconds to nanoseconds. NSEC_PER_SEC is the
accurate name for this macro. Move macro to common location in util.h.

Signed-off-by: Rahul Rameshbabu 
---

Notes:
Changes since RFC:

  * Refactored macro to live in util.h.
+ Noticed that float usage in phc_ctl.c does not need an explicit cast

 phc_ctl.c  |  8 +++-
 port.c | 14 +++---
 port_private.h |  3 +--
 servo.c|  3 +--
 tc.c   |  6 +++---
 util.h |  2 ++
 6 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index 92e597c..db89f01 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -48,8 +48,6 @@
 #include "util.h"
 #include "version.h"
 
-#define NSEC2SEC 10.0
-
 /* trap the alarm signal so that pause() will wake up on receipt */
 static void handle_alarm(int s)
 {
@@ -68,7 +66,7 @@ static void double_to_timespec(double d, struct timespec *ts)
 * value by our fractional component. This results in a correct
 * timespec from the double representing seconds.
 */
-   ts->tv_nsec = (long)(NSEC2SEC * fraction);
+   ts->tv_nsec = (long)(NSEC_PER_SEC * fraction);
 }
 
 static int install_handler(int signum, void(*handler)(int))
@@ -230,7 +228,7 @@ static int do_adj(clockid_t clkid, int cmdc, char *cmdv[])
return -2;
}
 
-   nsecs = (int64_t)(NSEC2SEC * time_arg);
+   nsecs = (int64_t)(NSEC_PER_SEC * time_arg);
 
clockadj_init(clkid);
clockadj_step(clkid, nsecs);
@@ -257,7 +255,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
}
 
/* parse the double ppb argument */
-   r = get_ranged_double(cmdv[0], &ppb, -NSEC2SEC, NSEC2SEC);
+   r = get_ranged_double(cmdv[0], &ppb, -NSEC_PER_SEC, NSEC_PER_SEC);
switch (r) {
case PARSED_OK:
break;
diff --git a/port.c b/port.c
index d551bef..b75f850 100644
--- a/port.c
+++ b/port.c
@@ -138,17 +138,17 @@ static int msg_current(struct ptp_message *m, struct 
timespec now)
 {
int64_t t1, t2, tmo;
 
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
if (m->header.logMessageInterval <= -31) {
tmo = 0;
} else if (m->header.logMessageInterval >= 31) {
tmo = INT64_MAX;
} else if (m->header.logMessageInterval < 0) {
-   tmo = 4LL * NSEC2SEC / (1 << -m->header.logMessageInterval);
+   tmo = 4LL * NSEC_PER_SEC / (1 << -m->header.logMessageInterval);
} else {
-   tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC2SEC;
+   tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC_PER_SEC;
}
 
return t2 - t1 < tmo;
@@ -340,10 +340,10 @@ static void fc_prune(struct foreign_clock *fc)
 
 static int delay_req_current(struct ptp_message *m, struct timespec now)
 {
-   int64_t t1, t2, tmo = 5 * NSEC2SEC;
+   int64_t t1, t2, tmo = 5 * NSEC_PER_SEC;
 
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
return t2 - t1 < tmo;
 }
diff --git a/port_private.h b/port_private.h
index 3b02d2f..d922a3d 100644
--- a/port_private.h
+++ b/port_private.h
@@ -28,8 +28,7 @@
 #include "msg.h"
 #include "power_profile.h"
 #include "tmv.h"
-
-#define NSEC2SEC 10LL
+#include "util.h"
 
 enum syfu_state {
SF_EMPTY,
diff --git a/servo.c b/servo.c
index daaa41c..a68c04a 100644
--- a/servo.c
+++ b/servo.c
@@ -26,11 +26,10 @@
 #include "pi.h"
 #include "refclock_sock.h"
 #include "servo_private.h"
+#include "util.h"
 
 #include "print.h"
 
-#define NSEC_PER_SEC 10
-
 struct servo *servo_create(struct config *cfg, enum servo_type type,
   double fadj, int max_ppb, int sw_ts)
 {
diff --git a/tc.c b/tc.c
index 1847041..7d1394c 100644
--- a/tc.c
+++ b/tc.c
@@ -256,9 +256,9 @@ static int tc_current(struct ptp_message *m, struct 
timespec now)
 {
int64_t t1, t2, tmo;
 
-   tmo = 1LL * NSEC2SEC;
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   tmo = 1LL * NSEC_PER_SEC;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
return t2 - t1 < tmo;
 }
diff --git a/util.h b/util.h
index 2bbde71..1cbd9b6 100644
--- a/util.h
+++ b/util.h
@@ -33,6 +33,8 @@
 #define MAX_PRINT_BYTES 16
 #define BIN_BUF_SIZE (MAX_PRINT_BYTES * 3 + 1)
 
+#define NSEC_PER_SEC 10LL
+
 /**
  * Table of human readable strings, one f

[Linuxptp-devel] [PATCH 0/5] General improvements for linuxptp focused around phase adjustment

2023-06-20 Thread Rahul Rameshbabu via Linuxptp-devel
The main focus of this submission is adding support for testing ADJ_OFFSET with
phc_ctl and querying the maximum supported ADJ_OFFSET adjustment that a device
is capable of. Some other minor cleanups are also included in the submission.

That patch the introduces support for querying the maximum offset supported by
ADJ_OFFSET depends on a kernel patch series (linked below) that is targeted for
kernel 6.5. Previously, sent this series out as an RFC to inquire feedback early
on. Have incorporated that feedback into this submission.

Link: https://sourceforge.net/p/linuxptp/mailman/message/37854603/
Link: 
https://lore.kernel.org/netdev/20230612211500.309075-1-rrameshb...@nvidia.com/

Rahul Rameshbabu (5):
  Rename NSEC2SEC as NSEC_PER_SEC and refactor to util.h
  phc_ctl: Add phase command to support ADJ_OFFSET
  phc_ctl: Add maximum offset capability
  phc_ctl: Use pr_notice instead of pr_err for displaying adjusted
frequency
  phc_ctl: Handle errors returned by various clockadj helpers

 missing.h  |  9 +++---
 phc_ctl.8  |  4 +++
 phc_ctl.c  | 77 ++
 port.c | 14 -
 port_private.h |  3 +-
 servo.c|  3 +-
 tc.c   |  6 ++--
 util.h |  2 ++
 8 files changed, 82 insertions(+), 36 deletions(-)

-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH 2/5] phc_ctl: Add phase command to support ADJ_OFFSET

2023-06-20 Thread Rahul Rameshbabu via Linuxptp-devel
Take double precision floating point representation of an offset value in
seconds. Feed this value to the PHC's phase control keyword.

Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.8 |  4 
 phc_ctl.c | 55 ---
 2 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/phc_ctl.8 b/phc_ctl.8
index 650e661..b10566e 100644
--- a/phc_ctl.8
+++ b/phc_ctl.8
@@ -62,6 +62,10 @@ Adjust the frequency of the PHC clock by the specified parts 
per billion. If no
 argument is provided, it will attempt to read the current frequency and report
 it.
 .TP
+.BI phase " seconds"
+Pass an amount in seconds to the PHC clock's phase control keyword. This
+argument is required.
+.TP
 .BI cmp
 Compare the PHC clock device to CLOCK_REALTIME, using the best method 
available.
 .TP
diff --git a/phc_ctl.c b/phc_ctl.c
index db89f01..c5430d8 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -106,13 +106,14 @@ static void usage(const char *progname)
" specify commands with arguments. Can specify multiple\n"
" commands to be executed in order. Seconds are read as\n"
" double precision floating point values.\n"
-   "  set  [seconds]  set PHC time (defaults to time on 
CLOCK_REALTIME)\n"
-   "  get get PHC time\n"
-   "  adjadjust PHC time by offset\n"
-   "  freq [ppb]  adjust PHC frequency (default returns 
current offset)\n"
-   "  cmp compare PHC offset to CLOCK_REALTIME\n"
-   "  capsdisplay device capabilities (default if no 
command given)\n"
-   "  wait   pause between commands\n"
+   "  set   [seconds]  set PHC time (defaults to time on 
CLOCK_REALTIME)\n"
+   "  get  get PHC time\n"
+   "  adj adjust PHC time by offset\n"
+   "  freq  [ppb]  adjust PHC frequency (default returns 
current offset)\n"
+   "  phase   pass offset to PHC phase control keyword\n"
+   "  cmp  compare PHC offset to CLOCK_REALTIME\n"
+   "  caps display device capabilities (default if no 
command given)\n"
+   "  waitpause between commands\n"
"\n",
progname);
 }
@@ -277,6 +278,45 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
return 1;
 }
 
+static int do_phase(clockid_t clkid, int cmdc, char *cmdv[])
+{
+   double offset_arg;
+   long nsecs;
+   enum parser_result r;
+
+   if (cmdc < 1 || name_is_a_command(cmdv[0])) {
+   pr_err("phase: missing required time argument");
+   return -2;
+   }
+
+   /* parse the double time offset argument */
+   r = get_ranged_double(cmdv[0], &offset_arg, -DBL_MAX, DBL_MAX);
+   switch (r) {
+   case PARSED_OK:
+   break;
+   case MALFORMED:
+   pr_err("phase: '%s' is not a valid double", cmdv[0]);
+   return -2;
+   case OUT_OF_RANGE:
+   pr_err("phase: '%s' is out of range.", cmdv[0]);
+   return -2;
+   default:
+   pr_err("phase: couldn't process '%s'", cmdv[0]);
+   return -2;
+   }
+
+   nsecs = (long)(NSEC_PER_SEC * offset_arg);
+
+   clockadj_init(clkid);
+   clockadj_set_phase(clkid, nsecs);
+
+   pr_notice("offset of %lf seconds provided to PHC phase control keyword",
+ offset_arg);
+
+   /* phase offset always consumes one argument */
+   return 1;
+}
+
 static int do_caps(clockid_t clkid, int cmdc, char *cmdv[])
 {
struct ptp_clock_caps caps;
@@ -399,6 +439,7 @@ static const struct cmd_t all_commands[] = {
{ "get", &do_get },
{ "adj", &do_adj },
{ "freq", &do_freq },
+   { "phase", &do_phase },
{ "cmp", &do_cmp },
{ "caps", &do_caps },
{ "wait", &do_wait },
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH 3/5] phc_ctl: Add maximum offset capability

2023-06-20 Thread Rahul Rameshbabu via Linuxptp-devel
Advertise the maximum offset that can be fed to the PHC phase control
keyword.

Signed-off-by: Rahul Rameshbabu 
---
 missing.h | 9 +
 phc_ctl.c | 4 
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/missing.h b/missing.h
index 79a87d4..165a297 100644
--- a/missing.h
+++ b/missing.h
@@ -98,9 +98,9 @@ enum {
 #define PTP_PEROUT_REQUEST2 PTP_PEROUT_REQUEST
 #endif
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(6,5,0)
 
-/* from upcoming Linux kernel version 5.8 */
+/* from upcoming Linux kernel version 6.5 */
 struct compat_ptp_clock_caps {
int max_adj;   /* Maximum frequency adjustment in parts per billon. */
int n_alarm;   /* Number of programmable alarms. */
@@ -112,12 +112,13 @@ struct compat_ptp_clock_caps {
int cross_timestamping;
/* Whether the clock supports adjust phase */
int adjust_phase;
-   int rsv[12];   /* Reserved for future use. */
+   int max_phase_adj;
+   int rsv[11];   /* Reserved for future use. */
 };
 
 #define ptp_clock_caps compat_ptp_clock_caps
 
-#endif /*LINUX_VERSION_CODE < 5.8*/
+#endif /*LINUX_VERSION_CODE < 6.5*/
 
 /*
  * Bits of the ptp_perout_request.flags field:
diff --git a/phc_ctl.c b/phc_ctl.c
index c5430d8..a814648 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -355,6 +355,10 @@ static int do_caps(clockid_t clkid, int cmdc, char *cmdv[])
"no information regarding"
#endif
);
+
+   if (caps.max_phase_adj)
+   pr_notice("  %d maximum offset adjustment (ns)\n", 
caps.max_phase_adj);
+
return 0;
 }
 
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH 4/5] phc_ctl: Use pr_notice instead of pr_err for displaying adjusted frequency

2023-06-20 Thread Rahul Rameshbabu via Linuxptp-devel
Adjusted frequency value displayed by do_freq is not an error, but a
notication to the user. pr_err should not be used for providing notices
with information about successful operations.

Fixes: bdb6a35883b0 ("linuxptp: add phc_ctl program to help debug PHC devices")
Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index a814648..34d9e0c 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -249,7 +249,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
 
if (cmdc < 1 || name_is_a_command(cmdv[0])) {
ppb = clockadj_get_freq(clkid);
-   pr_err("clock frequency offset is %lfppb", ppb);
+   pr_notice("clock frequency offset is %lfppb", ppb);
 
/* no argument was used */
return 0;
@@ -272,7 +272,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
}
 
clockadj_set_freq(clkid, ppb);
-   pr_err("adjusted clock frequency offset to %lfppb", ppb);
+   pr_notice("adjusted clock frequency offset to %lfppb", ppb);
 
/* consumed one argument to determine the frequency adjustment value */
return 1;
-- 
2.40.1



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


Re: [Linuxptp-devel] [PATCH RFC 1/5] Rename NSEC2SEC as NSEC_PER_SEC

2023-06-07 Thread Rahul Rameshbabu via Linuxptp-devel
On Wed, 07 Jun, 2023 18:04:08 +0200 Maciek Machnikowski 
 wrote:
> On 6/7/2023 17:03, Erez wrote:
>> 
>> 
>> On Wed, 7 Jun 2023 at 00:09, Rahul Rameshbabu via Linuxptp-devel
>> > <mailto:linuxptp-devel@lists.sourceforge.net>> wrote:
>> 
>> The name NSEC2SEC implies converting nanoseconds to seconds, but the
>> value
>> used for the macro converts seconds to nanoseconds. NSEC_PER_SEC is the
>> accurate name for this macro.
>> 
>> 
>> +1
>> 
>> And follow Linux kernel.
>> 
>> Erez 
>
> +1 as well, but with comments :)
>
> NSEC_PER_SEC is a uint64 in the kernel, this value is a float/double in
> the phc_ctl.
> Maybe NSEC_PER_SEC_F would work better? Or just add the cast in one
> place that requires float?

I am leaning more towards the cast.

>
> Also - wouldn't it be better to move it to the util.h and have it in one
> place?

I agree with this. Will do this in a follow-up submission which I can
either send as an independent submission not gated by the kernel patch
series mentioned or as a follow-up submission to this patch series. I
would prefer the latter just because I expect the kernel patch series to
converge soon.

-- Rahul Rameshbabu

>
> Thanks,
> Maciek
>
>> 
>> 
>> Signed-off-by: Rahul Rameshbabu > <mailto:rrameshb...@nvidia.com>>
>> ---
>>  phc_ctl.c      |  8 
>>  port.c         | 14 +++---
>>  port_private.h |  2 +-
>>  tc.c           |  6 +++---
>>  4 files changed, 15 insertions(+), 15 deletions(-)
>> 
>> diff --git a/phc_ctl.c b/phc_ctl.c
>> index 92e597c..50948e0 100644
>> --- a/phc_ctl.c
>> +++ b/phc_ctl.c
>> @@ -48,7 +48,7 @@
>>  #include "util.h"
>>  #include "version.h"
>> 
>> -#define NSEC2SEC 10.0
>> +#define NSEC_PER_SEC 10.0
>> 
>>  /* trap the alarm signal so that pause() will wake up on receipt */
>>  static void handle_alarm(int s)
>> @@ -68,7 +68,7 @@ static void double_to_timespec(double d, struct
>> timespec *ts)
>>          * value by our fractional component. This results in a correct
>>          * timespec from the double representing seconds.
>>          */
>> -       ts->tv_nsec = (long)(NSEC2SEC * fraction);
>> +       ts->tv_nsec = (long)(NSEC_PER_SEC * fraction);
>>  }
>> 
>>  static int install_handler(int signum, void(*handler)(int))
>> @@ -230,7 +230,7 @@ static int do_adj(clockid_t clkid, int cmdc,
>> char *cmdv[])
>>                 return -2;
>>         }
>> 
>> -       nsecs = (int64_t)(NSEC2SEC * time_arg);
>> +       nsecs = (int64_t)(NSEC_PER_SEC * time_arg);
>> 
>>         clockadj_init(clkid);
>>         clockadj_step(clkid, nsecs);
>> @@ -257,7 +257,7 @@ static int do_freq(clockid_t clkid, int cmdc,
>> char *cmdv[])
>>         }
>> 
>>         /* parse the double ppb argument */
>> -       r = get_ranged_double(cmdv[0], &ppb, -NSEC2SEC, NSEC2SEC);
>> +       r = get_ranged_double(cmdv[0], &ppb, -NSEC_PER_SEC,
>> NSEC_PER_SEC);
>>         switch (r) {
>>         case PARSED_OK:
>>                 break;
>> diff --git a/port.c b/port.c
>> index d551bef..b75f850 100644
>> --- a/port.c
>> +++ b/port.c
>> @@ -138,17 +138,17 @@ static int msg_current(struct ptp_message *m,
>> struct timespec now)
>>  {
>>         int64_t t1, t2, tmo;
>> 
>> -       t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
>> -       t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
>> +       t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
>> +       t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
>> 
>>         if (m->header.logMessageInterval <= -31) {
>>                 tmo = 0;
>>         } else if (m->header.logMessageInterval >= 31) {
>>                 tmo = INT64_MAX;
>>         } else if (m->header.logMessageInterval < 0) {
>> -               tmo = 4LL * NSEC2SEC / (1 <<
>> -m->header.logMessageInterval);
>> +               tmo = 4LL * NSEC_PER_SEC / (1 <<
>> -m->header.logMessageInterval);
>>         } else {
>> -               tmo = 4LL * (1 << m->header.logMessageInterval) *
>> NSEC2SEC;
>> +               tm

[Linuxptp-devel] [PATCH RFC 5/5] phc_ctl: Handle errors returned by various clockadj helpers

2023-06-06 Thread Rahul Rameshbabu via Linuxptp-devel
Do not print success notices if clockadj operation fails using return
values provided by the clockadj helpers.

Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.c | 16 +++-
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index 0db9352..70ee1e9 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -234,9 +234,8 @@ static int do_adj(clockid_t clkid, int cmdc, char *cmdv[])
nsecs = (int64_t)(NSEC_PER_SEC * time_arg);
 
clockadj_init(clkid);
-   clockadj_step(clkid, nsecs);
-
-   pr_notice("adjusted clock by %lf seconds", time_arg);
+   if (!clockadj_step(clkid, nsecs))
+   pr_notice("adjusted clock by %lf seconds", time_arg);
 
/* adjustment always consumes one argument */
return 1;
@@ -273,8 +272,8 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
return -2;
}
 
-   clockadj_set_freq(clkid, ppb);
-   pr_notice("adjusted clock frequency offset to %lfppb", ppb);
+   if (!clockadj_set_freq(clkid, ppb))
+   pr_notice("adjusted clock frequency offset to %lfppb", ppb);
 
/* consumed one argument to determine the frequency adjustment value */
return 1;
@@ -310,10 +309,9 @@ static int do_phase(clockid_t clkid, int cmdc, char 
*cmdv[])
nsecs = (long)(NSEC_PER_SEC * offset_arg);
 
clockadj_init(clkid);
-   clockadj_set_phase(clkid, nsecs);
-
-   pr_notice("offset of %lf seconds provided to PHC phase control keyword",
- offset_arg);
+   if (!clockadj_set_phase(clkid, nsecs))
+   pr_notice("offset of %lf seconds provided to PHC phase control 
keyword",
+ offset_arg);
 
/* phase offset always consumes one argument */
return 1;
-- 
2.38.5



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH RFC 2/5] phc_ctl: Add phase command to support ADJ_OFFSET

2023-06-06 Thread Rahul Rameshbabu via Linuxptp-devel
Take double precision floating point representation of an offset value in
seconds. Feed this value to the PHC's phase control keyword.

Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.8 |  4 
 phc_ctl.c | 55 ---
 2 files changed, 52 insertions(+), 7 deletions(-)

diff --git a/phc_ctl.8 b/phc_ctl.8
index 650e661..b10566e 100644
--- a/phc_ctl.8
+++ b/phc_ctl.8
@@ -62,6 +62,10 @@ Adjust the frequency of the PHC clock by the specified parts 
per billion. If no
 argument is provided, it will attempt to read the current frequency and report
 it.
 .TP
+.BI phase " seconds"
+Pass an amount in seconds to the PHC clock's phase control keyword. This
+argument is required.
+.TP
 .BI cmp
 Compare the PHC clock device to CLOCK_REALTIME, using the best method 
available.
 .TP
diff --git a/phc_ctl.c b/phc_ctl.c
index 50948e0..2575ca3 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -108,13 +108,14 @@ static void usage(const char *progname)
" specify commands with arguments. Can specify multiple\n"
" commands to be executed in order. Seconds are read as\n"
" double precision floating point values.\n"
-   "  set  [seconds]  set PHC time (defaults to time on 
CLOCK_REALTIME)\n"
-   "  get get PHC time\n"
-   "  adjadjust PHC time by offset\n"
-   "  freq [ppb]  adjust PHC frequency (default returns 
current offset)\n"
-   "  cmp compare PHC offset to CLOCK_REALTIME\n"
-   "  capsdisplay device capabilities (default if no 
command given)\n"
-   "  wait   pause between commands\n"
+   "  set   [seconds]  set PHC time (defaults to time on 
CLOCK_REALTIME)\n"
+   "  get  get PHC time\n"
+   "  adj adjust PHC time by offset\n"
+   "  freq  [ppb]  adjust PHC frequency (default returns 
current offset)\n"
+   "  phase   pass offset to PHC phase control keyword\n"
+   "  cmp  compare PHC offset to CLOCK_REALTIME\n"
+   "  caps display device capabilities (default if no 
command given)\n"
+   "  waitpause between commands\n"
"\n",
progname);
 }
@@ -279,6 +280,45 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
return 1;
 }
 
+static int do_phase(clockid_t clkid, int cmdc, char *cmdv[])
+{
+   double offset_arg;
+   long nsecs;
+   enum parser_result r;
+
+   if (cmdc < 1 || name_is_a_command(cmdv[0])) {
+   pr_err("phase: missing required time argument");
+   return -2;
+   }
+
+   /* parse the double time offset argument */
+   r = get_ranged_double(cmdv[0], &offset_arg, -DBL_MAX, DBL_MAX);
+   switch (r) {
+   case PARSED_OK:
+   break;
+   case MALFORMED:
+   pr_err("phase: '%s' is not a valid double", cmdv[0]);
+   return -2;
+   case OUT_OF_RANGE:
+   pr_err("phase: '%s' is out of range.", cmdv[0]);
+   return -2;
+   default:
+   pr_err("phase: couldn't process '%s'", cmdv[0]);
+   return -2;
+   }
+
+   nsecs = (long)(NSEC_PER_SEC * offset_arg);
+
+   clockadj_init(clkid);
+   clockadj_set_phase(clkid, nsecs);
+
+   pr_notice("offset of %lf seconds provided to PHC phase control keyword",
+ offset_arg);
+
+   /* phase offset always consumes one argument */
+   return 1;
+}
+
 static int do_caps(clockid_t clkid, int cmdc, char *cmdv[])
 {
struct ptp_clock_caps caps;
@@ -401,6 +441,7 @@ static const struct cmd_t all_commands[] = {
{ "get", &do_get },
{ "adj", &do_adj },
{ "freq", &do_freq },
+   { "phase", &do_phase },
{ "cmp", &do_cmp },
{ "caps", &do_caps },
{ "wait", &do_wait },
-- 
2.38.5



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH RFC 1/5] Rename NSEC2SEC as NSEC_PER_SEC

2023-06-06 Thread Rahul Rameshbabu via Linuxptp-devel
The name NSEC2SEC implies converting nanoseconds to seconds, but the value
used for the macro converts seconds to nanoseconds. NSEC_PER_SEC is the
accurate name for this macro.

Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.c  |  8 
 port.c | 14 +++---
 port_private.h |  2 +-
 tc.c   |  6 +++---
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index 92e597c..50948e0 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -48,7 +48,7 @@
 #include "util.h"
 #include "version.h"
 
-#define NSEC2SEC 10.0
+#define NSEC_PER_SEC 10.0
 
 /* trap the alarm signal so that pause() will wake up on receipt */
 static void handle_alarm(int s)
@@ -68,7 +68,7 @@ static void double_to_timespec(double d, struct timespec *ts)
 * value by our fractional component. This results in a correct
 * timespec from the double representing seconds.
 */
-   ts->tv_nsec = (long)(NSEC2SEC * fraction);
+   ts->tv_nsec = (long)(NSEC_PER_SEC * fraction);
 }
 
 static int install_handler(int signum, void(*handler)(int))
@@ -230,7 +230,7 @@ static int do_adj(clockid_t clkid, int cmdc, char *cmdv[])
return -2;
}
 
-   nsecs = (int64_t)(NSEC2SEC * time_arg);
+   nsecs = (int64_t)(NSEC_PER_SEC * time_arg);
 
clockadj_init(clkid);
clockadj_step(clkid, nsecs);
@@ -257,7 +257,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
}
 
/* parse the double ppb argument */
-   r = get_ranged_double(cmdv[0], &ppb, -NSEC2SEC, NSEC2SEC);
+   r = get_ranged_double(cmdv[0], &ppb, -NSEC_PER_SEC, NSEC_PER_SEC);
switch (r) {
case PARSED_OK:
break;
diff --git a/port.c b/port.c
index d551bef..b75f850 100644
--- a/port.c
+++ b/port.c
@@ -138,17 +138,17 @@ static int msg_current(struct ptp_message *m, struct 
timespec now)
 {
int64_t t1, t2, tmo;
 
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
if (m->header.logMessageInterval <= -31) {
tmo = 0;
} else if (m->header.logMessageInterval >= 31) {
tmo = INT64_MAX;
} else if (m->header.logMessageInterval < 0) {
-   tmo = 4LL * NSEC2SEC / (1 << -m->header.logMessageInterval);
+   tmo = 4LL * NSEC_PER_SEC / (1 << -m->header.logMessageInterval);
} else {
-   tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC2SEC;
+   tmo = 4LL * (1 << m->header.logMessageInterval) * NSEC_PER_SEC;
}
 
return t2 - t1 < tmo;
@@ -340,10 +340,10 @@ static void fc_prune(struct foreign_clock *fc)
 
 static int delay_req_current(struct ptp_message *m, struct timespec now)
 {
-   int64_t t1, t2, tmo = 5 * NSEC2SEC;
+   int64_t t1, t2, tmo = 5 * NSEC_PER_SEC;
 
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
return t2 - t1 < tmo;
 }
diff --git a/port_private.h b/port_private.h
index 3b02d2f..c5f55a4 100644
--- a/port_private.h
+++ b/port_private.h
@@ -29,7 +29,7 @@
 #include "power_profile.h"
 #include "tmv.h"
 
-#define NSEC2SEC 10LL
+#define NSEC_PER_SEC 10LL
 
 enum syfu_state {
SF_EMPTY,
diff --git a/tc.c b/tc.c
index 1847041..7d1394c 100644
--- a/tc.c
+++ b/tc.c
@@ -256,9 +256,9 @@ static int tc_current(struct ptp_message *m, struct 
timespec now)
 {
int64_t t1, t2, tmo;
 
-   tmo = 1LL * NSEC2SEC;
-   t1 = m->ts.host.tv_sec * NSEC2SEC + m->ts.host.tv_nsec;
-   t2 = now.tv_sec * NSEC2SEC + now.tv_nsec;
+   tmo = 1LL * NSEC_PER_SEC;
+   t1 = m->ts.host.tv_sec * NSEC_PER_SEC + m->ts.host.tv_nsec;
+   t2 = now.tv_sec * NSEC_PER_SEC + now.tv_nsec;
 
return t2 - t1 < tmo;
 }
-- 
2.38.5



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH RFC 4/5] phc_ctl: Use pr_notice instead of pr_err for displaying adjusted frequency

2023-06-06 Thread Rahul Rameshbabu via Linuxptp-devel
Adjusted frequency value displayed by do_freq is not an error, but a
notication to the user. pr_err should not be used for providing notices
with information about successful operations.

Fixes: bdb6a35883b0 ("linuxptp: add phc_ctl program to help debug PHC devices")
Signed-off-by: Rahul Rameshbabu 
---
 phc_ctl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/phc_ctl.c b/phc_ctl.c
index 8c55404..0db9352 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -251,7 +251,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
 
if (cmdc < 1 || name_is_a_command(cmdv[0])) {
ppb = clockadj_get_freq(clkid);
-   pr_err("clock frequency offset is %lfppb", ppb);
+   pr_notice("clock frequency offset is %lfppb", ppb);
 
/* no argument was used */
return 0;
@@ -274,7 +274,7 @@ static int do_freq(clockid_t clkid, int cmdc, char *cmdv[])
}
 
clockadj_set_freq(clkid, ppb);
-   pr_err("adjusted clock frequency offset to %lfppb", ppb);
+   pr_notice("adjusted clock frequency offset to %lfppb", ppb);
 
/* consumed one argument to determine the frequency adjustment value */
return 1;
-- 
2.38.5



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH RFC 0/5] General improvements for linuxptp focused around phase adjustment

2023-06-06 Thread Rahul Rameshbabu via Linuxptp-devel
The main focus of this submission is adding support for testing ADJ_OFFSET with
phc_ctl and querying the maximum supported ADJ_OFFSET adjustment that a device
is capable of. Some other minor cleanups are also included in the submission.

The patch the introduces support for querying the maximum offset supported by
ADJ_OFFSET depends on the following kernel patch series. Since the related patch
series in the kernel has not been accepted yet, submitting this patch as an RFC
for now.

Link: 
https://lore.kernel.org/netdev/20230523205440.326934-1-rrameshb...@nvidia.com/

Rahul Rameshbabu (5):
  Rename NSEC2SEC as NSEC_PER_SEC
  phc_ctl: Add phase command to support ADJ_OFFSET
  phc_ctl: Add maximum offset capability
  phc_ctl: Use pr_notice instead of pr_err for displaying adjusted
frequency
  phc_ctl: Handle errors returned by various clockadj helpers

 missing.h  |  9 +++---
 phc_ctl.8  |  4 +++
 phc_ctl.c  | 77 +++---
 port.c | 14 -
 port_private.h |  2 +-
 tc.c   |  6 ++--
 6 files changed, 80 insertions(+), 32 deletions(-)

-- 
2.38.5



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH RFC 3/5] phc_ctl: Add maximum offset capability

2023-06-06 Thread Rahul Rameshbabu via Linuxptp-devel
Advertise the maximum offset that can be fed to the PHC phase control
keyword.

Signed-off-by: Rahul Rameshbabu 
---
 missing.h | 9 +
 phc_ctl.c | 4 
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/missing.h b/missing.h
index 79a87d4..165a297 100644
--- a/missing.h
+++ b/missing.h
@@ -98,9 +98,9 @@ enum {
 #define PTP_PEROUT_REQUEST2 PTP_PEROUT_REQUEST
 #endif
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(5,8,0)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(6,5,0)
 
-/* from upcoming Linux kernel version 5.8 */
+/* from upcoming Linux kernel version 6.5 */
 struct compat_ptp_clock_caps {
int max_adj;   /* Maximum frequency adjustment in parts per billon. */
int n_alarm;   /* Number of programmable alarms. */
@@ -112,12 +112,13 @@ struct compat_ptp_clock_caps {
int cross_timestamping;
/* Whether the clock supports adjust phase */
int adjust_phase;
-   int rsv[12];   /* Reserved for future use. */
+   int max_phase_adj;
+   int rsv[11];   /* Reserved for future use. */
 };
 
 #define ptp_clock_caps compat_ptp_clock_caps
 
-#endif /*LINUX_VERSION_CODE < 5.8*/
+#endif /*LINUX_VERSION_CODE < 6.5*/
 
 /*
  * Bits of the ptp_perout_request.flags field:
diff --git a/phc_ctl.c b/phc_ctl.c
index 2575ca3..8c55404 100644
--- a/phc_ctl.c
+++ b/phc_ctl.c
@@ -357,6 +357,10 @@ static int do_caps(clockid_t clkid, int cmdc, char *cmdv[])
"no information regarding"
#endif
);
+
+   if (caps.max_phase_adj)
+   pr_notice("  %d maximum offset adjustment (ns)\n", 
caps.max_phase_adj);
+
return 0;
 }
 
-- 
2.38.5



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


Re: [Linuxptp-devel] [PATCH 0/2] Improve performance of the nullf servo by using write_phase_mode

2023-01-04 Thread Rahul Rameshbabu via Linuxptp-devel
Hi,

Any feedback on this patch would be appreciated. I believe this patch is useful
for improving the performance of the nullf servo, when write_phase_mode is
enabled. Provided below is demonstration of the performance benefits of the
patch. By transitioning to state s3 (SERVO_LOCKED_STABLE), we see improved
stability and a smaller drift below the 4000ns range.

Setup used in testing both cases


* A ptp clock device with ADJ_OFFSET supported

Key configuration settings used
---

  step_threshold 0.2
  first_step_threshold 0.1
  clock_servo   nullf
  servo_offset_threshold  10
  write_phase_mode1

Using the nullf servo without the patch
---

ptp4l[1901.436]: selected /dev/ptp1 as PTP clock
ptp4l[1901.437]: port 1 (eth2): INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[1901.437]: port 0 (/var/run/ptp4l): INITIALIZING to LISTENING on 
INIT_COMPLETE
ptp4l[1901.437]: port 0 (/var/run/ptp4lro): INITIALIZING to LISTENING on 
INIT_COMPLETE
ptp4l[1908.273]: port 1 (eth2): LISTENING to MASTER on 
ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES
ptp4l[1908.273]: selected local clock 0c42a1.fffe.d1d0d4 as best master
ptp4l[1908.273]: port 1 (eth2): assuming the grand master role
ptp4l[1914.276]: port 1 (eth2): new foreign master 0c42a1.fffe.d1d084-1
ptp4l[1918.276]: selected best master clock 0c42a1.fffe.d1d084
ptp4l[1918.276]: port 1 (eth2): MASTER to UNCALIBRATED on RS_SLAVE
ptp4l[1920.275]: master offset3880206 s1 freq  +0 path delay -1304
ptp4l[1921.276]: master offset -57638 s1 freq  +0 path delay -1304
ptp4l[1922.275]: master offset   7514 s0 freq  +0 path delay -1304
ptp4l[1923.275]: master offset  11241 s0 freq  +0 path delay -1091
ptp4l[1924.275]: master offset  15193 s0 freq  +0 path delay -1091
ptp4l[1925.275]: master offset  18924 s0 freq  +0 path delay  -878
ptp4l[1926.277]: master offset  22722 s1 freq  +0 path delay  -728
ptp4l[1927.276]: master offset   4434 s0 freq  +0 path delay  -728
ptp4l[1928.276]: master offset   8224 s0 freq  +0 path delay  -578
ptp4l[1929.276]: master offset  12468 s0 freq  +0 path delay  -878
ptp4l[1930.276]: master offset  16420 s0 freq  +0 path delay  -878
ptp4l[1931.277]: master offset  20360 s1 freq  +0 path delay  -878
ptp4l[1932.276]: master offset   4344 s0 freq  +0 path delay  -878
ptp4l[1933.276]: master offset   8423 s0 freq  +0 path delay -1009
ptp4l[1934.276]: master offset  12367 s0 freq  +0 path delay -1009
ptp4l[1935.276]: master offset  16487 s0 freq  +0 path delay -1189
ptp4l[1936.277]: master offset  20431 s1 freq  +0 path delay -1189
ptp4l[1937.276]: master offset   4347 s0 freq  +0 path delay -1189
ptp4l[1938.276]: master offset   8287 s0 freq  +0 path delay -1189
ptp4l[1939.276]: master offset  12215 s0 freq  +0 path delay -1189
ptp4l[1940.276]: master offset  16050 s0 freq  +0 path delay -1080
ptp4l[1941.276]: master offset  19716 s0 freq  +0 path delay  -806
ptp4l[1942.278]: master offset  23934 s1 freq  +0 path delay -1080
ptp4l[1943.276]: master offset   4502 s0 freq  +0 path delay -1080
ptp4l[1944.276]: master offset   8387 s0 freq  +0 path delay -1025
ptp4l[1945.276]: master offset  12327 s0 freq  +0 path delay -1025
ptp4l[1946.276]: master offset  16165 s0 freq  +0 path delay  -919
ptp4l[1947.278]: master offset  20093 s1 freq  +0 path delay  -919
ptp4l[1948.277]: master offset   4329 s0 freq  +0 path delay  -919
ptp4l[1949.277]: master offset   8371 s0 freq  +0 path delay -1025
ptp4l[1950.277]: master offset  12311 s0 freq  +0 path delay -1025
ptp4l[1951.277]: master offset  16247 s0 freq  +0 path delay -1025
ptp4l[1952.278]: master offset  20191 s1 freq  +0 path delay -1025
ptp4l[1953.277]: master offset   4323 s0 freq  +0 path delay -1025
ptp4l[1954.277]: master offset   8382 s0 freq  +0 path delay -1148
ptp4l[1955.277]: master offset  12322 s0 freq  +0 path delay -1148
ptp4l[1956.277]: master offset  16262 s0 freq  +0 path delay -1148
ptp4l[1957.278]: master offset  20194 s1 freq  +0 path delay -1148
ptp4l[1958.277]: master offset   4338 s0 freq  +0 path delay -1148
ptp4l[1959.277]: master offset   8180 s0 freq  +0 path delay -1050
ptp4l[1960.277]: master offset  12329 s0 freq  +0 path delay -1271

Using the nullf servo with the patch


ptp4l[11138.115]: selected /dev/ptp1 as PTP clock
ptp4l[11138.116]: port 1 (eth2): INITIALIZING to LISTENING on INIT_COMPLETE
ptp4l[11138.116]: port 0 (/var/run/ptp4l): INITIALIZING

[Linuxptp-devel] [PATCH 0/2] Improve performance of the nullf servo by using write_phase_mode

2022-12-20 Thread Rahul Rameshbabu via Linuxptp-devel
In the upstream linuxptp tree, the nullf servo has no way to transition to
the SERVO_LOCKED state except when the offset is zero. Transitioning to the
SERVO_LOCKED state is important for a servo that makes no frequency
adjustments because SERVO_LOCKED_STABLE is the only state that invokes
write_phase_mode, a performant way of adjusting the clock offset. The goal
of this change is to make it simple to configure entering the
SERVO_LOCKED_STABLE state by setting the offset_threshold when using the
nullf servo. In cases where the offset_threshold is not set but the
step_threshold is, the SERVO_LOCKED state is entered when the offset is
within the step_threshold.

Signed-off-by: Rahul Rameshbabu 

Rahul Rameshbabu (2):
  Improve efficiency of nullf servo synchronization
  Fix SERVO_JUMP docstring comment

 nullf.c   |  9 ++---
 phc2sys.8 | 12 ++--
 ptp4l.8   | 14 +++---
 servo.h   |  2 +-
 ts2phc.8  |  8 
 5 files changed, 24 insertions(+), 21 deletions(-)

-- 
2.36.2



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH 1/2] Improve efficiency of nullf servo synchronization

2022-12-20 Thread Rahul Rameshbabu via Linuxptp-devel
The nullf servo can now enter the SERVO_LOCKED_STABLE state by
transitioning first to the SERVO_LOCKED state when the offset is less than
the set value for offset_threshold. If offset_threshold is not set, the
SERVO_LOCKED state can be entered when the offset is less than or equal to
the set value for step_threshold.

Signed-off-by: Rahul Rameshbabu 
---
 nullf.c   |  9 ++---
 phc2sys.8 | 12 ++--
 ptp4l.8   | 14 +++---
 ts2phc.8  |  8 
 4 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/nullf.c b/nullf.c
index 9a40d07..8228636 100644
--- a/nullf.c
+++ b/nullf.c
@@ -38,14 +38,17 @@ static double nullf_sample(struct servo *servo, int64_t 
offset,
   uint64_t local_ts, double weight,
   enum servo_state *state)
 {
-   if (!offset) {
+   long long int abs_offset = llabs(offset);
+
+   if ((servo->offset_threshold && abs_offset < servo->offset_threshold) ||
+   (servo->step_threshold && servo->step_threshold >= abs_offset)) {
*state = SERVO_LOCKED;
return 0.0;
}
 
if ((servo->first_update && servo->first_step_threshold &&
-servo->first_step_threshold < llabs(offset)) ||
-   (servo->step_threshold && servo->step_threshold < llabs(offset))) {
+servo->first_step_threshold < abs_offset) ||
+   (servo->step_threshold && servo->step_threshold < abs_offset)) {
*state = SERVO_JUMP;
} else {
*state = SERVO_UNLOCKED;
diff --git a/phc2sys.8 b/phc2sys.8
index 6de2d25..b8f2224 100644
--- a/phc2sys.8
+++ b/phc2sys.8
@@ -362,12 +362,12 @@ Same as option
 
 .TP
 .B step_threshold
-Specifies the step threshold of the servo. It is the maximum offset that
-the servo corrects by changing the clock frequency instead of stepping
-the clock. The clock is stepped on start regardless of the option if the
-offset is larger than 20 microseconds (unless the -F option is used).
-It's  specified  in seconds. The value of 0.0 disables stepping after
-the start. The default is 0.0.
+Specifies the step threshold of the servo. It is the maximum offset that the
+servo corrects by changing the clock frequency (phase when using nullf servo)
+instead of stepping the clock. The clock is stepped on start regardless of the
+option if the offset is larger than 20 microseconds (unless the -F option is
+used). It's specified in seconds. The value of 0.0 disables stepping after the
+start. The default is 0.0.
 Same as option
 .B \-S
 (see above).
diff --git a/ptp4l.8 b/ptp4l.8
index 1268802..10316ad 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -591,18 +591,18 @@ the PI controller from the sync interval.
 The default is 0.3.
 .TP
 .B step_threshold
-The maximum offset the servo will correct by changing the clock
-frequency instead of stepping the clock. When set to 0.0, the servo will
-never step the clock except on start. It's specified in seconds.
+The maximum offset the servo will correct by changing the clock frequency 
(phase
+when using nullf servo) instead of stepping the clock. When set to 0.0, the
+servo will never step the clock except on start. It's specified in seconds.
 The default is 0.0.
 This option used to be called
 .BR pi_offset_const .
 .TP
 .B first_step_threshold
-The maximum offset the servo will correct by changing the clock
-frequency instead of stepping the clock. This is only applied on the first
-update. It's specified in seconds. When set to 0.0, the servo won't step
-the clock on start.
+The maximum offset the servo will correct by changing the clock frequency 
(phase
+when using nullf servo) instead of stepping the clock. This is only applied on
+the first update. It's specified in seconds. When set to 0.0, the servo won't
+step the clock on start.
 The default is 0.2 (20 microseconds).
 This option used to be called
 .BR pi_f_offset_const .
diff --git a/ts2phc.8 b/ts2phc.8
index ded6f9a..ef78c6b 100644
--- a/ts2phc.8
+++ b/ts2phc.8
@@ -119,10 +119,10 @@ command line option.
 
 .TP
 .B first_step_threshold
-The maximum offset, specified in seconds, that the servo will correct
-by changing the clock frequency instead of stepping the clock. This is
-only applied on the first update. When set to 0.0, the servo will not
-step the clock on start.
+The maximum offset, specified in seconds, that the servo will correct by
+changing the clock frequency (phase when using nullf servo) instead of stepping
+the clock. This is only applied on the first update. When set to 0.0, the servo
+will not step the clock on start.
 The default is 0.2 (20 microseconds).
 .TP
 .B free_running
-- 
2.36.2



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel


[Linuxptp-devel] [PATCH 2/2] Fix SERVO_JUMP docstring comment

2022-12-20 Thread Rahul Rameshbabu via Linuxptp-devel
Signed-off-by: Rahul Rameshbabu 
---
 servo.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/servo.h b/servo.h
index 6c30d33..6e42b0a 100644
--- a/servo.h
+++ b/servo.h
@@ -48,7 +48,7 @@ enum servo_state {
SERVO_UNLOCKED,
 
/**
-* The is ready to track and requests a clock jump to
+* The servo is ready to track and requests a clock jump to
 * immediately correct the estimated offset.
 */
SERVO_JUMP,
-- 
2.36.2



___
Linuxptp-devel mailing list
Linuxptp-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linuxptp-devel