@@ -118,6 +118,13 @@ void can_stat_update(struct timer_list *t)
118
118
struct can_pkg_stats * pkg_stats = net -> can .pkg_stats ;
119
119
unsigned long j = jiffies ; /* snapshot */
120
120
121
+ long rx_frames = atomic_long_read (& pkg_stats -> rx_frames );
122
+ long tx_frames = atomic_long_read (& pkg_stats -> tx_frames );
123
+ long matches = atomic_long_read (& pkg_stats -> matches );
124
+ long rx_frames_delta = atomic_long_read (& pkg_stats -> rx_frames_delta );
125
+ long tx_frames_delta = atomic_long_read (& pkg_stats -> tx_frames_delta );
126
+ long matches_delta = atomic_long_read (& pkg_stats -> matches_delta );
127
+
121
128
/* restart counting in timer context on user request */
122
129
if (user_reset )
123
130
can_init_stats (net );
@@ -127,35 +134,33 @@ void can_stat_update(struct timer_list *t)
127
134
can_init_stats (net );
128
135
129
136
/* prevent overflow in calc_rate() */
130
- if (pkg_stats -> rx_frames > (ULONG_MAX / HZ ))
137
+ if (rx_frames > (LONG_MAX / HZ ))
131
138
can_init_stats (net );
132
139
133
140
/* prevent overflow in calc_rate() */
134
- if (pkg_stats -> tx_frames > (ULONG_MAX / HZ ))
141
+ if (tx_frames > (LONG_MAX / HZ ))
135
142
can_init_stats (net );
136
143
137
144
/* matches overflow - very improbable */
138
- if (pkg_stats -> matches > (ULONG_MAX / 100 ))
145
+ if (matches > (LONG_MAX / 100 ))
139
146
can_init_stats (net );
140
147
141
148
/* calc total values */
142
- if (pkg_stats -> rx_frames )
143
- pkg_stats -> total_rx_match_ratio = (pkg_stats -> matches * 100 ) /
144
- pkg_stats -> rx_frames ;
149
+ if (rx_frames )
150
+ pkg_stats -> total_rx_match_ratio = (matches * 100 ) / rx_frames ;
145
151
146
152
pkg_stats -> total_tx_rate = calc_rate (pkg_stats -> jiffies_init , j ,
147
- pkg_stats -> tx_frames );
153
+ tx_frames );
148
154
pkg_stats -> total_rx_rate = calc_rate (pkg_stats -> jiffies_init , j ,
149
- pkg_stats -> rx_frames );
155
+ rx_frames );
150
156
151
157
/* calc current values */
152
- if (pkg_stats -> rx_frames_delta )
158
+ if (rx_frames_delta )
153
159
pkg_stats -> current_rx_match_ratio =
154
- (pkg_stats -> matches_delta * 100 ) /
155
- pkg_stats -> rx_frames_delta ;
160
+ (matches_delta * 100 ) / rx_frames_delta ;
156
161
157
- pkg_stats -> current_tx_rate = calc_rate (0 , HZ , pkg_stats -> tx_frames_delta );
158
- pkg_stats -> current_rx_rate = calc_rate (0 , HZ , pkg_stats -> rx_frames_delta );
162
+ pkg_stats -> current_tx_rate = calc_rate (0 , HZ , tx_frames_delta );
163
+ pkg_stats -> current_rx_rate = calc_rate (0 , HZ , rx_frames_delta );
159
164
160
165
/* check / update maximum values */
161
166
if (pkg_stats -> max_tx_rate < pkg_stats -> current_tx_rate )
@@ -168,9 +173,9 @@ void can_stat_update(struct timer_list *t)
168
173
pkg_stats -> max_rx_match_ratio = pkg_stats -> current_rx_match_ratio ;
169
174
170
175
/* clear values for 'current rate' calculation */
171
- pkg_stats -> tx_frames_delta = 0 ;
172
- pkg_stats -> rx_frames_delta = 0 ;
173
- pkg_stats -> matches_delta = 0 ;
176
+ atomic_long_set ( & pkg_stats -> tx_frames_delta , 0 ) ;
177
+ atomic_long_set ( & pkg_stats -> rx_frames_delta , 0 ) ;
178
+ atomic_long_set ( & pkg_stats -> matches_delta , 0 ) ;
174
179
175
180
/* restart timer (one second) */
176
181
mod_timer (& net -> can .stattimer , round_jiffies (jiffies + HZ ));
@@ -214,9 +219,12 @@ static int can_stats_proc_show(struct seq_file *m, void *v)
214
219
struct can_rcv_lists_stats * rcv_lists_stats = net -> can .rcv_lists_stats ;
215
220
216
221
seq_putc (m , '\n' );
217
- seq_printf (m , " %8ld transmitted frames (TXF)\n" , pkg_stats -> tx_frames );
218
- seq_printf (m , " %8ld received frames (RXF)\n" , pkg_stats -> rx_frames );
219
- seq_printf (m , " %8ld matched frames (RXMF)\n" , pkg_stats -> matches );
222
+ seq_printf (m , " %8ld transmitted frames (TXF)\n" ,
223
+ atomic_long_read (& pkg_stats -> tx_frames ));
224
+ seq_printf (m , " %8ld received frames (RXF)\n" ,
225
+ atomic_long_read (& pkg_stats -> rx_frames ));
226
+ seq_printf (m , " %8ld matched frames (RXMF)\n" ,
227
+ atomic_long_read (& pkg_stats -> matches ));
220
228
221
229
seq_putc (m , '\n' );
222
230
0 commit comments