X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fsvm%2Fssvm.h;h=1c0373f126c3cdea6479152c695a2c09130c7d8f;hb=c5df8c71c;hp=8466e15579b590dedfc01cb271e25fd011949278;hpb=2c25a62cc1cc4937165de740a3b32d78429c72d6;p=vpp.git diff --git a/src/svm/ssvm.h b/src/svm/ssvm.h index 8466e15579b..1c0373f126c 100644 --- a/src/svm/ssvm.h +++ b/src/svm/ssvm.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Cisco and/or its affiliates. + * Copyright (c) 2015-2019 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: @@ -44,6 +44,14 @@ #define SSVM_N_OPAQUE 7 +typedef enum ssvm_segment_type_ +{ + SSVM_SEGMENT_SHM = 0, + SSVM_SEGMENT_MEMFD, + SSVM_SEGMENT_PRIVATE, + SSVM_N_SEGMENT_TYPES /**< Private segments */ +} ssvm_segment_type_t; + typedef struct { /* Spin-lock */ @@ -56,9 +64,9 @@ typedef struct void *heap; /* Segment must be mapped at this address, or no supper */ - u64 ssvm_va; + uword ssvm_va; /* The actual mmap size */ - u64 ssvm_size; + uword ssvm_size; u32 master_pid; u32 slave_pid; u8 *name; @@ -67,8 +75,7 @@ typedef struct /* Set when the master application thinks it's time to make the donuts */ volatile u32 ready; - /* Needed to make unique MAC addresses, etc. */ - u32 master_index; + ssvm_segment_type_t type; } ssvm_shared_header_t; typedef struct @@ -76,12 +83,15 @@ typedef struct ssvm_shared_header_t *sh; u64 ssvm_size; u32 my_pid; - u32 vlib_hw_if_index; u8 *name; uword requested_va; int i_am_master; - u32 per_interface_next_index; - u32 *rx_queue; + + union + { + int fd; /**< memfd segments */ + int attach_timeout; /**< shm segments attach timeout (sec) */ + }; } ssvm_private_t; always_inline void @@ -93,7 +103,7 @@ ssvm_lock (ssvm_shared_header_t * h, u32 my_pid, u32 tag) return; } - while (__sync_lock_test_and_set (&h->lock, 1)) + while (clib_atomic_test_and_set (&h->lock)) ; h->owner_pid = my_pid; @@ -104,7 +114,7 @@ ssvm_lock (ssvm_shared_header_t * h, u32 my_pid, u32 tag) always_inline void ssvm_lock_non_recursive (ssvm_shared_header_t * h, u32 tag) { - while (__sync_lock_test_and_set (&h->lock, 1)) + while (clib_atomic_test_and_set (&h->lock)) ; h->tag = tag; @@ -144,6 +154,18 @@ ssvm_pop_heap (void *oldheap) clib_mem_set_heap (oldheap); } +static inline void * +ssvm_mem_alloc (ssvm_private_t * ssvm, uword size) +{ + u8 *oldheap; + void *rv; + + oldheap = clib_mem_set_heap (ssvm->sh->heap); + rv = clib_mem_alloc (size); + clib_mem_set_heap (oldheap); + return (rv); +} + #define foreach_ssvm_api_error \ _(NO_NAME, "No shared segment name", -100) \ _(NO_SIZE, "Size not set (master)", -101) \ @@ -161,10 +183,25 @@ typedef enum #define SSVM_API_ERROR_NO_NAME (-10) -int ssvm_master_init (ssvm_private_t * ssvm, u32 master_index); -int ssvm_slave_init (ssvm_private_t * ssvm, int timeout_in_seconds); +int ssvm_master_init (ssvm_private_t * ssvm, ssvm_segment_type_t type); +int ssvm_slave_init (ssvm_private_t * ssvm, ssvm_segment_type_t type); void ssvm_delete (ssvm_private_t * ssvm); +int ssvm_master_init_shm (ssvm_private_t * ssvm); +int ssvm_slave_init_shm (ssvm_private_t * ssvm); +void ssvm_delete_shm (ssvm_private_t * ssvm); + +int ssvm_master_init_memfd (ssvm_private_t * memfd); +int ssvm_slave_init_memfd (ssvm_private_t * memfd); +void ssvm_delete_memfd (ssvm_private_t * memfd); + +int ssvm_master_init_private (ssvm_private_t * ssvm); +int ssvm_slave_init_private (ssvm_private_t * ssvm); +void ssvm_delete_private (ssvm_private_t * ssvm); + +ssvm_segment_type_t ssvm_type (const ssvm_private_t * ssvm); +u8 *ssvm_name (const ssvm_private_t * ssvm); + #endif /* __included_ssvm_h__ */ /*