Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 1 | /* |
Florin Coras | 288eaab | 2019-02-03 15:26:14 -0800 | [diff] [blame] | 2 | * Copyright (c) 2017-2019 Cisco and/or its affiliates. |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 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 | #ifndef SRC_VNET_SESSION_SESSION_DEBUG_H_ |
| 16 | #define SRC_VNET_SESSION_SESSION_DEBUG_H_ |
| 17 | |
| 18 | #include <vnet/session/transport.h> |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 19 | #include <vlib/vlib.h> |
| 20 | |
| 21 | #define foreach_session_dbg_evt \ |
| 22 | _(ENQ, "enqueue") \ |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 23 | _(DEQ, "dequeue") \ |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 24 | _(DEQ_NODE, "dequeue") \ |
| 25 | _(POLL_GAP_TRACK, "poll gap track") \ |
Florin Coras | 8b20bf5 | 2018-06-14 14:55:50 -0700 | [diff] [blame] | 26 | _(POLL_DISPATCH_TIME, "dispatch time")\ |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 27 | _(DISPATCH_START, "dispatch start") \ |
Florin Coras | 8b20bf5 | 2018-06-14 14:55:50 -0700 | [diff] [blame] | 28 | _(DISPATCH_END, "dispatch end") \ |
Florin Coras | 6416e62 | 2019-04-03 17:52:43 -0700 | [diff] [blame] | 29 | _(FREE, "session free") \ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 30 | |
| 31 | typedef enum _session_evt_dbg |
| 32 | { |
| 33 | #define _(sym, str) SESSION_EVT_##sym, |
| 34 | foreach_session_dbg_evt |
| 35 | #undef _ |
| 36 | } session_evt_dbg_e; |
| 37 | |
Florin Coras | 8b20bf5 | 2018-06-14 14:55:50 -0700 | [diff] [blame] | 38 | #define SESSION_DEBUG 0 * (TRANSPORT_DEBUG > 0) |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 39 | #define SESSION_DEQ_EVTS (0) |
Florin Coras | ba13c3b | 2019-10-30 17:11:53 -0700 | [diff] [blame^] | 40 | #define SESSION_DISPATCH_DBG (0) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 41 | #define SESSION_EVT_POLL_DBG (0) |
Florin Coras | 6416e62 | 2019-04-03 17:52:43 -0700 | [diff] [blame] | 42 | #define SESSION_SM (0) |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 43 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 44 | #if SESSION_DEBUG |
| 45 | |
| 46 | #define SESSION_DBG(_fmt, _args...) clib_warning (_fmt, ##_args) |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 47 | |
| 48 | #define DEC_SESSION_ETD(_s, _e, _size) \ |
| 49 | struct \ |
| 50 | { \ |
| 51 | u32 data[_size]; \ |
| 52 | } * ed; \ |
Florin Coras | c1a448b | 2018-04-20 10:51:49 -0700 | [diff] [blame] | 53 | transport_connection_t *_tc = session_get_transport (_s); \ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 54 | ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, \ |
| 55 | _e, _tc->elog_track) |
| 56 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 57 | #define DEC_SESSION_ED(_e, _size) \ |
| 58 | struct \ |
| 59 | { \ |
| 60 | u32 data[_size]; \ |
| 61 | } * ed; \ |
| 62 | ed = ELOG_DATA (&vlib_global_main.elog_main, _e) |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 63 | |
Florin Coras | 6416e62 | 2019-04-03 17:52:43 -0700 | [diff] [blame] | 64 | #if SESSION_SM |
| 65 | #define SESSION_EVT_FREE_HANDLER(_s) \ |
| 66 | { \ |
| 67 | ELOG_TYPE_DECLARE (_e) = \ |
| 68 | { \ |
| 69 | .format = "free: idx %u", \ |
| 70 | .format_args = "i4", \ |
| 71 | }; \ |
| 72 | DEC_SESSION_ETD(_s, _e, 1); \ |
| 73 | ed->data[0] = _s->session_index; \ |
| 74 | } |
| 75 | #else |
| 76 | #define SESSION_EVT_FREE_HANDLER(_s) |
| 77 | #endif |
| 78 | |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 79 | #if SESSION_DEQ_EVTS |
| 80 | #define SESSION_EVT_DEQ_HANDLER(_s, _now, _max, _has_evt, _ts) \ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 81 | { \ |
| 82 | ELOG_TYPE_DECLARE (_e) = \ |
| 83 | { \ |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 84 | .format = "deq: now %u max %d evt %u ts %d", \ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 85 | .format_args = "i4i4i4i4", \ |
| 86 | }; \ |
| 87 | DEC_SESSION_ETD(_s, _e, 4); \ |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 88 | ed->data[0] = _now; \ |
| 89 | ed->data[1] = _max; \ |
| 90 | ed->data[2] = _has_evt; \ |
| 91 | ed->data[3] = _ts * 1000000.0; \ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 94 | #define SESSION_EVT_ENQ_HANDLER(_s, _len) \ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 95 | { \ |
| 96 | ELOG_TYPE_DECLARE (_e) = \ |
| 97 | { \ |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 98 | .format = "enq: length %d", \ |
| 99 | .format_args = "i4", \ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 100 | }; \ |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 101 | DEC_SESSION_ETD(_s, _e, 1); \ |
| 102 | ed->data[0] = _len; \ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 103 | } |
Florin Coras | ba13c3b | 2019-10-30 17:11:53 -0700 | [diff] [blame^] | 104 | #else |
| 105 | #define SESSION_EVT_DEQ_HANDLER(_s, _now, _max, _has_evt, _ts) |
| 106 | #define SESSION_EVT_ENQ_HANDLER(_s, _body) |
| 107 | #endif /* SESSION_DEQ_NODE_EVTS */ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 108 | |
Florin Coras | ba13c3b | 2019-10-30 17:11:53 -0700 | [diff] [blame^] | 109 | #if SESSION_DISPATCH_DBG |
| 110 | #define SESSION_EVT_DEQ_NODE_HANDLER(_wrk, _node_evt, _ntx) \ |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 111 | { \ |
| 112 | ELOG_TYPE_DECLARE (_e) = \ |
| 113 | { \ |
Florin Coras | ba13c3b | 2019-10-30 17:11:53 -0700 | [diff] [blame^] | 114 | .format = "dispatch: %s pkts %u re-entry: %u dispatch %u", \ |
| 115 | .format_args = "t4i4i4i4", \ |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 116 | .n_enum_strings = 2, \ |
| 117 | .enum_strings = { \ |
| 118 | "start", \ |
| 119 | "end", \ |
| 120 | }, \ |
| 121 | }; \ |
Florin Coras | ba13c3b | 2019-10-30 17:11:53 -0700 | [diff] [blame^] | 122 | DEC_SESSION_ED(_e, 4); \ |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 123 | ed->data[0] = _node_evt; \ |
Florin Coras | ba13c3b | 2019-10-30 17:11:53 -0700 | [diff] [blame^] | 124 | ed->data[1] = _ntx; \ |
| 125 | ed->data[2] = (_wrk->last_vlib_time - _wrk->last_event_poll) \ |
| 126 | * 1000000.0; \ |
| 127 | ed->data[3] = (vlib_time_now (_wrk->vm) - _wrk->last_vlib_time) \ |
| 128 | * 1000000.0; \ |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 129 | } |
| 130 | #else |
Florin Coras | ba13c3b | 2019-10-30 17:11:53 -0700 | [diff] [blame^] | 131 | #define SESSION_EVT_DEQ_NODE_HANDLER(_node_evt, _ntx) |
| 132 | #endif /* SESSION_DISPATCH_DBG */ |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 133 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 134 | #if SESSION_EVT_POLL_DBG && SESSION_DEBUG > 1 |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 135 | #define SESSION_EVT_POLL_GAP(_wrk) \ |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 136 | { \ |
| 137 | ELOG_TYPE_DECLARE (_e) = \ |
| 138 | { \ |
Florin Coras | c1a448b | 2018-04-20 10:51:49 -0700 | [diff] [blame] | 139 | .format = "nixon-gap: %d us", \ |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 140 | .format_args = "i4", \ |
| 141 | }; \ |
| 142 | DEC_SESSION_ED(_e, 1); \ |
Florin Coras | ba13c3b | 2019-10-30 17:11:53 -0700 | [diff] [blame^] | 143 | ed->data[0] = (u32) ((_wrk->last_vlib_time - _wrk->last_event_poll) \ |
| 144 | *1000000.0); \ |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 145 | } |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 146 | #define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_wrk) \ |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 147 | { \ |
Florin Coras | ba13c3b | 2019-10-30 17:11:53 -0700 | [diff] [blame^] | 148 | if (PREDICT_TRUE (_wrk->last_event_poll != 0.0)) \ |
| 149 | if (_wrk->last_vlib_time > _wrk->last_event_poll + 500e-6) \ |
| 150 | SESSION_EVT_POLL_GAP(_wrk); \ |
| 151 | _wrk->last_event_poll = _wrk->last_vlib_time; \ |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 154 | #define SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_wrk) \ |
Florin Coras | 8b20bf5 | 2018-06-14 14:55:50 -0700 | [diff] [blame] | 155 | { \ |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 156 | f64 diff = vlib_time_now (vlib_get_main ()) - _wrk->last_event_poll; \ |
Florin Coras | 8b20bf5 | 2018-06-14 14:55:50 -0700 | [diff] [blame] | 157 | if (diff > 5e-2) \ |
| 158 | { \ |
| 159 | ELOG_TYPE_DECLARE (_e) = \ |
| 160 | { \ |
| 161 | .format = "dispatch time: %d us", \ |
| 162 | .format_args = "i4", \ |
| 163 | }; \ |
| 164 | DEC_SESSION_ED(_e, 1); \ |
| 165 | ed->data[0] = diff *1000000.0; \ |
| 166 | } \ |
| 167 | } |
| 168 | |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 169 | #else |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 170 | #define SESSION_EVT_POLL_GAP(_wrk) |
| 171 | #define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_wrk) |
| 172 | #define SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_wrk) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 173 | #endif /* SESSION_EVT_POLL_DBG */ |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 174 | |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 175 | #define SESSION_EVT_DISPATCH_START_HANDLER(_wrk) \ |
Florin Coras | 8b20bf5 | 2018-06-14 14:55:50 -0700 | [diff] [blame] | 176 | { \ |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 177 | if (SESSION_DEQ_EVTS > 1) \ |
Florin Coras | ba13c3b | 2019-10-30 17:11:53 -0700 | [diff] [blame^] | 178 | SESSION_EVT_DEQ_NODE_HANDLER (_wrk, 0, 0); \ |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 179 | SESSION_EVT_POLL_GAP_TRACK_HANDLER (wrk); \ |
| 180 | } |
| 181 | |
| 182 | #define SESSION_EVT_DISPATCH_END_HANDLER(_wrk, _ntx) \ |
| 183 | { \ |
Florin Coras | ba13c3b | 2019-10-30 17:11:53 -0700 | [diff] [blame^] | 184 | if (_ntx) \ |
| 185 | SESSION_EVT_DEQ_NODE_HANDLER (_wrk, 1, _ntx); \ |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 186 | SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_wrk); \ |
Florin Coras | ba13c3b | 2019-10-30 17:11:53 -0700 | [diff] [blame^] | 187 | _wrk->last_event_poll = vlib_time_now (_wrk->vm); \ |
Florin Coras | 8b20bf5 | 2018-06-14 14:55:50 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 190 | #define CONCAT_HELPER(_a, _b) _a##_b |
| 191 | #define CC(_a, _b) CONCAT_HELPER(_a, _b) |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 192 | #define SESSION_EVT(_evt, _args...) CC(_evt, _HANDLER)(_args) |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 193 | |
| 194 | #else |
Florin Coras | cca9618 | 2019-07-19 07:34:13 -0700 | [diff] [blame] | 195 | #define SESSION_EVT(_evt, _args...) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 196 | #define SESSION_DBG(_fmt, _args...) |
| 197 | #endif /* SESSION_DEBUG */ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 198 | |
| 199 | #endif /* SRC_VNET_SESSION_SESSION_DEBUG_H_ */ |
| 200 | /* |
| 201 | * fd.io coding-style-patch-verification: ON |
| 202 | * |
| 203 | * Local Variables: |
| 204 | * eval: (c-set-style "gnu") |
| 205 | * End: |
| 206 | */ |