2013-09-16 21:57:40 +00:00
|
|
|
/*
|
|
|
|
* BIRD -- I/O and event loop
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
2013-09-10 10:09:36 +00:00
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
#ifndef _BIRD_SYSDEP_UNIX_IO_LOOP_H_
|
|
|
|
#define _BIRD_SYSDEP_UNIX_IO_LOOP_H_
|
2013-09-10 10:09:36 +00:00
|
|
|
|
2021-11-12 21:58:40 +00:00
|
|
|
#include "lib/rcu.h"
|
|
|
|
|
2023-01-21 22:42:02 +00:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2022-09-20 15:01:50 +00:00
|
|
|
struct pipe
|
|
|
|
{
|
|
|
|
int fd[2];
|
|
|
|
};
|
|
|
|
|
2023-02-24 08:13:35 +00:00
|
|
|
struct pfd {
|
|
|
|
BUFFER(struct pollfd) pfd;
|
|
|
|
BUFFER(struct birdloop *) loop;
|
|
|
|
};
|
|
|
|
|
|
|
|
void sockets_prepare(struct birdloop *, struct pfd *);
|
2023-04-02 17:15:22 +00:00
|
|
|
void socket_changed(struct birdsock *);
|
2023-02-24 08:13:35 +00:00
|
|
|
|
2022-09-20 15:01:50 +00:00
|
|
|
void pipe_new(struct pipe *);
|
2023-02-24 08:13:35 +00:00
|
|
|
void pipe_pollin(struct pipe *, struct pfd *);
|
2022-09-20 15:01:50 +00:00
|
|
|
void pipe_drain(struct pipe *);
|
|
|
|
void pipe_kick(struct pipe *);
|
|
|
|
|
2023-04-26 20:24:42 +00:00
|
|
|
#define TIME_BY_SEC_SIZE 16
|
|
|
|
|
|
|
|
struct spent_time {
|
|
|
|
u64 total_ns;
|
|
|
|
u64 last_written_ns;
|
|
|
|
u64 by_sec_ns[TIME_BY_SEC_SIZE];
|
2023-04-26 17:10:52 +00:00
|
|
|
};
|
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
struct birdloop
|
|
|
|
{
|
2023-01-19 09:49:47 +00:00
|
|
|
node n;
|
|
|
|
|
2023-02-24 08:13:35 +00:00
|
|
|
event event;
|
|
|
|
timer timer;
|
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
pool *pool;
|
2013-09-16 21:57:40 +00:00
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
struct timeloop time;
|
|
|
|
event_list event_list;
|
|
|
|
list sock_list;
|
2023-04-02 17:15:22 +00:00
|
|
|
struct birdsock *sock_active;
|
2023-01-19 09:49:47 +00:00
|
|
|
int sock_num;
|
2023-04-30 20:17:42 +00:00
|
|
|
uint sock_changed:1;
|
2013-09-10 10:09:36 +00:00
|
|
|
|
2022-07-28 17:49:03 +00:00
|
|
|
uint ping_pending;
|
2021-11-12 21:58:40 +00:00
|
|
|
|
2023-02-24 08:13:35 +00:00
|
|
|
_Atomic u32 thread_transition;
|
|
|
|
#define LTT_PING 1
|
|
|
|
#define LTT_MOVE 2
|
2022-09-12 08:24:55 +00:00
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
void (*stopped)(void *data);
|
|
|
|
void *stop_data;
|
2013-09-16 21:57:40 +00:00
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
struct birdloop *prev_loop;
|
2023-01-19 09:49:47 +00:00
|
|
|
|
|
|
|
struct bird_thread *thread;
|
|
|
|
|
2023-04-26 17:10:52 +00:00
|
|
|
#define TIME_BY_SEC_SIZE 16
|
2023-04-26 20:24:42 +00:00
|
|
|
struct spent_time working, locking;
|
2023-01-19 09:49:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct bird_thread
|
|
|
|
{
|
|
|
|
node n;
|
|
|
|
|
|
|
|
struct pipe wakeup;
|
|
|
|
event_list priority_events;
|
|
|
|
|
2023-02-24 08:13:35 +00:00
|
|
|
struct birdloop *meta;
|
|
|
|
|
2023-01-19 09:49:47 +00:00
|
|
|
pthread_t thread_id;
|
|
|
|
pthread_attr_t thread_attr;
|
|
|
|
|
|
|
|
struct rcu_thread rcu;
|
|
|
|
|
|
|
|
list loops;
|
2023-04-17 09:37:29 +00:00
|
|
|
struct birdloop_pickup_group *group;
|
2023-01-19 09:49:47 +00:00
|
|
|
pool *pool;
|
2023-02-24 08:13:35 +00:00
|
|
|
struct pfd *pfd;
|
2023-01-19 09:49:47 +00:00
|
|
|
|
|
|
|
event cleanup_event;
|
2023-04-02 17:15:22 +00:00
|
|
|
|
2023-04-30 20:17:42 +00:00
|
|
|
u8 sock_changed;
|
|
|
|
u8 busy_active;
|
|
|
|
u16 busy_counter;
|
2023-04-06 18:18:04 +00:00
|
|
|
uint loop_count;
|
|
|
|
|
|
|
|
u64 max_latency_ns;
|
|
|
|
u64 max_loop_time_ns;
|
2023-04-26 20:24:42 +00:00
|
|
|
|
2023-04-30 20:17:42 +00:00
|
|
|
struct spent_time overhead, idle;
|
2021-06-19 18:50:18 +00:00
|
|
|
};
|
2013-09-10 10:09:36 +00:00
|
|
|
|
2023-08-21 18:56:19 +00:00
|
|
|
|
|
|
|
struct bird_thread_syncer {
|
|
|
|
pool *pool;
|
|
|
|
DOMAIN(control) lock;
|
|
|
|
uint total;
|
|
|
|
uint done;
|
|
|
|
void (*hook)(struct bird_thread_syncer *); /* Runs in worker threads */
|
|
|
|
void (*finish)(struct bird_thread_syncer *); /* Runs in main thread last */
|
|
|
|
};
|
|
|
|
|
|
|
|
void bird_thread_sync_all(struct bird_thread_syncer *sync,
|
|
|
|
void (*hook)(struct bird_thread_syncer *),
|
|
|
|
void (*done)(struct bird_thread_syncer *), const char *name);
|
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
#endif
|