52 (result)->tv_usec += 1000000; \ |
52 (result)->tv_usec += 1000000; \ |
53 } \ |
53 } \ |
54 } while (0) |
54 } while (0) |
55 #endif |
55 #endif |
56 |
56 |
57 /** List of intervals for frame statistics [s]. |
|
58 */ |
|
59 static const unsigned int rate_intervals[] = { |
|
60 1, 10, 60 |
|
61 }; |
|
62 |
|
63 /*****************************************************************************/ |
57 /*****************************************************************************/ |
64 |
58 |
65 /** Constructor. |
59 /** Constructor. |
66 * |
60 * |
67 * \return 0 in case of success, else < 0 |
61 * \return 0 in case of success, else < 0 |
307 size_t size /**< number of bytes to send */ |
301 size_t size /**< number of bytes to send */ |
308 ) |
302 ) |
309 { |
303 { |
310 struct sk_buff *skb = device->tx_skb[device->tx_ring_index]; |
304 struct sk_buff *skb = device->tx_skb[device->tx_ring_index]; |
311 |
305 |
312 // frame statistics |
|
313 if (unlikely(jiffies - device->stats_jiffies >= HZ)) { |
|
314 unsigned int i; |
|
315 u32 tx_frame_rate = |
|
316 (u32) (device->tx_count - device->last_tx_count) * 1000; |
|
317 u32 tx_byte_rate = |
|
318 (device->tx_bytes - device->last_tx_bytes); |
|
319 u64 loss = device->tx_count - device->rx_count; |
|
320 s32 loss_rate = (s32) (loss - device->last_loss) * 1000; |
|
321 for (i = 0; i < EC_RATE_COUNT; i++) { |
|
322 unsigned int n = rate_intervals[i]; |
|
323 device->tx_frame_rates[i] = |
|
324 (device->tx_frame_rates[i] * (n - 1) + tx_frame_rate) / n; |
|
325 device->tx_byte_rates[i] = |
|
326 (device->tx_byte_rates[i] * (n - 1) + tx_byte_rate) / n; |
|
327 device->loss_rates[i] = |
|
328 (device->loss_rates[i] * (n - 1) + loss_rate) / n; |
|
329 } |
|
330 device->last_tx_count = device->tx_count; |
|
331 device->last_tx_bytes = device->tx_bytes; |
|
332 device->last_loss = loss; |
|
333 device->stats_jiffies = jiffies; |
|
334 } |
|
335 |
|
336 // set the right length for the data |
306 // set the right length for the data |
337 skb->len = ETH_HLEN + size; |
307 skb->len = ETH_HLEN + size; |
338 |
308 |
339 if (unlikely(device->master->debug_level > 1)) { |
309 if (unlikely(device->master->debug_level > 1)) { |
340 EC_MASTER_DBG(device->master, 2, "Sending frame:\n"); |
310 EC_MASTER_DBG(device->master, 2, "Sending frame:\n"); |
348 #else |
318 #else |
349 if (device->dev->hard_start_xmit(skb, device->dev) == NETDEV_TX_OK) |
319 if (device->dev->hard_start_xmit(skb, device->dev) == NETDEV_TX_OK) |
350 #endif |
320 #endif |
351 { |
321 { |
352 device->tx_count++; |
322 device->tx_count++; |
|
323 device->master->device_stats.tx_count++; |
353 device->tx_bytes += ETH_HLEN + size; |
324 device->tx_bytes += ETH_HLEN + size; |
|
325 device->master->device_stats.tx_bytes += ETH_HLEN + size; |
354 #ifdef EC_DEBUG_IF |
326 #ifdef EC_DEBUG_IF |
355 ec_debug_send(&device->dbg, skb->data, ETH_HLEN + size); |
327 ec_debug_send(&device->dbg, skb->data, ETH_HLEN + size); |
356 #endif |
328 #endif |
357 #ifdef EC_DEBUG_RING |
329 #ifdef EC_DEBUG_RING |
358 ec_device_debug_ring_append( |
330 ec_device_debug_ring_append( |
373 { |
345 { |
374 unsigned int i; |
346 unsigned int i; |
375 |
347 |
376 // zero frame statistics |
348 // zero frame statistics |
377 device->tx_count = 0; |
349 device->tx_count = 0; |
|
350 device->last_tx_count = 0; |
378 device->rx_count = 0; |
351 device->rx_count = 0; |
|
352 device->last_rx_count = 0; |
|
353 device->tx_bytes = 0; |
|
354 device->last_tx_bytes = 0; |
|
355 device->rx_bytes = 0; |
|
356 device->last_rx_bytes = 0; |
379 device->tx_errors = 0; |
357 device->tx_errors = 0; |
380 device->tx_bytes = 0; |
358 |
381 device->last_tx_count = 0; |
|
382 device->last_tx_bytes = 0; |
|
383 device->last_loss = 0; |
|
384 for (i = 0; i < EC_RATE_COUNT; i++) { |
359 for (i = 0; i < EC_RATE_COUNT; i++) { |
385 device->tx_frame_rates[i] = 0; |
360 device->tx_frame_rates[i] = 0; |
|
361 device->rx_frame_rates[i] = 0; |
386 device->tx_byte_rates[i] = 0; |
362 device->tx_byte_rates[i] = 0; |
387 device->loss_rates[i] = 0; |
363 device->rx_byte_rates[i] = 0; |
388 } |
364 } |
389 } |
365 } |
390 |
366 |
391 /*****************************************************************************/ |
367 /*****************************************************************************/ |
392 |
368 |
475 device->jiffies_poll = jiffies; |
451 device->jiffies_poll = jiffies; |
476 #ifdef EC_DEBUG_RING |
452 #ifdef EC_DEBUG_RING |
477 do_gettimeofday(&device->timeval_poll); |
453 do_gettimeofday(&device->timeval_poll); |
478 #endif |
454 #endif |
479 device->poll(device->dev); |
455 device->poll(device->dev); |
|
456 } |
|
457 |
|
458 /*****************************************************************************/ |
|
459 |
|
460 /** Update device statistics. |
|
461 */ |
|
462 void ec_device_update_stats( |
|
463 ec_device_t *device /**< EtherCAT device */ |
|
464 ) |
|
465 { |
|
466 unsigned int i; |
|
467 |
|
468 u32 tx_frame_rate = |
|
469 (u32) (device->tx_count - device->last_tx_count) * 1000; |
|
470 u32 rx_frame_rate = |
|
471 (u32) (device->rx_count - device->last_rx_count) * 1000; |
|
472 u32 tx_byte_rate = |
|
473 (device->tx_bytes - device->last_tx_bytes); |
|
474 u32 rx_byte_rate = |
|
475 (device->rx_bytes - device->last_rx_bytes); |
|
476 |
|
477 for (i = 0; i < EC_RATE_COUNT; i++) { |
|
478 unsigned int n = rate_intervals[i]; |
|
479 device->tx_frame_rates[i] = |
|
480 (device->tx_frame_rates[i] * (n - 1) + tx_frame_rate) / n; |
|
481 device->rx_frame_rates[i] = |
|
482 (device->rx_frame_rates[i] * (n - 1) + rx_frame_rate) / n; |
|
483 device->tx_byte_rates[i] = |
|
484 (device->tx_byte_rates[i] * (n - 1) + tx_byte_rate) / n; |
|
485 device->rx_byte_rates[i] = |
|
486 (device->rx_byte_rates[i] * (n - 1) + rx_byte_rate) / n; |
|
487 } |
|
488 |
|
489 device->last_tx_count = device->tx_count; |
|
490 device->last_rx_count = device->rx_count; |
|
491 device->last_tx_bytes = device->tx_bytes; |
|
492 device->last_rx_bytes = device->rx_bytes; |
480 } |
493 } |
481 |
494 |
482 /****************************************************************************** |
495 /****************************************************************************** |
483 * Device interface |
496 * Device interface |
484 *****************************************************************************/ |
497 *****************************************************************************/ |
591 __func__); |
604 __func__); |
592 return; |
605 return; |
593 } |
606 } |
594 |
607 |
595 device->rx_count++; |
608 device->rx_count++; |
|
609 device->master->device_stats.rx_count++; |
|
610 device->rx_bytes += size; |
|
611 device->master->device_stats.rx_bytes += size; |
596 |
612 |
597 if (unlikely(device->master->debug_level > 1)) { |
613 if (unlikely(device->master->debug_level > 1)) { |
598 EC_MASTER_DBG(device->master, 2, "Received frame:\n"); |
614 EC_MASTER_DBG(device->master, 2, "Received frame:\n"); |
599 ec_print_data(data, size); |
615 ec_print_data(data, size); |
600 } |
616 } |