0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2025-01-03 07:31:54 +00:00

Task deferrer: kinda more dumb-resistant macro

Originally, this mechanism required to check whether there's enough time to work
and then to send an event. This macro combines all the logic and goes more straightforwardly
to the _end_ of the export processing loop.

One should note that there were two cases where the export processing loop
was deferred at the _beginning_, which led to ignoring some routes on
reimports. This wasn't easily noticeable in the tests until the one-task
limit got a ceiling on 300 ms to keep reasonable latency.
This commit is contained in:
Maria Matejka 2024-06-03 11:12:20 +02:00
parent 2705c385c0
commit b287c13f21
4 changed files with 74 additions and 73 deletions

View File

@ -22,6 +22,13 @@ extern _Thread_local struct birdloop *this_birdloop;
/* Check that the task has enough time to do a bit more */
_Bool task_still_in_limit(void);
#define MAYBE_DEFER_TASK(target, event, fmt, args...) do { \
if (!task_still_in_limit()) { \
if (config && config->latency_debug) \
log(L_TRACE "Deferring " fmt, ##args); \
return ev_send(target, event); \
} } while (0)
/* Start a new birdloop owned by given pool and domain */
struct birdloop *birdloop_new(pool *p, uint order, btime max_latency, const char *fmt, ...);

View File

@ -763,7 +763,6 @@ channel_do_reload(void *_c)
struct channel *c = _c;
RT_FEED_WALK(&c->reimporter, f)
if (task_still_in_limit())
{
for (uint i = 0; i < f->count_routes; i++)
{
@ -787,11 +786,9 @@ channel_do_reload(void *_c)
/* Local data needed no more */
tmp_flush();
}
else
{
ev_send(proto_work_list(c->proto), &c->reimport_event);
return;
MAYBE_DEFER_TASK(proto_work_list(c->proto), &c->reimport_event,
"%s.%s reimport", c->proto->name, c->name);
}
}

View File

@ -921,8 +921,8 @@ channel_notify_accepted(void *_channel)
}
}
if (!task_still_in_limit())
return ev_send(c->out_req.r.target, c->out_req.r.event);
MAYBE_DEFER_TASK(c->out_req.r.target, c->out_req.r.event,
"export to %s.%s (secondary)", c->proto->name, c->name);
}
}
@ -1054,8 +1054,8 @@ channel_notify_merged(void *_channel)
}
}
if (!task_still_in_limit())
return ev_send(c->out_req.r.target, c->out_req.r.event);
MAYBE_DEFER_TASK(c->out_req.r.target, c->out_req.r.event,
"export to %s.%s (merged)", c->proto->name, c->name);
}
}
@ -1145,8 +1145,8 @@ channel_notify_basic(void *_channel)
}
}
if (!task_still_in_limit())
return ev_send(c->out_req.r.target, c->out_req.r.event);
MAYBE_DEFER_TASK(c->out_req.r.target, c->out_req.r.event,
"export to %s.%s (regular)", c->proto->name, c->name);
}
}
@ -2569,8 +2569,8 @@ rt_flowspec_export(void *_link)
rt_schedule_nhu(dst);
}
if (!task_still_in_limit())
return ev_send_loop(dst_pub->loop, &ln->event);
MAYBE_DEFER_TASK(birdloop_event_list(dst_pub->loop), &ln->event,
"flowspec ctl export from %s to %s", ln->src->name, dst_pub->name);
}
}
@ -4294,8 +4294,8 @@ hc_notify_export(void *_hc)
}
}
if (!task_still_in_limit())
return ev_send(hc->req.r.target, hc->req.r.event);
MAYBE_DEFER_TASK(hc->req.r.target, hc->req.r.event,
"hostcache updater in %s", tab->name);
}
}

View File

@ -2793,7 +2793,6 @@ bgp_rte_modify_stale(void *_bc)
struct rt_import_hook *irh = c->c.in_req.hook;
RT_FEED_WALK(&c->stale_feed, f) TMP_SAVED
if (task_still_in_limit())
{
for (uint i = 0; i < f->count_routes; i++)
{
@ -2830,11 +2829,9 @@ bgp_rte_modify_stale(void *_bc)
rte_import(&c->c.in_req, r->net, r, r->src);
irh->stale_set++;
}
}
else
{
proto_send_event(c->c.proto, &c->stale_event);
return;
MAYBE_DEFER_TASK(proto_event_list(c->c.proto), &c->stale_event,
"BGP %s.%s LLGR updater", c->c.proto->name, c->c.name);
}
rt_feeder_unsubscribe(&c->stale_feed);