ip: Replace Sematics for Interface IP addresses
[vpp.git] / src / svm / ssvm.h
index 9bf009e..6225a63 100644 (file)
@@ -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:
@@ -37,7 +37,7 @@
 #include <vppinfra/heap.h>
 #include <vppinfra/pool.h>
 #include <vppinfra/format.h>
-#include <vppinfra/linux/syscall.h>
+#include <vppinfra/lock.h>
 
 #ifndef MMAP_PAGESIZE
 #define MMAP_PAGESIZE (clib_mem_get_page_size())
@@ -49,6 +49,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;
 
@@ -64,9 +65,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;
@@ -81,10 +82,11 @@ typedef struct
 typedef struct
 {
   ssvm_shared_header_t *sh;
-  u64 ssvm_size;
+  uword ssvm_size;
+  uword requested_va;
   u32 my_pid;
   u8 *name;
-  uword requested_va;
+  u8 numa;                     /**< Numa requested at alloc time */
   int i_am_master;
 
   union
@@ -103,8 +105,8 @@ 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))
+    CLIB_PAUSE ();
 
   h->owner_pid = my_pid;
   h->recursion_count = 1;
@@ -114,8 +116,8 @@ 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))
+    CLIB_PAUSE ();
 
   h->tag = tag;
 }
@@ -127,8 +129,7 @@ ssvm_unlock (ssvm_shared_header_t * h)
     {
       h->owner_pid = 0;
       h->tag = 0;
-      CLIB_MEMORY_BARRIER ();
-      h->lock = 0;
+      clib_atomic_release (&h->lock);
     }
 }
 
@@ -136,8 +137,7 @@ always_inline void
 ssvm_unlock_non_recursive (ssvm_shared_header_t * h)
 {
   h->tag = 0;
-  CLIB_MEMORY_BARRIER ();
-  h->lock = 0;
+  clib_atomic_release (&h->lock);
 }
 
 static inline void *
@@ -195,6 +195,10 @@ 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);