[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[UNIKRAFT PATCH 11/18] lib/ukalloc: Global statistics



Provides a configuration option that collects a consolidated global
statistic over all allocators.

Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
---
 lib/ukalloc/Config.uk               | 10 ++++++++++
 lib/ukalloc/exportsyms.uk           |  2 ++
 lib/ukalloc/include/uk/alloc.h      |  4 ++++
 lib/ukalloc/include/uk/alloc_impl.h | 14 ++++++++++++++
 lib/ukalloc/stats.c                 | 15 +++++++++++++++
 5 files changed, 45 insertions(+)

diff --git a/lib/ukalloc/Config.uk b/lib/ukalloc/Config.uk
index fc64a13b..ffeec00e 100644
--- a/lib/ukalloc/Config.uk
+++ b/lib/ukalloc/Config.uk
@@ -16,4 +16,14 @@ if LIBUKALLOC
                default n
                help
                        Provide interfaces for querying allocator statistics.
+
+       config LIBUKALLOC_IFSTATS_GLOBAL
+               bool "Global statistics"
+               default n
+               depends on LIBUKALLOC_IFSTATS
+               help
+                       Compute consolidated global allocator statistics.
+                       Please note that this option may slow down allocation
+                       perfomance due to competition to the single global
+                       counters.
 endif
diff --git a/lib/ukalloc/exportsyms.uk b/lib/ukalloc/exportsyms.uk
index 48de908c..f6765b5c 100644
--- a/lib/ukalloc/exportsyms.uk
+++ b/lib/ukalloc/exportsyms.uk
@@ -21,3 +21,5 @@ uk_alloc_availmem_total
 uk_alloc_pavail_total
 _uk_alloc_head
 uk_alloc_stats
+_uk_alloc_stats_global
+uk_alloc_stats_global
diff --git a/lib/ukalloc/include/uk/alloc.h b/lib/ukalloc/include/uk/alloc.h
index 59155d8c..28137e4e 100644
--- a/lib/ukalloc/include/uk/alloc.h
+++ b/lib/ukalloc/include/uk/alloc.h
@@ -310,6 +310,10 @@ unsigned long uk_alloc_pavail_total(void);
  * Memory allocation statistics
  */
 void uk_alloc_stats(struct uk_alloc *a, struct uk_alloc_stats *dst);
+
+#if CONFIG_LIBUKALLOC_IFSTATS_GLOBAL
+void uk_alloc_stats_global(struct uk_alloc_stats *dst);
+#endif /* CONFIG_LIBUKALLOC_IFSTATS_GLOBAL */
 #endif /* CONFIG_LIBUKALLOC_IFSTATS */
 
 #ifdef __cplusplus
diff --git a/lib/ukalloc/include/uk/alloc_impl.h 
b/lib/ukalloc/include/uk/alloc_impl.h
index 9ef6df13..961e36b5 100644
--- a/lib/ukalloc/include/uk/alloc_impl.h
+++ b/lib/ukalloc/include/uk/alloc_impl.h
@@ -141,6 +141,18 @@ static inline void _uk_alloc_stats_count_free(struct 
uk_alloc_stats *stats,
        uk_preempt_enable();
 }
 
+#if CONFIG_LIBUKALLOC_IFSTATS_GLOBAL
+#define _uk_alloc_stats_global_count_alloc(ptr, size) \
+       _uk_alloc_stats_count_alloc(&_uk_alloc_stats_global, (ptr), (size))
+#define _uk_alloc_stats_global_count_free(ptr, freed_size) \
+       _uk_alloc_stats_count_free(&_uk_alloc_stats_global, (ptr), (freed_size))
+#else /* !CONFIG_LIBUKALLOC_IFSTATS_GLOBAL */
+#define _uk_alloc_stats_global_count_alloc(ptr, size) \
+       do {} while (0)
+#define _uk_alloc_stats_global_count_free(ptr, freed_size) \
+       do {} while (0)
+#endif /* !CONFIG_LIBUKALLOC_IFSTATS_GLOBAL */
+
 /*
  * The following macros should be used to instrument an allocator for
  * statistics:
@@ -150,6 +162,7 @@ static inline void _uk_alloc_stats_count_free(struct 
uk_alloc_stats *stats,
        do {                                                            \
                _uk_alloc_stats_count_alloc(&((a)->_stats),             \
                                            (ptr), (size));             \
+               _uk_alloc_stats_global_count_alloc((ptr), (size));      \
        } while (0)
 #define uk_alloc_stats_count_palloc(a, ptr, num_pages)                 \
        uk_alloc_stats_count_alloc((a), (ptr),                          \
@@ -166,6 +179,7 @@ static inline void _uk_alloc_stats_count_free(struct 
uk_alloc_stats *stats,
        do {                                                            \
                _uk_alloc_stats_count_free(&((a)->_stats),              \
                                           (ptr), (freed_size));        \
+               _uk_alloc_stats_global_count_free((ptr), (freed_size)); \
        } while (0)
 #define uk_alloc_stats_count_pfree(a, ptr, num_pages)                  \
        uk_alloc_stats_count_free((a), (ptr),                           \
diff --git a/lib/ukalloc/stats.c b/lib/ukalloc/stats.c
index 26dcc405..2505d278 100644
--- a/lib/ukalloc/stats.c
+++ b/lib/ukalloc/stats.c
@@ -35,6 +35,10 @@
 #include <uk/preempt.h>
 #include <uk/alloc_impl.h>
 
+#if CONFIG_LIBUKALLOC_IFSTATS_GLOBAL
+struct uk_alloc_stats _uk_alloc_stats_global = { 0 };
+#endif
+
 void uk_alloc_stats(struct uk_alloc *a,
                    struct uk_alloc_stats *dst)
 {
@@ -45,3 +49,14 @@ void uk_alloc_stats(struct uk_alloc *a,
        memcpy(dst, &a->_stats, sizeof(*dst));
        uk_preempt_enable();
 }
+
+#if CONFIG_LIBUKALLOC_IFSTATS_GLOBAL
+void uk_alloc_stats_global(struct uk_alloc_stats *dst)
+{
+       UK_ASSERT(dst);
+
+       uk_preempt_disable();
+       memcpy(dst, &_uk_alloc_stats_global, sizeof(*dst));
+       uk_preempt_enable();
+}
+#endif
-- 
2.20.1



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.