From e92f260e7a128c49e1a2884bad8399c64bd8fcfe Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 14 Apr 2025 16:12:38 -0400 Subject: [PATCH] MT#55283 convert daemon/ to int64_t Change-Id: Ie557204821fddfa5af0be96cc8f0ff2dd093fc7c --- daemon/audio_player.c | 6 +++--- daemon/control_ng.c | 16 +++++++++------- daemon/helpers.c | 5 ++--- daemon/ice.c | 12 ++++++------ daemon/main.c | 10 +++++----- daemon/media_socket.c | 8 ++++---- daemon/redis.c | 14 +++++++------- daemon/statistics.c | 8 ++++---- include/redis.h | 2 +- 9 files changed, 41 insertions(+), 40 deletions(-) diff --git a/daemon/audio_player.c b/daemon/audio_player.c index de3df8f23..e012c79b2 100644 --- a/daemon/audio_player.c +++ b/daemon/audio_player.c @@ -10,7 +10,7 @@ struct audio_player { struct media_player *mp; struct mix_buffer mb; - struct timeval last_run; + int64_t last_run; unsigned int ptime_us; unsigned int ptime; // in samples @@ -28,7 +28,7 @@ static bool audio_player_run(struct media_player *mp) { if (!ap || !ap->ptime_us) return false; - ap->last_run = timeval_from_us(rtpe_now); // equals mp->next_run + ap->last_run = rtpe_now; // equals mp->next_run unsigned int size; void *buf = mix_buffer_read_fast(&ap->mb, ap->ptime, &size); @@ -167,7 +167,7 @@ void audio_player_start(struct call_media *m) { ilogs(transcoding, LOG_DEBUG, "Starting audio player"); - ap->last_run = timeval_from_us(rtpe_now); + ap->last_run = rtpe_now; mp->next_run = rtpe_now; mp->next_run += ap->ptime_us; diff --git a/daemon/control_ng.c b/daemon/control_ng.c index c9f4b56a7..216e448a8 100644 --- a/daemon/control_ng.c +++ b/daemon/control_ng.c @@ -670,7 +670,7 @@ static void control_ng_process_payload(ng_ctx *hctx, str *reply, str *data, cons str cmd = STR_NULL, callid; const char *errstr, *resultstr; GString *log_str; - struct timeval cmd_start, cmd_stop, cmd_process_time = {0}; + int64_t cmd_start, cmd_stop, cmd_process_time = {0}; struct control_ng_stats* cur = get_control_ng_stats(&sin->address); ng_command_ctx_t command_ctx = {.opmode = -1}; @@ -739,7 +739,7 @@ static void control_ng_process_payload(ng_ctx *hctx, str *reply, str *data, cons resultstr = "ok"; // start command timer - gettimeofday(&cmd_start, NULL); + cmd_start = now_us(); switch (__csh_lookup(&cmd)) { case CSH_LOOKUP("ping"): @@ -863,14 +863,14 @@ static void control_ng_process_payload(ng_ctx *hctx, str *reply, str *data, cons CH(homer_trace_msg_in, hctx, data); // stop command timer - gettimeofday(&cmd_stop, NULL); + cmd_stop = now_us(); //print command duration - cmd_process_time = timeval_subtract(cmd_stop, cmd_start); + cmd_process_time = cmd_stop - cmd_start; if (command_ctx.opmode >= 0 && command_ctx.opmode < OP_COUNT) { mutex_lock(&cur->cmd[command_ctx.opmode].lock); cur->cmd[command_ctx.opmode].count++; - cur->cmd[command_ctx.opmode].time += timeval_us(cmd_process_time); + cur->cmd[command_ctx.opmode].time += cmd_process_time; mutex_unlock(&cur->cmd[command_ctx.opmode].lock); } @@ -881,7 +881,7 @@ static void control_ng_process_payload(ng_ctx *hctx, str *reply, str *data, cons // update interval statistics RTPE_STATS_INC(ng_commands[command_ctx.opmode]); - RTPE_STATS_SAMPLE(ng_command_times[command_ctx.opmode], timeval_us(cmd_process_time)); + RTPE_STATS_SAMPLE(ng_command_times[command_ctx.opmode], cmd_process_time); goto send_resp; @@ -902,7 +902,9 @@ err_send: send_resp: if (cmd.s) { - ilogs(control, LOG_INFO, "Replying to '"STR_FORMAT"' from %s (elapsed time %llu.%06llu sec)", STR_FMT(&cmd), addr, (unsigned long long)cmd_process_time.tv_sec, (unsigned long long)cmd_process_time.tv_usec); + ilogs(control, LOG_INFO, "Replying to '" STR_FORMAT "'" + "from %s (elapsed time %" PRId64 ".%06" PRId64 " sec)", + STR_FMT(&cmd), addr, cmd_process_time / 1000000, cmd_process_time % 1000000); if (get_log_level(control) >= LOG_DEBUG) { log_str = g_string_sized_new(256); diff --git a/daemon/helpers.c b/daemon/helpers.c index 5bd81beb4..d870fedab 100644 --- a/daemon/helpers.c +++ b/daemon/helpers.c @@ -309,9 +309,8 @@ static void thread_looper_helper(void *fp) { if (ret == TLA_BREAK) break; - struct timeval stop; - gettimeofday(&stop, NULL); - int64_t duration_us = timeval_diff(stop, timeval_from_us(rtpe_now)); + int64_t stop = now_us(); + int64_t duration_us = stop - rtpe_now; if (duration_us > warn_limit_us) ilog(LOG_WARN, "Run time of timer \"%s\": %" PRId64" .%06" PRId64" sec, " "exceeding limit of %" PRId64" %% (%" PRId64" .%06" PRId64" sec)", diff --git a/daemon/ice.c b/daemon/ice.c index 386956ca2..67757794f 100644 --- a/daemon/ice.c +++ b/daemon/ice.c @@ -817,7 +817,7 @@ static void __do_ice_checks(struct ice_agent *ag) { struct ice_candidate_pair *pair, *highest = NULL, *frozen = NULL, *valid; stream_fd *sfd; GQueue retransmits = G_QUEUE_INIT; - struct timeval next_run = {0,0}; + int64_t next_run = 0; int have_more = 0; if (!ag) { @@ -839,7 +839,7 @@ static void __do_ice_checks(struct ice_agent *ag) { if (AGENT_ISSET(ag, CONTROLLING) && !AGENT_ISSET(ag, NOMINATING) && ag->start_nominating) { if (timeval_cmp(timeval_from_us(rtpe_now), timeval_from_us(ag->start_nominating)) >= 0) __nominate_pairs(ag); - next_run = timeval_lowest(next_run, timeval_from_us(ag->start_nominating)); + next_run = timeval_us(timeval_lowest(timeval_from_us(next_run), timeval_from_us(ag->start_nominating))); } /* triggered checks are preferred */ @@ -847,7 +847,7 @@ static void __do_ice_checks(struct ice_agent *ag) { if (pair) { __DBG("running triggered check on " PAIR_FORMAT, PAIR_FMT(pair)); PAIR_CLEAR(pair, TRIGGERED); - next_run = timeval_from_us(rtpe_now); + next_run = rtpe_now; goto check; } @@ -878,7 +878,7 @@ static void __do_ice_checks(struct ice_agent *ag) { g_queue_push_tail(&retransmits, pair); /* can't run check directly due to locks */ else - next_run = timeval_lowest(next_run, timeval_from_us(pair->retransmit)); + next_run = timeval_us(timeval_lowest(timeval_from_us(next_run), timeval_from_us(pair->retransmit))); continue; } @@ -927,8 +927,8 @@ check: /* determine when to run next */ if (have_more) __agent_schedule(ag, 0); - else if (next_run.tv_sec) - __agent_schedule_abs(ag, timeval_us(next_run)); /* for retransmits */ + else if (next_run) + __agent_schedule_abs(ag, next_run); /* for retransmits */ } static void __agent_shutdown(struct ice_agent *ag) { diff --git a/daemon/main.c b/daemon/main.c index 8d0c7ecdf..ea39fc6f4 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -1715,11 +1715,11 @@ static void do_redis_restore(void) { if (!rtpe_redis) return; - struct timeval redis_start, redis_stop; + int64_t redis_start, redis_stop; double redis_diff = 0; // start redis restore timer - gettimeofday(&redis_start, NULL); + redis_start = now_us(); // restore if (rtpe_redis_notify) { @@ -1747,11 +1747,11 @@ static void do_redis_restore(void) { } // stop redis restore timer - gettimeofday(&redis_stop, NULL); + redis_stop = now_us(); // print redis restore duration - redis_diff += timeval_diff(redis_stop, redis_start) / 1000.0; - ilog(LOG_INFO, "Redis restore time = %.0lf ms", redis_diff); + redis_diff += redis_stop - redis_start; + ilog(LOG_INFO, "Redis restore time = %.0lf ms", redis_diff / 1000.0); } diff --git a/daemon/media_socket.c b/daemon/media_socket.c index 9a476456b..3a20b88d3 100644 --- a/daemon/media_socket.c +++ b/daemon/media_socket.c @@ -89,7 +89,7 @@ struct late_port_release { }; struct interface_stats_interval { struct interface_stats_block stats; - struct timeval last_run; + int64_t last_run; }; @@ -3413,10 +3413,10 @@ struct interface_stats_block *interface_sampled_rate_stats_get(struct interface_ ret = g_new0(__typeof(*ret), 1); g_hash_table_insert(s->ht, lif, ret); } - if (ret->last_run.tv_sec) - *time_diff_us = timeval_diff(timeval_from_us(rtpe_now), ret->last_run); + if (ret->last_run) + *time_diff_us = rtpe_now - ret->last_run; else *time_diff_us = 0; - ret->last_run = timeval_from_us(rtpe_now); + ret->last_run = rtpe_now; return &ret->stats; } diff --git a/daemon/redis.c b/daemon/redis.c index fc3e8b6b9..ea18344be 100644 --- a/daemon/redis.c +++ b/daemon/redis.c @@ -227,16 +227,16 @@ static void redis_consume(struct redis *r) { } } -int redis_set_timeout(struct redis* r, int timeout) { +int redis_set_timeout(struct redis* r, int64_t timeout) { struct timeval tv_cmd; if (!timeout) return 0; - tv_cmd.tv_sec = (int) timeout / 1000; - tv_cmd.tv_usec = (int) (timeout % 1000) * 1000; + tv_cmd.tv_sec = timeout / 1000; + tv_cmd.tv_usec = (timeout % 1000) * 1000; if (redisSetTimeout(r->ctx, tv_cmd)) return -1; - ilog(LOG_INFO, "Setting timeout for Redis commands to %d milliseconds",timeout); + ilog(LOG_INFO, "Setting timeout for Redis commands to %" PRId64 " milliseconds", timeout); return 0; } @@ -265,7 +265,7 @@ static int redis_connect(struct redis *r, int wait, bool resolve) { struct timeval tv; redisReply *rp; char *s; - int cmd_timeout, connect_timeout; + int64_t cmd_timeout, connect_timeout; sockaddr_t a; if (r->ctx) @@ -276,8 +276,8 @@ static int redis_connect(struct redis *r, int wait, bool resolve) { connect_timeout = atomic_get_na(&rtpe_config.redis_connect_timeout); cmd_timeout = atomic_get_na(&rtpe_config.redis_cmd_timeout); - tv.tv_sec = (int) connect_timeout / 1000; - tv.tv_usec = (int) (connect_timeout % 1000) * 1000; + tv.tv_sec = connect_timeout / 1000; + tv.tv_usec = (connect_timeout % 1000) * 1000; /* re-resolve if asked */ if (resolve && r->hostname) { diff --git a/daemon/statistics.c b/daemon/statistics.c index 2f1ddbce9..ae7155998 100644 --- a/daemon/statistics.c +++ b/daemon/statistics.c @@ -1028,16 +1028,16 @@ const char *statistics_ng(ng_command_ctx_t *ctx) { * Separate thread for update of running min/max call counters. */ enum thread_looper_action call_rate_stats_updater(void) { - static struct timeval last_run; + static int64_t last_run; stats_rate_min_max(&rtpe_rate_graphite_min_max, &rtpe_stats_rate); - if (last_run.tv_sec) { /* `stats_counters_calc_rate()` shouldn't be called on the very first cycle */ - int64_t run_diff_us = timeval_diff(timeval_from_us(rtpe_now), last_run); + if (last_run) { /* `stats_counters_calc_rate()` shouldn't be called on the very first cycle */ + int64_t run_diff_us = rtpe_now - last_run; stats_counters_calc_rate(rtpe_stats, run_diff_us, &rtpe_stats_intv, &rtpe_stats_rate); } - last_run = timeval_from_us(rtpe_now); + last_run = rtpe_now; return TLA_CONTINUE; } diff --git a/include/redis.h b/include/redis.h index 1e67f0c63..9c2cc0df7 100644 --- a/include/redis.h +++ b/include/redis.h @@ -100,7 +100,7 @@ void redis_delete(call_t *, struct redis *); void redis_wipe(struct redis *); int redis_async_event_base_action(struct redis *r, enum event_base_action); int redis_notify_subscribe_action(struct redis *r, enum subscribe_action action, int keyspace); -int redis_set_timeout(struct redis* r, int timeout); +int redis_set_timeout(struct redis* r, int64_t timeout); // XXX scale to micro int redis_reconnect(struct redis* r);