Make sure that vpp_get_stats main heap does not address-collide with
the stats segment, which lands "somewhere" in the vpp address space.
Add mising MAP_ANONYMOUS flag in clib_mem_vm_map
Change-Id: I8a671d174eefd8dd24771ad2ed9f1250e2c7a9f8
Signed-off-by: Dave Barach <dave@barachs.net>
Signed-off-by: Ole Troan <ot@cisco.com>
u8 *stat_segment_name, *pattern = 0, **patterns = 0;
int rv;
enum stat_client_cmd_e cmd = STAT_CLIENT_CMD_UNKNOWN;
u8 *stat_segment_name, *pattern = 0, **patterns = 0;
int rv;
enum stat_client_cmd_e cmd = STAT_CLIENT_CMD_UNKNOWN;
- clib_mem_init (0, 128 << 20);
+ heap_base = clib_mem_vm_map ((void *) 0x10000000ULL, 128 << 20);
+ clib_mem_init (heap_base, 128 << 20);
unformat_init_command_line (a, argv);
unformat_init_command_line (a, argv);
unformat_input_t _argv, *a = &_argv;
u8 *stat_segment_name, *pattern = 0, **patterns = 0;
int rv;
unformat_input_t _argv, *a = &_argv;
u8 *stat_segment_name, *pattern = 0, **patterns = 0;
int rv;
- clib_mem_init (0, 128 << 20);
+ heap_base = clib_mem_vm_map ((void *) 0x10000000ULL, 128 << 20);
+ clib_mem_init (heap_base, 128 << 20);
unformat_init_command_line (a, argv);
unformat_init_command_line (a, argv);
vlib_stat_segment_lock (void)
{
stats_main_t *sm = &stats_main;
vlib_stat_segment_lock (void)
{
stats_main_t *sm = &stats_main;
- clib_spinlock_lock (sm->stat_segment_lockp);
+ vlib_main_t *vm = vlib_get_main ();
+ f64 deadman;
+
+ /* 3ms is WAY long enough to be reasonably sure something is wrong */
+ deadman = vlib_time_now (vm) + 3e-3;
+
+ while (__sync_lock_test_and_set (&((*sm->stat_segment_lockp)->lock), 1))
+ {
+ if (vlib_time_now (vm) >= deadman)
+ {
+ clib_warning ("BUG: stat segment lock held too long...");
+ break;
+ }
+ }
stat_segment_name = cm->stat_segment_name ?
cm->stat_segment_name : cm->name;
stat_segment_name = cm->stat_segment_name ?
cm->stat_segment_name : cm->name;
- clib_spinlock_lock (sm->stat_segment_lockp);
+ vlib_stat_segment_lock ();
/* Update hash table. The name must be copied into the segment */
hp = hash_get_pair (sm->counter_vector_by_name, stat_segment_name);
/* Update hash table. The name must be copied into the segment */
hp = hash_get_pair (sm->counter_vector_by_name, stat_segment_name);
/* Warn clients to refresh any pointers they might be holding */
shared_header->opaque[STAT_SEGMENT_OPAQUE_EPOCH] = (void *)
((u64) shared_header->opaque[STAT_SEGMENT_OPAQUE_EPOCH] + 1);
/* Warn clients to refresh any pointers they might be holding */
shared_header->opaque[STAT_SEGMENT_OPAQUE_EPOCH] = (void *)
((u64) shared_header->opaque[STAT_SEGMENT_OPAQUE_EPOCH] + 1);
- clib_spinlock_unlock (sm->stat_segment_lockp);
+ vlib_stat_segment_unlock ();
}
ssvm_pop_heap (oldheap);
}
}
ssvm_pop_heap (oldheap);
}
shared_header = ssvmp->sh;
shared_header = ssvmp->sh;
- clib_spinlock_lock (sm->stat_segment_lockp);
-
+ vlib_stat_segment_lock ();
/* Update hash table. The name must be copied into the segment */
hp = hash_get_pair (sm->counter_vector_by_name, name);
if (hp)
/* Update hash table. The name must be copied into the segment */
hp = hash_get_pair (sm->counter_vector_by_name, name);
if (hp)
/* Warn clients to refresh any pointers they might be holding */
shared_header->opaque[STAT_SEGMENT_OPAQUE_EPOCH] = (void *)
((u64) shared_header->opaque[STAT_SEGMENT_OPAQUE_EPOCH] + 1);
/* Warn clients to refresh any pointers they might be holding */
shared_header->opaque[STAT_SEGMENT_OPAQUE_EPOCH] = (void *)
((u64) shared_header->opaque[STAT_SEGMENT_OPAQUE_EPOCH] + 1);
- clib_spinlock_unlock (sm->stat_segment_lockp);
+ vlib_stat_segment_unlock ();
shared_header = ssvmp->sh;
shared_header = ssvmp->sh;
- clib_spinlock_lock (sm->stat_segment_lockp);
-
+ vlib_stat_segment_lock ();
error_vector_name = format (0, "/err/%d/counter_vector%c", thread_index, 0);
/* Update hash table. The name must be copied into the segment */
error_vector_name = format (0, "/err/%d/counter_vector%c", thread_index, 0);
/* Update hash table. The name must be copied into the segment */
/* Warn clients to refresh any pointers they might be holding */
shared_header->opaque[STAT_SEGMENT_OPAQUE_EPOCH] = (void *)
((u64) shared_header->opaque[STAT_SEGMENT_OPAQUE_EPOCH] + 1);
/* Warn clients to refresh any pointers they might be holding */
shared_header->opaque[STAT_SEGMENT_OPAQUE_EPOCH] = (void *)
((u64) shared_header->opaque[STAT_SEGMENT_OPAQUE_EPOCH] + 1);
- clib_spinlock_unlock (sm->stat_segment_lockp);
+ vlib_stat_segment_unlock ();
ssvm_pop_heap (oldheap);
}
ssvm_pop_heap (oldheap);
}
if (unformat (input, "verbose"))
verbose = 1;
if (unformat (input, "verbose"))
verbose = 1;
- clib_spinlock_lock (sm->stat_segment_lockp);
+ vlib_stat_segment_lock ();
/* *INDENT-OFF* */
hash_foreach_pair (p, sm->counter_vector_by_name,
/* *INDENT-OFF* */
hash_foreach_pair (p, sm->counter_vector_by_name,
- clib_spinlock_unlock (sm->stat_segment_lockp);
+ vlib_stat_segment_unlock ();
vec_sort_with_function (show_data, name_sort_cmp);
vec_sort_with_function (show_data, name_sort_cmp);
oldheap = ssvm_push_heap (shared_header);
oldheap = ssvm_push_heap (shared_header);
- clib_spinlock_lock (sm->stat_segment_lockp);
-
+ vlib_stat_segment_lock ();
vlib_node_get_nodes (0 /* vm, for barrier sync */ ,
(u32) ~ 0 /* all threads */ ,
1 /* include stats */ ,
vlib_node_get_nodes (0 /* vm, for barrier sync */ ,
(u32) ~ 0 /* all threads */ ,
1 /* include stats */ ,
((u64) shared_header->opaque[STAT_SEGMENT_OPAQUE_EPOCH] + 1);
}
((u64) shared_header->opaque[STAT_SEGMENT_OPAQUE_EPOCH] + 1);
}
- clib_spinlock_unlock (sm->stat_segment_lockp);
+ vlib_stat_segment_unlock ();
ssvm_pop_heap (oldheap);
}
ssvm_pop_heap (oldheap);
}
clib_mem_vm_map (void *addr, uword size)
{
void *mmap_addr;
clib_mem_vm_map (void *addr, uword size)
{
void *mmap_addr;
- uword flags = MAP_PRIVATE | MAP_FIXED;
+ uword flags = MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS;
mmap_addr = mmap (addr, size, (PROT_READ | PROT_WRITE), flags, -1, 0);
if (mmap_addr == (void *) -1)
mmap_addr = mmap (addr, size, (PROT_READ | PROT_WRITE), flags, -1, 0);
if (mmap_addr == (void *) -1)