Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
varnish-cache
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
varnishcache
varnish-cache
Commits
c522f7af
Commit
c522f7af
authored
Sep 22, 2014
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Record the start and end of the worker thread stack.
parent
5125065c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
32 deletions
+65
-32
cache.h
bin/varnishd/cache/cache.h
+5
-2
cache_panic.c
bin/varnishd/cache/cache_panic.c
+2
-0
cache_pool.c
bin/varnishd/cache/cache_pool.c
+41
-19
cache_wrk.c
bin/varnishd/cache/cache_wrk.c
+17
-11
No files found.
bin/varnishd/cache/cache.h
View file @
c522f7af
...
@@ -367,6 +367,9 @@ struct worker {
...
@@ -367,6 +367,9 @@ struct worker {
unsigned
cur_method
;
unsigned
cur_method
;
unsigned
seen_methods
;
unsigned
seen_methods
;
unsigned
handling
;
unsigned
handling
;
uintptr_t
stack_start
;
uintptr_t
stack_end
;
};
};
/* LRU ---------------------------------------------------------------*/
/* LRU ---------------------------------------------------------------*/
...
@@ -1020,7 +1023,7 @@ void PipeRequest(struct req *req, struct busyobj *bo);
...
@@ -1020,7 +1023,7 @@ void PipeRequest(struct req *req, struct busyobj *bo);
/* cache_pool.c */
/* cache_pool.c */
void
Pool_Init
(
void
);
void
Pool_Init
(
void
);
void
Pool_Accept
(
void
);
void
Pool_Accept
(
void
);
void
Pool_Work_Thread
(
void
*
priv
,
struct
worker
*
w
);
void
Pool_Work_Thread
(
struct
pool
*
,
struct
worker
*
w
);
int
Pool_Task
(
struct
pool
*
pp
,
struct
pool_task
*
task
,
enum
pool_how
how
);
int
Pool_Task
(
struct
pool
*
pp
,
struct
pool_task
*
task
,
enum
pool_how
how
);
void
Pool_Sumstat
(
struct
worker
*
w
);
void
Pool_Sumstat
(
struct
worker
*
w
);
void
Pool_PurgeStat
(
unsigned
nobj
);
void
Pool_PurgeStat
(
unsigned
nobj
);
...
@@ -1136,7 +1139,7 @@ void WAIT_Write_Session(struct sess *sp, int fd);
...
@@ -1136,7 +1139,7 @@ void WAIT_Write_Session(struct sess *sp, int fd);
/* cache_wrk.c */
/* cache_wrk.c */
void
*
WRK_thread
(
void
*
priv
);
void
WRK_Thread
(
struct
pool
*
qp
,
size_t
stacksize
,
unsigned
thread_workspace
);
typedef
void
*
bgthread_t
(
struct
worker
*
,
void
*
priv
);
typedef
void
*
bgthread_t
(
struct
worker
*
,
void
*
priv
);
void
WRK_BgThread
(
pthread_t
*
thr
,
const
char
*
name
,
bgthread_t
*
func
,
void
WRK_BgThread
(
pthread_t
*
thr
,
const
char
*
name
,
bgthread_t
*
func
,
void
*
priv
);
void
*
priv
);
...
...
bin/varnishd/cache/cache_panic.c
View file @
c522f7af
...
@@ -277,6 +277,8 @@ pan_wrk(const struct worker *wrk)
...
@@ -277,6 +277,8 @@ pan_wrk(const struct worker *wrk)
const
char
*
p
;
const
char
*
p
;
VSB_printf
(
pan_vsp
,
" worker = %p {
\n
"
,
wrk
);
VSB_printf
(
pan_vsp
,
" worker = %p {
\n
"
,
wrk
);
VSB_printf
(
pan_vsp
,
" stack = {0x%jx -> 0x%jx}
\n
"
,
wrk
->
stack_start
,
wrk
->
stack_end
);
pan_ws
(
wrk
->
aws
,
4
);
pan_ws
(
wrk
->
aws
,
4
);
m
=
wrk
->
cur_method
;
m
=
wrk
->
cur_method
;
...
...
bin/varnishd/cache/cache_pool.c
View file @
c522f7af
...
@@ -348,14 +348,13 @@ pool_stat_summ(struct worker *wrk, void *priv)
...
@@ -348,14 +348,13 @@ pool_stat_summ(struct worker *wrk, void *priv)
*/
*/
void
void
Pool_Work_Thread
(
void
*
priv
,
struct
worker
*
wrk
)
Pool_Work_Thread
(
struct
pool
*
pp
,
struct
worker
*
wrk
)
{
{
struct
pool
*
pp
;
struct
pool_task
*
tp
;
struct
pool_task
*
tp
;
struct
pool_task
tps
;
struct
pool_task
tps
;
int
i
;
int
i
;
C
AST_OBJ_NOTNULL
(
pp
,
priv
,
POOL_MAGIC
);
C
HECK_OBJ_NOTNULL
(
pp
,
POOL_MAGIC
);
wrk
->
pool
=
pp
;
wrk
->
pool
=
pp
;
while
(
1
)
{
while
(
1
)
{
Lck_Lock
(
&
pp
->
mtx
);
Lck_Lock
(
&
pp
->
mtx
);
...
@@ -416,15 +415,48 @@ Pool_Work_Thread(void *priv, struct worker *wrk)
...
@@ -416,15 +415,48 @@ Pool_Work_Thread(void *priv, struct worker *wrk)
}
}
/*--------------------------------------------------------------------
/*--------------------------------------------------------------------
* Create another thread.
* Create another
worker
thread.
*/
*/
struct
pool_info
{
unsigned
magic
;
#define POOL_INFO_MAGIC 0x4e4442d3
size_t
stacksize
;
struct
pool
*
qp
;
};
static
void
*
pool_thread
(
void
*
priv
)
{
struct
pool_info
*
pi
;
CAST_OBJ_NOTNULL
(
pi
,
priv
,
POOL_INFO_MAGIC
);
WRK_Thread
(
pi
->
qp
,
pi
->
stacksize
,
cache_param
->
workspace_thread
);
FREE_OBJ
(
pi
);
return
(
NULL
);
}
static
void
static
void
pool_breed
(
struct
pool
*
qp
,
const
pthread_attr_t
*
tp_attr
)
pool_breed
(
struct
pool
*
qp
)
{
{
pthread_t
tp
;
pthread_t
tp
;
pthread_attr_t
tp_attr
;
struct
pool_info
*
pi
;
AZ
(
pthread_attr_init
(
&
tp_attr
));
AZ
(
pthread_attr_setdetachstate
(
&
tp_attr
,
PTHREAD_CREATE_DETACHED
));
/* Set the stacksize for worker threads we create */
if
(
cache_param
->
wthread_stacksize
!=
UINT_MAX
)
AZ
(
pthread_attr_setstacksize
(
&
tp_attr
,
cache_param
->
wthread_stacksize
));
ALLOC_OBJ
(
pi
,
POOL_INFO_MAGIC
);
AN
(
pi
);
AZ
(
pthread_attr_getstacksize
(
&
tp_attr
,
&
pi
->
stacksize
));
pi
->
qp
=
qp
;
if
(
pthread_create
(
&
tp
,
tp_attr
,
WRK_thread
,
qp
))
{
if
(
pthread_create
(
&
tp
,
&
tp_attr
,
pool_thread
,
pi
))
{
VSL
(
SLT_Debug
,
0
,
"Create worker thread failed %d %s"
,
VSL
(
SLT_Debug
,
0
,
"Create worker thread failed %d %s"
,
errno
,
strerror
(
errno
));
errno
,
strerror
(
errno
));
Lck_Lock
(
&
pool_mtx
);
Lck_Lock
(
&
pool_mtx
);
...
@@ -432,7 +464,6 @@ pool_breed(struct pool *qp, const pthread_attr_t *tp_attr)
...
@@ -432,7 +464,6 @@ pool_breed(struct pool *qp, const pthread_attr_t *tp_attr)
Lck_Unlock
(
&
pool_mtx
);
Lck_Unlock
(
&
pool_mtx
);
VTIM_sleep
(
cache_param
->
wthread_fail_delay
);
VTIM_sleep
(
cache_param
->
wthread_fail_delay
);
}
else
{
}
else
{
AZ
(
pthread_detach
(
tp
));
qp
->
dry
=
0
;
qp
->
dry
=
0
;
qp
->
nthr
++
;
qp
->
nthr
++
;
Lck_Lock
(
&
pool_mtx
);
Lck_Lock
(
&
pool_mtx
);
...
@@ -441,6 +472,8 @@ pool_breed(struct pool *qp, const pthread_attr_t *tp_attr)
...
@@ -441,6 +472,8 @@ pool_breed(struct pool *qp, const pthread_attr_t *tp_attr)
Lck_Unlock
(
&
pool_mtx
);
Lck_Unlock
(
&
pool_mtx
);
VTIM_sleep
(
cache_param
->
wthread_add_delay
);
VTIM_sleep
(
cache_param
->
wthread_add_delay
);
}
}
AZ
(
pthread_attr_destroy
(
&
tp_attr
));
}
}
/*--------------------------------------------------------------------
/*--------------------------------------------------------------------
...
@@ -463,27 +496,16 @@ pool_herder(void *priv)
...
@@ -463,27 +496,16 @@ pool_herder(void *priv)
{
{
struct
pool
*
pp
;
struct
pool
*
pp
;
struct
pool_task
*
pt
;
struct
pool_task
*
pt
;
pthread_attr_t
tp_attr
;
double
t_idle
;
double
t_idle
;
struct
worker
*
wrk
;
struct
worker
*
wrk
;
CAST_OBJ_NOTNULL
(
pp
,
priv
,
POOL_MAGIC
);
CAST_OBJ_NOTNULL
(
pp
,
priv
,
POOL_MAGIC
);
AZ
(
pthread_attr_init
(
&
tp_attr
));
while
(
1
)
{
while
(
1
)
{
/* Set the stacksize for worker threads we create */
if
(
cache_param
->
wthread_stacksize
!=
UINT_MAX
)
AZ
(
pthread_attr_setstacksize
(
&
tp_attr
,
cache_param
->
wthread_stacksize
));
else
{
AZ
(
pthread_attr_destroy
(
&
tp_attr
));
AZ
(
pthread_attr_init
(
&
tp_attr
));
}
/* Make more threads if needed and allowed */
/* Make more threads if needed and allowed */
if
(
pp
->
nthr
<
cache_param
->
wthread_min
||
if
(
pp
->
nthr
<
cache_param
->
wthread_min
||
(
pp
->
dry
&&
pp
->
nthr
<
cache_param
->
wthread_max
))
{
(
pp
->
dry
&&
pp
->
nthr
<
cache_param
->
wthread_max
))
{
pool_breed
(
pp
,
&
tp_attr
);
pool_breed
(
pp
);
continue
;
continue
;
}
}
...
...
bin/varnishd/cache/cache_wrk.c
View file @
c522f7af
...
@@ -32,6 +32,7 @@
...
@@ -32,6 +32,7 @@
#include "config.h"
#include "config.h"
#include <math.h>
#include <math.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdlib.h>
#include "cache.h"
#include "cache.h"
...
@@ -84,11 +85,16 @@ WRK_BgThread(pthread_t *thr, const char *name, bgthread_t *func, void *priv)
...
@@ -84,11 +85,16 @@ WRK_BgThread(pthread_t *thr, const char *name, bgthread_t *func, void *priv)
/*--------------------------------------------------------------------*/
/*--------------------------------------------------------------------*/
static
void
*
void
wrk_thread_real
(
void
*
priv
,
unsigned
thread_workspace
)
WRK_Thread
(
struct
pool
*
qp
,
size_t
stacksize
,
unsigned
thread_workspace
)
{
{
struct
worker
*
w
,
ww
;
struct
worker
*
w
,
ww
;
unsigned
char
ws
[
thread_workspace
];
unsigned
char
ws
[
thread_workspace
];
uintptr_t
u
;
AN
(
qp
);
AN
(
stacksize
);
AN
(
thread_workspace
);
THR_SetName
(
"cache-worker"
);
THR_SetName
(
"cache-worker"
);
w
=
&
ww
;
w
=
&
ww
;
...
@@ -99,9 +105,17 @@ wrk_thread_real(void *priv, unsigned thread_workspace)
...
@@ -99,9 +105,17 @@ wrk_thread_real(void *priv, unsigned thread_workspace)
WS_Init
(
w
->
aws
,
"wrk"
,
ws
,
thread_workspace
);
WS_Init
(
w
->
aws
,
"wrk"
,
ws
,
thread_workspace
);
u
=
getpagesize
();
AN
(
u
);
u
-=
1U
;
w
->
stack_start
=
(((
uintptr_t
)
&
qp
)
+
u
)
&
~
u
;
/* XXX: assuming stack grows down. */
w
->
stack_end
=
w
->
stack_start
-
stacksize
;
VSL
(
SLT_WorkThread
,
0
,
"%p start"
,
w
);
VSL
(
SLT_WorkThread
,
0
,
"%p start"
,
w
);
Pool_Work_Thread
(
priv
,
w
);
Pool_Work_Thread
(
qp
,
w
);
AZ
(
w
->
pool
);
AZ
(
w
->
pool
);
VSL
(
SLT_WorkThread
,
0
,
"%p end"
,
w
);
VSL
(
SLT_WorkThread
,
0
,
"%p end"
,
w
);
...
@@ -112,12 +126,4 @@ wrk_thread_real(void *priv, unsigned thread_workspace)
...
@@ -112,12 +126,4 @@ wrk_thread_real(void *priv, unsigned thread_workspace)
VBO_Free
(
&
w
->
nbo
);
VBO_Free
(
&
w
->
nbo
);
HSH_Cleanup
(
w
);
HSH_Cleanup
(
w
);
Pool_Sumstat
(
w
);
Pool_Sumstat
(
w
);
return
(
NULL
);
}
void
*
WRK_thread
(
void
*
priv
)
{
return
(
wrk_thread_real
(
priv
,
cache_param
->
workspace_thread
));
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment