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

Shave 8 bytes of struct ws on 64 bit archs.

With 8 byte pointers, having a char[X] for X <= 8 is cheaper than
than a char *.

Don't waste 32bits on the overflow flag.
parent 30c60379
......@@ -170,8 +170,7 @@ struct lock { void *priv; }; // Opaque
struct ws {
unsigned magic;
#define WS_MAGIC 0x35fac554
unsigned overflow; /* workspace overflowed */
const char *id; /* identity */
char id[4]; /* identity */
char *s; /* (S)tart of buffer */
char *f; /* (F)ree/front pointer */
char *r; /* (R)eserved length */
......@@ -1207,6 +1206,7 @@ void WS_Reset(struct ws *ws, char *p);
char *WS_Alloc(struct ws *ws, unsigned bytes);
void *WS_Copy(struct ws *ws, const void *str, int len);
char *WS_Snapshot(struct ws *ws);
int WS_Overflowed(const struct ws *ws);
/* rfc2616.c */
void RFC2616_Ttl(struct busyobj *);
......
......@@ -433,7 +433,7 @@ vbf_stp_fetch(struct worker *wrk, struct busyobj *bo)
assert(bo->refcount >= 1);
AZ(bo->ws_o->overflow);
AZ(WS_Overflowed(bo->ws_o));
if (bo->do_stream)
HSH_Unbusy(&wrk->stats, obj->objcore);
......@@ -587,7 +587,7 @@ vbf_stp_condfetch(struct worker *wrk, struct busyobj *bo)
http_CopyHome(obj->http);
AZ(bo->ws_o->overflow);
AZ(WS_Overflowed(bo->ws_o));
VBO_setstate(bo, BOS_FETCHING);
HSH_Unbusy(&wrk->stats, obj->objcore);
......
......@@ -108,9 +108,10 @@ static void
pan_ws(const struct ws *ws, int indent)
{
VSB_printf(pan_vsp, "%*sws = %p { %s\n", indent, "",
ws, ws->overflow ? "overflow" : "");
VSB_printf(pan_vsp, "%*sid = \"%s\",\n", indent + 2, "", ws->id);
VSB_printf(pan_vsp, "%*sws = %p {", indent, "", ws);
if (WS_Overflowed(ws))
VSB_printf(pan_vsp, " OVERFLOW");
VSB_printf(pan_vsp, "\n%*sid = \"%s\",\n", indent + 2, "", ws->id);
VSB_printf(pan_vsp, "%*s{s,f,r,e} = {%p", indent + 2, "", ws->s);
if (ws->f > ws->s)
VSB_printf(pan_vsp, ",+%ld", (long) (ws->f - ws->s));
......
......@@ -111,7 +111,7 @@ ses_new(struct sesspool *pp)
p = (char*)(sp + 1);
p = (void*)PRNDUP(p);
assert(p < e);
WS_Init(sp->ws, "sess", p, e - p);
WS_Init(sp->ws, "ses", p, e - p);
sp->local_addr = (void*)WS_Alloc(sp->ws, vsa_suckaddr_len);
sp->remote_addr = (void*)WS_Alloc(sp->ws, vsa_suckaddr_len);
......
......@@ -56,6 +56,11 @@ WS_Assert(const struct ws *ws)
}
}
/*
* NB: The id must be max 3 char and lower-case.
* (upper-case the first char to indicate overflow)
*/
void
WS_Init(struct ws *ws, const char *id, void *space, unsigned len)
{
......@@ -70,10 +75,21 @@ WS_Init(struct ws *ws, const char *id, void *space, unsigned len)
ws->e = ws->s + len;
assert(PAOK(len));
ws->f = ws->s;
ws->id = id;
assert(id[0] & 0x40);
assert(strlen(id) < sizeof ws->id);
strcpy(ws->id, id);
WS_Assert(ws);
}
static void
WS_MarkOverflow(struct ws *ws)
{
WS_Assert(ws);
ws->id[0] &= ~0x40; // Cheasy toupper()
}
/*
* Reset a WS to start or a given pointer, likely from WS_Snapshot
*/
......@@ -105,7 +121,7 @@ WS_Alloc(struct ws *ws, unsigned bytes)
assert(ws->r == NULL);
if (ws->f + bytes > ws->e) {
ws->overflow++;
WS_MarkOverflow(ws);
WS_Assert(ws);
return(NULL);
}
......@@ -131,7 +147,7 @@ WS_Copy(struct ws *ws, const void *str, int len)
bytes = PRNDUP((unsigned)len);
if (ws->f + bytes > ws->e) {
ws->overflow++;
WS_MarkOverflow(ws);
WS_Assert(ws);
return(NULL);
}
......@@ -201,3 +217,12 @@ WS_ReleaseP(struct ws *ws, char *ptr)
ws->r = NULL;
WS_Assert(ws);
}
int
WS_Overflowed(const struct ws *ws)
{
WS_Assert(ws);
if (ws->id[0] & 0x40)
return (0);
return (1);
}
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