summaryrefslogtreecommitdiffstats
path: root/src/svm
diff options
context:
space:
mode:
Diffstat (limited to 'src/svm')
-rw-r--r--src/svm/svm_fifo_segment.c32
-rw-r--r--src/svm/svm_fifo_segment.h30
-rw-r--r--src/svm/test_svm_fifo1.c28
3 files changed, 49 insertions, 41 deletions
diff --git a/src/svm/svm_fifo_segment.c b/src/svm/svm_fifo_segment.c
index 6cb402f1a6b..c72de406633 100644
--- a/src/svm/svm_fifo_segment.c
+++ b/src/svm/svm_fifo_segment.c
@@ -15,8 +15,6 @@
#include <svm/svm_fifo_segment.h>
-svm_fifo_segment_main_t svm_fifo_segment_main;
-
static void
allocate_new_fifo_chunk (svm_fifo_segment_header_t * fsh,
u32 data_size_in_bytes, int chunk_size)
@@ -203,9 +201,9 @@ svm_fifo_segment_init (svm_fifo_segment_private_t * s)
* Create an svm fifo segment and initialize as master
*/
int
-svm_fifo_segment_create (svm_fifo_segment_create_args_t * a)
+svm_fifo_segment_create (svm_fifo_segment_main_t * sm,
+ svm_fifo_segment_create_args_t * a)
{
- svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
svm_fifo_segment_private_t *s;
int rv;
@@ -237,9 +235,9 @@ svm_fifo_segment_create (svm_fifo_segment_create_args_t * a)
* Create an svm fifo segment in process-private memory
*/
int
-svm_fifo_segment_create_process_private (svm_fifo_segment_create_args_t * a)
+svm_fifo_segment_create_process_private (svm_fifo_segment_main_t * sm,
+ svm_fifo_segment_create_args_t * a)
{
- svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
svm_fifo_segment_private_t *s;
ssvm_shared_header_t *sh;
u32 rnd_size = 0;
@@ -291,9 +289,9 @@ svm_fifo_segment_create_process_private (svm_fifo_segment_create_args_t * a)
* Attach as slave to an svm fifo segment
*/
int
-svm_fifo_segment_attach (svm_fifo_segment_create_args_t * a)
+svm_fifo_segment_attach (svm_fifo_segment_main_t * sm,
+ svm_fifo_segment_create_args_t * a)
{
- svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
svm_fifo_segment_private_t *s;
int rv;
@@ -324,10 +322,9 @@ svm_fifo_segment_attach (svm_fifo_segment_create_args_t * a)
}
void
-svm_fifo_segment_delete (svm_fifo_segment_private_t * s)
+svm_fifo_segment_delete (svm_fifo_segment_main_t * sm,
+ svm_fifo_segment_private_t * s)
{
- svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
-
ssvm_delete (&s->ssvm);
clib_memset (s, 0xfe, sizeof (*s));
pool_put (sm->segments, s);
@@ -495,27 +492,26 @@ svm_fifo_segment_free_fifo (svm_fifo_segment_private_t * s, svm_fifo_t * f,
}
void
-svm_fifo_segment_main_init (u64 baseva, u32 timeout_in_seconds)
+svm_fifo_segment_main_init (svm_fifo_segment_main_t * sm, u64 baseva,
+ u32 timeout_in_seconds)
{
- svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
-
sm->next_baseva = baseva;
sm->timeout_in_seconds = timeout_in_seconds;
}
u32
-svm_fifo_segment_index (svm_fifo_segment_private_t * s)
+svm_fifo_segment_index (svm_fifo_segment_main_t * sm,
+ svm_fifo_segment_private_t * s)
{
- return s - svm_fifo_segment_main.segments;
+ return s - sm->segments;
}
/**
* Retrieve svm segments pool. Used only for debug purposes.
*/
svm_fifo_segment_private_t *
-svm_fifo_segment_segments_pool (void)
+svm_fifo_segment_segments_pool (svm_fifo_segment_main_t * sm)
{
- svm_fifo_segment_main_t *sm = &svm_fifo_segment_main;
return sm->segments;
}
diff --git a/src/svm/svm_fifo_segment.h b/src/svm/svm_fifo_segment.h
index cbc327e8e9b..a7695549d1c 100644
--- a/src/svm/svm_fifo_segment.h
+++ b/src/svm/svm_fifo_segment.h
@@ -59,8 +59,6 @@ typedef struct
u32 timeout_in_seconds;
} svm_fifo_segment_main_t;
-extern svm_fifo_segment_main_t svm_fifo_segment_main;
-
typedef struct
{
ssvm_segment_type_t segment_type;
@@ -73,10 +71,9 @@ typedef struct
#define svm_fifo_segment_flags(_seg) _seg->h->flags
static inline svm_fifo_segment_private_t *
-svm_fifo_segment_get_segment (u32 segment_index)
+svm_fifo_segment_get_segment (svm_fifo_segment_main_t * sm, u32 segment_index)
{
- svm_fifo_segment_main_t *ssm = &svm_fifo_segment_main;
- return pool_elt_at_index (ssm->segments, segment_index);
+ return pool_elt_at_index (sm->segments, segment_index);
}
static inline u8
@@ -92,15 +89,19 @@ svm_fifo_segment_get_fifo_list (svm_fifo_segment_private_t * fifo_segment)
}
int svm_fifo_segment_init (svm_fifo_segment_private_t * s);
-int svm_fifo_segment_create (svm_fifo_segment_create_args_t * a);
-int svm_fifo_segment_create_process_private (svm_fifo_segment_create_args_t
- * a);
+int svm_fifo_segment_create (svm_fifo_segment_main_t * sm,
+ svm_fifo_segment_create_args_t * a);
+int svm_fifo_segment_create_process_private (svm_fifo_segment_main_t * sm,
+ svm_fifo_segment_create_args_t
+ *);
void svm_fifo_segment_preallocate_fifo_pairs (svm_fifo_segment_private_t * s,
u32 rx_fifo_size,
u32 tx_fifo_size,
u32 * n_fifo_pairs);
-int svm_fifo_segment_attach (svm_fifo_segment_create_args_t * a);
-void svm_fifo_segment_delete (svm_fifo_segment_private_t * s);
+int svm_fifo_segment_attach (svm_fifo_segment_main_t * sm,
+ svm_fifo_segment_create_args_t * a);
+void svm_fifo_segment_delete (svm_fifo_segment_main_t * sm,
+ svm_fifo_segment_private_t * s);
svm_fifo_t *svm_fifo_segment_alloc_fifo (svm_fifo_segment_private_t * s,
u32 data_size_in_bytes,
@@ -108,15 +109,18 @@ svm_fifo_t *svm_fifo_segment_alloc_fifo (svm_fifo_segment_private_t * s,
void svm_fifo_segment_free_fifo (svm_fifo_segment_private_t * s,
svm_fifo_t * f,
svm_fifo_segment_freelist_t index);
-void svm_fifo_segment_main_init (u64 baseva, u32 timeout_in_seconds);
-u32 svm_fifo_segment_index (svm_fifo_segment_private_t * s);
+void svm_fifo_segment_main_init (svm_fifo_segment_main_t * sm, u64 baseva,
+ u32 timeout_in_seconds);
+u32 svm_fifo_segment_index (svm_fifo_segment_main_t * sm,
+ svm_fifo_segment_private_t * s);
u32 svm_fifo_segment_num_fifos (svm_fifo_segment_private_t * fifo_segment);
u32 svm_fifo_segment_num_free_fifos (svm_fifo_segment_private_t *
fifo_segment, u32 fifo_size_in_bytes);
void svm_fifo_segment_info (svm_fifo_segment_private_t * seg, uword * address,
u64 * size);
-svm_fifo_segment_private_t *svm_fifo_segment_segments_pool (void);
+svm_fifo_segment_private_t
+ * svm_fifo_segment_segments_pool (svm_fifo_segment_main_t * sm);
format_function_t format_svm_fifo_segment;
format_function_t format_svm_fifo_segment_type;
diff --git a/src/svm/test_svm_fifo1.c b/src/svm/test_svm_fifo1.c
index 243f8b61673..0a09916f3bf 100644
--- a/src/svm/test_svm_fifo1.c
+++ b/src/svm/test_svm_fifo1.c
@@ -15,10 +15,13 @@
#include "svm_fifo_segment.h"
+svm_fifo_segment_main_t segment_main;
+
clib_error_t *
hello_world (int verbose)
{
svm_fifo_segment_create_args_t _a, *a = &_a;
+ svm_fifo_segment_main_t *sm = &segment_main;
svm_fifo_segment_private_t *sp;
svm_fifo_t *f;
int rv;
@@ -31,12 +34,12 @@ hello_world (int verbose)
a->segment_name = "fifo-test1";
a->segment_size = 256 << 10;
- rv = svm_fifo_segment_create (a);
+ rv = svm_fifo_segment_create (sm, a);
if (rv)
return clib_error_return (0, "svm_fifo_segment_create returned %d", rv);
- sp = svm_fifo_segment_get_segment (a->new_segment_indices[0]);
+ sp = svm_fifo_segment_get_segment (sm, a->new_segment_indices[0]);
f = svm_fifo_segment_alloc_fifo (sp, 4096, FIFO_SEGMENT_RX_FREELIST);
@@ -72,6 +75,7 @@ clib_error_t *
master (int verbose)
{
svm_fifo_segment_create_args_t _a, *a = &_a;
+ svm_fifo_segment_main_t *sm = &segment_main;
svm_fifo_segment_private_t *sp;
svm_fifo_t *f;
int rv;
@@ -84,12 +88,12 @@ master (int verbose)
a->segment_name = "fifo-test1";
a->segment_size = 256 << 10;
- rv = svm_fifo_segment_create (a);
+ rv = svm_fifo_segment_create (sm, a);
if (rv)
return clib_error_return (0, "svm_fifo_segment_create returned %d", rv);
- sp = svm_fifo_segment_get_segment (a->new_segment_indices[0]);
+ sp = svm_fifo_segment_get_segment (sm, a->new_segment_indices[0]);
f = svm_fifo_segment_alloc_fifo (sp, 4096, FIFO_SEGMENT_RX_FREELIST);
@@ -109,6 +113,7 @@ clib_error_t *
mempig (int verbose)
{
svm_fifo_segment_create_args_t _a, *a = &_a;
+ svm_fifo_segment_main_t *sm = &segment_main;
svm_fifo_segment_private_t *sp;
svm_fifo_t *f;
svm_fifo_t **flist = 0;
@@ -120,12 +125,12 @@ mempig (int verbose)
a->segment_name = "fifo-test1";
a->segment_size = 256 << 10;
- rv = svm_fifo_segment_create (a);
+ rv = svm_fifo_segment_create (sm, a);
if (rv)
return clib_error_return (0, "svm_fifo_segment_create returned %d", rv);
- sp = svm_fifo_segment_get_segment (a->new_segment_indices[0]);
+ sp = svm_fifo_segment_get_segment (sm, a->new_segment_indices[0]);
for (i = 0; i < 1000; i++)
{
@@ -166,6 +171,7 @@ clib_error_t *
offset (int verbose)
{
svm_fifo_segment_create_args_t _a, *a = &_a;
+ svm_fifo_segment_main_t *sm = &segment_main;
svm_fifo_segment_private_t *sp;
svm_fifo_t *f;
int rv;
@@ -178,12 +184,12 @@ offset (int verbose)
a->segment_name = "fifo-test1";
a->segment_size = 256 << 10;
- rv = svm_fifo_segment_create (a);
+ rv = svm_fifo_segment_create (sm, a);
if (rv)
return clib_error_return (0, "svm_fifo_segment_create returned %d", rv);
- sp = svm_fifo_segment_get_segment (a->new_segment_indices[0]);
+ sp = svm_fifo_segment_get_segment (sm, a->new_segment_indices[0]);
f = svm_fifo_segment_alloc_fifo (sp, 200 << 10, FIFO_SEGMENT_RX_FREELIST);
@@ -225,6 +231,7 @@ clib_error_t *
slave (int verbose)
{
svm_fifo_segment_create_args_t _a, *a = &_a;
+ svm_fifo_segment_main_t *sm = &segment_main;
svm_fifo_segment_private_t *sp;
svm_fifo_t *f;
ssvm_shared_header_t *sh;
@@ -243,7 +250,7 @@ slave (int verbose)
if (rv)
return clib_error_return (0, "svm_fifo_segment_attach returned %d", rv);
- sp = svm_fifo_segment_get_segment (a->new_segment_indices[0]);
+ sp = svm_fifo_segment_get_segment (sm, a->new_segment_indices[0]);
sh = sp->ssvm.sh;
fsh = (svm_fifo_segment_header_t *) sh->opaque[0];
@@ -269,11 +276,12 @@ slave (int verbose)
int
test_ssvm_fifo1 (unformat_input_t * input)
{
+ svm_fifo_segment_main_t *sm = &segment_main;
clib_error_t *error = 0;
int verbose = 0;
int test_id = 0;
- svm_fifo_segment_main_init (0x200000000ULL, 20);
+ svm_fifo_segment_main_init (sm, 0x200000000ULL, 20);
while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
{