Fix clocks (ebpf.plugin and others) (#22009)
thiagoftsm committed
Mar 23, 2026 at 20:58 UTC
790f4a6f0ad44a63b3a6c6132789b4ed557f3611
2 files changed
+8
-4
src/libnetdata/clocks/clocks.c
+7
-2
@@ -331,10 +331,15 @@ static XXH64_hash_t heartbeat_hash(usec_t step, size_t statistics_id) {
331
static usec_t heartbeat_randomness(XXH64_hash_t hash) {
332
usec_t offset_ut = HEARTBEAT_MIN_OFFSET_UT + (hash % HEARTBEAT_RANDOM_OFFSET_UT);
333
334
- // Calculate the scheduler tick interval in microseconds
335
- usec_t scheduler_step_ut = USEC_PER_SEC / (usec_t)system_hz;
334
+ // A zero HZ value turns heartbeat initialization into SIGFPE.
335
+ usec_t hz = system_hz ? (usec_t)system_hz : 100;
336
+
337
+ // Calculate the scheduler tick interval in microseconds.
338
+ usec_t scheduler_step_ut = USEC_PER_SEC / hz;
339
if(scheduler_step_ut > 10 * USEC_PER_MS)
340
scheduler_step_ut = 10 * USEC_PER_MS;
341
+ else if(unlikely(!scheduler_step_ut))
342
+ scheduler_step_ut = 1;
343
344
// if the offset is close to the scheduler tick, move it away from it
345
if(offset_ut % scheduler_step_ut < scheduler_step_ut / 4)
src/libnetdata/os/os.c
+1
-2
@@ -10,7 +10,7 @@ unsigned int system_hz = 100;
10
void os_get_system_HZ(void) {
11
long ticks;
12
13
- if ((ticks = sysconf(_SC_CLK_TCK)) == -1) {
13
+ if ((ticks = sysconf(_SC_CLK_TCK)) <= 0) {
14
netdata_log_error("Cannot get system clock ticks");
15
ticks = 100;
16
}
@@ -36,4 +36,3 @@ const char *os_type = "macos";
36
#if defined(OS_WINDOWS)
37
const char *os_type = "windows";
38
#endif
39
-