#include <vppinfra/fifo.h>
#include <vppinfra/tw_timer_1t_3w_1024sl_ov.h>
+#ifdef CLIB_SANITIZE_ADDR
+#include <sanitizer/asan_interface.h>
+#endif
+
+static_always_inline void
+vlib_process_start_switch_stack (vlib_main_t * vm, vlib_process_t * p)
+{
+#ifdef CLIB_SANITIZE_ADDR
+ void *stack = p ? (void *) p->stack : vlib_thread_stacks[vm->thread_index];
+ u32 stack_bytes = p ? p->log2_n_stack_bytes : VLIB_THREAD_STACK_SIZE;
+ __sanitizer_start_switch_fiber (&vm->asan_stack_save, stack, stack_bytes);
+#endif
+}
+
+static_always_inline void
+vlib_process_finish_switch_stack (vlib_main_t * vm)
+{
+#ifdef CLIB_SANITIZE_ADDR
+ const void *bottom_old;
+ size_t size_old;
+
+ __sanitizer_finish_switch_fiber (&vm->asan_stack_save, &bottom_old,
+ &size_old);
+#endif
+}
+
/** \brief Get vlib node by index.
@warning This function will ASSERT if @c i is out of range.
@param vm vlib_main_t pointer, varies by thread
STRUCT_OFFSET_OF (vlib_node_runtime_t, runtime_data));
if (vec_len (n->runtime_data) > 0)
- clib_memcpy (r->runtime_data, n->runtime_data, vec_len (n->runtime_data));
+ clib_memcpy_fast (r->runtime_data, n->runtime_data,
+ vec_len (n->runtime_data));
}
/** \brief Set node dispatch state.
nm->input_node_counts_by_state[new_state] += 1;
}
+ if (PREDICT_FALSE (r->state == VLIB_NODE_STATE_DISABLED))
+ vlib_node_runtime_perf_counter (vm, r, 0, 0, 0,
+ VLIB_NODE_RUNTIME_PERF_RESET);
+
n->state = new_state;
r->state = new_state;
}
}
always_inline void
-vlib_node_set_interrupt_pending (vlib_main_t * vm, u32 node_index)
+vlib_node_set_interrupt_pending_with_data (vlib_main_t * vm, u32 node_index,
+ u32 data)
{
vlib_node_main_t *nm = &vm->node_main;
vlib_node_t *n = vec_elt (nm->nodes, node_index);
+ vlib_node_interrupt_t *i;
ASSERT (n->type == VLIB_NODE_TYPE_INPUT);
- clib_spinlock_lock_if_init (&nm->pending_interrupt_lock);
- vec_add1 (nm->pending_interrupt_node_runtime_indices, n->runtime_index);
- clib_spinlock_unlock_if_init (&nm->pending_interrupt_lock);
+
+ if (vm == vlib_get_main ())
+ {
+ /* local thread */
+ vec_add2 (nm->pending_local_interrupts, i, 1);
+ i->node_runtime_index = n->runtime_index;
+ i->data = data;
+ }
+ else
+ {
+ /* remote thread */
+ clib_spinlock_lock (&nm->pending_interrupt_lock);
+ vec_add2 (nm->pending_remote_interrupts, i, 1);
+ i->node_runtime_index = n->runtime_index;
+ i->data = data;
+ *nm->pending_remote_interrupts_notify = 1;
+ clib_spinlock_unlock (&nm->pending_interrupt_lock);
+ }
+}
+
+always_inline void
+vlib_node_set_interrupt_pending (vlib_main_t * vm, u32 node_index)
+{
+ vlib_node_set_interrupt_pending_with_data (vm, node_index, 0);
}
always_inline vlib_process_t *
return vec_elt (nm->processes, node->runtime_index);
}
-/* Fetches frame with given handle. */
always_inline vlib_frame_t *
-vlib_get_frame_no_check (vlib_main_t * vm, uword frame_index)
+vlib_get_frame (vlib_main_t * vm, vlib_frame_t * f)
{
- vlib_frame_t *f;
- f = vm->heap_base + (frame_index * VLIB_FRAME_ALIGN);
+ ASSERT (f != NULL);
+ ASSERT (f->frame_flags & VLIB_FRAME_IS_ALLOCATED);
return f;
}
-always_inline u32
-vlib_frame_index_no_check (vlib_main_t * vm, vlib_frame_t * f)
-{
- uword i;
-
- ASSERT (((uword) f & (VLIB_FRAME_ALIGN - 1)) == 0);
-
- i = ((u8 *) f - (u8 *) vm->heap_base);
- ASSERT ((i / VLIB_FRAME_ALIGN) <= 0xFFFFFFFFULL);
-
- return i / VLIB_FRAME_ALIGN;
-}
-
-always_inline vlib_frame_t *
-vlib_get_frame (vlib_main_t * vm, uword frame_index)
-{
- vlib_frame_t *f = vlib_get_frame_no_check (vm, frame_index);
- ASSERT (f->flags & VLIB_FRAME_IS_ALLOCATED);
- return f;
-}
-
-always_inline u32
-vlib_frame_index (vlib_main_t * vm, vlib_frame_t * f)
+always_inline void
+vlib_frame_no_append (vlib_frame_t * f)
{
- uword i = vlib_frame_index_no_check (vm, f);
- ASSERT (vlib_get_frame (vm, i) == f);
- return i;
+ f->frame_flags |= VLIB_FRAME_NO_APPEND;
}
/* Byte alignment for vector arguments. */
/** \brief Get pointer to frame scalar data.
- @warning This is almost certainly not the function you wish to call.
- See @ref vlib_frame_vector_args instead.
-
@param f vlib_frame_t pointer
@return arbitrary node scalar data
@sa vlib_frame_vector_args
*/
always_inline void *
-vlib_frame_args (vlib_frame_t * f)
+vlib_frame_scalar_args (vlib_frame_t * f)
{
return vlib_frame_vector_args (f) - f->scalar_size;
}
return vlib_get_current_process (vm)->node_runtime.node_index;
}
+always_inline u32
+vlib_get_current_process_node_index (vlib_main_t * vm)
+{
+ vlib_process_t *process = vlib_get_current_process (vm);
+ return process->node_runtime.node_index;
+}
+
/** Returns TRUE if a process suspend time is less than 10us
@param dt - remaining poll time in seconds
@returns 1 if dt < 10e-6, 0 otherwise
{
/* expiration time in 10us ticks */
p->resume_clock_interval = dt * 1e5;
+ vlib_process_start_switch_stack (vm, 0);
clib_longjmp (&p->return_longjmp, VLIB_PROCESS_RETURN_LONGJMP_SUSPEND);
}
+ else
+ vlib_process_finish_switch_stack (vm);
return r;
}
r =
clib_setjmp (&p->resume_longjmp, VLIB_PROCESS_RESUME_LONGJMP_SUSPEND);
if (r == VLIB_PROCESS_RESUME_LONGJMP_SUSPEND)
- clib_longjmp (&p->return_longjmp,
- VLIB_PROCESS_RETURN_LONGJMP_SUSPEND);
+ {
+ vlib_process_start_switch_stack (vm, 0);
+ clib_longjmp (&p->return_longjmp,
+ VLIB_PROCESS_RETURN_LONGJMP_SUSPEND);
+ }
+ else
+ vlib_process_finish_switch_stack (vm);
}
return p->non_empty_event_type_bitmap;
r =
clib_setjmp (&p->resume_longjmp, VLIB_PROCESS_RESUME_LONGJMP_SUSPEND);
if (r == VLIB_PROCESS_RESUME_LONGJMP_SUSPEND)
- clib_longjmp (&p->return_longjmp,
- VLIB_PROCESS_RETURN_LONGJMP_SUSPEND);
+ {
+ vlib_process_start_switch_stack (vm, 0);
+ clib_longjmp (&p->return_longjmp,
+ VLIB_PROCESS_RETURN_LONGJMP_SUSPEND);
+ }
+ else
+ vlib_process_finish_switch_stack (vm);
}
return vlib_process_get_events_helper (p, with_type_index, data_vector);
r =
clib_setjmp (&p->resume_longjmp, VLIB_PROCESS_RESUME_LONGJMP_SUSPEND);
if (r == VLIB_PROCESS_RESUME_LONGJMP_SUSPEND)
- clib_longjmp (&p->return_longjmp,
- VLIB_PROCESS_RETURN_LONGJMP_SUSPEND);
+ {
+ vlib_process_start_switch_stack (vm, 0);
+ clib_longjmp (&p->return_longjmp,
+ VLIB_PROCESS_RETURN_LONGJMP_SUSPEND);
+ }
+ else
+ vlib_process_finish_switch_stack (vm);
/* See if unknown event type has been signaled now. */
if (!h)
if (r == VLIB_PROCESS_RESUME_LONGJMP_SUSPEND)
{
p->resume_clock_interval = dt * 1e5;
+ vlib_process_start_switch_stack (vm, 0);
clib_longjmp (&p->return_longjmp, VLIB_PROCESS_RETURN_LONGJMP_SUSPEND);
}
+ else
+ vlib_process_finish_switch_stack (vm);
/* Return amount of time still left to sleep.
If <= 0 then we've been waken up by the clock (and not an event). */
uword p_flags, add_to_pending, delete_from_wheel;
void *data_to_be_written_by_caller;
+ ASSERT (n->type == VLIB_NODE_TYPE_PROCESS);
+
ASSERT (!pool_is_free_index (p->event_type_pool, t));
vec_validate (p->pending_event_data_by_type_index, t);
{
/* Waiting for both event and clock? */
if (p_flags & VLIB_PROCESS_IS_SUSPENDED_WAITING_FOR_EVENT)
- delete_from_wheel = 1;
+ {
+ if (!TW (tw_timer_handle_is_free)
+ ((TWT (tw_timer_wheel) *) nm->timing_wheel,
+ p->stop_timer_handle))
+ delete_from_wheel = 1;
+ else
+ /* timer just popped so process should already be on the list */
+ add_to_pending = 0;
+ }
else
/* Waiting only for clock. Event will be queue and may be
handled when timer expires. */
vlib_process_t *p = vec_elt (nm->processes, n->runtime_index);
uword *h, t;
+ /* Must be in main thread */
+ ASSERT (vlib_get_thread_index () == 0);
+
h = hash_get (p->event_type_index_by_type_opaque, type_opaque);
if (!h)
{
d[0] = data;
}
+/**
+ * Signal event to process from any thread.
+ *
+ * When in doubt, use this.
+ */
+always_inline void
+vlib_process_signal_event_mt (vlib_main_t * vm,
+ uword node_index, uword type_opaque, uword data)
+{
+ if (vlib_get_thread_index () != 0)
+ {
+ vlib_process_signal_event_mt_args_t args = {
+ .node_index = node_index,
+ .type_opaque = type_opaque,
+ .data = data,
+ };
+ vlib_rpc_call_main_thread (vlib_process_signal_event_mt_helper,
+ (u8 *) & args, sizeof (args));
+ }
+ else
+ vlib_process_signal_event (vm, node_index, type_opaque, data);
+}
+
always_inline void
vlib_process_signal_one_time_event (vlib_main_t * vm,
uword node_index,
{
vlib_process_signal_one_time_event (vm, p->node_index, p->one_time_event,
/* data */ ~0);
- memset (p, ~0, sizeof (p[0]));
+ clib_memset (p, ~0, sizeof (p[0]));
}
always_inline void
return vlib_node_add_named_next_with_slot (vm, node, name, ~0);
}
+/**
+ * Get list of nodes
+ */
+void
+vlib_node_get_nodes (vlib_main_t * vm, u32 max_threads, int include_stats,
+ int barrier_sync, vlib_node_t **** node_dupsp,
+ vlib_main_t *** stat_vmsp);
+
/* Query node given name. */
vlib_node_t *vlib_get_node_by_name (vlib_main_t * vm, u8 * name);
em->counters[node_counter_base_index + counter_index] += increment;
}
+/** @brief Create a vlib process
+ * @param vm &vlib_global_main
+ * @param f the process node function
+ * @param log2_n_stack_bytes size of the process stack, defaults to 16K
+ * @return newly-create node index
+ * @warning call only on the main thread. Barrier sync required
+ */
+u32 vlib_process_create (vlib_main_t * vm, char *name,
+ vlib_node_function_t * f, u32 log2_n_stack_bytes);
+
#endif /* included_vlib_node_funcs_h */
/*