Browse Source

uasync: add event loop stall detection (warn if >10ms between poll entries)

topo_upd
Evgeny 2 months ago
parent
commit
48bfe644c4
  1. 8
      lib/u_async.c
  2. 1
      lib/u_async.h

8
lib/u_async.c

@ -984,6 +984,13 @@ void uasync_poll(struct UASYNC* ua, int timeout_tb) {
if (!ua) return;
if (!ua->sockets || !ua->timeout_heap) return;
uint64_t now_us_poll_entry = get_time_us();
if (ua->last_poll_entry_us && now_us_poll_entry - ua->last_poll_entry_us > 10000) {
DEBUG_WARN(DEBUG_CATEGORY_UASYNC, "Event loop stall: %lluus since last poll entry",
(unsigned long long)(now_us_poll_entry - ua->last_poll_entry_us));
}
ua->last_poll_entry_us = now_us_poll_entry;
DEBUG_DEBUG(DEBUG_CATEGORY_UASYNC, "poll(%d sockets, %zu timers, timeout=%d.%dms)",
ua->sockets->count, ua->timeout_heap->size, timeout_tb >= 0 ? timeout_tb / 10000 : -1,
timeout_tb >= 0 ? (timeout_tb % 10000) / 10 : 0);
@ -1320,6 +1327,7 @@ struct UASYNC* uasync_create(void) {
ua->posted_tasks_head = NULL;
ua->immediate_queue_head = NULL;
ua->immediate_queue_tail = NULL;
ua->last_poll_entry_us = 0;
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "Creating SA...");
ua->sockets = socket_array_create(16);

1
lib/u_async.h

@ -75,6 +75,7 @@ struct UASYNC {
pthread_mutex_t posted_lock;
#endif
volatile sig_atomic_t stop;
uint64_t last_poll_entry_us;
};
// Type definitions

Loading…
Cancel
Save