diff options
author | Thomas Haller <thaller@redhat.com> | 2019-12-13 16:54:30 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-12-13 16:54:40 +0100 |
commit | bd9b253540ae283af8f1e6651a7b2a095b1533d4 (patch) | |
tree | 24cdcf08684770db8eac4746fbb58c58989aafaf | |
parent | 13741aa952b57b6cfa60df42ed63a51b2fd59f06 (diff) | |
download | NetworkManager-bd9b253540ae283af8f1e6651a7b2a095b1533d4.tar.gz |
all: rename time related function to spell out nsec/usec/msec/sec
The abbreviations "ns" and "ms" seem not very clear to me. Spell them
out to nsec/msec. Also, in parts we already used the longer abbreviations,
so it wasn't consistent.
48 files changed, 286 insertions, 281 deletions
diff --git a/clients/cli/connections.c b/clients/cli/connections.c index 3297d0af62..25751c10dd 100644 --- a/clients/cli/connections.c +++ b/clients/cli/connections.c @@ -7927,7 +7927,7 @@ editor_menu_main (NmCli *nmc, NMConnection *connection, const char *connection_t connection_changed = FALSE; } - source = g_timeout_source_new (10 * NM_UTILS_MSEC_PER_SECOND); + source = g_timeout_source_new (10 * NM_UTILS_MSEC_PER_SEC); g_source_set_callback (source, editor_save_timeout, &timeout, NULL); g_source_attach (source, g_main_loop_get_context (loop)); diff --git a/clients/cli/devices.c b/clients/cli/devices.c index 58a11a3f2d..0a7339bc2c 100644 --- a/clients/cli/devices.c +++ b/clients/cli/devices.c @@ -3083,7 +3083,7 @@ do_device_wifi_list (NmCli *nmc, int argc, char **argv) } if (rescan == NULL || strcmp (rescan, "auto") == 0) { - rescan_cutoff = NM_MAX (nm_utils_get_timestamp_msec () - 30 * NM_UTILS_MSEC_PER_SECOND, 0); + rescan_cutoff = NM_MAX (nm_utils_get_timestamp_msec () - 30 * NM_UTILS_MSEC_PER_SEC, 0); } else if (strcmp (rescan, "no") == 0) { rescan_cutoff = 0; } else if (strcmp (rescan, "yes") == 0) { diff --git a/clients/cloud-setup/nm-cloud-setup-utils.c b/clients/cloud-setup/nm-cloud-setup-utils.c index 50a5989225..872ab44d3a 100644 --- a/clients/cloud-setup/nm-cloud-setup-utils.c +++ b/clients/cloud-setup/nm-cloud-setup-utils.c @@ -52,8 +52,8 @@ _nm_log_impl_cs (NMLogLevel level, ts = nm_utils_clock_gettime_ns (CLOCK_BOOTTIME); g_print ("[%"G_GINT64_FORMAT".%05"G_GINT64_FORMAT"] %s %s\n", - ts / NM_UTILS_NS_PER_SECOND, - (ts / (NM_UTILS_NS_PER_SECOND / 10000)) % 10000, + ts / NM_UTILS_NSEC_PER_SEC, + (ts / (NM_UTILS_NSEC_PER_SEC / 10000)) % 10000, level_str, msg); } @@ -305,7 +305,7 @@ _poll_done_cb (GObject *source, return; } - now_ms = nm_utils_get_monotonic_timestamp_ms (); + now_ms = nm_utils_get_monotonic_timestamp_msec (); if (poll_task_data->ratelimit_timeout_ms > 0) wait_ms = (poll_task_data->last_poll_start_ms + poll_task_data->ratelimit_timeout_ms) - now_ms; else @@ -328,7 +328,7 @@ _poll_start_cb (gpointer user_data) nm_clear_g_source_inst (&poll_task_data->source_next_poll); - poll_task_data->last_poll_start_ms = nm_utils_get_monotonic_timestamp_ms (); + poll_task_data->last_poll_start_ms = nm_utils_get_monotonic_timestamp_msec (); g_object_ref (poll_task_data->task); /* balanced by _poll_done_cb() */ diff --git a/libnm/nm-libnm-utils.c b/libnm/nm-libnm-utils.c index 662bc33fa5..f223545c78 100644 --- a/libnm/nm-libnm-utils.c +++ b/libnm/nm-libnm-utils.c @@ -93,8 +93,8 @@ _nml_dbus_log (NMLDBusLogLevel level, g_printerr ("libnm-dbus: %s[%"G_GINT64_FORMAT".%05"G_GINT64_FORMAT"] %s\n", prefix, - ts / NM_UTILS_NS_PER_SECOND, - (ts / (NM_UTILS_NS_PER_SECOND / 10000)) % 10000, + ts / NM_UTILS_NSEC_PER_SEC, + (ts / (NM_UTILS_NSEC_PER_SEC / 10000)) % 10000, msg); } diff --git a/libnm/tests/test-remote-settings-client.c b/libnm/tests/test-remote-settings-client.c index 8483eca838..429eecb235 100644 --- a/libnm/tests/test-remote-settings-client.c +++ b/libnm/tests/test-remote-settings-client.c @@ -454,12 +454,12 @@ test_save_hostname (void) nm_client_save_hostname_async (gl.client, "example.com", NULL, save_hostname_cb, &done); - until_ts = nm_utils_get_monotonic_timestamp_ms () + 5000; + until_ts = nm_utils_get_monotonic_timestamp_msec () + 5000; while (TRUE) { g_main_context_iteration (NULL, FALSE); if (done) break; - if (nm_utils_get_monotonic_timestamp_ms () >= until_ts) + if (nm_utils_get_monotonic_timestamp_msec () >= until_ts) g_assert_not_reached (); } diff --git a/shared/nm-glib-aux/nm-shared-utils.c b/shared/nm-glib-aux/nm-shared-utils.c index 8e1c8b5806..d7581f9a65 100644 --- a/shared/nm-glib-aux/nm-shared-utils.c +++ b/shared/nm-glib-aux/nm-shared-utils.c @@ -2223,7 +2223,7 @@ nm_utils_str_utf8safe_escape_take (char *str, NMUtilsStrUtf8SafeFlags flags) /* taken from systemd's fd_wait_for_event(). Note that the timeout * is here in nano-seconds, not micro-seconds. */ int -nm_utils_fd_wait_for_event (int fd, int event, gint64 timeout_ns) +nm_utils_fd_wait_for_event (int fd, int event, gint64 timeout_nsec) { struct pollfd pollfd = { .fd = fd, @@ -2232,11 +2232,11 @@ nm_utils_fd_wait_for_event (int fd, int event, gint64 timeout_ns) struct timespec ts, *pts; int r; - if (timeout_ns < 0) + if (timeout_nsec < 0) pts = NULL; else { - ts.tv_sec = (time_t) (timeout_ns / NM_UTILS_NS_PER_SECOND); - ts.tv_nsec = (long int) (timeout_ns % NM_UTILS_NS_PER_SECOND); + ts.tv_sec = (time_t) (timeout_nsec / NM_UTILS_NSEC_PER_SEC); + ts.tv_nsec = (long int) (timeout_nsec % NM_UTILS_NSEC_PER_SEC); pts = &ts; } @@ -3591,7 +3591,7 @@ nm_g_idle_source_new (int priority, } GSource * -nm_g_timeout_source_new (guint timeout_ms, +nm_g_timeout_source_new (guint timeout_msec, int priority, GSourceFunc func, gpointer user_data, @@ -3599,7 +3599,7 @@ nm_g_timeout_source_new (guint timeout_ms, { GSource *source; - source = g_timeout_source_new (timeout_ms); + source = g_timeout_source_new (timeout_msec); if (priority != G_PRIORITY_DEFAULT) g_source_set_priority (source, priority); g_source_set_callback (source, func, user_data, destroy_notify); diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h index 3bd1afaea3..0af58c4b6d 100644 --- a/shared/nm-glib-aux/nm-shared-utils.h +++ b/shared/nm-glib-aux/nm-shared-utils.h @@ -978,7 +978,7 @@ GSource *nm_g_idle_source_new (int priority, gpointer user_data, GDestroyNotify destroy_notify); -GSource *nm_g_timeout_source_new (guint timeout_ms, +GSource *nm_g_timeout_source_new (guint timeout_msec, int priority, GSourceFunc func, gpointer user_data, @@ -1182,14 +1182,19 @@ _nm_utils_strv_equal (char **strv1, char **strv2) /*****************************************************************************/ -#define NM_UTILS_NS_PER_SECOND ((gint64) 1000000000) -#define NM_UTILS_NS_PER_MSEC ((gint64) 1000000) -#define NM_UTILS_MSEC_PER_SECOND ((gint64) 1000) -#define NM_UTILS_NS_TO_MSEC_CEIL(nsec) (((nsec) + (NM_UTILS_NS_PER_MSEC - 1)) / NM_UTILS_NS_PER_MSEC) +#define NM_UTILS_NSEC_PER_SEC ((gint64) 1000000000) +#define NM_UTILS_NSEC_PER_MSEC ((gint64) 1000000) +#define NM_UTILS_MSEC_PER_SEC ((gint64) 1000) + +static inline gint64 +NM_UTILS_NSEC_TO_MSEC_CEIL (gint64 nsec) +{ + return (nsec + (NM_UTILS_NSEC_PER_MSEC - 1)) / NM_UTILS_NSEC_PER_MSEC; +} /*****************************************************************************/ -int nm_utils_fd_wait_for_event (int fd, int event, gint64 timeout_ns); +int nm_utils_fd_wait_for_event (int fd, int event, gint64 timeout_nsec); ssize_t nm_utils_fd_read_loop (int fd, void *buf, size_t nbytes, bool do_poll); int nm_utils_fd_read_loop_exact (int fd, void *buf, size_t nbytes, bool do_poll); diff --git a/shared/nm-glib-aux/nm-time-utils.c b/shared/nm-glib-aux/nm-time-utils.c index 20d663bc02..6afaf05aa3 100644 --- a/shared/nm-glib-aux/nm-time-utils.c +++ b/shared/nm-glib-aux/nm-time-utils.c @@ -40,19 +40,19 @@ _t_init_global_state (void) /* The only failure we tolerate is that CLOCK_BOOTTIME is not supported. * Other than that, we rely on kernel to not fail on this. */ g_assert (r == 0); - g_assert (tp.tv_nsec >= 0 && tp.tv_nsec < NM_UTILS_NS_PER_SECOND); + g_assert (tp.tv_nsec >= 0 && tp.tv_nsec < NM_UTILS_NSEC_PER_SEC); /* Calculate an offset for the time stamp. * * We always want positive values, because then we can initialize * a timestamp with 0 and be sure, that it will be less then any * value nm_utils_get_monotonic_timestamp_*() might return. - * For this to be true also for nm_utils_get_monotonic_timestamp_s() at + * For this to be true also for nm_utils_get_monotonic_timestamp_sec() at * early boot, we have to shift the timestamp to start counting at * least from 1 second onward. * * Another advantage of shifting is, that this way we make use of the whole 31 bit - * range of signed int, before the time stamp for nm_utils_get_monotonic_timestamp_s() + * range of signed int, before the time stamp for nm_utils_get_monotonic_timestamp_sec() * wraps (~68 years). **/ offset_sec = (- ((gint64) tp.tv_sec)) + 1; @@ -96,7 +96,7 @@ _t_init_global_state (void) _r = clock_gettime (_p2->clk_id, _tp); \ \ nm_assert (_r == 0); \ - nm_assert (_tp->tv_nsec >= 0 && _tp->tv_nsec < NM_UTILS_NS_PER_SECOND); \ + nm_assert (_tp->tv_nsec >= 0 && _tp->tv_nsec < NM_UTILS_NSEC_PER_SEC); \ \ _p2; \ }) @@ -107,7 +107,7 @@ _t_init_global_state (void) /*****************************************************************************/ /** - * nm_utils_get_monotonic_timestamp_ns: + * nm_utils_get_monotonic_timestamp_nsec: * * Returns: a monotonically increasing time stamp in nanoseconds, * starting at an unspecified offset. See clock_gettime(), %CLOCK_BOOTTIME. @@ -115,11 +115,11 @@ _t_init_global_state (void) * The returned value will start counting at an undefined point * in the past and will always be positive. * - * All the nm_utils_get_monotonic_timestamp_*s functions return the same + * All the nm_utils_get_monotonic_timestamp_*sec functions return the same * timestamp but in different scales (nsec, usec, msec, sec). **/ gint64 -nm_utils_get_monotonic_timestamp_ns (void) +nm_utils_get_monotonic_timestamp_nsec (void) { const GlobalState *p; struct timespec tp; @@ -130,12 +130,12 @@ nm_utils_get_monotonic_timestamp_ns (void) * integer, which makes it easier to calculate time differences (when * you want to subtract signed values). **/ - return (((gint64) tp.tv_sec) + p->offset_sec) * NM_UTILS_NS_PER_SECOND + + return (((gint64) tp.tv_sec) + p->offset_sec) * NM_UTILS_NSEC_PER_SEC + tp.tv_nsec; } /** - * nm_utils_get_monotonic_timestamp_us: + * nm_utils_get_monotonic_timestamp_usec: * * Returns: a monotonically increasing time stamp in microseconds, * starting at an unspecified offset. See clock_gettime(), %CLOCK_BOOTTIME. @@ -143,11 +143,11 @@ nm_utils_get_monotonic_timestamp_ns (void) * The returned value will start counting at an undefined point * in the past and will always be positive. * - * All the nm_utils_get_monotonic_timestamp_*s functions return the same + * All the nm_utils_get_monotonic_timestamp_*sec functions return the same * timestamp but in different scales (nsec, usec, msec, sec). **/ gint64 -nm_utils_get_monotonic_timestamp_us (void) +nm_utils_get_monotonic_timestamp_usec (void) { const GlobalState *p; struct timespec tp; @@ -159,11 +159,11 @@ nm_utils_get_monotonic_timestamp_us (void) * you want to subtract signed values). **/ return (((gint64) tp.tv_sec) + p->offset_sec) * ((gint64) G_USEC_PER_SEC) + - (tp.tv_nsec / (NM_UTILS_NS_PER_SECOND/G_USEC_PER_SEC)); + (tp.tv_nsec / (NM_UTILS_NSEC_PER_SEC/G_USEC_PER_SEC)); } /** - * nm_utils_get_monotonic_timestamp_ms: + * nm_utils_get_monotonic_timestamp_msec: * * Returns: a monotonically increasing time stamp in milliseconds, * starting at an unspecified offset. See clock_gettime(), %CLOCK_BOOTTIME. @@ -171,11 +171,11 @@ nm_utils_get_monotonic_timestamp_us (void) * The returned value will start counting at an undefined point * in the past and will always be positive. * - * All the nm_utils_get_monotonic_timestamp_*s functions return the same + * All the nm_utils_get_monotonic_timestamp_*sec functions return the same * timestamp but in different scales (nsec, usec, msec, sec). **/ gint64 -nm_utils_get_monotonic_timestamp_ms (void) +nm_utils_get_monotonic_timestamp_msec (void) { const GlobalState *p; struct timespec tp; @@ -187,23 +187,23 @@ nm_utils_get_monotonic_timestamp_ms (void) * you want to subtract signed values). **/ return (((gint64) tp.tv_sec) + p->offset_sec) * ((gint64) 1000) + - (tp.tv_nsec / (NM_UTILS_NS_PER_SECOND/1000)); + (tp.tv_nsec / (NM_UTILS_NSEC_PER_SEC/1000)); } /** - * nm_utils_get_monotonic_timestamp_s: + * nm_utils_get_monotonic_timestamp_sec: * - * Returns: nm_utils_get_monotonic_timestamp_ms() in seconds (throwing + * Returns: nm_utils_get_monotonic_timestamp_msec() in seconds (throwing * away sub second parts). The returned value will always be positive. * * This value wraps after roughly 68 years which should be fine for any * practical purpose. * - * All the nm_utils_get_monotonic_timestamp_*s functions return the same + * All the nm_utils_get_monotonic_timestamp_*sec functions return the same * timestamp but in different scales (nsec, usec, msec, sec). **/ gint32 -nm_utils_get_monotonic_timestamp_s (void) +nm_utils_get_monotonic_timestamp_sec (void) { const GlobalState *p; struct timespec tp; @@ -216,13 +216,13 @@ nm_utils_get_monotonic_timestamp_s (void) /** * nm_utils_monotonic_timestamp_as_boottime: * @timestamp: the monotonic-timestamp that should be converted into CLOCK_BOOTTIME. - * @timestamp_ns_per_tick: How many nanoseconds make one unit of @timestamp? E.g. if - * @timestamp is in unit seconds, pass %NM_UTILS_NS_PER_SECOND; if @timestamp is - * in nanoseconds, pass 1; if @timestamp is in milliseconds, pass %NM_UTILS_NS_PER_SECOND/1000. - * This must be a multiple of 10, and between 1 and %NM_UTILS_NS_PER_SECOND. + * @timestamp_nsec_per_tick: How many nanoseconds make one unit of @timestamp? E.g. if + * @timestamp is in unit seconds, pass %NM_UTILS_NSEC_PER_SEC; if @timestamp is + * in nanoseconds, pass 1; if @timestamp is in milliseconds, pass %NM_UTILS_NSEC_PER_SEC/1000. + * This must be a multiple of 10, and between 1 and %NM_UTILS_NSEC_PER_SEC. * * Returns: the monotonic-timestamp as CLOCK_BOOTTIME, as returned by clock_gettime(). - * The unit is the same as the passed in @timestamp based on @timestamp_ns_per_tick. + * The unit is the same as the passed in @timestamp based on @timestamp_nsec_per_tick. * E.g. if you passed @timestamp in as seconds, it will return boottime in seconds. * * Note that valid monotonic-timestamps are always positive numbers (counting roughly since @@ -234,16 +234,16 @@ nm_utils_get_monotonic_timestamp_s (void) * On older kernels that don't support CLOCK_BOOTTIME, the returned time is instead CLOCK_MONOTONIC. **/ gint64 -nm_utils_monotonic_timestamp_as_boottime (gint64 timestamp, gint64 timestamp_ns_per_tick) +nm_utils_monotonic_timestamp_as_boottime (gint64 timestamp, gint64 timestamp_nsec_per_tick) { const GlobalState *p; gint64 offset; - /* only support ns-per-tick being a multiple of 10. */ - g_return_val_if_fail (timestamp_ns_per_tick == 1 - || (timestamp_ns_per_tick > 0 && - timestamp_ns_per_tick <= NM_UTILS_NS_PER_SECOND && - timestamp_ns_per_tick % 10 == 0), + /* only support nsec-per-tick being a multiple of 10. */ + g_return_val_if_fail ( timestamp_nsec_per_tick == 1 + || (timestamp_nsec_per_tick > 0 && + timestamp_nsec_per_tick <= NM_UTILS_NSEC_PER_SEC && + timestamp_nsec_per_tick % 10 == 0), -1); /* if the caller didn't yet ever fetch a monotonic-timestamp, he cannot pass any meaningful @@ -255,7 +255,7 @@ nm_utils_monotonic_timestamp_as_boottime (gint64 timestamp, gint64 timestamp_ns_ nm_assert (p->offset_sec <= 0); /* calculate the offset of monotonic-timestamp to boottime. offset_s is <= 1. */ - offset = p->offset_sec * (NM_UTILS_NS_PER_SECOND / timestamp_ns_per_tick); + offset = p->offset_sec * (NM_UTILS_NSEC_PER_SEC / timestamp_nsec_per_tick); nm_assert (offset <= 0 && offset > G_MININT64); @@ -270,9 +270,9 @@ nm_utils_monotonic_timestamp_as_boottime (gint64 timestamp, gint64 timestamp_ns_ * @boottime: the timestamp from CLOCK_BOOTTIME (or CLOCK_MONOTONIC, if * kernel does not support CLOCK_BOOTTIME and monotonic timestamps are based * on CLOCK_MONOTONIC). - * @timestamp_ns_per_tick: the scale in which @boottime is. If @boottime is in + * @timestamp_nsec_per_tick: the scale in which @boottime is. If @boottime is in * nano seconds, this should be 1. If it is in milli seconds, this should be - * %NM_UTILS_NS_PER_SECOND/1000, etc. + * %NM_UTILS_NSEC_PER_SEC/1000, etc. * * Returns: the same timestamp in monotonic timestamp scale. * @@ -284,16 +284,16 @@ nm_utils_monotonic_timestamp_as_boottime (gint64 timestamp, gint64 timestamp_ns_ * This is the inverse of nm_utils_monotonic_timestamp_as_boottime(). */ gint64 -nm_utils_monotonic_timestamp_from_boottime (guint64 boottime, gint64 timestamp_ns_per_tick) +nm_utils_monotonic_timestamp_from_boottime (guint64 boottime, gint64 timestamp_nsec_per_tick) { const GlobalState *p; gint64 offset; - /* only support ns-per-tick being a multiple of 10. */ - g_return_val_if_fail (timestamp_ns_per_tick == 1 - || (timestamp_ns_per_tick > 0 && - timestamp_ns_per_tick <= NM_UTILS_NS_PER_SECOND && - timestamp_ns_per_tick % 10 == 0), + /* only support nsec-per-tick being a multiple of 10. */ + g_return_val_if_fail ( timestamp_nsec_per_tick == 1 + || (timestamp_nsec_per_tick > 0 && + timestamp_nsec_per_tick <= NM_UTILS_NSEC_PER_SEC && + timestamp_nsec_per_tick % 10 == 0), -1); p = _t_get_global_state (); @@ -301,7 +301,7 @@ nm_utils_monotonic_timestamp_from_boottime (guint64 boottime, gint64 timestamp_n nm_assert (p->offset_sec <= 0); /* calculate the offset of monotonic-timestamp to boottime. offset_s is <= 1. */ - offset = p->offset_sec * (NM_UTILS_NS_PER_SECOND / timestamp_ns_per_tick); + offset = p->offset_sec * (NM_UTILS_NSEC_PER_SEC / timestamp_nsec_per_tick); nm_assert (offset <= 0 && offset > G_MININT64); diff --git a/shared/nm-glib-aux/nm-time-utils.h b/shared/nm-glib-aux/nm-time-utils.h index 8bf41b96a1..fe48be0aed 100644 --- a/shared/nm-glib-aux/nm-time-utils.h +++ b/shared/nm-glib-aux/nm-time-utils.h @@ -11,7 +11,7 @@ static inline gint64 nm_utils_timespec_to_ns (const struct timespec *ts) { - return (((gint64) ts->tv_sec) * ((gint64) NM_UTILS_NS_PER_SECOND)) + return (((gint64) ts->tv_sec) * ((gint64) NM_UTILS_NSEC_PER_SEC)) + ((gint64) ts->tv_nsec); } @@ -19,21 +19,21 @@ static inline gint64 nm_utils_timespec_to_ms (const struct timespec *ts) { return (((gint64) ts->tv_sec) * ((gint64) 1000)) - + (((gint64) ts->tv_nsec) / ((gint64) NM_UTILS_NS_PER_SECOND / 1000)); + + (((gint64) ts->tv_nsec) / ((gint64) NM_UTILS_NSEC_PER_SEC / 1000)); } -gint64 nm_utils_get_monotonic_timestamp_ns (void); -gint64 nm_utils_get_monotonic_timestamp_us (void); -gint64 nm_utils_get_monotonic_timestamp_ms (void); -gint32 nm_utils_get_monotonic_timestamp_s (void); -gint64 nm_utils_monotonic_timestamp_as_boottime (gint64 timestamp, gint64 timestamp_ticks_per_ns); -gint64 nm_utils_monotonic_timestamp_from_boottime (guint64 boottime, gint64 timestamp_ns_per_tick); +gint64 nm_utils_get_monotonic_timestamp_nsec (void); +gint64 nm_utils_get_monotonic_timestamp_usec (void); +gint64 nm_utils_get_monotonic_timestamp_msec (void); +gint32 nm_utils_get_monotonic_timestamp_sec (void); +gint64 nm_utils_monotonic_timestamp_as_boottime (gint64 timestamp, gint64 timestamp_ticks_per_nsec); +gint64 nm_utils_monotonic_timestamp_from_boottime (guint64 boottime, gint64 timestamp_nsec_per_tick); static inline gint64 nm_utils_get_monotonic_timestamp_ns_cached (gint64 *cache_now) { return (*cache_now) - ?: (*cache_now = nm_utils_get_monotonic_timestamp_ns ()); + ?: (*cache_now = nm_utils_get_monotonic_timestamp_nsec ()); } gint64 nm_utils_clock_gettime_ns (clockid_t clockid); diff --git a/shared/nm-glib-aux/tests/test-shared-general.c b/shared/nm-glib-aux/tests/test-shared-general.c index 34da19b32f..a6721c362d 100644 --- a/shared/nm-glib-aux/tests/test-shared-general.c +++ b/shared/nm-glib-aux/tests/test-shared-general.c @@ -44,7 +44,7 @@ test_gpid (void) static void test_monotonic_timestamp (void) { - g_assert (nm_utils_get_monotonic_timestamp_s () > 0); + g_assert (nm_utils_get_monotonic_timestamp_sec () > 0); } /*****************************************************************************/ diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h index f0ea11790d..fd90c3b5e7 100644 --- a/shared/nm-utils/nm-test-utils.h +++ b/shared/nm-utils/nm-test-utils.h @@ -622,7 +622,7 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_ #ifdef __NETWORKMANAGER_UTILS_H__ /* ensure that monotonic timestamp is called (because it initially logs a line) */ - nm_utils_get_monotonic_timestamp_s (); + nm_utils_get_monotonic_timestamp_sec (); #endif #ifdef NM_UTILS_H @@ -978,13 +978,13 @@ _nmtst_main_loop_run_timeout (gpointer user_data) } static inline gboolean -nmtst_main_loop_run (GMainLoop *loop, guint timeout_ms) +nmtst_main_loop_run (GMainLoop *loop, guint timeout_msec) { nm_auto_unref_gsource GSource *source = NULL; GMainLoop *loopx = loop; - if (timeout_ms > 0) { - source = g_timeout_source_new (timeout_ms); + if (timeout_msec > 0) { + source = g_timeout_source_new (timeout_msec); g_source_set_callback (source, _nmtst_main_loop_run_timeout, &loopx, NULL); g_source_attach (source, g_main_loop_get_context (loop)); } @@ -1020,13 +1020,13 @@ _nmtst_main_context_iterate_until_timeout (gpointer user_data) return G_SOURCE_CONTINUE; } -#define nmtst_main_context_iterate_until(context, timeout_ms, condition) \ +#define nmtst_main_context_iterate_until(context, timeout_msec, condition) \ G_STMT_START { \ nm_auto_destroy_and_unref_gsource GSource *_source = NULL; \ GMainContext *_context = (context); \ gboolean _had_timeout = FALSE; \ \ - _source = g_timeout_source_new (timeout_ms); \ + _source = g_timeout_source_new (timeout_msec); \ g_source_set_callback (_source, _nmtst_main_context_iterate_until_timeout, &_had_timeout, NULL); \ g_source_attach (_source, _context); \ \ diff --git a/src/devices/bluetooth/nm-bluez5-dun.c b/src/devices/bluetooth/nm-bluez5-dun.c index 72582fae99..063c3db575 100644 --- a/src/devices/bluetooth/nm-bluez5-dun.c +++ b/src/devices/bluetooth/nm-bluez5-dun.c @@ -145,7 +145,7 @@ _connect_open_tty_retry_cb (gpointer user_data) if (r >= 0) return G_SOURCE_REMOVE; - if (nm_utils_get_monotonic_timestamp_ns () > context->cdat->connect_open_tty_started_at + (30 * 100 * NM_UTILS_NS_PER_MSEC)) { + if (nm_utils_get_monotonic_timestamp_nsec () > context->cdat->connect_open_tty_started_at + (30 * 100 * NM_UTILS_NSEC_PER_MSEC)) { gs_free_error GError *error = NULL; context->cdat->source_id = 0; @@ -179,7 +179,7 @@ _connect_open_tty (NMBluez5DunContext *context) context->rfcomm_tty_no, nm_strerror_native (errsv), errsv); - context->cdat->connect_open_tty_started_at = nm_utils_get_monotonic_timestamp_ns (); + context->cdat->connect_open_tty_started_at = nm_utils_get_monotonic_timestamp_nsec (); context->cdat->source_id = g_timeout_add (100, _connect_open_tty_retry_cb, context); diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 6b80c4ed49..c7c42eaa27 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -920,7 +920,7 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason) * otherwise after restart the device won't work for the first seconds. */ if (priv->last_pppoe_time != 0) { - gint32 delay = nm_utils_get_monotonic_timestamp_s () - priv->last_pppoe_time; + gint32 delay = nm_utils_get_monotonic_timestamp_sec () - priv->last_pppoe_time; if ( delay < PPPOE_RECONNECT_DELAY && nm_device_get_applied_setting (device, NM_TYPE_SETTING_PPPOE)) { @@ -1468,7 +1468,7 @@ deactivate (NMDevice *device) /* Set last PPPoE connection time */ if (nm_device_get_applied_setting (device, NM_TYPE_SETTING_PPPOE)) - priv->last_pppoe_time = nm_utils_get_monotonic_timestamp_s (); + priv->last_pppoe_time = nm_utils_get_monotonic_timestamp_sec (); } static gboolean diff --git a/src/devices/nm-device-wireguard.c b/src/devices/nm-device-wireguard.c index c916fa4658..a5fce0a604 100644 --- a/src/devices/nm-device-wireguard.c +++ b/src/devices/nm-device-wireguard.c @@ -51,7 +51,7 @@ G_STATIC_ASSERT (NM_WIREGUARD_SYMMETRIC_KEY_LEN == NMP_WIREGUARD_SYMMETRIC_KEY_L /*****************************************************************************/ -#define LINK_CONFIG_RATE_LIMIT_NSEC (50 * NM_UTILS_NS_PER_MSEC) +#define LINK_CONFIG_RATE_LIMIT_NSEC (50 * NM_UTILS_NSEC_PER_MSEC) /* a special @next_try_at_nsec timestamp indicating that we should try again as soon as possible. */ #define NEXT_TRY_AT_NSEC_ASAP ((gint64) G_MAXINT64) @@ -80,7 +80,7 @@ typedef struct { NMSockAddrUnion sockaddr; - /* the timestamp (in nm_utils_get_monotonic_timestamp_ns() scale) when we want + /* the timestamp (in nm_utils_get_monotonic_timestamp_nsec() scale) when we want * to retry resolving the endpoint (again). * * It may be set to %NEXT_TRY_AT_NSEC_ASAP to indicate to re-resolve as soon as possible. @@ -555,7 +555,7 @@ _peers_resolve_retry_timeout (gpointer user_data) _LOGT (LOGD_DEVICE, "wireguard-peers: rechecking peer endpoints..."); - now = nm_utils_get_monotonic_timestamp_ns (); + now = nm_utils_get_monotonic_timestamp_nsec (); next = G_MAXINT64; c_list_for_each_entry (peer_data, &priv->lst_peers_head, lst_peers) { if (peer_data->ep_resolv.next_try_at_nsec <= 0) @@ -606,11 +606,11 @@ _peers_resolve_retry_reschedule (NMDeviceWireGuard *self, return; } - now = nm_utils_get_monotonic_timestamp_ns (); + now = nm_utils_get_monotonic_timestamp_nsec (); /* schedule at most one day ahead. No problem if we expire earlier * than expected. Also, rate-limit to 500 msec. */ - interval_ms = NM_CLAMP ((new_next_try_at_nsec - now) / NM_UTILS_NS_PER_MSEC, + interval_ms = NM_CLAMP ((new_next_try_at_nsec - now) / NM_UTILS_NSEC_PER_MSEC, (gint64) 500, (gint64) (24*60*60*1000)); @@ -636,8 +636,8 @@ _peers_resolve_retry_reschedule_for_peer (NMDeviceWireGuard *self, return; } - peer_data->ep_resolv.next_try_at_nsec = nm_utils_get_monotonic_timestamp_ns () - + (retry_in_msec * NM_UTILS_NS_PER_MSEC); + peer_data->ep_resolv.next_try_at_nsec = nm_utils_get_monotonic_timestamp_nsec () + + (retry_in_msec * NM_UTILS_NSEC_PER_MSEC); _peers_resolve_retry_reschedule (self, peer_data->ep_resolv.next_try_at_nsec); } @@ -1370,7 +1370,7 @@ link_config (NMDeviceWireGuard *self, s_wg = NM_SETTING_WIREGUARD (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIREGUARD)); g_return_val_if_fail (s_wg, NM_ACT_STAGE_RETURN_FAILURE); - priv->link_config_last_at = nm_utils_get_monotonic_timestamp_ns (); + priv->link_config_last_at = nm_utils_get_monotonic_timestamp_nsec (); _LOGT (LOGD_DEVICE, "wireguard link config (%s, %s)...", reason, _link_config_mode_to_string (config_mode)); @@ -1475,12 +1475,12 @@ link_config_delayed (NMDeviceWireGuard *self, priv->link_config_delayed_id = 0; if (priv->link_config_last_at != 0) { - now = nm_utils_get_monotonic_timestamp_ns (); + now = nm_utils_get_monotonic_timestamp_nsec (); if (now < priv->link_config_last_at + LINK_CONFIG_RATE_LIMIT_NSEC) { /* we ratelimit calls to link_config(), because we call this whenever a resolver * completes. */ _LOGT (LOGD_DEVICE, "wireguard link config (%s) (postponed)", reason); - priv->link_config_delayed_id = g_timeout_add (NM_MAX ((priv->link_config_last_at + LINK_CONFIG_RATE_LIMIT_NSEC - now) / NM_UTILS_NS_PER_MSEC, + priv->link_config_delayed_id = g_timeout_add (NM_MAX ((priv->link_config_last_at + LINK_CONFIG_RATE_LIMIT_NSEC - now) / NM_UTILS_NSEC_PER_MSEC, (gint64) 1), link_config_delayed_ratelimit_cb, self); diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 3b595938df..381f68874d 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -2641,17 +2641,17 @@ concheck_periodic_schedule_do (NMDevice *self, int addr_family, gint64 now_ns) * Before calling concheck_periodic_schedule_do(), make sure that these properties are * correct. */ - expiry = priv->concheck_x[IS_IPv4].p_cur_basetime_ns + (priv->concheck_x[IS_IPv4].p_cur_interval * NM_UTILS_NS_PER_SECOND); + expiry = priv->concheck_x[IS_IPv4].p_cur_basetime_ns + (priv->concheck_x[IS_IPv4].p_cur_interval * NM_UTILS_NSEC_PER_SEC); tdiff = expiry - now_ns; _LOGT (LOGD_CONCHECK, "connectivity: [IPv%c] periodic-check: %sscheduled in %lld milliseconds (%u seconds interval)", nm_utils_addr_family_to_char (addr_family), periodic_check_disabled ? "re-" : "", - (long long) (tdiff / NM_UTILS_NS_PER_MSEC), + (long long) (tdiff / NM_UTILS_NSEC_PER_MSEC), priv->concheck_x[IS_IPv4].p_cur_interval); priv->concheck_x[IS_IPv4].p_cur_id = - g_timeout_add (NM_MAX ((gint64) 0, tdiff) / NM_UTILS_NS_PER_MSEC, + g_timeout_add (NM_MAX ((gint64) 0, tdiff) / NM_UTILS_NSEC_PER_MSEC, IS_IPv4 ? concheck_ip4_periodic_timeout_cb : concheck_ip6_periodic_timeout_cb, self); return TRUE; @@ -2713,7 +2713,7 @@ concheck_periodic_schedule_set (NMDevice *self, int addr_family, ConcheckSchedul return; } - cur_expiry = priv->concheck_x[IS_IPv4].p_cur_basetime_ns + (priv->concheck_x[IS_IPv4].p_max_interval * NM_UTILS_NS_PER_SECOND); + cur_expiry = priv->concheck_x[IS_IPv4].p_cur_basetime_ns + (priv->concheck_x[IS_IPv4].p_max_interval * NM_UTILS_NSEC_PER_SEC); nm_utils_get_monotonic_timestamp_ns_cached (&now_ns); priv->concheck_x[IS_IPv4].p_cur_interval = priv->concheck_x[IS_IPv4].p_max_interval; @@ -2769,10 +2769,10 @@ concheck_periodic_schedule_set (NMDevice *self, int addr_family, ConcheckSchedul * * We want to reschedule the timeout at exp_expiry (aka now) + cur_interval. */ nm_utils_get_monotonic_timestamp_ns_cached (&now_ns); - exp_expiry = priv->concheck_x[IS_IPv4].p_cur_basetime_ns + (old_interval * NM_UTILS_NS_PER_SECOND); - new_expiry = exp_expiry + (priv->concheck_x[IS_IPv4].p_cur_interval * NM_UTILS_NS_PER_SECOND); + exp_expiry = priv->concheck_x[IS_IPv4].p_cur_basetime_ns + (old_interval * NM_UTILS_NSEC_PER_SEC); + new_expiry = exp_expiry + (priv->concheck_x[IS_IPv4].p_cur_interval * NM_UTILS_NSEC_PER_SEC); tdiff = NM_MAX (new_expiry - now_ns, 0); - priv->concheck_x[IS_IPv4].p_cur_basetime_ns = (now_ns + tdiff) - (priv->concheck_x[IS_IPv4].p_cur_interval * NM_UTILS_NS_PER_SECOND); + priv->concheck_x[IS_IPv4].p_cur_basetime_ns = (now_ns + tdiff) - (priv->concheck_x[IS_IPv4].p_cur_interval * NM_UTILS_NSEC_PER_SEC); if (concheck_periodic_schedule_do (self, addr_family, now_ns)) { handle = concheck_start (self, addr_family, NULL, NULL, TRUE); if (old_interval != priv->concheck_x[IS_IPv4].p_cur_interval) { @@ -2806,9 +2806,9 @@ concheck_periodic_schedule_set (NMDevice *self, int addr_family, ConcheckSchedul * last check, instead of counting from now. The reason is that we want that the times * when we schedule checks be at precise intervals, without including the time it took for * the connectivity check. */ - new_expiry = priv->concheck_x[IS_IPv4].p_cur_basetime_ns + (priv->concheck_x[IS_IPv4].p_cur_interval * NM_UTILS_NS_PER_SECOND); + new_expiry = priv->concheck_x[IS_IPv4].p_cur_basetime_ns + (priv->concheck_x[IS_IPv4].p_cur_interval * NM_UTILS_NSEC_PER_SEC); tdiff = NM_MAX (new_expiry - nm_utils_get_monotonic_timestamp_ns_cached (&now_ns), 0); - priv->concheck_x[IS_IPv4].p_cur_basetime_ns = now_ns + tdiff - (priv->concheck_x[IS_IPv4].p_cur_interval * NM_UTILS_NS_PER_SECOND); + priv->concheck_x[IS_IPv4].p_cur_basetime_ns = now_ns + tdiff - (priv->concheck_x[IS_IPv4].p_cur_interval * NM_UTILS_NSEC_PER_SEC); concheck_periodic_schedule_do (self, addr_family, now_ns); } @@ -3646,7 +3646,7 @@ nm_device_set_carrier (NMDevice *self, gboolean carrier) } else { gint64 now_ms, until_ms; - now_ms = nm_utils_get_monotonic_timestamp_ms (); + now_ms = nm_utils_get_monotonic_timestamp_msec (); until_ms = NM_MAX (now_ms + _get_carrier_wait_ms (self), priv->carrier_wait_until_ms); priv->carrier_defer_id = g_timeout_add (until_ms - now_ms, carrier_disconnected_action_cb, self); _LOGD (LOGD_DEVICE, "carrier: link disconnected (deferring action for %ld milliseconds) (id=%u)", @@ -3742,7 +3742,7 @@ ndisc_set_router_config (NMNDisc *ndisc, NMDevice *self) if (nm_ndisc_get_node_type (ndisc) != NM_NDISC_NODE_TYPE_ROUTER) return; - now = nm_utils_get_monotonic_timestamp_s (); + now = nm_utils_get_monotonic_timestamp_sec (); head_entry = nm_ip6_config_lookup_addresses (priv->ip_config_6); addresses = g_array_sized_new (FALSE, TRUE, sizeof (NMNDiscAddress), @@ -8920,7 +8920,7 @@ dhcp6_get_duid (NMDevice *self, NMConnection *connection, GBytes *hwaddr, gboole duid_out = generate_duid_ll (arp_type, hwaddr_bin, hwaddr_len); else { duid_out = generate_duid_llt (arp_type, hwaddr_bin, hwaddr_len, - nm_utils_host_id_get_timestamp_ns () / NM_UTILS_NS_PER_SECOND); + nm_utils_host_id_get_timestamp_ns () / NM_UTILS_NSEC_PER_SEC); } goto out_good; @@ -9015,7 +9015,7 @@ dhcp6_get_duid (NMDevice *self, NMConnection *connection, GBytes *hwaddr, gboole * before. Let's compute the time (in seconds) from 0 to 3 years; then we'll * subtract it from the host_id timestamp. */ - time = nm_utils_host_id_get_timestamp_ns () / NM_UTILS_NS_PER_SECOND; + time = nm_utils_host_id_get_timestamp_ns () / NM_UTILS_NSEC_PER_SEC; /* don't use too old timestamps. They cannot be expressed in DUID-LLT and * would all be truncated to zero. */ @@ -9785,7 +9785,7 @@ _commit_mtu (NMDevice *self, const NMIP4Config *config) ? "Are the MTU sizes of the slaves large enough?" : "Did you configure the MTU correctly?")); } - priv->carrier_wait_until_ms = nm_utils_get_monotonic_timestamp_ms () + CARRIER_WAIT_TIME_AFTER_MTU_MS; + priv->carrier_wait_until_ms = nm_utils_get_monotonic_timestamp_msec () + CARRIER_WAIT_TIME_AFTER_MTU_MS; } if (ip6_mtu && ip6_mtu != _IP6_MTU_SYS ()) { @@ -9801,7 +9801,7 @@ _commit_mtu (NMDevice *self, const NMIP4Config *config) : ""); success = FALSE; } - priv->carrier_wait_until_ms = nm_utils_get_monotonic_timestamp_ms () + CARRIER_WAIT_TIME_AFTER_MTU_MS; + priv->carrier_wait_until_ms = nm_utils_get_monotonic_timestamp_msec () + CARRIER_WAIT_TIME_AFTER_MTU_MS; } } @@ -12230,7 +12230,7 @@ _rt6_temporary_not_available_set (NMDevice *self, nm_g_slice_free_fcn (IP6RoutesTemporaryNotAvailableData)); } - now_ms = nm_utils_get_monotonic_timestamp_ms (); + now_ms = nm_utils_get_monotonic_timestamp_msec (); oldest_ms = now_ms; for (i = 0; i < temporary_not_available->len; i++) { @@ -13267,14 +13267,14 @@ nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware) device_is_up = nm_device_is_up (self); if (block && !device_is_up) { - gint64 wait_until = nm_utils_get_monotonic_timestamp_us () + 10000 /* microseconds */; + gint64 wait_until = nm_utils_get_monotonic_timestamp_usec () + 10000 /* microseconds */; do { g_usleep (200); if (!nm_platform_link_refresh (nm_device_get_platform (self), ifindex)) return FALSE; device_is_up = nm_device_is_up (self); - } while (!device_is_up && nm_utils_get_monotonic_timestamp_us () < wait_until); + } while (!device_is_up && nm_utils_get_monotonic_timestamp_usec () < wait_until); } if (!device_is_up) { @@ -13309,7 +13309,7 @@ nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware) if (!priv->carrier) nm_device_add_pending_action (self, NM_PENDING_ACTION_CARRIER_WAIT, FALSE); - now_ms = nm_utils_get_monotonic_timestamp_ms (); + now_ms = nm_utils_get_monotonic_timestamp_msec (); until_ms = NM_MAX (now_ms + _get_carrier_wait_ms (self), priv->carrier_wait_until_ms); priv->carrier_wait_id = g_timeout_add (until_ms - now_ms, carrier_wait_timeout, self); } @@ -13352,14 +13352,14 @@ nm_device_take_down (NMDevice *self, gboolean block) device_is_up = nm_device_is_up (self); if (block && device_is_up) { - gint64 wait_until = nm_utils_get_monotonic_timestamp_us () + 10000 /* microseconds */; + gint64 wait_until = nm_utils_get_monotonic_timestamp_usec () + 10000 /* microseconds */; do { g_usleep (200); if (!nm_platform_link_refresh (nm_device_get_platform (self), ifindex)) return; device_is_up = nm_device_is_up (self); - } while (device_is_up && nm_utils_get_monotonic_timestamp_us () < wait_until); + } while (device_is_up && nm_utils_get_monotonic_timestamp_usec () < wait_until); } if (device_is_up) { @@ -15151,7 +15151,7 @@ nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason, CleanupType clean (guint) priv->mtu_initial, (guint) priv->ip6_mtu_initial, ifindex); if (priv->mtu_initial) { nm_platform_link_set_mtu (nm_device_get_platform (self), ifindex, priv->mtu_initial); - priv->carrier_wait_until_ms = nm_utils_get_monotonic_timestamp_ms () + CARRIER_WAIT_TIME_AFTER_MTU_MS; + priv->carrier_wait_until_ms = nm_utils_get_monotonic_timestamp_msec () + CARRIER_WAIT_TIME_AFTER_MTU_MS; } if (priv->ip6_mtu_initial) { char sbuf[64]; @@ -16319,7 +16319,7 @@ again: * * wait/poll up to 100 msec until it changes. */ - poll_end = nm_utils_get_monotonic_timestamp_us () + (100 * 1000); + poll_end = nm_utils_get_monotonic_timestamp_usec () + (100 * 1000); for (;;) { if (!nm_platform_link_refresh (nm_device_get_platform (self), nm_device_get_ip_ifindex (self))) goto handle_fail; @@ -16330,7 +16330,7 @@ again: break; handle_wait: - now = nm_utils_get_monotonic_timestamp_us (); + now = nm_utils_get_monotonic_timestamp_usec (); if (now < poll_end) { g_usleep (NM_MIN (poll_end - now, 500)); continue; diff --git a/src/devices/nm-lldp-listener.c b/src/devices/nm-lldp-listener.c index 4c9e77056d..9201660f53 100644 --- a/src/devices/nm-lldp-listener.c +++ b/src/devices/nm-lldp-listener.c @@ -17,7 +17,7 @@ #include "systemd/nm-sd.h" #define MAX_NEIGHBORS 4096 -#define MIN_UPDATE_INTERVAL_NS (2 * NM_UTILS_NS_PER_SECOND) +#define MIN_UPDATE_INTERVAL_NS (2 * NM_UTILS_NSEC_PER_SEC) #define LLDP_MAC_NEAREST_BRIDGE ((const struct ether_addr *) ((uint8_t[ETH_ALEN]) { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x0e })) #define LLDP_MAC_NEAREST_NON_TPMR_BRIDGE ((const struct ether_addr *) ((uint8_t[ETH_ALEN]) { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x03 })) @@ -828,7 +828,7 @@ data_changed_timeout (gpointer user_data) priv = NM_LLDP_LISTENER_GET_PRIVATE (self); priv->ratelimit_id = 0; - priv->ratelimit_next = nm_utils_get_monotonic_timestamp_ns() + MIN_UPDATE_INTERVAL_NS; + priv->ratelimit_next = nm_utils_get_monotonic_timestamp_nsec() + MIN_UPDATE_INTERVAL_NS; data_changed_notify (self, priv); return G_SOURCE_REMOVE; } @@ -839,13 +839,13 @@ data_changed_schedule (NMLldpListener *self) NMLldpListenerPrivate *priv = NM_LLDP_LISTENER_GET_PRIVATE (self); gint64 now; - now = nm_utils_get_monotonic_timestamp_ns (); + now = nm_utils_get_monotonic_timestamp_nsec (); if (now >= priv->ratelimit_next) { nm_clear_g_source (&priv->ratelimit_id); priv->ratelimit_next = now + MIN_UPDATE_INTERVAL_NS; data_changed_notify (self, priv); } else if (!priv->ratelimit_id) - priv->ratelimit_id = g_timeout_add (NM_UTILS_NS_TO_MSEC_CEIL (priv->ratelimit_next - now), data_changed_timeout, self); + priv->ratelimit_id = g_timeout_add (NM_UTILS_NSEC_TO_MSEC_CEIL (priv->ratelimit_next - now), data_changed_timeout, self); } static void diff --git a/src/devices/wifi/nm-device-iwd.c b/src/devices/wifi/nm-device-iwd.c index 6b587e3f3b..356f590faa 100644 --- a/src/devices/wifi/nm-device-iwd.c +++ b/src/devices/wifi/nm-device-iwd.c @@ -998,7 +998,7 @@ scan_cb (GObject *source, GAsyncResult *res, gpointer user_data) priv = NM_DEVICE_IWD_GET_PRIVATE (self); priv->scan_requested = FALSE; - priv->last_scan = nm_utils_get_monotonic_timestamp_ms (); + priv->last_scan = nm_utils_get_monotonic_timestamp_msec (); _notify (self, PROP_LAST_SCAN); /* On success, priv->scanning becomes true right before or right @@ -2099,7 +2099,7 @@ get_property (GObject *object, guint prop_id, case PROP_LAST_SCAN: g_value_set_int64 (value, priv->last_scan > 0 - ? nm_utils_monotonic_timestamp_as_boottime (priv->last_scan, NM_UTILS_NS_PER_MSEC) + ? nm_utils_monotonic_timestamp_as_boottime (priv->last_scan, NM_UTILS_NSEC_PER_MSEC) : (gint64) -1); break; default: diff --git a/src/devices/wifi/nm-device-wifi-p2p.c b/src/devices/wifi/nm-device-wifi-p2p.c index 34ff70fa0e..e3860ebf2f 100644 --- a/src/devices/wifi/nm-device-wifi-p2p.c +++ b/src/devices/wifi/nm-device-wifi-p2p.c @@ -104,7 +104,7 @@ peer_list_dump (gpointer user_data) if (_LOGD_ENABLED (LOGD_WIFI_SCAN)) { NMWifiP2PPeer *peer; - gint32 now_s = nm_utils_get_monotonic_timestamp_s (); + gint32 now_s = nm_utils_get_monotonic_timestamp_sec (); _LOGD (LOGD_WIFI_SCAN, "P2P Peers: [now:%u]", now_s); c_list_for_each_entry (peer, &priv->peers_lst_head, peers_lst) diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 65ba2bcc0f..75b9943c80 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -1047,7 +1047,7 @@ _hw_addr_set_scanning (NMDeviceWifi *self, gboolean do_reset) return; } - now = nm_utils_get_monotonic_timestamp_s (); + now = nm_utils_get_monotonic_timestamp_sec (); if (now >= priv->hw_addr_scan_expire) { gs_free char *generate_mac_address_mask = NULL; @@ -1188,7 +1188,7 @@ _nm_device_wifi_request_scan (NMDeviceWifi *self, } last_scan = nm_supplicant_interface_get_last_scan (priv->sup_iface); - if (last_scan && (nm_utils_get_monotonic_timestamp_ms () - last_scan) < 10 * NM_UTILS_MSEC_PER_SECOND) { + if (last_scan && (nm_utils_get_monotonic_timestamp_msec () - last_scan) < 10 * NM_UTILS_MSEC_PER_SEC) { g_dbus_method_invocation_return_error_literal (invocation, NM_DEVICE_ERROR, NM_DEVICE_ERROR_NOT_ALLOWED, @@ -1419,7 +1419,7 @@ static void schedule_scan (NMDeviceWifi *self, gboolean backoff) { NMDeviceWifiPrivate *priv = NM_DEVICE_WIFI_GET_PRIVATE (self); - gint32 now = nm_utils_get_monotonic_timestamp_s (); + gint32 now = nm_utils_get_monotonic_timestamp_sec (); /* Cancel the pending scan if it would happen later than (now + the scan_interval) */ if (priv->pending_scan_id) { @@ -1466,7 +1466,7 @@ supplicant_iface_scan_done_cb (NMSupplicantInterface *iface, _LOGD (LOGD_WIFI, "wifi-scan: scan-done callback: %s", success ? "successful" : "failed"); - priv->last_scan = nm_utils_get_monotonic_timestamp_ms (); + priv->last_scan = nm_utils_get_monotonic_timestamp_msec (); _notify (self, PROP_LAST_SCAN); schedule_scan (self, success); @@ -1488,11 +1488,11 @@ ap_list_dump (gpointer user_data) if (_LOGD_ENABLED (LOGD_WIFI_SCAN)) { NMWifiAP *ap; - gint32 now_s = nm_utils_get_monotonic_timestamp_s (); + gint32 now_s = nm_utils_get_monotonic_timestamp_sec (); _LOGD (LOGD_WIFI_SCAN, "APs: [now:%u last:%" G_GINT64_FORMAT " next:%u]", now_s, - priv->last_scan / NM_UTILS_MSEC_PER_SECOND, + priv->last_scan / NM_UTILS_MSEC_PER_SEC, priv->scheduled_scan_time); c_list_for_each_entry (ap, &priv->aps_lst_head, aps_lst) _ap_dump (self, LOGL_DEBUG, ap, "dump", now_s); @@ -3255,7 +3255,7 @@ get_property (GObject *object, guint prop_id, case PROP_LAST_SCAN: g_value_set_int64 (value, priv->last_scan > 0 - ? nm_utils_monotonic_timestamp_as_boottime (priv->last_scan, NM_UTILS_NS_PER_MSEC) + ? nm_utils_monotonic_timestamp_as_boottime (priv->last_scan, NM_UTILS_NSEC_PER_MSEC) : (gint64) -1); break; default: diff --git a/src/devices/wifi/nm-wifi-ap.c b/src/devices/wifi/nm-wifi-ap.c index b4e07ff9be..e07fde543a 100644 --- a/src/devices/wifi/nm-wifi-ap.c +++ b/src/devices/wifi/nm-wifi-ap.c @@ -58,7 +58,7 @@ struct _NMWifiAPPrivate { /* Non-scanned attributes */ bool fake:1; /* Whether or not the AP is from a scan */ bool hotspot:1; /* Whether the AP is a local device's hotspot network */ - gint32 last_seen; /* Timestamp when the AP was seen lastly (obtained via nm_utils_get_monotonic_timestamp_s()) */ + gint32 last_seen; /* Timestamp when the AP was seen lastly (obtained via nm_utils_get_monotonic_timestamp_sec()) */ }; typedef struct _NMWifiAPPrivate NMWifiAPPrivate; @@ -898,7 +898,7 @@ nm_wifi_ap_update_from_properties (NMWifiAP *ap, changed = TRUE; } - changed |= nm_wifi_ap_set_last_seen (ap, nm_utils_get_monotonic_timestamp_s ()); + changed |= nm_wifi_ap_set_last_seen (ap, nm_utils_get_monotonic_timestamp_sec ()); changed |= nm_wifi_ap_set_fake (ap, FALSE); g_object_thaw_notify (G_OBJECT (ap)); @@ -1026,7 +1026,7 @@ nm_wifi_ap_to_string (const NMWifiAP *self, priv->metered ? 'M' : '_', priv->wpa_flags & 0xFFFF, priv->rsn_flags & 0xFFFF, - priv->last_seen > 0 ? ((now_s > 0 ? now_s : nm_utils_get_monotonic_timestamp_s ()) - priv->last_seen) : -1, + priv->last_seen > 0 ? ((now_s > 0 ? now_s : nm_utils_get_monotonic_timestamp_sec ()) - priv->last_seen) : -1, supplicant_id, export_path); return str_buf; @@ -1180,7 +1180,7 @@ get_property (GObject *object, guint prop_id, case PROP_LAST_SEEN: g_value_set_int (value, priv->last_seen > 0 - ? (int) nm_utils_monotonic_timestamp_as_boottime (priv->last_seen, NM_UTILS_NS_PER_SECOND) + ? (int) nm_utils_monotonic_timestamp_as_boottime (priv->last_seen, NM_UTILS_NSEC_PER_SEC) : -1); break; default: diff --git a/src/devices/wifi/nm-wifi-p2p-peer.c b/src/devices/wifi/nm-wifi-p2p-peer.c index f8da004669..ccdd56c4fd 100644 --- a/src/devices/wifi/nm-wifi-p2p-peer.c +++ b/src/devices/wifi/nm-wifi-p2p-peer.c @@ -55,7 +55,7 @@ struct _NMWifiP2PPeerPrivate { NM80211ApFlags flags; /* General flags */ /* Non-scanned attributes */ - gint32 last_seen; /* Timestamp when the Peer was seen lastly (obtained via nm_utils_get_monotonic_timestamp_s()) */ + gint32 last_seen; /* Timestamp when the Peer was seen lastly (obtained via nm_utils_get_monotonic_timestamp_sec()) */ }; typedef struct _NMWifiP2PPeerPrivate NMWifiP2PPeerPrivate; @@ -499,7 +499,7 @@ nm_wifi_p2p_peer_update_from_properties (NMWifiP2PPeer *peer, changed = TRUE; } - changed |= nm_wifi_p2p_peer_set_last_seen (peer, nm_utils_get_monotonic_timestamp_s ()); + changed |= nm_wifi_p2p_peer_set_last_seen (peer, nm_utils_get_monotonic_timestamp_sec ()); g_object_thaw_notify (G_OBJECT (peer)); @@ -537,7 +537,7 @@ nm_wifi_p2p_peer_to_string (const NMWifiP2PPeer *self, priv->model, priv->model_number, priv->serial, - priv->last_seen > 0 ? ((now_s > 0 ? now_s : nm_utils_get_monotonic_timestamp_s ()) - priv->last_seen) : -1, + priv->last_seen > 0 ? ((now_s > 0 ? now_s : nm_utils_get_monotonic_timestamp_sec ()) - priv->last_seen) : -1, supplicant_id, export_path); @@ -616,7 +616,7 @@ get_property (GObject *object, guint prop_id, case PROP_LAST_SEEN: g_value_set_int (value, priv->last_seen > 0 - ? (int) nm_utils_monotonic_timestamp_as_boottime (priv->last_seen, NM_UTILS_NS_PER_SECOND) + ? (int) nm_utils_monotonic_timestamp_as_boottime (priv->last_seen, NM_UTILS_NSEC_PER_SEC) : -1); break; default: diff --git a/src/dhcp/nm-dhcp-nettools.c b/src/dhcp/nm-dhcp-nettools.c index e557c00487..654bdf5031 100644 --- a/src/dhcp/nm-dhcp-nettools.c +++ b/src/dhcp/nm-dhcp-nettools.c @@ -373,8 +373,8 @@ lease_parse_address (NDhcp4ClientLease *lease, * Here we still do it... it seems safe enough. */ nm_assert (nettools_basetime > 0); nm_assert (nettools_lifetime >= nettools_basetime); - nm_assert (((nettools_lifetime - nettools_basetime) % NM_UTILS_NS_PER_SECOND) == 0); - nm_assert ((nettools_lifetime - nettools_basetime) / NM_UTILS_NS_PER_SECOND <= G_MAXUINT32); + nm_assert (((nettools_lifetime - nettools_basetime) % NM_UTILS_NSEC_PER_SEC) == 0); + nm_assert ((nettools_lifetime - nettools_basetime) / NM_UTILS_NSEC_PER_SEC <= G_MAXUINT32); if (nettools_lifetime <= nettools_basetime) { /* A lease time of 0 is allowed on some dhcp servers, so, let's accept it. */ @@ -384,7 +384,7 @@ lease_parse_address (NDhcp4ClientLease *lease, /* we "ceil" the value to the next second. In practice, we don't expect any sub-second values * from n-dhcp4 anyway, so this should have no effect. */ - lifetime += NM_UTILS_NS_PER_SECOND - 1; + lifetime += NM_UTILS_NSEC_PER_SEC - 1; } ts = nm_utils_monotonic_timestamp_from_boottime (nettools_basetime, 1); @@ -392,11 +392,11 @@ lease_parse_address (NDhcp4ClientLease *lease, /* the timestamp must be positive, because we only started nettools DHCP client * after obtaining the first monotonic timestamp. Hence, the lease must have been * received afterwards. */ - nm_assert (ts >= NM_UTILS_NS_PER_SECOND); + nm_assert (ts >= NM_UTILS_NSEC_PER_SEC); - a_timestamp = ts / NM_UTILS_NS_PER_SECOND; - a_lifetime = NM_MIN (lifetime / NM_UTILS_NS_PER_SECOND, NM_PLATFORM_LIFETIME_PERMANENT - 1); - a_expiry = time (NULL) + ((lifetime - (nm_utils_clock_gettime_ns (CLOCK_BOOTTIME) - nettools_basetime)) / NM_UTILS_NS_PER_SECOND); + a_timestamp = ts / NM_UTILS_NSEC_PER_SEC; + a_lifetime = NM_MIN (lifetime / NM_UTILS_NSEC_PER_SEC, NM_PLATFORM_LIFETIME_PERMANENT - 1); + a_expiry = time (NULL) + ((lifetime - (nm_utils_clock_gettime_ns (CLOCK_BOOTTIME) - nettools_basetime)) / NM_UTILS_NSEC_PER_SEC); } if (!lease_get_in_addr (lease, NM_DHCP_OPTION_DHCP4_SUBNET_MASK, &a_netmask)) { diff --git a/src/dhcp/nm-dhcp-systemd.c b/src/dhcp/nm-dhcp-systemd.c index 1518d46576..b5ebd1bc98 100644 --- a/src/dhcp/nm-dhcp-systemd.c +++ b/src/dhcp/nm-dhcp-systemd.c @@ -93,7 +93,7 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx, gboolean has_router_from_classless = FALSE; gboolean has_classless_route = FALSE; gboolean has_static_route = FALSE; - const gint32 ts = nm_utils_get_monotonic_timestamp_s (); + const gint32 ts = nm_utils_get_monotonic_timestamp_sec (); gint64 ts_time = time (NULL); struct in_addr a_address; struct in_addr a_netmask; @@ -803,7 +803,7 @@ static void bound6_handle (NMDhcpSystemd *self) { NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (self); - const gint32 ts = nm_utils_get_monotonic_timestamp_s (); + const gint32 ts = nm_utils_get_monotonic_timestamp_sec (); const char *iface = nm_dhcp_client_get_iface (NM_DHCP_CLIENT (self)); gs_unref_object NMIP6Config *ip6_config = NULL; gs_unref_hashtable GHashTable *options = NULL; diff --git a/src/dhcp/nm-dhcp-utils.c b/src/dhcp/nm-dhcp-utils.c index c5da3e0227..e1c1fa1d85 100644 --- a/src/dhcp/nm-dhcp-utils.c +++ b/src/dhcp/nm-dhcp-utils.c @@ -388,7 +388,7 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx, ip4_config = nm_ip4_config_new (multi_idx, ifindex); memset (&address, 0, sizeof (address)); - address.timestamp = nm_utils_get_monotonic_timestamp_s (); + address.timestamp = nm_utils_get_monotonic_timestamp_sec (); str = g_hash_table_lookup (options, "ip_address"); if (str && (inet_pton (AF_INET, str, &addr) > 0)) @@ -601,7 +601,7 @@ nm_dhcp_utils_ip6_prefix_from_options (GHashTable *options) address.address = tmp_addr; address.addr_source = NM_IP_CONFIG_SOURCE_DHCP; address.plen = prefix; - address.timestamp = nm_utils_get_monotonic_timestamp_s (); + address.timestamp = nm_utils_get_monotonic_timestamp_sec (); str = g_hash_table_lookup (options, "max_life"); if (str) @@ -630,7 +630,7 @@ nm_dhcp_utils_ip6_config_from_options (NMDedupMultiIndex *multi_idx, memset (&address, 0, sizeof (address)); address.plen = 128; - address.timestamp = nm_utils_get_monotonic_timestamp_s (); + address.timestamp = nm_utils_get_monotonic_timestamp_sec (); ip6_config = nm_ip6_config_new (multi_idx, ifindex); diff --git a/src/dns/nm-dns-dnsmasq.c b/src/dns/nm-dns-dnsmasq.c index a5028e426d..e2bd0b790d 100644 --- a/src/dns/nm-dns-dnsmasq.c +++ b/src/dns/nm-dns-dnsmasq.c @@ -129,7 +129,7 @@ _gl_pid_kill_external_timeout_cb (gpointer user_data) goto process_gone; } - now = nm_utils_get_monotonic_timestamp_ms (); + now = nm_utils_get_monotonic_timestamp_msec (); if (gl_pid.kill_external_data->started_at + WAIT_MSEC_AFTER_SIGTERM < now) { if (!gl_pid.kill_external_data->sigkilled) { @@ -240,7 +240,7 @@ handle_kill: gl_pid.kill_external_data = g_slice_new (GlPidKillExternalData); *gl_pid.kill_external_data = (GlPidKillExternalData) { .shutdown_wait_handle = nm_shutdown_wait_obj_register_handle_full (g_strdup_printf ("kill-external-dnsmasq-process-%"G_PID_FORMAT, pid), TRUE), - .started_at = nm_utils_get_monotonic_timestamp_ms (), + .started_at = nm_utils_get_monotonic_timestamp_msec (), .pid = pid, .p_start_time = p_start_time, }; @@ -1058,7 +1058,7 @@ start_dnsmasq (NMDnsDnsmasq *self, gboolean force_start, GError **error) } } - now = nm_utils_get_monotonic_timestamp_ms (); + now = nm_utils_get_monotonic_timestamp_msec (); if ( force_start || priv->burst_start_at == 0 || priv->burst_start_at + RATELIMIT_INTERVAL_MSEC <= now) { diff --git a/src/ndisc/nm-fake-ndisc.c b/src/ndisc/nm-fake-ndisc.c index 020764d3d9..851ff70721 100644 --- a/src/ndisc/nm-fake-ndisc.c +++ b/src/ndisc/nm-fake-ndisc.c @@ -234,7 +234,7 @@ receive_ra (gpointer user_data) NMNDiscDataInternal *rdata = ndisc->rdata; FakeRa *ra = priv->ras->data; NMNDiscConfigMap changed = 0; - gint32 now = nm_utils_get_monotonic_timestamp_s (); + gint32 now = nm_utils_get_monotonic_timestamp_sec (); guint i; NMNDiscDHCPLevel dhcp_level; diff --git a/src/ndisc/nm-lndp-ndisc.c b/src/ndisc/nm-lndp-ndisc.c index 8077099f6f..d052426f4a 100644 --- a/src/ndisc/nm-lndp-ndisc.c +++ b/src/ndisc/nm-lndp-ndisc.c @@ -99,7 +99,7 @@ receive_ra (struct ndp *ndp, struct ndp_msg *msg, gpointer user_data) NMNDiscConfigMap changed = 0; struct ndp_msgra *msgra = ndp_msgra (msg); struct in6_addr gateway_addr; - gint32 now = nm_utils_get_monotonic_timestamp_s (); + gint32 now = nm_utils_get_monotonic_timestamp_sec (); int offset; int hop_limit; guint32 val; @@ -348,7 +348,7 @@ send_ra (NMNDisc *ndisc, GError **error) { NMLndpNDiscPrivate *priv = NM_LNDP_NDISC_GET_PRIVATE ((NMLndpNDisc *) ndisc); NMNDiscDataInternal *rdata = ndisc->rdata; - gint32 now = nm_utils_get_monotonic_timestamp_s (); + gint32 now = nm_utils_get_monotonic_timestamp_sec (); int errsv; struct in6_addr *addr; struct ndp_msg *msg; diff --git a/src/ndisc/nm-ndisc.c b/src/ndisc/nm-ndisc.c index 41201e24aa..7369bacddc 100644 --- a/src/ndisc/nm-ndisc.c +++ b/src/ndisc/nm-ndisc.c @@ -171,7 +171,7 @@ _get_exp (char *buf, gsize buf_size, gint64 now_ns, gint64 expiry_time) return "permanent"; l = g_snprintf (buf, buf_size, "%.4f", - ((double) ((expiry_time * NM_UTILS_NS_PER_SECOND) - now_ns)) / ((double) NM_UTILS_NS_PER_SECOND)); + ((double) ((expiry_time * NM_UTILS_NSEC_PER_SEC) - now_ns)) / ((double) NM_UTILS_NSEC_PER_SEC)); nm_assert (l < buf_size); return buf; } @@ -701,7 +701,7 @@ send_rs_timeout (NMNDisc *ndisc) g_clear_error (&error); } - priv->last_rs = nm_utils_get_monotonic_timestamp_s (); + priv->last_rs = nm_utils_get_monotonic_timestamp_sec (); if (priv->solicitations_left > 0) { _LOGD ("scheduling router solicitation retry in %d seconds.", (int) priv->router_solicitation_interval); @@ -725,7 +725,7 @@ solicit_routers (NMNDisc *ndisc) if (priv->send_rs_id) return; - now = nm_utils_get_monotonic_timestamp_s (); + now = nm_utils_get_monotonic_timestamp_sec (); priv->solicitations_left = priv->router_solicitations; t = (((gint64) priv->last_rs) + priv->router_solicitation_interval) - now; @@ -746,7 +746,7 @@ announce_router (NMNDisc *ndisc) if (!nm_ndisc_netns_push (ndisc, &netns)) return G_SOURCE_REMOVE; - priv->last_ra = nm_utils_get_monotonic_timestamp_s (); + priv->last_ra = nm_utils_get_monotonic_timestamp_sec (); if (klass->send_ra (ndisc, &error)) { _LOGD ("router advertisement sent"); g_clear_pointer (&priv->last_error, g_free); @@ -786,7 +786,7 @@ announce_router_initial (NMNDisc *ndisc) priv->announcements_left = NM_NDISC_ROUTER_ADVERTISEMENTS_DEFAULT; /* Unschedule an unsolicited resend if we are allowed to send now. */ - if (G_LIKELY (nm_utils_get_monotonic_timestamp_s () - priv->last_ra > NM_NDISC_ROUTER_ADVERT_DELAY)) + if (G_LIKELY (nm_utils_get_monotonic_timestamp_sec () - priv->last_ra > NM_NDISC_ROUTER_ADVERT_DELAY)) nm_clear_g_source (&priv->send_ra_id); /* Schedule the initial send rather early. Clamp the delay by minimal @@ -805,7 +805,7 @@ announce_router_solicited (NMNDisc *ndisc) _LOGD ("will send an solicited router advertisement"); /* Unschedule an unsolicited resend if we are allowed to send now. */ - if (nm_utils_get_monotonic_timestamp_s () - priv->last_ra > NM_NDISC_ROUTER_ADVERT_DELAY) + if (nm_utils_get_monotonic_timestamp_sec () - priv->last_ra > NM_NDISC_ROUTER_ADVERT_DELAY) nm_clear_g_source (&priv->send_ra_id); if (!priv->send_ra_id) { @@ -1017,7 +1017,7 @@ _config_changed_log (NMNDisc *ndisc, NMNDiscConfigMap changed) if (!_LOGD_ENABLED ()) return; - now_ns = nm_utils_get_monotonic_timestamp_ns (); + now_ns = nm_utils_get_monotonic_timestamp_nsec (); priv = NM_NDISC_GET_PRIVATE (ndisc); rdata = &priv->rdata; @@ -1231,7 +1231,7 @@ timeout_cb (gpointer user_data) NMNDisc *self = user_data; NM_NDISC_GET_PRIVATE (self)->timeout_id = 0; - check_timestamps (self, nm_utils_get_monotonic_timestamp_s (), 0); + check_timestamps (self, nm_utils_get_monotonic_timestamp_sec (), 0); return G_SOURCE_REMOVE; } @@ -1350,7 +1350,7 @@ nm_ndisc_init (NMNDisc *ndisc) priv->rdata.public.hop_limit = 64; /* Start at very low number so that last_rs - router_solicitation_interval - * is much lower than nm_utils_get_monotonic_timestamp_s() at startup. + * is much lower than nm_utils_get_monotonic_timestamp_sec() at startup. */ priv->last_rs = G_MININT32; } diff --git a/src/ndisc/tests/test-ndisc-fake.c b/src/ndisc/tests/test-ndisc-fake.c index 8bdc053ded..91fe9802d7 100644 --- a/src/ndisc/tests/test-ndisc-fake.c +++ b/src/ndisc/tests/test-ndisc-fake.c @@ -157,7 +157,7 @@ static void test_simple (void) { NMFakeNDisc *ndisc = ndisc_new (); - guint32 now = nm_utils_get_monotonic_timestamp_s (); + guint32 now = nm_utils_get_monotonic_timestamp_sec (); TestData data = { g_main_loop_new (NULL, FALSE), 0, 0, now }; guint id; @@ -239,7 +239,7 @@ static void test_everything (void) { NMFakeNDisc *ndisc = ndisc_new (); - guint32 now = nm_utils_get_monotonic_timestamp_s (); + guint32 now = nm_utils_get_monotonic_timestamp_sec (); TestData data = { g_main_loop_new (NULL, FALSE), 0, 0, now }; guint id; @@ -313,7 +313,7 @@ static void test_preference_order (void) { NMFakeNDisc *ndisc = ndisc_new (); - guint32 now = nm_utils_get_monotonic_timestamp_s (); + guint32 now = nm_utils_get_monotonic_timestamp_sec (); TestData data = { g_main_loop_new (NULL, FALSE), 0, 0, now }; guint id; @@ -386,7 +386,7 @@ static void test_preference_changed (void) { NMFakeNDisc *ndisc = ndisc_new (); - guint32 now = nm_utils_get_monotonic_timestamp_s (); + guint32 now = nm_utils_get_monotonic_timestamp_sec (); TestData data = { g_main_loop_new (NULL, FALSE), 0, 0, now }; guint id; @@ -440,7 +440,7 @@ success_timeout (TestData *data) static void test_dns_solicit_loop_rs_sent (NMFakeNDisc *ndisc, TestData *data) { - guint32 now = nm_utils_get_monotonic_timestamp_s (); + guint32 now = nm_utils_get_monotonic_timestamp_sec (); guint id; if (data->rs_counter > 0 && data->rs_counter < 6) { @@ -472,7 +472,7 @@ static void test_dns_solicit_loop (void) { NMFakeNDisc *ndisc = ndisc_new (); - guint32 now = nm_utils_get_monotonic_timestamp_s (); + guint32 now = nm_utils_get_monotonic_timestamp_sec (); TestData data = { g_main_loop_new (NULL, FALSE), 0, 0, now, 0 }; guint id; diff --git a/src/nm-checkpoint.c b/src/nm-checkpoint.c index 734a40e1e2..1ab0f07d36 100644 --- a/src/nm-checkpoint.c +++ b/src/nm-checkpoint.c @@ -585,7 +585,7 @@ nm_checkpoint_adjust_rollback_timeout (NMCheckpoint *self, guint32 add_timeout) if (add_timeout == 0) rollback_timeout_s = 0; else { - now_ms = nm_utils_get_monotonic_timestamp_ms (); + now_ms = nm_utils_get_monotonic_timestamp_msec (); add_timeout_ms = ((gint64) add_timeout) * 1000; rollback_timeout_ms = (now_ms - priv->created_at_ms) + add_timeout_ms; @@ -626,7 +626,7 @@ get_property (GObject *object, guint prop_id, case PROP_CREATED: g_value_set_int64 (value, nm_utils_monotonic_timestamp_as_boottime (priv->created_at_ms, - NM_UTILS_NS_PER_MSEC)); + NM_UTILS_NSEC_PER_MSEC)); break; case PROP_ROLLBACK_TIMEOUT: g_value_set_uint (value, priv->rollback_timeout_s); @@ -679,7 +679,7 @@ nm_checkpoint_new (NMManager *manager, GPtrArray *devices, guint32 rollback_time priv = NM_CHECKPOINT_GET_PRIVATE (self); priv->manager = g_object_ref (manager); priv->rollback_timeout_s = rollback_timeout_s; - priv->created_at_ms = nm_utils_get_monotonic_timestamp_ms (); + priv->created_at_ms = nm_utils_get_monotonic_timestamp_msec (); priv->flags = flags; if (rollback_timeout_s != 0) { diff --git a/src/nm-connectivity.c b/src/nm-connectivity.c index ccac63766b..bcafc90893 100644 --- a/src/nm-connectivity.c +++ b/src/nm-connectivity.c @@ -415,13 +415,13 @@ _con_curl_timeout_cb (gpointer user_data) } static int -multi_timer_cb (CURLM *multi, long timeout_ms, void *userdata) +multi_timer_cb (CURLM *multi, long timeout_msec, void *userdata) { NMConnectivityCheckHandle *cb_data = userdata; nm_clear_g_source (&cb_data->concheck.curl_timer); - if (timeout_ms != -1) - cb_data->concheck.curl_timer = g_timeout_add (timeout_ms, _con_curl_timeout_cb, cb_data); + if (timeout_msec != -1) + cb_data->concheck.curl_timer = g_timeout_add (timeout_msec, _con_curl_timeout_cb, cb_data); return 0; } diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index fb92289f0d..1438a0bb5e 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -436,7 +436,7 @@ static const char * _kc_waited_to_string (char *buf, gint64 wait_start_us) #define _kc_waited_to_string(buf, wait_start_us) ( G_STATIC_ASSERT_EXPR(sizeof (buf) == KC_WAITED_TO_STRING && sizeof ((buf)[0]) == 1), _kc_waited_to_string (buf, wait_start_us) ) { - g_snprintf (buf, KC_WAITED_TO_STRING, " (%ld usec elapsed)", (long) (nm_utils_get_monotonic_timestamp_us () - wait_start_us)); + g_snprintf (buf, KC_WAITED_TO_STRING, " (%ld usec elapsed)", (long) (nm_utils_get_monotonic_timestamp_usec () - wait_start_us)); return buf; } @@ -476,7 +476,7 @@ _kc_cb_timeout_grace_period (void *user_data) } } else { nm_log_dbg (data->log_domain, "%s: process not terminated after %ld usec. Sending SIGKILL signal", - data->log_name, (long) (nm_utils_get_monotonic_timestamp_us () - data->async.wait_start_us)); + data->log_name, (long) (nm_utils_get_monotonic_timestamp_usec () - data->async.wait_start_us)); } return G_SOURCE_REMOVE; @@ -591,7 +591,7 @@ nm_utils_kill_child_async (pid_t pid, int sig, NMLogDomain log_domain, } data = _kc_async_data_alloc (pid, log_domain, log_name, callback, user_data); - data->async.wait_start_us = nm_utils_get_monotonic_timestamp_us (); + data->async.wait_start_us = nm_utils_get_monotonic_timestamp_usec (); if (sig != SIGKILL && wait_before_kill_msec > 0) { data->async.source_timeout_kill_id = g_timeout_add (wait_before_kill_msec, _kc_cb_timeout_grace_period, data); @@ -694,7 +694,7 @@ nm_utils_kill_child_sync (pid_t pid, int sig, NMLogDomain log_domain, const char goto out; } - wait_start_us = nm_utils_get_monotonic_timestamp_us (); + wait_start_us = nm_utils_get_monotonic_timestamp_usec (); /* wait for the process to terminated... */ if (sig != SIGKILL) { @@ -728,7 +728,7 @@ nm_utils_kill_child_sync (pid_t pid, int sig, NMLogDomain log_domain, const char if (!wait_until) break; - now = nm_utils_get_monotonic_timestamp_us (); + now = nm_utils_get_monotonic_timestamp_usec (); if (now >= wait_until) break; @@ -871,7 +871,7 @@ nm_utils_kill_process_sync (pid_t pid, guint64 start_time, int sig, NMLogDomain /* wait for the process to terminate... */ - wait_start_us = nm_utils_get_monotonic_timestamp_us (); + wait_start_us = nm_utils_get_monotonic_timestamp_usec (); sleep_duration_usec = _sleep_duration_convert_ms_to_us (sleep_duration_msec); if (sig != SIGKILL && wait_before_kill_msec) @@ -922,7 +922,7 @@ nm_utils_kill_process_sync (pid_t pid, guint64 start_time, int sig, NMLogDomain } sleep_time = sleep_duration_usec; - now = nm_utils_get_monotonic_timestamp_us (); + now = nm_utils_get_monotonic_timestamp_usec (); if ( max_wait_until != 0 && now >= max_wait_until) { @@ -2453,13 +2453,13 @@ _host_id_read_timestamp (gboolean use_secret_key_file, * is not stable across restarts, but apparently neither is the host-id * nor the secret_key itself. */ -#define EPOCH_TWO_YEARS (G_GINT64_CONSTANT (2 * 365 * 24 * 3600) * NM_UTILS_NS_PER_SECOND) +#define EPOCH_TWO_YEARS (G_GINT64_CONSTANT (2 * 365 * 24 * 3600) * NM_UTILS_NSEC_PER_SEC) v = nm_hash_siphash42 (1156657133u, host_id, host_id_len); now = time (NULL); *out_timestamp_ns = NM_MAX ((gint64) 1, - (now * NM_UTILS_NS_PER_SECOND) - ((gint64) (v % ((guint64) (EPOCH_TWO_YEARS))))); + (now * NM_UTILS_NSEC_PER_SEC) - ((gint64) (v % ((guint64) (EPOCH_TWO_YEARS))))); return FALSE; } @@ -3721,7 +3721,7 @@ nm_utils_lifetime_get (guint32 timestamp, } if (now <= 0) - now = nm_utils_get_monotonic_timestamp_s (); + now = nm_utils_get_monotonic_timestamp_sec (); t_lifetime = nm_utils_lifetime_rebase_relative_time_on_now (timestamp, lifetime, now); if (!t_lifetime) { diff --git a/src/nm-dbus-manager.c b/src/nm-dbus-manager.c index 3f6f8115e2..f2d63b4bdc 100644 --- a/src/nm-dbus-manager.c +++ b/src/nm-dbus-manager.c @@ -523,7 +523,7 @@ _get_caller_info_ensure (NMDBusManager *self, gint64 now_ns; gsize num; -#define CALLER_INFO_MAX_AGE (NM_UTILS_NS_PER_SECOND * 1) +#define CALLER_INFO_MAX_AGE (NM_UTILS_NSEC_PER_SEC * 1) /* Linear search the cache for the sender. * @@ -564,7 +564,7 @@ _get_caller_info_ensure (NMDBusManager *self, } } - now_ns = nm_utils_get_monotonic_timestamp_ns (); + now_ns = nm_utils_get_monotonic_timestamp_nsec (); if ( ensure_uid && (now_ns - caller_info->uid_checked_at) > CALLER_INFO_MAX_AGE) { diff --git a/src/nm-logging.c b/src/nm-logging.c index 34dd2797aa..9e0aa16563 100644 --- a/src/nm-logging.c +++ b/src/nm-logging.c @@ -730,7 +730,7 @@ _nm_log_impl (const char *file, char *iov_free_data[5]; char **iov_free = iov_free_data; - now = nm_utils_get_monotonic_timestamp_ns (); + now = nm_utils_get_monotonic_timestamp_nsec (); boottime = nm_utils_monotonic_timestamp_as_boottime (now, 1); _iovec_set_format_a (iov++, 30, "PRIORITY=%d", level_desc[level].syslog_level); @@ -763,8 +763,8 @@ _nm_log_impl (const char *file, _iovec_set_format (iov++, iov_free++, "CODE_FUNC=%s", func); _iovec_set_format (iov++, iov_free++, "CODE_FILE=%s", file ?: ""); _iovec_set_format_a (iov++, 20, "CODE_LINE=%u", line); - _iovec_set_format_a (iov++, 60, "TIMESTAMP_MONOTONIC=%lld.%06lld", (long long) (now / NM_UTILS_NS_PER_SECOND), (long long) ((now % NM_UTILS_NS_PER_SECOND) / 1000)); - _iovec_set_format_a (iov++, 60, "TIMESTAMP_BOOTTIME=%lld.%06lld", (long long) (boottime / NM_UTILS_NS_PER_SECOND), (long long) ((boottime % NM_UTILS_NS_PER_SECOND) / 1000)); + _iovec_set_format_a (iov++, 60, "TIMESTAMP_MONOTONIC=%lld.%06lld", (long long) (now / NM_UTILS_NSEC_PER_SEC), (long long) ((now % NM_UTILS_NSEC_PER_SEC) / 1000)); + _iovec_set_format_a (iov++, 60, "TIMESTAMP_BOOTTIME=%lld.%06lld", (long long) (boottime / NM_UTILS_NSEC_PER_SEC), (long long) ((boottime % NM_UTILS_NSEC_PER_SEC) / 1000)); if (error != 0) _iovec_set_format_a (iov++, 30, "ERRNO=%d", error); if (ifname) @@ -865,7 +865,7 @@ nm_log_handler (const char *log_domain, { gint64 now, boottime; - now = nm_utils_get_monotonic_timestamp_ns (); + now = nm_utils_get_monotonic_timestamp_nsec (); boottime = nm_utils_monotonic_timestamp_as_boottime (now, 1); sd_journal_send ("PRIORITY=%d", syslog_priority, @@ -875,8 +875,8 @@ nm_log_handler (const char *log_domain, "SYSLOG_FACILITY=3", "GLIB_DOMAIN=%s", log_domain ?: "", "GLIB_LEVEL=%d", (int) (level & G_LOG_LEVEL_MASK), - "TIMESTAMP_MONOTONIC=%lld.%06lld", (long long) (now / NM_UTILS_NS_PER_SECOND), (long long) ((now % NM_UTILS_NS_PER_SECOND) / 1000), - "TIMESTAMP_BOOTTIME=%lld.%06lld", (long long) (boottime / NM_UTILS_NS_PER_SECOND), (long long) ((boottime % NM_UTILS_NS_PER_SECOND) / 1000), + "TIMESTAMP_MONOTONIC=%lld.%06lld", (long long) (now / NM_UTILS_NSEC_PER_SEC), (long long) ((now % NM_UTILS_NSEC_PER_SEC) / 1000), + "TIMESTAMP_BOOTTIME=%lld.%06lld", (long long) (boottime / NM_UTILS_NSEC_PER_SEC), (long long) ((boottime % NM_UTILS_NSEC_PER_SEC) / 1000), NULL); } break; @@ -996,7 +996,7 @@ nm_logging_init (const char *logging_backend, gboolean debug) if (fetch_monotonic_timestamp) { /* ensure we read a monotonic timestamp. Reading the timestamp the first * time causes a logging message. We don't want to do that during _nm_log_impl. */ - nm_utils_get_monotonic_timestamp_ns (); + nm_utils_get_monotonic_timestamp_nsec (); } if (obsolete_debug_backend) diff --git a/src/nm-policy.c b/src/nm-policy.c index d322b2efea..7fd818b675 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -195,7 +195,7 @@ static void expire_ip6_delegations (NMPolicy *self) { NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE (self); - guint32 now = nm_utils_get_monotonic_timestamp_s (); + guint32 now = nm_utils_get_monotonic_timestamp_sec (); IP6PrefixDelegation *delegation = NULL; guint i; @@ -1549,7 +1549,7 @@ reset_connections_retries (gpointer user_data) priv->reset_retries_id = 0; min_stamp = 0; - now = nm_utils_get_monotonic_timestamp_s (); + now = nm_utils_get_monotonic_timestamp_sec (); connections = nm_settings_get_connections (priv->settings, NULL); for (i = 0; connections[i]; i++) { NMSettingsConnection *connection = connections[i]; @@ -1594,7 +1594,7 @@ _connection_autoconnect_retries_set (NMPolicy *self, gint32 retry_time = nm_settings_connection_autoconnect_retries_blocked_until (connection); g_warn_if_fail (retry_time != 0); - priv->reset_retries_id = g_timeout_add_seconds (MAX (0, retry_time - nm_utils_get_monotonic_timestamp_s ()), reset_connections_retries, self); + priv->reset_retries_id = g_timeout_add_seconds (MAX (0, retry_time - nm_utils_get_monotonic_timestamp_sec ()), reset_connections_retries, self); } } } diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c index 6aae808aeb..9fa2791fec 100644 --- a/src/platform/nm-fake-platform.c +++ b/src/platform/nm-fake-platform.c @@ -980,7 +980,7 @@ ip4_address_add (NMPlatform *platform, address.address = addr; address.peer_address = peer_addr; address.plen = plen; - address.timestamp = nm_utils_get_monotonic_timestamp_s (); + address.timestamp = nm_utils_get_monotonic_timestamp_sec (); address.lifetime = lifetime; address.preferred = preferred; address.n_ifa_flags = flags; @@ -1008,7 +1008,7 @@ ip6_address_add (NMPlatform *platform, address.address = addr; address.peer_address = (IN6_IS_ADDR_UNSPECIFIED (&peer_addr) || IN6_ARE_ADDR_EQUAL (&addr, &peer_addr)) ? in6addr_any : peer_addr; address.plen = plen; - address.timestamp = nm_utils_get_monotonic_timestamp_s (); + address.timestamp = nm_utils_get_monotonic_timestamp_sec (); address.lifetime = lifetime; address.preferred = preferred; address.n_ifa_flags = flags; diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 305ae52e3a..4f8c900491 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -738,7 +738,7 @@ _addrtime_timestamp_to_nm (guint32 timestamp, gint32 *out_now_nm) /* do all the calculations in milliseconds scale */ - now_nm = nm_utils_get_monotonic_timestamp_ms (); + now_nm = nm_utils_get_monotonic_timestamp_msec (); now_nl = nm_utils_clock_gettime_ms (CLOCK_MONOTONIC); nm_assert (now_nm >= 1000); @@ -748,13 +748,13 @@ _addrtime_timestamp_to_nm (guint32 timestamp, gint32 *out_now_nm) NM_SET_OUT (out_now_nm, now_nm / 1000); - /* converting the timestamp into nm_utils_get_monotonic_timestamp_ms() scale is + /* converting the timestamp into nm_utils_get_monotonic_timestamp_msec() scale is * a good guess but fails in the following situations: * * - If the address existed before start of the process, the timestamp in nm scale would * be negative or zero. In this case we default to 1. * - during hibernation, the CLOCK_MONOTONIC/timestamp drifts from - * nm_utils_get_monotonic_timestamp_ms() scale. + * nm_utils_get_monotonic_timestamp_msec() scale. */ if (result <= 1000) return 1; @@ -809,7 +809,7 @@ _addrtime_get_lifetimes (guint32 timestamp, if (now == 0) { /* strange. failed to detect the last-update time and assumed that timestamp is 1. */ nm_assert (timestamp == 1); - now = nm_utils_get_monotonic_timestamp_s (); + now = nm_utils_get_monotonic_timestamp_sec (); } if (timestamp < now) { guint32 diff = now - timestamp; @@ -5030,14 +5030,14 @@ delayed_action_to_string_full (DelayedActionType action_type, gpointer user_data data = user_data; if (data) { - gint64 timeout = data->timeout_abs_ns - nm_utils_get_monotonic_timestamp_ns (); + gint64 timeout = data->timeout_abs_ns - nm_utils_get_monotonic_timestamp_nsec (); char b[255]; nm_utils_strbuf_append (&buf, &buf_size, " (seq %u, timeout in %s%"G_GINT64_FORMAT".%09"G_GINT64_FORMAT", response-type %d%s%s)", data->seq_number, timeout < 0 ? "-" : "", - (timeout < 0 ? -timeout : timeout) / NM_UTILS_NS_PER_SECOND, - (timeout < 0 ? -timeout : timeout) % NM_UTILS_NS_PER_SECOND, + (timeout < 0 ? -timeout : timeout) / NM_UTILS_NSEC_PER_SEC, + (timeout < 0 ? -timeout : timeout) % NM_UTILS_NSEC_PER_SEC, (int) data->response_type, data->seq_result ? ", " : "", data->seq_result ? wait_for_nl_response_to_string (data->seq_result, NULL, b, sizeof (b)) : ""); @@ -5139,7 +5139,7 @@ delayed_action_wait_for_nl_response_complete_check (NMPlatform *platform, if (data->seq_result) delayed_action_wait_for_nl_response_complete (platform, i, data->seq_result); else if ( p_now_ns - && ((now_ns ?: (now_ns = nm_utils_get_monotonic_timestamp_ns ())) >= data->timeout_abs_ns)) { + && ((now_ns ?: (now_ns = nm_utils_get_monotonic_timestamp_nsec ())) >= data->timeout_abs_ns)) { /* the caller can optionally check for timeout by providing a p_now_ns argument. */ delayed_action_wait_for_nl_response_complete (platform, i, WAIT_FOR_NL_RESPONSE_RESULT_FAILED_TIMEOUT); } else if (force_result != WAIT_FOR_NL_RESPONSE_RESULT_UNKNOWN) @@ -5359,7 +5359,7 @@ delayed_action_schedule_WAIT_FOR_NL_RESPONSE (NMPlatform *platform, { DelayedActionWaitForNlResponseData data = { .seq_number = seq_number, - .timeout_abs_ns = nm_utils_get_monotonic_timestamp_ns () + (200 * (NM_UTILS_NS_PER_SECOND / 1000)), + .timeout_abs_ns = nm_utils_get_monotonic_timestamp_nsec () + (200 * (NM_UTILS_NSEC_PER_SEC / 1000)), .out_seq_result = out_seq_result, .out_errmsg = out_errmsg, .response_type = response_type, @@ -8799,7 +8799,7 @@ event_handler_read_netlink (NMPlatform *platform, gboolean wait_for_acks) int r; struct pollfd pfd; gboolean any = FALSE; - int timeout_ms; + int timeout_msec; struct { guint32 seq_number; gint64 timeout_abs_ns; @@ -8880,12 +8880,12 @@ after_read: _LOGT ("netlink: read: wait for ACK for sequence number %u...", next.seq_number); - timeout_ms = (next.timeout_abs_ns - next.now_ns) / (NM_UTILS_NS_PER_SECOND / 1000); + timeout_msec = (next.timeout_abs_ns - next.now_ns) / (NM_UTILS_NSEC_PER_SEC / 1000); memset (&pfd, 0, sizeof (pfd)); pfd.fd = nl_socket_get_fd (priv->nlh); pfd.events = POLLIN; - r = poll (&pfd, 1, MAX (1, timeout_ms)); + r = poll (&pfd, 1, MAX (1, timeout_msec)); if (r == 0) { /* timeout and there is nothing to read. */ diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 6795dde772..2636df9a08 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -4048,7 +4048,7 @@ nm_platform_ip4_address_sync (NMPlatform *self, { gs_unref_ptrarray GPtrArray *plat_addresses = NULL; const NMPlatformIP4Address *known_address; - gint32 now = nm_utils_get_monotonic_timestamp_s (); + gint32 now = nm_utils_get_monotonic_timestamp_sec (); GHashTable *plat_subnets = NULL; GHashTable *known_subnets = NULL; gs_unref_hashtable GHashTable *known_addresses_idx = NULL; @@ -4224,7 +4224,7 @@ nm_platform_ip6_address_sync (NMPlatform *self, gboolean full_sync) { gs_unref_ptrarray GPtrArray *plat_addresses = NULL; - gint32 now = nm_utils_get_monotonic_timestamp_s (); + gint32 now = nm_utils_get_monotonic_timestamp_sec (); guint i_plat, i_know; gs_unref_hashtable GHashTable *known_addresses_idx = NULL; NMPLookup lookup; @@ -4965,15 +4965,15 @@ nm_platform_ip_route_get (NMPlatform *self, #define IP4_DEV_ROUTE_BLACKLIST_GC_TIMEOUT_S ((int) (((IP4_DEV_ROUTE_BLACKLIST_TIMEOUT_MS + 999) * 3) / 1000)) static gint64 -_ip4_dev_route_blacklist_timeout_ms_get (gint64 timeout_ms) +_ip4_dev_route_blacklist_timeout_ms_get (gint64 timeout_msec) { - return timeout_ms >> 1; + return timeout_msec >> 1; } static gint64 -_ip4_dev_route_blacklist_timeout_ms_marked (gint64 timeout_ms) +_ip4_dev_route_blacklist_timeout_ms_marked (gint64 timeout_msec) { - return !!(timeout_ms & ((gint64) 1)); + return !!(timeout_msec & ((gint64) 1)); } static gboolean @@ -4992,7 +4992,7 @@ again: if (!priv->ip4_dev_route_blacklist_hash) goto out; - now_ms = nm_utils_get_monotonic_timestamp_ms (); + now_ms = nm_utils_get_monotonic_timestamp_msec (); g_hash_table_iter_init (&iter, priv->ip4_dev_route_blacklist_hash); while (g_hash_table_iter_next (&iter, (gpointer *) &p_obj, (gpointer *) &p_timeout_ms)) { @@ -5055,7 +5055,7 @@ _ip4_dev_route_blacklist_notify_route (NMPlatform *self, (gpointer *) &p_timeout_ms)) return; - now_ms = nm_utils_get_monotonic_timestamp_ms (); + now_ms = nm_utils_get_monotonic_timestamp_msec (); if (now_ms > _ip4_dev_route_blacklist_timeout_ms_get (*p_timeout_ms)) { /* already expired. Wait for gc. */ return; @@ -5086,7 +5086,7 @@ _ip4_dev_route_blacklist_gc_timeout_handle (gpointer user_data) nm_assert (priv->ip4_dev_route_blacklist_gc_timeout_id); - now_ms = nm_utils_get_monotonic_timestamp_ms (); + now_ms = nm_utils_get_monotonic_timestamp_msec (); g_hash_table_iter_init (&iter, priv->ip4_dev_route_blacklist_hash); while (g_hash_table_iter_next (&iter, (gpointer *) &p_obj, (gpointer *) &p_timeout_ms)) { @@ -5155,8 +5155,8 @@ nm_platform_ip4_dev_route_blacklist_set (NMPlatform *self, GHashTableIter iter; const NMPObject *p_obj; guint i; - gint64 timeout_ms; - gint64 timeout_ms_val; + gint64 timeout_msec; + gint64 timeout_msec_val; gint64 *p_timeout_ms; gboolean needs_check = FALSE; @@ -5191,8 +5191,8 @@ nm_platform_ip4_dev_route_blacklist_set (NMPlatform *self, nm_g_slice_free_fcn_gint64); } - timeout_ms = nm_utils_get_monotonic_timestamp_ms () + IP4_DEV_ROUTE_BLACKLIST_TIMEOUT_MS; - timeout_ms_val = (timeout_ms << 1) | ((gint64) 1); + timeout_msec = nm_utils_get_monotonic_timestamp_msec () + IP4_DEV_ROUTE_BLACKLIST_TIMEOUT_MS; + timeout_msec_val = (timeout_msec << 1) | ((gint64) 1); for (i = 0; i < ip4_dev_route_blacklist->len; i++) { const NMPObject *o; @@ -5206,7 +5206,7 @@ nm_platform_ip4_dev_route_blacklist_set (NMPlatform *self, /* un-expire and reuse the entry. */ _LOGT ("ip4-dev-route: register %s (update)", nmp_object_to_string (p_obj, NMP_OBJECT_TO_STRING_PUBLIC, NULL, 0)); - *p_timeout_ms = timeout_ms_val; + *p_timeout_ms = timeout_msec_val; continue; } } @@ -5214,7 +5214,7 @@ nm_platform_ip4_dev_route_blacklist_set (NMPlatform *self, _LOGT ("ip4-dev-route: register %s", nmp_object_to_string (o, NMP_OBJECT_TO_STRING_PUBLIC, NULL, 0)); p_timeout_ms = g_slice_new (gint64); - *p_timeout_ms = timeout_ms_val; + *p_timeout_ms = timeout_msec_val; g_hash_table_replace (priv->ip4_dev_route_blacklist_hash, (gpointer) nmp_object_ref (o), p_timeout_ms); @@ -6054,7 +6054,7 @@ nm_platform_ip4_address_to_string (const NMPlatformIP4Address *address, char *bu char str_lft[30], str_pref[30], str_time[50], s_source[50]; char *str_peer = NULL; const char *str_lft_p, *str_pref_p, *str_time_p; - gint32 now = nm_utils_get_monotonic_timestamp_s (); + gint32 now = nm_utils_get_monotonic_timestamp_sec (); if (!nm_utils_to_string_buffer_init_null (address, &buf, &len)) return buf; @@ -6167,7 +6167,7 @@ nm_platform_ip6_address_to_string (const NMPlatformIP6Address *address, char *bu char str_dev[TO_STRING_DEV_BUF_SIZE]; char *str_peer = NULL; const char *str_lft_p, *str_pref_p, *str_time_p; - gint32 now = nm_utils_get_monotonic_timestamp_s (); + gint32 now = nm_utils_get_monotonic_timestamp_sec (); if (!nm_utils_to_string_buffer_init_null (address, &buf, &len)) return buf; diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index 4bd8e34d1e..a31564ed3f 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -287,7 +287,7 @@ typedef enum { * 2 @lifetime==@preferred==NM_PLATFORM_LIFETIME_PERMANENT: @timestamp is irrelevant (but mostly * set to 0). Such addresses are permanent. * 3 Non permanent addresses should (almost) always have @timestamp > 0. 0 is not a valid timestamp - * and never returned by nm_utils_get_monotonic_timestamp_s(). In this case @valid/@preferred + * and never returned by nm_utils_get_monotonic_timestamp_sec(). In this case @valid/@preferred * is anchored at @timestamp. * 4 Non permanent addresses with @timestamp == 0 are implicitly anchored at *now*, thus the time * moves as time goes by. This is usually not useful, except e.g. nm_platform_ip[46]_address_add(). @@ -325,7 +325,7 @@ typedef struct { /** * NMPlatformIP4Address: - * @timestamp: timestamp as returned by nm_utils_get_monotonic_timestamp_s() + * @timestamp: timestamp as returned by nm_utils_get_monotonic_timestamp_sec() **/ struct _NMPlatformIP4Address { __NMPlatformIPAddress_COMMON; @@ -349,7 +349,7 @@ struct _NMPlatformIP4Address { /** * NMPlatformIP6Address: - * @timestamp: timestamp as returned by nm_utils_get_monotonic_timestamp_s() + * @timestamp: timestamp as returned by nm_utils_get_monotonic_timestamp_sec() **/ struct _NMPlatformIP6Address { __NMPlatformIPAddress_COMMON; diff --git a/src/platform/tests/test-common.c b/src/platform/tests/test-common.c index b93213ef74..7d31e920b8 100644 --- a/src/platform/tests/test-common.c +++ b/src/platform/tests/test-common.c @@ -553,7 +553,7 @@ _wait_for_signal_timeout (gpointer user_data) } guint -nmtstp_wait_for_signal (NMPlatform *platform, gint64 timeout_ms) +nmtstp_wait_for_signal (NMPlatform *platform, gint64 timeout_msec) { WaitForSignalData data = { 0 }; gulong id_link, id_ip4_address, id_ip6_address, id_ip4_route, id_ip6_route; @@ -568,7 +568,7 @@ nmtstp_wait_for_signal (NMPlatform *platform, gint64 timeout_ms) id_ip4_route = g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data); id_ip6_route = g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, G_CALLBACK (_wait_for_signal_cb), &data); - /* if timeout_ms is negative, it means the wait-time already expired. + /* if timeout_msec is negative, it means the wait-time already expired. * Maybe, we should do nothing and return right away, without even * processing events from platform. However, that inconsistency (of not * processing events from mainloop) is inconvenient. @@ -578,7 +578,7 @@ nmtstp_wait_for_signal (NMPlatform *platform, gint64 timeout_ms) * a zero timeout: we check whether there are any events pending in platform, * and quite the mainloop immediately afterwards. But we always check. */ - data.id = g_timeout_add (CLAMP (timeout_ms, 0, G_MAXUINT32), + data.id = g_timeout_add (CLAMP (timeout_msec, 0, G_MAXUINT32), _wait_for_signal_timeout, &data); g_main_loop_run (data.loop); @@ -603,7 +603,7 @@ nmtstp_wait_for_signal_until (NMPlatform *platform, gint64 until_ms) guint signal_counts; while (TRUE) { - now = nm_utils_get_monotonic_timestamp_ms (); + now = nm_utils_get_monotonic_timestamp_msec (); if (until_ms < now) return 0; @@ -615,11 +615,11 @@ nmtstp_wait_for_signal_until (NMPlatform *platform, gint64 until_ms) } const NMPlatformLink * -nmtstp_wait_for_link (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, gint64 timeout_ms) +nmtstp_wait_for_link (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, gint64 timeout_msec) { return nmtstp_wait_for_link_until (platform, ifname, expected_link_type, - timeout_ms - ? nm_utils_get_monotonic_timestamp_ms () + timeout_ms + timeout_msec + ? nm_utils_get_monotonic_timestamp_msec () + timeout_msec : 0); } @@ -633,7 +633,7 @@ nmtstp_wait_for_link_until (NMPlatform *platform, const char *ifname, NMLinkType _init_platform (&platform, FALSE); while (TRUE) { - now = nm_utils_get_monotonic_timestamp_ms (); + now = nm_utils_get_monotonic_timestamp_msec (); plink = nm_platform_link_get_by_ifname (platform, ifname); if ( plink @@ -704,7 +704,7 @@ nmtstp_ip_address_check_lifetime (const NMPlatformIPAddress *addr, g_assert (addr); if (now == -1) - now = nm_utils_get_monotonic_timestamp_s (); + now = nm_utils_get_monotonic_timestamp_sec (); g_assert (now > 0); g_assert (expected_preferred <= expected_lifetime); @@ -750,7 +750,7 @@ nmtstp_ip_address_assert_lifetime (const NMPlatformIPAddress *addr, g_assert (addr); if (now == -1) - now = nm_utils_get_monotonic_timestamp_s (); + now = nm_utils_get_monotonic_timestamp_sec (); g_assert (now > 0); g_assert (expected_preferred <= expected_lifetime); @@ -886,7 +886,7 @@ _ip_address_add (NMPlatform *platform, } /* Let's wait until we see the address. */ - end_time = nm_utils_get_monotonic_timestamp_ms () + 500; + end_time = nm_utils_get_monotonic_timestamp_msec () + 500; do { if (external_command) @@ -1091,7 +1091,7 @@ _ip_address_del (NMPlatform *platform, } /* Let's wait until we get the result */ - end_time = nm_utils_get_monotonic_timestamp_ms () + 250; + end_time = nm_utils_get_monotonic_timestamp_msec () + 250; do { if (external_command) nm_platform_process_events (platform); @@ -1736,7 +1736,7 @@ nmtstp_link_delete (NMPlatform *platform, } /* Let's wait until we get the result */ - end_time = nm_utils_get_monotonic_timestamp_ms () + 250; + end_time = nm_utils_get_monotonic_timestamp_msec () + 250; do { if (external_command) nm_platform_process_events (platform); @@ -1785,7 +1785,7 @@ nmtstp_link_set_updown (NMPlatform *platform, } /* Let's wait until we get the result */ - end_time = nm_utils_get_monotonic_timestamp_ms () + 250; + end_time = nm_utils_get_monotonic_timestamp_msec () + 250; do { if (external_command) nm_platform_process_events (platform); diff --git a/src/platform/tests/test-common.h b/src/platform/tests/test-common.h index c571df6a06..6f5a6cf62b 100644 --- a/src/platform/tests/test-common.h +++ b/src/platform/tests/test-common.h @@ -32,13 +32,13 @@ const NMLogDomain __domain = (domain); \ \ if (nm_logging_enabled (__level, __domain)) { \ - gint64 _ts = nm_utils_get_monotonic_timestamp_ns (); \ + gint64 _ts = nm_utils_get_monotonic_timestamp_nsec (); \ \ _nm_log (__level, __domain, 0, NULL, NULL, \ "%s[%ld.%09ld]: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \ _NMLOG_PREFIX_NAME, \ - (long) (_ts / NM_UTILS_NS_PER_SECOND), \ - (long) (_ts % NM_UTILS_NS_PER_SECOND) \ + (long) (_ts / NM_UTILS_NSEC_PER_SEC), \ + (long) (_ts % NM_UTILS_NSEC_PER_SEC) \ _NM_UTILS_MACRO_REST (__VA_ARGS__)); \ } \ } G_STMT_END @@ -101,14 +101,14 @@ int nmtstp_run_command (const char *format, ...) _nm_printf (1, 2); /*****************************************************************************/ -guint nmtstp_wait_for_signal (NMPlatform *platform, gint64 timeout_ms); +guint nmtstp_wait_for_signal (NMPlatform *platform, gint64 timeout_msec); guint nmtstp_wait_for_signal_until (NMPlatform *platform, gint64 until_ms); -const NMPlatformLink *nmtstp_wait_for_link (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, gint64 timeout_ms); +const NMPlatformLink *nmtstp_wait_for_link (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, gint64 timeout_msec); const NMPlatformLink *nmtstp_wait_for_link_until (NMPlatform *platform, const char *ifname, NMLinkType expected_link_type, gint64 until_ms); -#define nmtstp_assert_wait_for_signal(platform, timeout_ms) \ +#define nmtstp_assert_wait_for_signal(platform, timeout_msec) \ G_STMT_START { \ - if (nmtstp_wait_for_signal (platform, timeout_ms) == 0) \ + if (nmtstp_wait_for_signal (platform, timeout_msec) == 0) \ g_assert_not_reached (); \ } G_STMT_END @@ -118,8 +118,8 @@ const NMPlatformLink *nmtstp_wait_for_link_until (NMPlatform *platform, const ch g_assert_not_reached (); \ } G_STMT_END -#define nmtstp_assert_wait_for_link(platform, ifname, expected_link_type, timeout_ms) \ - nmtst_assert_nonnull (nmtstp_wait_for_link (platform, ifname, expected_link_type, timeout_ms)) +#define nmtstp_assert_wait_for_link(platform, ifname, expected_link_type, timeout_msec) \ + nmtst_assert_nonnull (nmtstp_wait_for_link (platform, ifname, expected_link_type, timeout_msec)) #define nmtstp_assert_wait_for_link_until(platform, ifname, expected_link_type, until_ms) \ nmtst_assert_nonnull (nmtstp_wait_for_link_until (platform, ifname, expected_link_type, until_ms)) diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c index 37e1cde516..0e166a5f7f 100644 --- a/src/platform/tests/test-link.c +++ b/src/platform/tests/test-link.c @@ -2095,7 +2095,7 @@ test_vlan_set_xgress (void) static void test_create_many_links_do (guint n_devices) { - gint64 time, start_time = nm_utils_get_monotonic_timestamp_ns (); + gint64 time, start_time = nm_utils_get_monotonic_timestamp_nsec (); guint i; char name[64]; const NMPlatformLink *pllink; @@ -2149,8 +2149,8 @@ test_create_many_links_do (guint n_devices) _LOGI (">>> process events after deleting devices..."); nm_platform_process_events (NM_PLATFORM_GET); - time = nm_utils_get_monotonic_timestamp_ns () - start_time; - _LOGI (">>> finished in %ld.%09ld seconds", (long) (time / NM_UTILS_NS_PER_SECOND), (long) (time % NM_UTILS_NS_PER_SECOND)); + time = nm_utils_get_monotonic_timestamp_nsec () - start_time; + _LOGI (">>> finished in %ld.%09ld seconds", (long) (time / NM_UTILS_NSEC_PER_SEC), (long) (time % NM_UTILS_NSEC_PER_SEC)); } static void diff --git a/src/platform/tests/test-route.c b/src/platform/tests/test-route.c index f8b1bb9abf..e2c1ed80e4 100644 --- a/src/platform/tests/test-route.c +++ b/src/platform/tests/test-route.c @@ -19,7 +19,7 @@ static void _wait_for_ipv4_addr_device_route (NMPlatform *platform, - gint64 timeout_ms, + gint64 timeout_msec, int ifindex, in_addr_t addr, guint8 plen) @@ -55,7 +55,7 @@ _wait_for_ipv4_addr_device_route (NMPlatform *platform, static void _wait_for_ipv6_addr_non_tentative (NMPlatform *platform, - gint64 timeout_ms, + gint64 timeout_msec, int ifindex, guint addr_n, const struct in6_addr *addrs) @@ -67,7 +67,7 @@ _wait_for_ipv6_addr_non_tentative (NMPlatform *platform, * small amount of time, which prevents the immediate addition of the route * with RTA_PREFSRC */ - NMTST_WAIT_ASSERT (timeout_ms, { + NMTST_WAIT_ASSERT (timeout_msec, { gboolean should_wait = FALSE; const NMPlatformIP6Address *plt_addr; diff --git a/src/settings/nm-settings-connection.c b/src/settings/nm-settings-connection.c index ccbab807ab..555d1e1a6f 100644 --- a/src/settings/nm-settings-connection.c +++ b/src/settings/nm-settings-connection.c @@ -2365,7 +2365,7 @@ _autoconnect_retries_set (NMSettingsConnection *self, * the tracking of resetting the retry count in NMPolicy needs adjustment * in _connection_autoconnect_retries_set() (as it would need to re-evaluate * the next-timeout every time a connection gets blocked). */ - priv->autoconnect_retries_blocked_until = nm_utils_get_monotonic_timestamp_s () + AUTOCONNECT_RESET_RETRIES_TIMER; + priv->autoconnect_retries_blocked_until = nm_utils_get_monotonic_timestamp_sec () + AUTOCONNECT_RESET_RETRIES_TIMER; } } diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index f964fb16e4..bbf4595463 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -548,7 +548,7 @@ _startup_complete_check (NMSettings *self, goto ready; if (!now_us) - now_us = nm_utils_get_monotonic_timestamp_us (); + now_us = nm_utils_get_monotonic_timestamp_usec (); next_expiry = 0; @@ -654,7 +654,7 @@ _startup_complete_notify_connection (NMSettings *self, } else scd = g_hash_table_lookup (priv->startup_complete_idx, &sett_conn); if (!scd) { - now_us = nm_utils_get_monotonic_timestamp_us (); + now_us = nm_utils_get_monotonic_timestamp_usec (); scd = g_slice_new (StartupCompleteData); *scd = (StartupCompleteData) { .sett_conn = g_object_ref (sett_conn), diff --git a/src/supplicant/nm-supplicant-interface.c b/src/supplicant/nm-supplicant-interface.c index 6ef2931129..794955b3d9 100644 --- a/src/supplicant/nm-supplicant-interface.c +++ b/src/supplicant/nm-supplicant-interface.c @@ -160,7 +160,7 @@ typedef struct { GHashTable * peer_proxies; - gint64 last_scan; /* timestamp as returned by nm_utils_get_monotonic_timestamp_ms() */ + gint64 last_scan; /* timestamp as returned by nm_utils_get_monotonic_timestamp_msec() */ NMSupplicantAuthState auth_state; } NMSupplicantInterfacePrivate; @@ -241,7 +241,7 @@ bss_proxy_properties_changed_cb (GDBusProxy *proxy, NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); if (priv->scanning) - priv->last_scan = nm_utils_get_monotonic_timestamp_ms (); + priv->last_scan = nm_utils_get_monotonic_timestamp_msec (); g_signal_emit (self, signals[BSS_UPDATED], 0, g_dbus_proxy_get_object_path (proxy), @@ -492,7 +492,7 @@ set_state (NMSupplicantInterface *self, NMSupplicantInterfaceState new_state) if ( priv->state == NM_SUPPLICANT_INTERFACE_STATE_SCANNING || old_state == NM_SUPPLICANT_INTERFACE_STATE_SCANNING) - priv->last_scan = nm_utils_get_monotonic_timestamp_ms (); + priv->last_scan = nm_utils_get_monotonic_timestamp_msec (); /* Disconnect reason is no longer relevant when not in the DISCONNECTED state */ if (priv->state != NM_SUPPLICANT_INTERFACE_STATE_DISCONNECTED) @@ -554,7 +554,7 @@ set_scanning (NMSupplicantInterface *self, gboolean new_scanning) /* Cache time of last scan completion */ if (priv->scanning == FALSE) - priv->last_scan = nm_utils_get_monotonic_timestamp_ms (); + priv->last_scan = nm_utils_get_monotonic_timestamp_msec (); _notify (self, PROP_SCANNING); } @@ -1286,7 +1286,7 @@ wpas_iface_scan_done (GDBusProxy *proxy, NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); /* Cache last scan completed time */ - priv->last_scan = nm_utils_get_monotonic_timestamp_ms (); + priv->last_scan = nm_utils_get_monotonic_timestamp_msec (); priv->scan_done_success |= success; scan_done_emit_signal (self); } @@ -1301,7 +1301,7 @@ wpas_iface_bss_added (GDBusProxy *proxy, NMSupplicantInterfacePrivate *priv = NM_SUPPLICANT_INTERFACE_GET_PRIVATE (self); if (priv->scanning) - priv->last_scan = nm_utils_get_monotonic_timestamp_ms (); + priv->last_scan = nm_utils_get_monotonic_timestamp_msec (); bss_add_new (self, path); } diff --git a/src/tests/test-core-with-expect.c b/src/tests/test-core-with-expect.c index 74e1043b33..555b962473 100644 --- a/src/tests/test-core-with-expect.c +++ b/src/tests/test-core-with-expect.c @@ -20,7 +20,7 @@ static void test_nm_utils_monotonic_timestamp_as_boottime (void) { - gint64 timestamp_ns_per_tick, now, now_boottime, now_boottime_2, now_boottime_3; + gint64 timestamp_nsec_per_tick, now, now_boottime, now_boottime_2, now_boottime_3; struct timespec tp; clockid_t clockid; guint i; @@ -35,22 +35,22 @@ test_nm_utils_monotonic_timestamp_as_boottime (void) if (clock_gettime (clockid, &tp) != 0) g_assert_not_reached (); - now_boottime = ( ((gint64) tp.tv_sec) * NM_UTILS_NS_PER_SECOND ) + ((gint64) tp.tv_nsec); + now_boottime = ( ((gint64) tp.tv_sec) * NM_UTILS_NSEC_PER_SEC ) + ((gint64) tp.tv_nsec); - now = nm_utils_get_monotonic_timestamp_ns (); + now = nm_utils_get_monotonic_timestamp_nsec (); now_boottime_2 = nm_utils_monotonic_timestamp_as_boottime (now, 1); g_assert_cmpint (now_boottime_2, >=, 0); g_assert_cmpint (now_boottime_2, >=, now_boottime); - g_assert_cmpint (now_boottime_2 - now_boottime, <=, NM_UTILS_NS_PER_SECOND / 10); + g_assert_cmpint (now_boottime_2 - now_boottime, <=, NM_UTILS_NSEC_PER_SEC / 10); g_assert_cmpint (now, ==, nm_utils_monotonic_timestamp_from_boottime (now_boottime_2, 1)); - for (timestamp_ns_per_tick = 1; timestamp_ns_per_tick <= NM_UTILS_NS_PER_SECOND; timestamp_ns_per_tick *= 10) { - now_boottime_3 = nm_utils_monotonic_timestamp_as_boottime (now / timestamp_ns_per_tick, timestamp_ns_per_tick); + for (timestamp_nsec_per_tick = 1; timestamp_nsec_per_tick <= NM_UTILS_NSEC_PER_SEC; timestamp_nsec_per_tick *= 10) { + now_boottime_3 = nm_utils_monotonic_timestamp_as_boottime (now / timestamp_nsec_per_tick, timestamp_nsec_per_tick); - g_assert_cmpint (now_boottime_2 / timestamp_ns_per_tick, ==, now_boottime_3); - g_assert_cmpint (now / timestamp_ns_per_tick, ==, nm_utils_monotonic_timestamp_from_boottime (now_boottime_3, timestamp_ns_per_tick)); + g_assert_cmpint (now_boottime_2 / timestamp_nsec_per_tick, ==, now_boottime_3); + g_assert_cmpint (now / timestamp_nsec_per_tick, ==, nm_utils_monotonic_timestamp_from_boottime (now_boottime_3, timestamp_nsec_per_tick)); } } } diff --git a/src/tests/test-systemd.c b/src/tests/test-systemd.c index faed0e567b..6425c29488 100644 --- a/src/tests/test-systemd.c +++ b/src/tests/test-systemd.c @@ -27,7 +27,7 @@ _nm_utils_set_testing (NMUtilsTestFlags flags) } gint32 -nm_utils_get_monotonic_timestamp_s (void) +nm_utils_get_monotonic_timestamp_sec (void) { return 1; } |