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

Move the stats into an allocated chunk of shmem.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4803 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent ede6a6dd
...@@ -77,7 +77,7 @@ mgt_SHM_Alloc(unsigned size, const char *type, const char *ident) ...@@ -77,7 +77,7 @@ mgt_SHM_Alloc(unsigned size, const char *type, const char *ident)
CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC); CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC);
if (strcmp(sha->type, "Free")) { if (strcmp(sha->type, "Free")) {
sha = (void*)((uintptr_t)sha + sha->len); sha = SHA_NEXT(sha);
continue; continue;
} }
assert(size <= sha->len); assert(size <= sha->len);
...@@ -288,7 +288,6 @@ mgt_SHM_Init(const char *fn, const char *l_arg) ...@@ -288,7 +288,6 @@ mgt_SHM_Init(const char *fn, const char *l_arg)
loghead->master_pid = getpid(); loghead->master_pid = getpid();
xxxassert(loghead != MAP_FAILED); xxxassert(loghead != MAP_FAILED);
(void)mlock((void*)loghead, size); (void)mlock((void*)loghead, size);
VSL_stats = &loghead->stats;
/* Initialize pool */ /* Initialize pool */
loghead->alloc_seq = 0; loghead->alloc_seq = 0;
...@@ -300,7 +299,11 @@ mgt_SHM_Init(const char *fn, const char *l_arg) ...@@ -300,7 +299,11 @@ mgt_SHM_Init(const char *fn, const char *l_arg)
bprintf(loghead->head.type, "%s", "Free"); bprintf(loghead->head.type, "%s", "Free");
MEMORY_BARRIER(); MEMORY_BARRIER();
VSL_stats = mgt_SHM_Alloc(sizeof *VSL_stats, VSL_STAT_TYPE, "");
AN(VSL_stats);
pp = mgt_SHM_Alloc(sizeof *pp, "Params", ""); pp = mgt_SHM_Alloc(sizeof *pp, "Params", "");
AN(pp);
*pp = *params; *pp = *params;
params = pp; params = pp;
......
...@@ -55,6 +55,9 @@ struct shmalloc { ...@@ -55,6 +55,9 @@ struct shmalloc {
char ident[8]; char ident[8];
}; };
#define SHA_NEXT(sha) ((void*)((uintptr_t)(sha) + (sha)->len))
#define SHA_PTR(sha) ((void*)((uintptr_t)((sha) + 1)))
struct shmloghead { struct shmloghead {
#define SHMLOGHEAD_MAGIC 4185512500U /* From /dev/random */ #define SHMLOGHEAD_MAGIC 4185512500U /* From /dev/random */
unsigned magic; unsigned magic;
...@@ -77,8 +80,6 @@ struct shmloghead { ...@@ -77,8 +80,6 @@ struct shmloghead {
/* Current write position relative to the beginning of start */ /* Current write position relative to the beginning of start */
unsigned ptr; unsigned ptr;
struct varnish_stats stats;
/* Panic message buffer */ /* Panic message buffer */
char panicstr[64 * 1024]; char panicstr[64 * 1024];
......
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
#include <stdint.h> #include <stdint.h>
#define VSL_STAT_TYPE "Stats"
struct varnish_stats { struct varnish_stats {
#define MAC_STAT(n, t, l, f, e) t n; #define MAC_STAT(n, t, l, f, e) t n;
#include "stat_field.h" #include "stat_field.h"
......
...@@ -57,6 +57,7 @@ int VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv); ...@@ -57,6 +57,7 @@ int VSL_Dispatch(struct VSL_data *vd, vsl_handler *func, void *priv);
int VSL_NextLog(struct VSL_data *lh, unsigned char **pp); int VSL_NextLog(struct VSL_data *lh, unsigned char **pp);
int VSL_Arg(struct VSL_data *vd, int arg, const char *opt); int VSL_Arg(struct VSL_data *vd, int arg, const char *opt);
void VSL_Close(struct VSL_data *vd); void VSL_Close(struct VSL_data *vd);
int VSL_Open(struct VSL_data *vd);
void VSL_Delete(struct VSL_data *vd); void VSL_Delete(struct VSL_data *vd);
struct varnish_stats *VSL_OpenStats(struct VSL_data *vd); struct varnish_stats *VSL_OpenStats(struct VSL_data *vd);
const char *VSL_Name(struct VSL_data *vd); const char *VSL_Name(struct VSL_data *vd);
......
...@@ -123,8 +123,8 @@ const char *VSL_tags[256] = { ...@@ -123,8 +123,8 @@ const char *VSL_tags[256] = {
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static int int
vsl_shmem_map(struct VSL_data *vd) VSL_Open(struct VSL_data *vd)
{ {
int i; int i;
struct shmloghead slh; struct shmloghead slh;
...@@ -180,7 +180,6 @@ VSL_New(void) ...@@ -180,7 +180,6 @@ VSL_New(void)
vd->magic = VSL_MAGIC; vd->magic = VSL_MAGIC;
vd->vsl_fd = -1; vd->vsl_fd = -1;
/* XXX: Allocate only if log access */ /* XXX: Allocate only if log access */
vd->vbm_client = vbit_init(4096); vd->vbm_client = vbit_init(4096);
vd->vbm_backend = vbit_init(4096); vd->vbm_backend = vbit_init(4096);
...@@ -233,7 +232,7 @@ VSL_OpenLog(struct VSL_data *vd) ...@@ -233,7 +232,7 @@ VSL_OpenLog(struct VSL_data *vd)
if (vd->r_fd != -1) if (vd->r_fd != -1)
return (0); return (0);
if (vsl_shmem_map(vd)) if (VSL_Open(vd))
return (-1); return (-1);
vd->head = vd->vsl_lh; vd->head = vd->vsl_lh;
...@@ -611,13 +610,36 @@ VSL_Arg(struct VSL_data *vd, int arg, const char *opt) ...@@ -611,13 +610,36 @@ VSL_Arg(struct VSL_data *vd, int arg, const char *opt)
} }
} }
/*--------------------------------------------------------------------*/
static
struct shmalloc *
vsl_find_alloc(struct VSL_data *vd, const char *type, const char *ident)
{
struct shmalloc *sha;
assert (vd->vsl_lh != NULL);
for(sha = &vd->vsl_lh->head; ; sha = SHA_NEXT(sha)) {
CHECK_OBJ_NOTNULL(sha, SHMALLOC_MAGIC);
if (strcmp(sha->type, type))
continue;
if (ident != NULL && strcmp(sha->ident, ident))
continue;
return (sha);
}
return (NULL);
}
struct varnish_stats * struct varnish_stats *
VSL_OpenStats(struct VSL_data *vd) VSL_OpenStats(struct VSL_data *vd)
{ {
struct shmalloc *sha;
if (vsl_shmem_map(vd)) if (VSL_Open(vd))
return (NULL); return (NULL);
return (&vd->vsl_lh->stats); sha = vsl_find_alloc(vd, VSL_STAT_TYPE, "");
assert(sha != NULL);
return (SHA_PTR(sha));
} }
void void
......
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