31
31
* SOFTWARE.
32
32
*/
33
33
34
- #include "en.h"
34
+ #ifndef NET_DIM_H
35
+ #define NET_DIM_H
36
+
37
+ #include <linux/module.h>
38
+
39
+ struct net_dim_cq_moder {
40
+ u16 usec ;
41
+ u16 pkts ;
42
+ u8 cq_period_mode ;
43
+ };
44
+
45
+ struct net_dim_sample {
46
+ ktime_t time ;
47
+ u32 pkt_ctr ;
48
+ u32 byte_ctr ;
49
+ u16 event_ctr ;
50
+ };
51
+
52
+ struct net_dim_stats {
53
+ int ppms ; /* packets per msec */
54
+ int bpms ; /* bytes per msec */
55
+ int epms ; /* events per msec */
56
+ };
57
+
58
+ struct net_dim { /* Adaptive Moderation */
59
+ u8 state ;
60
+ struct net_dim_stats prev_stats ;
61
+ struct net_dim_sample start_sample ;
62
+ struct work_struct work ;
63
+ u8 profile_ix ;
64
+ u8 mode ;
65
+ u8 tune_state ;
66
+ u8 steps_right ;
67
+ u8 steps_left ;
68
+ u8 tired ;
69
+ };
70
+
71
+ enum {
72
+ NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE = 0x0 ,
73
+ NET_DIM_CQ_PERIOD_MODE_START_FROM_CQE = 0x1 ,
74
+ NET_DIM_CQ_PERIOD_NUM_MODES
75
+ };
76
+
77
+ /* Adaptive moderation logic */
78
+ enum {
79
+ NET_DIM_START_MEASURE ,
80
+ NET_DIM_MEASURE_IN_PROGRESS ,
81
+ NET_DIM_APPLY_NEW_PROFILE ,
82
+ };
83
+
84
+ enum {
85
+ NET_DIM_PARKING_ON_TOP ,
86
+ NET_DIM_PARKING_TIRED ,
87
+ NET_DIM_GOING_RIGHT ,
88
+ NET_DIM_GOING_LEFT ,
89
+ };
90
+
91
+ enum {
92
+ NET_DIM_STATS_WORSE ,
93
+ NET_DIM_STATS_SAME ,
94
+ NET_DIM_STATS_BETTER ,
95
+ };
96
+
97
+ enum {
98
+ NET_DIM_STEPPED ,
99
+ NET_DIM_TOO_TIRED ,
100
+ NET_DIM_ON_EDGE ,
101
+ };
35
102
36
103
#define NET_DIM_PARAMS_NUM_PROFILES 5
37
104
/* Adaptive moderation profiles */
@@ -62,7 +129,8 @@ profile[NET_DIM_CQ_PERIOD_NUM_MODES][NET_DIM_PARAMS_NUM_PROFILES] = {
62
129
NET_DIM_CQE_PROFILES ,
63
130
};
64
131
65
- struct net_dim_cq_moder net_dim_get_profile (u8 cq_period_mode , int ix )
132
+ static inline struct net_dim_cq_moder net_dim_get_profile (u8 cq_period_mode ,
133
+ int ix )
66
134
{
67
135
struct net_dim_cq_moder cq_moder ;
68
136
@@ -71,7 +139,7 @@ struct net_dim_cq_moder net_dim_get_profile(u8 cq_period_mode, int ix)
71
139
return cq_moder ;
72
140
}
73
141
74
- struct net_dim_cq_moder net_dim_get_def_profile (u8 rx_cq_period_mode )
142
+ static inline struct net_dim_cq_moder net_dim_get_def_profile (u8 rx_cq_period_mode )
75
143
{
76
144
int default_profile_ix ;
77
145
@@ -83,7 +151,7 @@ struct net_dim_cq_moder net_dim_get_def_profile(u8 rx_cq_period_mode)
83
151
return net_dim_get_profile (rx_cq_period_mode , default_profile_ix );
84
152
}
85
153
86
- static bool net_dim_on_top (struct net_dim * dim )
154
+ static inline bool net_dim_on_top (struct net_dim * dim )
87
155
{
88
156
switch (dim -> tune_state ) {
89
157
case NET_DIM_PARKING_ON_TOP :
@@ -96,7 +164,7 @@ static bool net_dim_on_top(struct net_dim *dim)
96
164
}
97
165
}
98
166
99
- static void net_dim_turn (struct net_dim * dim )
167
+ static inline void net_dim_turn (struct net_dim * dim )
100
168
{
101
169
switch (dim -> tune_state ) {
102
170
case NET_DIM_PARKING_ON_TOP :
@@ -113,7 +181,7 @@ static void net_dim_turn(struct net_dim *dim)
113
181
}
114
182
}
115
183
116
- static int net_dim_step (struct net_dim * dim )
184
+ static inline int net_dim_step (struct net_dim * dim )
117
185
{
118
186
if (dim -> tired == (NET_DIM_PARAMS_NUM_PROFILES * 2 ))
119
187
return NET_DIM_TOO_TIRED ;
@@ -140,22 +208,22 @@ static int net_dim_step(struct net_dim *dim)
140
208
return NET_DIM_STEPPED ;
141
209
}
142
210
143
- static void net_dim_park_on_top (struct net_dim * dim )
211
+ static inline void net_dim_park_on_top (struct net_dim * dim )
144
212
{
145
213
dim -> steps_right = 0 ;
146
214
dim -> steps_left = 0 ;
147
215
dim -> tired = 0 ;
148
216
dim -> tune_state = NET_DIM_PARKING_ON_TOP ;
149
217
}
150
218
151
- static void net_dim_park_tired (struct net_dim * dim )
219
+ static inline void net_dim_park_tired (struct net_dim * dim )
152
220
{
153
221
dim -> steps_right = 0 ;
154
222
dim -> steps_left = 0 ;
155
223
dim -> tune_state = NET_DIM_PARKING_TIRED ;
156
224
}
157
225
158
- static void net_dim_exit_parking (struct net_dim * dim )
226
+ static inline void net_dim_exit_parking (struct net_dim * dim )
159
227
{
160
228
dim -> tune_state = dim -> profile_ix ? NET_DIM_GOING_LEFT :
161
229
NET_DIM_GOING_RIGHT ;
@@ -165,8 +233,8 @@ static void net_dim_exit_parking(struct net_dim *dim)
165
233
#define IS_SIGNIFICANT_DIFF (val , ref ) \
166
234
(((100 * abs((val) - (ref))) / (ref)) > 10) /* more than 10% difference */
167
235
168
- static int net_dim_stats_compare (struct net_dim_stats * curr ,
169
- struct net_dim_stats * prev )
236
+ static inline int net_dim_stats_compare (struct net_dim_stats * curr ,
237
+ struct net_dim_stats * prev )
170
238
{
171
239
if (!prev -> bpms )
172
240
return curr -> bpms ? NET_DIM_STATS_BETTER :
@@ -187,8 +255,8 @@ static int net_dim_stats_compare(struct net_dim_stats *curr,
187
255
return NET_DIM_STATS_SAME ;
188
256
}
189
257
190
- static bool net_dim_decision (struct net_dim_stats * curr_stats ,
191
- struct net_dim * dim )
258
+ static inline bool net_dim_decision (struct net_dim_stats * curr_stats ,
259
+ struct net_dim * dim )
192
260
{
193
261
int prev_state = dim -> tune_state ;
194
262
int prev_ix = dim -> profile_ix ;
@@ -239,10 +307,10 @@ static bool net_dim_decision(struct net_dim_stats *curr_stats,
239
307
return dim -> profile_ix != prev_ix ;
240
308
}
241
309
242
- static void net_dim_sample (u16 event_ctr ,
243
- u64 packets ,
244
- u64 bytes ,
245
- struct net_dim_sample * s )
310
+ static inline void net_dim_sample (u16 event_ctr ,
311
+ u64 packets ,
312
+ u64 bytes ,
313
+ struct net_dim_sample * s )
246
314
{
247
315
s -> time = ktime_get ();
248
316
s -> pkt_ctr = packets ;
@@ -254,9 +322,9 @@ static void net_dim_sample(u16 event_ctr,
254
322
#define BITS_PER_TYPE (type ) (sizeof(type) * BITS_PER_BYTE)
255
323
#define BIT_GAP (bits , end , start ) ((((end) - (start)) + BIT_ULL(bits)) & (BIT_ULL(bits) - 1))
256
324
257
- static void net_dim_calc_stats (struct net_dim_sample * start ,
258
- struct net_dim_sample * end ,
259
- struct net_dim_stats * curr_stats )
325
+ static inline void net_dim_calc_stats (struct net_dim_sample * start ,
326
+ struct net_dim_sample * end ,
327
+ struct net_dim_stats * curr_stats )
260
328
{
261
329
/* u32 holds up to 71 minutes, should be enough */
262
330
u32 delta_us = ktime_us_delta (end -> time , start -> time );
@@ -273,10 +341,10 @@ static void net_dim_calc_stats(struct net_dim_sample *start,
273
341
delta_us );
274
342
}
275
343
276
- void net_dim (struct net_dim * dim ,
277
- u16 event_ctr ,
278
- u64 packets ,
279
- u64 bytes )
344
+ static inline void net_dim (struct net_dim * dim ,
345
+ u16 event_ctr ,
346
+ u64 packets ,
347
+ u64 bytes )
280
348
{
281
349
struct net_dim_sample end_sample ;
282
350
struct net_dim_stats curr_stats ;
@@ -305,3 +373,5 @@ void net_dim(struct net_dim *dim,
305
373
break ;
306
374
}
307
375
}
376
+
377
+ #endif /* NET_DIM_H */
0 commit comments