Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
U
unique-xids
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
uplex-varnish
unique-xids
Commits
69256c8e
Commit
69256c8e
authored
Jan 23, 2012
by
Poul-Henning Kamp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the list in the embedded task object to hold idle threads that saves
two pointers in workers.
parent
5b969ad5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
15 deletions
+37
-15
cache.h
bin/varnishd/cache/cache.h
+0
-1
cache_pool.c
bin/varnishd/cache/cache_pool.c
+37
-14
No files found.
bin/varnishd/cache/cache.h
View file @
69256c8e
...
...
@@ -335,7 +335,6 @@ struct worker {
pthread_cond_t
cond
;
VTAILQ_ENTRY
(
worker
)
list
;
struct
sess
*
sp
;
struct
VCL_conf
*
vcl
;
...
...
bin/varnishd/cache/cache_pool.c
View file @
69256c8e
...
...
@@ -80,7 +80,7 @@ pthread_condattr_setclock(pthread_condattr_t *attr, int foo)
}
#endif
/* !CLOCK_MONOTONIC */
VTAILQ_HEAD
(
workerhead
,
worker
);
VTAILQ_HEAD
(
taskhead
,
pool_task
);
struct
poolsock
{
unsigned
magic
;
...
...
@@ -101,9 +101,9 @@ struct pool {
pthread_t
herder_thr
;
struct
lock
mtx
;
struct
workerhead
idl
e
;
VTAILQ_HEAD
(,
pool_task
)
front_queue
;
VTAILQ_HEAD
(,
pool_task
)
back_queue
;
struct
taskhead
idle_queu
e
;
struct
taskhead
front_queue
;
struct
taskhead
back_queue
;
VTAILQ_HEAD
(,
poolsock
)
socks
;
unsigned
nthr
;
unsigned
lqueue
;
...
...
@@ -116,6 +116,27 @@ struct pool {
static
struct
lock
pool_mtx
;
static
pthread_t
thr_pool_herder
;
/*--------------------------------------------------------------------
*/
static
struct
worker
*
pool_getidleworker
(
const
struct
pool
*
pp
,
int
back
)
{
struct
pool_task
*
pt
;
struct
worker
*
wrk
;
CHECK_OBJ_NOTNULL
(
pp
,
POOL_MAGIC
);
if
(
back
)
pt
=
VTAILQ_LAST
(
&
pp
->
idle_queue
,
taskhead
);
else
pt
=
VTAILQ_FIRST
(
&
pp
->
idle_queue
);
if
(
pt
==
NULL
)
return
(
NULL
);
AZ
(
pt
->
func
);
CAST_OBJ_NOTNULL
(
wrk
,
pt
->
priv
,
WORKER_MAGIC
);
return
(
wrk
);
}
/*--------------------------------------------------------------------
* Nobody is accepting on this socket, so we do.
*
...
...
@@ -161,10 +182,10 @@ pool_accept(struct pool *pp, struct worker *wrk, const struct poolsock *ps)
}
Lck_Lock
(
&
pp
->
mtx
);
if
(
VTAILQ_EMPTY
(
&
pp
->
idle
))
wrk2
=
pool_getidleworker
(
pp
,
0
);
if
(
wrk2
==
NULL
)
return
(
0
);
wrk2
=
VTAILQ_FIRST
(
&
pp
->
idle
);
VTAILQ_REMOVE
(
&
pp
->
idle
,
wrk2
,
list
);
VTAILQ_REMOVE
(
&
pp
->
idle_queue
,
&
wrk2
->
task
,
list
);
Lck_Unlock
(
&
pp
->
mtx
);
assert
(
sizeof
*
wa2
==
WS_Reserve
(
wrk2
->
ws
,
sizeof
*
wa2
));
wa2
=
(
void
*
)
wrk2
->
ws
->
f
;
...
...
@@ -194,9 +215,9 @@ Pool_Task(struct pool *pp, struct pool_task *task, enum pool_how how)
* The common case first: Take an idle thread, do it.
*/
wrk
=
VTAILQ_FIRST
(
&
pp
->
idle
);
wrk
=
pool_getidleworker
(
pp
,
0
);
if
(
wrk
!=
NULL
)
{
VTAILQ_REMOVE
(
&
pp
->
idle
,
wr
k
,
list
);
VTAILQ_REMOVE
(
&
pp
->
idle
_queue
,
&
wrk
->
tas
k
,
list
);
Lck_Unlock
(
&
pp
->
mtx
);
wrk
->
task
.
func
=
task
->
func
;
wrk
->
task
.
priv
=
task
->
priv
;
...
...
@@ -296,7 +317,9 @@ Pool_Work_Thread(void *priv, struct worker *wrk)
/* Nothing to do: To sleep, perchance to dream ... */
if
(
isnan
(
wrk
->
lastused
))
wrk
->
lastused
=
VTIM_real
();
VTAILQ_INSERT_HEAD
(
&
pp
->
idle
,
wrk
,
list
);
wrk
->
task
.
func
=
NULL
;
wrk
->
task
.
priv
=
wrk
;
VTAILQ_INSERT_HEAD
(
&
pp
->
idle_queue
,
&
wrk
->
task
,
list
);
if
(
!
stats_clean
)
WRK_SumStat
(
wrk
);
(
void
)
Lck_CondWait
(
&
wrk
->
cond
,
&
pp
->
mtx
,
NULL
);
...
...
@@ -457,11 +480,11 @@ pool_herder(void *priv)
VSC_C_main
->
sess_queued
+=
pp
->
nqueued
;
VSC_C_main
->
sess_dropped
+=
pp
->
ndropped
;
pp
->
nqueued
=
pp
->
ndropped
=
0
;
wrk
=
VTAILQ_LAST
(
&
pp
->
idle
,
workerhead
);
wrk
=
pool_getidleworker
(
pp
,
1
);
if
(
wrk
!=
NULL
&&
(
wrk
->
lastused
<
t_idle
||
pp
->
nthr
>
cache_param
->
wthread_max
))
{
VTAILQ_REMOVE
(
&
pp
->
idle
,
wr
k
,
list
);
VTAILQ_REMOVE
(
&
pp
->
idle
_queue
,
&
wrk
->
tas
k
,
list
);
}
else
wrk
=
NULL
;
Lck_Unlock
(
&
pp
->
mtx
);
...
...
@@ -497,7 +520,7 @@ pool_mkpool(unsigned pool_no)
XXXAN
(
pp
);
Lck_New
(
&
pp
->
mtx
,
lck_wq
);
VTAILQ_INIT
(
&
pp
->
idle
);
VTAILQ_INIT
(
&
pp
->
idle
_queue
);
VTAILQ_INIT
(
&
pp
->
socks
);
VTAILQ_INIT
(
&
pp
->
front_queue
);
VTAILQ_INIT
(
&
pp
->
back_queue
);
...
...
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