Commit 46dd9617 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move the stat-summing from WRK to Pool where it mostly happens.

parent b1ad9cd6
......@@ -1107,6 +1107,8 @@ void Pool_Init(void);
void Pool_Accept(void);
void Pool_Work_Thread(void *priv, struct worker *w);
int Pool_Task(struct pool *pp, struct pool_task *task, enum pool_how how);
void Pool_Sumstat(struct worker *w);
void Pool_PurgeStat(unsigned nobj);
#define WRW_IsReleased(w) ((w)->wrw == NULL)
int WRW_Error(const struct worker *w);
......@@ -1216,10 +1218,6 @@ void WAIT_Write_Session(struct sess *sp, int fd);
/* cache_wrk.c */
void WRK_Init(void);
int WRK_TrySumStat(struct worker *w);
void WRK_SumStat(struct worker *w);
void WRK_PurgeStat(unsigned nobj);
void *WRK_thread(void *priv);
typedef void *bgthread_t(struct worker *, void *priv);
void WRK_BgThread(pthread_t *thr, const char *name, bgthread_t *func,
......
......@@ -404,7 +404,7 @@ EXP_NukeLRU(struct worker *wrk, struct vsl_log *vsl, struct lru *lru)
}
Lck_Unlock(&lru->mtx);
WRK_SumStat(wrk);
Pool_Sumstat(wrk);
}
#endif
......@@ -589,7 +589,7 @@ exp_thread(struct worker *wrk, void *priv)
tnext = 0;
} else if (tnext > t) {
VSL_Flush(&ep->vsl, 0);
WRK_SumStat(wrk);
Pool_Sumstat(wrk);
(void)Lck_CondWait(&ep->condvar, &ep->mtx, tnext);
}
Lck_Unlock(&ep->mtx);
......
......@@ -603,7 +603,7 @@ double keep)
(void)HSH_DerefObj(&wrk->stats, &o);
}
WS_Release(wrk->aws, 0);
WRK_PurgeStat(nobj);
Pool_PurgeStat(nobj);
}
......
......@@ -217,7 +217,6 @@ child_main(void)
VBO_Init();
VBE_InitCfg();
VBP_Init();
WRK_Init();
Pool_Init();
Pipe_Init();
......
......@@ -78,6 +78,59 @@ static struct lock pool_mtx;
static pthread_t thr_pool_herder;
static unsigned pool_accepting = 0;
static struct lock wstat_mtx;
/*--------------------------------------------------------------------*/
static void
wrk_sumstat(const struct dstat *ds)
{
Lck_AssertHeld(&wstat_mtx);
#define L0(n)
#define L1(n) (VSC_C_main->n += ds->n)
#define VSC_F(n, t, l, f, v, d, e) L##l(n);
#include "tbl/vsc_f_main.h"
#undef VSC_F
#undef L0
#undef L1
}
void
Pool_Sumstat(struct worker *w)
{
Lck_Lock(&wstat_mtx);
wrk_sumstat(&w->stats);
Lck_Unlock(&wstat_mtx);
memset(&w->stats, 0, sizeof w->stats);
}
static int
Pool_TrySumstat(struct worker *w)
{
if (Lck_Trylock(&wstat_mtx))
return (0);
wrk_sumstat(&w->stats);
Lck_Unlock(&wstat_mtx);
memset(&w->stats, 0, sizeof w->stats);
return (1);
}
/*--------------------------------------------------------------------
* Helper function to update stats for purges under lock
*/
void
Pool_PurgeStat(unsigned nobj)
{
Lck_Lock(&wstat_mtx);
VSC_C_main->n_purges++;
VSC_C_main->n_obj_purged += nobj;
Lck_Unlock(&wstat_mtx);
}
/*--------------------------------------------------------------------
*/
......@@ -148,7 +201,7 @@ pool_accept(struct worker *wrk, void *arg)
if (VCA_Accept(ps->lsock, wa) < 0) {
wrk->stats.sess_fail++;
/* We're going to pace in vca anyway... */
(void)WRK_TrySumStat(wrk);
(void)Pool_TrySumstat(wrk);
continue;
}
......@@ -287,7 +340,7 @@ Pool_Work_Thread(void *priv, struct worker *wrk)
wrk->task.priv = wrk;
VTAILQ_INSERT_HEAD(&pp->idle_queue, &wrk->task, list);
if (stats_dirty) {
WRK_SumStat(wrk);
Pool_Sumstat(wrk);
stats_dirty = 0;
}
do {
......@@ -307,9 +360,9 @@ Pool_Work_Thread(void *priv, struct worker *wrk)
tp->func(wrk, tp->priv);
if (++stats_dirty >= cache_param->wthread_stats_rate) {
WRK_SumStat(wrk);
Pool_Sumstat(wrk);
stats_dirty = 0;
} else if (WRK_TrySumStat(wrk))
} else if (Pool_TrySumstat(wrk))
stats_dirty = 0;
}
wrk->pool = NULL;
......@@ -531,6 +584,7 @@ void
Pool_Init(void)
{
Lck_New(&wstat_mtx, lck_wstat);
Lck_New(&pool_mtx, lck_wq);
AZ(pthread_create(&thr_pool_herder, NULL, pool_poolherder, NULL));
}
......@@ -37,59 +37,6 @@
#include "cache.h"
#include "hash/hash_slinger.h"
static struct lock wstat_mtx;
/*--------------------------------------------------------------------*/
static void
wrk_sumstat(const struct dstat *ds)
{
Lck_AssertHeld(&wstat_mtx);
#define L0(n)
#define L1(n) (VSC_C_main->n += ds->n)
#define VSC_F(n, t, l, f, v, d, e) L##l(n);
#include "tbl/vsc_f_main.h"
#undef VSC_F
#undef L0
#undef L1
}
void
WRK_SumStat(struct worker *w)
{
Lck_Lock(&wstat_mtx);
wrk_sumstat(&w->stats);
Lck_Unlock(&wstat_mtx);
memset(&w->stats, 0, sizeof w->stats);
}
int
WRK_TrySumStat(struct worker *w)
{
if (Lck_Trylock(&wstat_mtx))
return (0);
wrk_sumstat(&w->stats);
Lck_Unlock(&wstat_mtx);
memset(&w->stats, 0, sizeof w->stats);
return (1);
}
/*--------------------------------------------------------------------
* Helper function to update stats for purges under lock
*/
void
WRK_PurgeStat(unsigned nobj)
{
Lck_Lock(&wstat_mtx);
VSC_C_main->n_purges++;
VSC_C_main->n_obj_purged += nobj;
Lck_Unlock(&wstat_mtx);
}
/*--------------------------------------------------------------------
* Create and starte a back-ground thread which as its own worker and
* session data structures;
......@@ -164,7 +111,7 @@ wrk_thread_real(void *priv, unsigned thread_workspace)
if (w->nbo != NULL)
VBO_Free(&w->nbo);
HSH_Cleanup(w);
WRK_SumStat(w);
Pool_Sumstat(w);
return (NULL);
}
......@@ -174,9 +121,3 @@ WRK_thread(void *priv)
return (wrk_thread_real(priv, cache_param->workspace_thread));
}
void
WRK_Init(void)
{
Lck_New(&wstat_mtx, lck_wstat);
}
......@@ -369,7 +369,7 @@ hcb_cleaner(struct worker *wrk, void *priv)
VSTAILQ_CONCAT(&dead_y, &cool_y);
VTAILQ_CONCAT(&dead_h, &cool_h, hoh_list);
Lck_Unlock(&hcb_mtx);
WRK_SumStat(wrk);
Pool_Sumstat(wrk);
VTIM_sleep(cache_param->critbit_cooloff);
}
NEEDLESS_RETURN(NULL);
......
......@@ -161,7 +161,7 @@ smp_load_seg(struct worker *wrk, const struct smp_sc *sc,
EXP_Inject(oc, sg->lru, so->ttl);
sg->nobj++;
}
WRK_SumStat(wrk);
Pool_Sumstat(wrk);
sg->flags |= SMP_SEG_LOADED;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment