diff --git a/configure.ac b/configure.ac index 9f05cfa..7d1ab31 100644 --- a/configure.ac +++ b/configure.ac @@ -490,6 +490,8 @@ AC_CHECK_FUNCS(clock_gettime) AC_CHECK_FUNCS([accept4], [AC_DEFINE(HAVE_ACCEPT4, 1, [Define to 1 if support accept4])]) AC_CHECK_FUNCS([getopt_long], [AC_DEFINE(HAVE_GETOPT_LONG, 1, [Define to 1 if support getopt_long])]) +dnl Need to disable opt for alignment check. GCC is too clever and turns this +dnl into wide stores and no cmp under O2. AC_DEFUN([AC_C_ALIGNMENT], [AC_CACHE_CHECK(for alignment, ac_cv_c_alignment, [ @@ -497,6 +499,7 @@ AC_DEFUN([AC_C_ALIGNMENT], [AC_LANG_PROGRAM([ #include #include +#pragma GCC optimize ("O0") ], [ char *buf = malloc(32); @@ -551,7 +554,8 @@ dnl Check for usage of 64bit atomics dnl 32bit systems shouldn't have these. have_gcc_64atomics=no AC_MSG_CHECKING(for GCC 64bit atomics) -AC_TRY_LINK([],[ +AC_TRY_LINK([#include + ],[ uint64_t a; uint64_t b; b = __sync_add_and_fetch(&a, 1); diff --git a/logger.c b/logger.c index 7af9917..ba0c62e 100644 --- a/logger.c +++ b/logger.c @@ -363,7 +363,7 @@ static int logger_thread_read(logger *l, struct logger_stats *ls) { } else { logger_thread_write_entry(e, ls, scratch, scratch_len); } - pos += sizeof(logentry) + e->size; + pos += sizeof(logentry) + e->size + e->pad; } assert(pos <= size); @@ -699,8 +699,9 @@ enum logger_ret_type logger_log(logger *l, const enum log_entry_type event, cons l->dropped++; return LOGGER_RET_NOSPACE; } - e->gid = logger_get_gid(); e->event = d->subtype; + e->pad = 0; + e->gid = logger_get_gid(); /* TODO: Could pass this down as an argument now that we're using * LOGGER_LOG() macro. */ @@ -754,8 +755,15 @@ enum logger_ret_type logger_log(logger *l, const enum log_entry_type event, cons break; } +#ifdef NEED_ALIGN + /* Need to ensure *next* request is aligned. */ + if (sizeof(logentry) + e->size % 8 != 0) { + e->pad = 8 - (sizeof(logentry) + e->size % 8); + } +#endif + /* Push pointer forward by the actual amount required */ - if (bipbuf_push(buf, (sizeof(logentry) + e->size)) == 0) { + if (bipbuf_push(buf, (sizeof(logentry) + e->size + e->pad)) == 0) { fprintf(stderr, "LOGGER: Failed to bipbuf push a text entry\n"); pthread_mutex_unlock(&l->mutex); return LOGGER_RET_ERR; diff --git a/logger.h b/logger.h index 3d4c44c..730c86f 100644 --- a/logger.h +++ b/logger.h @@ -100,6 +100,7 @@ struct logentry_item_store { typedef struct _logentry { enum log_entry_subtype event; + uint8_t pad; uint16_t eflags; uint64_t gid; struct timeval tv; /* not monotonic! */