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