]> xenbits.xensource.com Git - unikraft/unikraft.git/commitdiff
lib/ukalloc: Global statistics
authorSimon Kuenzer <simon.kuenzer@neclab.eu>
Thu, 12 Nov 2020 23:12:15 +0000 (00:12 +0100)
committerUnikraft <monkey@unikraft.io>
Tue, 22 Jun 2021 13:14:08 +0000 (13:14 +0000)
Provides a configuration option that collects a consolidated global
statistic over all allocators.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Cezar Craciunoiu <cezar.craciunoiu@gmail.com>
Tested-by: Unikraft CI <monkey@unikraft.io>
GitHub-Pull-Request: #229

lib/ukalloc/Config.uk
lib/ukalloc/exportsyms.uk
lib/ukalloc/include/uk/alloc.h
lib/ukalloc/include/uk/alloc_impl.h
lib/ukalloc/stats.c

index fc64a13b6c868aa05aea4bdd9f1692f507a545f0..ffeec00e96f386093651332dd4b535a25d380ce6 100644 (file)
@@ -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
index 24fe12e123a340b44078dde5b400c8146ef7beb8..5a8edfc9c34d5f74a86174d809ee639743e7289c 100644 (file)
@@ -21,3 +21,5 @@ uk_alloc_availmem_total
 uk_alloc_pavailmem_total
 _uk_alloc_head
 uk_alloc_stats_get
+_uk_alloc_stats_global
+uk_alloc_stats_get_global
index f008a129208967e39201c456c912e39be5117d21..d89c023222836f25db326fa755a837601391171a 100644 (file)
@@ -310,6 +310,10 @@ unsigned long uk_alloc_pavailmem_total(void);
  * Memory allocation statistics
  */
 void uk_alloc_stats_get(struct uk_alloc *a, struct uk_alloc_stats *dst);
+
+#if CONFIG_LIBUKALLOC_IFSTATS_GLOBAL
+void uk_alloc_stats_get_global(struct uk_alloc_stats *dst);
+#endif /* CONFIG_LIBUKALLOC_IFSTATS_GLOBAL */
 #endif /* CONFIG_LIBUKALLOC_IFSTATS */
 
 #ifdef __cplusplus
index 4ead0f56745b069d678be6d9da57672e1fed21b6..2da5005993ce26181272d0f2ac0e872225d8337d 100644 (file)
@@ -145,14 +145,29 @@ 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:
  */
 /* NOTE: If ptr is NULL, an ENOMEM event is counted */
 #define uk_alloc_stats_count_alloc(a, ptr, size)                       \
-       _uk_alloc_stats_count_alloc(&((a)->_stats),                     \
-                                   (ptr), (size))
+       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),                          \
                                   ((size_t) (num_pages)) << __PAGE_SHIFT)
@@ -165,8 +180,11 @@ static inline void _uk_alloc_stats_count_free(struct uk_alloc_stats *stats,
 
 /* Note: if ptr is NULL, nothing is counted */
 #define uk_alloc_stats_count_free(a, ptr, freed_size)                  \
-       _uk_alloc_stats_count_free(&((a)->_stats),                      \
-                                  (ptr), (freed_size))
+       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),                           \
                                  ((size_t) (num_pages)) << __PAGE_SHIFT)
index 4351686ed9d20ea1fea6b2daa0f8f85ef7a2ed77..54bbda358621c25e4f02e31c37d6a45c65b3e7a6 100644 (file)
 
 #include <uk/alloc_impl.h>
 
+#if CONFIG_LIBUKALLOC_IFSTATS_GLOBAL
+struct uk_alloc_stats _uk_alloc_stats_global = { 0 };
+#endif
+
 void uk_alloc_stats_get(struct uk_alloc *a,
                        struct uk_alloc_stats *dst)
 {
@@ -43,3 +47,14 @@ void uk_alloc_stats_get(struct uk_alloc *a,
        memcpy(dst, &a->_stats, sizeof(*dst));
        uk_preempt_enable();
 }
+
+#if CONFIG_LIBUKALLOC_IFSTATS_GLOBAL
+void uk_alloc_stats_get_global(struct uk_alloc_stats *dst)
+{
+       UK_ASSERT(dst);
+
+       uk_preempt_disable();
+       memcpy(dst, &_uk_alloc_stats_global, sizeof(*dst));
+       uk_preempt_enable();
+}
+#endif