Commit 11ee59c0 authored by Alessandro Rubini's avatar Alessandro Rubini

general: add ppi argument to all time operations

Unfortunately, we need to pass ppi to the time operations, so we
can have per-instance logging options. This is the second time I found
the need for such extra argument: the first time I worked it around, now
I surrender.

Actually, I don't find it unlikely for a multi-instance process to
spit a lot of diagnostics about timestamps. A developer may need to
filter messages according to who is tiemstamping/timing out etc.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 37167d27
......@@ -84,7 +84,7 @@ static int posix_recv_msg(struct pp_instance *ppi, int fd, void *pkt, int len,
* spike in the offset signal sent to the clock servo
*/
PP_VPRINTF("no receive time stamp, getting it in user space\n");
ppi->t_ops->get(t);
ppi->t_ops->get(ppi, t);
}
return ret;
}
......@@ -135,7 +135,7 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len,
memcpy(hdr->h_source, NP(ppi)->ch[PP_NP_GEN].addr, ETH_ALEN);
if (t)
ppi->t_ops->get(t);
ppi->t_ops->get(ppi, t);
return send(NP(ppi)->ch[PP_NP_GEN].fd, hdr, len, 0);
}
......@@ -147,7 +147,7 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len,
addr.sin_addr.s_addr = NP(ppi)->mcast_addr;
if (t)
ppi->t_ops->get(t);
ppi->t_ops->get(ppi, t);
return sendto(NP(ppi)->ch[chtype].fd, pkt, len, 0,
(struct sockaddr *)&addr, sizeof(struct sockaddr_in));
......
......@@ -16,7 +16,7 @@ static void clock_fatal_error(char *context)
exit(1);
}
static int posix_time_get(TimeInternal *t)
static int posix_time_get(struct pp_instance *ppi, TimeInternal *t)
{
struct timespec tp;
if (clock_gettime(CLOCK_REALTIME, &tp) < 0)
......@@ -28,7 +28,7 @@ static int posix_time_get(TimeInternal *t)
return 0;
}
int32_t posix_time_set(TimeInternal *t)
int32_t posix_time_set(struct pp_instance *ppi, TimeInternal *t)
{
struct timespec tp;
......@@ -41,7 +41,7 @@ int32_t posix_time_set(TimeInternal *t)
return 0;
}
int posix_time_adjust(long offset_ns, long freq_ppm)
int posix_time_adjust(struct pp_instance *ppi, long offset_ns, long freq_ppm)
{
struct timex t;
int ret;
......@@ -61,7 +61,7 @@ int posix_time_adjust(long offset_ns, long freq_ppm)
return ret;
}
static unsigned long posix_calc_timeout(int millisec)
static unsigned long posix_calc_timeout(struct pp_instance *ppi, int millisec)
{
struct timespec now;
uint64_t now_ms;
......
......@@ -21,7 +21,7 @@ static void pp_fsm_printf(struct pp_instance *ppi, char *fmt, ...)
/* temporarily set NOTIMELOG, as we'll print the time ourselves */
pp_global_flags |= PP_FLAG_NOTIMELOG;
ppi->t_ops->get(&t);
ppi->t_ops->get(ppi, &t);
pp_global_flags = oflags;
pp_printf("diag-fsm-1-%s: %09d.%03d: ", OPTS(ppi)->iface_name,
......
......@@ -132,11 +132,12 @@ struct pp_network_operations {
* Maybe this structure will need updating, to pass ppi as well
*/
struct pp_time_operations {
int (*get)(TimeInternal *t); /* returns error code */
int (*set)(TimeInternal *t); /* returns error code */
int (*get)(struct pp_instance *ppi, TimeInternal *t);
int (*set)(struct pp_instance *ppi, TimeInternal *t);
/* freq_ppm is "scaled-ppm" like the argument of adjtimex(2) */
int (*adjust)(long offset_ns, long freq_ppm);
unsigned long (*calc_timeout)(int millisec); /* cannot return zero */
int (*adjust)(struct pp_instance *ppi, long offset_ns, long freq_ppm);
/* calc_timeout cannot return zero */
unsigned long (*calc_timeout)(struct pp_instance *ppi, int millisec);
};
/* IF the configuration prevents jumps, this is the max jump (0.5ms) */
......@@ -157,7 +158,7 @@ struct pp_time_operations {
static inline void pp_timeout_set(struct pp_instance *ppi, int index,
int millisec)
{
ppi->timeouts[index] = ppi->t_ops->calc_timeout(millisec);
ppi->timeouts[index] = ppi->t_ops->calc_timeout(ppi, millisec);
}
extern void pp_timeout_rand(struct pp_instance *ppi, int index, int logval);
......@@ -172,7 +173,7 @@ extern void pp_timeout_log(struct pp_instance *ppi, int index);
static inline int pp_timeout(struct pp_instance *ppi, int index)
{
int ret = ppi->timeouts[index] &&
time_after_eq(ppi->t_ops->calc_timeout(0),
time_after_eq(ppi->t_ops->calc_timeout(ppi, 0),
ppi->timeouts[index]);
if (ret && pp_verbose_time)
......@@ -197,7 +198,7 @@ static inline int pp_ms_to_timeout(struct pp_instance *ppi, int index)
if (!ppi->timeouts[index]) /* not pending, nothing to wait for */
return 0;
ret = ppi->timeouts[index] - ppi->t_ops->calc_timeout(0);
ret = ppi->timeouts[index] - ppi->t_ops->calc_timeout(ppi, 0);
return ret <= 0 ? 0 : ret;
}
......
......@@ -11,7 +11,7 @@ static int bare_net_recv(struct pp_instance *ppi, void *pkt, int len,
TimeInternal *t)
{
if (t)
ppi->t_ops->get(t);
ppi->t_ops->get(ppi, t);
return sys_recv(NP(ppi)->ch[PP_NP_GEN].fd, pkt, len, 0);
}
......@@ -29,7 +29,7 @@ static int bare_net_send(struct pp_instance *ppi, void *pkt, int len,
memcpy(hdr->h_source, NP(ppi)->ch[PP_NP_GEN].addr, 6);
if (t)
ppi->t_ops->get(t);
ppi->t_ops->get(ppi, t);
return sys_send(NP(ppi)->ch[chtype].fd, pkt, len, 0);
}
......
......@@ -4,7 +4,7 @@
#include <ppsi/ppsi.h>
#include "bare-linux.h"
static int bare_time_get(TimeInternal *t)
static int bare_time_get(struct pp_instance *ppi, TimeInternal *t)
{
struct bare_timeval tv;
......@@ -19,7 +19,7 @@ static int bare_time_get(TimeInternal *t)
return 0;
}
static int bare_time_set(TimeInternal *t)
static int bare_time_set(struct pp_instance *ppi, TimeInternal *t)
{
struct bare_timeval tv;
......@@ -35,7 +35,7 @@ static int bare_time_set(TimeInternal *t)
return 0;
}
static int bare_time_adjust(long offset_ns, long freq_ppm)
static int bare_time_adjust(struct pp_instance *ppi, long offset_ns, long freq_ppm)
{
struct bare_timex t;
int ret;
......@@ -55,7 +55,7 @@ static int bare_time_adjust(long offset_ns, long freq_ppm)
return ret;
}
static unsigned long bare_calc_timeout(int millisec)
static unsigned long bare_calc_timeout(struct pp_instance *ppi, int millisec)
{
struct bare_timespec now;
uint64_t now_ms;
......
......@@ -462,7 +462,7 @@ int msg_issue_sync(struct pp_instance *ppi)
{
Timestamp orig_tstamp;
TimeInternal now;
ppi->t_ops->get(&now);
ppi->t_ops->get(ppi, &now);
from_TimeInternal(&now, &orig_tstamp);
msg_pack_sync(ppi, &orig_tstamp);
......@@ -487,7 +487,7 @@ int msg_issue_delay_req(struct pp_instance *ppi)
{
Timestamp orig_tstamp;
TimeInternal now;
ppi->t_ops->get(&now);
ppi->t_ops->get(ppi, &now);
from_TimeInternal(&now, &orig_tstamp);
msg_pack_delay_req(ppi, &orig_tstamp);
......
......@@ -18,7 +18,7 @@ void pp_init_clock(struct pp_instance *ppi)
/* level clock */
if (!OPTS(ppi)->no_adjust)
ppi->t_ops->adjust(0, 0);
ppi->t_ops->adjust(ppi, 0, 0);
}
void pp_update_delay(struct pp_instance *ppi, TimeInternal *correction_field)
......@@ -186,15 +186,15 @@ void pp_update_clock(struct pp_instance *ppi)
if (!OPTS(ppi)->no_adjust) {
if (!OPTS(ppi)->no_rst_clk) {
/* FIXME: use adjust instead of set? */
ppi->t_ops->get(&time_tmp);
ppi->t_ops->get(ppi, &time_tmp);
sub_TimeInternal(&time_tmp, &time_tmp,
&DSCUR(ppi)->offsetFromMaster);
ppi->t_ops->set(&time_tmp);
ppi->t_ops->set(ppi, &time_tmp);
pp_init_clock(ppi);
} else {
adj = DSCUR(ppi)->offsetFromMaster.nanoseconds
> 0 ? PP_ADJ_NS_MAX:-PP_ADJ_NS_MAX;
ppi->t_ops->adjust(-adj, 0);
ppi->t_ops->adjust(ppi, -adj, 0);
}
}
} else {
......@@ -217,7 +217,7 @@ void pp_update_clock(struct pp_instance *ppi)
/* apply controller output as a clock tick rate adjustment */
if (!OPTS(ppi)->no_adjust)
ppi->t_ops->adjust(0, -adj);
ppi->t_ops->adjust(ppi, 0, -adj);
dc++;
if (dc % 2 == 0) { /* Prints statistics every 8s */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment