Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016, Mellanox Technologies. All rights reserved. |
Andy Gospodarek | b9c872f | 2018-01-09 16:06:16 -0500 | [diff] [blame] | 3 | * Copyright (c) 2017-2018, Broadcom Limited. All rights reserved. |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 4 | * |
| 5 | * This software is available to you under a choice of one of two |
| 6 | * licenses. You may choose to be licensed under the terms of the GNU |
| 7 | * General Public License (GPL) Version 2, available from the file |
| 8 | * COPYING in the main directory of this source tree, or the |
| 9 | * OpenIB.org BSD license below: |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or |
| 12 | * without modification, are permitted provided that the following |
| 13 | * conditions are met: |
| 14 | * |
| 15 | * - Redistributions of source code must retain the above |
| 16 | * copyright notice, this list of conditions and the following |
| 17 | * disclaimer. |
| 18 | * |
| 19 | * - Redistributions in binary form must reproduce the above |
| 20 | * copyright notice, this list of conditions and the following |
| 21 | * disclaimer in the documentation and/or other materials |
| 22 | * provided with the distribution. |
| 23 | * |
| 24 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 25 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 26 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 27 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 28 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 29 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 30 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 31 | * SOFTWARE. |
| 32 | */ |
| 33 | |
Andy Gospodarek | 4c4dbb4 | 2018-01-09 16:06:18 -0500 | [diff] [blame] | 34 | #ifndef NET_DIM_H |
| 35 | #define NET_DIM_H |
| 36 | |
| 37 | #include <linux/module.h> |
Tal Gilboa | 0e58983 | 2018-11-04 19:07:02 +0200 | [diff] [blame] | 38 | #include <linux/dim.h> |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 39 | |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 40 | #define NET_DIM_PARAMS_NUM_PROFILES 5 |
Tal Gilboa | 0e58983 | 2018-11-04 19:07:02 +0200 | [diff] [blame] | 41 | /* Netdev dynamic interrupt moderation profiles */ |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 42 | #define NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE 256 |
Tal Gilboa | 623ad75 | 2018-04-24 13:36:02 +0300 | [diff] [blame] | 43 | #define NET_DIM_DEFAULT_TX_CQ_MODERATION_PKTS_FROM_EQE 128 |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 44 | #define NET_DIM_DEF_PROFILE_CQE 1 |
| 45 | #define NET_DIM_DEF_PROFILE_EQE 1 |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 46 | |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 47 | /* All profiles sizes must be NET_PARAMS_DIM_NUM_PROFILES */ |
Tal Gilboa | 623ad75 | 2018-04-24 13:36:02 +0300 | [diff] [blame] | 48 | #define NET_DIM_RX_EQE_PROFILES { \ |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 49 | {1, NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \ |
| 50 | {8, NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \ |
| 51 | {64, NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \ |
| 52 | {128, NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \ |
| 53 | {256, NET_DIM_DEFAULT_RX_CQ_MODERATION_PKTS_FROM_EQE}, \ |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 54 | } |
| 55 | |
Tal Gilboa | 623ad75 | 2018-04-24 13:36:02 +0300 | [diff] [blame] | 56 | #define NET_DIM_RX_CQE_PROFILES { \ |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 57 | {2, 256}, \ |
| 58 | {8, 128}, \ |
| 59 | {16, 64}, \ |
| 60 | {32, 64}, \ |
| 61 | {64, 64} \ |
| 62 | } |
| 63 | |
Tal Gilboa | 623ad75 | 2018-04-24 13:36:02 +0300 | [diff] [blame] | 64 | #define NET_DIM_TX_EQE_PROFILES { \ |
| 65 | {1, NET_DIM_DEFAULT_TX_CQ_MODERATION_PKTS_FROM_EQE}, \ |
| 66 | {8, NET_DIM_DEFAULT_TX_CQ_MODERATION_PKTS_FROM_EQE}, \ |
| 67 | {32, NET_DIM_DEFAULT_TX_CQ_MODERATION_PKTS_FROM_EQE}, \ |
| 68 | {64, NET_DIM_DEFAULT_TX_CQ_MODERATION_PKTS_FROM_EQE}, \ |
| 69 | {128, NET_DIM_DEFAULT_TX_CQ_MODERATION_PKTS_FROM_EQE} \ |
| 70 | } |
| 71 | |
| 72 | #define NET_DIM_TX_CQE_PROFILES { \ |
| 73 | {5, 128}, \ |
| 74 | {8, 64}, \ |
| 75 | {16, 32}, \ |
| 76 | {32, 32}, \ |
| 77 | {64, 32} \ |
| 78 | } |
| 79 | |
Tal Gilboa | 8960b38 | 2019-01-31 16:44:48 +0200 | [diff] [blame^] | 80 | static const struct dim_cq_moder |
Tal Gilboa | c002bd5 | 2018-11-05 12:07:52 +0200 | [diff] [blame] | 81 | rx_profile[DIM_CQ_PERIOD_NUM_MODES][NET_DIM_PARAMS_NUM_PROFILES] = { |
Tal Gilboa | 623ad75 | 2018-04-24 13:36:02 +0300 | [diff] [blame] | 82 | NET_DIM_RX_EQE_PROFILES, |
| 83 | NET_DIM_RX_CQE_PROFILES, |
| 84 | }; |
| 85 | |
Tal Gilboa | 8960b38 | 2019-01-31 16:44:48 +0200 | [diff] [blame^] | 86 | static const struct dim_cq_moder |
Tal Gilboa | c002bd5 | 2018-11-05 12:07:52 +0200 | [diff] [blame] | 87 | tx_profile[DIM_CQ_PERIOD_NUM_MODES][NET_DIM_PARAMS_NUM_PROFILES] = { |
Tal Gilboa | 623ad75 | 2018-04-24 13:36:02 +0300 | [diff] [blame] | 88 | NET_DIM_TX_EQE_PROFILES, |
| 89 | NET_DIM_TX_CQE_PROFILES, |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 90 | }; |
| 91 | |
Tal Gilboa | 8960b38 | 2019-01-31 16:44:48 +0200 | [diff] [blame^] | 92 | static inline struct dim_cq_moder |
Tal Gilboa | 026a807 | 2018-04-24 13:36:01 +0300 | [diff] [blame] | 93 | net_dim_get_rx_moderation(u8 cq_period_mode, int ix) |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 94 | { |
Tal Gilboa | 8960b38 | 2019-01-31 16:44:48 +0200 | [diff] [blame^] | 95 | struct dim_cq_moder cq_moder = rx_profile[cq_period_mode][ix]; |
Tal Gilboa | 0088cbb | 2017-09-26 16:20:43 +0300 | [diff] [blame] | 96 | |
Tal Gilboa | 0088cbb | 2017-09-26 16:20:43 +0300 | [diff] [blame] | 97 | cq_moder.cq_period_mode = cq_period_mode; |
| 98 | return cq_moder; |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 99 | } |
| 100 | |
Tal Gilboa | 8960b38 | 2019-01-31 16:44:48 +0200 | [diff] [blame^] | 101 | static inline struct dim_cq_moder |
Tal Gilboa | 623ad75 | 2018-04-24 13:36:02 +0300 | [diff] [blame] | 102 | net_dim_get_def_rx_moderation(u8 cq_period_mode) |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 103 | { |
Tal Gilboa | c002bd5 | 2018-11-05 12:07:52 +0200 | [diff] [blame] | 104 | u8 profile_ix = cq_period_mode == DIM_CQ_PERIOD_MODE_START_FROM_CQE ? |
Tal Gilboa | 623ad75 | 2018-04-24 13:36:02 +0300 | [diff] [blame] | 105 | NET_DIM_DEF_PROFILE_CQE : NET_DIM_DEF_PROFILE_EQE; |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 106 | |
Tal Gilboa | 623ad75 | 2018-04-24 13:36:02 +0300 | [diff] [blame] | 107 | return net_dim_get_rx_moderation(cq_period_mode, profile_ix); |
| 108 | } |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 109 | |
Tal Gilboa | 8960b38 | 2019-01-31 16:44:48 +0200 | [diff] [blame^] | 110 | static inline struct dim_cq_moder |
Tal Gilboa | 623ad75 | 2018-04-24 13:36:02 +0300 | [diff] [blame] | 111 | net_dim_get_tx_moderation(u8 cq_period_mode, int ix) |
| 112 | { |
Tal Gilboa | 8960b38 | 2019-01-31 16:44:48 +0200 | [diff] [blame^] | 113 | struct dim_cq_moder cq_moder = tx_profile[cq_period_mode][ix]; |
Tal Gilboa | 623ad75 | 2018-04-24 13:36:02 +0300 | [diff] [blame] | 114 | |
| 115 | cq_moder.cq_period_mode = cq_period_mode; |
| 116 | return cq_moder; |
| 117 | } |
| 118 | |
Tal Gilboa | 8960b38 | 2019-01-31 16:44:48 +0200 | [diff] [blame^] | 119 | static inline struct dim_cq_moder |
Tal Gilboa | 623ad75 | 2018-04-24 13:36:02 +0300 | [diff] [blame] | 120 | net_dim_get_def_tx_moderation(u8 cq_period_mode) |
| 121 | { |
Tal Gilboa | c002bd5 | 2018-11-05 12:07:52 +0200 | [diff] [blame] | 122 | u8 profile_ix = cq_period_mode == DIM_CQ_PERIOD_MODE_START_FROM_CQE ? |
Tal Gilboa | 623ad75 | 2018-04-24 13:36:02 +0300 | [diff] [blame] | 123 | NET_DIM_DEF_PROFILE_CQE : NET_DIM_DEF_PROFILE_EQE; |
| 124 | |
| 125 | return net_dim_get_tx_moderation(cq_period_mode, profile_ix); |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 126 | } |
| 127 | |
Tal Gilboa | 8960b38 | 2019-01-31 16:44:48 +0200 | [diff] [blame^] | 128 | static inline int net_dim_step(struct dim *dim) |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 129 | { |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 130 | if (dim->tired == (NET_DIM_PARAMS_NUM_PROFILES * 2)) |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 131 | return DIM_TOO_TIRED; |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 132 | |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 133 | switch (dim->tune_state) { |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 134 | case DIM_PARKING_ON_TOP: |
| 135 | case DIM_PARKING_TIRED: |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 136 | break; |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 137 | case DIM_GOING_RIGHT: |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 138 | if (dim->profile_ix == (NET_DIM_PARAMS_NUM_PROFILES - 1)) |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 139 | return DIM_ON_EDGE; |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 140 | dim->profile_ix++; |
| 141 | dim->steps_right++; |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 142 | break; |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 143 | case DIM_GOING_LEFT: |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 144 | if (dim->profile_ix == 0) |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 145 | return DIM_ON_EDGE; |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 146 | dim->profile_ix--; |
| 147 | dim->steps_left++; |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 148 | break; |
| 149 | } |
| 150 | |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 151 | dim->tired++; |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 152 | return DIM_STEPPED; |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 153 | } |
| 154 | |
Tal Gilboa | 8960b38 | 2019-01-31 16:44:48 +0200 | [diff] [blame^] | 155 | static inline void net_dim_exit_parking(struct dim *dim) |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 156 | { |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 157 | dim->tune_state = dim->profile_ix ? DIM_GOING_LEFT : |
| 158 | DIM_GOING_RIGHT; |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 159 | net_dim_step(dim); |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 160 | } |
| 161 | |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 162 | static inline int net_dim_stats_compare(struct dim_stats *curr, |
| 163 | struct dim_stats *prev) |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 164 | { |
Tal Gilboa | c3164d2 | 2017-05-15 14:13:16 +0300 | [diff] [blame] | 165 | if (!prev->bpms) |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 166 | return curr->bpms ? DIM_STATS_BETTER : |
| 167 | DIM_STATS_SAME; |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 168 | |
Tal Gilboa | c3164d2 | 2017-05-15 14:13:16 +0300 | [diff] [blame] | 169 | if (IS_SIGNIFICANT_DIFF(curr->bpms, prev->bpms)) |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 170 | return (curr->bpms > prev->bpms) ? DIM_STATS_BETTER : |
| 171 | DIM_STATS_WORSE; |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 172 | |
Talat Batheesh | 5165674 | 2018-01-17 23:13:16 +0200 | [diff] [blame] | 173 | if (!prev->ppms) |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 174 | return curr->ppms ? DIM_STATS_BETTER : |
| 175 | DIM_STATS_SAME; |
Talat Batheesh | 5165674 | 2018-01-17 23:13:16 +0200 | [diff] [blame] | 176 | |
Tal Gilboa | c3164d2 | 2017-05-15 14:13:16 +0300 | [diff] [blame] | 177 | if (IS_SIGNIFICANT_DIFF(curr->ppms, prev->ppms)) |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 178 | return (curr->ppms > prev->ppms) ? DIM_STATS_BETTER : |
| 179 | DIM_STATS_WORSE; |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 180 | |
Talat Batheesh | 5165674 | 2018-01-17 23:13:16 +0200 | [diff] [blame] | 181 | if (!prev->epms) |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 182 | return DIM_STATS_SAME; |
Talat Batheesh | 5165674 | 2018-01-17 23:13:16 +0200 | [diff] [blame] | 183 | |
Tal Gilboa | c3164d2 | 2017-05-15 14:13:16 +0300 | [diff] [blame] | 184 | if (IS_SIGNIFICANT_DIFF(curr->epms, prev->epms)) |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 185 | return (curr->epms < prev->epms) ? DIM_STATS_BETTER : |
| 186 | DIM_STATS_WORSE; |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 187 | |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 188 | return DIM_STATS_SAME; |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 189 | } |
| 190 | |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 191 | static inline bool net_dim_decision(struct dim_stats *curr_stats, |
Tal Gilboa | 8960b38 | 2019-01-31 16:44:48 +0200 | [diff] [blame^] | 192 | struct dim *dim) |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 193 | { |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 194 | int prev_state = dim->tune_state; |
| 195 | int prev_ix = dim->profile_ix; |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 196 | int stats_res; |
| 197 | int step_res; |
| 198 | |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 199 | switch (dim->tune_state) { |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 200 | case DIM_PARKING_ON_TOP: |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 201 | stats_res = net_dim_stats_compare(curr_stats, &dim->prev_stats); |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 202 | if (stats_res != DIM_STATS_SAME) |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 203 | net_dim_exit_parking(dim); |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 204 | break; |
| 205 | |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 206 | case DIM_PARKING_TIRED: |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 207 | dim->tired--; |
| 208 | if (!dim->tired) |
| 209 | net_dim_exit_parking(dim); |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 210 | break; |
| 211 | |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 212 | case DIM_GOING_RIGHT: |
| 213 | case DIM_GOING_LEFT: |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 214 | stats_res = net_dim_stats_compare(curr_stats, &dim->prev_stats); |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 215 | if (stats_res != DIM_STATS_BETTER) |
| 216 | dim_turn(dim); |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 217 | |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 218 | if (dim_on_top(dim)) { |
| 219 | dim_park_on_top(dim); |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 220 | break; |
| 221 | } |
| 222 | |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 223 | step_res = net_dim_step(dim); |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 224 | switch (step_res) { |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 225 | case DIM_ON_EDGE: |
| 226 | dim_park_on_top(dim); |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 227 | break; |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 228 | case DIM_TOO_TIRED: |
| 229 | dim_park_tired(dim); |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 230 | break; |
| 231 | } |
| 232 | |
| 233 | break; |
| 234 | } |
| 235 | |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 236 | if (prev_state != DIM_PARKING_ON_TOP || |
| 237 | dim->tune_state != DIM_PARKING_ON_TOP) |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 238 | dim->prev_stats = *curr_stats; |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 239 | |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 240 | return dim->profile_ix != prev_ix; |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 241 | } |
| 242 | |
Tal Gilboa | 8960b38 | 2019-01-31 16:44:48 +0200 | [diff] [blame^] | 243 | static inline void net_dim(struct dim *dim, |
| 244 | struct dim_sample end_sample) |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 245 | { |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 246 | struct dim_stats curr_stats; |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 247 | u16 nevents; |
| 248 | |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 249 | switch (dim->state) { |
Tal Gilboa | c002bd5 | 2018-11-05 12:07:52 +0200 | [diff] [blame] | 250 | case DIM_MEASURE_IN_PROGRESS: |
Andy Gospodarek | 8115b75 | 2018-01-09 16:06:19 -0500 | [diff] [blame] | 251 | nevents = BIT_GAP(BITS_PER_TYPE(u16), |
| 252 | end_sample.event_ctr, |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 253 | dim->start_sample.event_ctr); |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 254 | if (nevents < DIM_NEVENTS) |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 255 | break; |
Tal Gilboa | 449986e | 2018-11-05 11:57:10 +0200 | [diff] [blame] | 256 | dim_calc_stats(&dim->start_sample, &end_sample, &curr_stats); |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 257 | if (net_dim_decision(&curr_stats, dim)) { |
Tal Gilboa | c002bd5 | 2018-11-05 12:07:52 +0200 | [diff] [blame] | 258 | dim->state = DIM_APPLY_NEW_PROFILE; |
Andy Gospodarek | 9a31742 | 2018-01-09 16:06:17 -0500 | [diff] [blame] | 259 | schedule_work(&dim->work); |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 260 | break; |
| 261 | } |
| 262 | /* fall through */ |
Tal Gilboa | c002bd5 | 2018-11-05 12:07:52 +0200 | [diff] [blame] | 263 | case DIM_START_MEASURE: |
Tal Gilboa | 8960b38 | 2019-01-31 16:44:48 +0200 | [diff] [blame^] | 264 | dim_update_sample(end_sample.event_ctr, end_sample.pkt_ctr, |
| 265 | end_sample.byte_ctr, &dim->start_sample); |
Tal Gilboa | c002bd5 | 2018-11-05 12:07:52 +0200 | [diff] [blame] | 266 | dim->state = DIM_MEASURE_IN_PROGRESS; |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 267 | break; |
Tal Gilboa | c002bd5 | 2018-11-05 12:07:52 +0200 | [diff] [blame] | 268 | case DIM_APPLY_NEW_PROFILE: |
Gil Rockah | cb3c7fd | 2016-06-23 17:02:41 +0300 | [diff] [blame] | 269 | break; |
| 270 | } |
| 271 | } |
Andy Gospodarek | 4c4dbb4 | 2018-01-09 16:06:18 -0500 | [diff] [blame] | 272 | |
| 273 | #endif /* NET_DIM_H */ |