PERFORCE change 180356 for review

Alexandre Fiveg afiveg at FreeBSD.org
Thu Jul 1 00:17:30 UTC 2010


http://p4web.freebsd.org/@@180356?ac=10

Change 180356 by afiveg at cottonmouth on 2010/07/01 00:16:33

	Using EM_RX_LOCK for locking the ringmap data structures

Affected files ...

.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap.c#5 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/ringmap_pcap.c#10 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.c#18 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.h#16 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.c#17 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.h#15 edit
.. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.c#21 edit
.. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.h#21 edit
.. //depot/projects/soc2010/ringmap/scripts/build_ringmap.sh#5 edit
.. //depot/projects/soc2010/ringmap/scripts/set_ringmap.sh#6 edit
.. //depot/projects/soc2010/ringmap/tests/libpcap/easy_pcap.c#6 edit
.. //depot/projects/soc2010/ringmap/tests/libpcap/test_pcap.c#5 edit

Differences ...

==== //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap.c#5 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/contrib/libpcap/ringmap_pcap.c#10 (text+ko) ====

@@ -347,7 +347,7 @@
 		goto again;
 	}
 
-	if (cnt == -1)
+	if ( (cnt == -1) || (cnt == 0) )
 		cnt = SW_TAIL_TO_HEAD_DIST(p->ring);
 
 	for (ws = cnt ; ( (ws) && (RING_NOT_EMPTY(p->ring)) ) ; ) 

==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.c#18 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.h#16 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.c#17 (text+ko) ====

@@ -47,25 +47,22 @@
 {
 	struct adapter *adapter = (struct adapter *)device_get_softc(dev);
 
-	if ( adapter == NULL ) 
+	if ( (adapter == NULL) || (ring == NULL) ) 
 		goto out;
 
 	/* Disable interrupts of adapter */
 	rm_8254_disable_intr(dev);
 
-	/* 
-	 * Check whether we have some tasks in the queue. It should be done 
-	 * because we want to free the memory regions that could be accessed  
-	 * from the delayed interrupt tasks
-	 */
-	taskqueue_run(adapter->tq);
-	
-	if (ring != NULL){
-		contigfree(ring, sizeof(struct ring), M_DEVBUF);
-	} else {
-		RINGMAP_ERROR(The pointer to ring structure is NULL);
-	}
+	EM_RX_LOCK(adapter);
+
+	contigfree(ring, sizeof(struct ring), M_DEVBUF);
+
+	adapter->rm->ring = NULL;
+
+	EM_RX_UNLOCK(adapter);
+
 out: ;
+
 }
 
 struct ring *
@@ -74,7 +71,7 @@
 	struct ring *ring;
 	struct adapter *adapter = (struct adapter *)device_get_softc(dev);
 
-	if ( adapter == NULL ) {
+	if ( (adapter == NULL) || (adapter->rm == NULL) ) {
 		return (NULL);
 	}
 	
@@ -93,12 +90,7 @@
 
 	/* Disable interrupts of adapter while allocating the ring */
 	rm_8254_disable_intr(dev);
-
-	/* 
-	 * Before continue look whether any delayed interrupt tasks are 
-	 * in the taskqueue.
-	 */
-	taskqueue_run(adapter->tq);
+	EM_RX_LOCK(adapter);
 	
 	/* Set ring fields in the initial state */
 	ring->kern_wait_user = 0;
@@ -111,9 +103,28 @@
 		RINGMAP_ERROR(The ring is not initialized. Device will not be opened!);
 		contigfree(ring, sizeof(struct ring), M_DEVBUF);
 
+		EM_RX_UNLOCK(adapter);
+		rm_8254_enable_intr(dev);
+
 		return (NULL);
 	}	
+	
+	/**
+	 **	Currently only one process only one time can open our device !!!
+	 **/
+	if (!atomic_cmpset_int(&adapter->rm->open_cnt, 0, 1)){
+		RINGMAP_ERROR(Sorry! Can not open device more then one time!);
+		atomic_readandclear_int(&adapter->rm->open_cnt); 
+
+		EM_RX_UNLOCK(adapter);
+		rm_8254_enable_intr(dev);
+
+		return (NULL);
+	}
 
+	adapter->rm->ring = ring;
+
+	EM_RX_UNLOCK(adapter);
 	rm_8254_enable_intr(dev);
 
 	return (ring);
@@ -123,14 +134,17 @@
 rm_8254_delayed_interrupt_per_packet(struct ring *ring, int slot_num)
 {
 	RINGMAP_INTR(start);
-	ring->cur_slot_kern = slot_num;
-	ring->slot[slot_num].is_ok = 1;
-	ring->slot[slot_num].intr_num = ring->interrupts_counter;
+
+	if ( ring != NULL ) {
+		ring->cur_slot_kern = slot_num;
+		ring->slot[slot_num].is_ok = 1;
+		ring->slot[slot_num].intr_num = ring->interrupts_counter;
 
 #ifdef RINGMAP_TIMESTAMP
-	ring->slot[slot_num].ts.tv_sec = ring->last_ts.tv_sec;
-	ring->slot[slot_num].ts.tv_usec = ring->last_ts.tv_usec;
+		ring->slot[slot_num].ts.tv_sec = ring->last_ts.tv_sec;
+		ring->slot[slot_num].ts.tv_usec = ring->last_ts.tv_usec;
 #endif 
+	}
 
 	RINGMAP_INTR(end);
 }

==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.h#15 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/sys/net/ringmap.c#21 (text+ko) ====

@@ -43,7 +43,6 @@
 device_t 		(*get_device_p)(struct cdev *);
 
 extern int rm_8254_set_ringmap_to_adapter(device_t, struct ringmap *);
-extern int rm_8254_init_slots(struct ring *, device_t);
 extern struct ringmap * rm_8254_get_ringmap_p(device_t);
 extern device_t rm_8254_get_device_p(struct cdev *);
 extern void rm_8254_enable_intr(device_t);
@@ -120,7 +119,6 @@
 				rm_8254_set_ringmap_to_adapter;
 			rm->funcs->enable_intr  		= rm_8254_enable_intr;
 			rm->funcs->disable_intr 		= rm_8254_disable_intr;
-			rm->funcs->init_slots 			= rm_8254_init_slots;
 			rm->funcs->isr		 			= rm_8254_interrupt;
 			rm->funcs->delayed_isr			= rm_8254_delayed_interrupt;
 			rm->funcs->delayed_isr_per_packet = 
@@ -176,7 +174,6 @@
 		return (-1); 
 	}
 
-
 	funcs = (struct ringmap_functions *) contigmalloc 
 			(
 				sizeof (struct ringmap_functions),
@@ -266,35 +263,29 @@
 
 	/* a little magic */
 	rm = get_ringmap_p(get_device_p(cdev));
-	if (rm == NULL) {
+	if ( rm == NULL ) {
 		RINGMAP_ERROR(Null pointer to ringmap structure);
 
 		return (EIO);
 	}
 	
-	/**
-	 **	Currently only one process only one time can open our device !!!
-	 **/
-	if (!atomic_cmpset_int(&rm->open_cnt, 0, 1)){
-		RINGMAP_ERROR(Sorry! Can not open device more then one time!);
-		atomic_readandclear_int(&rm->open_cnt); 
 
-		return (EIO);
-	}
-
-	if (rm->dev == NULL){
+	if ( rm->dev == NULL ) {
 		RINGMAP_ERROR(Null pointer to device structure of adapter);
-		atomic_readandclear_int(&rm->open_cnt); 
 
 		return (EIO);
 	}
 	
 	/* Allocate ring */
-	rm->ring = rm->funcs->alloc_ring(rm->dev);
-	if (rm->ring == NULL){
+	if ( rm->funcs->alloc_ring(rm->dev ) == NULL) {
 		RINGMAP_ERROR(Null pointer to ring the structure);
-		atomic_readandclear_int(&rm->open_cnt); 
+
+		return (EIO);
+	}
 
+	/* Check for any cases */
+	if ( rm->ring == NULL ) {
+		RINGMAP_ERROR(Error! Please debug!);
 		return (EIO);
 	}
 

==== //depot/projects/soc2010/ringmap/current/sys/net/ringmap.h#21 (text+ko) ====


==== //depot/projects/soc2010/ringmap/scripts/build_ringmap.sh#5 (text+ko) ====


==== //depot/projects/soc2010/ringmap/scripts/set_ringmap.sh#6 (text+ko) ====


==== //depot/projects/soc2010/ringmap/tests/libpcap/easy_pcap.c#6 (text+ko) ====

@@ -15,31 +15,66 @@
 #include "../../current/sys/net/ringmap.h"
 
 
-
 int capture_pkts (const char*);
 void got_packet(u_char *, const struct pcap_pkthdr *, const u_char *);
-
+void stop_cpusage_measurement(void);
+void start_cpusage_measurement(void);
+void exitFunc(void);
+void sig_ctrlc(int);
+void sig_alarm(int);
 
 pcap_t *handle;
-unsigned int pcnt = 0;
+unsigned long pcnt = 0;
+long pkt_limit = 0;
 
-#define HOWMANY 20
+/* Time stamps from first and last captured packets */
+struct timeval first_timestamp ;
+struct timeval last_timestamp ;
 
 int
 main(int argc, char **argv)
 {
 	char *iface;
 
-	if (argc < 2) {
-		printf("Usage: %s iface \n", argv[0]);
+	/* Proof the number of parameters */
+	if (argc < 3) {
+		printf("Usage: %s iface pkt_limit\n", argv[0]);
 		exit(1);
 	}
 
+	/* Network interface name */
 	iface = argv[1];
 
+	/* Packets number */
+	pkt_limit = strtol(argv[2], NULL, 10);
+	if ( (pkt_limit == 0) && (errno == EINVAL)){
+		printf("Wrong second parameter\n");
+		exit (1);
+	}
+	if ( pkt_limit < 0 )
+		pkt_limit = -1;
+
+	/* Register Exit function */
+	if (atexit(exitFunc)){
+		printf("Error: Can't register exit function!\n");
+		exit(1);
+	}
+
+	/* Register signals */
+	if (signal(SIGINT, sig_ctrlc) == SIG_ERR){
+		printf("Error: Can't register signal\n");
+		exit(1);
+	}
+	if (signal(SIGALRM, sig_alarm) == SIG_ERR){
+		printf("Error: Can't register signal\n");
+		exit(1);
+	}
+
+	/* Let's go to capture */
 	capture_pkts(iface);
 
-	return (0);
+	/* Call our exitFunc() to end the job */
+	exit(0);
 }
 
 int 
@@ -53,11 +88,8 @@
 		return (-1);	
 	}
 
-	pcap_loop(handle, HOWMANY, got_packet, NULL);
-	
-	if (handle != NULL)
-		pcap_close(handle);	
-	
+	pcap_loop(handle, pkt_limit, got_packet, NULL);
+
 	return (0);
 }
 
@@ -65,8 +97,85 @@
  * Callback function. Will called for each captured packet
  */
 void
-got_packet(u_char *args, const struct pcap_pkthdr *header, const u_char *packet)
+got_packet(u_char *args, const struct pcap_pkthdr *header,
+		const u_char *packet)
 {
 	pcnt++;
-	printf("===> [%s] Packet %d \n", __func__, pcnt);
+	if ( pcnt == 1 ){
+		start_cpusage_measurement();
+		first_timestamp = header->ts;
+	}
+	last_timestamp = header->ts;
+
+	printf("\n===> [%s] Packet %d\n", __func__, pcnt);
+}
+
+/*
+ * Signal function for catching Ctrl-C
+ */
+void 
+sig_ctrlc(int signo)
+{
+	if (signo == SIGINT) {
+		printf("Stop Capturing. Exit!\n");
+		exit(0);
+	}
+}
+
+void 
+sig_alarm(int signo)
+{
+	if (signo == SIGALRM){
+		printf("Stop capturing. Exit!\n");
+		exit(0);
+	}
+}
+
+/* Exit Point */
+void
+exitFunc()
+{
+	unsigned long pps = 0;
+	unsigned long cap_time = 0;
+		
+	stop_cpusage_measurement();
+
+	cap_time = 
+		((last_timestamp.tv_sec*1000000+last_timestamp.tv_usec)  - 
+		(first_timestamp.tv_sec*1000000+first_timestamp.tv_usec))/1000000;
+	if ( !cap_time )
+		cap_time = 1;
+
+	pps = pcnt / cap_time;
+
+	/* Print stats */
+	printf("\n\nRESULTS:\n \n");
+	printf("++++++++++++++++++++++++++++++++++++++++++++++++++ \n");
+	printf("\n");
+	printf("PROCESS STATISTICS: \n");
+	printf("------------------  \n");
+	printf("Captured: %lu pkts\n", pcnt);
+	printf("Capturing time: %lu (seconds)\n", cap_time);
+	printf("Packets per Second: %lu \n", pps);
+	printf("------------------\n\n");
+
+#ifdef RINGMAP
+	/* Our function from libpcap */
+	printf("RINGMAP STATISTICS: \n");
+	printf("------------------  \n");
+#endif 
+
+
+	/* close pcap */
+	if (handle != NULL)
+		pcap_close(handle);
+}
+
+void stop_cpusage_measurement()
+{
+	;
+}
+void start_cpusage_measurement()
+{
+	;
 }

==== //depot/projects/soc2010/ringmap/tests/libpcap/test_pcap.c#5 (text+ko) ====



More information about the p4-projects mailing list