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")\ |
| 27 | _(DISPATCH_END, "dispatch end") \ |
Florin Coras | 6416e62 | 2019-04-03 17:52:43 -0700 | [diff] [blame] | 28 | _(FREE, "session free") \ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 29 | |
| 30 | typedef enum _session_evt_dbg |
| 31 | { |
| 32 | #define _(sym, str) SESSION_EVT_##sym, |
| 33 | foreach_session_dbg_evt |
| 34 | #undef _ |
| 35 | } session_evt_dbg_e; |
| 36 | |
Florin Coras | 8b20bf5 | 2018-06-14 14:55:50 -0700 | [diff] [blame] | 37 | #define SESSION_DEBUG 0 * (TRANSPORT_DEBUG > 0) |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 38 | #define SESSION_DEQ_NODE_EVTS (0) |
Florin Coras | 371ca50 | 2018-02-21 12:07:41 -0800 | [diff] [blame] | 39 | #define SESSION_EVT_POLL_DBG (0) |
Florin Coras | 6416e62 | 2019-04-03 17:52:43 -0700 | [diff] [blame] | 40 | #define SESSION_SM (0) |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 41 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 42 | #if SESSION_DEBUG |
| 43 | |
| 44 | #define SESSION_DBG(_fmt, _args...) clib_warning (_fmt, ##_args) |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 45 | |
| 46 | #define DEC_SESSION_ETD(_s, _e, _size) \ |
| 47 | struct \ |
| 48 | { \ |
| 49 | u32 data[_size]; \ |
| 50 | } * ed; \ |
Florin Coras | c1a448b | 2018-04-20 10:51:49 -0700 | [diff] [blame] | 51 | transport_connection_t *_tc = session_get_transport (_s); \ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 52 | ed = ELOG_TRACK_DATA (&vlib_global_main.elog_main, \ |
| 53 | _e, _tc->elog_track) |
| 54 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 55 | #define DEC_SESSION_ED(_e, _size) \ |
| 56 | struct \ |
| 57 | { \ |
| 58 | u32 data[_size]; \ |
| 59 | } * ed; \ |
| 60 | ed = ELOG_DATA (&vlib_global_main.elog_main, _e) |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 61 | |
Florin Coras | 6416e62 | 2019-04-03 17:52:43 -0700 | [diff] [blame] | 62 | #if SESSION_SM |
| 63 | #define SESSION_EVT_FREE_HANDLER(_s) \ |
| 64 | { \ |
| 65 | ELOG_TYPE_DECLARE (_e) = \ |
| 66 | { \ |
| 67 | .format = "free: idx %u", \ |
| 68 | .format_args = "i4", \ |
| 69 | }; \ |
| 70 | DEC_SESSION_ETD(_s, _e, 1); \ |
| 71 | ed->data[0] = _s->session_index; \ |
| 72 | } |
| 73 | #else |
| 74 | #define SESSION_EVT_FREE_HANDLER(_s) |
| 75 | #endif |
| 76 | |
Florin Coras | 8b20bf5 | 2018-06-14 14:55:50 -0700 | [diff] [blame] | 77 | #if SESSION_DEQ_NODE_EVTS && SESSION_DEBUG > 1 |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 78 | #define SESSION_EVT_DEQ_HANDLER(_s, _body) \ |
| 79 | { \ |
| 80 | ELOG_TYPE_DECLARE (_e) = \ |
| 81 | { \ |
| 82 | .format = "deq: id %d len %d rd %d wnd %d", \ |
| 83 | .format_args = "i4i4i4i4", \ |
| 84 | }; \ |
| 85 | DEC_SESSION_ETD(_s, _e, 4); \ |
| 86 | do { _body; } while (0); \ |
| 87 | } |
| 88 | |
| 89 | #define SESSION_EVT_ENQ_HANDLER(_s, _body) \ |
| 90 | { \ |
| 91 | ELOG_TYPE_DECLARE (_e) = \ |
| 92 | { \ |
| 93 | .format = "enq: id %d length %d", \ |
| 94 | .format_args = "i4i4", \ |
| 95 | }; \ |
| 96 | DEC_SESSION_ETD(_s, _e, 2); \ |
| 97 | do { _body; } while (0); \ |
| 98 | } |
| 99 | |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 100 | #define SESSION_EVT_DEQ_NODE_HANDLER(_node_evt) \ |
| 101 | { \ |
| 102 | ELOG_TYPE_DECLARE (_e) = \ |
| 103 | { \ |
| 104 | .format = "deq-node: %s", \ |
| 105 | .format_args = "t4", \ |
| 106 | .n_enum_strings = 2, \ |
| 107 | .enum_strings = { \ |
| 108 | "start", \ |
| 109 | "end", \ |
| 110 | }, \ |
| 111 | }; \ |
| 112 | DEC_SESSION_ED(_e, 1); \ |
| 113 | ed->data[0] = _node_evt; \ |
| 114 | } |
| 115 | #else |
Florin Coras | 8b20bf5 | 2018-06-14 14:55:50 -0700 | [diff] [blame] | 116 | #define SESSION_EVT_DEQ_HANDLER(_s, _body) |
| 117 | #define SESSION_EVT_ENQ_HANDLER(_s, _body) |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 118 | #define SESSION_EVT_DEQ_NODE_HANDLER(_node_evt) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 119 | #endif /* SESSION_DEQ_NODE_EVTS */ |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 120 | |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 121 | #if SESSION_EVT_POLL_DBG && SESSION_DEBUG > 1 |
Florin Coras | c1a448b | 2018-04-20 10:51:49 -0700 | [diff] [blame] | 122 | #define SESSION_EVT_POLL_GAP(_smm, _ti) \ |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 123 | { \ |
| 124 | ELOG_TYPE_DECLARE (_e) = \ |
| 125 | { \ |
Florin Coras | c1a448b | 2018-04-20 10:51:49 -0700 | [diff] [blame] | 126 | .format = "nixon-gap: %d us", \ |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 127 | .format_args = "i4", \ |
| 128 | }; \ |
| 129 | DEC_SESSION_ED(_e, 1); \ |
| 130 | ed->data[0] = (u32) ((now - \ |
Florin Coras | c1a448b | 2018-04-20 10:51:49 -0700 | [diff] [blame] | 131 | _smm->last_event_poll_by_thread[_ti])*1000000.0); \ |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 132 | } |
Florin Coras | c1a448b | 2018-04-20 10:51:49 -0700 | [diff] [blame] | 133 | #define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_smm, _ti) \ |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 134 | { \ |
Florin Coras | c1a448b | 2018-04-20 10:51:49 -0700 | [diff] [blame] | 135 | if (PREDICT_TRUE (smm->last_event_poll_by_thread[_ti] != 0.0)) \ |
| 136 | if (now > smm->last_event_poll_by_thread[_ti] + 500e-6) \ |
| 137 | SESSION_EVT_POLL_GAP(smm, _ti); \ |
| 138 | _smm->last_event_poll_by_thread[_ti] = now; \ |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 139 | } |
| 140 | |
Florin Coras | 8b20bf5 | 2018-06-14 14:55:50 -0700 | [diff] [blame] | 141 | #define SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_smm, _ti) \ |
| 142 | { \ |
| 143 | f64 diff = vlib_time_now (vlib_get_main ()) - \ |
| 144 | _smm->last_event_poll_by_thread[_ti]; \ |
| 145 | if (diff > 5e-2) \ |
| 146 | { \ |
| 147 | ELOG_TYPE_DECLARE (_e) = \ |
| 148 | { \ |
| 149 | .format = "dispatch time: %d us", \ |
| 150 | .format_args = "i4", \ |
| 151 | }; \ |
| 152 | DEC_SESSION_ED(_e, 1); \ |
| 153 | ed->data[0] = diff *1000000.0; \ |
| 154 | } \ |
| 155 | } |
| 156 | |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 157 | #else |
| 158 | #define SESSION_EVT_POLL_GAP(_smm, _my_thread_index) |
| 159 | #define SESSION_EVT_POLL_GAP_TRACK_HANDLER(_smm, _my_thread_index) |
Florin Coras | 8b20bf5 | 2018-06-14 14:55:50 -0700 | [diff] [blame] | 160 | #define SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_smm, _ti) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 161 | #endif /* SESSION_EVT_POLL_DBG */ |
Florin Coras | 3e350af | 2017-03-30 02:54:28 -0700 | [diff] [blame] | 162 | |
Florin Coras | 8b20bf5 | 2018-06-14 14:55:50 -0700 | [diff] [blame] | 163 | #define SESSION_EVT_DISPATCH_END_HANDLER(_smm, _ti) \ |
| 164 | { \ |
| 165 | SESSION_EVT_DEQ_NODE_HANDLER(1); \ |
| 166 | SESSION_EVT_POLL_DISPATCH_TIME_HANDLER(_smm, _ti); \ |
| 167 | } |
| 168 | |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 169 | #define CONCAT_HELPER(_a, _b) _a##_b |
| 170 | #define CC(_a, _b) CONCAT_HELPER(_a, _b) |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 171 | #define SESSION_EVT_DBG(_evt, _args...) CC(_evt, _HANDLER)(_args) |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 172 | |
| 173 | #else |
Florin Coras | 6792ec0 | 2017-03-13 03:49:51 -0700 | [diff] [blame] | 174 | #define SESSION_EVT_DBG(_evt, _args...) |
Florin Coras | cea194d | 2017-10-02 00:18:51 -0700 | [diff] [blame] | 175 | #define SESSION_DBG(_fmt, _args...) |
| 176 | #endif /* SESSION_DEBUG */ |
Florin Coras | e69f495 | 2017-03-07 10:06:24 -0800 | [diff] [blame] | 177 | |
| 178 | #endif /* SRC_VNET_SESSION_SESSION_DEBUG_H_ */ |
| 179 | /* |
| 180 | * fd.io coding-style-patch-verification: ON |
| 181 | * |
| 182 | * Local Variables: |
| 183 | * eval: (c-set-style "gnu") |
| 184 | * End: |
| 185 | */ |