summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Fedoryshchenko <denys.f@collabora.com>2026-04-29 15:29:20 +0300
committerDenys Fedoryshchenko <denys.f@collabora.com>2026-05-04 03:09:49 +0300
commite5fe0eaa1fc6b1109db784e818e360159d8dd2ac (patch)
tree8171a65c511849b941fbf492514cb5c89918b4e4
parentd6383d69813cf2244f31d8116176733ffbbeaceb (diff)
downloadaccel-ppp-e5fe0eaa1fc6b1109db784e818e360159d8dd2ac.tar.gz
accel-ppp-e5fe0eaa1fc6b1109db784e818e360159d8dd2ac.zip
triton: encapsulate statistics counters
Group the Triton core statistics in struct triton_stat_t and keep the storage private to triton.c instead of exporting the writable triton_stat object through triton.h. This keeps ownership inside the Triton core while preserving the existing CLI and ACCEL-PPP-MIB counter semantics. Route counter updates through triton_stat_*() helpers. Thread, context, md handler, timer, mempool, CPU, and start-time update paths no longer open-code direct triton_stat mutations; the update policy now lives beside the Triton-owned storage and uses relaxed atomic operations for the simple counters. Make the CLI show-stat path render from a local snapshot and update statCore SNMP readers to use triton_stat_start_time() and triton_stat_cpu(). Out-of-tree modules that accessed the exported triton_stat object directly must switch to the new accessors, because triton_stat is no longer part of the public ABI. Signed-off-by: Denys Fedoryshchenko <denys.f@collabora.com>
-rw-r--r--accel-pppd/cli/std_cmd.c29
-rw-r--r--accel-pppd/extra/net-snmp/statCore.c4
-rw-r--r--accel-pppd/triton/md.c8
-rw-r--r--accel-pppd/triton/mempool.c18
-rw-r--r--accel-pppd/triton/timer.c8
-rw-r--r--accel-pppd/triton/triton.c185
-rw-r--r--accel-pppd/triton/triton.h4
-rw-r--r--accel-pppd/triton/triton_p.h24
8 files changed, 228 insertions, 52 deletions
diff --git a/accel-pppd/cli/std_cmd.c b/accel-pppd/cli/std_cmd.c
index 9e7bf557..951b10da 100644
--- a/accel-pppd/cli/std_cmd.c
+++ b/accel-pppd/cli/std_cmd.c
@@ -30,6 +30,9 @@ static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt,
#ifdef MEMDEBUG
struct mallinfo mi = mallinfo();
#endif
+ struct triton_stat_t stat;
+
+ triton_stat_get(&stat);
sprintf(statm_fname, "/proc/%i/statm", getpid());
f = fopen(statm_fname, "r");
@@ -39,14 +42,14 @@ static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt,
}
clock_gettime(CLOCK_MONOTONIC, &ts);
- dt = ts.tv_sec - triton_stat.start_time;
+ dt = ts.tv_sec - stat.start_time;
day = dt / (60 * 60 * 24);
dt %= 60 * 60 * 24;
hour = dt / (60 * 60);
dt %= 60 * 60;
cli_sendv(client, "uptime: %i.%02i:%02lu:%02lu\r\n", day, hour, dt / 60, dt % 60);
- cli_sendv(client, "cpu: %i%%\r\n", triton_stat.cpu);
+ cli_sendv(client, "cpu: %i%%\r\n", stat.cpu);
#ifdef MEMDEBUG
cli_send(client, "memory:\r\n");
cli_sendv(client, " rss/virt: %lu/%lu kB\r\n", vmrss * page_size_kb, vmsize * page_size_kb);
@@ -58,17 +61,17 @@ static int show_stat_exec(const char *cmd, char * const *fields, int fields_cnt,
cli_sendv(client, "mem(rss/virt): %lu/%lu kB\r\n", vmrss * page_size_kb, vmsize * page_size_kb);
#endif
cli_send(client, "core:\r\n");
- cli_sendv(client, " mempool_allocated: %" PRIu64 "\r\n", triton_stat.mempool_allocated);
- cli_sendv(client, " mempool_available: %" PRIu64 "\r\n", triton_stat.mempool_available);
- cli_sendv(client, " thread_count: %u\r\n", triton_stat.thread_count);
- cli_sendv(client, " thread_active: %u\r\n", triton_stat.thread_active);
- cli_sendv(client, " context_count: %u\r\n", triton_stat.context_count);
- cli_sendv(client, " context_sleeping: %u\r\n", triton_stat.context_sleeping);
- cli_sendv(client, " context_pending: %u\r\n", triton_stat.context_pending);
- cli_sendv(client, " md_handler_count: %u\r\n", triton_stat.md_handler_count);
- cli_sendv(client, " md_handler_pending: %u\r\n", triton_stat.md_handler_pending);
- cli_sendv(client, " timer_count: %u\r\n", triton_stat.timer_count);
- cli_sendv(client, " timer_pending: %u\r\n", triton_stat.timer_pending);
+ cli_sendv(client, " mempool_allocated: %" PRIu64 "\r\n", stat.mempool_allocated);
+ cli_sendv(client, " mempool_available: %" PRIu64 "\r\n", stat.mempool_available);
+ cli_sendv(client, " thread_count: %u\r\n", stat.thread_count);
+ cli_sendv(client, " thread_active: %u\r\n", stat.thread_active);
+ cli_sendv(client, " context_count: %u\r\n", stat.context_count);
+ cli_sendv(client, " context_sleeping: %u\r\n", stat.context_sleeping);
+ cli_sendv(client, " context_pending: %u\r\n", stat.context_pending);
+ cli_sendv(client, " md_handler_count: %u\r\n", stat.md_handler_count);
+ cli_sendv(client, " md_handler_pending: %u\r\n", stat.md_handler_pending);
+ cli_sendv(client, " timer_count: %u\r\n", stat.timer_count);
+ cli_sendv(client, " timer_pending: %u\r\n", stat.timer_pending);
//===========
{
diff --git a/accel-pppd/extra/net-snmp/statCore.c b/accel-pppd/extra/net-snmp/statCore.c
index 9206f6ed..7e9047da 100644
--- a/accel-pppd/extra/net-snmp/statCore.c
+++ b/accel-pppd/extra/net-snmp/statCore.c
@@ -49,7 +49,7 @@ handle_statCoreUpTime(netsnmp_mib_handler *handler,
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
- ts.tv_sec -= triton_stat.start_time;
+ ts.tv_sec -= triton_stat_start_time();
/* We are never called for a GETNEXT if it's registered as a
"instance", as it's "magically" handled for us. */
@@ -91,7 +91,7 @@ handle_statCoreCPU(netsnmp_mib_handler *handler,
switch(reqinfo->mode) {
case MODE_GET:
- cpu = triton_stat.cpu;
+ cpu = triton_stat_cpu();
snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,
(u_char *)&cpu /* XXX: a pointer to the scalar's data */,
sizeof(cpu)/* XXX: the length of the data in bytes */);
diff --git a/accel-pppd/triton/md.c b/accel-pppd/triton/md.c
index 9b7dd81a..374e49a5 100644
--- a/accel-pppd/triton/md.c
+++ b/accel-pppd/triton/md.c
@@ -87,7 +87,7 @@ static void *md_thread(void *arg)
if (!h->pending) {
list_add_tail(&h->entry2, &h->ctx->pending_handlers);
h->pending = 1;
- __sync_add_and_fetch(&triton_stat.md_handler_pending, 1);
+ triton_stat_md_handler_pending_inc();
r = triton_queue_ctx(h->ctx);
} else
r = 0;
@@ -129,7 +129,7 @@ void __export triton_md_register_handler(struct triton_context_t *ctx, struct tr
list_add_tail(&h->entry, &h->ctx->handlers);
spin_unlock(&h->ctx->lock);
- __sync_add_and_fetch(&triton_stat.md_handler_count, 1);
+ triton_stat_md_handler_count_inc();
}
void __export triton_md_unregister_handler(struct triton_md_handler_t *ud, int c)
@@ -148,7 +148,7 @@ void __export triton_md_unregister_handler(struct triton_md_handler_t *ud, int c
list_del(&h->entry);
if (h->pending) {
list_del(&h->entry2);
- __sync_sub_and_fetch(&triton_stat.md_handler_pending, 1);
+ triton_stat_md_handler_pending_dec();
}
spin_unlock(&h->ctx->lock);
@@ -158,7 +158,7 @@ void __export triton_md_unregister_handler(struct triton_md_handler_t *ud, int c
ud->tpd = NULL;
- __sync_sub_and_fetch(&triton_stat.md_handler_count, 1);
+ triton_stat_md_handler_count_dec();
}
int __export triton_md_enable_handler(struct triton_md_handler_t *ud, int mode)
diff --git a/accel-pppd/triton/mempool.c b/accel-pppd/triton/mempool.c
index 149f09d5..a3c72dae 100644
--- a/accel-pppd/triton/mempool.c
+++ b/accel-pppd/triton/mempool.c
@@ -104,7 +104,7 @@ void __export *mempool_alloc(mempool_t *pool)
spin_unlock(&p->lock);
--p->objects;
- __sync_sub_and_fetch(&triton_stat.mempool_available, size);
+ triton_stat_mempool_available_sub(size);
return it->ptr;
}
@@ -121,10 +121,10 @@ void __export *mempool_alloc(mempool_t *pool)
it = (struct _item_t *)mmap_ptr;
mmap_ptr += size;
spin_unlock(&mmap_lock);
- __sync_sub_and_fetch(&triton_stat.mempool_available, size);
+ triton_stat_mempool_available_sub(size);
} else {
it = _malloc(size);
- __sync_add_and_fetch(&triton_stat.mempool_allocated, size);
+ triton_stat_mempool_allocated_add(size);
}
if (!it) {
@@ -184,9 +184,9 @@ void __export mempool_free(void *ptr)
#else
if (need_free) {
_free(it);
- __sync_sub_and_fetch(&triton_stat.mempool_allocated, size);
+ triton_stat_mempool_allocated_sub(size);
} else
- __sync_add_and_fetch(&triton_stat.mempool_available, size);
+ triton_stat_mempool_available_add(size);
#endif
}
@@ -238,8 +238,8 @@ static void mempool_clean(void)
#endif
list_del(&it->entry);
_free(it);
- __sync_sub_and_fetch(&triton_stat.mempool_allocated, size);
- __sync_sub_and_fetch(&triton_stat.mempool_available, size);
+ triton_stat_mempool_allocated_sub(size);
+ triton_stat_mempool_available_sub(size);
#ifdef VALGRIND
} else
break;
@@ -275,8 +275,8 @@ static int mmap_grow(void)
mmap_endptr = ptr + size;
- __sync_add_and_fetch(&triton_stat.mempool_allocated, size);
- __sync_add_and_fetch(&triton_stat.mempool_available, size);
+ triton_stat_mempool_allocated_add(size);
+ triton_stat_mempool_available_add(size);
return 0;
oom:
diff --git a/accel-pppd/triton/timer.c b/accel-pppd/triton/timer.c
index 5b5d9535..ed23eb1d 100644
--- a/accel-pppd/triton/timer.c
+++ b/accel-pppd/triton/timer.c
@@ -95,7 +95,7 @@ void *timer_thread(void *arg)
if (!t->pending) {
list_add_tail(&t->entry2, &t->ctx->pending_timers);
t->pending = 1;
- __sync_add_and_fetch(&triton_stat.timer_pending, 1);
+ triton_stat_timer_pending_inc();
r = triton_queue_ctx(t->ctx);
} else
r = 0;
@@ -167,7 +167,7 @@ int __export triton_timer_add(struct triton_context_t *ctx, struct triton_timer_
goto out_err;
}
- __sync_add_and_fetch(&triton_stat.timer_count, 1);
+ triton_stat_timer_count_inc();
return 0;
@@ -206,7 +206,7 @@ void __export triton_timer_del(struct triton_timer_t *ud)
list_del(&t->entry);
if (t->pending) {
list_del(&t->entry2);
- __sync_sub_and_fetch(&triton_stat.timer_pending, 1);
+ triton_stat_timer_pending_dec();
}
spin_unlock(&t->ctx->lock);
@@ -216,6 +216,6 @@ void __export triton_timer_del(struct triton_timer_t *ud)
ud->tpd = NULL;
- __sync_sub_and_fetch(&triton_stat.timer_count, 1);
+ triton_stat_timer_count_dec();
}
diff --git a/accel-pppd/triton/triton.c b/accel-pppd/triton/triton.c
index 395a42df..5c7231b7 100644
--- a/accel-pppd/triton/triton.c
+++ b/accel-pppd/triton/triton.c
@@ -38,7 +38,7 @@ static void (*config_reload_notify)(int);
static mempool_t *ctx_pool;
static mempool_t *call_pool;
-struct triton_stat_t __export triton_stat;
+static struct triton_stat_t triton_stat;
static struct timeval ru_utime;
static struct timeval ru_stime;
@@ -57,6 +57,153 @@ static __thread void *thread_frame;
#define log_debug2(fmt, ...)
+void __export triton_stat_get(struct triton_stat_t *stat)
+{
+ stat->mempool_allocated = __atomic_load_n(&triton_stat.mempool_allocated, __ATOMIC_RELAXED);
+ stat->mempool_available = __atomic_load_n(&triton_stat.mempool_available, __ATOMIC_RELAXED);
+ stat->thread_count = __atomic_load_n(&triton_stat.thread_count, __ATOMIC_RELAXED);
+ stat->thread_active = __atomic_load_n(&triton_stat.thread_active, __ATOMIC_RELAXED);
+ stat->context_count = __atomic_load_n(&triton_stat.context_count, __ATOMIC_RELAXED);
+ stat->context_sleeping = __atomic_load_n(&triton_stat.context_sleeping, __ATOMIC_RELAXED);
+ stat->context_pending = __atomic_load_n(&triton_stat.context_pending, __ATOMIC_RELAXED);
+ stat->md_handler_count = __atomic_load_n(&triton_stat.md_handler_count, __ATOMIC_RELAXED);
+ stat->md_handler_pending = __atomic_load_n(&triton_stat.md_handler_pending, __ATOMIC_RELAXED);
+ stat->timer_count = __atomic_load_n(&triton_stat.timer_count, __ATOMIC_RELAXED);
+ stat->timer_pending = __atomic_load_n(&triton_stat.timer_pending, __ATOMIC_RELAXED);
+ stat->start_time = __atomic_load_n(&triton_stat.start_time, __ATOMIC_RELAXED);
+ stat->cpu = __atomic_load_n(&triton_stat.cpu, __ATOMIC_RELAXED);
+}
+
+time_t __export triton_stat_start_time(void)
+{
+ return __atomic_load_n(&triton_stat.start_time, __ATOMIC_RELAXED);
+}
+
+unsigned int __export triton_stat_cpu(void)
+{
+ return __atomic_load_n(&triton_stat.cpu, __ATOMIC_RELAXED);
+}
+
+void triton_stat_mempool_allocated_add(uint64_t value)
+{
+ __atomic_add_fetch(&triton_stat.mempool_allocated, value, __ATOMIC_RELAXED);
+}
+
+void triton_stat_mempool_allocated_sub(uint64_t value)
+{
+ __atomic_sub_fetch(&triton_stat.mempool_allocated, value, __ATOMIC_RELAXED);
+}
+
+void triton_stat_mempool_available_add(uint64_t value)
+{
+ __atomic_add_fetch(&triton_stat.mempool_available, value, __ATOMIC_RELAXED);
+}
+
+void triton_stat_mempool_available_sub(uint64_t value)
+{
+ __atomic_sub_fetch(&triton_stat.mempool_available, value, __ATOMIC_RELAXED);
+}
+
+void triton_stat_thread_count_inc(void)
+{
+ __atomic_add_fetch(&triton_stat.thread_count, 1, __ATOMIC_RELAXED);
+}
+
+void triton_stat_thread_active_inc(void)
+{
+ __atomic_add_fetch(&triton_stat.thread_active, 1, __ATOMIC_RELAXED);
+}
+
+unsigned int triton_stat_thread_active_dec(void)
+{
+ return __atomic_sub_fetch(&triton_stat.thread_active, 1, __ATOMIC_RELAXED);
+}
+
+static unsigned int triton_stat_thread_active(void)
+{
+ return __atomic_load_n(&triton_stat.thread_active, __ATOMIC_RELAXED);
+}
+
+void triton_stat_context_count_inc(void)
+{
+ __atomic_add_fetch(&triton_stat.context_count, 1, __ATOMIC_RELAXED);
+}
+
+unsigned int triton_stat_context_count_dec(void)
+{
+ return __atomic_sub_fetch(&triton_stat.context_count, 1, __ATOMIC_RELAXED);
+}
+
+void triton_stat_context_sleeping_inc(void)
+{
+ __atomic_add_fetch(&triton_stat.context_sleeping, 1, __ATOMIC_RELAXED);
+}
+
+void triton_stat_context_sleeping_dec(void)
+{
+ __atomic_sub_fetch(&triton_stat.context_sleeping, 1, __ATOMIC_RELAXED);
+}
+
+void triton_stat_context_pending_inc(void)
+{
+ __atomic_add_fetch(&triton_stat.context_pending, 1, __ATOMIC_RELAXED);
+}
+
+void triton_stat_context_pending_dec(void)
+{
+ __atomic_sub_fetch(&triton_stat.context_pending, 1, __ATOMIC_RELAXED);
+}
+
+void triton_stat_md_handler_count_inc(void)
+{
+ __atomic_add_fetch(&triton_stat.md_handler_count, 1, __ATOMIC_RELAXED);
+}
+
+void triton_stat_md_handler_count_dec(void)
+{
+ __atomic_sub_fetch(&triton_stat.md_handler_count, 1, __ATOMIC_RELAXED);
+}
+
+void triton_stat_md_handler_pending_inc(void)
+{
+ __atomic_add_fetch(&triton_stat.md_handler_pending, 1, __ATOMIC_RELAXED);
+}
+
+void triton_stat_md_handler_pending_dec(void)
+{
+ __atomic_sub_fetch(&triton_stat.md_handler_pending, 1, __ATOMIC_RELAXED);
+}
+
+void triton_stat_timer_count_inc(void)
+{
+ __atomic_add_fetch(&triton_stat.timer_count, 1, __ATOMIC_RELAXED);
+}
+
+void triton_stat_timer_count_dec(void)
+{
+ __atomic_sub_fetch(&triton_stat.timer_count, 1, __ATOMIC_RELAXED);
+}
+
+void triton_stat_timer_pending_inc(void)
+{
+ __atomic_add_fetch(&triton_stat.timer_pending, 1, __ATOMIC_RELAXED);
+}
+
+void triton_stat_timer_pending_dec(void)
+{
+ __atomic_sub_fetch(&triton_stat.timer_pending, 1, __ATOMIC_RELAXED);
+}
+
+void triton_stat_set_cpu(unsigned int value)
+{
+ __atomic_store_n(&triton_stat.cpu, value, __ATOMIC_RELAXED);
+}
+
+void triton_stat_set_start_time(time_t value)
+{
+ __atomic_store_n(&triton_stat.start_time, value, __ATOMIC_RELAXED);
+}
+
void triton_thread_wakeup(struct _triton_thread_t *thread)
{
log_debug2("wake up thread %p\n", thread);
@@ -146,7 +293,7 @@ static void* triton_thread(struct _triton_thread_t *thread)
thread->ctx->thread = thread;
thread->ctx->queued = 0;
spin_unlock(&threads_lock);
- __sync_sub_and_fetch(&triton_stat.context_pending, 1);
+ triton_stat_context_pending_dec();
}
} else {
log_debug2("thread: %p: sleeping\n", thread);
@@ -154,7 +301,7 @@ static void* triton_thread(struct _triton_thread_t *thread)
if (!terminate)
list_add(&thread->entry2, &sleep_threads);
- if (__sync_sub_and_fetch(&triton_stat.thread_active, 1) == 0 && need_config_reload) {
+ if (triton_stat_thread_active_dec() == 0 && need_config_reload) {
spin_unlock(&threads_lock);
__config_reload(config_reload_notify);
} else
@@ -172,7 +319,7 @@ static void* triton_thread(struct _triton_thread_t *thread)
//printf("thread %p: exit sigwait\n", thread);
spin_lock(&threads_lock);
- __sync_add_and_fetch(&triton_stat.thread_active, 1);
+ triton_stat_thread_active_inc();
if (!thread->ctx) {
list_del(&thread->entry2);
spin_unlock(&threads_lock);
@@ -228,7 +375,7 @@ static void ctx_thread(struct _triton_context_t *ctx)
list_del(&t->entry2);
t->pending = 0;
spin_unlock(&ctx->lock);
- __sync_sub_and_fetch(&triton_stat.timer_pending, 1);
+ triton_stat_timer_pending_dec();
read(t->fd, &tt, sizeof(tt));
if (t->ud)
t->ud->expire(t->ud);
@@ -243,7 +390,7 @@ static void ctx_thread(struct _triton_context_t *ctx)
h->trig_epoll_events = 0;
spin_unlock(&ctx->lock);
- __sync_sub_and_fetch(&triton_stat.md_handler_pending, 1);
+ triton_stat_md_handler_pending_dec();
h->armed = 0;
@@ -320,8 +467,8 @@ struct _triton_thread_t *create_thread()
while (pthread_create(&thread->thread, &attr, (void*(*)(void*))triton_thread, thread))
sleep(1);
- __sync_add_and_fetch(&triton_stat.thread_count, 1);
- __sync_add_and_fetch(&triton_stat.thread_active, 1);
+ triton_stat_thread_count_inc();
+ triton_stat_thread_active_inc();
return thread;
}
@@ -340,7 +487,7 @@ int triton_queue_ctx(struct _triton_context_t *ctx)
spin_unlock(&threads_lock);
ctx->queued = 1;
log_debug2("ctx %p: queued\n", ctx);
- __sync_add_and_fetch(&triton_stat.context_pending, 1);
+ triton_stat_context_pending_inc();
return 0;
}
@@ -386,8 +533,8 @@ int __export triton_context_register(struct triton_context_t *ud, void *bf_arg)
list_add_tail(&ctx->entry, &ctx_list);
spin_unlock(&ctx_list_lock);
- __sync_add_and_fetch(&triton_stat.context_sleeping, 1);
- __sync_add_and_fetch(&triton_stat.context_count, 1);
+ triton_stat_context_sleeping_inc();
+ triton_stat_context_count_inc();
return 0;
}
@@ -437,7 +584,7 @@ void __export triton_context_unregister(struct triton_context_t *ud)
spin_lock(&ctx_list_lock);
list_del(&ctx->entry);
- if (__sync_sub_and_fetch(&triton_stat.context_count, 1) == 1) {
+ if (triton_stat_context_count_dec() == 1) {
if (need_terminate)
terminate = 1;
}
@@ -492,7 +639,7 @@ void __export triton_context_schedule()
volatile struct _triton_context_t *ctx = (struct _triton_context_t *)this_ctx->tpd;
log_debug2("ctx %p: enter schedule\n", ctx);
- __sync_add_and_fetch(&triton_stat.context_sleeping, 1);
+ triton_stat_context_sleeping_inc();
ctx->uc = alloc_context();
@@ -509,7 +656,7 @@ void __export triton_context_schedule()
spin_unlock(&threads_lock);
_free(ctx->uc);
ctx->uc = NULL;
- __sync_sub_and_fetch(&triton_stat.context_sleeping, 1);
+ triton_stat_context_sleeping_dec();
log_debug2("ctx %p: exit schedule\n", ctx);
} else {
ctx->asleep = 1;
@@ -527,7 +674,7 @@ void __export triton_context_wakeup(struct triton_context_t *ud)
log_debug2("ctx %p: wakeup\n", ctx);
if (ctx->init) {
- __sync_sub_and_fetch(&triton_stat.context_sleeping, 1);
+ triton_stat_context_sleeping_dec();
spin_lock(&ctx->lock);
ctx->init = 0;
if (ctx->pending)
@@ -610,7 +757,7 @@ void __export triton_collect_cpu_usage(void)
clock_gettime(CLOCK_MONOTONIC, &ru_timestamp);
ru_utime = rusage.ru_utime;
ru_stime = rusage.ru_stime;
- triton_stat.cpu = 0;
+ triton_stat_set_cpu(0);
}
}
@@ -634,7 +781,7 @@ static void ru_update(struct triton_timer_t *t)
val = (double)((rusage.ru_utime.tv_sec - ru_utime.tv_sec) * 1000000 + (rusage.ru_utime.tv_usec - ru_utime.tv_usec) +
(rusage.ru_stime.tv_sec - ru_stime.tv_sec) * 1000000 + (rusage.ru_stime.tv_usec - ru_stime.tv_usec)) / dt * 100;
- triton_stat.cpu = val;
+ triton_stat_set_cpu(val);
ru_timestamp = ts;
ru_utime = rusage.ru_utime;
@@ -714,7 +861,7 @@ void __export triton_conf_reload(void (*notify)(int))
spin_lock(&threads_lock);
need_config_reload = 1;
config_reload_notify = notify;
- if (triton_stat.thread_active == 0) {
+ if (triton_stat_thread_active() == 0) {
spin_unlock(&threads_lock);
__config_reload(notify);
} else
@@ -752,7 +899,7 @@ void __export triton_run()
}
clock_gettime(CLOCK_MONOTONIC, &ts);
- triton_stat.start_time = ts.tv_sec;
+ triton_stat_set_start_time(ts.tv_sec);
md_run();
timer_run();
diff --git a/accel-pppd/triton/triton.h b/accel-pppd/triton/triton.h
index 3ce4bcbd..aef77c2b 100644
--- a/accel-pppd/triton/triton.h
+++ b/accel-pppd/triton/triton.h
@@ -70,7 +70,9 @@ struct triton_stat_t
unsigned int cpu;
};
-extern struct triton_stat_t triton_stat;
+void triton_stat_get(struct triton_stat_t *stat);
+time_t triton_stat_start_time(void);
+unsigned int triton_stat_cpu(void);
int triton_context_register(struct triton_context_t *, void *arg);
void triton_context_unregister(struct triton_context_t *);
void triton_context_set_priority(struct triton_context_t *, int);
diff --git a/accel-pppd/triton/triton_p.h b/accel-pppd/triton/triton_p.h
index bc39d626..7fa70b63 100644
--- a/accel-pppd/triton/triton_p.h
+++ b/accel-pppd/triton/triton_p.h
@@ -119,4 +119,28 @@ void triton_log_debug(const char *fmt, ...) __attribute__((format(gnu_printf, 1,
int load_modules(const char *name);
void triton_context_release(struct _triton_context_t *ctx);
+void triton_stat_mempool_allocated_add(uint64_t value);
+void triton_stat_mempool_allocated_sub(uint64_t value);
+void triton_stat_mempool_available_add(uint64_t value);
+void triton_stat_mempool_available_sub(uint64_t value);
+void triton_stat_thread_count_inc(void);
+void triton_stat_thread_active_inc(void);
+unsigned int triton_stat_thread_active_dec(void);
+void triton_stat_context_count_inc(void);
+unsigned int triton_stat_context_count_dec(void);
+void triton_stat_context_sleeping_inc(void);
+void triton_stat_context_sleeping_dec(void);
+void triton_stat_context_pending_inc(void);
+void triton_stat_context_pending_dec(void);
+void triton_stat_md_handler_count_inc(void);
+void triton_stat_md_handler_count_dec(void);
+void triton_stat_md_handler_pending_inc(void);
+void triton_stat_md_handler_pending_dec(void);
+void triton_stat_timer_count_inc(void);
+void triton_stat_timer_count_dec(void);
+void triton_stat_timer_pending_inc(void);
+void triton_stat_timer_pending_dec(void);
+void triton_stat_set_cpu(unsigned int value);
+void triton_stat_set_start_time(time_t value);
+
#endif