MXS-1218 Poll statistics changed to 64bit to avoid looparound

Statistics calculation, printing and MaxInfo are modified.
n_fds remains 32bit.
This commit is contained in:
Esa Korhonen
2017-04-06 13:51:15 +03:00
parent 496189dd59
commit a418387d0a
7 changed files with 70 additions and 69 deletions

View File

@ -23,12 +23,12 @@
* @endverbatim * @endverbatim
*/ */
#include <atomic.h>
/** /**
* Implementation of an atomic add operation for the GCC environment, or the * Implementation of an atomic add operation for the GCC environment.
* X86 processor. If we are working within GNU C then we can use the GCC * If we are working within GNU C then we can use the GCC atomic add
* atomic add built in function, which is portable across platforms that * built in function, which is portable across platforms that implement GCC.
* implement GCC. Otherwise, this function currently supports only X86
* architecture (without further development).
* *
* Adds a value to the contents of a location pointed to by the first parameter. * 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 * 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 * @param value Value to be added
* @return The value of variable before the add occurred * @return The value of variable before the add occurred
*/ */
int int atomic_add(int *variable, int value)
atomic_add(int *variable, int value)
{ {
#ifdef __GNUC__ return __sync_fetch_and_add(variable, value);
return (int) __sync_fetch_and_add (variable, value); }
#else
asm volatile( int64_t atomic_add_int64(int64_t *variable, int64_t value)
"lock; xaddl %%eax, %2;" {
:"=a" (value) return __sync_fetch_and_add(variable, value);
: "a" (value), "m" (*variable)
: "memory" );
return value;
#endif
} }

View File

@ -16,6 +16,7 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
#include <signal.h> #include <signal.h>
#include <inttypes.h>
#include <sys/epoll.h> #include <sys/epoll.h>
#include <errno.h> #include <errno.h>
#include <maxscale/poll.h> #include <maxscale/poll.h>
@ -162,11 +163,11 @@ static struct
ts_stats_t *n_pollev; /*< Number of polls returning events */ ts_stats_t *n_pollev; /*< Number of polls returning events */
ts_stats_t *n_nbpollev; /*< 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 */ ts_stats_t *n_nothreads; /*< Number of times no threads are polling */
int n_fds[MAXNFDS]; /*< Number of wakeups with particular n_fds value */ int32_t n_fds[MAXNFDS]; /*< Number of wakeups with particular n_fds value */
int evq_length; /*< Event queue length */ int64_t evq_length; /*< Event queue length */
int evq_pending; /*< Number of pending descriptors in event queue */ int64_t evq_pending; /*< Number of pending descriptors in event queue */
int evq_max; /*< Maximum event queue length */ int64_t evq_max; /*< Maximum event queue length */
int wake_evqpending; /*< Woken from epoll_wait with pending events in queue */ 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 */ ts_stats_t *blockingpolls; /*< Number of epoll_waits with a timeout specified */
} pollStats; } pollStats;
@ -615,7 +616,7 @@ poll_waitevents(void *arg)
(max_poll_sleep * timeout_bias) / 10); (max_poll_sleep * timeout_bias) / 10);
if (nfds == 0 && pollStats.evq_pending) if (nfds == 0 && pollStats.evq_pending)
{ {
atomic_add(&pollStats.wake_evqpending, 1); atomic_add_int64(&pollStats.wake_evqpending, 1);
poll_spins = 0; poll_spins = 0;
} }
} }
@ -1254,42 +1255,42 @@ dprintPollStats(DCB *dcb)
int i; int i;
dcb_printf(dcb, "\nPoll Statistics.\n\n"); 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)); 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)); 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)); 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)); 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)); 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)); 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)); 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)); 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)); 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)); 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); pollStats.evq_length);
dcb_printf(dcb, "Maximum event queue length: %d\n", dcb_printf(dcb, "Maximum event queue length: %" PRId64 "\n",
pollStats.evq_max); 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); 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); pollStats.wake_evqpending);
dcb_printf(dcb, "No of poll completions with descriptors\n"); dcb_printf(dcb, "No of poll completions with descriptors\n");
dcb_printf(dcb, "\tNo. of descriptors\tNo. of poll completions.\n"); dcb_printf(dcb, "\tNo. of descriptors\tNo. of poll completions.\n");
for (i = 0; i < MAXNFDS - 1; i++) 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]); pollStats.n_fds[MAXNFDS - 1]);
#if SPINLOCK_PROFILE #if SPINLOCK_PROFILE
@ -1802,8 +1803,8 @@ dShowEventStats(DCB *pdcb)
dcb_printf(pdcb, "\nEvent statistics.\n"); dcb_printf(pdcb, "\nEvent statistics.\n");
dcb_printf(pdcb, "Maximum queue time: %3lu00ms\n", queueStats.maxqtime); dcb_printf(pdcb, "Maximum queue time: %3lu00ms\n", queueStats.maxqtime);
dcb_printf(pdcb, "Maximum execution time: %3lu00ms\n", queueStats.maxexectime); 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, "Maximum event queue length: %3" PRId64 "\n", pollStats.evq_max);
dcb_printf(pdcb, "Current event queue length: %3d\n", pollStats.evq_length); dcb_printf(pdcb, "Current event queue length: %3" PRId64 "\n", pollStats.evq_length);
dcb_printf(pdcb, "\n"); dcb_printf(pdcb, "\n");
dcb_printf(pdcb, " | Number of events\n"); dcb_printf(pdcb, " | Number of events\n");
dcb_printf(pdcb, "Duration | Queued | Executed\n"); dcb_printf(pdcb, "Duration | Queued | Executed\n");
@ -1825,8 +1826,7 @@ dShowEventStats(DCB *pdcb)
* @param stat The required statistic * @param stat The required statistic
* @return The value of that statistic * @return The value of that statistic
*/ */
int int64_t poll_get_stat(POLL_STAT stat)
poll_get_stat(POLL_STAT stat)
{ {
switch (stat) switch (stat)
{ {
@ -1847,9 +1847,9 @@ poll_get_stat(POLL_STAT stat)
case POLL_STAT_EVQ_MAX: case POLL_STAT_EVQ_MAX:
return pollStats.evq_max; return pollStats.evq_max;
case POLL_STAT_MAX_QTIME: case POLL_STAT_MAX_QTIME:
return (int)queueStats.maxqtime; return (int64_t)queueStats.maxqtime;
case POLL_STAT_MAX_EXECTIME: case POLL_STAT_MAX_EXECTIME:
return (int)queueStats.maxexectime; return (int64_t)queueStats.maxexectime;
} }
return 0; return 0;
} }

