Commit aa29b554 authored by Alessandro Rubini's avatar Alessandro Rubini

general: rename freq_ppm to freq_ppb (and fix arch-bare)

All adjustments are passed as part-per-billion, so after getting mad
in understanding what freq_ppm was, I renamed all of them to freq_ppb.

While making changes I verified this is what it is. Thus I fixed the comment
in ppsi.h (that was wrong by a factor of 64) and the adjustment code in
bare-time.c that made the same error (I admit I don't test arch-bare often).
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 03d47e6b
......@@ -15,8 +15,8 @@
*/
struct pp_sim_time_instance {
int64_t current_ns; // with nsecs it's enough for ~300 years
int64_t freq_ppm_real; // drift of the simulated hw clock
int64_t freq_ppm_servo; // drift applied from servo to correct the hw
int64_t freq_ppb_real; // drift of the simulated hw clock
int64_t freq_ppb_servo; // drift applied from servo to correct the hw
// Future parameters can be added
};
......
......@@ -16,7 +16,7 @@ static int f_ppm_real(int lineno, struct pp_globals *ppg,
/* master clock is supposed to be perfect. parameters about ppm are
* modifiable only for slave ppi */
ppi_slave = pp_sim_get_slave(ppg);
SIM_PPI_ARCH(ppi_slave)->time.freq_ppm_real = arg->i * 1000;
SIM_PPI_ARCH(ppi_slave)->time.freq_ppb_real = arg->i * 1000;
return 0;
}
......@@ -28,7 +28,7 @@ static int f_ppm_servo(int lineno, struct pp_globals *ppg,
/* master clock is supposed to be perfect. parameters about ppm are
* modifiable only for slave ppi */
ppi_slave = pp_sim_get_slave(ppg);
SIM_PPI_ARCH(ppi_slave)->time.freq_ppm_servo = arg->i * 1000;
SIM_PPI_ARCH(ppi_slave)->time.freq_ppb_servo = arg->i * 1000;
return 0;
}
......
......@@ -168,10 +168,10 @@ extern struct pp_network_operations unix_net_ops;
struct pp_time_operations {
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)(struct pp_instance *ppi, long offset_ns, long freq_ppm);
/* freq_ppb is parts per billion */
int (*adjust)(struct pp_instance *ppi, long offset_ns, long freq_ppb);
int (*adjust_offset)(struct pp_instance *ppi, long offset_ns);
int (*adjust_freq)(struct pp_instance *ppi, long freq_ppm);
int (*adjust_freq)(struct pp_instance *ppi, long freq_ppb);
int (*init_servo)(struct pp_instance *ppi);
/* calc_timeout cannot return zero */
unsigned long (*calc_timeout)(struct pp_instance *ppi, int millisec);
......
......@@ -37,7 +37,7 @@ static int bare_time_set(struct pp_instance *ppi, TimeInternal *t)
if (sys_adjtimex(&t) < 0)
pp_diag(ppi, time, 1, "Can't change TAI offset");
else
pp_diag(ppi, time, 1, "New TAI offset: %i\n",
pp_diag(ppi, time, 1, "New TAI offset: %i\n",
DSPRO(ppi)->currentUtcOffset);
return 0;
}
......@@ -56,7 +56,7 @@ static int bare_time_set(struct pp_instance *ppi, TimeInternal *t)
}
static int bare_time_adjust(struct pp_instance *ppi, long offset_ns,
long freq_ppm)
long freq_ppb)
{
struct bare_timex t;
int ret;
......@@ -64,17 +64,17 @@ static int bare_time_adjust(struct pp_instance *ppi, long offset_ns,
/* FIXME: handle MOD_FREQUENCY and MOD_OFFSET separately, and
* set t.modes only for the mode having non-zero parameter.
* See unix_time_adjust in arch-unix/unix-time.c */
if (freq_ppm > PP_ADJ_FREQ_MAX)
freq_ppm = PP_ADJ_FREQ_MAX;
if (freq_ppm < -PP_ADJ_FREQ_MAX)
freq_ppm = -PP_ADJ_FREQ_MAX;
if (freq_ppb > PP_ADJ_FREQ_MAX)
freq_ppb = PP_ADJ_FREQ_MAX;
if (freq_ppb < -PP_ADJ_FREQ_MAX)
freq_ppb = -PP_ADJ_FREQ_MAX;
t.offset = offset_ns / 1000;
t.freq = freq_ppm; /* was: "adj * ((1 << 16) / 1000)" */
t.freq = freq_ppb * ((1 << 16) / 1000);
t.modes = MOD_FREQUENCY | MOD_OFFSET;
ret = sys_adjtimex(&t);
pp_diag(ppi, time, 1, "%s: %li %li\n", __func__, offset_ns, freq_ppm);
pp_diag(ppi, time, 1, "%s: %li %li\n", __func__, offset_ns, freq_ppb);
return ret;
}
......@@ -83,9 +83,9 @@ int bare_time_adjust_offset(struct pp_instance *ppi, long offset_ns)
return bare_time_adjust(ppi, offset_ns, 0);
}
int bare_time_adjust_freq(struct pp_instance *ppi, long freq_ppm)
int bare_time_adjust_freq(struct pp_instance *ppi, long freq_ppb)
{
return bare_time_adjust(ppi, 0, freq_ppm);
return bare_time_adjust(ppi, 0, freq_ppb);
}
static unsigned long bare_calc_timeout(struct pp_instance *ppi, int millisec)
......
......@@ -23,8 +23,8 @@ int sim_fast_forward_ns(struct pp_globals *ppg, int64_t ff_ns)
for (i = 0; i < ppg->nlinks; i++) {
t_inst = &SIM_PPI_ARCH(INST(ppg, i))->time;
tmp = ff_ns + t_inst->freq_ppm_real * ff_ns / 1000 / 1000 / 1000;
t_inst->current_ns += tmp + (t_inst->freq_ppm_servo) *
tmp = ff_ns + t_inst->freq_ppb_real * ff_ns / 1000 / 1000 / 1000;
t_inst->current_ns += tmp + (t_inst->freq_ppb_servo) *
tmp / 1000 / 1000 / 1000;
}
pp_diag(0, ext, 2, "%s: %lli ns\n", __func__, (long long)ff_ns);
......@@ -76,26 +76,26 @@ static int sim_time_set(struct pp_instance *ppi, TimeInternal *t)
}
static int sim_time_adjust(struct pp_instance *ppi, long offset_ns,
long freq_ppm)
long freq_ppb)
{
if (freq_ppm) {
if (freq_ppm > PP_ADJ_FREQ_MAX)
freq_ppm = PP_ADJ_FREQ_MAX;
if (freq_ppm < -PP_ADJ_FREQ_MAX)
freq_ppm = -PP_ADJ_FREQ_MAX;
SIM_PPI_ARCH(ppi)->time.freq_ppm_servo = freq_ppm;
if (freq_ppb) {
if (freq_ppb > PP_ADJ_FREQ_MAX)
freq_ppb = PP_ADJ_FREQ_MAX;
if (freq_ppb < -PP_ADJ_FREQ_MAX)
freq_ppb = -PP_ADJ_FREQ_MAX;
SIM_PPI_ARCH(ppi)->time.freq_ppb_servo = freq_ppb;
}
if (offset_ns)
SIM_PPI_ARCH(ppi)->time.current_ns += offset_ns;
pp_diag(ppi, time, 1, "%s: %li %li\n", __func__, offset_ns, freq_ppm);
pp_diag(ppi, time, 1, "%s: %li %li\n", __func__, offset_ns, freq_ppb);
return 0;
}
static int sim_adjust_freq(struct pp_instance *ppi, long freq_ppm)
static int sim_adjust_freq(struct pp_instance *ppi, long freq_ppb)
{
return sim_time_adjust(ppi, 0, freq_ppm);
return sim_time_adjust(ppi, 0, freq_ppb);
}
static int sim_adjust_offset(struct pp_instance *ppi, long offset_ns)
......@@ -105,7 +105,7 @@ static int sim_adjust_offset(struct pp_instance *ppi, long offset_ns)
static inline int sim_init_servo(struct pp_instance *ppi)
{
return SIM_PPI_ARCH(ppi)->time.freq_ppm_real;
return SIM_PPI_ARCH(ppi)->time.freq_ppb_real;
}
static unsigned long sim_calc_timeout(struct pp_instance *ppi, int millisec)
......
......@@ -76,20 +76,20 @@ static int unix_time_init_servo(struct pp_instance *ppi)
return (t.freq >> 16) * 1000; /* positive or negative, not -1 */
}
static int unix_time_adjust(struct pp_instance *ppi, long offset_ns, long freq_ppm)
static int unix_time_adjust(struct pp_instance *ppi, long offset_ns, long freq_ppb)
{
struct timex t;
int ret;
t.modes = 0;
if (freq_ppm) {
if (freq_ppm > PP_ADJ_FREQ_MAX)
freq_ppm = PP_ADJ_FREQ_MAX;
if (freq_ppm < -PP_ADJ_FREQ_MAX)
freq_ppm = -PP_ADJ_FREQ_MAX;
if (freq_ppb) {
if (freq_ppb > PP_ADJ_FREQ_MAX)
freq_ppb = PP_ADJ_FREQ_MAX;
if (freq_ppb < -PP_ADJ_FREQ_MAX)
freq_ppb = -PP_ADJ_FREQ_MAX;
t.freq = freq_ppm * ((1 << 16) / 1000);
t.freq = freq_ppb * ((1 << 16) / 1000);
t.modes = MOD_FREQUENCY;
}
......@@ -99,7 +99,7 @@ static int unix_time_adjust(struct pp_instance *ppi, long offset_ns, long freq_p
}
ret = adjtimex(&t);
pp_diag(ppi, time, 1, "%s: %li %li\n", __func__, offset_ns, freq_ppm);
pp_diag(ppi, time, 1, "%s: %li %li\n", __func__, offset_ns, freq_ppb);
return ret;
}
......@@ -108,9 +108,9 @@ static int unix_time_adjust_offset(struct pp_instance *ppi, long offset_ns)
return unix_time_adjust(ppi, offset_ns, 0);
}
static int unix_time_adjust_freq(struct pp_instance *ppi, long freq_ppm)
static int unix_time_adjust_freq(struct pp_instance *ppi, long freq_ppb)
{
return unix_time_adjust(ppi, 0, freq_ppm);
return unix_time_adjust(ppi, 0, freq_ppb);
}
static unsigned long unix_calc_timeout(struct pp_instance *ppi, int millisec)
......
......@@ -51,11 +51,11 @@ static int wrpc_time_adjust_offset(struct pp_instance *ppi, long offset_ns)
}
static int wrpc_time_adjust(struct pp_instance *ppi, long offset_ns,
long freq_ppm)
long freq_ppb)
{
if (freq_ppm != 0)
pp_diag(ppi, time, 1, "Warning: %s: can not adjust freq_ppm %li\n",
__func__, freq_ppm);
if (freq_ppb != 0)
pp_diag(ppi, time, 1, "Warning: %s: can not adjust freq_ppb %li\n",
__func__, freq_ppb);
return wrpc_time_adjust_offset(ppi, offset_ns);
}
......
......@@ -222,11 +222,11 @@ static int wrs_time_adjust_offset(struct pp_instance *ppi, long offset_ns)
}
static int wrs_time_adjust(struct pp_instance *ppi, long offset_ns,
long freq_ppm)
long freq_ppb)
{
if (freq_ppm != 0)
pp_diag(ppi, time, 1, "Warning: %s: can not adjust freq_ppm %li\n",
__func__, freq_ppm);
if (freq_ppb != 0)
pp_diag(ppi, time, 1, "Warning: %s: can not adjust freq_ppb %li\n",
__func__, freq_ppb);
return wrs_time_adjust_offset(ppi, offset_ns);
}
......
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