[master] 73ba50b Hand back an opaque pointer to VSC segments.
Poul-Henning Kamp
phk at FreeBSD.org
Fri Dec 22 09:58:09 UTC 2017
commit 73ba50b89ad9d33f62453667c8e8e93074f0f5cf
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Fri Dec 22 09:56:05 2017 +0000
Hand back an opaque pointer to VSC segments.
This eliminates a O(N) lookup when we want to do something
(ie: Destroy) to a VSC segment subsequently.
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index 189e5ef..fdf131f 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -757,8 +757,7 @@ int Lck_CondWait(pthread_cond_t *cond, struct lock *lck, double);
assert(Lck__Owned(a)); \
} while (0)
-struct VSC_lck *Lck_CreateClass(const char *name);
-void Lck_DestroyClass(struct VSC_lck **vsclck);
+struct VSC_lck *Lck_CreateClass(struct vsc_seg **, const char *name);
#define LOCK(nam) extern struct VSC_lck *lck_##nam;
#include "tbl/locks.h"
diff --git a/bin/varnishd/cache/cache_backend.c b/bin/varnishd/cache/cache_backend.c
index d1e5525..3b67257 100644
--- a/bin/varnishd/cache/cache_backend.c
+++ b/bin/varnishd/cache/cache_backend.c
@@ -335,14 +335,14 @@ static void
vbe_dir_event(const struct director *d, enum vcl_event_e ev)
{
struct backend *bp;
- struct VSC_vbe *vsc;
CHECK_OBJ_NOTNULL(d, DIRECTOR_MAGIC);
CAST_OBJ_NOTNULL(bp, d->priv, BACKEND_MAGIC);
if (ev == VCL_EVENT_WARM) {
AZ(bp->vsc);
- bp->vsc = VSC_vbe_New(bp->director->display_name);
+ bp->vsc =
+ VSC_vbe_New(&bp->vsc_seg, bp->director->display_name);
AN(bp->vsc);
}
@@ -353,13 +353,10 @@ vbe_dir_event(const struct director *d, enum vcl_event_e ev)
VBP_Control(bp, 0);
if (ev == VCL_EVENT_COLD) {
- AN(bp->vsc);
Lck_Lock(&backends_mtx);
- vsc = bp->vsc;
bp->vsc = NULL;
Lck_Unlock(&backends_mtx);
- VSC_vbe_Destroy(&vsc);
- AZ(bp->vsc);
+ VSC_vbe_Destroy(&bp->vsc_seg);
}
}
diff --git a/bin/varnishd/cache/cache_backend.h b/bin/varnishd/cache/cache_backend.h
index ff3cde3..b0a0442 100644
--- a/bin/varnishd/cache/cache_backend.h
+++ b/bin/varnishd/cache/cache_backend.h
@@ -59,6 +59,7 @@ struct backend {
struct vbp_target *probe;
+ struct vsc_seg *vsc_seg;
struct VSC_vbe *vsc;
struct tcp_pool *tcp_pool;
diff --git a/bin/varnishd/cache/cache_lck.c b/bin/varnishd/cache/cache_lck.c
index ee3e864..1509723 100644
--- a/bin/varnishd/cache/cache_lck.c
+++ b/bin/varnishd/cache/cache_lck.c
@@ -245,15 +245,9 @@ Lck_Delete(struct lock *lck)
}
struct VSC_lck *
-Lck_CreateClass(const char *name)
+Lck_CreateClass(struct vsc_seg **sg, const char *name)
{
- return(VSC_lck_New(name));
-}
-
-void
-Lck_DestroyClass(struct VSC_lck **vsclck)
-{
- VSC_lck_Destroy(vsclck);
+ return(VSC_lck_New(sg, name));
}
#define LOCK(nam) struct VSC_lck *lck_##nam;
@@ -265,6 +259,6 @@ LCK_Init(void)
AZ(pthread_mutexattr_init(&attr));
AZ(pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_ERRORCHECK));
-#define LOCK(nam) lck_##nam = Lck_CreateClass(#nam);
+#define LOCK(nam) lck_##nam = Lck_CreateClass(NULL, #nam);
#include "tbl/locks.h"
}
diff --git a/bin/varnishd/cache/cache_mempool.c b/bin/varnishd/cache/cache_mempool.c
index 9017532..1a9f040 100644
--- a/bin/varnishd/cache/cache_mempool.c
+++ b/bin/varnishd/cache/cache_mempool.c
@@ -59,6 +59,7 @@ struct mempool {
volatile struct poolparam *param;
volatile unsigned *cur_size;
uint64_t live;
+ struct vsc_seg *vsc_seg;
struct VSC_mempool *vsc;
unsigned n_pool;
pthread_t thread;
@@ -160,7 +161,7 @@ mpl_guard(void *priv)
FREE_OBJ(mi);
mi = NULL;
}
- VSC_mempool_Destroy(&mpl->vsc);
+ VSC_mempool_Destroy(&mpl->vsc_seg);
Lck_Unlock(&mpl->mtx);
Lck_Delete(&mpl->mtx);
FREE_OBJ(mpl);
@@ -238,7 +239,7 @@ MPL_New(const char *name,
VTAILQ_INIT(&mpl->surplus);
Lck_New(&mpl->mtx, lck_mempool);
/* XXX: prealloc min_pool */
- mpl->vsc = VSC_mempool_New(mpl->name + 4);
+ mpl->vsc = VSC_mempool_New(&mpl->vsc_seg, mpl->name + 4);
AN(mpl->vsc);
AZ(pthread_create(&mpl->thread, NULL, mpl_guard, mpl));
AZ(pthread_detach(mpl->thread));
diff --git a/bin/varnishd/cache/cache_shmlog.c b/bin/varnishd/cache/cache_shmlog.c
index f663bff..cbb72a8 100644
--- a/bin/varnishd/cache/cache_shmlog.c
+++ b/bin/varnishd/cache/cache_shmlog.c
@@ -505,7 +505,7 @@ VSM_Init(void)
vsc_lock = vsm_vsc_lock;
vsc_unlock = vsm_vsc_unlock;
- VSC_C_main = VSC_main_New("");
+ VSC_C_main = VSC_main_New(NULL, "");
AN(VSC_C_main);
AN(heritage.proc_vsmw);
diff --git a/bin/varnishd/common/common_vsc.c b/bin/varnishd/common/common_vsc.c
index 7f9f239..1e8842d 100644
--- a/bin/varnishd/common/common_vsc.c
+++ b/bin/varnishd/common/common_vsc.c
@@ -49,29 +49,29 @@
/*--------------------------------------------------------------------*/
-struct vsc_segs {
+struct vsc_seg {
unsigned magic;
-#define VSC_SEGS_MAGIC 0x9b355991
+#define VSC_SEG_MAGIC 0x9b355991
const char *nm;
- VTAILQ_ENTRY(vsc_segs) list;
+ VTAILQ_ENTRY(vsc_seg) list;
void *seg;
struct vsc_head *head;
void *ptr;
};
-static VTAILQ_HEAD(,vsc_segs) vsc_seglist =
+static VTAILQ_HEAD(,vsc_seg) vsc_seglist =
VTAILQ_HEAD_INITIALIZER(vsc_seglist);
vsc_callback_f *vsc_lock;
vsc_callback_f *vsc_unlock;
void *
-VRT_VSC_Alloc(const char *nm, size_t sd, const unsigned char *jp,
- size_t sj, const char *fmt, va_list va)
+VRT_VSC_Alloc(struct vsc_seg **sg, const char *nm, size_t sd,
+ const unsigned char *jp, size_t sj, const char *fmt, va_list va)
{
char *p;
- struct vsc_segs *vsg;
+ struct vsc_seg *vsg;
char buf[1024];
uint64_t co, jo;
@@ -90,7 +90,7 @@ VRT_VSC_Alloc(const char *nm, size_t sd, const unsigned char *jp,
jo + PRNDUP(sj), buf, va);
AN(p);
- ALLOC_OBJ(vsg, VSC_SEGS_MAGIC);
+ ALLOC_OBJ(vsg, VSC_SEG_MAGIC);
AN(vsg);
vsg->seg = p;
vsg->head = (void*)p;
@@ -103,22 +103,20 @@ VRT_VSC_Alloc(const char *nm, size_t sd, const unsigned char *jp,
vsg->nm = nm;
if (vsc_unlock != NULL)
vsc_unlock();
+ if (sg != NULL)
+ *sg = vsg;
return (vsg->ptr);
}
void
-VRT_VSC_Destroy(const char *nm, const void *p)
+VRT_VSC_Destroy(const char *nm, struct vsc_seg *vsg)
{
- struct vsc_segs *vsg;
if (vsc_lock != NULL)
vsc_lock();
AN(heritage.proc_vsmw);
- VTAILQ_FOREACH(vsg, &vsc_seglist, list)
- if (vsg->ptr == p)
- break;
- AN(vsg);
+ CHECK_OBJ_NOTNULL(vsg, VSC_SEG_MAGIC);
assert(vsg->nm == nm);
VSMW_Free(heritage.proc_vsmw, &vsg->seg);
VTAILQ_REMOVE(&vsc_seglist, vsg, list);
diff --git a/bin/varnishd/hash/hash_classic.c b/bin/varnishd/hash/hash_classic.c
index 33704e4..3440b9b 100644
--- a/bin/varnishd/hash/hash_classic.c
+++ b/bin/varnishd/hash/hash_classic.c
@@ -94,7 +94,7 @@ hcl_start(void)
{
unsigned u;
- lck_hcl = Lck_CreateClass("hcl");
+ lck_hcl = Lck_CreateClass(NULL, "hcl");
hcl_head = calloc(hcl_nhash, sizeof *hcl_head);
XXXAN(hcl_head);
diff --git a/bin/varnishd/hash/hash_simple_list.c b/bin/varnishd/hash/hash_simple_list.c
index e2726ea..4c1e902 100644
--- a/bin/varnishd/hash/hash_simple_list.c
+++ b/bin/varnishd/hash/hash_simple_list.c
@@ -52,7 +52,7 @@ static void v_matchproto_(hash_start_f)
hsl_start(void)
{
- lck_hsl = Lck_CreateClass("hsl");
+ lck_hsl = Lck_CreateClass(NULL, "hsl");
Lck_New(&hsl_mtx, lck_hsl);
}
diff --git a/bin/varnishd/mgt/mgt.h b/bin/varnishd/mgt/mgt.h
index 9a03a4a..46595d2 100644
--- a/bin/varnishd/mgt/mgt.h
+++ b/bin/varnishd/mgt/mgt.h
@@ -48,6 +48,7 @@
#include "common/common_param.h"
+struct vsc_seg;
#include "VSC_mgt.h"
struct cli;
diff --git a/bin/varnishd/mgt/mgt_main.c b/bin/varnishd/mgt/mgt_main.c
index cf9c454..da963b5 100644
--- a/bin/varnishd/mgt/mgt_main.c
+++ b/bin/varnishd/mgt/mgt_main.c
@@ -808,7 +808,7 @@ main(int argc, char * const *argv)
mgt_SHM_Init();
mgt_SHM_static_alloc(i_arg, strlen(i_arg) + 1L, "Arg", "-i");
- VSC_C_mgt = VSC_mgt_New("");
+ VSC_C_mgt = VSC_mgt_New(NULL, "");
if (M_arg != NULL)
mgt_cli_master(M_arg);
diff --git a/bin/varnishd/storage/storage_file.c b/bin/varnishd/storage/storage_file.c
index 285a62d..af2817f 100644
--- a/bin/varnishd/storage/storage_file.c
+++ b/bin/varnishd/storage/storage_file.c
@@ -411,9 +411,9 @@ smf_open(struct stevedore *st)
ASSERT_CLI();
st->lru = LRU_Alloc();
if (lck_smf == NULL)
- lck_smf = Lck_CreateClass("smf");
+ lck_smf = Lck_CreateClass(NULL, "smf");
CAST_OBJ_NOTNULL(sc, st->priv, SMF_SC_MAGIC);
- sc->stats = VSC_smf_New(st->ident);
+ sc->stats = VSC_smf_New(NULL, st->ident);
Lck_New(&sc->mtx, lck_smf);
Lck_Lock(&sc->mtx);
smf_open_chunk(sc, sc->filesize, 0, &fail, &sum);
diff --git a/bin/varnishd/storage/storage_malloc.c b/bin/varnishd/storage/storage_malloc.c
index e82217e..4ea548b 100644
--- a/bin/varnishd/storage/storage_malloc.c
+++ b/bin/varnishd/storage/storage_malloc.c
@@ -210,10 +210,10 @@ sma_open(struct stevedore *st)
ASSERT_CLI();
st->lru = LRU_Alloc();
if (lck_sma == NULL)
- lck_sma = Lck_CreateClass("sma");
+ lck_sma = Lck_CreateClass(NULL, "sma");
CAST_OBJ_NOTNULL(sma_sc, st->priv, SMA_SC_MAGIC);
Lck_New(&sma_sc->sma_mtx, lck_sma);
- sma_sc->stats = VSC_sma_New(st->ident);
+ sma_sc->stats = VSC_sma_New(NULL, st->ident);
if (sma_sc->sma_max != SIZE_MAX)
sma_sc->stats->g_space = sma_sc->sma_max;
}
diff --git a/bin/varnishd/storage/storage_persistent.c b/bin/varnishd/storage/storage_persistent.c
index 59af759..95f7b4f 100644
--- a/bin/varnishd/storage/storage_persistent.c
+++ b/bin/varnishd/storage/storage_persistent.c
@@ -679,7 +679,7 @@ static struct cli_proto debug_cmds[] = {
static void
smp_init(void)
{
- lck_smp = Lck_CreateClass("smp");
+ lck_smp = Lck_CreateClass(NULL, "smp");
CLI_AddFuncs(debug_cmds);
smp_oc_realmethods = SML_methods;
smp_oc_realmethods.objtouch = NULL;
diff --git a/include/vrt.h b/include/vrt.h
index 6c96796..ee440aa 100644
--- a/include/vrt.h
+++ b/include/vrt.h
@@ -112,6 +112,7 @@ struct vmod;
struct vmod_priv;
struct vrt_acl;
struct vsb;
+struct vsc_seg;
struct vsl_log;
struct ws;
@@ -443,7 +444,7 @@ VCL_STRING VRT_STRANDS_string(VCL_STRANDS);
VCL_STRING VRT_TIME_string(VRT_CTX, VCL_TIME);
#ifdef va_start // XXX: hackish
-void *VRT_VSC_Alloc(const char *, size_t, const unsigned char *, size_t,
- const char *, va_list);
-void VRT_VSC_Destroy(const char *, const void *);
+void *VRT_VSC_Alloc(struct vsc_seg **, const char *, size_t,
+ const unsigned char *, size_t, const char *, va_list);
+void VRT_VSC_Destroy(const char *, struct vsc_seg *);
#endif
diff --git a/lib/libvcc/vsctool.py b/lib/libvcc/vsctool.py
index da89aee..98283ed 100644
--- a/lib/libvcc/vsctool.py
+++ b/lib/libvcc/vsctool.py
@@ -144,10 +144,10 @@ class vscset(object):
fo.write("\n");
fo.write(self.struct + " *VSC_" + self.name + "_New")
- fo.write("(const char *fmt, ...);\n");
+ fo.write("(struct vsc_seg **, const char *fmt, ...);\n");
fo.write("void VSC_" + self.name + "_Destroy")
- fo.write("(" + self.struct + "**);\n")
+ fo.write("(struct vsc_seg **);\n")
if 'sumfunction' in self.head.param:
fo.write("void VSC_" + self.name + "_Summ")
@@ -186,14 +186,14 @@ class vscset(object):
fo.write("\n")
fo.write(self.struct + "*\n");
fo.write("VSC_" + self.name + "_New")
- fo.write("(const char *fmt, ...)\n");
+ fo.write("(struct vsc_seg **sg, const char *fmt, ...)\n");
fo.write("{\n")
fo.write("\tva_list ap;\n")
fo.write("\t" + self.struct + " *retval;\n")
fo.write("\n")
fo.write("\tva_start(ap, fmt);\n")
fo.write("\tretval = VRT_VSC_Alloc")
- fo.write("(vsc_" + self.name + "_name, ")
+ fo.write("(sg, vsc_" + self.name + "_name, ")
fo.write("sizeof(" + self.struct + "),\n\t ")
fo.write("vsc_" + self.name + "_json, ")
fo.write("sizeof vsc_" + self.name + "_json, fmt, ap);\n")
@@ -204,13 +204,13 @@ class vscset(object):
fo.write("\n")
fo.write("void\n")
fo.write("VSC_" + self.name + "_Destroy")
- fo.write("(" + self.struct + " **pp)\n")
+ fo.write("(struct vsc_seg **sg)\n")
fo.write("{\n")
- fo.write("\t" + self.struct + "*p;\n")
+ fo.write("\tstruct vsc_seg *p;\n")
fo.write("\n")
- fo.write("\tAN(pp);\n")
- fo.write("\tp = *pp;\n")
- fo.write("\t*pp = NULL;\n")
+ fo.write("\tAN(sg);\n")
+ fo.write("\tp = *sg;\n")
+ fo.write("\t*sg = NULL;\n")
fo.write('\tVRT_VSC_Destroy(vsc_%s_name, p);\n' % self.name)
fo.write("}\n")
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index c24d78a..2298d10 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -66,6 +66,7 @@ struct priv_vcl {
static VCL_DURATION vcl_release_delay = 0.0;
static pthread_mutex_t vsc_mtx = PTHREAD_MUTEX_INITIALIZER;
+static struct vsc_seg *vsc_seg;
static struct VSC_debug *vsc;
VCL_VOID v_matchproto_(td_debug_panic)
@@ -361,7 +362,7 @@ event_function(VRT_CTX, struct vmod_priv *priv, enum vcl_event_e e)
case VCL_EVENT_COLD: return (event_cold(ctx, priv));
case VCL_EVENT_DISCARD:
if (vsc)
- VSC_debug_Destroy(&vsc);
+ VSC_debug_Destroy(&vsc_seg);
return (0);
default: return (0);
}
@@ -584,7 +585,7 @@ xyzzy_vsc_new(VRT_CTX)
(void)ctx;
AZ(pthread_mutex_lock(&vsc_mtx));
if (vsc == NULL)
- vsc = VSC_debug_New("");
+ vsc = VSC_debug_New(&vsc_seg, "");
AN(vsc);
AZ(pthread_mutex_unlock(&vsc_mtx));
}
@@ -594,8 +595,8 @@ xyzzy_vsc_destroy(VRT_CTX)
{
(void)ctx;
AZ(pthread_mutex_lock(&vsc_mtx));
- if (vsc)
- VSC_debug_Destroy(&vsc);
+ if (vsc != NULL)
+ VSC_debug_Destroy(&vsc_seg);
AZ(vsc);
AZ(pthread_mutex_unlock(&vsc_mtx));
}
More information about the varnish-commit
mailing list