View File

@ -47,7 +47,7 @@ void ts_stats_end()
ts_stats_t ts_stats_alloc() ts_stats_t ts_stats_alloc()
{ {
ss_dassert(initialized); 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 stats Statistics to add to
* @param value Value to add * @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); 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 stats Statistics to set
* @param value Value to set to * @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); 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 * @param stats Statistics to read
* @return Value of statistics * @return Value of statistics
*/ */
int ts_stats_sum(ts_stats_t stats) int64_t ts_stats_sum(ts_stats_t stats)
{ {
ss_dassert(initialized); ss_dassert(initialized);
int sum = 0; int64_t sum = 0;
for (int i = 0; i < thread_count; i++) for (int i = 0; i < thread_count; i++)
{ {
sum += ((int*)stats)[i]; sum += ((int64_t*)stats)[i];
} }
return sum; return sum;
} }

View File

@ -26,9 +26,13 @@
* @endverbatim * @endverbatim
*/ */
#include <stdint.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" int atomic_add(int *variable, int value); extern "C" int atomic_add(int *variable, int value);
extern "C" int64_t atomic_add_int64(int64_t *variable, int64_t value);
#else #else
extern int atomic_add(int *variable, int value); extern int atomic_add(int *variable, int value);
extern int64_t atomic_add_int64(int64_t *variable, int64_t value);
#endif #endif
#endif #endif

View File

