Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 4 Nov 2010 12:33:50 GMT
From:      Alexandre Fiveg <afiveg@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 185371 for review
Message-ID:  <201011041233.oA4CXomF021260@skunkworks.freebsd.org>

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

Change 185371 by afiveg@cottonmouth on 2010/11/04 12:33:13

	Changes in the libppcap:
	- the new data structure pcap_ringmap inserted into pcap structure. 
	All variables that are related to ringmap are now members of pcap_ringmap.
	- include "ringmap.h" is moved into pcap-int.h

Affected files ...

.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-bpf.c#20 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-int.h#20 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap.c#24 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap/pcap.h#4 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/ringmap_pcap.c#37 edit
.. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.c#53 edit
.. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.h#52 edit
.. //depot/projects/soc2010/ringmap/scripts/build_ringmap.sh#35 edit
.. //depot/projects/soc2010/ringmap/scripts/set_ringmap.sh#36 edit
.. //depot/projects/soc2010/ringmap/scripts/tailf_ringmap_msgs.sh#30 edit

Differences ...

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

@@ -163,7 +163,6 @@
 
 #ifdef RINGMAP
 #include <machine/bus.h>
-#include "../../sys/net/ringmap.h"
 extern void	uninit_mmapped_capturing(pcap_t *);
 #endif 
 
@@ -1142,7 +1141,7 @@
 #endif
 
 #ifdef RINGMAP
-	if (p->ringmap_flags == 1){  
+	if (p->rp.status == 1) {  
 		uninit_mmapped_capturing(p);
 	}
 #endif 

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

@@ -56,6 +56,10 @@
 #include <io.h>
 #endif
 
+#ifdef RINGMAP
+#include "../../sys/net/ringmap.h"
+#endif 
+
 #if (defined(_MSC_VER) && (_MSC_VER <= 1200)) /* we are compiling with Visual Studio 6, that doesn't support the LL suffix*/
 
 /*
@@ -333,8 +337,9 @@
 	struct pcap_pkthdr pcap_header;	/* This is needed for the pcap_next_ex() to work */
 
 #ifdef RINGMAP
-	int ringmap_flags;
-	struct ring *ring;
+	struct pcap_ringmap rp;
+//	int ringmap_flags;
+//	struct ring *ring;
 #endif
 };
 

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

@@ -72,11 +72,10 @@
 #endif
 
 #ifdef RINGMAP
-#include "../../sys/net/ringmap.h"
 #include <sys/ioccom.h>
 
 extern int init_mmapped_capturing(const char *device, pcap_t *);
-extern void ringmap_setfilter(struct bpf_program *);
+extern void ringmap_setfilter(struct bpf_program *, pcap_t *);
 extern int pcap_read_ringmap(pcap_t *, int , pcap_handler , u_char *);
 #endif 
 
@@ -280,10 +279,10 @@
 	 * requires the modification of these application.  Thats why I set
 	 * ringmap_flags staticaly here 
 	 */
-	p->ringmap_flags = set_ringmap_flags(1);
+	p->rp.status = set_ringmap_status(1, p);
 
 	/* Replace 1 with RINGMAP_ACTIVE macro */
