summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordormando <dormando@rydia.net>2016-06-10 16:12:29 -0700
committerdormando <dormando@rydia.net>2016-06-10 16:12:29 -0700
commit4b7228ed75aafc7428806f92bc3399f16b928a90 (patch)
treea683d57ae97c9bda13483c239dd4cf327fa95ab2
parentbb55beb20c3c692a0e77e2ef368d5831318b33d0 (diff)
downloadmemcached-4b7228ed75aafc7428806f92bc3399f16b928a90.tar.gz
switch from bit fields to bit manipulation
can't compare bit fields en-masse, which makes things too difficult.
-rw-r--r--items.c2
-rw-r--r--logger.c29
-rw-r--r--logger.h25
-rw-r--r--memcached.c13
4 files changed, 26 insertions, 43 deletions
diff --git a/items.c b/items.c
index ef73815..c02dcb4 100644
--- a/items.c
+++ b/items.c
@@ -854,7 +854,7 @@ static int lru_pull_tail(const int orig_id, const int cur_lru,
if ((search->it_flags & ITEM_FETCHED) == 0) {
itemstats[id].evicted_unfetched++;
}
- if (l->f.log_evictions)
+ if (l->eflags & LOG_EVICTIONS)
logger_log(l, LOGGER_EVICTION, search);
do_item_unlink_nolock(search, hv);
removed++;
diff --git a/logger.c b/logger.c
index 48ee48d..49f2383 100644
--- a/logger.c
+++ b/logger.c
@@ -209,31 +209,18 @@ static void logger_chunk_release(logger_chunk *lc) {
static void logger_set_flags(void) {
logger *l = NULL;
int x = 0;
- struct logger_eflags f;
- memset(&f, 0, sizeof(struct logger_eflags));
-
- /* Would love to | the fields together, but bitfields have intederminate
- * sizing. Could use a union and some startup asserts to sniff out
- * platforms where 8 bitfields take more than a uint64_t.. Some research
- * is required though. For now an if/else tree will have to do.
- */
+ uint16_t f = 0; /* logger eflags */
+
for (x = 0; x < WATCHER_LIMIT; x++) {
logger_watcher *w = watchers[x];
if (w == NULL)
continue;
- if (w->f.log_evictions)
- f.log_evictions = 1;
-
- if (w->f.log_fetchers)
- f.log_fetchers = 1;
-
- if (w->f.log_time)
- f.log_time = 1;
+ f |= w->eflags;
}
for (l = logger_stack_head; l != NULL; l=l->next) {
- /* lock logger, call function to manipulate it */
- memcpy(&l->f, &f, sizeof(struct logger_eflags));
+ /* TODO: lock logger, call function to manipulate it */
+ l->eflags = f;
}
return;
}
@@ -550,7 +537,7 @@ logger *logger_create(void) {
#define SET_LOGGER_TIME() \
do { \
- if (l->f.log_time) { \
+ if (l->eflags & LOG_TIME) { \
gettimeofday(&e->tv, NULL); \
} else { \
e->tv.tv_sec = 0; \
@@ -632,7 +619,7 @@ enum logger_ret_type logger_log(logger *l, const enum log_entry_type event, cons
* logger thread. Caller *must* event_del() the client before handing it over.
* Presently there's no way to hand the client back to the worker thread.
*/
-enum logger_add_watcher_ret logger_add_watcher(void *c, const int sfd, const struct logger_eflags f) {
+enum logger_add_watcher_ret logger_add_watcher(void *c, const int sfd, uint16_t f) {
int x;
logger_watcher *w = NULL;
pthread_mutex_lock(&logger_stack_lock);
@@ -656,7 +643,7 @@ enum logger_add_watcher_ret logger_add_watcher(void *c, const int sfd, const str
w->t = LOGGER_WATCHER_CLIENT;
}
w->id = x;
- memcpy(&w->f, &f, sizeof(struct logger_eflags));
+ w->eflags = f;
/* Attach to an existing log chunk if there is one */
if (logger_thread_last_lc && !logger_thread_last_lc->filled) {
logger_chunk *lc = logger_thread_last_lc;
diff --git a/logger.h b/logger.h
index c4279ac..31a246d 100644
--- a/logger.h
+++ b/logger.h
@@ -48,17 +48,14 @@ typedef struct _logentry {
} data[];
} logentry;
-struct logger_eflags {
- unsigned int log_sysevents :1; /* threads start/stop/working */
- unsigned int log_fetchers :1; /* get/gets/etc */
- unsigned int log_mutations :1; /* set/append/incr/etc */
- unsigned int log_syserrors :1; /* malloc/etc errors */
- unsigned int log_connevents :1; /* new client, closed, etc */
- unsigned int log_vconnevents :1; /* client state changes */
- unsigned int log_evictions :1; /* log details of evicted items */
- unsigned int log_strict :1; /* block instead of drop */
- unsigned int log_time :1; /* log the time the entry is created */
-};
+#define LOG_SYSEVENTS (1<<1) /* threads start/stop/working */
+#define LOG_FETCHERS (1<<2) /* get/gets/etc */
+#define LOG_MUTATIONS (1<<3) /* set/append/incr/etc */
+#define LOG_SYSERRORS (1<<4) /* malloc/etc errors */
+#define LOG_CONNEVENTS (1<<5) /* new client, closed, etc */
+#define LOG_EVICTIONS (1<<6) /* defailts of evicted items */
+#define LOG_STRICT (1<<7) /* block worker instead of drop */
+#define LOG_TIME (1<<8) /* log the entry time */
typedef struct _logger {
struct _logger *prev;
@@ -69,7 +66,7 @@ typedef struct _logger {
uint64_t blocked; /* times blocked instead of dropped */
uint16_t fetcher_ratio; /* log one out of every N fetches */
uint16_t mutation_ratio; /* log one out of every N mutations */
- struct logger_eflags f; /* flags this logger should log */
+ uint16_t eflags; /* flags this logger should log */
bipbuf_t *buf;
const entry_details *entry_map;
} logger;
@@ -96,7 +93,7 @@ typedef struct {
int flushed; /* backlog data flushed so far from active chunk */
int id; /* id number for watcher list */
enum logger_watcher_type t; /* stderr, client, syslog, etc */
- struct logger_eflags f; /* flags we are interested in */
+ uint16_t eflags; /* flags we are interested in */
} logger_watcher;
extern pthread_key_t logger_key;
@@ -114,6 +111,6 @@ enum logger_add_watcher_ret {
LOGGER_ADD_WATCHER_FAILED
};
-enum logger_add_watcher_ret logger_add_watcher(void *c, const int sfd, const struct logger_eflags);
+enum logger_add_watcher_ret logger_add_watcher(void *c, const int sfd, uint16_t f);
#endif
diff --git a/memcached.c b/memcached.c
index d4906ca..a07d356 100644
--- a/memcached.c
+++ b/memcached.c
@@ -3445,7 +3445,7 @@ static void process_command(conn *c, char *command) {
MEMCACHED_PROCESS_COMMAND_START(c->sfd, c->rcurr, c->rbytes);
- if (c->thread->l->f.log_fetchers)
+ if (c->thread->l->eflags & LOG_FETCHERS)
logger_log(c->thread->l, LOGGER_ASCII_CMD, NULL, c->sfd, command);
/*
@@ -3677,22 +3677,21 @@ static void process_command(conn *c, char *command) {
out_string(c, "ERROR");
}
} else if (ntokens > 1 && strcmp(tokens[COMMAND_TOKEN].value, "watch") == 0) {
- struct logger_eflags f;
- memset(&f, 0, sizeof(struct logger_eflags));
+ uint16_t f = 0;
/* TODO: pass to function for full argument processing. */
/* This is very temporary... need to decide on a real flag parser. */
if (ntokens == 3) {
if ((strcmp(tokens[COMMAND_TOKEN + 1].value, "fetchers") == 0)) {
- f.log_fetchers = 1;
+ f |= LOG_FETCHERS;
} else if ((strcmp(tokens[COMMAND_TOKEN + 1].value, "evictions") == 0)) {
- f.log_evictions = 1;
+ f |= LOG_EVICTIONS;
} else {
out_string(c, "ERROR");
}
} else {
- f.log_fetchers = 1;
+ f |= LOG_FETCHERS;
}
- f.log_time = 1; /* not optional yet */
+ f |= LOG_TIME; /* not optional yet */
switch(logger_add_watcher(c, c->sfd, f)) {
case LOGGER_ADD_WATCHER_TOO_MANY:
out_string(c, "WATCHER_TOO_MANY log watcher limit reached");