Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 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 | * counter.h: simple and packet/byte counters |
| 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_counter_h |
| 41 | #define included_vlib_counter_h |
| 42 | |
Ole Troan | 58492a8 | 2018-09-04 13:19:12 +0200 | [diff] [blame] | 43 | #include <vlib/counter_types.h> |
| 44 | |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 45 | /** \file |
| 46 | |
| 47 | Optimized thread-safe counters. |
| 48 | |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 49 | Each vlib_[simple|combined]_counter_main_t consists of a per-thread |
| 50 | vector of per-object counters. |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 51 | |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 52 | The idea is to drastically eliminate atomic operations. |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 53 | */ |
| 54 | |
| 55 | /** A collection of simple counters */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 56 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 57 | typedef struct |
| 58 | { |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 59 | counter_t **counters; /**< Per-thread u64 non-atomic counters */ |
| 60 | counter_t *value_at_last_serialize; /**< Values as of last serialize. */ |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 61 | u32 last_incremental_serialize_index; /**< Last counter index |
| 62 | serialized incrementally. */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 63 | |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 64 | char *name; /**< The counter collection's name. */ |
Dave Barach | 048a4e5 | 2018-06-01 18:52:25 -0400 | [diff] [blame] | 65 | char *stat_segment_name; /**< Name in stat segment directory */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 66 | } vlib_simple_counter_main_t; |
| 67 | |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 68 | /** The number of counters (not the number of per-thread counters) */ |
| 69 | u32 vlib_simple_counter_n_counters (const vlib_simple_counter_main_t * cm); |
| 70 | |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 71 | /** Increment a simple counter |
| 72 | @param cm - (vlib_simple_counter_main_t *) simple counter main pointer |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 73 | @param thread_index - (u32) the current cpu index |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 74 | @param index - (u32) index of the counter to increment |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 75 | @param increment - (u64) quantitiy to add to the counter |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 76 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 77 | always_inline void |
| 78 | vlib_increment_simple_counter (vlib_simple_counter_main_t * cm, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 79 | u32 thread_index, u32 index, u64 increment) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 80 | { |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 81 | counter_t *my_counters; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 82 | |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 83 | my_counters = cm->counters[thread_index]; |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 84 | my_counters[index] += increment; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Matus Fabian | b0055c8 | 2018-12-17 05:29:28 -0800 | [diff] [blame] | 87 | /** Set a simple counter |
| 88 | @param cm - (vlib_simple_counter_main_t *) simple counter main pointer |
| 89 | @param thread_index - (u32) the current cpu index |
| 90 | @param index - (u32) index of the counter to increment |
| 91 | @param value - (u64) quantitiy to set to the counter |
| 92 | */ |
| 93 | always_inline void |
| 94 | vlib_set_simple_counter (vlib_simple_counter_main_t * cm, |
| 95 | u32 thread_index, u32 index, u64 value) |
| 96 | { |
| 97 | counter_t *my_counters; |
| 98 | |
| 99 | my_counters = cm->counters[thread_index]; |
| 100 | my_counters[index] = value; |
| 101 | } |
| 102 | |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 103 | /** Get the value of a simple counter |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 104 | Scrapes the entire set of per-thread counters. Innacurate unless |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 105 | worker threads which might increment the counter are |
| 106 | barrier-synchronized |
| 107 | |
| 108 | @param cm - (vlib_simple_counter_main_t *) simple counter main pointer |
| 109 | @param index - (u32) index of the counter to fetch |
| 110 | @returns - (u64) current counter value |
| 111 | */ |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 112 | always_inline counter_t |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 113 | vlib_get_simple_counter (vlib_simple_counter_main_t * cm, u32 index) |
| 114 | { |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 115 | counter_t *my_counters; |
| 116 | counter_t v; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 117 | int i; |
| 118 | |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 119 | ASSERT (index < vlib_simple_counter_n_counters (cm)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 120 | |
| 121 | v = 0; |
| 122 | |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 123 | for (i = 0; i < vec_len (cm->counters); i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 124 | { |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 125 | my_counters = cm->counters[i]; |
| 126 | v += my_counters[index]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | return v; |
| 130 | } |
| 131 | |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 132 | /** Clear a simple counter |
| 133 | Clears the set of per-thread u16 counters, and the u64 counter |
| 134 | |
| 135 | @param cm - (vlib_simple_counter_main_t *) simple counter main pointer |
| 136 | @param index - (u32) index of the counter to clear |
| 137 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 138 | always_inline void |
| 139 | vlib_zero_simple_counter (vlib_simple_counter_main_t * cm, u32 index) |
| 140 | { |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 141 | counter_t *my_counters; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 142 | int i; |
| 143 | |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 144 | ASSERT (index < vlib_simple_counter_n_counters (cm)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 145 | |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 146 | for (i = 0; i < vec_len (cm->counters); i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 147 | { |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 148 | my_counters = cm->counters[i]; |
| 149 | my_counters[index] = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 150 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 153 | /** Add two combined counters, results in the first counter |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 154 | @param [in,out] a - (vlib_counter_t *) dst counter |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 155 | @param b - (vlib_counter_t *) src counter |
| 156 | */ |
| 157 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 158 | always_inline void |
| 159 | vlib_counter_add (vlib_counter_t * a, vlib_counter_t * b) |
| 160 | { |
| 161 | a->packets += b->packets; |
| 162 | a->bytes += b->bytes; |
| 163 | } |
| 164 | |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 165 | /** Subtract combined counters, results in the first counter |
Chris Luke | d4024f5 | 2016-09-06 09:32:36 -0400 | [diff] [blame] | 166 | @param [in,out] a - (vlib_counter_t *) dst counter |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 167 | @param b - (vlib_counter_t *) src counter |
| 168 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 169 | always_inline void |
| 170 | vlib_counter_sub (vlib_counter_t * a, vlib_counter_t * b) |
| 171 | { |
| 172 | ASSERT (a->packets >= b->packets); |
| 173 | ASSERT (a->bytes >= b->bytes); |
| 174 | a->packets -= b->packets; |
| 175 | a->bytes -= b->bytes; |
| 176 | } |
| 177 | |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 178 | /** Clear a combined counter |
| 179 | @param a - (vlib_counter_t *) counter to clear |
| 180 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 181 | always_inline void |
| 182 | vlib_counter_zero (vlib_counter_t * a) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 183 | { |
| 184 | a->packets = a->bytes = 0; |
| 185 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 186 | |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 187 | /** A collection of combined counters */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 188 | typedef struct |
| 189 | { |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 190 | vlib_counter_t **counters; /**< Per-thread u64 non-atomic counter pairs */ |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 191 | vlib_counter_t *value_at_last_serialize; /**< Counter values as of last serialize. */ |
| 192 | u32 last_incremental_serialize_index; /**< Last counter index serialized incrementally. */ |
| 193 | char *name; /**< The counter collection's name. */ |
Dave Barach | 048a4e5 | 2018-06-01 18:52:25 -0400 | [diff] [blame] | 194 | char *stat_segment_name; /**< Name in stat segment directory */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 195 | } vlib_combined_counter_main_t; |
| 196 | |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 197 | /** The number of counters (not the number of per-thread counters) */ |
| 198 | u32 vlib_combined_counter_n_counters (const vlib_combined_counter_main_t * |
| 199 | cm); |
| 200 | |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 201 | /** Clear a collection of simple counters |
| 202 | @param cm - (vlib_simple_counter_main_t *) collection to clear |
| 203 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 204 | void vlib_clear_simple_counters (vlib_simple_counter_main_t * cm); |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 205 | |
| 206 | /** Clear a collection of combined counters |
| 207 | @param cm - (vlib_combined_counter_main_t *) collection to clear |
| 208 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 209 | void vlib_clear_combined_counters (vlib_combined_counter_main_t * cm); |
| 210 | |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 211 | /** Increment a combined counter |
| 212 | @param cm - (vlib_combined_counter_main_t *) comined counter main pointer |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 213 | @param thread_index - (u32) the current cpu index |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 214 | @param index - (u32) index of the counter to increment |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 215 | @param packet_increment - (u64) number of packets to add to the counter |
| 216 | @param byte_increment - (u64) number of bytes to add to the counter |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 217 | */ |
| 218 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 219 | always_inline void |
| 220 | vlib_increment_combined_counter (vlib_combined_counter_main_t * cm, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 221 | u32 thread_index, |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 222 | u32 index, u64 n_packets, u64 n_bytes) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 223 | { |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 224 | vlib_counter_t *my_counters; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 225 | |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 226 | /* Use this CPU's counter array */ |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 227 | my_counters = cm->counters[thread_index]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 228 | |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 229 | my_counters[index].packets += n_packets; |
| 230 | my_counters[index].bytes += n_bytes; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 233 | /** Pre-fetch a per-thread combined counter for the given object index */ |
| 234 | always_inline void |
| 235 | vlib_prefetch_combined_counter (const vlib_combined_counter_main_t * cm, |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 236 | u32 thread_index, u32 index) |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 237 | { |
| 238 | vlib_counter_t *cpu_counters; |
| 239 | |
| 240 | /* |
| 241 | * This CPU's index is assumed to already be in cache |
| 242 | */ |
Damjan Marion | 586afd7 | 2017-04-05 19:18:20 +0200 | [diff] [blame] | 243 | cpu_counters = cm->counters[thread_index]; |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 244 | CLIB_PREFETCH (cpu_counters + index, CLIB_CACHE_LINE_BYTES, STORE); |
Neale Ranns | 044183f | 2017-01-24 01:34:25 -0800 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 248 | /** Get the value of a combined counter, never called in the speed path |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 249 | Scrapes the entire set of per-thread counters. Innacurate unless |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 250 | worker threads which might increment the counter are |
| 251 | barrier-synchronized |
| 252 | |
| 253 | @param cm - (vlib_combined_counter_main_t *) combined counter main pointer |
| 254 | @param index - (u32) index of the combined counter to fetch |
| 255 | @param result [out] - (vlib_counter_t *) result stored here |
| 256 | */ |
| 257 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 258 | static inline void |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 259 | vlib_get_combined_counter (const vlib_combined_counter_main_t * cm, |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 260 | u32 index, vlib_counter_t * result) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 261 | { |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 262 | vlib_counter_t *my_counters, *counter; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 263 | int i; |
| 264 | |
| 265 | result->packets = 0; |
| 266 | result->bytes = 0; |
| 267 | |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 268 | for (i = 0; i < vec_len (cm->counters); i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 269 | { |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 270 | my_counters = cm->counters[i]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 271 | |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 272 | counter = vec_elt_at_index (my_counters, index); |
| 273 | result->packets += counter->packets; |
| 274 | result->bytes += counter->bytes; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 275 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 276 | } |
| 277 | |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 278 | /** Clear a combined counter |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 279 | Clears the set of per-thread counters. |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 280 | |
| 281 | @param cm - (vlib_combined_counter_main_t *) combined counter main pointer |
| 282 | @param index - (u32) index of the counter to clear |
| 283 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 284 | always_inline void |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 285 | vlib_zero_combined_counter (vlib_combined_counter_main_t * cm, u32 index) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 286 | { |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 287 | vlib_counter_t *my_counters, *counter; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 288 | int i; |
| 289 | |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 290 | for (i = 0; i < vec_len (cm->counters); i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 291 | { |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 292 | my_counters = cm->counters[i]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 293 | |
Neale Ranns | 1bd0109 | 2017-03-15 15:41:17 -0400 | [diff] [blame] | 294 | counter = vec_elt_at_index (my_counters, index); |
| 295 | counter->packets = 0; |
| 296 | counter->bytes = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 297 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 298 | } |
| 299 | |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 300 | /** validate a simple counter |
| 301 | @param cm - (vlib_simple_counter_main_t *) pointer to the counter collection |
| 302 | @param index - (u32) index of the counter to validate |
| 303 | */ |
| 304 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 305 | void vlib_validate_simple_counter (vlib_simple_counter_main_t * cm, |
| 306 | u32 index); |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 307 | /** validate a combined counter |
| 308 | @param cm - (vlib_combined_counter_main_t *) pointer to the counter |
| 309 | collection |
| 310 | @param index - (u32) index of the counter to validate |
| 311 | */ |
| 312 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 313 | void vlib_validate_combined_counter (vlib_combined_counter_main_t * cm, |
| 314 | u32 index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 315 | |
Dave Barach | 6353920 | 2016-08-11 17:21:02 -0400 | [diff] [blame] | 316 | /** Obtain the number of simple or combined counters allocated. |
| 317 | A macro which reduces to to vec_len(cm->maxi), the answer in either |
| 318 | case. |
| 319 | |
| 320 | @param cm - (vlib_simple_counter_main_t) or |
| 321 | (vlib_combined_counter_main_t) the counter collection to interrogate |
| 322 | @returns vec_len(cm->maxi) |
| 323 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 324 | #define vlib_counter_len(cm) vec_len((cm)->maxi) |
| 325 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 326 | #endif /* included_vlib_counter_h */ |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 327 | |
| 328 | /* |
| 329 | * fd.io coding-style-patch-verification: ON |
| 330 | * |
| 331 | * Local Variables: |
| 332 | * eval: (c-set-style "gnu") |
| 333 | * End: |
| 334 | */ |