mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 06:11:32 +02:00
MINOR: applet: Count number of (active) applets
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]
This commit is contained in:
parent
90b5abe46e
commit
1cbe74cd83
@ -29,6 +29,9 @@
|
|||||||
#include <types/applet.h>
|
#include <types/applet.h>
|
||||||
#include <proto/connection.h>
|
#include <proto/connection.h>
|
||||||
|
|
||||||
|
extern unsigned int nb_applets;
|
||||||
|
extern unsigned int applets_active_queue;
|
||||||
|
|
||||||
extern struct list applet_active_queue;
|
extern struct list applet_active_queue;
|
||||||
|
|
||||||
void applet_run_active();
|
void applet_run_active();
|
||||||
@ -58,6 +61,7 @@ static inline struct appctx *appctx_new(struct applet *applet)
|
|||||||
appctx->applet = applet;
|
appctx->applet = applet;
|
||||||
appctx_init(appctx);
|
appctx_init(appctx);
|
||||||
LIST_INIT(&appctx->runq);
|
LIST_INIT(&appctx->runq);
|
||||||
|
nb_applets++;
|
||||||
}
|
}
|
||||||
return appctx;
|
return appctx;
|
||||||
}
|
}
|
||||||
@ -67,16 +71,21 @@ static inline struct appctx *appctx_new(struct applet *applet)
|
|||||||
*/
|
*/
|
||||||
static inline void appctx_free(struct appctx *appctx)
|
static inline void appctx_free(struct appctx *appctx)
|
||||||
{
|
{
|
||||||
if (!LIST_ISEMPTY(&appctx->runq))
|
if (!LIST_ISEMPTY(&appctx->runq)) {
|
||||||
LIST_DEL(&appctx->runq);
|
LIST_DEL(&appctx->runq);
|
||||||
|
applets_active_queue--;
|
||||||
|
}
|
||||||
pool_free2(pool2_connection, appctx);
|
pool_free2(pool2_connection, appctx);
|
||||||
|
nb_applets--;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* wakes up an applet when conditions have changed */
|
/* wakes up an applet when conditions have changed */
|
||||||
static inline void appctx_wakeup(struct appctx *appctx)
|
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);
|
LIST_ADDQ(&applet_active_queue, &appctx->runq);
|
||||||
|
applets_active_queue++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* removes an applet from the list of active applets */
|
/* 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)) {
|
if (!LIST_ISEMPTY(&appctx->runq)) {
|
||||||
LIST_DEL(&appctx->runq);
|
LIST_DEL(&appctx->runq);
|
||||||
LIST_INIT(&appctx->runq);
|
LIST_INIT(&appctx->runq);
|
||||||
|
applets_active_queue--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
17
src/applet.c
17
src/applet.c
@ -19,8 +19,11 @@
|
|||||||
#include <proto/stream.h>
|
#include <proto/stream.h>
|
||||||
#include <proto/stream_interface.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_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()
|
void applet_run_active()
|
||||||
{
|
{
|
||||||
@ -31,18 +34,18 @@ void applet_run_active()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* move active queue to run queue */
|
/* move active queue to run queue */
|
||||||
applet_active_queue.n->p = &applet_run_queue;
|
applet_active_queue.n->p = &applet_cur_queue;
|
||||||
applet_active_queue.p->n = &applet_run_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);
|
LIST_INIT(&applet_active_queue);
|
||||||
|
|
||||||
/* The list is only scanned from the head. This guarantees that if any
|
/* The list is only scanned from the head. This guarantees that if any
|
||||||
* applet removes another one, there is no side effect while walking
|
* applet removes another one, there is no side effect while walking
|
||||||
* through the list.
|
* through the list.
|
||||||
*/
|
*/
|
||||||
while (!LIST_ISEMPTY(&applet_run_queue)) {
|
while (!LIST_ISEMPTY(&applet_cur_queue)) {
|
||||||
curr = LIST_ELEM(applet_run_queue.n, typeof(curr), runq);
|
curr = LIST_ELEM(applet_cur_queue.n, typeof(curr), runq);
|
||||||
si = curr->owner;
|
si = curr->owner;
|
||||||
|
|
||||||
/* now we'll need a buffer */
|
/* now we'll need a buffer */
|
||||||
@ -63,7 +66,7 @@ void applet_run_active()
|
|||||||
curr->applet->fct(curr);
|
curr->applet->fct(curr);
|
||||||
si_applet_wake_cb(si);
|
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 */
|
/* curr was left in the list, move it back to the active list */
|
||||||
LIST_DEL(&curr->runq);
|
LIST_DEL(&curr->runq);
|
||||||
LIST_ADDQ(&applet_active_queue, &curr->runq);
|
LIST_ADDQ(&applet_active_queue, &curr->runq);
|
||||||
|
@ -1730,7 +1730,7 @@ void run_poll_loop()
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
/* expire immediately if events are pending */
|
/* 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;
|
next = now_ms;
|
||||||
|
|
||||||
/* The poller will ensure it returns around <next> */
|
/* The poller will ensure it returns around <next> */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user