master/device.c
changeset 1856 10175d5f35ea
parent 1854 b61bece1ec1c
child 1857 ed8b490b5bc3
equal deleted inserted replaced
1855:30ddfc665fcb 1856:10175d5f35ea
   322     struct sk_buff *skb = device->tx_skb[device->tx_ring_index];
   322     struct sk_buff *skb = device->tx_skb[device->tx_ring_index];
   323 
   323 
   324     // frame statistics
   324     // frame statistics
   325     if (unlikely(jiffies - device->stats_jiffies >= HZ)) {
   325     if (unlikely(jiffies - device->stats_jiffies >= HZ)) {
   326         unsigned int i;
   326         unsigned int i;
   327         if (device->link_state) {
   327         unsigned int tx_rate =
   328             unsigned int tx_rate =
   328             (device->tx_count - device->last_tx_count) * 1000;
   329                 (device->tx_count - device->last_tx_count) * 1000;
   329         int loss = device->tx_count - device->rx_count;
   330             int loss = device->tx_count - device->rx_count;
   330         int loss_rate = (loss - device->last_loss) * 1000;
   331             int loss_rate = (loss - device->last_loss) * 1000;
   331         for (i = 0; i < EC_RATE_COUNT; i++) {
   332             for (i = 0; i < EC_RATE_COUNT; i++) {
   332             unsigned int n = rate_intervals[i];
   333                 unsigned int n = rate_intervals[i];
   333             device->tx_rates[i] =
   334                 device->tx_rates[i] =
   334                 (device->tx_rates[i] * (n - 1) + tx_rate) / n;
   335                     (device->tx_rates[i] * (n - 1) + tx_rate) / n;
   335             device->loss_rates[i] =
   336                 device->loss_rates[i] =
   336                 (device->loss_rates[i] * (n - 1) + loss_rate) / n;
   337                     (device->loss_rates[i] * (n - 1) + loss_rate) / n;
       
   338             }
       
   339             device->last_tx_count = device->tx_count;
       
   340             device->last_loss = loss;
       
   341         } else {
       
   342             // zero frame statistics
       
   343             device->tx_count = 0;
       
   344             device->rx_count = 0;
       
   345             device->last_tx_count = 0;
       
   346             device->last_loss = 0;
       
   347             for (i = 0; i < EC_RATE_COUNT; i++) {
       
   348                 device->tx_rates[i] = 0;
       
   349                 device->loss_rates[i] = 0;
       
   350             }
       
   351         }
   337         }
       
   338         device->last_tx_count = device->tx_count;
       
   339         device->last_loss = loss;
   352         device->stats_jiffies = jiffies;
   340         device->stats_jiffies = jiffies;
   353     }
   341     }
   354 
       
   355     if (unlikely(!device->link_state)) // Link down
       
   356         return;
       
   357 
   342 
   358     // set the right length for the data
   343     // set the right length for the data
   359     skb->len = ETH_HLEN + size;
   344     skb->len = ETH_HLEN + size;
   360 
   345 
   361     if (unlikely(device->master->debug_level > 1)) {
   346     if (unlikely(device->master->debug_level > 1)) {
   377 #endif
   362 #endif
   378 #ifdef EC_DEBUG_RING
   363 #ifdef EC_DEBUG_RING
   379         ec_device_debug_ring_append(
   364         ec_device_debug_ring_append(
   380                 device, TX, skb->data + ETH_HLEN, size);
   365                 device, TX, skb->data + ETH_HLEN, size);
   381 #endif
   366 #endif
       
   367     }
       
   368 }
       
   369 
       
   370 /*****************************************************************************/
       
   371 
       
   372 /** Clears the frame statistics.
       
   373  */
       
   374 void ec_device_clear_stats(
       
   375         ec_device_t *device /**< EtherCAT device */
       
   376         )
       
   377 {
       
   378     unsigned int i;
       
   379 
       
   380     // zero frame statistics
       
   381     device->tx_count = 0;
       
   382     device->rx_count = 0;
       
   383     device->last_tx_count = 0;
       
   384     device->last_loss = 0;
       
   385     for (i = 0; i < EC_RATE_COUNT; i++) {
       
   386         device->tx_rates[i] = 0;
       
   387         device->loss_rates[i] = 0;
   382     }
   388     }
   383 }
   389 }
   384 
   390 
   385 /*****************************************************************************/
   391 /*****************************************************************************/
   386 
   392