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