Commit ad277d29 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add a facility to give each session a unique number with a minimum of

locking:  Each pool fetches blocks of numbers to assign, then hands them
out one by one using the existing lock.

Session numbers are 32bit and start at zero on worker process startup.

Together with another 32bit number, local to the session, they will
be used to link VSL records into transactions.
parent c9c05728
......@@ -252,6 +252,13 @@ struct vsl_log {
/*--------------------------------------------------------------------*/
struct vxid {
uint32_t next;
uint32_t count;
};
/*--------------------------------------------------------------------*/
struct wrk_accept {
unsigned magic;
#define WRK_ACCEPT_MAGIC 0x8c4b4d59
......@@ -261,6 +268,7 @@ struct wrk_accept {
socklen_t acceptaddrlen;
int acceptsock;
struct listen_sock *acceptlsock;
uint32_t vxid;
};
/* Worker pool stuff -------------------------------------------------*/
......@@ -626,6 +634,8 @@ struct sess {
enum step step;
int fd;
unsigned vsl_id;
uint32_t vxid;
uint32_t vseq;
/* Cross references ------------------------------------------*/
......@@ -834,6 +844,7 @@ int HTC_Complete(struct http_conn *htc);
#undef HTTPH
/* cache_main.c */
uint32_t VXID_Get(struct vxid *v);
extern volatile struct params * cache_param;
void THR_SetName(const char *name);
const char* THR_GetName(void);
......
......@@ -249,6 +249,8 @@ VCA_SetupSess(struct worker *wrk)
CAST_OBJ_NOTNULL(wa, (void*)wrk->aws->f, WRK_ACCEPT_MAGIC);
sp = wrk->sp;
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
sp->vxid = wa->vxid;
sp->vseq = 0;
sp->fd = wa->acceptsock;
sp->vsl_id = wa->acceptsock | VSL_CLIENTMARKER ;
wa->acceptsock = -1;
......
......@@ -84,6 +84,33 @@ THR_GetName(void)
return (pthread_getspecific(name_key));
}
/*--------------------------------------------------------------------
*/
static uint32_t vxid_base;
static struct lock vxid_lock;
static void
vxid_More(struct vxid *v)
{
Lck_Lock(&vxid_lock);
v->next = vxid_base;
v->count = 32768;
vxid_base = v->count;
Lck_Unlock(&vxid_lock);
}
uint32_t
VXID_Get(struct vxid *v)
{
if (v->count == 0)
vxid_More(v);
AN(v->count);
v->count--;
return (v->next++);
}
/*--------------------------------------------------------------------
* XXX: Think more about which order we start things
*/
......@@ -107,6 +134,8 @@ child_main(void)
LCK_Init(); /* Second, locking */
Lck_New(&vxid_lock, lck_vxid);
WAIT_Init();
PAN_Init();
CLI_Init();
......
......@@ -100,6 +100,8 @@ struct pool {
struct lock herder_mtx;
pthread_t herder_thr;
struct vxid vxid;
struct lock mtx;
struct taskhead idle_queue;
struct taskhead front_queue;
......@@ -182,6 +184,7 @@ pool_accept(struct worker *wrk, void *arg)
}
Lck_Lock(&pp->mtx);
wa->vxid = VXID_Get(&pp->vxid);
wrk2 = pool_getidleworker(pp, 0);
if (wrk2 == NULL) {
/* No idle threads, do it ourselves */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment