Commit afa607df authored by Alessandro Rubini's avatar Alessandro Rubini

timeout: now calc_timeout() is part of the time_ops

By moving calc_timeout into the time functions, we simplify
the split-out of ./time-<arch> as a separate subdirectory.

As a side effect, calc_timeout disappears from arch-wrpc, and
wrpc-sw needs to be adapted to this commit, to provide it
inside its own time_ops.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 493dee1e
...@@ -11,7 +11,6 @@ LIBARCH := $A/libarch.a ...@@ -11,7 +11,6 @@ LIBARCH := $A/libarch.a
OBJ-libarch := $A/bare-startup.o \ OBJ-libarch := $A/bare-startup.o \
$A/main-loop.o \ $A/main-loop.o \
$A/bare-socket.o \ $A/bare-socket.o \
$A/bare-timeout.o \
$A/bare-io.o \ $A/bare-io.o \
$A/bare-time.o \ $A/bare-time.o \
$A/syscalls.o \ $A/syscalls.o \
......
...@@ -56,8 +56,24 @@ static int bare_time_adjust(long offset_ns, long freq_ppm) ...@@ -56,8 +56,24 @@ static int bare_time_adjust(long offset_ns, long freq_ppm)
return ret; return ret;
} }
static unsigned long bare_calc_timeout(int millisec)
{
struct bare_timespec now;
uint64_t now_ms;
unsigned long result;
if (!millisec)
millisec = 1;
sys_clock_gettime(CLOCK_MONOTONIC, &now);
now_ms = 1000LL * now.tv_sec + now.tv_nsec / 1000 / 1000;
result = now_ms + millisec;
return result ? result : 1; /* cannot return 0 */
}
struct pp_time_operations pp_t_ops = { struct pp_time_operations pp_t_ops = {
.get = bare_time_get, .get = bare_time_get,
.set = bare_time_set, .set = bare_time_set,
.adjust = bare_time_adjust, .adjust = bare_time_adjust,
.calc_timeout = bare_calc_timeout,
}; };
/*
* There is no such thing as a timer in ptp. We only have timeouts.
*
* A timeout is a point in time. We calculate; we can be earlier; we
* can be later. The only thing which is arch-specific is calculating.
*/
#include <ppsi/ppsi.h>
#include "bare-i386.h"
unsigned long pp_calc_timeout(int millisec)
{
struct bare_timespec now;
uint64_t now_ms;
unsigned long result;
if (!millisec)
millisec = 1;
sys_clock_gettime(CLOCK_MONOTONIC, &now);
now_ms = 1000LL * now.tv_sec + now.tv_nsec / 1000 / 1000;
result = now_ms + millisec;
return result ? result : 1; /* cannot return 0 */
}
...@@ -11,7 +11,6 @@ LIBARCH := $A/libarch.a ...@@ -11,7 +11,6 @@ LIBARCH := $A/libarch.a
OBJ-libarch := $A/bare-startup.o \ OBJ-libarch := $A/bare-startup.o \
$A/main-loop.o \ $A/main-loop.o \
$A/bare-socket.o \ $A/bare-socket.o \
$A/bare-timeout.o \
$A/bare-io.o \ $A/bare-io.o \
$A/bare-time.o \ $A/bare-time.o \
$A/syscall.o \ $A/syscall.o \
......
...@@ -56,8 +56,24 @@ static int bare_time_adjust(long offset_ns, long freq_ppm) ...@@ -56,8 +56,24 @@ static int bare_time_adjust(long offset_ns, long freq_ppm)
return ret; return ret;
} }
static unsigned long bare_calc_timeout(int millisec)
{
struct bare_timespec now;
uint64_t now_ms;
unsigned long result;
if (!millisec)
millisec = 1;
sys_clock_gettime(CLOCK_MONOTONIC, &now);
now_ms = 1000LL * now.tv_sec + now.tv_nsec / 1000 / 1000;
result = now_ms + millisec;
return result ? result : 1; /* cannot return 0 */
}
struct pp_time_operations pp_t_ops = { struct pp_time_operations pp_t_ops = {
.get = bare_time_get, .get = bare_time_get,
.set = bare_time_set, .set = bare_time_set,
.adjust = bare_time_adjust, .adjust = bare_time_adjust,
.calc_timeout = bare_calc_timeout,
}; };
/*
* There is no such thing as a timer in ptp. We only have timeouts.
*
* A timeout is a point in time. We calculate; we can be earlier; we
* can be later. The only thing which is arch-specific is calculating.
*/
#include <ppsi/ppsi.h>
#include "bare-x86-64.h"
unsigned long pp_calc_timeout(int millisec)
{
struct bare_timespec now;
uint64_t now_ms;
unsigned long result;
if (!millisec)
millisec = 1;
sys_clock_gettime(CLOCK_MONOTONIC, &now);
now_ms = 1000LL * now.tv_sec + now.tv_nsec / 1000 / 1000;
result = now_ms + millisec;
return result ? result : 1; /* cannot return 0 */
}
...@@ -13,7 +13,6 @@ OBJ-libarch := $A/posix-startup.o \ ...@@ -13,7 +13,6 @@ OBJ-libarch := $A/posix-startup.o \
$A/posix-socket.o \ $A/posix-socket.o \
$A/posix-io.o \ $A/posix-io.o \
$A/posix-time.o \ $A/posix-time.o \
$A/posix-timeout.o \
lib/cmdline.o \ lib/cmdline.o \
lib/libc-functions.o \ lib/libc-functions.o \
lib/div64.o lib/div64.o
......
...@@ -62,8 +62,24 @@ int posix_time_adjust(long offset_ns, long freq_ppm) ...@@ -62,8 +62,24 @@ int posix_time_adjust(long offset_ns, long freq_ppm)
return ret; return ret;
} }
static unsigned long posix_calc_timeout(int millisec)
{
struct timespec now;
uint64_t now_ms;
unsigned long result;
if (!millisec)
millisec = 1;
clock_gettime(CLOCK_MONOTONIC, &now);
now_ms = 1000LL * now.tv_sec + now.tv_nsec / 1000 / 1000;
result = now_ms + millisec;
return result ? result : 1; /* cannot return 0 */
}
struct pp_time_operations pp_t_ops = { struct pp_time_operations pp_t_ops = {
.get = posix_time_get, .get = posix_time_get,
.set = posix_time_set, .set = posix_time_set,
.adjust = posix_time_adjust, .adjust = posix_time_adjust,
.calc_timeout = posix_calc_timeout,
}; };
/*
* There is no such thing as a timer in ptp. We only have timeouts.
*
* A timeout is a point in time. We calculate; we can be earlier; we
* can be later. The only thing which is arch-specific is calculating.
*/
#include <ppsi/ppsi.h>
#include <time.h>
unsigned long pp_calc_timeout(int millisec)
{
struct timespec now;
uint64_t now_ms;
unsigned long result;
if (!millisec)
millisec = 1;
clock_gettime(CLOCK_MONOTONIC, &now);
now_ms = 1000LL * now.tv_sec + now.tv_nsec / 1000 / 1000;
result = now_ms + millisec;
return result ? result : 1; /* cannot return 0 */
}
...@@ -29,7 +29,6 @@ LIBS += -L$A -larch ...@@ -29,7 +29,6 @@ LIBS += -L$A -larch
OBJ-libarch := $A/wrpc-socket.o \ OBJ-libarch := $A/wrpc-socket.o \
$A/wrpc-io.o \ $A/wrpc-io.o \
$A/wrpc-timeout.o \
$A/wrpc-spll.o \ $A/wrpc-spll.o \
$A/wrpc-calibration.o \ $A/wrpc-calibration.o \
lib/div64.o lib/div64.o
......
/*
* There is no such thing as a timer in ptp. We only have timeouts.
*
* A timeout is a point in time. We calculate; we can be earlier; we
* can be later. The only thing which is arch-specific is calculating.
*/
#include <ppsi/ppsi.h>
#include <syscon.h>
unsigned long pp_calc_timeout(int millisec)
{
unsigned long result;
if (!millisec)
millisec = 1;
result = timer_get_tics() + millisec;
return result ? result : 1; /* cannot return 0 */
}
...@@ -286,6 +286,7 @@ struct pp_time_operations { ...@@ -286,6 +286,7 @@ struct pp_time_operations {
int (*set)(TimeInternal *t); /* returns error code */ int (*set)(TimeInternal *t); /* returns error code */
/* freq_ppm is "scaled-ppm" like the argument of adjtimex(2) */ /* freq_ppm is "scaled-ppm" like the argument of adjtimex(2) */
int (*adjust)(long offset_ns, long freq_ppm); int (*adjust)(long offset_ns, long freq_ppm);
unsigned long (*calc_timeout)(int millisec); /* cannot return zero */
}; };
/* IF the configuration prevents jumps, this is the max jump (0.5ms) */ /* IF the configuration prevents jumps, this is the max jump (0.5ms) */
...@@ -301,14 +302,14 @@ extern struct pp_time_operations pp_t_ops; ...@@ -301,14 +302,14 @@ extern struct pp_time_operations pp_t_ops;
* Timeouts. I renamed from "timer" to "timeout" to avoid * Timeouts. I renamed from "timer" to "timeout" to avoid
* misread/miswrite with the time operations above. A timeout, actually, * misread/miswrite with the time operations above. A timeout, actually,
* is just a number that must be compared with the current counter. * is just a number that must be compared with the current counter.
* So we don't need struct operations, as it is one function only. * So we don't need struct operations, as it is one function only,
* which is folded into the "pp_time_operations" above.
*/ */
extern unsigned long pp_calc_timeout(int millisec); /* cannot return zero */
static inline void pp_timeout_set(struct pp_instance *ppi, int index, static inline void pp_timeout_set(struct pp_instance *ppi, int index,
int millisec) int millisec)
{ {
ppi->timeouts[index] = pp_calc_timeout(millisec); ppi->timeouts[index] = pp_t_ops.calc_timeout(millisec);
} }
extern void pp_timeout_rand(struct pp_instance *ppi, int index, int logval); extern void pp_timeout_rand(struct pp_instance *ppi, int index, int logval);
...@@ -323,7 +324,7 @@ extern void pp_timeout_log(struct pp_instance *ppi, int index); ...@@ -323,7 +324,7 @@ extern void pp_timeout_log(struct pp_instance *ppi, int index);
static inline int pp_timeout(struct pp_instance *ppi, int index) static inline int pp_timeout(struct pp_instance *ppi, int index)
{ {
int ret = ppi->timeouts[index] && int ret = ppi->timeouts[index] &&
time_after_eq(pp_calc_timeout(0), ppi->timeouts[index]); time_after_eq(pp_t_ops.calc_timeout(0), ppi->timeouts[index]);
if (ret && pp_verbose_time) if (ret && pp_verbose_time)
pp_timeout_log(ppi, index); pp_timeout_log(ppi, index);
......
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