mirror of
https://github.com/FRRouting/frr.git
synced 2025-04-30 13:37:17 +02:00
*: Convert thread_fetch and thread_call to event_fetch and event_call
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
This commit is contained in:
parent
2ccccdf5d0
commit
de2754be3a
|
@ -162,7 +162,7 @@ void *bgp_keepalives_start(void *arg)
|
|||
/*
|
||||
* The RCU mechanism for each pthread is initialized in a "locked"
|
||||
* state. That's ok for pthreads using the frr_pthread,
|
||||
* thread_fetch event loop, because that event loop unlocks regularly.
|
||||
* event_fetch event loop, because that event loop unlocks regularly.
|
||||
* For foreign pthreads, the lock needs to be unlocked so that the
|
||||
* background rcu pthread can run.
|
||||
*/
|
||||
|
|
|
@ -111,13 +111,13 @@ program. When no more tasks are available, the program dies. Typically at
|
|||
startup the first task added is an I/O task for VTYSH as well as any network
|
||||
sockets needed for peerings or IPC.
|
||||
|
||||
To retrieve the next task to run the program calls ``thread_fetch()``.
|
||||
``thread_fetch()`` internally computes which task to execute next based on
|
||||
To retrieve the next task to run the program calls ``event_fetch()``.
|
||||
``event_fetch()`` internally computes which task to execute next based on
|
||||
rudimentary priority logic. Events (type ``THREAD_EVENT``) execute with the
|
||||
highest priority, followed by expired timers and finally I/O tasks (type
|
||||
``THREAD_READ`` and ``THREAD_WRITE``). When scheduling a task a function and an
|
||||
arbitrary argument are provided. The task returned from ``thread_fetch()`` is
|
||||
then executed with ``thread_call()``.
|
||||
arbitrary argument are provided. The task returned from ``event_fetch()`` is
|
||||
then executed with ``event_call()``.
|
||||
|
||||
The following diagram illustrates a simplified version of this infrastructure.
|
||||
|
||||
|
@ -134,8 +134,8 @@ illustrated at the bottom.
|
|||
Mapping the general names used in the figure to specific FRR functions:
|
||||
|
||||
- ``task`` is ``struct event *``
|
||||
- ``fetch`` is ``thread_fetch()``
|
||||
- ``exec()`` is ``thread_call``
|
||||
- ``fetch`` is ``event_fetch()``
|
||||
- ``exec()`` is ``event_call``
|
||||
- ``cancel()`` is ``event_cancel()``
|
||||
- ``schedule()`` is any of the various task-specific ``event_add_*`` functions
|
||||
|
||||
|
|
|
@ -146,8 +146,8 @@ lde(void)
|
|||
ldeconf = config_new_empty();
|
||||
|
||||
struct event thread;
|
||||
while (thread_fetch(master, &thread))
|
||||
thread_call(&thread);
|
||||
while (event_fetch(master, &thread))
|
||||
event_call(&thread);
|
||||
|
||||
/* NOTREACHED */
|
||||
return;
|
||||
|
|
|
@ -123,8 +123,8 @@ ldpe(void)
|
|||
leconf = config_new_empty();
|
||||
|
||||
struct event thread;
|
||||
while (thread_fetch(master, &thread))
|
||||
thread_call(&thread);
|
||||
while (event_fetch(master, &thread))
|
||||
event_call(&thread);
|
||||
|
||||
/* NOTREACHED */
|
||||
return;
|
||||
|
|
16
lib/event.c
16
lib/event.c
|
@ -589,7 +589,7 @@ struct thread_master *thread_master_create(const char *name)
|
|||
thread_list_init(&rv->unuse);
|
||||
thread_timer_list_init(&rv->timer);
|
||||
|
||||
/* Initialize thread_fetch() settings */
|
||||
/* Initialize event_fetch() settings */
|
||||
rv->spin = true;
|
||||
rv->handle_signals = true;
|
||||
|
||||
|
@ -1159,7 +1159,7 @@ void _event_add_event(const struct xref_threadsched *xref,
|
|||
* NOT's out the .events field of pollfd corresponding to the given file
|
||||
* descriptor. The event to be NOT'd is passed in the 'state' parameter.
|
||||
*
|
||||
* This needs to happen for both copies of pollfd's. See 'thread_fetch'
|
||||
* This needs to happen for both copies of pollfd's. See 'event_fetch'
|
||||
* implementation for details.
|
||||
*
|
||||
* @param master
|
||||
|
@ -1741,7 +1741,7 @@ static unsigned int thread_process(struct thread_list_head *list)
|
|||
|
||||
|
||||
/* Fetch next ready thread. */
|
||||
struct event *thread_fetch(struct thread_master *m, struct event *fetch)
|
||||
struct event *event_fetch(struct thread_master *m, struct event *fetch)
|
||||
{
|
||||
struct event *thread = NULL;
|
||||
struct timeval now;
|
||||
|
@ -1962,7 +1962,7 @@ void thread_getrusage(RUSAGE_T *r)
|
|||
* particular, the maximum real and cpu times must be monotonically increasing
|
||||
* or this code is not correct.
|
||||
*/
|
||||
void thread_call(struct event *thread)
|
||||
void event_call(struct event *thread)
|
||||
{
|
||||
RUSAGE_T before, after;
|
||||
|
||||
|
@ -1979,10 +1979,10 @@ void thread_call(struct event *thread)
|
|||
|
||||
thread->real = before.real;
|
||||
|
||||
frrtrace(9, frr_libfrr, thread_call, thread->master,
|
||||
frrtrace(9, frr_libfrr, event_call, thread->master,
|
||||
thread->xref->funcname, thread->xref->xref.file,
|
||||
thread->xref->xref.line, NULL, thread->u.fd,
|
||||
thread->u.val, thread->arg, thread->u.sands.tv_sec);
|
||||
thread->xref->xref.line, NULL, thread->u.fd, thread->u.val,
|
||||
thread->arg, thread->u.sands.tv_sec);
|
||||
|
||||
pthread_setspecific(thread_current, thread);
|
||||
(*thread->func)(thread);
|
||||
|
@ -2077,7 +2077,7 @@ void _thread_execute(const struct xref_threadsched *xref,
|
|||
}
|
||||
|
||||
/* Execute thread doing all accounting. */
|
||||
thread_call(thread);
|
||||
event_call(thread);
|
||||
|
||||
/* Give back or free thread. */
|
||||
thread_add_unuse(m, thread);
|
||||
|
|
|
@ -249,8 +249,8 @@ extern void event_cancel_async(struct thread_master *, struct event **, void *);
|
|||
extern void event_cancel_event_ready(struct thread_master *m, void *arg);
|
||||
/* Cancel all tasks with an arg matching 'arg', including timers and io */
|
||||
extern void event_cancel_event(struct thread_master *m, void *arg);
|
||||
extern struct event *thread_fetch(struct thread_master *, struct event *event);
|
||||
extern void thread_call(struct event *event);
|
||||
extern struct event *event_fetch(struct thread_master *, struct event *event);
|
||||
extern void event_call(struct event *event);
|
||||
extern unsigned long thread_timer_remain_second(struct event *event);
|
||||
extern struct timeval thread_timer_remain(struct event *event);
|
||||
extern unsigned long thread_timer_remain_msec(struct event *event);
|
||||
|
|
|
@ -292,8 +292,8 @@ static void *fpt_run(void *arg)
|
|||
struct event task;
|
||||
while (atomic_load_explicit(&fpt->running, memory_order_relaxed)) {
|
||||
pthread_testcancel();
|
||||
if (thread_fetch(fpt->master, &task)) {
|
||||
thread_call(&task);
|
||||
if (event_fetch(fpt->master, &task)) {
|
||||
event_call(&task);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -45,8 +45,8 @@ int main(int argc, char **argv)
|
|||
vty_stdio(vty_do_exit);
|
||||
|
||||
/* Fetch next active thread. */
|
||||
while (thread_fetch(master, &event))
|
||||
thread_call(&event);
|
||||
while (event_fetch(master, &event))
|
||||
event_call(&event);
|
||||
|
||||
/* Not reached. */
|
||||
exit(0);
|
||||
|
|
|
@ -1181,8 +1181,8 @@ void frr_run(struct thread_master *master)
|
|||
zlog_startup_end();
|
||||
|
||||
struct event thread;
|
||||
while (thread_fetch(master, &thread))
|
||||
thread_call(&thread);
|
||||
while (event_fetch(master, &thread))
|
||||
event_call(&thread);
|
||||
}
|
||||
|
||||
void frr_early_fini(void)
|
||||
|
|
|
@ -105,7 +105,7 @@ THREAD_OPERATION_TRACEPOINT_INSTANCE(schedule_read)
|
|||
THREAD_OPERATION_TRACEPOINT_INSTANCE(schedule_write)
|
||||
THREAD_OPERATION_TRACEPOINT_INSTANCE(event_cancel)
|
||||
THREAD_OPERATION_TRACEPOINT_INSTANCE(event_cancel_async)
|
||||
THREAD_OPERATION_TRACEPOINT_INSTANCE(thread_call)
|
||||
THREAD_OPERATION_TRACEPOINT_INSTANCE(event_call)
|
||||
|
||||
TRACEPOINT_EVENT(
|
||||
frr_libfrr,
|
||||
|
|
|
@ -320,8 +320,8 @@ int main(int argc, char *argv[])
|
|||
|
||||
/* Now connection is established, run loop */
|
||||
while (1) {
|
||||
thread_fetch(master, &thread);
|
||||
thread_call(&thread);
|
||||
event_fetch(master, &thread);
|
||||
event_call(&thread);
|
||||
}
|
||||
|
||||
/* Never reached */
|
||||
|
|
|
@ -164,8 +164,8 @@ int main(int argc, char **argv)
|
|||
test_init();
|
||||
|
||||
/* Fetch next active thread. */
|
||||
while (thread_fetch(master, &thread))
|
||||
thread_call(&thread);
|
||||
while (event_fetch(master, &thread))
|
||||
event_call(&thread);
|
||||
|
||||
/* Not reached. */
|
||||
exit(0);
|
||||
|
|
|
@ -549,8 +549,8 @@ int main(int argc, char **argv)
|
|||
vty_stdio(vty_do_exit);
|
||||
|
||||
/* Fetch next active thread. */
|
||||
while (thread_fetch(master, &thread))
|
||||
thread_call(&thread);
|
||||
while (event_fetch(master, &thread))
|
||||
event_call(&thread);
|
||||
|
||||
/* Not reached. */
|
||||
exit(0);
|
||||
|
|
|
@ -81,8 +81,8 @@ int main(int argc, char **argv)
|
|||
vty_stdio(vty_do_exit);
|
||||
|
||||
/* Fetch next active thread. */
|
||||
while (thread_fetch(master, &thread))
|
||||
thread_call(&thread);
|
||||
while (event_fetch(master, &thread))
|
||||
event_call(&thread);
|
||||
|
||||
/* Not reached. */
|
||||
exit(0);
|
||||
|
|
|
@ -395,8 +395,8 @@ int main(int argc, char **argv)
|
|||
vty_stdio(vty_do_exit);
|
||||
|
||||
/* Fetch next active thread. */
|
||||
while (thread_fetch(master, &thread))
|
||||
thread_call(&thread);
|
||||
while (event_fetch(master, &thread))
|
||||
event_call(&thread);
|
||||
|
||||
/* Not reached. */
|
||||
exit(0);
|
||||
|
|
|
@ -546,8 +546,8 @@ int main(int argc, char **argv)
|
|||
|
||||
/* Event Loop */
|
||||
struct event thread;
|
||||
while (thread_fetch(master, &thread))
|
||||
thread_call(&thread);
|
||||
while (event_fetch(master, &thread))
|
||||
event_call(&thread);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -45,8 +45,8 @@ int main(void)
|
|||
|
||||
zlog_aux_init("NONE: ", LOG_DEBUG);
|
||||
|
||||
while (thread_fetch(master, &t))
|
||||
thread_call(&t);
|
||||
while (event_fetch(master, &t))
|
||||
event_call(&t);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
|
|
@ -166,8 +166,8 @@ int main(int argc, char **argv)
|
|||
}
|
||||
XFREE(MTYPE_TMP, alarms);
|
||||
|
||||
while (thread_fetch(master, &t))
|
||||
thread_call(&t);
|
||||
while (event_fetch(master, &t))
|
||||
event_call(&t);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -279,8 +279,8 @@ static void run_server(int syncfd)
|
|||
frrzmq_event_add_read_msg(master, serverfn, NULL, NULL, zmqsock, &cb);
|
||||
|
||||
write(syncfd, &dummy, sizeof(dummy));
|
||||
while (thread_fetch(master, &t))
|
||||
thread_call(&t);
|
||||
while (event_fetch(master, &t))
|
||||
event_call(&t);
|
||||
|
||||
zmq_close(zmqsock);
|
||||
frrzmq_finish();
|
||||
|
|
|
@ -297,8 +297,8 @@ int main(int argc, char **argv)
|
|||
vty_stdio(vty_do_exit);
|
||||
|
||||
/* Fetch next active thread. */
|
||||
while (thread_fetch(master, &thread))
|
||||
thread_call(&thread);
|
||||
while (event_fetch(master, &thread))
|
||||
event_call(&thread);
|
||||
|
||||
/* Not reached. */
|
||||
exit(0);
|
||||
|
|
|
@ -234,8 +234,8 @@ static void vtysh_rl_run(void)
|
|||
event_add_read(master, vtysh_rl_read, NULL, STDIN_FILENO,
|
||||
&vtysh_rl_read_thread);
|
||||
|
||||
while (!vtysh_loop_exited && thread_fetch(master, &thread))
|
||||
thread_call(&thread);
|
||||
while (!vtysh_loop_exited && event_fetch(master, &thread))
|
||||
event_call(&thread);
|
||||
|
||||
if (!vtysh_loop_exited)
|
||||
rl_callback_handler_remove();
|
||||
|
|
Loading…
Reference in a new issue