master/master.c
branchredundancy
changeset 2372 d895cd1db2bf
parent 2371 a5052376202b
child 2374 e898451c054a
equal deleted inserted replaced
2371:a5052376202b 2372:d895cd1db2bf
  1227 void ec_master_update_device_stats(
  1227 void ec_master_update_device_stats(
  1228         ec_master_t *master /**< EtherCAT master */
  1228         ec_master_t *master /**< EtherCAT master */
  1229         )
  1229         )
  1230 {
  1230 {
  1231     ec_device_stats_t *s = &master->device_stats;
  1231     ec_device_stats_t *s = &master->device_stats;
  1232     u32 tx_frame_rate, rx_frame_rate, tx_byte_rate, rx_byte_rate;
  1232     s32 tx_frame_rate, rx_frame_rate, tx_byte_rate, rx_byte_rate, loss_rate;
  1233     u64 loss;
  1233     u64 loss;
  1234     s32 loss_rate;
       
  1235     unsigned int i;
  1234     unsigned int i;
  1236 
  1235 
  1237     // frame statistics
  1236     // frame statistics
  1238     if (likely(jiffies - s->jiffies < HZ)) {
  1237     if (likely(jiffies - s->jiffies < HZ)) {
  1239         return;
  1238         return;
  1240     }
  1239     }
  1241 
  1240 
  1242     tx_frame_rate = (u32) (s->tx_count - s->last_tx_count) * 1000;
  1241     tx_frame_rate = (s->tx_count - s->last_tx_count) * 1000;
  1243     rx_frame_rate = (u32) (s->rx_count - s->last_rx_count) * 1000;
  1242     rx_frame_rate = (s->rx_count - s->last_rx_count) * 1000;
  1244     tx_byte_rate = (s->tx_bytes - s->last_tx_bytes);
  1243     tx_byte_rate = s->tx_bytes - s->last_tx_bytes;
  1245     rx_byte_rate = (s->rx_bytes - s->last_rx_bytes);
  1244     rx_byte_rate = s->rx_bytes - s->last_rx_bytes;
  1246     loss = s->tx_count - s->rx_count;
  1245     loss = s->tx_count - s->rx_count;
  1247     loss_rate = (s32) (loss - s->last_loss) * 1000;
  1246     loss_rate = (loss - s->last_loss) * 1000;
  1248 
  1247 
       
  1248     /* Low-pass filter:
       
  1249      *      Y_n = y_(n - 1) + T / tau * (x - y_(n - 1))   | T = 1
       
  1250      *   -> Y_n += (x - y_(n - 1)) / tau
       
  1251      */
  1249     for (i = 0; i < EC_RATE_COUNT; i++) {
  1252     for (i = 0; i < EC_RATE_COUNT; i++) {
  1250         unsigned int n = rate_intervals[i];
  1253         s32 n = rate_intervals[i];
  1251         s->tx_frame_rates[i] =
  1254         s->tx_frame_rates[i] += (tx_frame_rate - s->tx_frame_rates[i]) / n;
  1252             (s->tx_frame_rates[i] * (n - 1) + tx_frame_rate) / n;
  1255         s->rx_frame_rates[i] += (rx_frame_rate - s->rx_frame_rates[i]) / n;
  1253         s->rx_frame_rates[i] =
  1256         s->tx_byte_rates[i] += (tx_byte_rate - s->tx_byte_rates[i]) / n;
  1254             (s->rx_frame_rates[i] * (n - 1) + rx_frame_rate) / n;
  1257         s->rx_byte_rates[i] += (rx_byte_rate - s->rx_byte_rates[i]) / n;
  1255         s->tx_byte_rates[i] =
  1258         s->loss_rates[i] += (loss_rate - s->loss_rates[i]) / n;
  1256             (s->tx_byte_rates[i] * (n - 1) + tx_byte_rate) / n;
  1259     }
  1257         s->rx_byte_rates[i] =
  1260 
  1258             (s->rx_byte_rates[i] * (n - 1) + rx_byte_rate) / n;
       
  1259         s->loss_rates[i] =
       
  1260             (s->loss_rates[i] * (n - 1) + loss_rate) / n;
       
  1261 
       
  1262     }
       
  1263     s->last_tx_count = s->tx_count;
  1261     s->last_tx_count = s->tx_count;
  1264     s->last_rx_count = s->rx_count;
  1262     s->last_rx_count = s->rx_count;
  1265     s->last_tx_bytes = s->tx_bytes;
  1263     s->last_tx_bytes = s->tx_bytes;
  1266     s->last_rx_bytes = s->rx_bytes;
  1264     s->last_rx_bytes = s->rx_bytes;
  1267     s->last_loss = loss;
  1265     s->last_loss = loss;