diff --git a/server/core/atomic.c b/server/core/atomic.c index 9c15d2782..fee35048d 100644 --- a/server/core/atomic.c +++ b/server/core/atomic.c @@ -23,12 +23,12 @@ * @endverbatim */ +#include + /** - * Implementation of an atomic add operation for the GCC environment, or the - * X86 processor. If we are working within GNU C then we can use the GCC - * atomic add built in function, which is portable across platforms that - * implement GCC. Otherwise, this function currently supports only X86 - * architecture (without further development). + * Implementation of an atomic add operation for the GCC environment. + * If we are working within GNU C then we can use the GCC atomic add + * built in function, which is portable across platforms that implement GCC. * * Adds a value to the contents of a location pointed to by the first parameter. * The add operation is atomic and the return value is the value stored in the @@ -39,17 +39,12 @@ * @param value Value to be added * @return The value of variable before the add occurred */ -int -atomic_add(int *variable, int value) +int atomic_add(int *variable, int value) { -#ifdef __GNUC__ - return (int) __sync_fetch_and_add (variable, value); -#else - asm volatile( - "lock; xaddl %%eax, %2;" - :"=a" (value) - : "a" (value), "m" (*variable) - : "memory" ); - return value; -#endif + return __sync_fetch_and_add(variable, value); +} + +int64_t atomic_add_int64(int64_t *variable, int64_t value) +{ + return __sync_fetch_and_add(variable, value); } diff --git a/server/core/poll.c b/server/core/poll.c index a2078f387..783c836f6 100644 --- a/server/core/poll.c +++ b/server/core/poll.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -162,11 +163,11 @@ static struct ts_stats_t *n_pollev; /*< Number of polls returning events */ ts_stats_t *n_nbpollev; /*< Number of polls returning events */ ts_stats_t *n_nothreads; /*< Number of times no threads are polling */ - int n_fds[MAXNFDS]; /*< Number of wakeups with particular n_fds value */ - int evq_length; /*< Event queue length */ - int evq_pending; /*< Number of pending descriptors in event queue */ - int evq_max; /*< Maximum event queue length */ - int wake_evqpending; /*< Woken from epoll_wait with pending events in queue */ + int32_t n_fds[MAXNFDS]; /*< Number of wakeups with particular n_fds value */ + int64_t evq_length; /*< Event queue length */ + int64_t evq_pending; /*< Number of pending descriptors in event queue */ + int64_t evq_max; /*< Maximum event queue length */ + int64_t wake_evqpending; /*< Woken from epoll_wait with pending events in queue */ ts_stats_t *blockingpolls; /*< Number of epoll_waits with a timeout specified */ } pollStats; @@ -615,7 +616,7 @@ poll_waitevents(void *arg) (max_poll_sleep * timeout_bias) / 10); if (nfds == 0 && pollStats.evq_pending) { - atomic_add(&pollStats.wake_evqpending, 1); + atomic_add_int64(&pollStats.wake_evqpending, 1); poll_spins = 0; } } @@ -1254,42 +1255,42 @@ dprintPollStats(DCB *dcb) int i; dcb_printf(dcb, "\nPoll Statistics.\n\n"); - dcb_printf(dcb, "No. of epoll cycles: %d\n", + dcb_printf(dcb, "No. of epoll cycles: %" PRId64 "\n", ts_stats_sum(pollStats.n_polls)); - dcb_printf(dcb, "No. of epoll cycles with wait: %d\n", + dcb_printf(dcb, "No. of epoll cycles with wait: %" PRId64 "\n", ts_stats_sum(pollStats.blockingpolls)); - dcb_printf(dcb, "No. of epoll calls returning events: %d\n", + dcb_printf(dcb, "No. of epoll calls returning events: %" PRId64 "\n", ts_stats_sum(pollStats.n_pollev)); - dcb_printf(dcb, "No. of non-blocking calls returning events: %d\n", + dcb_printf(dcb, "No. of non-blocking calls returning events: %" PRId64 "\n", ts_stats_sum(pollStats.n_nbpollev)); - dcb_printf(dcb, "No. of read events: %d\n", + dcb_printf(dcb, "No. of read events: %" PRId64 "\n", ts_stats_sum(pollStats.n_read)); - dcb_printf(dcb, "No. of write events: %d\n", + dcb_printf(dcb, "No. of write events: %" PRId64 "\n", ts_stats_sum(pollStats.n_write)); - dcb_printf(dcb, "No. of error events: %d\n", + dcb_printf(dcb, "No. of error events: %" PRId64 "\n", ts_stats_sum(pollStats.n_error)); - dcb_printf(dcb, "No. of hangup events: %d\n", + dcb_printf(dcb, "No. of hangup events: %" PRId64 "\n", ts_stats_sum(pollStats.n_hup)); - dcb_printf(dcb, "No. of accept events: %d\n", + dcb_printf(dcb, "No. of accept events: %" PRId64 "\n", ts_stats_sum(pollStats.n_accept)); - dcb_printf(dcb, "No. of times no threads polling: %d\n", + dcb_printf(dcb, "No. of times no threads polling: %" PRId64 "\n", ts_stats_sum(pollStats.n_nothreads)); - dcb_printf(dcb, "Current event queue length: %d\n", + dcb_printf(dcb, "Current event queue length: %" PRId64 "\n", pollStats.evq_length); - dcb_printf(dcb, "Maximum event queue length: %d\n", + dcb_printf(dcb, "Maximum event queue length: %" PRId64 "\n", pollStats.evq_max); - dcb_printf(dcb, "No. of DCBs with pending events: %d\n", + dcb_printf(dcb, "No. of DCBs with pending events: %" PRId64 "\n", pollStats.evq_pending); - dcb_printf(dcb, "No. of wakeups with pending queue: %d\n", + dcb_printf(dcb, "No. of wakeups with pending queue: %" PRId64 "\n", pollStats.wake_evqpending); dcb_printf(dcb, "No of poll completions with descriptors\n"); dcb_printf(dcb, "\tNo. of descriptors\tNo. of poll completions.\n"); for (i = 0; i < MAXNFDS - 1; i++) { - dcb_printf(dcb, "\t%2d\t\t\t%d\n", i + 1, pollStats.n_fds[i]); + dcb_printf(dcb, "\t%2d\t\t\t%" PRId32 "\n", i + 1, pollStats.n_fds[i]); } - dcb_printf(dcb, "\t>= %d\t\t\t%d\n", MAXNFDS, + dcb_printf(dcb, "\t>= %d\t\t\t%" PRId32 "\n", MAXNFDS, pollStats.n_fds[MAXNFDS - 1]); #if SPINLOCK_PROFILE @@ -1802,8 +1803,8 @@ dShowEventStats(DCB *pdcb) dcb_printf(pdcb, "\nEvent statistics.\n"); dcb_printf(pdcb, "Maximum queue time: %3lu00ms\n", queueStats.maxqtime); dcb_printf(pdcb, "Maximum execution time: %3lu00ms\n", queueStats.maxexectime); - dcb_printf(pdcb, "Maximum event queue length: %3d\n", pollStats.evq_max); - dcb_printf(pdcb, "Current event queue length: %3d\n", pollStats.evq_length); + dcb_printf(pdcb, "Maximum event queue length: %3" PRId64 "\n", pollStats.evq_max); + dcb_printf(pdcb, "Current event queue length: %3" PRId64 "\n", pollStats.evq_length); dcb_printf(pdcb, "\n"); dcb_printf(pdcb, " | Number of events\n"); dcb_printf(pdcb, "Duration | Queued | Executed\n"); @@ -1825,8 +1826,7 @@ dShowEventStats(DCB *pdcb) * @param stat The required statistic * @return The value of that statistic */ -int -poll_get_stat(POLL_STAT stat) +int64_t poll_get_stat(POLL_STAT stat) { switch (stat) { @@ -1847,9 +1847,9 @@ poll_get_stat(POLL_STAT stat) case POLL_STAT_EVQ_MAX: return pollStats.evq_max; case POLL_STAT_MAX_QTIME: - return (int)queueStats.maxqtime; + return (int64_t)queueStats.maxqtime; case POLL_STAT_MAX_EXECTIME: - return (int)queueStats.maxexectime; + return (int64_t)queueStats.maxexectime; } return 0; } diff --git a/server/core/statistics.c b/server/core/statistics.c index 26fe69ef0..cb76cad09 100644 --- a/server/core/statistics.c +++ b/server/core/statistics.c @@ -47,7 +47,7 @@ void ts_stats_end() ts_stats_t ts_stats_alloc() { ss_dassert(initialized); - return calloc(thread_count, sizeof(int)); + return calloc(thread_count, sizeof(int64_t)); } /** @@ -79,10 +79,10 @@ void ts_stats_set_thread_id(int id) * @param stats Statistics to add to * @param value Value to add */ -void ts_stats_add(ts_stats_t stats, int value) +void ts_stats_add(ts_stats_t stats, int64_t value) { ss_dassert(initialized); - ((int*)stats)[current_thread_id] += value; + ((int64_t*)stats)[current_thread_id] += value; } /** @@ -92,10 +92,10 @@ void ts_stats_add(ts_stats_t stats, int value) * @param stats Statistics to set * @param value Value to set to */ -void ts_stats_set(ts_stats_t stats, int value) +void ts_stats_set(ts_stats_t stats, int64_t value) { ss_dassert(initialized); - ((int*)stats)[current_thread_id] = value; + ((int64_t*)stats)[current_thread_id] = value; } /** @@ -104,13 +104,13 @@ void ts_stats_set(ts_stats_t stats, int value) * @param stats Statistics to read * @return Value of statistics */ -int ts_stats_sum(ts_stats_t stats) +int64_t ts_stats_sum(ts_stats_t stats) { ss_dassert(initialized); - int sum = 0; + int64_t sum = 0; for (int i = 0; i < thread_count; i++) { - sum += ((int*)stats)[i]; + sum += ((int64_t*)stats)[i]; } return sum; } diff --git a/server/include/atomic.h b/server/include/atomic.h index acc177aa9..5990f701b 100644 --- a/server/include/atomic.h +++ b/server/include/atomic.h @@ -26,9 +26,13 @@ * @endverbatim */ +#include + #ifdef __cplusplus extern "C" int atomic_add(int *variable, int value); +extern "C" int64_t atomic_add_int64(int64_t *variable, int64_t value); #else extern int atomic_add(int *variable, int value); +extern int64_t atomic_add_int64(int64_t *variable, int64_t value); #endif #endif diff --git a/server/include/maxscale/poll.h b/server/include/maxscale/poll.h index 044077f14..e2ed799bc 100644 --- a/server/include/maxscale/poll.h +++ b/server/include/maxscale/poll.h @@ -61,7 +61,7 @@ extern void dShowThreads(DCB *dcb); extern void poll_add_epollin_event_to_dcb(DCB* dcb, GWBUF* buf); extern void dShowEventQ(DCB *dcb); extern void dShowEventStats(DCB *dcb); -extern int poll_get_stat(POLL_STAT stat); +extern int64_t poll_get_stat(POLL_STAT stat); extern RESULTSET *eventTimesGetList(); extern void poll_fake_event(DCB *dcb, enum EPOLL_EVENTS ev); extern void poll_fake_hangup_event(DCB *dcb); diff --git a/server/include/statistics.h b/server/include/statistics.h index 00750cd23..1962598b6 100644 --- a/server/include/statistics.h +++ b/server/include/statistics.h @@ -23,6 +23,7 @@ * 21/01/16 Markus Makela Initial implementation * @endverbatim */ +#include typedef void* ts_stats_t; @@ -37,8 +38,8 @@ void ts_stats_set_thread_id(int id); ts_stats_t ts_stats_alloc(); void ts_stats_free(ts_stats_t stats); -void ts_stats_add(ts_stats_t stats, int value); -void ts_stats_set(ts_stats_t stats, int value); -int ts_stats_sum(ts_stats_t stats); +void ts_stats_add(ts_stats_t stats, int64_t value); +void ts_stats_set(ts_stats_t stats, int64_t value); +int64_t ts_stats_sum(ts_stats_t stats); #endif diff --git a/server/modules/routing/maxinfo/maxinfo_exec.c b/server/modules/routing/maxinfo/maxinfo_exec.c index 235a8d400..9d4be0e66 100644 --- a/server/modules/routing/maxinfo/maxinfo_exec.c +++ b/server/modules/routing/maxinfo/maxinfo_exec.c @@ -44,6 +44,7 @@ #include #include #include +#include static void exec_show(DCB *dcb, MAXINFO_TREE *tree); static void exec_select(DCB *dcb, MAXINFO_TREE *tree); @@ -995,7 +996,7 @@ maxinfo_zombie_dcbs() /** * Interface to poll stats for reads */ -static int +static int64_t maxinfo_read_events() { return poll_get_stat(POLL_STAT_READ); @@ -1004,7 +1005,7 @@ maxinfo_read_events() /** * Interface to poll stats for writes */ -static int +static int64_t maxinfo_write_events() { return poll_get_stat(POLL_STAT_WRITE); @@ -1013,7 +1014,7 @@ maxinfo_write_events() /** * Interface to poll stats for errors */ -static int +static int64_t maxinfo_error_events() { return poll_get_stat(POLL_STAT_ERROR); @@ -1022,7 +1023,7 @@ maxinfo_error_events() /** * Interface to poll stats for hangup */ -static int +static int64_t maxinfo_hangup_events() { return poll_get_stat(POLL_STAT_HANGUP); @@ -1031,7 +1032,7 @@ maxinfo_hangup_events() /** * Interface to poll stats for accepts */ -static int +static int64_t maxinfo_accept_events() { return poll_get_stat(POLL_STAT_ACCEPT); @@ -1040,7 +1041,7 @@ maxinfo_accept_events() /** * Interface to poll stats for event queue length */ -static int +static int64_t maxinfo_event_queue_length() { return poll_get_stat(POLL_STAT_EVQ_LEN); @@ -1049,7 +1050,7 @@ maxinfo_event_queue_length() /** * Interface to poll stats for event pending queue length */ -static int +static int64_t maxinfo_event_pending_queue_length() { return poll_get_stat(POLL_STAT_EVQ_PENDING); @@ -1058,7 +1059,7 @@ maxinfo_event_pending_queue_length() /** * Interface to poll stats for max event queue length */ -static int +static int64_t maxinfo_max_event_queue_length() { return poll_get_stat(POLL_STAT_EVQ_MAX); @@ -1067,7 +1068,7 @@ maxinfo_max_event_queue_length() /** * Interface to poll stats for max queue time */ -static int +static int64_t maxinfo_max_event_queue_time() { return poll_get_stat(POLL_STAT_MAX_QTIME); @@ -1076,7 +1077,7 @@ maxinfo_max_event_queue_time() /** * Interface to poll stats for max event execution time */ -static int +static int64_t maxinfo_max_event_exec_time() { return poll_get_stat(POLL_STAT_MAX_EXECTIME); @@ -1149,8 +1150,8 @@ status_row(RESULTSET *result, void *data) (char *)(*status[context->index].func)()); break; case VT_INT: - snprintf(buf, 80, "%ld", - (long)(*status[context->index].func)()); + snprintf(buf, 80, "%" PRId64, + (int64_t)(*status[context->index].func)()); resultset_row_set(row, 1, buf); break; default: