Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Jun 2010 17:37:45 GMT
From:      Alexandre Fiveg <afiveg@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 180191 for review
Message-ID:  <201006241737.o5OHbjV3046754@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@180191?ac=10

Change 180191 by afiveg@cottonmouth on 2010/06/24 17:36:53

	cosmetic fixes

Affected files ...

.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-int.h#3 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/ringmap_pcap.c#3 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.c#11 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.h#9 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.c#10 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.h#8 edit
.. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.c#14 edit
.. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.h#14 edit

Differences ...

==== //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-int.h#3 (text+ko) ====


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

@@ -133,9 +133,6 @@
 		return (-1); 
 	}
 
-	/* STOP CAPTURING */
-	// ringmap_disable_capturing();
-
 #if (__RINGMAP_DEB)
 	printf("[%s] Number of descriptors: %d \n", __func__, SLOTS_NUMBER);
 #endif
@@ -203,23 +200,19 @@
 		}
 		p->ring->slot[i].mbuf.user = (vm_offset_t)tmp_addr;
 
+
 		/* Map packet data */
 		memoffset = (off_t)p->ring->slot[i].packet.phys;
 		tmp_addr = 
-			mmap (		
-				0, 						/*	System will choose the addrress */
-				MCLBYTES,				/*	Size of region = mbuf cluster	*/
-				PROT_WRITE|PROT_READ,	/*	protection: write & read 		*/
-				MAP_SHARED,				/*	shared maping					*/
-				devmem_fd,				/*	device is /dev/mem				*/
-				memoffset				/*	offset is physical addres 		*/
-			);
+			mmap(0, MCLBYTES, PROT_WRITE|PROT_READ, MAP_SHARED,				
+				devmem_fd, memoffset);
 		if (tmp_addr == MAP_FAILED){
-			printf(ERR_PREFIX"[%s] Mapping of packet buffer %d failed! Exit!\n", __func__, i);
+			printf(ERR_PREFIX"[%s] Mapping of packets buffer %d failed! Exit!\n", __func__, i);
 			return -1;
 		}
 		p->ring->slot[i].packet.user = (vm_offset_t)tmp_addr;
 		
+
 //		/* Map descriptor structure */
 //		memoffset = (off_t)p->ring->slot[i].descriptor.phys;
 //		tmp_addr = 
@@ -257,16 +250,13 @@
 //	p->buffer_2048 	=	0;
 //	p->buffer_4096	=	0;
 
-	/* Disable Flow Control on the NIC */
-	// ioctl(ringmap_cdev_fd, IOCTL_DISABLE_FLOWCNTR); 
 
 	/* Close memory device */
 	if (close(devmem_fd) == -1){
 		perror("close()");
 	}
 
-	/* START CAPTURING */
-	//ringmap_enable_capturing();
+	RINGMAP_FUNC_DEBUG(end);
 
 	return (0);
 }
@@ -279,8 +269,6 @@
 {
 	int tmp_res, i;
 
-	// ringmap_disable_capturing();
-
 	RINGMAP_FUNC_DEBUG(start);
 
 	for (i = 0; i < SLOTS_NUMBER; i++){
@@ -321,28 +309,38 @@
 pcap_read_ringmap(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
 {
 	unsigned int ws,  wait_flag = 1, tmp_dist; 
+	unsigned int curr_slot;
 	struct mbuf *mb; 
 	caddr_t datap; 
 	struct pcap_pkthdr pkthdr;
+	struct ring *ring;
 
 	RINGMAP_FUNC_DEBUG(start);
 
+	if (p->ring == NULL){
+		RINGMAP_ERROR(Ring is not allocated);
+
+		exit (1);
+	}
+
+	ring = p->ring;
+
 	if (p->break_loop) {
 		p->break_loop = 0;
 		return (-2);
 	}
 
-again1: 
+again: 
 	
 #ifdef __RINGMAP_DEB
-	printf("[%s] user kern distance = %d\n", __func__, 
-			SW_TAIL_TO_HEAD_DIST(p->ring));
+	printf("[%s] user to kern distance = %d\n", __func__, 
+			SW_TAIL_TO_HEAD_DIST(ring));
 #endif
 
-	if ( RING_IS_EMPTY(p->ring) ) {
+	if ( RING_IS_EMPTY(ring) ) {
 		/* Sleep and wait for new incoming packets */
 		ioctl(ringmap_cdev_fd, IOCTL_SLEEP_WAIT);
-		goto again1;
+		goto again;
 	}
 
 	if (cnt == -1)
@@ -358,15 +356,18 @@
 				return (cnt - ws);
 		}
 
-		mb = (struct mbuf *)p->ring->slot[p->ring->userrp].mbuf.user;
+		curr_slot = R_MODULO(SW_TAIL(ring) + 1);
+
+		mb = (struct mbuf *)ring->slot[curr_slot].mbuf.user;
 
-		pkthdr.ts = p->ring->slot[p->ring->userrp].ts;
+		pkthdr.ts = ring->slot[curr_slot].ts;
 		pkthdr.caplen = pkthdr.len = mb->m_len;
-		datap = (caddr_t)p->ring->slot[p->ring->userrp].packet.user;
+		datap = (caddr_t)ring->slot[curr_slot].packet.user;
 
 		(*callback)(user, &pkthdr, datap);
 
-		INC_TAIL(p->ring);
+		INC_TAIL(ring);
+		ring->pkt_counter++;
 
 		--ws;
 	} 
@@ -376,42 +377,9 @@
 	return (cnt - ws);
 }
 
-/*
- * Set hardware registers to enabling pkts receive and interrupts on NIC
- */
-//void 
-//ringmap_enable_capturing()
-//{
-//	if (ringmap_cdev_fd > 0){
-//		ioctl(ringmap_cdev_fd, IOCTL_ENABLE_RECEIVE);
-//	}else{
-//		printf("[%s] Error: Wrong descriptor of /dev/fiveg_cdev \n", __func__);
-//		printf("[%s] Error: Can't enable pkt receive \n", __func__);
-//
-//		/* TODO: set return and check returned value */
-//		exit(1);
-//	}
-//}
 
 /*
- * Set hardware registers to disabling pkts receive and interrupts on NIC
- */
-//void 
-//ringmap_disable_capturing()
-//{
-//	if (ringmap_cdev_fd > 0)
-//		ioctl(ringmap_cdev_fd, IOCTL_DISABLE_RECEIVE);
-//	else{
-//		printf("[%s] Error: Wrong descriptor of /dev/fiveg_cdev \n", __func__);
-//		printf("[%s] Error: Can't disable pkt receive \n", __func__);
-//		
-//		/* TODO: set return and check returned value */
-//		exit(1);
-//	}
-//}
-
-/*
- * Prints Kern(Hardware)- and User(Software)-Pointers
+ * Prints HEAD (kern) and TAIL (user) pointers
  * Return Value: 
  * 	-1	-	Error
  */
@@ -423,8 +391,8 @@
 	if (p->ring == NULL)
 		return (-1);
 
-	printf("Hardware Pointer (kern) = %d\n", p->ring->kernrp);
-	printf("Software Pointer (user)	= %d\n", p->ring->userrp);
+	printf("HEAD Pointer (kern) = %d\n", SW_HEAD(p->ring));
+	printf("TAIL Pointer (user)	= %d\n", SW_TAIL(p->ring));
 
 	return (err);
 }
@@ -434,16 +402,20 @@
 {
 	int err = 0;
 
-	if (p->ring == NULL)
+	if (p->ring == NULL){
+		RINGMAP_ERROR(Ring is not allocated!);
+
 		return (-1);
+	}
 
 	printf("\nSYSTEM STATISTICS:\n");
 	printf("----------------- \n");
-	printf("Kernel waited for user capturing process:  %llu\n", p->ring->kern_wait_user);
-	printf("Capturing User process waited for kernel:  %llu\n", p->ring->user_wait_kern);
+	printf("Ring-Full  counter:  %llu\n", p->ring->kern_wait_user);
+	printf("Ring-Empty counter:  %llu\n", p->ring->user_wait_kern);
 
 	printf("Number of interrupts: %llu\n", p->ring->interrupts_counter);
-	// printf("Packets per Interrupt: %llu\n", (((unsigned long long )p->pkt_counter) / p->ring->interrupts_counter));
+	printf("Packets per Interrupt: %llu\n", 
+		(((unsigned long long )p->ring->pkt_counter) / p->ring->interrupts_counter));
 
 	return (err);
 }

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


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


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

@@ -132,17 +132,10 @@
 		return (-1);
 	}
 	
-	/* Set ring fields in the initial state */
-	ring->kern_wait_user = 0;	
-    ring->user_wait_kern = 0;	
-    ring->interrupts_counter = 0;	
-
 	RINGMAP_HW_WRITE_TAIL(adapter, 
 			(R_MODULO(RINGMAP_HW_READ_HEAD(adapter) - 1))); 
 
-	ring->userrp = RINGMAP_HW_READ_TAIL(adapter);
-	ring->size = SLOTS_NUMBER;		
-
+	SW_TAIL(ring) = RINGMAP_HW_READ_TAIL(adapter);
 
 	/* Set ring pointers */
 	for (slot_num = 0 ; slot_num < SLOTS_NUMBER ; slot_num ++){

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


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

@@ -107,7 +107,7 @@
 
 	switch(controller_type) {
 		case 8254:
-			RINGMAP_OUTPUT(Controller Type: 8254);
+			RINGMAP_FUNC_DEBUG(Controller Type: 8254);
 			
 			/* Set ringmap pointer in the drivrs structure of adapter */
 			rm->funcs->set_ringmap_to_adapter = 
@@ -124,13 +124,13 @@
 		break;
 
 		case 8257:
-			RINGMAP_OUTPUT(Controller Type: 8257);
-			RINGMAP_OUTPUT(Now not supported!);
+			RINGMAP_FUNC_DEBUG(Controller Type: 8257);
+			RINGMAP_FUNC_DEBUG(Now not supported!);
 
 		break;
 
 		default:
-			RINGMAP_OUTPUT(Unsupported Controller Type!);
+			RINGMAP_FUNC_DEBUG(Unsupported Controller Type!);
 	}
 	return (0);
 }
@@ -292,6 +292,13 @@
 
 	/* Disable interrupts of adapter */
 	rm->funcs->disable_intr(rm->dev);
+	
+	/* Set ring fields in the initial state */
+	ring->kern_wait_user = 0;
+    ring->user_wait_kern = 0;
+    ring->interrupts_counter = 0;
+	ring->pkt_counter = 0;
+	ring->size = SLOTS_NUMBER;
 
 	if (rm->funcs->init_slots(rm->ring, rm->dev) == -1){ 
 		RINGMAP_ERROR(The ring is not initialized. Device will not be opened!);
@@ -387,80 +394,39 @@
 	int err = 0, err_sleep = err_sleep;
 	struct ringmap *ringmap = NULL;
 
-//	struct adapter *adapter = (struct adapter *)get_adapter_struct(dev);
-//	struct ringmap *rm = adapter->rm;
-//
-//	unsigned int *userp = NULL;
-//
 	RINGMAP_IOCTL(start);
 
+	/* TODO: use private data to set and get ring from curr. thread */
+	ringmap = get_ringmap_p(get_device_p(cdev));
+	if ((ringmap == NULL) || (ringmap->ring == NULL)){
+		RINGMAP_ERROR(NULL pointer. ioctl can not be accomplished);
+
+		/* TODO: look if ENODEV is a correctly for this case */
+		return(ENODEV);
+	}
+
 	switch( cmd ){
-//
-//		/* Tell to user number of descriptors */
-//		case IOCTL_G_DNUM:
-//			RINGMAP_OUTPUT(IOCTL_G_DNUM);
-//			
-//			userp = (unsigned int *)(*(unsigned int *)data);
-//			if (userp == NULL){
-//				RINGMAP_ERROR(NULL pointer by ioctl IOCTL_G_DNUM);
-//				return (EINVAL);
-//			}
-//
-//			unsigned int dn = (unsigned int)adapter->num_rx_desc;
-//			copyout(&dn, userp, sizeof(unsigned int));
-//
-//		break; 
-//
-//		/* Enable Receive and Interrupts */
-//		case IOCTL_ENABLE_RECEIVE:
-//			RINGMAP_IOCTL(IOCTL_ENABLE_RECEIVE);
-//			RINGMAP_HW_ENABLE_INTR(adapter);
-//			RINGMAP_HW_ENABLE_RECEIVE(adapter);
-//		break;
-//
-//		/* Disable Receive and Interrupts */
-//		case IOCTL_DISABLE_RECEIVE:
-//			RINGMAP_IOCTL(IOCTL_DISABLE_RECEIVE);
-//			RINGMAP_HW_DISABLE_INTR(adapter);
-//			RINGMAP_HW_DISABLE_RECEIVE(adapter);
-//		break;
-//		
-//		/* Disable Flow Control */
-//		case IOCTL_DISABLE_FLOWCNTR:
-//			RINGMAP_IOCTL(IOCTL_DISABLE_FLOWCNTR);
-//			RINGMAP_HW_DISABLE_FLOWCONTR(adapter);
-//		break;
-//
+
+		/* Enable  Interrupts */
+		case IOCTL_ENABLE_INTR:
+			ringmap->funcs->enable_intr(ringmap->dev);
+		break;
+
+		/* Disable  Interrupts */
+		case IOCTL_DISABLE_INTR:
+			ringmap->funcs->disable_intr(ringmap->dev);
+		break;
+		
 		/* Sleep and wait for new frames */
 		case IOCTL_SLEEP_WAIT:
-			/* TODO: use private data to set and get ring from curr. thread */
-			ringmap = get_ringmap_p(get_device_p(cdev));
-			if ((ringmap != NULL) && (ringmap->ring != NULL)){
-				ringmap->ring->user_wait_kern++;
-				ringmap->funcs->sync_head_tail(get_device_p(cdev), 
-												ringmap->ring);
-				err_sleep = tsleep(ringmap, (PRI_MIN) | PCATCH, "ioctl", 0);
-			} else {
-				RINGMAP_ERROR(NULL pointer. ioctl can not be accomplished);
-
-				/* TODO: look if ENODEV is a correctly for this case */
-				return(ENODEV);
-			}
+			ringmap->ring->user_wait_kern++;
+			ringmap->funcs->sync_head_tail(get_device_p(cdev), ringmap->ring);
+			err_sleep = tsleep(ringmap, (PRI_MIN) | PCATCH, "ioctl", 0);
 		break;
 
 		/* Synchronize sowftware ring-tail with hardware-ring-tail (RDT) */
 		case IOCTL_SYNC_HEAD_TAIL:
-			/* TODO: use private data to set and get ring from curr. thread */
-			ringmap = get_ringmap_p(get_device_p(cdev));
-			if ((ringmap != NULL) && (ringmap->ring != NULL)){
-				ringmap->funcs->sync_head_tail(get_device_p(cdev), 
-												ringmap->ring);
-			} else {
-				RINGMAP_ERROR(NULL pointer. ioctl can not be accomplished);
-
-				/* TODO: look if ENODEV is a correctly for this case */
-				return(ENODEV);
-			}
+			ringmap->funcs->sync_head_tail(get_device_p(cdev), ringmap->ring);
 		break;
 
 		default:

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

@@ -101,15 +101,15 @@
 
 	/* 
 	 * Number of times kernel (hardware) waits for user process. More
-	 * specifically, this is the number of times that the write pointer (RDT)
-	 * bumps into the slot whose number is (userrp - RING_SAFETY_MARGIN = RDT)
+	 * specifically, this is the number of times that the write pointer (HEAD)
+	 * bumps into the slot whose number is stored in TAIL register
 	 *
 	 * A.K.A. Hardware is writing faster than the userprocess can read
 	 */
 	unsigned long long kern_wait_user;
 
 	/* 
-	 * Number of times the user process bumps into the RDH.
+	 * Number of times the user process bumps into the HEAD.
 	 *
 	 * A.K.A. User process has read everything there is to read in the ring.
 	 */
@@ -118,6 +118,13 @@
 	/* Counts number of hardware interrupts */
 	unsigned long long interrupts_counter;
 
+	/* 
+	 * Number of received packets. This variable should be changed  only in
+	 * user-space. We want to count the packets, that was seen by user-space
+	 * process
+	 */
+	unsigned long long pkt_counter;
+
 	/* Array of slots */
 	struct ring_slot slot[SLOTS_NUMBER];
 };
@@ -221,21 +228,28 @@
  * *************************************/
 #define RINGMAP_IOC_MAGIC	'T'
 
-/* Start capturing. Enable packets receive and interrupts on NIC */
-#define IOCTL_ENABLE_RECEIVE	_IO(RINGMAP_IOC_MAGIC, 3)
+/* RDT = (userrp - RING_SAFETY_MARGIN) mod SLOTS_NUMBER */
+#define IOCTL_SYNC_HEAD_TAIL	_IO(RINGMAP_IOC_MAGIC, 2) 
+/* 
+ * Disable interrupts on NIC. In some cases it is safe 
+ * to disable interrupts in order to avoid kernel panics 
+ */
+#define IOCTL_DISABLE_INTR		_IO(RINGMAP_IOC_MAGIC, 4)
 
-/* Disable packets receive and interrupts on NIC */
-#define IOCTL_DISABLE_RECEIVE	_IO(RINGMAP_IOC_MAGIC, 4)
+/* Enable interrupts on NIC */
+#define IOCTL_ENABLE_INTR		_IO(RINGMAP_IOC_MAGIC, 3)
 
-/* Sleep and wait for new pkts in ring buffer */
+/* 
+ * Sleep and wait for new pkts in ring buffer. By this 
+ * system call should the user-space process be blocked 
+ * and should be awoken from ISR or delayed ISR after the  
+ * new packets was received. Additional in kontext of this
+ * syscall hardware HEAD and TAIL registers should be 
+ * synchronized with ring->kernerp and ring->userrp
+ */
 #define IOCTL_SLEEP_WAIT		_IO(RINGMAP_IOC_MAGIC, 5)
 
-/* Disable Flow Control */
-#define IOCTL_DISABLE_FLOWCNTR	_IO(RINGMAP_IOC_MAGIC, 6) 
 
-/* RDT = (userrp - RING_SAFETY_MARGIN) mod SLOTS_NUMBER */
-#define IOCTL_SYNC_HEAD_TAIL	_IO(RINGMAP_IOC_MAGIC, 2) 
-
 /**********************************************
  *  	Arithmetic in Ring Buffer	
  **********************************************/
@@ -314,25 +328,24 @@
 #define RINGMAP_PREFIX 	"--> RINGMAP: " 
 #define ERR_PREFIX 		"--> RINGMAP ERROR: " 
 #define WARN_PREFIX 	"--> RINGMAP WARN: "
+#define IOCTL_PREFIX 	"--> RINGMAP IOCTL: "
+#define INTR_PREFIX 	"--> RINGMAP IOCTL: "
 
 #define RINGMAP_ERROR(x) 	\
-	printf("---> RINGMAP ERROR: [%s]: "  #x "\n", __func__);
+	printf(ERR_PREFIX "[%s]: "  #x "\n", __func__);
 
 #define RINGMAP_IOCTL(x)	\
-	if (RINGMAP_IOCTL_DEB) 	printf(" --> RINGMAP IOCTL: " #x "\n");
+	if (RINGMAP_IOCTL_DEB) 	printf(IOCTL_PREFIX "[%s] " #x "\n", __func__);
 
-#define RINGMAP_INTR(x)  	\
-	if (RINGMAP_INTR_DEB) 	\
-		printf("[%s] --> RINGMAP INTR: " #x "\n", __func__);
+#define RINGMAP_INTR(x)  								\
+	if (RINGMAP_INTR_DEB) 								\
+		printf(INTR_PREFIX "[%s] " #x "\n", __func__);
 
 #define RINGMAP_FUNC_DEBUG(x) \
-	if (__RINGMAP_DEB) printf("[%s] --> RINGMAP FUNC: " #x "\n", __func__);
+	if (__RINGMAP_DEB) printf(RINGMAP_PREFIX "[%s] " #x "\n", __func__);
 
-#define RINGMAP_OUTPUT(x) \
-	if (__RINGMAP_DEB) printf("--> RINGMAP: [%s]: "  #x "\n", __func__);
-
 #define RINGMAP_WARN(x) 	\
-	if (__RINGMAP_DEB) printf("--> WARN: [%s]: "  #x "\n", __func__);
+	if (__RINGMAP_DEB) printf(WARN_PREFIX"[%s]: "  #x "\n", __func__);
 
 
 
@@ -347,19 +360,23 @@
 				(unsigned int)adapter->rx_buffer_area[i].m_head->m_data,\
 				(unsigned int)adapter->rx_desc_base[i].buffer_addr);
 
-#define FIVEG_PRINT_SOME_BYTES_FROM_PKT(i)					\
-   printf("[%s] SOME BYTES FROM PKT: %hhX %hhX %hhX %hhX %hhX\n", __func__,	\
+#define FIVEG_PRINT_SOME_BYTES_FROM_PKT(i)							\
+   printf("[%s] SOME BYTES FROM PKT: %hhX %hhX %hhX %hhX %hhX\n", 	\
+		   __func__,	\
 		   adapter->rx_buffer_area[i].m_head->m_data[0],	\
 		   adapter->rx_buffer_area[i].m_head->m_data[1],	\
 		   adapter->rx_buffer_area[i].m_head->m_data[16],	\
 		   adapter->rx_buffer_area[i].m_head->m_data[32],	\
 		   adapter->rx_buffer_area[i].m_head->m_data[59]);	
 #else 
-#define FIVEG_PRINT_SOME_BYTES_FROM_PKT(pktp)					\
-   printf("[%s] SOME BYTES FROM PKT: %hhX %hhX %hhX %hhX %hhX\n", __func__,	\
+#define FIVEG_PRINT_SOME_BYTES_FROM_PKT(pktp)						\
+   printf("[%s] SOME BYTES FROM PKT: %hhX %hhX %hhX %hhX %hhX\n", 	\
+		   __func__,	\
 		   pktp[0],		\
 		   pktp[1],		\
 		   pktp[16],	\
 		   pktp[32],	\
 		   pktp[59]);	
 #endif
+
+



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201006241737.o5OHbjV3046754>