>From 3746edff1786ad967c2299200e7d250456bb33c2 Mon Sep 17 00:00:00 2001
From: Nils Goroll <[email protected]>
Date: Wed, 18 Mar 2015 08:27:37 +0100
Subject: [PATCH] stack space check example
---
bin/varnishtest/tests/c00031.vtc | 17 ++++++++++++++++-
lib/libvmod_debug/vmod.vcc | 4 ++++
lib/libvmod_debug/vmod_debug.c | 18 ++++++++++++++++++
3 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/bin/varnishtest/tests/c00031.vtc b/bin/varnishtest/tests/c00031.vtc
index de30c6d..47fd162 100644
--- a/bin/varnishtest/tests/c00031.vtc
+++ b/bin/varnishtest/tests/c00031.vtc
@@ -2,13 +2,28 @@ varnishtest "Worker thread stack size setting"
server s1 {
rxreq
+ # see comment in client c1
+ expect req.http.stackspace > 240000
+
txresp
} -start
-varnish v1 -arg "-p thread_pool_stack=262144" -vcl+backend {} -start
+varnish v1 -arg "-p thread_pool_stack=262144" -vcl+backend {
+ import ${vmod_debug};
+
+ sub vcl_backend_fetch {
+ set bereq.http.stackspace = debug.stackspace();
+ }
+
+ sub vcl_deliver {
+ set resp.http.stackspace = debug.stackspace();
+ }
+} -start
client c1 {
txreq -url "/"
rxresp
expect resp.status == 200
+ # veery safe margin - should rather be in the order of 250K
+ expect resp.http.stackspace > 240000
} -run
diff --git a/lib/libvmod_debug/vmod.vcc b/lib/libvmod_debug/vmod.vcc
index 434ee78..21dc2e2 100644
--- a/lib/libvmod_debug/vmod.vcc
+++ b/lib/libvmod_debug/vmod.vcc
@@ -101,3 +101,7 @@ $Function INT vre_limit()
$Function VOID register_exp_callback(PRIV_VCL)
Register the vmod to receive expiry callbacks
+
+$Function INT stackspace()
+
+Return an approximation of the stackspace left in the worker thread
diff --git a/lib/libvmod_debug/vmod_debug.c b/lib/libvmod_debug/vmod_debug.c
index 6ef7c15..5fedca3 100644
--- a/lib/libvmod_debug/vmod_debug.c
+++ b/lib/libvmod_debug/vmod_debug.c
@@ -220,6 +220,24 @@ vmod_register_exp_callback(VRT_CTX, struct vmod_priv *priv)
VSL(SLT_Debug, 0, "exp_cb: registered");
}
+VCL_INT
+vmod_stackspace(VRT_CTX)
+{
+ VCL_INT r;
+ struct worker *wrk;
+
+ CHECK_OBJ_NOTNULL(ctx, VRT_CTX_MAGIC);
+
+ wrk = ctx->req ? ctx->req->wrk : ctx->bo->wrk;
+ CHECK_OBJ_NOTNULL(wrk, WORKER_MAGIC);
+
+ assert((uintptr_t)&wrk < wrk->stack_start);
+ assert((uintptr_t)&wrk > wrk->stack_end);
+
+ r = (uintptr_t)&wrk - wrk->stack_end;
+ return (r);
+}
+
static void __match_proto__(vmod_priv_free_f)
priv_vcl_free(void *priv)
{
--
2.1.4
_______________________________________________
varnish-dev mailing list
[email protected]
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-dev