Compare commits

...

5 Commits

Author SHA1 Message Date
Witold Kręcicki
7a39f8c80f make stats increment phony 2018-11-22 08:45:09 +00:00
Witold Kręcicki
c347d433e9 Prime 2018-11-21 23:17:40 +00:00
Witold Kręcicki
d6b33a78b5 Another approach 2018-11-21 21:45:21 +00:00
Witold Kręcicki
2015de2c61 16 buckets; non-uniform random 2018-11-21 21:27:12 +00:00
Witold Kręcicki
ce3efa0ba4 Experiment: bucketed stats 2018-11-21 21:11:07 +00:00

View File

@@ -23,13 +23,19 @@
#include <isc/mem.h>
#include <isc/platform.h>
#include <isc/print.h>
#include <isc/random.h>
#include <isc/rwlock.h>
#include <isc/stats.h>
#include <isc/util.h>
#define CBUCKETS 11
#define ISC_STATS_MAGIC ISC_MAGIC('S', 't', 'a', 't')
#define ISC_STATS_VALID(x) ISC_MAGIC_VALID(x, ISC_STATS_MAGIC)
inline unsigned int xxhash() {
return (((unsigned int)(13337*pthread_self())) % CBUCKETS);
}
typedef atomic_int_fast64_t isc_stat_t;
struct isc_stats {
@@ -64,29 +70,16 @@ struct isc_stats {
static isc_result_t
create_stats(isc_mem_t *mctx, int ncounters, isc_stats_t **statsp) {
isc_stats_t *stats;
isc_result_t result = ISC_R_SUCCESS;
REQUIRE(statsp != NULL && *statsp == NULL);
stats = isc_mem_get(mctx, sizeof(*stats));
if (stats == NULL)
return (ISC_R_NOMEMORY);
isc_mutex_init(&stats->lock);
result = isc_mutex_init(&stats->lock);
if (result != ISC_R_SUCCESS)
goto clean_stats;
stats->counters = isc_mem_get(mctx, sizeof(isc_stat_t) * ncounters * CBUCKETS);
stats->counters = isc_mem_get(mctx, sizeof(isc_stat_t) * ncounters);
if (stats->counters == NULL) {
result = ISC_R_NOMEMORY;
goto clean_mutex;
}
stats->copiedcounters = isc_mem_get(mctx,
sizeof(uint64_t) * ncounters);
if (stats->copiedcounters == NULL) {
result = ISC_R_NOMEMORY;
goto clean_counters;
}
stats->references = 1;
memset(stats->counters, 0, sizeof(isc_stat_t) * ncounters);
@@ -97,18 +90,7 @@ create_stats(isc_mem_t *mctx, int ncounters, isc_stats_t **statsp) {
*statsp = stats;
return (result);
clean_counters:
isc_mem_put(mctx, stats->counters, sizeof(isc_stat_t) * ncounters);
clean_mutex:
DESTROYLOCK(&stats->lock);
clean_stats:
isc_mem_put(mctx, stats, sizeof(*stats));
return (result);
return (ISC_R_SUCCESS);
}
void
@@ -139,7 +121,7 @@ isc_stats_detach(isc_stats_t **statsp) {
isc_mem_put(stats->mctx, stats->copiedcounters,
sizeof(isc_stat_t) * stats->ncounters);
isc_mem_put(stats->mctx, stats->counters,
sizeof(isc_stat_t) * stats->ncounters);
sizeof(uint64_t) * stats->ncounters * CBUCKETS);
UNLOCK(&stats->lock);
DESTROYLOCK(&stats->lock);
isc_mem_putanddetach(&stats->mctx, stats, sizeof(*stats));
@@ -165,19 +147,21 @@ isc_stats_create(isc_mem_t *mctx, isc_stats_t **statsp, int ncounters) {
void
isc_stats_increment(isc_stats_t *stats, isc_statscounter_t counter) {
return;
REQUIRE(ISC_STATS_VALID(stats));
REQUIRE(counter < stats->ncounters);
atomic_fetch_add_explicit(&stats->counters[counter], 1,
atomic_fetch_add_explicit(&stats->counters[counter + xxhash() * stats->ncounters], 1,
memory_order_relaxed);
}
void
isc_stats_decrement(isc_stats_t *stats, isc_statscounter_t counter) {
return;
REQUIRE(ISC_STATS_VALID(stats));
REQUIRE(counter < stats->ncounters);
atomic_fetch_sub_explicit(&stats->counters[counter], 1,
atomic_fetch_sub_explicit(&stats->counters[counter + xxhash() * stats->ncounters], 1,
memory_order_relaxed);
}
@@ -185,14 +169,17 @@ void
isc_stats_dump(isc_stats_t *stats, isc_stats_dumper_t dump_fn,
void *arg, unsigned int options)
{
int i;
int i, j;
REQUIRE(ISC_STATS_VALID(stats));
for (i = 0; i < stats->ncounters; i++) {
stats->copiedcounters[i] =
atomic_load_explicit(&stats->counters[i],
memory_order_relaxed);
stats->copiedcounters[i] = 0;
for (j = 0; i < CBUCKETS; j++) {
stats->copiedcounters[i] +=
atomic_load_explicit(&stats->counters[i+j*stats->ncounters],
memory_order_relaxed);
}
}
for (i = 0; i < stats->ncounters; i++) {
@@ -207,9 +194,13 @@ void
isc_stats_set(isc_stats_t *stats, uint64_t val,
isc_statscounter_t counter)
{
int i;
REQUIRE(ISC_STATS_VALID(stats));
REQUIRE(counter < stats->ncounters);
atomic_store_explicit(&stats->counters[counter], val,
memory_order_relaxed);
for (i = 1; i < CBUCKETS; i++) {
atomic_store_explicit(&stats->counters[counter + i*stats->ncounters], 0, memory_order_relaxed);
}
}