[master] 771c02cfa wrk: Centralize pool_addstat() conditions
Dridi Boukelmoune
dridi.boukelmoune at gmail.com
Mon Jan 11 17:06:08 UTC 2021
commit 771c02cfa98cfa1e4960f0db91482c1e8d433769
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Wed Oct 21 15:21:29 2020 +0200
wrk: Centralize pool_addstat() conditions
It's a bit dirty because one code paths comes locked while the other one
has the pool unlocked, but this removes the need to duplicate conditions.
The pool_addstat() function was unrolled to its single call site.
diff --git a/bin/varnishd/cache/cache_wrk.c b/bin/varnishd/cache/cache_wrk.c
index 0fbe71229..d32bf16d6 100644
--- a/bin/varnishd/cache/cache_wrk.c
+++ b/bin/varnishd/cache/cache_wrk.c
@@ -160,28 +160,39 @@ WRK_Thread(struct pool *qp, size_t stacksize, unsigned thread_workspace)
* Summing of stats into pool counters
*/
-static void
-pool_addstat(struct VSC_main_wrk *dst, struct VSC_main_wrk *src)
+static unsigned
+wrk_addstat(struct worker *wrk, const struct pool_task *tp, unsigned locked)
{
+ struct pool *pp;
- dst->summs++;
- VSC_main_Summ_wrk_wrk(dst, src);
- memset(src, 0, sizeof *src);
+ CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+ pp = wrk->pool;
+ CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
+ if (locked)
+ Lck_AssertHeld(&pp->mtx);
+
+ if ((tp == NULL && wrk->stats->summs > 0) ||
+ (wrk->stats->summs >= cache_param->wthread_stats_rate)) {
+ if (!locked)
+ Lck_Lock(&pp->mtx);
+
+ pp->a_stat->summs++;
+ VSC_main_Summ_wrk_wrk(pp->a_stat, wrk->stats);
+ memset(wrk->stats, 0, sizeof *wrk->stats);
+
+ if (!locked)
+ Lck_Unlock(&pp->mtx);
+ }
+
+ return (tp == NULL ? 0 : 1);
}
void
WRK_AddStat(struct worker *wrk)
{
- struct pool *pp;
- CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
- pp = wrk->pool;
- CHECK_OBJ_NOTNULL(pp, POOL_MAGIC);
- if (++wrk->stats->summs >= cache_param->wthread_stats_rate) {
- Lck_Lock(&pp->mtx);
- pool_addstat(pp->a_stat, wrk->stats);
- Lck_Unlock(&pp->mtx);
- }
+ (void)wrk_addstat(wrk, wrk->task, 0);
+ wrk->stats->summs++;
}
/*--------------------------------------------------------------------
@@ -385,11 +396,7 @@ Pool_Work_Thread(struct pool *pp, struct worker *wrk)
}
}
- if ((tp == NULL && wrk->stats->summs > 0) ||
- (wrk->stats->summs >= cache_param->wthread_stats_rate))
- pool_addstat(pp->a_stat, wrk->stats);
-
- if (tp != NULL) {
+ if (wrk_addstat(wrk, tp, 1)) {
wrk->stats->summs++;
} else if (pp->b_stat != NULL && pp->a_stat->summs) {
/* Nothing to do, push pool stats into global pool */
More information about the varnish-commit
mailing list