0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-10 13:18:42 +00:00
bird/sysdep/unix/io-loop.h
Maria Matejka 84c298465f Decoupling loops from threads to allow fixed thread count
On large configurations, too many threads would spawn with one thread
per loop. Therefore, threads may now run multiple loops at once. The
thread count is configurable and may be changed during run. All threads
are spawned on startup.

This change helps with memory bloating. BIRD filters need large
temporary memory blocks to store their stack and also memory management
keeps its hot page storage per-thread.

Known bugs:
* Thread autobalancing is not yet implemented.
* Low latency loops are executed together with standard loops.
2023-01-19 11:13:50 +01:00

77 lines
1.1 KiB
C

/*
* BIRD -- I/O and event loop
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
#ifndef _BIRD_SYSDEP_UNIX_IO_LOOP_H_
#define _BIRD_SYSDEP_UNIX_IO_LOOP_H_
#include "lib/rcu.h"
struct pipe
{
int fd[2];
};
void pipe_new(struct pipe *);
void pipe_pollin(struct pipe *, struct pollfd *);
void pipe_drain(struct pipe *);
void pipe_kick(struct pipe *);
struct birdloop
{
node n;
pool *pool;
struct timeloop time;
event_list event_list;
list sock_list;
int sock_num;
uint ping_pending;
uint links;
_Atomic u32 flags;
struct birdloop_flag_handler *flag_handler;
void (*stopped)(void *data);
void *stop_data;
struct birdloop *prev_loop;
struct bird_thread *thread;
struct pollfd *pfd;
u64 total_time_spent_ns;
};
struct bird_thread
{
node n;
struct pollfd *pfd;
uint pfd_max;
_Atomic u32 ping_sent;
_Atomic u32 run_cleanup;
_Atomic u32 poll_changed;
struct pipe wakeup;
event_list priority_events;
pthread_t thread_id;
pthread_attr_t thread_attr;
struct rcu_thread rcu;
list loops;
pool *pool;
event cleanup_event;
};
#endif