This plugin provides a simplified example of how to hand off packets between threads. I used it to debug packet-tracer handoff tracing support.
The demo plugin hands packets from worker 1 to worker 2.
1 DBGvpp# ex /tmp/pg_input_script
5 5 handoffdemo-1 packets handed off processed
6 5 handoffdemo-2 completed packets
8 Thread 1 vpp_wk_0 (lcore 0)
9 Time 133.9, average vectors/node 5.00, last 128 main loops 0.00 per node 0.00
10 vector rates in 3.7331e-2, out 0.0000e0, drop 0.0000e0, punt 0.0000e0
11 Name State Calls Vectors Suspends Clocks Vectors/Call
12 handoffdemo-1 active 1 5 0 4.76e3 5.00
13 pg-input disabled 2 5 0 5.58e4 2.50
14 unix-epoll-input polling 22760 0 0 2.14e7 0.00
16 Thread 2 vpp_wk_1 (lcore 2)
17 Time 133.9, average vectors/node 5.00, last 128 main loops 0.00 per node 0.00
18 vector rates in 0.0000e0, out 0.0000e0, drop 3.7331e-2, punt 0.0000e0
19 Name State Calls Vectors Suspends Clocks Vectors/Call
20 drop active 1 5 0 1.35e4 5.00
21 error-drop active 1 5 0 2.52e4 5.00
22 handoffdemo-2 active 1 5 0 2.56e4 5.00
23 unix-epoll-input polling 22406 0 0 2.18e7 0.00
Enable the packet tracer and run it again...
1 DBGvpp# trace add pg-input 100
5 ------------------- Start of thread 0 vpp_main -------------------
6 No packets in trace buffer
7 ------------------- Start of thread 1 vpp_wk_0 -------------------
10 00:06:50:520688: pg-input
11 stream x, 128 bytes, 0 sw_if_index
12 current data 0, length 128, buffer-pool 0, ref-count 1, trace handle 0x1000000
13 00000000: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d0000
14 00000020: 0000000000000000000000000000000000000000000000000000000000000000
15 00000040: 0000000000000000000000000000000000000000000000000000000000000000
16 00000060: 0000000000000000000000000000000000000000000000000000000000000000
17 00:06:50:520762: handoffdemo-1
18 HANDOFFDEMO: current thread 1
22 00:06:50:520688: pg-input
23 stream x, 128 bytes, 0 sw_if_index
24 current data 0, length 128, buffer-pool 0, ref-count 1, trace handle 0x1000001
25 00000000: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d0000
26 00000020: 0000000000000000000000000000000000000000000000000000000000000000
27 00000040: 0000000000000000000000000000000000000000000000000000000000000000
28 00000060: 0000000000000000000000000000000000000000000000000000000000000000
29 00:06:50:520762: handoffdemo-1
30 HANDOFFDEMO: current thread 1
34 00:06:50:520688: pg-input
35 stream x, 128 bytes, 0 sw_if_index
36 current data 0, length 128, buffer-pool 0, ref-count 1, trace handle 0x1000002
37 00000000: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d0000
38 00000020: 0000000000000000000000000000000000000000000000000000000000000000
39 00000040: 0000000000000000000000000000000000000000000000000000000000000000
40 00000060: 0000000000000000000000000000000000000000000000000000000000000000
41 00:06:50:520762: handoffdemo-1
42 HANDOFFDEMO: current thread 1
46 00:06:50:520688: pg-input
47 stream x, 128 bytes, 0 sw_if_index
48 current data 0, length 128, buffer-pool 0, ref-count 1, trace handle 0x1000003
49 00000000: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d0000
50 00000020: 0000000000000000000000000000000000000000000000000000000000000000
51 00000040: 0000000000000000000000000000000000000000000000000000000000000000
52 00000060: 0000000000000000000000000000000000000000000000000000000000000000
53 00:06:50:520762: handoffdemo-1
54 HANDOFFDEMO: current thread 1
58 00:06:50:520688: pg-input
59 stream x, 128 bytes, 0 sw_if_index
60 current data 0, length 128, buffer-pool 0, ref-count 1, trace handle 0x1000004
61 00000000: 000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d0000
62 00000020: 0000000000000000000000000000000000000000000000000000000000000000
63 00000040: 0000000000000000000000000000000000000000000000000000000000000000
64 00000060: 0000000000000000000000000000000000000000000000000000000000000000
65 00:06:50:520762: handoffdemo-1
66 HANDOFFDEMO: current thread 1
68 ------------------- Start of thread 2 vpp_wk_1 -------------------
71 00:06:50:520796: handoff_trace
72 HANDED-OFF: from thread 1 trace index 0
73 00:06:50:520796: handoffdemo-2
74 HANDOFFDEMO: current thread 2
75 00:06:50:520867: error-drop
78 handoffdemo-2: completed packets
82 00:06:50:520796: handoff_trace
83 HANDED-OFF: from thread 1 trace index 1
84 00:06:50:520796: handoffdemo-2
85 HANDOFFDEMO: current thread 2
86 00:06:50:520867: error-drop
89 handoffdemo-2: completed packets
93 00:06:50:520796: handoff_trace
94 HANDED-OFF: from thread 1 trace index 2
95 00:06:50:520796: handoffdemo-2
96 HANDOFFDEMO: current thread 2
97 00:06:50:520867: error-drop
100 handoffdemo-2: completed packets
104 00:06:50:520796: handoff_trace
105 HANDED-OFF: from thread 1 trace index 3
106 00:06:50:520796: handoffdemo-2
107 HANDOFFDEMO: current thread 2
108 00:06:50:520867: error-drop
110 00:06:50:520914: drop
111 handoffdemo-2: completed packets
115 00:06:50:520796: handoff_trace
116 HANDED-OFF: from thread 1 trace index 4
117 00:06:50:520796: handoffdemo-2
118 HANDOFFDEMO: current thread 2
119 00:06:50:520867: error-drop
121 00:06:50:520914: drop
122 handoffdemo-2: completed packets