Commit 9b27811e authored by Adam Wujek's avatar Adam Wujek 💬

userspace/libwr: (no tech change) rename get_monotonic_tics() to get_monotonic_us()

Make clear what kind of resolution get_monotonic_tics function returns (micro
seconds).
Signed-off-by: Adam Wujek's avatarAdam Wujek <adam.wujek@cern.ch>
parent 8be9b102
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
void shw_udelay_init(void); void shw_udelay_init(void);
void shw_udelay(uint32_t microseconds); void shw_udelay(uint32_t microseconds);
/* get monotonic number of useconds */ /* get monotonic number of useconds */
uint64_t get_monotonic_tics(void); uint64_t get_monotonic_us(void);
/* get monotonic number of seconds */ /* get monotonic number of seconds */
time_t get_monotonic_sec(void); time_t get_monotonic_sec(void);
......
...@@ -51,20 +51,20 @@ struct etherpacket { ...@@ -51,20 +51,20 @@ struct etherpacket {
static inline int tmo_init(struct wr_tmo * tmo, uint32_t milliseconds) static inline int tmo_init(struct wr_tmo * tmo, uint32_t milliseconds)
{ {
tmo->start_tics = get_monotonic_tics(); tmo->start_tics = get_monotonic_us();
tmo->timeout = (uint64_t) milliseconds *1000ULL; tmo->timeout = (uint64_t) milliseconds *1000ULL;
return 0; return 0;
} }
static inline int tmo_restart(struct wr_tmo * tmo) static inline int tmo_restart(struct wr_tmo * tmo)
{ {
tmo->start_tics = get_monotonic_tics(); tmo->start_tics = get_monotonic_us();
return 0; return 0;
} }
static inline int tmo_expired(struct wr_tmo * tmo) static inline int tmo_expired(struct wr_tmo * tmo)
{ {
return (get_monotonic_tics() - tmo->start_tics > tmo->timeout); return (get_monotonic_us() - tmo->start_tics > tmo->timeout);
} }
// cheks if x is inside range <min, max> // cheks if x is inside range <min, max>
......
...@@ -80,7 +80,7 @@ struct wrs_shm_head *wrs_shm_get(enum wrs_shm_name name_id, char *name, ...@@ -80,7 +80,7 @@ struct wrs_shm_head *wrs_shm_get(enum wrs_shm_name name_id, char *name,
if (!(flags & wrs_shm_locked)) if (!(flags & wrs_shm_locked))
return map; return map;
tv1 = get_monotonic_tics(); tv1 = get_monotonic_us();
while (1) { while (1) {
/* Releasing does not mean initial data is in place! */ /* Releasing does not mean initial data is in place! */
/* Read data with wrs_shm_seqbegin and /* Read data with wrs_shm_seqbegin and
...@@ -89,7 +89,7 @@ struct wrs_shm_head *wrs_shm_get(enum wrs_shm_name name_id, char *name, ...@@ -89,7 +89,7 @@ struct wrs_shm_head *wrs_shm_get(enum wrs_shm_name name_id, char *name,
return map; return map;
usleep(10 * 1000); usleep(10 * 1000);
tv2 = get_monotonic_tics(); tv2 = get_monotonic_us();
if (((tv2 - tv1) / 1000) < SHM_LOCK_TIMEOUT_MS) if (((tv2 - tv1) / 1000) < SHM_LOCK_TIMEOUT_MS)
continue; continue;
......
...@@ -14,10 +14,10 @@ void shw_udelay_init(void) ...@@ -14,10 +14,10 @@ void shw_udelay_init(void)
int j, cur, min = 0; int j, cur, min = 0;
uint64_t tv1, tv2; uint64_t tv1, tv2;
for (j = 0; j < 10; j++) { for (j = 0; j < 10; j++) {
tv1 = get_monotonic_tics(); tv1 = get_monotonic_us();
for (i = 0; i < 100*1000; i++) for (i = 0; i < 100*1000; i++)
; ;
tv2 = get_monotonic_tics(); tv2 = get_monotonic_us();
cur = tv2 - tv1; cur = tv2 - tv1;
/* keep minimum time, assuming we were scheduled-off less */ /* keep minimum time, assuming we were scheduled-off less */
if (!min || cur < min) if (!min || cur < min)
...@@ -53,7 +53,7 @@ void shw_udelay(uint32_t microseconds) ...@@ -53,7 +53,7 @@ void shw_udelay(uint32_t microseconds)
} }
/* get monotonic number of useconds */ /* get monotonic number of useconds */
uint64_t get_monotonic_tics(void) uint64_t get_monotonic_us(void)
{ {
struct timespec tv; struct timespec tv;
clock_gettime(CLOCK_MONOTONIC, &tv); clock_gettime(CLOCK_MONOTONIC, &tv);
......
...@@ -254,13 +254,13 @@ int main(int argc, char *argv[]) ...@@ -254,13 +254,13 @@ int main(int argc, char *argv[])
* includes some jitter. * includes some jitter.
*/ */
t1 = get_monotonic_tics(); t1 = get_monotonic_us();
for (;;) { for (;;) {
int delay_ms; int delay_ms;
hal_update_wripc(25 /* max ms delay */); hal_update_wripc(25 /* max ms delay */);
t2 = get_monotonic_tics(); t2 = get_monotonic_us();
delay_ms = (t2 - t1) / 1000; delay_ms = (t2 - t1) / 1000;
if (delay_ms < PORT_FAN_MS_PERIOD) if (delay_ms < PORT_FAN_MS_PERIOD)
continue; continue;
......
...@@ -15,23 +15,23 @@ typedef struct { ...@@ -15,23 +15,23 @@ typedef struct {
static inline int tmo_init(timeout_t * tmo, uint32_t milliseconds, int repeat) static inline int tmo_init(timeout_t * tmo, uint32_t milliseconds, int repeat)
{ {
tmo->repeat = repeat; tmo->repeat = repeat;
tmo->start_tics = get_monotonic_tics(); tmo->start_tics = get_monotonic_us();
tmo->timeout = (uint64_t) milliseconds *1000ULL; tmo->timeout = (uint64_t) milliseconds *1000ULL;
return 0; return 0;
} }
static inline int tmo_restart(timeout_t * tmo) static inline int tmo_restart(timeout_t * tmo)
{ {
tmo->start_tics = get_monotonic_tics(); tmo->start_tics = get_monotonic_us();
return 0; return 0;
} }
static inline int tmo_expired(timeout_t * tmo) static inline int tmo_expired(timeout_t * tmo)
{ {
int expired = (get_monotonic_tics() - tmo->start_tics > tmo->timeout); int expired = (get_monotonic_us() - tmo->start_tics > tmo->timeout);
if (tmo->repeat && expired) if (tmo->repeat && expired)
tmo->start_tics = get_monotonic_tics(); tmo->start_tics = get_monotonic_us();
return expired; return expired;
} }
......
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