-	if (p->ringmap_flags == 1){
+	if (p->rp.status == 1) {
 		if (init_mmapped_capturing(source, p) < 0)
 			goto fail;
 		p->read_op = pcap_read_ringmap;
@@ -1022,9 +1021,9 @@
 #ifdef RINGMAP
 	int err = p->setfilter_op(p, fp);
 
-	if (p->ringmap_flags == 1){
+	if (p->rp.status == 1) {
 		if (err == 0)
-			ringmap_setfilter(fp);
+			ringmap_setfilter(fp, p);
 	}
 		
 	return (err);

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

@@ -340,7 +340,7 @@
 void	bpf_dump(struct bpf_program *, int);
 
 #ifdef RINGMAP
-int set_ringmap_flags(int val);
+int set_ringmap_status(int val, pcap_t *p);
 #endif
 
 #if defined(WIN32)

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

@@ -22,38 +22,25 @@
 #include "pcap.h"
 #include "pcap-int.h"
 
-#include "../../sys/net/ringmap.h"
-
-
-/* TODO: That's dirty! Place the next into the pcap structure */
-/* File descriptor of /dev/iface */
-int ringmap_cdev_fd = -1;
-int ringmap_active_status = 0;
-
-/***	F U N C T I O N S	***/
 int init_mmapped_capturing(const char *device, pcap_t *);
 void uninit_mmapped_capturing(pcap_t *);
 int pcap_read_ringmap(pcap_t *, int , pcap_handler , u_char *);
-void ringmap_setfilter(struct bpf_program *);
+void ringmap_setfilter(struct bpf_program *, pcap_t *);
 
-
-
-
 int 
-set_ringmap_flags(int val)
+set_ringmap_status(int val, pcap_t *p)
 {
 	/* If active status already set do nothing */
-	if (ringmap_active_status == 0)
-		ringmap_active_status = val;
-
-	return (ringmap_active_status);
+	if (p->rp.status == 0)
+		p->rp.status = val;
+	return (p->rp.status);
 }
 
-/********************************************************
+/* 
  * Open  (/dev/iface) device to communicate with 
- * kernel. Map buffers by calling mmap (/dev/mem, ...)
+ * kernel. Map buffers by calling mmap(/dev/mem, ...)
  * in space of our user process. 
- ********************************************************/
+ */
 int
 init_mmapped_capturing(const char *device, pcap_t *p)
 {
@@ -68,39 +55,41 @@
 	sprintf(dev_path, "/dev/%s", device);
 
 	/* Open /dev/ device for communication with our driver */
-	if ((ringmap_cdev_fd = open(dev_path, O_RDWR)) == -1) {
+	if ((p->rp.cdev_fd = open(dev_path, O_RDWR)) == -1) {
 		printf("[%s] Error by opening %s \n", __func__, dev_path);
 		perror("/dev/" RINGMAP_DEVICE);
-		return(-1);
+		return (-1);
 	}
 
+	/* Set queue number we want to attach to our thread */
+	queue_num = DEFAULT_QUEUE;
+
+	/* Associate our thread with the queue_num */
+	ioctl(p->rp.cdev_fd, IOCTL_ATTACH_RING, &queue_num);
+
 	/* 
 	 * Open mem device for mmaping of kernel memory regions into space of our
 	 * process 
 	 */
-	if ((devmem_fd = open("/dev/mem", O_RDWR)) == -1){
+	if ((devmem_fd = open("/dev/mem", O_RDWR)) == -1) {
 		perror("/dev/mem");
 		return (-1); 
 	}
 
 	/**
-	 ** Here we map the ring structure into the 
-	 ** memory space of current process.
+	 ** Get the physical address of the ring
 	 **/
-	if (read(ringmap_cdev_fd, &ring, sizeof(vm_paddr_t)) == -1) {
-		RINGMAP_ERROR(Can not read phys addr of ring from kernel);
+	if (read(p->rp.cdev_fd, &ring, sizeof(vm_paddr_t)) == -1) {
+		RINGMAP_ERROR(Can not get phys addr of ring!);
 		return (-1);
 	}
 
-	/* TODO: extend this for multiple queue case */
-	queue_num = DEFAULT_QUEUE;
-	/* Attach and init the ring to our thread */
-	ioctl(ringmap_cdev_fd, IOCTL_ATTACH_RING, &queue_num);
 
 #if (__RINGMAP_DEB)
 	printf("[%s] Phys addr of ring 0x%X\n", __func__, ring);
 #endif
 
+	/* Map ring into our address space */
 	tmp_addr = mmap(0,	 		/* Kernel gives us the address */
 		sizeof(struct ring), 	/* Number of bytes we are mapping */
 		PROT_WRITE|PROT_READ,	/* We want both read and write */
@@ -112,31 +101,30 @@
 		return (-1);
 	}
 
-	p->ring = (struct ring *)tmp_addr;
-	if (p->ring->size != SLOTS_NUMBER){
+	p->rp.ring = (struct ring *)tmp_addr;
+	if (p->rp.ring->size != SLOTS_NUMBER) {
 		RINGMAP_ERROR("Wrong size of ring buffer!");
-		return -1;
+		return (-1);
 	}
 	
 #if (__RINGMAP_DEB)
-	printf("Virtual address of ring is 0x%X\n", p->ring);
-	printf("Ring Size = %d \n", p->ring->size);
+	printf("Virtual address of ring is 0x%X\n", p->rp.ring);
+	printf("Ring Size = %d \n", p->rp.ring->size);
 
-	for(i=0 ;i < SLOTS_NUMBER; i++){
-		PRINT_PACKET_ADDR(p->ring, i);
+	for (i=0 ;i < SLOTS_NUMBER; i++) {
+		PACKET_ADDR_DEB(p->rp.ring, i);
 	}
 
-	PRINT_RING_PTRS(p->ring);
+	PRINT_RING_PTRS(p->rp.ring);
 #endif 
 
 	/* 
 	 * Mapping mbufs and packet buffers from kern into userspace. 
 	 */
 	for (i = 0; i < SLOTS_NUMBER; i++) {
-
 		/* Map mbuf */
-		memoffset = (off_t)p->ring->slot[i].mbuf.phys;
-		tmp_addr = mmap (0, 		/*	System will choose the addrress */
+		memoffset = (off_t)p->rp.ring->slot[i].mbuf.phys;
+		tmp_addr = mmap(0,	 		/*	System will choose the addrress */
 			sizeof(struct mbuf),	/*	Size of mapped region (mbuf) 	*/
 			PROT_WRITE|PROT_READ,	/*	protection: write & read 		*/
 			MAP_SHARED,				/*	shared maping					*/
@@ -146,12 +134,12 @@
 		if (tmp_addr == MAP_FAILED) {
 			printf(ERR_PREFIX"[%s] Mapping of mbuf %d failed!\n", 
 								__func__, i);
-			return -1;
+			return (-1);
 		}
-		p->ring->slot[i].mbuf.user = (vm_offset_t)tmp_addr;
+		U_MBUF(p->rp.ring, i) = (vm_offset_t)tmp_addr;
 
 		/* Map packet data */
-		memoffset = (off_t)p->ring->slot[i].packet.phys;
+		memoffset = (off_t)p->rp.ring->slot[i].packet.phys;
 		tmp_addr = 
 			mmap(	0, 
 					MCLBYTES, 
@@ -159,20 +147,18 @@
 					MAP_SHARED,				
 					devmem_fd, 
 					memoffset);
-		if (tmp_addr == MAP_FAILED){
+		if (tmp_addr == MAP_FAILED) {
 			printf(ERR_PREFIX"[%s] Mapping of packets buffer %d failed!\n", 
 					__func__, i);
-			return -1;
+			return (-1);
 		}
-		p->ring->slot[i].packet.user = (vm_offset_t)tmp_addr;
+		U_PACKET(p->rp.ring, i) = (vm_offset_t)tmp_addr;
 		
-#if (__RINGMAP_DEB)
-		PRINT_PACKET_ADDR(p->ring, i);
-#endif
+		PACKET_ADDR_DEB(p->rp.ring, i);
 	}
 
 	/* Close memory device */
-	if (close(devmem_fd) == -1){
+	if (close(devmem_fd) == -1) {
 		perror("close()");
 	}
 
@@ -197,35 +183,37 @@
 		goto out;
 	}
 
-	if (p->ring == NULL) {
+	if (p->rp.ring == NULL) {
 		RINGMAP_FUNC_DEBUG(NULL pointer to ringstructure);
 		goto out;
 	}
 
+	p->rp.status = 0;
+
 	/* Unmap slots */
-	for (i = 0; i < SLOTS_NUMBER; i++){
-		tmp_res = munmap((void *)p->ring->slot[i].mbuf.user, 
+	for (i = 0; i < SLOTS_NUMBER; i++) {
+		tmp_res = munmap((void *)U_MBUF(p->rp.ring, i), 
 							sizeof(struct mbuf));
 
 		if (tmp_res == -1)
 			printf(ERR_PREFIX"[%s] Error by unmapping of mbuf %d\n", 
 								__func__, i);
 	
-		tmp_res = munmap((void *)p->ring->slot[i].packet.user, MCLBYTES);
+		tmp_res = munmap((void *)U_PACKET(p->rp.ring, i), MCLBYTES);
 		if (tmp_res == -1)
 			printf(ERR_PREFIX"[%s] Error by unmapping of packet buffer %d\n", 
 					__func__, i);
 	}
 
 	/* Unmap ring */
-	tmp_res = munmap(p->ring, sizeof(struct ring));
+	tmp_res = munmap(p->rp.ring, sizeof(struct ring));
 	if (tmp_res == -1) {
 		RINGMAP_ERROR(Unmaping the ring pointer);
 	}
 
 out:	
-	if (ringmap_cdev_fd >= 0){
-		if ( close(ringmap_cdev_fd) == -1 )
+	if (p->rp.cdev_fd >= 0) {
+		if (close(p->rp.cdev_fd) == -1)
 			perror("close()");
 	}
 
@@ -233,9 +221,9 @@
 }
 
 void
-ringmap_setfilter(struct bpf_program *fp)
+ringmap_setfilter(struct bpf_program *fp, pcap_t *p)
 {
-	if (ioctl(ringmap_cdev_fd, IOCTL_SETFILTER, (caddr_t)fp) == 0) {
+	if (ioctl(p->rp.cdev_fd, IOCTL_SETFILTER, (caddr_t)fp) == 0) {
 		RINGMAP_FUNC_DEBUG(Filter is set);
 	} else {
 		RINGMAP_WARN(Filter is not set!);
@@ -261,22 +249,21 @@
 		return (-2);
 	}
 
-	if (p->ring == NULL){
+	if (p->rp.ring == NULL) {
 		RINGMAP_ERROR(Ring is not allocated);
 		exit (1);
 	}
 
-	ring = p->ring;
+	ring = p->rp.ring;
 
-	/* stay here as long as the ring is empty */
+	/* stay here while the ring is empty */
 	while (RING_IS_EMPTY(ring)) {
 
-#if (__RINGMAP_DEB)
-		PRINT_RING_PTRS(ring);
+		RING_PTRS_DEB(ring);
 		RINGMAP_FUNC_DEBUG(Ring is empty. Sleep...);
-#endif 
+
 		/* Sleep and wait for new incoming packets */
-		err_sleep = ioctl(ringmap_cdev_fd, IOCTL_SLEEP_WAIT);
+		err_sleep = ioctl(p->rp.cdev_fd, IOCTL_SLEEP_WAIT);
 
 		/* catching signals */
 		if (err_sleep) {
@@ -288,16 +275,13 @@
 	}
 
 	/* Ok, if we are here the ring shouldn't be empty, let's capture */
-#if (__RINGMAP_DEB)
-		RINGMAP_FUNC_DEBUG(Ring is NOT empty:);
-		PRINT_RING_PTRS(ring);
-#endif 
+	RINGMAP_FUNC_DEBUG(Ring is NOT empty:);
+	RING_PTRS_DEB(ring);
 
-	if ( (cnt == -1) || (cnt == 0) )
-		cnt = SW_TAIL_TO_HEAD_DIST(p->ring);
+	if ((cnt == -1) || (cnt == 0))
+		cnt = SW_TAIL_TO_HEAD_DIST(p->rp.ring);
 
-	for (ws = cnt ; ( (ws) && (RING_NOT_EMPTY(p->ring)) ) ; ) 
-	{
+	for (ws = cnt; ((ws) && (RING_NOT_EMPTY(p->rp.ring)));) {
 		if (p->break_loop) {
 			p->break_loop = 0;
 			if (!(cnt - ws))
@@ -307,7 +291,8 @@
 		}
 
 		/* Slot we want to check */
-		curr_slot = R_MODULO( SW_TAIL(ring) + 1 );
+		curr_slot = R_MODULO(SW_TAIL(ring) + 1);
+
 		/* 
 		 * ringmap-Driver tell us whether the slot contains 
 		 * a good packet 
@@ -343,19 +328,15 @@
 		ring->pkt_counter++;
 		--ws;
 
-#if (__RINGMAP_DEB)
-		PRINT_PKT_BYTES(datap, curr_slot);	
-#endif 
+		PKT_BYTES_DEB(datap, curr_slot);	
 
 		/* callback function */
 		(*callback)(user, &pkthdr, datap);
 
-#if (__RINGMAP_DEB)
-		PRINT_SLOT(ring, curr_slot);
-#endif
+		PRINT_SLOT_DEB(ring, curr_slot);
 
 out:
-		SW_INCR_TAIL(ring);
+		INCR_TAIL(ring);
 
 		ring->slot[curr_slot].filtered = 0;
 		ring->slot[curr_slot].is_ok = 0;
@@ -375,11 +356,11 @@
 {
 	int err = 0;
 
-	if (p->ring == NULL)
+	if (p->rp.ring == NULL)
 		return (-1);
 
-	printf("HEAD Pointer (kern) = %d\n", SW_HEAD(p->ring));
-	printf("TAIL Pointer (user)	= %d\n", SW_TAIL(p->ring));
+	printf("HEAD Pointer (kern) = %d\n", SW_HEAD(p->rp.ring));
+	printf("TAIL Pointer (user)	= %d\n", SW_TAIL(p->rp.ring));
 
 	return (err);
 }
@@ -390,17 +371,15 @@
 {
 	int err = 0;
 
-	if (p->ring == NULL){
+	if (p->rp.ring == NULL) {
 		RINGMAP_ERROR(Ring is not allocated!);
 
 		return (-1);
 	}
 
-	printf("Ring-Full  counter:  %llu\n", p->ring->kern_wait_user);
-	printf("Ring-Empty counter:  %llu\n", p->ring->user_wait_kern);
-	printf("Interrupt counter:  %llu\n", p->ring->intr_num);
-	printf("Pkts per interrupt:  %llu\n", 
-			(p->ring->pkt_counter / p->ring->intr_num));
+	printf("Ring-Full  counter:  %llu\n", p->rp.ring->kern_wait_user);
+	printf("Ring-Empty counter:  %llu\n", p->rp.ring->user_wait_kern);
+	printf("Interrupt counter:  %llu\n", p->rp.ring->intr_num);
 
 	return (err);
 }

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

@@ -33,7 +33,7 @@
 #include <vm/vm_param.h>
 #include <vm/vm_kern.h>
 
-#include <dev/pci/pcivar.h>   /* For pci_get macros! */
+#include <dev/pci/pcivar.h>
 #include <dev/pci/pcireg.h>
 
 #include "ringmap.h"
@@ -54,7 +54,6 @@
 d_close_t	ringmap_close;
 d_ioctl_t	ringmap_ioctl;
 d_read_t	ringmap_read;
-d_mmap_single_t ringmap_mmap_single;
 
 static struct cdevsw ringmap_devsw = {
 	.d_version 	= D_VERSION,
@@ -62,7 +61,6 @@
 	.d_close 	= ringmap_close,
 	.d_ioctl	= ringmap_ioctl,
 	.d_read		= ringmap_read,		/* Tell to user ring physical addr */
-	.d_mmap_single = ringmap_mmap_single,	/* Doesn't work yet */
 	.d_name 	= "ringmap_cdev"
 };
 
@@ -72,7 +70,7 @@
 
 /*
  * The function should be called from the attach function of generic network
- * driver.  Here the ringmap structure is allocated and the character special
+ * driver. Here the ringmap structure is allocated and the character special
  * device for the communication with user is created. Also default ringmap
  * functions are set.
  */
@@ -116,11 +114,11 @@
 
 	/* 
 	 * Initialize the list of capturing objects. Each object represents the
-	 * thread that capture traffic and its ring.
+	 * thread that capture traffic and its ring. The objects werden created 
+	 * by open(2): see ringmap_open() further.
 	 */
 	SLIST_INIT(&rm->object_list);
 
-	/* Insert ringmap structure into the list */
 	SLIST_INSERT_HEAD(&ringmap_list_head, rm, entries);
 
 	/* Init the mutex for protecting our data */
@@ -165,6 +163,7 @@
 		return (-1);
 	}
 	
+again:
 	/* Remove all capturing objects associated with ringmap */
     while (!SLIST_EMPTY(&rm->object_list)) {
 	    co = SLIST_FIRST(&rm->object_list);
@@ -172,9 +171,11 @@
     }
 
 	RINGMAP_LOCK(rm);
-	/* To be sure */
+	/* To be sure . This is dirty:(. TODO: do in other way */
 	if (!SLIST_EMPTY(&rm->object_list)) {
 		RINGMAP_WARN(There are still active capturing objects);
+		RINGMAP_UNLOCK(rm);
+		goto again;
 	}
 	/* Destroy char device associated with ringmap */
 	if (rm->cdev != NULL)
@@ -212,7 +213,7 @@
 	printf(RINGMAP_PREFIX"[%s] pid = %d\n", __func__, td->td_proc->p_pid);
 #endif 
 	rm = cdev2ringmap(cdev);
-	if ( rm == NULL ) {
+	if (rm == NULL) {
 		RINGMAP_ERROR(Could not get the pointer to ringmap structure);
 		return (EIO);
 	}
@@ -222,7 +223,8 @@
 	/* TODO: set max number of threads in the ringmap struct as a member */
 	if (rm->open_cnt == RINGMAP_MAX_THREADS) {
 		RINGMAP_ERROR(Can not open device!);
-		err = EIO; goto out;
+		err = EIO; 
+		goto out;
 	}
 
 	/* First stop receive and interupts while we allocate our data */
@@ -234,7 +236,8 @@
 	SLIST_FOREACH(co, &rm->object_list, objects) {
 		if (co->td == td) {
 			RINGMAP_ERROR(Device is opened!);
-			err = EIO; goto out;
+			err = EIO; 
+			goto out;
 		}
 	}
 
@@ -246,7 +249,8 @@
 			M_DEVBUF, M_ZERO, 0, -1L, PAGE_SIZE, 0);
 	if (ring == NULL) {
 		RINGMAP_ERROR(Can not allocate space for ring);
-		err = EIO; goto out;
+		err = EIO; 
+		goto out;
 	}
 	ring->size = SLOTS_NUMBER;
 
@@ -267,7 +271,7 @@
 	SLIST_INSERT_HEAD(&rm->object_list, co, objects);
 
 	/* 
-	 * Store capturing object as private data. So we can access our capturing
+	 * Store capturing object as private data. So we can access it
 	 * object in other syscalls, e.g. read, close, etc... 
 	 */
 	if (devfs_set_cdevpriv((void *)co, clear_capt_object)) {
@@ -284,7 +288,9 @@
 	rm->funcs->receive_enable(rm);
 
 	RINGMAP_UNLOCK(rm);
+
 	RINGMAP_FUNC_DEBUG(end);
+
 	return (err);
 }
 
@@ -341,53 +347,6 @@
 }
 
 
-/* doesn't work yet */
-int 
-ringmap_mmap_single(struct cdev *cdev, vm_ooffset_t *offset,
-    vm_size_t size, struct vm_object **object, int nprot)
-{
-	struct ringmap *rm = NULL;
-	struct capt_object *co = NULL;
-	vm_object_t obj;
-	vm_map_entry_t  entry;
-    vm_pindex_t pindex;
-    vm_prot_t prot;
-    boolean_t wired;
-
-	rm = cdev2ringmap(cdev);
-	if ( rm == NULL ) {
-		RINGMAP_ERROR(Null pointer to ringmap structure);
-
-		return (EIO);
-	}
-
-	SLIST_FOREACH(co, &rm->object_list, objects) {
-		if (co->td == curthread) {
-			break;
-		}
-	}
-
-	if ((co == NULL) || (co->ring == NULL)) {
-		RINGMAP_ERROR(Null pointer);
-		return (EIO);
-	}
-
-	vm_map_lookup(&kmem_map, (vm_offset_t)co->ring, VM_PROT_ALL,
-			      &entry, &obj, &pindex, &prot, &wired);
-	vm_map_lookup_done(kmem_map, entry);
-
-	if (obj == kmem_object) {
-		RINGMAP_ERROR(Got kmem_object);
-	} else {
-		RINGMAP_FUNC_DEBUG(Got other obj);
-	}
-
-	object = &obj;
-
-	return (0);
-}
-
-
 /*
  * Tells usre the physical addres of ring. User process will 
  * use this addres in order to map the buffer in its address 
@@ -539,9 +498,7 @@
 					err = EINVAL; 
 					goto xxx;
 				}
-#if (__RINGMAP_DEB)
-				PRINT_SLOT(co->ring, i);
-#endif
+				PRINT_SLOT_DEB(co->ring, i);
 			}
 xxx:		
 			rm->funcs->intr_enable(rm);

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

@@ -28,6 +28,11 @@
  */
 #define RINGMAP_MAX_THREADS 8
 
+/*
+ * TODO:
+ * Somehow I don't like this addres stuff. We can get by whithout it.
+ * I am looking how to eliminate it. 
+ */
 struct address {
 	vm_paddr_t 	volatile phys;
 	vm_offset_t	volatile kern;
@@ -35,13 +40,11 @@
 };
 
 /*
- * This structure represents the ring slot. Each slot contains two entities:
- * mbuf and packet. Mbuf represents the kernel view of packet. The packet
- * represents the buffer where the packet data is placed. 
- *
- * Each entity is of type 'struct address'. Struct 'address' contains 
- * three addresses: physical-, kernel- and user-address. We need to store 
- * the physical addresses to be able to do memory mapping. 
+ * This structure represents the ring slot. "mbuf" represents the kernel view
+ * of packet. The "packet" represents the buffer where the packet data is
+ * placed. Both are of type 'struct address'. Struct 'address' contains three
+ * addresses: physical-, kernel- and user-address. We need to store the
+ * physical addresses to be able to do memory mapping. 
  */
 struct ring_slot {
 
@@ -54,10 +57,6 @@
 	/* 1 if accepted by driver and contains no errors */
 	int volatile is_ok;
 
-	/* 
-	 * Next fields are for statistics:
-	 */
-
 	/* Time stamp of packet stored in this slot */
 	struct timeval	ts;
 
@@ -130,6 +129,13 @@
 	struct ring_slot volatile slot[SLOTS_NUMBER];
 }; 
 
+/* For libpcap. To be set in the pcap structure */
+struct pcap_ringmap {
+	int cdev_fd;
+	int status;
+	int flags;
+	struct ring *ring;
+};
 
 /* *************************************
  * IOCTL ' s  system calls             *
@@ -211,7 +217,7 @@
 	((SW_TAIL(ringp) == SW_HEAD(ringp)) ? SLOTS_NUMBER : 	\
 	R_DISTANCE(SW_TAIL(ringp), SW_HEAD(ringp)))
 
-#define SW_INCR_TAIL(ringp)							\
+#define INCR_TAIL(ringp)							\
 	(SW_TAIL(ringp)) = R_MODULO(SW_TAIL(ringp) + 1);
 
 #define RING_IS_EMPTY(ringp)				\
@@ -294,13 +300,13 @@
    printf("=+= [%s] SOME BYTES FROM PKT: %hhu %hhu %hhu %hhu %hhu %hhu %hhu\n", 	\
 	   __func__, pktp[0], pktp[1], pktp[2], pktp[30], pktp[31], pktp[32], pktp[33]);
 
-#define PRINT_PACKET_ADDR(ring, i)	\
-	do {							\
+#define PACKET_ADDR_DEB(ring, i)	\
+	if (__RINGMAP_DEB) {							\
 		printf("=+= packet.user=0x%X, packet.phys=0x%X, packet.kern=0x%X\n",\
 		(unsigned int)ring->slot[i].packet.user, 	\
 		(unsigned int)ring->slot[i].packet.phys, 	\
 		(unsigned int)ring->slot[i].packet.kern);	\
-	} while (0);
+	};
 
 #define PRINT_MBUF_ADDR(ring, i)	\
 	do {							\
@@ -311,7 +317,7 @@
 	} while (0);
 
 #define PRINT_SLOT(ring, i)												\
-	if (((ring) != NULL) && ((i) < SLOTS_NUMBER)){ 		 				\
+	if ((ring) != NULL) { 							\
 		printf("\n=+= ==================================\n");			\
 		printf("=+= Slot Number: %d \n", (i));							\
 		printf("=+= Intrr num:  %llu\n", (ring)->slot[(i)].intr_num);	\
@@ -321,27 +327,34 @@
 		printf("=+= Accepted: %d\n", (ring)->slot[(i)].is_ok);			\
 		printf("=+= -------------------------\n");						\
 		PRINT_MBUF_ADDR(ring, i);										\
-		PRINT_PACKET_ADDR(ring, i);										\
+		PACKET_ADDR_DEB(ring, i);										\
 		printf("=+= -------------------------\n");						\
 		printf("=+= ==================================\n\n");			\
-	} else {															\
-		RINGMAP_ERROR(Print failed!);									\
-	}
-
-#define PRINT_SLOT_DEB(ring, i)				\
-	if (__RINGMAP_DEB) {					\
-		PRINT_SLOT((ring), (i))				\
 	};
 
-
 #define PRINT_TAIL(ring)				\
 	printf("=+= [%s] tail = %d\n", __func__, SW_TAIL(ring));	
 
 #define PRINT_HEAD(ring)				\
 	printf("=+= [%s] head = %d\n", __func__, SW_HEAD(ring));
 
+#define PRINT_SLOT_DEB(ring, i)		\
+	if (__RINGMAP_DEB) {			\
+		PRINT_SLOT((ring), (i))		\
+	};
+
 #define PRINT_RING_PTRS(ring)		\
 	do {							\
 		PRINT_TAIL(ring)			\
 		PRINT_HEAD(ring)			\
 	} while (0);
+
+#define RING_PTRS_DEB(ring)			\
+if (__RINGMAP_DEB) {				\
+		PRINT_RING_PTRS(ring)		\
+};
+
+#define PKT_BYTES_DEB(pktp, i)			\
+if (__RINGMAP_DEB) {					\
+		PRINT_PKT_BYTES(pktp, i);		\
+};

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


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


==== //depot/projects/soc2010/ringmap/scripts/tailf_ringmap_msgs.sh#30 (text+ko) ====




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