FD.io VPP  v16.06
Vector Packet Processing
trace_funcs.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /*
16  * trace_funcs.h: VLIB trace buffer.
17  *
18  * Copyright (c) 2008 Eliot Dresselhaus
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files (the
22  * "Software"), to deal in the Software without restriction, including
23  * without limitation the rights to use, copy, modify, merge, publish,
24  * distribute, sublicense, and/or sell copies of the Software, and to
25  * permit persons to whom the Software is furnished to do so, subject to
26  * the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */
39 
40 #ifndef included_vlib_trace_funcs_h
41 #define included_vlib_trace_funcs_h
42 
43 always_inline void
45 {
46  /*
47  * this assert seems right, but goes off constantly.
48  * disabling it appears to make the pain go away
49  */
52 }
53 
54 always_inline void *
57  vlib_buffer_t * b,
58  u32 n_data_bytes)
59 {
60  vlib_trace_main_t * tm = &vm->trace_main;
62  u32 n_data_words;
63 
64  vlib_validate_trace (tm, b);
65 
66  n_data_bytes = round_pow2 (n_data_bytes, sizeof (h[0]));
67  n_data_words = n_data_bytes / sizeof (h[0]);
69  1 + n_data_words,
70  sizeof (h[0]));
71 
73  h->n_data = n_data_words;
74  h->node_index = r->node_index;
75 
76  return h->data;
77 }
78 
81 { return h + 1 + h->n_data; }
82 
83 always_inline void
85 {
86  vlib_trace_main_t * tm = &vm->trace_main;
87  vlib_validate_trace (tm, b);
88  _vec_len (tm->trace_buffer_pool[b->trace_index]) = 0;
90 }
91 
92 always_inline void
95  u32 next_index)
96 {
97  vlib_next_frame_t * nf;
98  nf = vlib_node_runtime_get_next_frame (vm, r, next_index);
99  nf->flags |= VLIB_FRAME_TRACE;
100 }
101 
102 void trace_apply_filter (vlib_main_t * vm);
103 
104 /* Mark buffer as traced and allocate trace buffer. */
105 always_inline void
108  u32 next_index,
109  vlib_buffer_t * b,
110  int follow_chain)
111 {
112  vlib_trace_main_t * tm = &vm->trace_main;
113  vlib_trace_header_t ** h;
114 
115  /*
116  * Apply filter to existing traces to keep number of allocated traces low.
117  * Performed each time around the main loop.
118  */
119  if (tm->last_main_loop_count != vm->main_loop_count)
120  {
122  trace_apply_filter (vm);
123  }
124 
125  vlib_trace_next_frame (vm, r, next_index);
126 
127  pool_get (tm->trace_buffer_pool, h);
128 
129  do {
131  b->trace_index = h - tm->trace_buffer_pool;
132  } while (follow_chain && (b = vlib_get_next_buffer (vm, b)));
133 }
134 
135 always_inline void
137 {
138  vlib_buffer_t * b_target = vlib_get_buffer (vm, bi_target);
139  b_target->flags |= b->flags & VLIB_BUFFER_IS_TRACED;
140  b_target->trace_index = b->trace_index;
141 }
142 
145 {
146  vlib_trace_main_t * tm = &vm->trace_main;
147  vlib_trace_node_t * tn;
148  int n;
149 
150  if (rt->node_index >= vec_len (tm->nodes))
151  return 0;
152  tn = tm->nodes + rt->node_index;
153  n = tn->limit - tn->count;
154  ASSERT (n >= 0);
155 
156  return n;
157 }
158 
159 always_inline void
161  u32 count)
162 {
163  vlib_trace_main_t * tm = &vm->trace_main;
165 
166  ASSERT (count <= tn->limit);
167  tn->count = tn->limit - count;
168 }
169 
170 /* Helper function for nodes which only trace buffer data. */
171 void
173  vlib_node_runtime_t * node,
174  u32 * buffers,
175  uword n_buffers,
176  uword next_buffer_stride,
177  uword n_buffer_data_bytes_in_trace);
178 
179 #endif /* included_vlib_trace_funcs_h */
always_inline uword round_pow2(uword x, uword pow2)
Definition: clib.h:255
void vlib_trace_frame_buffers_only(vlib_main_t *vm, vlib_node_runtime_t *node, u32 *buffers, uword n_buffers, uword next_buffer_stride, uword n_buffer_data_bytes_in_trace)
Definition: trace.c:45
always_inline void vlib_trace_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index)
Definition: trace_funcs.h:93
vlib_trace_node_t * nodes
Definition: trace.h:83
always_inline vlib_next_frame_t * vlib_node_runtime_get_next_frame(vlib_main_t *vm, vlib_node_runtime_t *n, u32 next_index)
Definition: node_funcs.h:213
#define vec_add2_aligned(V, P, N, A)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:531
always_inline void vlib_set_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt, u32 count)
Definition: trace_funcs.h:160
#define pool_get(P, E)
Definition: pool.h:186
vlib_trace_header_t ** trace_buffer_pool
Definition: trace.h:69
u32 last_main_loop_count
Definition: trace.h:71
always_inline u32 vlib_get_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt)
Definition: trace_funcs.h:144
#define always_inline
Definition: clib.h:84
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define VLIB_FRAME_TRACE
Definition: node.h:344
always_inline void vlib_buffer_copy_trace_flag(vlib_main_t *vm, vlib_buffer_t *b, u32 bi_target)
Definition: trace_funcs.h:136
always_inline vlib_buffer_t * vlib_get_next_buffer(vlib_main_t *vm, vlib_buffer_t *b)
Get next buffer in buffer linklist, or zero for end of list.
Definition: buffer_funcs.h:96
void trace_apply_filter(vlib_main_t *vm)
Definition: trace.c:221
always_inline vlib_trace_header_t * vlib_trace_header_next(vlib_trace_header_t *h)
Definition: trace_funcs.h:80
#define pool_is_free_index(P, I)
Definition: pool.h:197
#define pool_put_index(p, i)
Definition: pool.h:214
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
vlib_trace_main_t trace_main
Definition: main.h:121
#define VLIB_BUFFER_IS_TRACED
Definition: buffer.h:91
u64 uword
Definition: types.h:112
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
always_inline void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
always_inline void vlib_free_trace(vlib_main_t *vm, vlib_buffer_t *b)
Definition: trace_funcs.h:84
always_inline void vlib_validate_trace(vlib_trace_main_t *tm, vlib_buffer_t *b)
Definition: trace_funcs.h:44
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:84
u32 main_loop_count
Definition: main.h:70
always_inline void vlib_trace_buffer(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, vlib_buffer_t *b, int follow_chain)
Definition: trace_funcs.h:106
always_inline vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:69
u32 trace_index
Specifies index into trace buffer if VLIB_PACKET_IS_TRACED flag is set.
Definition: buffer.h:116
u64 cpu_time_last_node_dispatch
Definition: main.h:64