From: Monty Taylor Date: Fri, 18 Dec 2009 23:59:37 +0000 (-0800) Subject: Deal with atomic stats variables on 32-bit machines. X-Git-Tag: 0.37~51^2~1 X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=8c0dca3fe0a9cfbf6f2d595dedaabc08c9ef8dda;p=m6w6%2Flibmemcached Deal with atomic stats variables on 32-bit machines. --- diff --git a/clients/ms_atomic.h b/clients/ms_atomic.h index ca117df8..c4f9a947 100644 --- a/clients/ms_atomic.h +++ b/clients/ms_atomic.h @@ -15,25 +15,36 @@ #if defined(__SUNPRO_C) # define _KERNEL # include +# if defined(_INT64_TYPE) +# define atomic_add_size(X, Y) atomic_add_64((X), (Y)) +# define atomic_add_size_nv(X, Y) atomic_add_64((X), (Y)) +# define atomic_dec_size(X, Y) atomic_add_64((X), (Y)) +# define atomic_dec_size_nv(X, Y) atomic_add_64((X), (Y)) +# else +# define atomic_add_size(X, Y) atomic_add_32((X), (Y)) +# define atomic_add_size_nv(X, Y) atomic_add_32((X), (Y)) +# define atomic_dec_size(X, Y) atomic_add_32((X), (Y)) +# define atomic_dec_size_nv(X, Y) atomic_add_32((X), (Y)) +# endif # undef _KERNEL #else # define atomic_add_8(X, Y) __sync_fetch_and_add((X), (Y)) # define atomic_add_16(X, Y) __sync_fetch_and_add((X), (Y)) # define atomic_add_32(X, Y) __sync_fetch_and_add((X), (Y)) -# define atomic_add_64(X, Y) __sync_fetch_and_add((X), (Y)) +# define atomic_add_size(X, Y) __sync_fetch_and_add((X), (Y)) # define atomic_dec_8(X) __sync_fetch_and_sub((X), 1) # define atomic_dec_16(X) __sync_fetch_and_sub((X), 1) # define atomic_dec_32(X) __sync_fetch_and_sub((X), 1) -# define atomic_dec_64(X) __sync_fetch_and_sub((X), 1) +# define atomic_dec_size(X) __sync_fetch_and_sub((X), 1) /* The same as above, but these return the new value instead of void */ # define atomic_add_8_nv(X, Y) __sync_fetch_and_add((X), (Y)) # define atomic_add_16_nv(X, Y) __sync_fetch_and_add((X), (Y)) # define atomic_add_32_nv(X, Y) __sync_fetch_and_add((X), (Y)) -# define atomic_add_64_nv(X, Y) __sync_fetch_and_add((X), (Y)) +# define atomic_add_size_nv(X, Y) __sync_fetch_and_add((X), (Y)) # define atomic_dec_8_nv(X) __sync_fetch_and_sub((X), 1) # define atomic_dec_16_nv(X) __sync_fetch_and_sub((X), 1) # define atomic_dec_32_nv(X) __sync_fetch_and_sub((X), 1) -# define atomic_dec_64_nv(X) __sync_fetch_and_sub((X), 1) +# define atomic_dec_size_nv(X) __sync_fetch_and_sub((X), 1) #endif /* defined(__SUNPRO_C) */ #endif /* CLIENTS_MS_ATOMIC_H */ diff --git a/clients/ms_conn.c b/clients/ms_conn.c index 34707958..c062dc29 100644 --- a/clients/ms_conn.c +++ b/clients/ms_conn.c @@ -1589,7 +1589,7 @@ static int ms_udp_read(ms_conn_t *c, char *buf, int len) if (res > 0) { - atomic_add_64(&ms_stats.bytes_read, res); + atomic_add_size(&ms_stats.bytes_read, res); c->rudpbytes+= res; rbytes+= res; if (res == avail) @@ -1623,7 +1623,7 @@ static int ms_udp_read(ms_conn_t *c, char *buf, int len) if (copybytes == -1) { - atomic_add_64(&ms_stats.pkt_disorder, 1); + atomic_add_size(&ms_stats.pkt_disorder, 1); } return copybytes; @@ -1701,7 +1701,7 @@ static int ms_try_read_network(ms_conn_t *c) { if (! c->udp) { - atomic_add_64(&ms_stats.bytes_read, res); + atomic_add_size(&ms_stats.bytes_read, res); } gotdata= 1; c->rbytes+= res; @@ -1765,7 +1765,7 @@ static void ms_verify_value(ms_conn_t *c, if (curr_time.tv_sec - c->curr_task.item->client_time > c->curr_task.item->exp_time + EXPIRE_TIME_ERROR) { - atomic_add_64(&ms_stats.exp_get, 1); + atomic_add_size(&ms_stats.exp_get, 1); if (ms_setting.verbose) { @@ -1806,7 +1806,7 @@ static void ms_verify_value(ms_conn_t *c, if ((c->curr_task.item->value_size != vlen) || (memcmp(orignval, value, (size_t)vlen) != 0)) { - atomic_add_64(&ms_stats.vef_failed, 1); + atomic_add_size(&ms_stats.vef_failed, 1); if (ms_setting.verbose) { @@ -2254,7 +2254,7 @@ static int ms_transmit(ms_conn_t *c) res= sendmsg(c->sfd, m, 0); if (res > 0) { - atomic_add_64(&ms_stats.bytes_written, res); + atomic_add_size(&ms_stats.bytes_written, res); /* We've written some of the data. Remove the completed * iovec entries from the list of pending writes. */ @@ -2997,9 +2997,9 @@ int ms_mcd_set(ms_conn_t *c, ms_task_item_t *item) } } - atomic_add_64(&ms_stats.obj_bytes, - item->key_size + item->value_size); - atomic_add_64(&ms_stats.cmd_set, 1); + atomic_add_size(&ms_stats.obj_bytes, + item->key_size + item->value_size); + atomic_add_size(&ms_stats.cmd_set, 1); return 0; } /* ms_mcd_set */ @@ -3083,7 +3083,7 @@ int ms_mcd_get(ms_conn_t *c, ms_task_item_t *item, bool verify) } } - atomic_add_64(&ms_stats.cmd_get, 1); + atomic_add_size(&ms_stats.cmd_get, 1); return 0; } /* ms_mcd_get */ @@ -3182,7 +3182,7 @@ int ms_mcd_mlget(ms_conn_t *c) for (int i= 0; i < c->mlget_task.mlget_num; i++) { item= c->mlget_task.mlget_item[i].item; - atomic_add_64(&ms_stats.cmd_get, 1); + atomic_add_size(&ms_stats.cmd_get, 1); } return 0; diff --git a/clients/ms_memslap.h b/clients/ms_memslap.h index 30cc7157..51023d9d 100644 --- a/clients/ms_memslap.h +++ b/clients/ms_memslap.h @@ -70,21 +70,21 @@ typedef struct statistic typedef struct stats { volatile uint32_t active_conns; /* active connections */ - uint64_t bytes_read; /* read bytes */ - uint64_t bytes_written; /* written bytes */ - uint64_t obj_bytes; /* object bytes */ - uint64_t pre_cmd_get; /* previous total get command count */ - uint64_t pre_cmd_set; /* previous total set command count */ - uint64_t cmd_get; /* current total get command count */ - uint64_t cmd_set; /* current total set command count */ - uint64_t get_misses; /* total objects of get miss */ - uint64_t vef_miss; /* total objects of verification miss */ - uint64_t vef_failed; /* total objects of verification failed */ - uint64_t unexp_unget; /* total objects which is unexpired but not get */ - uint64_t exp_get; /* total objects which is expired but get */ - volatile uint64_t pkt_disorder; /* disorder packages of UDP */ - uint64_t pkt_drop; /* packages dropped of UDP */ - uint64_t udp_timeout; /* how many times timeout of UDP happens */ + size_t bytes_read; /* read bytes */ + size_t bytes_written; /* written bytes */ + size_t obj_bytes; /* object bytes */ + size_t pre_cmd_get; /* previous total get command count */ + size_t pre_cmd_set; /* previous total set command count */ + size_t cmd_get; /* current total get command count */ + size_t cmd_set; /* current total set command count */ + size_t get_misses; /* total objects of get miss */ + size_t vef_miss; /* total objects of verification miss */ + size_t vef_failed; /* total objects of verification failed */ + size_t unexp_unget; /* total objects which is unexpired but not get */ + size_t exp_get; /* total objects which is expired but get */ + volatile size_t pkt_disorder; /* disorder packages of UDP */ + size_t pkt_drop; /* packages dropped of UDP */ + size_t udp_timeout; /* how many times timeout of UDP happens */ } ms_stats_t; /* lock adapter */ diff --git a/clients/ms_task.c b/clients/ms_task.c index 7a427332..bcd2757c 100644 --- a/clients/ms_task.c +++ b/clients/ms_task.c @@ -725,7 +725,7 @@ static void ms_update_multi_get_result(ms_conn_t *c) /* update get miss counter */ if (mlget_item->get_miss) { - atomic_add_64(&ms_stats.get_misses, 1); + atomic_add_size(&ms_stats.get_misses, 1); } /* get nothing from server for this task item */ @@ -741,7 +741,7 @@ static void ms_update_multi_get_result(ms_conn_t *c) if (curr_time.tv_sec - item->client_time < item->exp_time - EXPIRE_TIME_ERROR) { - atomic_add_64(&ms_stats.unexp_unget, 1); + atomic_add_size(&ms_stats.unexp_unget, 1); if (ms_setting.verbose) { @@ -779,7 +779,7 @@ static void ms_update_multi_get_result(ms_conn_t *c) } else { - atomic_add_64(&ms_stats.vef_miss, 1); + atomic_add_size(&ms_stats.vef_miss, 1); if (ms_setting.verbose) { @@ -829,7 +829,7 @@ static void ms_update_single_get_result(ms_conn_t *c, ms_task_item_t *item) /* update get miss counter */ if ((c->precmd.cmd == CMD_GET) && c->curr_task.get_miss) { - atomic_add_64(&ms_stats.get_misses, 1); + atomic_add_size(&ms_stats.get_misses, 1); } /* get nothing from server for this task item */ @@ -846,7 +846,7 @@ static void ms_update_single_get_result(ms_conn_t *c, ms_task_item_t *item) if (curr_time.tv_sec - item->client_time < item->exp_time - EXPIRE_TIME_ERROR) { - atomic_add_64(&ms_stats.unexp_unget, 1); + atomic_add_size(&ms_stats.unexp_unget, 1); if (ms_setting.verbose) { @@ -884,7 +884,7 @@ static void ms_update_single_get_result(ms_conn_t *c, ms_task_item_t *item) } else { - atomic_add_64(&ms_stats.vef_miss, 1); + atomic_add_size(&ms_stats.vef_miss, 1); if (ms_setting.verbose) { diff --git a/clients/ms_thread.c b/clients/ms_thread.c index 5c387d0e..92d68871 100644 --- a/clients/ms_thread.c +++ b/clients/ms_thread.c @@ -69,10 +69,10 @@ static void ms_check_sock_timeout(void) /* calculate dropped packets count */ if (c->recvpkt > 0) { - atomic_add_64(&ms_stats.pkt_drop, c->packets - c->recvpkt); + atomic_add_size(&ms_stats.pkt_drop, c->packets - c->recvpkt); } - atomic_add_64(&ms_stats.udp_timeout, 1); + atomic_add_size(&ms_stats.udp_timeout, 1); ms_reset_conn(c, true); } }