Browse Source

Add trivial net device statistics (TX and RX packet count), reported

via UNDI API and also by ifstat command; may be useful for debugging.
tags/v0.9.3
Michael Brown 17 years ago
parent
commit
4968caab82
4 changed files with 38 additions and 10 deletions
  1. 13
    0
      src/include/gpxe/netdevice.h
  2. 13
    8
      src/interface/pxe/pxe_undi.c
  3. 9
    0
      src/net/netdevice.c
  4. 3
    2
      src/usr/ifmgmt.c

+ 13
- 0
src/include/gpxe/netdevice.h View File

@@ -128,6 +128,17 @@ struct ll_protocol {
128 128
 	const uint8_t *ll_broadcast;
129 129
 };
130 130
 
131
+/**
132
+ * Network device statistics
133
+ *
134
+ */
135
+struct net_device_stats {
136
+	/** Count of successfully completed transmissions */
137
+	unsigned int tx_count;
138
+	/** Count of successfully received packets */
139
+	unsigned int rx_count;
140
+};
141
+
131 142
 /**
132 143
  * A network device
133 144
  *
@@ -215,6 +226,8 @@ struct net_device {
215 226
 	struct list_head tx_queue;
216 227
 	/** RX packet queue */
217 228
 	struct list_head rx_queue;
229
+	/** Device statistics */
230
+	struct net_device_stats stats;
218 231
 
219 232
 	/** Driver private data */
220 233
 	void *priv;

+ 13
- 8
src/interface/pxe/pxe_undi.c View File

@@ -343,28 +343,33 @@ PXENV_EXIT_t pxenv_undi_get_information ( struct s_PXENV_UNDI_GET_INFORMATION
343 343
 
344 344
 /* PXENV_UNDI_GET_STATISTICS
345 345
  *
346
- * Status: won't implement (would require driver API changes for no
347
- * real benefit)
346
+ * Status: working
348 347
  */
349 348
 PXENV_EXIT_t pxenv_undi_get_statistics ( struct s_PXENV_UNDI_GET_STATISTICS
350 349
 					 *undi_get_statistics ) {
351 350
 	DBG ( "PXENV_UNDI_GET_STATISTICS" );
352 351
 
353
-	undi_get_statistics->Status = PXENV_STATUS_UNSUPPORTED;
354
-	return PXENV_EXIT_FAILURE;
352
+	undi_get_statistics->XmtGoodFrames = pxe_netdev->stats.tx_count;
353
+	undi_get_statistics->RcvGoodFrames = pxe_netdev->stats.rx_count;
354
+	undi_get_statistics->RcvCRCErrors = 0;
355
+	undi_get_statistics->RcvResourceErrors = 0;
356
+
357
+	undi_get_statistics->Status = PXENV_STATUS_SUCCESS;
358
+	return PXENV_EXIT_SUCCESS;
355 359
 }
356 360
 
357 361
 /* PXENV_UNDI_CLEAR_STATISTICS
358 362
  *
359
- * Status: won't implement (would require driver API changes for no
360
- * real benefit)
363
+ * Status: working
361 364
  */
362 365
 PXENV_EXIT_t pxenv_undi_clear_statistics ( struct s_PXENV_UNDI_CLEAR_STATISTICS
363 366
 					   *undi_clear_statistics ) {
364 367
 	DBG ( "PXENV_UNDI_CLEAR_STATISTICS" );
365 368
 
366
-	undi_clear_statistics->Status = PXENV_STATUS_UNSUPPORTED;
367
-	return PXENV_EXIT_FAILURE;
369
+	memset ( &pxe_netdev->stats, 0, sizeof ( pxe_netdev->stats ) );
370
+
371
+	undi_clear_statistics->Status = PXENV_STATUS_SUCCESS;
372
+	return PXENV_EXIT_SUCCESS;
368 373
 }
369 374
 
370 375
 /* PXENV_UNDI_INITIATE_DIAGS

+ 9
- 0
src/net/netdevice.c View File

@@ -95,8 +95,12 @@ void netdev_tx_complete ( struct net_device *netdev, struct io_buffer *iobuf ) {
95 95
 	assert ( iobuf->list.next != NULL );
96 96
 	assert ( iobuf->list.prev != NULL );
97 97
 
98
+	/* Dequeue and free I/O buffer */
98 99
 	list_del ( &iobuf->list );
99 100
 	free_iob ( iobuf );
101
+
102
+	/* Update statistics counter */
103
+	netdev->stats.tx_count++;
100 104
 }
101 105
 
102 106
 /**
@@ -140,7 +144,12 @@ static void netdev_tx_flush ( struct net_device *netdev ) {
140 144
 void netdev_rx ( struct net_device *netdev, struct io_buffer *iobuf ) {
141 145
 	DBGC ( netdev, "NETDEV %p received %p (%p+%zx)\n",
142 146
 	       netdev, iobuf, iobuf->data, iob_len ( iobuf ) );
147
+
148
+	/* Enqueue packet */
143 149
 	list_add_tail ( &iobuf->list, &netdev->rx_queue );
150
+
151
+	/* Update statistics counter */
152
+	netdev->stats.rx_count++;
144 153
 }
145 154
 
146 155
 /**

+ 3
- 2
src/usr/ifmgmt.c View File

@@ -61,7 +61,8 @@ void ifclose ( struct net_device *netdev ) {
61 61
  * @v netdev		Network device
62 62
  */
63 63
 void ifstat ( struct net_device *netdev ) {
64
-	printf ( "%s: %s on %s (%s)\n",
64
+	printf ( "%s: %s on %s (%s) TX:%d RX:%d\n",
65 65
 		 netdev->name, netdev_hwaddr ( netdev ), netdev->dev->name,
66
-		 ( ( netdev->state & NETDEV_OPEN ) ? "open" : "closed" ) );
66
+		 ( ( netdev->state & NETDEV_OPEN ) ? "open" : "closed" ),
67
+		 netdev->stats.tx_count, netdev->stats.rx_count );
67 68
 }

Loading…
Cancel
Save