odhcdp: use a more suitable clock
authorDavid Härdeman <[email protected]>
Fri, 10 Oct 2025 20:57:08 +0000 (22:57 +0200)
committerÁlvaro Fernández Rojas <[email protected]>
Tue, 21 Oct 2025 17:01:11 +0000 (19:01 +0200)
In my testing, CLOCK_MONOTONIC_COARSE uses about 1/3 of the CPU cycles.

And the accuracy is completely irrelevant.

Signed-off-by: David Härdeman <[email protected]>
Link: https://github.com/openwrt/odhcpd/pull/282
Signed-off-by: Álvaro Fernández Rojas <[email protected]>
src/odhcpd.c

index 4b17a161152c6e7f672b9b21bf9e0d4e5a984bd7..ef67acc630a1c142be0b29eab29179dccd3333dd 100644 (file)
@@ -551,7 +551,7 @@ int odhcpd_urandom(void *data, size_t len)
 time_t odhcpd_time(void)
 {
        struct timespec ts;
-       clock_gettime(CLOCK_MONOTONIC, &ts);
+       clock_gettime(CLOCK_MONOTONIC_COARSE, &ts);
        return ts.tv_sec;
 }