summaryrefslogtreecommitdiff
path: root/sysdep/unix/io-loop.h
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2023-02-24 09:13:35 +0100
committerMaria Matejka <mq@ucw.cz>2023-04-04 17:00:59 +0200
commit571c4f69bfbcf437d848b332bb2f4995fea2347d (patch)
tree01af432e1fa4a61be6793be90c59bf4223de6539 /sysdep/unix/io-loop.h
parentd9f0f4af7dc49c22232cc3be5e40866fc7d5dda7 (diff)
More efficient IO loop event execution to avoid long loops
If there are lots of loops in a single thread and only some of the loops are actually active, the other loops are now kept aside and not checked until they actually get some timers, events or active sockets. This should help with extreme loads like 100k tables and protocols. Also ping and loop pickup mechanism was allowing subtle race conditions. Now properly handling collisions between loop ping and pickup.
Diffstat (limited to 'sysdep/unix/io-loop.h')
-rw-r--r--sysdep/unix/io-loop.h24
1 files changed, 17 insertions, 7 deletions
diff --git a/sysdep/unix/io-loop.h b/sysdep/unix/io-loop.h
index e23a9be0..e606f07e 100644
--- a/sysdep/unix/io-loop.h
+++ b/sysdep/unix/io-loop.h
@@ -16,8 +16,15 @@ struct pipe
int fd[2];
};
+struct pfd {
+ BUFFER(struct pollfd) pfd;
+ BUFFER(struct birdloop *) loop;
+};
+
+void sockets_prepare(struct birdloop *, struct pfd *);
+
void pipe_new(struct pipe *);
-void pipe_pollin(struct pipe *, struct pollfd *);
+void pipe_pollin(struct pipe *, struct pfd *);
void pipe_drain(struct pipe *);
void pipe_kick(struct pipe *);
@@ -25,6 +32,9 @@ struct birdloop
{
node n;
+ event event;
+ timer timer;
+
pool *pool;
struct timeloop time;
@@ -36,6 +46,9 @@ struct birdloop
uint links;
+ _Atomic u32 thread_transition;
+#define LTT_PING 1
+#define LTT_MOVE 2
_Atomic u32 flags;
struct birdloop_flag_handler *flag_handler;
@@ -45,7 +58,6 @@ struct birdloop
struct birdloop *prev_loop;
struct bird_thread *thread;
- struct pollfd *pfd;
u64 total_time_spent_ns;
};
@@ -54,16 +66,13 @@ 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;
+ struct birdloop *meta;
+
pthread_t thread_id;
pthread_attr_t thread_attr;
@@ -71,6 +80,7 @@ struct bird_thread
list loops;
pool *pool;
+ struct pfd *pfd;
event cleanup_event;
};