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.c: 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 | #include <vlib/vlib.h> |
| 41 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 42 | void |
| 43 | vlib_clear_simple_counters (vlib_simple_counter_main_t * cm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 44 | { |
| 45 | uword i, j; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 46 | u16 *my_minis; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 47 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 48 | for (i = 0; i < vec_len (cm->minis); i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 49 | { |
| 50 | my_minis = cm->minis[i]; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 51 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 52 | for (j = 0; j < vec_len (my_minis); j++) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 53 | { |
| 54 | cm->maxi[j] += my_minis[j]; |
| 55 | my_minis[j] = 0; |
| 56 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | j = vec_len (cm->maxi); |
| 60 | if (j > 0) |
| 61 | vec_validate (cm->value_at_last_clear, j - 1); |
| 62 | for (i = 0; i < j; i++) |
| 63 | cm->value_at_last_clear[i] = cm->maxi[i]; |
| 64 | } |
| 65 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 66 | void |
| 67 | vlib_clear_combined_counters (vlib_combined_counter_main_t * cm) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 68 | { |
| 69 | uword i, j; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 70 | vlib_mini_counter_t *my_minis; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 71 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 72 | for (i = 0; i < vec_len (cm->minis); i++) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 73 | { |
| 74 | my_minis = cm->minis[i]; |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 75 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 76 | for (j = 0; j < vec_len (my_minis); j++) |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 77 | { |
| 78 | cm->maxi[j].packets += my_minis[j].packets; |
| 79 | cm->maxi[j].bytes += my_minis[j].bytes; |
| 80 | my_minis[j].packets = 0; |
| 81 | my_minis[j].bytes = 0; |
| 82 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | j = vec_len (cm->maxi); |
| 86 | if (j > 0) |
| 87 | vec_validate (cm->value_at_last_clear, j - 1); |
| 88 | |
| 89 | for (i = 0; i < j; i++) |
| 90 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 91 | vlib_counter_t *c = vec_elt_at_index (cm->value_at_last_clear, i); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 92 | |
| 93 | c[0] = cm->maxi[i]; |
| 94 | } |
| 95 | } |
| 96 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 97 | void |
| 98 | vlib_validate_simple_counter (vlib_simple_counter_main_t * cm, u32 index) |
Damjan Marion | cfb2d80 | 2016-02-06 00:54:12 +0100 | [diff] [blame] | 99 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 100 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
Damjan Marion | cfb2d80 | 2016-02-06 00:54:12 +0100 | [diff] [blame] | 101 | int i; |
| 102 | |
| 103 | vec_validate (cm->minis, tm->n_vlib_mains - 1); |
| 104 | for (i = 0; i < tm->n_vlib_mains; i++) |
| 105 | vec_validate_aligned (cm->minis[i], index, CLIB_CACHE_LINE_BYTES); |
| 106 | vec_validate_aligned (cm->maxi, index, CLIB_CACHE_LINE_BYTES); |
| 107 | } |
| 108 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 109 | void |
| 110 | vlib_validate_combined_counter (vlib_combined_counter_main_t * cm, u32 index) |
Damjan Marion | cfb2d80 | 2016-02-06 00:54:12 +0100 | [diff] [blame] | 111 | { |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 112 | vlib_thread_main_t *tm = vlib_get_thread_main (); |
Damjan Marion | cfb2d80 | 2016-02-06 00:54:12 +0100 | [diff] [blame] | 113 | int i; |
| 114 | |
| 115 | vec_validate (cm->minis, tm->n_vlib_mains - 1); |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 116 | for (i = 0; i < tm->n_vlib_mains; i++) |
Damjan Marion | cfb2d80 | 2016-02-06 00:54:12 +0100 | [diff] [blame] | 117 | vec_validate_aligned (cm->minis[i], index, CLIB_CACHE_LINE_BYTES); |
| 118 | vec_validate_aligned (cm->maxi, index, CLIB_CACHE_LINE_BYTES); |
| 119 | } |
| 120 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 121 | void |
| 122 | serialize_vlib_simple_counter_main (serialize_main_t * m, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 123 | { |
| 124 | clib_warning ("unimplemented"); |
| 125 | } |
| 126 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 127 | void |
| 128 | unserialize_vlib_simple_counter_main (serialize_main_t * m, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 129 | { |
| 130 | clib_warning ("unimplemented"); |
| 131 | } |
| 132 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 133 | void |
| 134 | serialize_vlib_combined_counter_main (serialize_main_t * m, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 135 | { |
| 136 | clib_warning ("unimplemented"); |
| 137 | } |
| 138 | |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 139 | void |
| 140 | unserialize_vlib_combined_counter_main (serialize_main_t * m, va_list * va) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 141 | { |
| 142 | clib_warning ("unimplemented"); |
| 143 | } |
Dave Barach | 9b8ffd9 | 2016-07-08 08:13:45 -0400 | [diff] [blame] | 144 | |
| 145 | /* |
| 146 | * fd.io coding-style-patch-verification: ON |
| 147 | * |
| 148 | * Local Variables: |
| 149 | * eval: (c-set-style "gnu") |
| 150 | * End: |
| 151 | */ |