3131 * SOFTWARE.
3232 */
3333
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+ };
35102
36103#define NET_DIM_PARAMS_NUM_PROFILES 5
37104/* Adaptive moderation profiles */
@@ -62,7 +129,8 @@ profile[NET_DIM_CQ_PERIOD_NUM_MODES][NET_DIM_PARAMS_NUM_PROFILES] = {
62129 NET_DIM_CQE_PROFILES ,
63130};
64131
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 )
66134{
67135 struct net_dim_cq_moder cq_moder ;
68136
@@ -71,7 +139,7 @@ struct net_dim_cq_moder net_dim_get_profile(u8 cq_period_mode, int ix)
71139 return cq_moder ;
72140}
73141
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 )
75143{
76144 int default_profile_ix ;
77145
@@ -83,7 +151,7 @@ struct net_dim_cq_moder net_dim_get_def_profile(u8 rx_cq_period_mode)
83151 return net_dim_get_profile (rx_cq_period_mode , default_profile_ix );
84152}
85153
86- static bool net_dim_on_top (struct net_dim * dim )
154+ static inline bool net_dim_on_top (struct net_dim * dim )
87155{
88156 switch (dim -> tune_state ) {
89157 case NET_DIM_PARKING_ON_TOP :
@@ -96,7 +164,7 @@ static bool net_dim_on_top(struct net_dim *dim)
96164 }
97165}
98166
99- static void net_dim_turn (struct net_dim * dim )
167+ static inline void net_dim_turn (struct net_dim * dim )
100168{
101169 switch (dim -> tune_state ) {
102170 case NET_DIM_PARKING_ON_TOP :
@@ -113,7 +181,7 @@ static void net_dim_turn(struct net_dim *dim)
113181 }
114182}
115183
116- static int net_dim_step (struct net_dim * dim )
184+ static inline int net_dim_step (struct net_dim * dim )
117185{
118186 if (dim -> tired == (NET_DIM_PARAMS_NUM_PROFILES * 2 ))
119187 return NET_DIM_TOO_TIRED ;
@@ -140,22 +208,22 @@ static int net_dim_step(struct net_dim *dim)
140208 return NET_DIM_STEPPED ;
141209}
142210
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 )
144212{
145213 dim -> steps_right = 0 ;
146214 dim -> steps_left = 0 ;
147215 dim -> tired = 0 ;
148216 dim -> tune_state = NET_DIM_PARKING_ON_TOP ;
149217}
150218
151- static void net_dim_park_tired (struct net_dim * dim )
219+ static inline void net_dim_park_tired (struct net_dim * dim )
152220{
153221 dim -> steps_right = 0 ;
154222 dim -> steps_left = 0 ;
155223 dim -> tune_state = NET_DIM_PARKING_TIRED ;
156224}
157225
158- static void net_dim_exit_parking (struct net_dim * dim )
226+ static inline void net_dim_exit_parking (struct net_dim * dim )
159227{
160228 dim -> tune_state = dim -> profile_ix ? NET_DIM_GOING_LEFT :
161229 NET_DIM_GOING_RIGHT ;
@@ -165,8 +233,8 @@ static void net_dim_exit_parking(struct net_dim *dim)
165233#define IS_SIGNIFICANT_DIFF (val , ref ) \
166234 (((100 * abs((val) - (ref))) / (ref)) > 10) /* more than 10% difference */
167235
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 )
170238{
171239 if (!prev -> bpms )
172240 return curr -> bpms ? NET_DIM_STATS_BETTER :
@@ -187,8 +255,8 @@ static int net_dim_stats_compare(struct net_dim_stats *curr,
187255 return NET_DIM_STATS_SAME ;
188256}
189257
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 )
192260{
193261 int prev_state = dim -> tune_state ;
194262 int prev_ix = dim -> profile_ix ;
@@ -239,10 +307,10 @@ static bool net_dim_decision(struct net_dim_stats *curr_stats,
239307 return dim -> profile_ix != prev_ix ;
240308}
241309
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 )
246314{
247315 s -> time = ktime_get ();
248316 s -> pkt_ctr = packets ;
@@ -254,9 +322,9 @@ static void net_dim_sample(u16 event_ctr,
254322#define BITS_PER_TYPE (type ) (sizeof(type) * BITS_PER_BYTE)
255323#define BIT_GAP (bits , end , start ) ((((end) - (start)) + BIT_ULL(bits)) & (BIT_ULL(bits) - 1))
256324
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 )
260328{
261329 /* u32 holds up to 71 minutes, should be enough */
262330 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,
273341 delta_us );
274342}
275343
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 )
280348{
281349 struct net_dim_sample end_sample ;
282350 struct net_dim_stats curr_stats ;
@@ -305,3 +373,5 @@ void net_dim(struct net_dim *dim,
305373 break ;
306374 }
307375}
376+
377+ #endif /* NET_DIM_H */
0 commit comments