fd-io-styleify for svm

Change-Id: I816de8b1f255dc3bc6d2904566ea0b0f68fac5d8
Signed-off-by: Dave Barach <dave@barachs.net>
This commit is contained in:
Dave Barach
2016-07-08 14:44:23 -04:00
parent 49a6963b13
commit 8a7fb0cf68
11 changed files with 2507 additions and 2108 deletions

View File

@ -1,15 +1,5 @@
#!/usr/bin/emacs --script
(fset 'fix-foreach
[?\C-u ?\C-s ?_ ?f ?o ?r ?e ?a ?c ?h ? ?* ?\( ?\C-a ?\C-o tab ?/ ?* ? ?* ?I ?N ?D ?E ?N ?T ?- ?O ?F ?F ?* ? ?* ?/ ?\C-u ?\C-s ?\C-s ?\C-b escape ?\C-f ?\C-e ?\C-j ?/ ?* ? ?* ?I ?N ?D ?E ?N ?T ?- ?O ?N ?* ? ?* ?/])
(fset 'fix-cli-command
[?\C-s ?C ?L ?I ?_ ?C ?O ?M ?M ?A ?N ?D ?\C-a ?\C-o ?/ ?* ? ?* ?I ?N ?D ?E ?N ?T ?- ?O ?F ?F ?* ? ?* ?/ ?\C-s ?\} ?\C-e ?\C-j ?/ ?* ? ?I ?N ?D ?E ?N backspace backspace backspace backspace backspace ?* ?I ?N ?D ?E ?N ?T ?- ?O ?N ?* ? ?* ?/])
(fset 'fix-node
[?\C-s ?R ?E ?G ?I ?S ?T ?E ?R ?_ ?N ?O ?D ?E ?\C-a ?\C-o ?/ ?* ? ?* ?I ?N ?D ?E ?N ?T ?- ?O ?F ?F ?* ? ?* ?/ ?\C-a ?\C-n ?\C-s ?\{ ?\C-b escape ?\C-f ?\C-e ?\C-j ?/ ?* ?\S- ?* ?I ?N ?D ?E ?N ?T ?- ?O ?N ?* ? ?* ?/])
(fset 'fix-elog-type
[?\C-s ?E ?L ?O ?G ?_ ?T ?Y ?P ?E ?_ ?D ?E ?C ?L ?A ?R ?E ?\C-a ?\C-o tab ?/ ?* ? ?* ?I ?N ?D ?E ?N ?T ?- ?O ?F ?F ?* ? ?* ?/ ?\C-a ?\C-n ?\C-n tab escape ?\C-f ?\C-e ?\C-j tab ?/ ?* ? ?* ?I ?N ?D ?E ?N ?T ?- ?O ?N ?* ? ?* ?/ ?\C-a ?\C-n])
;; insert style boilerplate
(defun insert-style-boilerplate () (interactive)
(save-excursion (goto-char (point-max))
@ -22,24 +12,64 @@
* End:
*/")))
;;
(defun fix-foreach () (interactive)
(save-excursion (goto-char (point-min))
(while (search-forward-regexp
"[pool|hash|clib_fifo|clib_bitmap]_foreach"
(point-max) t)
(move-beginning-of-line nil)
(open-line 1)
(c-indent-line-or-region)
(insert "/* *INDENT-OFF* */")
(search-forward "{")
(backward-char)
(forward-sexp)
(move-end-of-line nil)
(newline 1)
(c-indent-line-or-region)
(insert "/* *INDENT-ON* */"))))
(defun fix-initializer (what) (interactive)
(save-excursion
(goto-char (point-min))
(while (search-forward-regexp what (point-max) t)
(move-beginning-of-line nil)
(open-line 1)
(c-indent-line-or-region)
(insert "/* *INDENT-OFF* */")
(search-forward "{")
(backward-char)
(forward-sexp)
(move-end-of-line nil)
(newline 1)
(c-indent-line-or-region)
(insert "/* *INDENT-ON* */"))))
(defun fix-vlib-register-thread () (interactive)
(fix-initializer "VLIB_REGISTER_THREAD *("))
(defun fix-vlib-cli-command () (interactive)
(fix-initializer "VLIB_CLI_COMMAND *("))
(defun fix-vlib-register-node () (interactive)
(fix-initializer "VLIB_REGISTER_NODE *("))
;; Driver routine which runs the set of keyboard macros
;; defined above, as well as the bottom boilerplate lisp fn.
(defun fd-io-styleify () (interactive)
(save-excursion (goto-char (point-min))
(ignore-errors (execute-kbd-macro 'fix-foreach 0)))
(save-excursion (goto-char (point-min))
(ignore-errors (execute-kbd-macro 'fix-cli-command 0)))
(save-excursion (goto-char (point-min))
(ignore-errors (execute-kbd-macro 'fix-node 0)))
(save-excursion (goto-char (point-min))
(ignore-errors (execute-kbd-macro 'fix-elog-type 0)))
(fix-foreach)
(fix-vlib-register-thread)
(fix-vlib-cli-command)
(fix-vlib-register-node)
(insert-style-boilerplate))
;;(setq index 0)
;;(while (elt argv index)
;; (message "Processing argv %d is %s" index (elt argv index))
;; (find-file (elt argv index))
;; (fd-io-styleify)
;; (setq index (1+ index)))
;; (save-buffers-kill-emacs)
(setq index 0)
(while (elt argv index)
(message "Processing %s..." (elt argv index))
(find-file (elt argv index))
(fd-io-styleify)
(setq index (1+ index)))
(save-buffers-kill-emacs t)

File diff suppressed because it is too large Load Diff

View File

@ -14,16 +14,17 @@
*/
#include "ssvm.h"
int ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
int
ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
{
int ssvm_fd;
u8 * ssvm_filename;
u8 *ssvm_filename;
u8 junk = 0;
int flags;
ssvm_shared_header_t * sh;
u64 ticks = clib_cpu_time_now();
ssvm_shared_header_t *sh;
u64 ticks = clib_cpu_time_now ();
u64 randomize_baseva;
void * oldheap;
void *oldheap;
if (ssvm->ssvm_size == 0)
return SSVM_API_ERROR_NO_SIZE;
@ -32,9 +33,9 @@ int ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
unlink ((char *) ssvm_filename);
vec_free(ssvm_filename);
vec_free (ssvm_filename);
ssvm_fd = shm_open((char *) ssvm->name, O_RDWR | O_CREAT | O_EXCL, 0777);
ssvm_fd = shm_open ((char *) ssvm->name, O_RDWR | O_CREAT | O_EXCL, 0777);
if (ssvm_fd < 0)
{
@ -42,14 +43,14 @@ int ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
return SSVM_API_ERROR_CREATE_FAILURE;
}
lseek(ssvm_fd, ssvm->ssvm_size, SEEK_SET);
if (write(ssvm_fd, &junk, 1) != 1)
lseek (ssvm_fd, ssvm->ssvm_size, SEEK_SET);
if (write (ssvm_fd, &junk, 1) != 1)
{
clib_unix_warning ("set ssvm size");
close(ssvm_fd);
close (ssvm_fd);
return SSVM_API_ERROR_SET_SIZE;
}
flags = MAP_SHARED;
if (ssvm->requested_va)
flags |= MAP_FIXED;
@ -58,27 +59,29 @@ int ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
if (ssvm->requested_va)
ssvm->requested_va += randomize_baseva;
sh = ssvm->sh = (ssvm_shared_header_t *) mmap((void *)ssvm->requested_va, ssvm->ssvm_size,
PROT_READ | PROT_WRITE, flags, ssvm_fd, 0);
sh = ssvm->sh =
(ssvm_shared_header_t *) mmap ((void *) ssvm->requested_va,
ssvm->ssvm_size, PROT_READ | PROT_WRITE,
flags, ssvm_fd, 0);
if (ssvm->sh == MAP_FAILED)
{
clib_unix_warning ("mmap");
close(ssvm_fd);
close (ssvm_fd);
return SSVM_API_ERROR_MMAP;
}
close(ssvm_fd);
close (ssvm_fd);
ssvm->my_pid = getpid();
ssvm->my_pid = getpid ();
sh->master_pid = ssvm->my_pid;
sh->ssvm_size = ssvm->ssvm_size;
sh->heap = mheap_alloc_with_flags
(((u8 *)sh) + MMAP_PAGESIZE, ssvm->ssvm_size - MMAP_PAGESIZE,
sh->heap = mheap_alloc_with_flags
(((u8 *) sh) + MMAP_PAGESIZE, ssvm->ssvm_size - MMAP_PAGESIZE,
MHEAP_FLAG_DISABLE_VM | MHEAP_FLAG_THREAD_SAFE);
sh->ssvm_va = pointer_to_uword(sh);
sh->ssvm_va = pointer_to_uword (sh);
sh->master_index = master_index;
oldheap = ssvm_push_heap (sh);
@ -91,71 +94,79 @@ int ssvm_master_init (ssvm_private_t * ssvm, u32 master_index)
return 0;
}
int ssvm_slave_init (ssvm_private_t * ssvm, int timeout_in_seconds)
int
ssvm_slave_init (ssvm_private_t * ssvm, int timeout_in_seconds)
{
struct stat stat;
int ssvm_fd = -1;
ssvm_shared_header_t * sh;
struct stat stat;
int ssvm_fd = -1;
ssvm_shared_header_t *sh;
ssvm->i_am_master = 0;
ssvm->i_am_master = 0;
while (timeout_in_seconds-- > 0)
{
if (ssvm_fd < 0)
ssvm_fd = shm_open((char *)ssvm->name, O_RDWR, 0777);
if (ssvm_fd < 0)
{
sleep (1);
continue;
}
if (fstat(ssvm_fd, &stat) < 0)
{
sleep (1);
continue;
}
if (stat.st_size > 0)
goto map_it;
}
clib_warning ("slave timeout");
return SSVM_API_ERROR_SLAVE_TIMEOUT;
map_it:
sh = (void *) mmap (0, MMAP_PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
ssvm_fd, 0);
if (sh == MAP_FAILED)
{
clib_unix_warning ("slave research mmap");
close (ssvm_fd);
return SSVM_API_ERROR_MMAP;
}
while (timeout_in_seconds-- > 0)
{
if (sh->ready)
goto re_map_it;
}
close (ssvm_fd);
munmap (sh, MMAP_PAGESIZE);
clib_warning ("slave timeout 2");
return SSVM_API_ERROR_SLAVE_TIMEOUT;
re_map_it:
ssvm->requested_va = (u64) sh->ssvm_va;
ssvm->ssvm_size = sh->ssvm_size;
munmap (sh, MMAP_PAGESIZE);
while (timeout_in_seconds-- > 0)
{
if (ssvm_fd < 0)
ssvm_fd = shm_open ((char *) ssvm->name, O_RDWR, 0777);
if (ssvm_fd < 0)
{
sleep (1);
continue;
}
if (fstat (ssvm_fd, &stat) < 0)
{
sleep (1);
continue;
}
sh = ssvm->sh = (void *) mmap((void *)ssvm->requested_va, ssvm->ssvm_size,
PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_FIXED,
ssvm_fd, 0);
if (sh == MAP_FAILED)
{
clib_unix_warning ("slave final mmap");
close (ssvm_fd);
return SSVM_API_ERROR_MMAP;
}
sh->slave_pid = getpid();
return 0;
if (stat.st_size > 0)
goto map_it;
}
clib_warning ("slave timeout");
return SSVM_API_ERROR_SLAVE_TIMEOUT;
map_it:
sh = (void *) mmap (0, MMAP_PAGESIZE, PROT_READ | PROT_WRITE, MAP_SHARED,
ssvm_fd, 0);
if (sh == MAP_FAILED)
{
clib_unix_warning ("slave research mmap");
close (ssvm_fd);
return SSVM_API_ERROR_MMAP;
}
while (timeout_in_seconds-- > 0)
{
if (sh->ready)
goto re_map_it;
}
close (ssvm_fd);
munmap (sh, MMAP_PAGESIZE);
clib_warning ("slave timeout 2");
return SSVM_API_ERROR_SLAVE_TIMEOUT;
re_map_it:
ssvm->requested_va = (u64) sh->ssvm_va;
ssvm->ssvm_size = sh->ssvm_size;
munmap (sh, MMAP_PAGESIZE);
sh = ssvm->sh = (void *) mmap ((void *) ssvm->requested_va, ssvm->ssvm_size,
PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_FIXED, ssvm_fd, 0);
if (sh == MAP_FAILED)
{
clib_unix_warning ("slave final mmap");
close (ssvm_fd);
return SSVM_API_ERROR_MMAP;
}
sh->slave_pid = getpid ();
return 0;
}
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -41,15 +41,16 @@
#define MMAP_PAGESIZE (4<<10)
#define SSVM_N_OPAQUE 7
typedef struct {
typedef struct
{
/* Spin-lock */
volatile u32 lock;
volatile u32 owner_pid;
int recursion_count;
u32 tag; /* for debugging */
u32 tag; /* for debugging */
/* The allocation arena */
void * heap;
void *heap;
/* Segment must be mapped at this address, or no supper */
u64 ssvm_va;
@ -57,8 +58,8 @@ typedef struct {
u64 ssvm_size;
u32 master_pid;
u32 slave_pid;
u8 * name;
void * opaque [SSVM_N_OPAQUE];
u8 *name;
void *opaque[SSVM_N_OPAQUE];
/* Set when the master application thinks it's time to make the donuts */
volatile u32 ready;
@ -67,55 +68,60 @@ typedef struct {
u32 master_index;
} ssvm_shared_header_t;
typedef struct {
ssvm_shared_header_t * sh;
typedef struct
{
ssvm_shared_header_t *sh;
u64 ssvm_size;
u32 my_pid;
u32 vlib_hw_if_index;
u8 * name;
u8 *name;
uword requested_va;
int i_am_master;
u32 per_interface_next_index;
u32 * rx_queue;
u32 *rx_queue;
} ssvm_private_t;
always_inline void ssvm_lock (ssvm_shared_header_t * h, u32 my_pid, u32 tag)
always_inline void
ssvm_lock (ssvm_shared_header_t * h, u32 my_pid, u32 tag)
{
if (h->owner_pid == my_pid)
{
h->recursion_count++;
return;
}
while (__sync_lock_test_and_set (&h->lock, 1))
;
h->owner_pid = my_pid;
h->recursion_count = 1;
h->tag = tag;
}
always_inline void ssvm_unlock (ssvm_shared_header_t * h)
always_inline void
ssvm_unlock (ssvm_shared_header_t * h)
{
if (--h->recursion_count == 0)
{
h->owner_pid = 0;
h->tag = 0;
CLIB_MEMORY_BARRIER();
CLIB_MEMORY_BARRIER ();
h->lock = 0;
}
}
static inline void *ssvm_push_heap (ssvm_shared_header_t *sh)
static inline void *
ssvm_push_heap (ssvm_shared_header_t * sh)
{
u8 *oldheap;
oldheap = clib_mem_set_heap(sh->heap);
return ((void *) oldheap);
u8 *oldheap;
oldheap = clib_mem_set_heap (sh->heap);
return ((void *) oldheap);
}
static inline void ssvm_pop_heap (void *oldheap)
static inline void
ssvm_pop_heap (void *oldheap)
{
clib_mem_set_heap(oldheap);
clib_mem_set_heap (oldheap);
}
#define foreach_ssvm_api_error \
@ -126,7 +132,8 @@ _(SET_SIZE, "Set size failed", -13) \
_(MMAP, "mmap failed", -14) \
_(SLAVE_TIMEOUT, "Slave map timeout", -15)
typedef enum {
typedef enum
{
#define _(n,s,c) SSVM_API_ERROR_##n = c,
foreach_ssvm_api_error
#undef _
@ -138,3 +145,11 @@ int ssvm_master_init (ssvm_private_t * ssvm, u32 master_index);
int ssvm_slave_init (ssvm_private_t * ssvm, int timeout_in_seconds);
#endif /* __included_ssvm_h__ */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

1680
svm/svm.c

File diff suppressed because it is too large Load Diff

226
svm/svm.h
View File

@ -1,6 +1,6 @@
/*
/*
*------------------------------------------------------------------
* svm.h - shared VM allocation, mmap(...MAP_FIXED...)
* svm.h - shared VM allocation, mmap(...MAP_FIXED...)
* brain police
*
* Copyright (c) 2009 Cisco and/or its affiliates.
@ -27,162 +27,178 @@
#define MMAP_PAGESIZE (clib_mem_get_page_size())
#define SVM_VERSION ((1<<16) | 1) /* set to declare region ready. */
#define SVM_VERSION ((1<<16) | 1) /* set to declare region ready. */
#define SVM_FLAGS_MHEAP (1<<0) /* region contains an mheap */
#define SVM_FLAGS_FILE (1<<1) /* region backed by one or more files */
#define SVM_FLAGS_NODATA (1<<2) /* region will be further subdivided */
#define SVM_FLAGS_NEED_DATA_INIT (1<<3)
#define SVM_FLAGS_MHEAP (1<<0) /* region contains an mheap */
#define SVM_FLAGS_FILE (1<<1) /* region backed by one or more files */
#define SVM_FLAGS_NODATA (1<<2) /* region will be further subdivided */
#define SVM_FLAGS_NEED_DATA_INIT (1<<3)
#define SVM_PVT_MHEAP_SIZE (128<<10) /* region's private mheap (128k) */
#define SVM_PVT_MHEAP_SIZE (128<<10) /* region's private mheap (128k) */
typedef struct svm_region_ {
volatile uword version;
pthread_mutex_t mutex;
pthread_cond_t condvar;
int mutex_owner_pid; /* in case of trouble */
int mutex_owner_tag;
uword flags;
uword virtual_base; /* base of the region object */
uword virtual_size;
void *region_heap;
void *data_base; /* data portion base address */
void *data_heap; /* data heap, if any */
volatile void *user_ctx; /* user context pointer */
/* stuff allocated in the region's heap */
uword bitmap_size; /* nbits in virtual alloc bitmap */
uword *bitmap; /* the bitmap */
char *region_name;
char *backing_file;
char **filenames;
uword *client_pids;
/* pad */
typedef struct svm_region_
{
volatile uword version;
pthread_mutex_t mutex;
pthread_cond_t condvar;
int mutex_owner_pid; /* in case of trouble */
int mutex_owner_tag;
uword flags;
uword virtual_base; /* base of the region object */
uword virtual_size;
void *region_heap;
void *data_base; /* data portion base address */
void *data_heap; /* data heap, if any */
volatile void *user_ctx; /* user context pointer */
/* stuff allocated in the region's heap */
uword bitmap_size; /* nbits in virtual alloc bitmap */
uword *bitmap; /* the bitmap */
char *region_name;
char *backing_file;
char **filenames;
uword *client_pids;
/* pad */
/* next page:
* (64K) clib heap for the region itself
*
* data_base -> whatever is in this region
*/
/* next page:
* (64K) clib heap for the region itself
*
* data_base -> whatever is in this region
*/
} svm_region_t;
typedef struct svm_map_region_args_ {
char *root_path; /* NULL means use the truly global arena */
char *name;
uword baseva;
uword size;
uword flags;
char *backing_file;
uword backing_mmap_size;
/* uid, gid to own the svm region(s) */
int uid;
int gid;
typedef struct svm_map_region_args_
{
char *root_path; /* NULL means use the truly global arena */
char *name;
uword baseva;
uword size;
uword flags;
char *backing_file;
uword backing_mmap_size;
/* uid, gid to own the svm region(s) */
int uid;
int gid;
} svm_map_region_args_t;
/*
* Memory shared across all router instances. Packet buffers, etc
* Base should be "out of the way," and size should be big enough to
* Memory shared across all router instances. Packet buffers, etc
* Base should be "out of the way," and size should be big enough to
* cover everything we plan to put here.
*/
#define SVM_GLOBAL_REGION_BASEVA 0x30000000
#define SVM_GLOBAL_REGION_SIZE (64<<20)
#define SVM_GLOBAL_REGION_SIZE (64<<20)
#define SVM_GLOBAL_REGION_NAME "/global_vm"
/*
* Memory shared across individual router instances.
* Memory shared across individual router instances.
*/
#define SVM_OVERLAY_REGION_BASEVA \
(SVM_GLOBAL_REGION_BASEVA + SVM_GLOBAL_REGION_SIZE)
#define SVM_OVERLAY_REGION_SIZE (1<<20)
#define SVM_OVERLAY_REGION_SIZE (1<<20)
#define SVM_OVERLAY_REGION_BASENAME "/overlay_vm"
typedef struct {
u8 *subregion_name;
typedef struct
{
u8 *subregion_name;
} svm_subregion_t;
typedef struct {
svm_subregion_t *subregions; /* subregion pool */
uword *name_hash;
u8 *root_path;
typedef struct
{
svm_subregion_t *subregions; /* subregion pool */
uword *name_hash;
u8 *root_path;
} svm_main_region_t;
void *svm_region_find_or_create (svm_map_region_args_t *a);
void svm_region_init(void);
void svm_region_init_chroot(char *root_path);
void svm_region_init_chroot_uid_gid(char *root_path, int uid, int gid);
void *svm_region_find_or_create (svm_map_region_args_t * a);
void svm_region_init (void);
void svm_region_init_chroot (char *root_path);
void svm_region_init_chroot_uid_gid (char *root_path, int uid, int gid);
void svm_region_exit (void);
void svm_region_unmap(void *rp_arg);
void svm_region_unmap (void *rp_arg);
void svm_client_scan (char *root_path);
void svm_client_scan_this_region_nolock (svm_region_t *rp);
u8 *shm_name_from_svm_map_region_args (svm_map_region_args_t *a);
void svm_client_scan_this_region_nolock (svm_region_t * rp);
u8 *shm_name_from_svm_map_region_args (svm_map_region_args_t * a);
static inline void *svm_mem_alloc (svm_region_t *rp, uword size)
static inline void *
svm_mem_alloc (svm_region_t * rp, uword size)
{
u8 *oldheap;
ASSERT(rp->flags & SVM_FLAGS_MHEAP);
u8 *rv;
u8 *oldheap;
ASSERT (rp->flags & SVM_FLAGS_MHEAP);
u8 *rv;
pthread_mutex_lock(&rp->mutex);
oldheap = clib_mem_set_heap(rp->data_heap);
rv = clib_mem_alloc (size);
clib_mem_set_heap(oldheap);
pthread_mutex_unlock(&rp->mutex);
return (rv);
pthread_mutex_lock (&rp->mutex);
oldheap = clib_mem_set_heap (rp->data_heap);
rv = clib_mem_alloc (size);
clib_mem_set_heap (oldheap);
pthread_mutex_unlock (&rp->mutex);
return (rv);
}
static inline void *svm_mem_alloc_aligned_at_offset (svm_region_t *rp,
uword size,
uword align,
uword offset)
static inline void *
svm_mem_alloc_aligned_at_offset (svm_region_t * rp,
uword size, uword align, uword offset)
{
u8 *oldheap;
ASSERT(rp->flags & SVM_FLAGS_MHEAP);
u8 *rv;
u8 *oldheap;
ASSERT (rp->flags & SVM_FLAGS_MHEAP);
u8 *rv;
pthread_mutex_lock(&rp->mutex);
oldheap = clib_mem_set_heap(rp->data_heap);
rv = clib_mem_alloc_aligned_at_offset (size, align, offset);
clib_mem_set_heap(oldheap);
pthread_mutex_unlock(&rp->mutex);
return (rv);
pthread_mutex_lock (&rp->mutex);
oldheap = clib_mem_set_heap (rp->data_heap);
rv = clib_mem_alloc_aligned_at_offset (size, align, offset);
clib_mem_set_heap (oldheap);
pthread_mutex_unlock (&rp->mutex);
return (rv);
}
static inline void svm_mem_free (svm_region_t *rp, void *ptr)
static inline void
svm_mem_free (svm_region_t * rp, void *ptr)
{
u8 *oldheap;
ASSERT(rp->flags & SVM_FLAGS_MHEAP);
u8 *oldheap;
ASSERT (rp->flags & SVM_FLAGS_MHEAP);
pthread_mutex_lock(&rp->mutex);
oldheap = clib_mem_set_heap(rp->data_heap);
clib_mem_free (ptr);
clib_mem_set_heap(oldheap);
pthread_mutex_unlock(&rp->mutex);
pthread_mutex_lock (&rp->mutex);
oldheap = clib_mem_set_heap (rp->data_heap);
clib_mem_free (ptr);
clib_mem_set_heap (oldheap);
pthread_mutex_unlock (&rp->mutex);
}
static inline void *svm_push_pvt_heap (svm_region_t *rp)
static inline void *
svm_push_pvt_heap (svm_region_t * rp)
{
u8 *oldheap;
oldheap = clib_mem_set_heap(rp->region_heap);
return ((void *) oldheap);
u8 *oldheap;
oldheap = clib_mem_set_heap (rp->region_heap);
return ((void *) oldheap);
}
static inline void *svm_push_data_heap (svm_region_t *rp)
static inline void *
svm_push_data_heap (svm_region_t * rp)
{
u8 *oldheap;
oldheap = clib_mem_set_heap(rp->data_heap);
return ((void *) oldheap);
u8 *oldheap;
oldheap = clib_mem_set_heap (rp->data_heap);
return ((void *) oldheap);
}
static inline void svm_pop_heap (void *oldheap)
static inline void
svm_pop_heap (void *oldheap)
{
clib_mem_set_heap(oldheap);
clib_mem_set_heap (oldheap);
}
u8 * format_svm_region (u8 * s, va_list * args);
u8 *format_svm_region (u8 * s, va_list * args);
svm_region_t *svm_get_root_rp (void);
#endif /* __included_svm_h__ */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
/*
*------------------------------------------------------------------
* svm_test.c -- brain police
*------------------------------------------------------------------
@ -43,28 +43,37 @@
#include "svm.h"
int main (int argc, char **argv)
int
main (int argc, char **argv)
{
svm_region_t *root_rp, *rp;
svm_map_region_args_t *a = 0;
svm_region_t *root_rp, *rp;
svm_map_region_args_t *a = 0;
vec_validate (a, 0);
vec_validate (a, 0);
root_rp = svm_region_init();
root_rp = svm_region_init ();
ASSERT (root_rp);
ASSERT (root_rp);
a->name = "/qvnet";
a->size = (4<<10);
a->name = "/qvnet";
a->size = (4 << 10);
rp = svm_region_find_or_create (root_rp, a);
rp = svm_region_find_or_create (root_rp, a);
ASSERT (rp);
ASSERT (rp);
*((u32 *)rp->data_base) = 0xdeadbeef;
svm_region_unmap (root_rp, rp);
*((u32 *) rp->data_base) = 0xdeadbeef;
svm_region_unmap (root_rp, rp);
fformat(stdout, "exiting...\n");
fformat (stdout, "exiting...\n");
exit (0);
exit (0);
}
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

File diff suppressed because it is too large Load Diff

View File

@ -1,4 +1,4 @@
/*
/*
*------------------------------------------------------------------
* svmdb.h - shared VM database
*
@ -22,60 +22,67 @@
#include "svm.h"
typedef enum {
SVMDB_ACTION_ILLEGAL=0,
SVMDB_ACTION_GET, /* not clear why anyone would care */
SVMDB_ACTION_SET,
SVMDB_ACTION_UNSET,
typedef enum
{
SVMDB_ACTION_ILLEGAL = 0,
SVMDB_ACTION_GET, /* not clear why anyone would care */
SVMDB_ACTION_SET,
SVMDB_ACTION_UNSET,
} svmdb_action_t;
typedef struct {
int pid;
int signum;
u32 action:4;
u32 opaque:28;
typedef struct
{
int pid;
int signum;
u32 action:4;
u32 opaque:28;
} svmdb_notify_t;
typedef struct {
u8 *value;
svmdb_notify_t *notifications;
u32 elsize;
typedef struct
{
u8 *value;
svmdb_notify_t *notifications;
u32 elsize;
} svmdb_value_t;
typedef enum {
SVMDB_NAMESPACE_STRING=0,
SVMDB_NAMESPACE_VEC,
SVMDB_N_NAMESPACES,
typedef enum
{
SVMDB_NAMESPACE_STRING = 0,
SVMDB_NAMESPACE_VEC,
SVMDB_N_NAMESPACES,
} svmdb_namespace_t;
typedef struct {
uword version;
/* pool of values */
svmdb_value_t *values;
uword *namespaces [SVMDB_N_NAMESPACES];
typedef struct
{
uword version;
/* pool of values */
svmdb_value_t *values;
uword *namespaces[SVMDB_N_NAMESPACES];
} svmdb_shm_hdr_t;
#define SVMDB_SHM_VERSION 2
typedef struct {
int flags;
int pid;
svm_region_t *db_rp;
svmdb_shm_hdr_t *shm;
} svmdb_client_t;
typedef struct
{
int flags;
int pid;
svm_region_t *db_rp;
svmdb_shm_hdr_t *shm;
} svmdb_client_t;
typedef struct {
int add_del;
svmdb_namespace_t nspace;
char *var;
u32 elsize;
int signum;
u32 action:4;
u32 opaque:28;
typedef struct
{
int add_del;
svmdb_namespace_t nspace;
char *var;
u32 elsize;
int signum;
u32 action:4;
u32 opaque:28;
} svmdb_notification_args_t;
/*
* Must be a reasonable number, several mb smaller than
/*
* Must be a reasonable number, several mb smaller than
* SVM_GLOBAL_REGION_SIZE, or no donut for you...
*/
#define SVMDB_DEFAULT_SIZE (4<<20)
@ -88,28 +95,35 @@ svmdb_client_t *svmdb_map_chroot (char *root_path);
svmdb_client_t *svmdb_map_chroot_size (char *root_path, uword size);
void svmdb_unmap (svmdb_client_t *client);
void svmdb_local_unset_string_variable (svmdb_client_t *client, char *var);
void svmdb_local_set_string_variable (svmdb_client_t *client,
char *var, char *val);
char *svmdb_local_get_string_variable (svmdb_client_t *client, char *var);
void *svmdb_local_get_variable_reference (svmdb_client_t *client,
svmdb_namespace_t ns,
char *var);
void svmdb_unmap (svmdb_client_t * client);
void svmdb_local_unset_string_variable (svmdb_client_t * client, char *var);
void svmdb_local_set_string_variable (svmdb_client_t * client,
char *var, char *val);
char *svmdb_local_get_string_variable (svmdb_client_t * client, char *var);
void *svmdb_local_get_variable_reference (svmdb_client_t * client,
svmdb_namespace_t ns, char *var);
void svmdb_local_dump_strings (svmdb_client_t *client);
void svmdb_local_dump_strings (svmdb_client_t * client);
void svmdb_local_unset_vec_variable (svmdb_client_t *client, char *var);
void svmdb_local_set_vec_variable (svmdb_client_t *client,
char *var, void *val, u32 elsize);
void *svmdb_local_get_vec_variable (svmdb_client_t *client, char *var,
u32 elsize);
void svmdb_local_dump_vecs (svmdb_client_t *client);
void svmdb_local_unset_vec_variable (svmdb_client_t * client, char *var);
void svmdb_local_set_vec_variable (svmdb_client_t * client,
char *var, void *val, u32 elsize);
void *svmdb_local_get_vec_variable (svmdb_client_t * client, char *var,
u32 elsize);
void svmdb_local_dump_vecs (svmdb_client_t * client);
int svmdb_local_add_del_notification (svmdb_client_t *client,
svmdb_notification_args_t *args);
int svmdb_local_add_del_notification (svmdb_client_t * client,
svmdb_notification_args_t * args);
void *svmdb_local_find_or_add_vec_variable (svmdb_client_t *client,
char *var, u32 nbytes);
void *svmdb_local_find_or_add_vec_variable (svmdb_client_t * client,
char *var, u32 nbytes);
#endif /* __included_svmdb_h__ */
/*
* fd.io coding-style-patch-verification: ON
*
* Local Variables:
* eval: (c-set-style "gnu")
* End:
*/

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff