mempool: cpu=-1 for init_func argument (global pool)
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 9 Mar 2024 18:39:31 +0000 (13:39 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 9 Mar 2024 18:39:31 +0000 (13:39 -0500)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I956006f59186252d3dcc767fa21e5928f68d5cb8

include/rseq/mempool.h
src/rseq-mempool.c

index 1cad7611c3f47159ba378106580e46e3e6e9c997..4555a017e2e48df284a86d66387d40936d618703 100644 (file)
@@ -404,10 +404,13 @@ int rseq_mempool_attr_set_mmap(struct rseq_mempool_attr *attr,
  * rseq_mempool_attr_set_init: Set pool attribute structure memory init functions.
  *
  * The @init_func callback used to initialized memory after allocation
- * for the pool. The @init_func callback must return 0 on success, -1 on
- * error with errno set. If @init_func returns failure, the allocation
- * of the pool memory fails, which either causes the pool creation to
- * fail or memory allocation to fail (for extensible memory pools).
+ * for the pool. The @cpu argument of @init_func, if >= 0, is the cpu to
+ * which belongs the range starting at @addr of length @len. If cpu is
+ * -1, it means the range belongs to a global pool. The @init_func
+ * callback must return 0 on success, -1 on error with errno set. If
+ * @init_func returns failure, the allocation of the pool memory fails,
+ * which either causes the pool creation to fail or memory allocation to
+ * fail (for extensible memory pools).
  *
  * The @init_priv argument is a private data pointer passed to the
  * @init_func callback.
index 5823ae59be9e2cccff60c77ef00566c95b9c7b36..0c79e5a00ec57d79c7272931da4bcdd85f60deea 100644 (file)
@@ -465,14 +465,27 @@ struct rseq_mempool_range *rseq_mempool_range_create(struct rseq_mempool *pool)
                        goto error_alloc;
        }
        if (pool->attr.init_set) {
-               int cpu;
-
-               for (cpu = 0; cpu < pool->attr.max_nr_cpus; cpu++) {
+               switch (pool->attr.type) {
+               case MEMPOOL_TYPE_GLOBAL:
                        if (pool->attr.init_func(pool->attr.init_priv,
-                                       base + (pool->attr.stride * cpu),
-                                       pool->attr.stride, cpu)) {
+                                       base, pool->attr.stride, -1)) {
                                goto error_alloc;
                        }
+                       break;
+               case MEMPOOL_TYPE_PERCPU:
+               {
+                       int cpu;
+                       for (cpu = 0; cpu < pool->attr.max_nr_cpus; cpu++) {
+                               if (pool->attr.init_func(pool->attr.init_priv,
+                                               base + (pool->attr.stride * cpu),
+                                               pool->attr.stride, cpu)) {
+                                       goto error_alloc;
+                               }
+                       }
+                       break;
+               }
+               default:
+                       abort();
                }
        }
        return range;
This page took 0.02421 seconds and 4 git commands to generate.