]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Introducing an universal temporary linpool flushed after every task
authorMaria Matejka <mq@ucw.cz>
Wed, 2 Mar 2022 09:35:21 +0000 (10:35 +0100)
committerMaria Matejka <mq@ucw.cz>
Wed, 2 Mar 2022 11:13:49 +0000 (12:13 +0100)
lib/event.c
lib/mempool.c
lib/resource.c
lib/resource.h
lib/timer.c
proto/bfd/io.c
sysdep/unix/io.c
test/birdtest.c
test/bt-utils.c

index 273447e01df5267675d25d98c20a64cb4bc29c6e..33dc00b01350f2bb90c95a30db01b706f0cba492 100644 (file)
@@ -157,6 +157,7 @@ ev_run_list(event_list *l)
        io_log_event(e->hook, e->data);
 
       ev_run(e);
+      tmp_flush();
     }
 
   return !EMPTY_LIST(*l);
@@ -184,6 +185,7 @@ ev_run_list_limited(event_list *l, uint limit)
        io_log_event(e->hook, e->data);
 
       ev_run(e);
+      tmp_flush();
       limit--;
     }
 
index 90d7c7743396a67a48f7ef84cd6f1d0c3785a588..169826d4c59cf4d4a191f7430ba69b301e700695 100644 (file)
@@ -42,6 +42,8 @@ struct linpool {
   uint chunk_size, threshold, total, total_large;
 };
 
+_Thread_local linpool *tmp_linpool;
+
 static void lp_free(resource *);
 static void lp_dump(resource *);
 static resource *lp_lookup(resource *, unsigned long);
index 5d4c7780dd5d4fbdc038f182484b5b575b78d5a9..5636872c5d74cf8744de4a012f4d0d989a19cf1f 100644 (file)
@@ -273,6 +273,7 @@ resource_init(void)
   root_pool.r.class = &pool_class;
   root_pool.name = "Root";
   init_list(&root_pool.inside);
+  tmp_init(&root_pool);
 }
 
 /**
index 9ec41ed8e81b4b98a54ba64130ee26c960e39e13..0e4c44d8c4a891b73d2014fc0c83451f30fe5b4d 100644 (file)
@@ -79,6 +79,15 @@ void lp_flush(linpool *);                    /* Free everything, but leave linpool */
 void lp_save(linpool *m, lp_state *p);         /* Save state */
 void lp_restore(linpool *m, lp_state *p);      /* Restore state */
 
+extern _Thread_local linpool *tmp_linpool;     /* Temporary linpool autoflushed regularily */
+
+#define tmp_alloc(sz)  lp_alloc(tmp_linpool, sz)
+#define tmp_allocu(sz) lp_allocu(tmp_linpool, sz)
+#define tmp_allocz(sz) lp_allocz(tmp_linpool, sz)
+
+#define tmp_init(p)    tmp_linpool = lp_new_default(p)
+#define tmp_flush()    lp_flush(tmp_linpool)
+
 extern const int lp_chunk_size;
 #define LP_GAS             1024
 #define LP_GOOD_SIZE(x)            (((x + LP_GAS - 1) & (~(LP_GAS - 1))) - lp_chunk_size)
index 381163d0b09013fa1ceead5e2a52dd2ade17827a..c47e0bbc8b78d9797a61754b612cd1ee1df12bf3 100644 (file)
@@ -233,6 +233,7 @@ timers_fire(struct timeloop *loop)
       io_log_event(t->hook, t->data);
 
     t->hook(t);
+    tmp_flush();
   }
 }
 
index 1cd9365adb4df763c6665aae9134cbc19c24bc98..e696cc8970a70d1985bc5d1034783f47b548b94e 100644 (file)
@@ -482,6 +482,8 @@ birdloop_main(void *arg)
 
   birdloop_set_current(loop);
 
+  tmp_init(loop->pool);
+
   pthread_mutex_lock(&loop->mutex);
   while (1)
   {
index 4fd774534f1f488ea600d4643cd1bd98d927e47f..8a11678935c3a9e058c1ebe5221a06ca51dbcc54 100644 (file)
@@ -1854,8 +1854,8 @@ sk_read_ssh(sock *s)
 
  /* sk_read() and sk_write() are called from BFD's event loop */
 
-int
-sk_read(sock *s, int revents)
+static inline int
+sk_read_noflush(sock *s, int revents)
 {
   switch (s->type)
   {
@@ -1918,7 +1918,15 @@ sk_read(sock *s, int revents)
 }
 
 int
-sk_write(sock *s)
+sk_read(sock *s, int revents)
+{
+  int e = sk_read_noflush(s, revents);
+  tmp_flush();
+  return e;
+}
+
+static inline int
+sk_write_noflush(sock *s)
 {
   switch (s->type)
   {
@@ -1966,6 +1974,14 @@ sk_write(sock *s)
   }
 }
 
+int
+sk_write(sock *s)
+{
+  int e = sk_write_noflush(s);
+  tmp_flush();
+  return e;
+}
+
 int sk_is_ipv4(sock *s)
 { return s->af == AF_INET; }
 
@@ -1984,6 +2000,7 @@ sk_err(sock *s, int revents)
     }
 
   s->err_hook(s, se);
+  tmp_flush();
 }
 
 void
index 86a8882f0c805f589eb9e8af3ba4c9a1377fbf20..10d6d6ded4fcecc1d655f58a6664e77bb099c38b 100644 (file)
@@ -119,6 +119,8 @@ bt_init(int argc, char *argv[])
   clock_gettime(CLOCK_MONOTONIC, &bt_begin);
   bt_suite_case_begin = bt_suite_begin = bt_begin;
 
+  resource_init();
+
   return;
 
  usage:
@@ -172,6 +174,8 @@ int bt_run_test_fn(int (*fn)(const void *), const void *fn_arg, int timeout)
   if (!bt_suite_result)
     result = 0;
 
+  tmp_flush();
+
   return result;
 }
 
index cbca3a6b1a2a1735a0e175819024cdc3494db4f5..2a7799c379d5a0fbaac1ef26e9c737eefc01299b 100644 (file)
@@ -60,7 +60,6 @@ bt_bird_init(void)
     log_init_debug("");
   log_switch(bt_verbose != 0, NULL, NULL);
 
-  resource_init();
   olock_init();
   timer_init();
   io_init();