@ -61,7 +61,7 @@ extern void dShowThreads(DCB *dcb);
extern void poll_add_epollin_event_to_dcb(DCB* dcb, GWBUF* buf); extern void poll_add_epollin_event_to_dcb(DCB* dcb, GWBUF* buf);
extern void dShowEventQ(DCB *dcb); extern void dShowEventQ(DCB *dcb);
extern void dShowEventStats(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 RESULTSET *eventTimesGetList();
extern void poll_fake_event(DCB *dcb, enum EPOLL_EVENTS ev); extern void poll_fake_event(DCB *dcb, enum EPOLL_EVENTS ev);
extern void poll_fake_hangup_event(DCB *dcb); extern void poll_fake_hangup_event(DCB *dcb);

View File

@ -23,6 +23,7 @@
* 21/01/16 Markus Makela Initial implementation * 21/01/16 Markus Makela Initial implementation
* @endverbatim * @endverbatim
*/ */
#include <stdint.h>
typedef void* ts_stats_t; typedef void* ts_stats_t;
@ -37,8 +38,8 @@ void ts_stats_set_thread_id(int id);
ts_stats_t ts_stats_alloc(); ts_stats_t ts_stats_alloc();
void ts_stats_free(ts_stats_t stats); void ts_stats_free(ts_stats_t stats);
void ts_stats_add(ts_stats_t stats, int value); void ts_stats_add(ts_stats_t stats, int64_t value);
void ts_stats_set(ts_stats_t stats, int value); void ts_stats_set(ts_stats_t stats, int64_t value);
int ts_stats_sum(ts_stats_t stats); int64_t ts_stats_sum(ts_stats_t stats);
#endif #endif

View File

@ -44,6 +44,7 @@
#include <log_manager.h> #include <log_manager.h>
#include <resultset.h> #include <resultset.h>
#include <maxconfig.h> #include <maxconfig.h>
#include <inttypes.h>
static void exec_show(DCB *dcb, MAXINFO_TREE *tree); static void exec_show(DCB *dcb, MAXINFO_TREE *tree);
static void exec_select(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 * Interface to poll stats for reads
*/ */
static int static int64_t
maxinfo_read_events() maxinfo_read_events()
{ {
return poll_get_stat(POLL_STAT_READ); return poll_get_stat(POLL_STAT_READ);
@ -1004,7 +1005,7 @@ maxinfo_read_events()
/** /**
* Interface to poll stats for writes * Interface to poll stats for writes
*/ */
static int static int64_t
maxinfo_write_events() maxinfo_write_events()
{ {
return poll_get_stat(POLL_STAT_WRITE); return poll_get_stat(POLL_STAT_WRITE);
@ -1013,7 +1014,7 @@ maxinfo_write_events()
/** /**
* Interface to poll stats for errors * Interface to poll stats for errors
*/ */
static int static int64_t
maxinfo_error_events() maxinfo_error_events()
{ {
return poll_get_stat(POLL_STAT_ERROR); return poll_get_stat(POLL_STAT_ERROR);
@ -1022,7 +1023,7 @@ maxinfo_error_events()
/** /**
* Interface to poll stats for hangup * Interface to poll stats for hangup
*/ */
static int static int64_t
maxinfo_hangup_events() maxinfo_hangup_events()
{ {
return poll_get_stat(POLL_STAT_HANGUP); return poll_get_stat(POLL_STAT_HANGUP);
@ -1031,7 +1032,7 @@ maxinfo_hangup_events()
/** /**
* Interface to poll stats for accepts * Interface to poll stats for accepts
*/ */
static int static int64_t
maxinfo_accept_events() maxinfo_accept_events()
{ {
return poll_get_stat(POLL_STAT_ACCEPT); return poll_get_stat(POLL_STAT_ACCEPT);
@ -1040,7 +1041,7 @@ maxinfo_accept_events()
/** /**
* Interface to poll stats for event queue length * Interface to poll stats for event queue length
*/ */
static int static int64_t
maxinfo_event_queue_length() maxinfo_event_queue_length()
{ {
return poll_get_stat(POLL_STAT_EVQ_LEN); 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 * Interface to poll stats for event pending queue length
*/ */
static int static int64_t
maxinfo_event_pending_queue_length() maxinfo_event_pending_queue_length()
{ {
return poll_get_stat(POLL_STAT_EVQ_PENDING); 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 * Interface to poll stats for max event queue length
*/ */
static int static int64_t
maxinfo_max_event_queue_length() maxinfo_max_event_queue_length()
{ {
return poll_get_stat(POLL_STAT_EVQ_MAX); 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 * Interface to poll stats for max queue time
*/ */
static int static int64_t
maxinfo_max_event_queue_time() maxinfo_max_event_queue_time()
{ {
return poll_get_stat(POLL_STAT_MAX_QTIME); 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 * Interface to poll stats for max event execution time
*/ */
static int static int64_t
maxinfo_max_event_exec_time() maxinfo_max_event_exec_time()
{ {
return poll_get_stat(POLL_STAT_MAX_EXECTIME); return poll_get_stat(POLL_STAT_MAX_EXECTIME);
@ -1149,8 +1150,8 @@ status_row(RESULTSET *result, void *data)
(char *)(*status[context->index].func)()); (char *)(*status[context->index].func)());
break; break;
case VT_INT: case VT_INT:
snprintf(buf, 80, "%ld", snprintf(buf, 80, "%" PRId64,
(long)(*status[context->index].func)()); (int64_t)(*status[context->index].func)());
resultset_row_set(row, 1, buf); resultset_row_set(row, 1, buf);
break; break;
default: default: