]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Thread IO: a little bit faster RX repeat
authorMaria Matejka <mq@ucw.cz>
Sat, 8 Jun 2024 18:06:52 +0000 (20:06 +0200)
committerMaria Matejka <mq@ucw.cz>
Wed, 12 Jun 2024 12:48:33 +0000 (14:48 +0200)
lib/io-loop.h
sysdep/unix/io-loop.c

index 446cd17277d37408ec463d40230bab7b5957ebc1..154b0774eec5ce75026029083518ec31bd157e9a 100644 (file)
@@ -21,6 +21,7 @@ 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);
+_Bool task_before_halftime(void);
 
 #define MAYBE_DEFER_TASK(target, event, fmt, args...) do { \
   if (!task_still_in_limit()) { \
index 01cf74006e886aaff4b2d608f70e685d5e48af96..ddf190b0fddc61c22bf2078fa0e30ca402cd8e2e 100644 (file)
@@ -543,9 +543,14 @@ sockets_fire(struct birdloop *loop)
 
       if (rev & POLLIN)
        /* Read just one packet and request repeat. */
-       if ((s == loop->sock_active) && s->rx_hook)
-         if (sk_read(s, rev))
+       while ((s == loop->sock_active) && s->rx_hook)
+         if (!task_before_halftime())
+         {
            repeat++;
+           break;
+         }
+         else if (!sk_read(s, rev))
+           break;
 
       if (s != loop->sock_active)
        continue;
@@ -1356,6 +1361,11 @@ _Bool task_still_in_limit(void)
   return ns_now() < account_last + this_thread->max_loop_time_ns;
 }
 
+_Bool task_before_halftime(void)
+{
+  return ns_now() < account_last + this_thread->max_loop_time_ns / 2;
+}
+
 
 /*
  *     Birdloop