]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: applet: Count number of (active) applets
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 6 Dec 2016 08:13:22 +0000 (09:13 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 12 Dec 2016 18:10:46 +0000 (19:10 +0100)
As for tasks, 2 counters has been added to track :
  * the total number of applets : nb_applets
  * the number of active applets : applets_active_queue

[wt: needed for next fixes, to backport to 1.7 and 1.6]

include/proto/applet.h
src/applet.c
src/haproxy.c

index 81c20e11aaec2353417efa0bafa9c77e11c1be2d..5a503b43c4c419d3feac245c1a5e61ea312c860a 100644 (file)
@@ -29,6 +29,9 @@
 #include <types/applet.h>
 #include <proto/connection.h>
 
+extern unsigned int nb_applets;
+extern unsigned int applets_active_queue;
+
 extern struct list applet_active_queue;
 
 void applet_run_active();
@@ -58,6 +61,7 @@ static inline struct appctx *appctx_new(struct applet *applet)
                appctx->applet = applet;
                appctx_init(appctx);
                LIST_INIT(&appctx->runq);
+               nb_applets++;
        }
        return appctx;
 }
@@ -67,16 +71,21 @@ static inline struct appctx *appctx_new(struct applet *applet)
  */
 static inline void appctx_free(struct appctx *appctx)
 {
-       if (!LIST_ISEMPTY(&appctx->runq))
+       if (!LIST_ISEMPTY(&appctx->runq)) {
                LIST_DEL(&appctx->runq);
+               applets_active_queue--;
+       }
        pool_free2(pool2_connection, appctx);
+       nb_applets--;
 }
 
 /* wakes up an applet when conditions have changed */
 static inline void appctx_wakeup(struct appctx *appctx)
 {
-       if (LIST_ISEMPTY(&appctx->runq))
+       if (LIST_ISEMPTY(&appctx->runq)) {
                LIST_ADDQ(&applet_active_queue, &appctx->runq);
+               applets_active_queue++;
+       }
 }
 
 /* removes an applet from the list of active applets */
@@ -85,6 +94,7 @@ static inline void appctx_pause(struct appctx *appctx)
        if (!LIST_ISEMPTY(&appctx->runq)) {
                LIST_DEL(&appctx->runq);
                LIST_INIT(&appctx->runq);
+               applets_active_queue--;
        }
 }
 
index bc8972e6753f79680cc73039667393950378e177..ad40e1f9f97310e23cc4742457c819b0b08896e6 100644 (file)
 #include <proto/stream.h>
 #include <proto/stream_interface.h>
 
+unsigned int nb_applets = 0;
+unsigned int applets_active_queue = 0;
+
 struct list applet_active_queue = LIST_HEAD_INIT(applet_active_queue);
-struct list applet_run_queue    = LIST_HEAD_INIT(applet_run_queue);
+struct list applet_cur_queue    = LIST_HEAD_INIT(applet_cur_queue);
 
 void applet_run_active()
 {
@@ -31,18 +34,18 @@ void applet_run_active()
                return;
 
        /* move active queue to run queue */
-       applet_active_queue.n->p = &applet_run_queue;
-       applet_active_queue.p->n = &applet_run_queue;
+       applet_active_queue.n->p = &applet_cur_queue;
+       applet_active_queue.p->n = &applet_cur_queue;
 
-       applet_run_queue = applet_active_queue;
+       applet_cur_queue = applet_active_queue;
        LIST_INIT(&applet_active_queue);
 
        /* The list is only scanned from the head. This guarantees that if any
         * applet removes another one, there is no side effect while walking
         * through the list.
         */
-       while (!LIST_ISEMPTY(&applet_run_queue)) {
-               curr = LIST_ELEM(applet_run_queue.n, typeof(curr), runq);
+       while (!LIST_ISEMPTY(&applet_cur_queue)) {
+               curr = LIST_ELEM(applet_cur_queue.n, typeof(curr), runq);
                si = curr->owner;
 
                /* now we'll need a buffer */
@@ -63,7 +66,7 @@ void applet_run_active()
                curr->applet->fct(curr);
                si_applet_wake_cb(si);
 
-               if (applet_run_queue.n == &curr->runq) {
+               if (applet_cur_queue.n == &curr->runq) {
                        /* curr was left in the list, move it back to the active list */
                        LIST_DEL(&curr->runq);
                        LIST_ADDQ(&applet_active_queue, &curr->runq);
index 5d7d410bc1b71f926dce1cadcf2ec2d9c6bf8c18..b403ba1c105ac1a03ad3076c04cc8a26c9b707c6 100644 (file)
@@ -1730,7 +1730,7 @@ void run_poll_loop()
                        break;
 
                /* expire immediately if events are pending */
-               if (fd_cache_num || run_queue || signal_queue_len || !LIST_ISEMPTY(&applet_active_queue))
+               if (fd_cache_num || run_queue || signal_queue_len || applets_active_queue)
                        next = now_ms;
 
                /* The poller will ensure it returns around <next> */