vlib: add vlib_node_unschedule() and vlib_node_is_scheduled() 79/42679/2
authorDamjan Marion <[email protected]>
Fri, 4 Apr 2025 14:32:53 +0000 (16:32 +0200)
committerFlorin Coras <[email protected]>
Fri, 4 Apr 2025 18:08:48 +0000 (18:08 +0000)
Type: improvement
Change-Id: I18c3b2c688c2395e49976b9bb17c784cf6e62dc7
Signed-off-by: Damjan Marion <[email protected]>
src/vlib/node_funcs.h

index 91fedaa..ef8cf78 100644 (file)
@@ -261,6 +261,13 @@ vlib_node_set_interrupt_pending (vlib_main_t *vm, u32 node_index)
     clib_interrupt_set (interrupts, n->runtime_index);
 }
 
+always_inline int
+vlib_node_is_scheduled (vlib_main_t *vm, u32 node_index)
+{
+  vlib_node_runtime_t *rt = vlib_node_get_runtime (vm, node_index);
+  return rt->stop_timer_handle_plus_1 ? 1 : 0;
+}
+
 always_inline void
 vlib_node_schedule (vlib_main_t *vm, u32 node_index, f64 dt)
 {
@@ -273,6 +280,9 @@ vlib_node_schedule (vlib_main_t *vm, u32 node_index, f64 dt)
     .index = node_index,
   };
 
+  ASSERT (vm == vlib_get_main ());
+  ASSERT (vlib_node_is_scheduled (vm, node_index) == 0);
+
   dt = flt_round_nearest (dt * VLIB_TW_TICKS_PER_SECOND);
   ticks = clib_max ((u64) dt, 1);
 
@@ -280,6 +290,20 @@ vlib_node_schedule (vlib_main_t *vm, u32 node_index, f64 dt)
     1 + TW (tw_timer_start) (tw, e.as_u32, 0 /* timer_id */, ticks);
 }
 
+always_inline void
+vlib_node_unschedule (vlib_main_t *vm, u32 node_index)
+{
+  vlib_node_runtime_t *rt = vlib_node_get_runtime (vm, node_index);
+  TWT (tw_timer_wheel) *tw = (TWT (tw_timer_wheel) *) vm->timing_wheel;
+
+  ASSERT (vm == vlib_get_main ());
+  ASSERT (vlib_node_is_scheduled (vm, node_index) == 1);
+
+  TW (tw_timer_stop) (tw, rt->stop_timer_handle_plus_1);
+
+  rt->stop_timer_handle_plus_1 = 0;
+}
+
 always_inline vlib_process_t *
 vlib_get_process_from_node (vlib_main_t * vm, vlib_node_t * node)
 {