Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Aug 2010 18:26:05 GMT
From:      Alexandre Fiveg <afiveg@skunkworks.freebsd.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 182187 for review
Message-ID:  <201008111826.o7BIQ5IJ084300@skunkworks.freebsd.org>

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

Change 182187 by afiveg@cottonmouth on 2010/08/10 14:48:20

	ringmap for lem driver fixed. 
	Changes in ringmap.[hc] - now the global list of ringmap structures will be used. It reduces the number of ringmap function, that earlier was needed for access to the ringmap structure. Eliminated LOCKS from sync* functions - they could cause a dead-lock. TODO: fix ixgbe-ringmap to these changes. 

Affected files ...

.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-bpf.c#14 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-int.h#14 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap.c#17 edit
.. //depot/projects/soc2010/ringmap/current/contrib/libpcap/ringmap_pcap.c#29 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.c#30 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.c#29 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.h#27 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_e1000.h#19 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/ixgbe/ringmap_8259.h#12 edit
.. //depot/projects/soc2010/ringmap/current/sys/dev/ixgbe/ringmap_ixgbe.c#13 edit
.. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.c#43 edit
.. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.h#43 edit
.. //depot/projects/soc2010/ringmap/current/sys/net/ringmap_kernel.h#13 edit
.. //depot/projects/soc2010/ringmap/scripts/build_ringmap.sh#25 edit
.. //depot/projects/soc2010/ringmap/scripts/set_ringmap.sh#26 edit
.. //depot/projects/soc2010/ringmap/scripts/tailf_ringmap_msgs.sh#20 edit
.. //depot/projects/soc2010/ringmap/tests/libpcap/easy_pcap.c#11 edit

Differences ...

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


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


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


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


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

@@ -82,7 +82,7 @@
 
 #include "e1000_api.h"
 #ifdef RINGMAP
-#include <../../net/ringmap.h>
+#include <net/ringmap.h>
 #endif
 #include "if_lem.h"
 
@@ -272,8 +272,7 @@
 
 
 #ifdef RINGMAP
-
-extern int ringmap_attach (device_t, struct ringmap_functions *);
+extern struct ringmap * ringmap_attach(device_t, struct ringmap_functions *);
 extern int ringmap_detach (device_t);
 
 extern struct ringmap_functions ringmap_8254_f;
@@ -686,7 +685,10 @@
 	    device_get_nameunit(dev));
 
 #ifdef RINGMAP
-	ringmap_attach (dev, &ringmap_8254_f);
+	adapter->rm = ringmap_attach (dev, &ringmap_8254_f);
+	if (adapter->rm == NULL) {
+		goto err_rx_struct;
+	}
 #endif 
 
 	INIT_DEBUGOUT("lem_attach: end");
@@ -1383,37 +1385,15 @@
 	struct adapter	*adapter = context;
 	struct ifnet	*ifp = adapter->ifp;
 
-#ifdef RINGMAP
-	struct capt_object *co = NULL;
-#endif
-
 	if (ifp->if_drv_flags & IFF_DRV_RUNNING) {
-#ifdef RINGMAP
-		if ((adapter->rm != NULL) && (adapter->rm->open_cnt > 0)) {
-			adapter->rm->funcs->delayed_isr(context);
-#endif
 		if (lem_rxeof(adapter, adapter->rx_process_limit) != 0)
 			taskqueue_enqueue(adapter->tq, &adapter->rxtx_task);
-#ifdef RINGMAP
-			adapter->rm->funcs->sync_head(adapter->dev);
-			
-			SLIST_FOREACH(co, &adapter->rm->object_list, objects) {
-				if (RING_NOT_EMPTY(co->ring)){
-					wakeup(co->ring);
-				}
-			}
-		}
-#endif 
 
-#ifdef RINGMAP
-#if (RINGMAP_TX_ENABLE)
 		EM_TX_LOCK(adapter);
 		lem_txeof(adapter);
 		if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
 			lem_start_locked(ifp);
 		EM_TX_UNLOCK(adapter);
-#endif
-#endif
 	}
 
 	lem_enable_intr(adapter);
@@ -3521,6 +3501,10 @@
 	int		i, rx_sent = 0;
 	struct e1000_rx_desc   *current_desc;
 
+#ifdef RINGMAP
+	struct capt_object *co = NULL;
+#endif
+
 	EM_RX_LOCK(adapter);
 	i = adapter->next_rx_desc_to_check;
 	current_desc = &adapter->rx_desc_base[i];
@@ -3532,6 +3516,12 @@
 		return (rx_sent);
 	}
 
+#ifdef RINGMAP
+	/* Call our ringmap-isr only in case any process captures (open_cnt > 0) */ 
+	if ((adapter->rm != NULL) && (adapter->rm->open_cnt > 0)) 
+		adapter->rm->funcs->delayed_isr(adapter);
+#endif
+
 	while ((current_desc->status & E1000_RXD_STAT_DD) &&
 	    (count != 0) &&
 	    (ifp->if_drv_flags & IFF_DRV_RUNNING)) {
@@ -3586,12 +3576,12 @@
 		if (accept_frame) {
 
 #ifdef RINGMAP
-			if (adapter->rm != NULL) 
+			if ((adapter->rm != NULL) && (adapter->rm->open_cnt > 0)) 
 				adapter->rm->funcs->delayed_isr_per_packet(adapter->dev, i);
 #endif
 
 #ifndef RINGMAP
-		/* Do not allocate memory for new mbufs and packets. Work in ring */
+/* RINGMAP: Do not allocate memory for new mbufs and packets. Work in ring */
 			if (lem_get_buf(adapter, i) != 0) {
 				ifp->if_iqdrops++;
 				goto discard;
@@ -3696,6 +3686,18 @@
 		}
 		current_desc = &adapter->rx_desc_base[i];
 	}
+
+#ifdef RINGMAP
+	RINGMAP_LOCK(adapter->rm);
+	SLIST_FOREACH(co, &adapter->rm->object_list, objects) {
+		adapter->rm->funcs->sync_head(co);
+		if (RING_NOT_EMPTY(co->ring)){
+			wakeup(co->ring);
+		}
+	}
+	RINGMAP_UNLOCK(adapter->rm);
+#endif 
+
 	adapter->next_rx_desc_to_check = i;
 
 	/* Advance the E1000's Receive Queue #0  "Tail Pointer". */

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

@@ -18,7 +18,6 @@
 #include "if_lem.h"
 #include "ringmap_8254.h"
 
-int rm_8254_set_ringmap_to_adapter(device_t, struct ringmap *);
 struct ringmap * rm_8254_get_ringmap_p(device_t);
 device_t rm_8254_get_device_p(struct cdev *);
 void rm_8254_enable_intr(device_t);
@@ -28,9 +27,9 @@
 void rm_8254_delayed_interrupt(void *);
 void rm_8254_delayed_interrupt_per_packet(void *, int);
 int rm_8254_print_ring_pointers(struct adapter *);
-void rm_8254_sync_tail(void *);
-void rm_8254_sync_head(void *);
-struct ring * rm_8254_find_next(struct adapter *);
+void rm_8254_sync_tail(struct capt_object *);
+void rm_8254_sync_head(struct capt_object *);
+struct capt_object * rm_8254_find_next(struct adapter *);
 int rm_8254_set_queue(struct capt_object *, unsigned int);
 
 extern devclass_t em_devclass;
@@ -41,7 +40,6 @@
 
 
 struct ringmap_functions ringmap_8254_f = {
-	rm_8254_set_ringmap_to_adapter,
 	rm_8254_enable_intr,
 	rm_8254_disable_intr,
 	rm_8254_interrupt,
@@ -51,8 +49,6 @@
 	rm_8254_sync_head,
 	rm_8254_set_slot,
 	rm_8254_set_queue,
-	rm_8254_get_ringmap_p,
-	rm_8254_get_device_p
 };
 
 
@@ -61,61 +57,27 @@
  * 2. SYNC_TAIL: RDT =  ring->userrp
  */
 void 
-rm_8254_sync_tail(void *context)
+rm_8254_sync_tail(struct capt_object *co)
 {
-	device_t dev = (device_t)context;
-	struct adapter *adapter = (struct adapter *)device_get_softc(dev);
-	struct ring *ring = NULL;
+	struct adapter *adapter = (struct adapter *)device_get_softc(co->rm->dev);
 
 	RINGMAP_FUNC_DEBUG(start);
 
-	/* 
-	 * In case if there are many processes that capture, take the 
-	 * userrp from process that is next to RDH.
-	 */
-	ring = rm_8254_find_next(adapter);
+	RINGMAP_HW_SYNC_TAIL(adapter, co->ring);
 
-#if (__RINGMAP_DEB)
-	printf("Next ring->pid is %d\n", ring->pid);
-#endif 
-
-	RINGMAP_HW_SYNC_TAIL(adapter, ring);
-
 	RINGMAP_FUNC_DEBUG(end);
 }
 
 /* Set value from RDH to the ring->kernrp*/
 void 
-rm_8254_sync_head(void *context)
+rm_8254_sync_head(struct capt_object *co)
 {
-	device_t dev = (device_t)context;
-	struct capt_object *co = NULL;
-	struct adapter *adapter;
+	struct adapter *adapter = (struct adapter *)device_get_softc(co->rm->dev);
 
 	RINGMAP_FUNC_DEBUG(start);
 
-	adapter = (struct adapter *)device_get_softc(dev);
-	if (adapter->rm == NULL)
-		return;
+	RINGMAP_HW_SYNC_HEAD(adapter, co->ring); 
 
-	RINGMAP_LOCK(adapter->rm);
-
-	/* 
-	 * In case if there are many processes that capture, set in the 
-	 * ring structure of each process the kernrp
-	 */
-	SLIST_FOREACH(co, &adapter->rm->object_list, objects) {
-		if (co->ring != NULL) {
-			RINGMAP_HW_SYNC_HEAD(adapter, co->ring); 
-#if (__RINGMAP_DEB)
-			print_capt_obj(co);
-			PRINT_RING_PTRS(co->ring);
-#endif 
-		}
-	}
-
-	RINGMAP_UNLOCK(adapter->rm);
-
 	RINGMAP_FUNC_DEBUG(end);
 }
 
@@ -124,14 +86,11 @@
  * This should be called from ISR. Other interrupts are disallowed!
  * It means the functions must be as small as possible
  */
-void 
+void inline 
 rm_8254_interrupt(void *arg)
 {
-	struct adapter	*adapter = (struct adapter *) arg;
-
-	/* count interrupts only if there is capturing object */
-	if ( adapter->rm->open_cnt > 0 )
-		adapter->rm->interrupts_counter++;
+	/* Do nothing ... */
+   return;	
 }
 
 
@@ -146,15 +105,16 @@
 	RINGMAP_LOCK(adapter->rm);
 
 	getmicrotime(&last_ts);
-	rm_8254_sync_tail(adapter->dev);
+
+	rm_8254_sync_tail(rm_8254_find_next(adapter));
 
 	SLIST_FOREACH(co, &adapter->rm->object_list, objects) {
 		if (co->ring != NULL) {
-#if (__RINGMAP_DEB)
+#if (RINGMAP_INTR_DEB)
 			PRINT_RING_PTRS(co->ring);
 #endif
 			co->ring->last_ts = last_ts;
-			co->ring->intr_num = co->rm->interrupts_counter;
+			++co->ring->intr_num;
 		}
 	}
 
@@ -163,7 +123,7 @@
 }
 
 /* The ring which TAIL pointer is mostly near to to the HEAD(RDH) */
-struct ring *
+struct capt_object *
 rm_8254_find_next(struct adapter *adapter)
 {
 	unsigned int rdh, rdt, dist, min_dist = SLOTS_NUMBER;
@@ -181,7 +141,7 @@
 		}
 	}
 
-	return (min_co->ring);
+	return (min_co);
 }
 
 void 
@@ -199,9 +159,9 @@
 
 	RINGMAP_LOCK(rm);
 	SLIST_FOREACH(co, &rm->object_list, objects) {
-		if ( co->ring != NULL ) {
+		if (co->ring != NULL) {
 			co->ring->slot[slot_num].is_ok = 1;
-			co->ring->slot[slot_num].intr_num = rm->interrupts_counter;
+			co->ring->slot[slot_num].intr_num = co->ring->intr_num;;
 
 #ifdef RINGMAP_TIMESTAMP
 			co->ring->slot[slot_num].ts = co->ring->last_ts;
@@ -221,15 +181,27 @@
 int
 rm_8254_set_slot(struct capt_object *co, unsigned int slot_num)
 {
-	device_t dev = co->dev;
-	struct adapter *adapter = (struct adapter *)device_get_softc(dev);
-	struct ring *ring = co->ring;
+	device_t dev = NULL; 	
+	struct adapter *adapter = NULL; 
+	struct ring *ring = NULL; 
 
 #if (__RINGMAP_DEB)
 	printf("[%s] Set slot: %d\n", __func__, slot_num);
 #endif
 
-	/* First check pointers */
+	dev = co->rm->dev;
+	adapter = (struct adapter *)device_get_softc(dev);
+	ring = co->ring;
+
+	/* First check ALL pointers */
+	if (co == NULL) {
+		RINGMAP_ERROR(Pointer to capturing object is NULL);
+		goto fail;
+	}
+	if (co->rm == NULL) {
+		RINGMAP_ERROR(Pointer to ringmap is NULL);
+		goto fail;
+	}
 	if (GET_MBUF_P(adapter, slot_num) == NULL){
 		RINGMAP_ERROR(Pointer to mbuf is NULL);
 		goto fail;
@@ -273,7 +245,6 @@
 void 
 rm_8254_disable_intr(device_t dev)
 {
-	
 	struct adapter *adapter;
 	adapter = (struct adapter *)device_get_softc(dev);
 
@@ -288,7 +259,6 @@
 void 
 rm_8254_enable_intr(device_t dev)
 {
-	
 	struct adapter *adapter;
 	adapter = (struct adapter *)device_get_softc(dev);
 
@@ -319,21 +289,6 @@
 
 
 /*
- * Set pointer to ringmap in the adapter structure.
- */
-int
-rm_8254_set_ringmap_to_adapter(device_t dev, struct ringmap *rm)
-{
-	struct adapter *adapter;
-
-	adapter = (struct adapter *)device_get_softc(dev);
-	adapter->rm = rm;
-
-	return (0);
-}
-
-
-/*
  * Returns pointer to ringmap structure
  */
 struct ringmap * 

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


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


==== //depot/projects/soc2010/ringmap/current/sys/dev/ixgbe/ringmap_8259.h#12 (text+ko) ====


==== //depot/projects/soc2010/ringmap/current/sys/dev/ixgbe/ringmap_ixgbe.c#13 (text+ko) ====


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

@@ -36,15 +36,14 @@
 
 #include "ringmap.h"
 
-int ringmap_attach (device_t, struct ringmap_functions *);
+struct ringmap * ringmap_attach (device_t, struct ringmap_functions *);
 int ringmap_detach (device_t);
 void ringmap_close_cb (void *data);
 void clear_capt_object(void *);
 void print_capt_obj(struct capt_object *);
+struct ringmap * cdev2ringmap(struct cdev *);
+struct ringmap * dev2ringmap(device_t);
 
-struct ringmap *(*get_ringmap_p)(device_t);
-device_t 		(*get_device_p)(struct cdev *);
-
 d_open_t	ringmap_open;
 d_close_t	ringmap_close;
 d_ioctl_t	ringmap_ioctl;
@@ -61,11 +60,16 @@
 	.d_name 	= "ringmap_cdev"
 };
 
+
+struct ringmap_global_list ringmap_list_head = 
+		SLIST_HEAD_INITIALIZER(ringmap_list_head);
+
+
 /*
  * Will called from if_em.c before returning from 
  * em_attach() function.  
  */
-int 
+struct ringmap *
 ringmap_attach(device_t dev, struct ringmap_functions *rf) 
 {	
 	struct ringmap *rm = NULL;
@@ -75,8 +79,8 @@
 	rm = (struct ringmap *) contigmalloc (sizeof(struct ringmap), 
 							M_DEVBUF, M_ZERO, 0, -1L, PAGE_SIZE, 0);
 	if (rm == NULL) { 
-		RINGMAP_ERROR(Can not allocate space for ringmap structure); 
-		return (-1); 
+		RINGMAP_ERROR(Can not allocate space for ringmap structure);
+		return (NULL);
 	}
 
 	/* 
@@ -93,29 +97,31 @@
 						RINGMAP_DEVICE"%d", device_get_unit(dev));
 	if (rm->cdev == NULL) {
 		RINGMAP_ERROR(Can not create char device);
-		return (-1);
+		contigfree(rm, sizeof(struct ringmap), M_DEVBUF);
+		return (NULL);
 	}
 
-	/* Set function pointers */
+	/* 
+	 * Tell to ringmap which hardware and driver speciffic functions 
+	 * should it use 
+	 */
 	rm->funcs = rf;
-	get_ringmap_p = rf->dev_to_ringmap;
-	get_device_p = rf->cdev_to_dev;
 
-	/* Store adapters device structure */
+	/* Store adapters device structure by ringmap */
 	rm->dev = dev;
 
 	/* Initialize the list of capturing objects */
 	SLIST_INIT(&rm->object_list);
 
+	/* Insert ringmap in the global list */
+	SLIST_INSERT_HEAD(&ringmap_list_head, rm, entries);
+
 	/* Init the mutex to protecting our data */
 	RINGMAP_LOCK_INIT(rm, device_get_nameunit(dev));
 
-	/* set the pointer to ringmap into the adapters structure */
-	rm->funcs->set_ringmap_to_adapter(dev, rm);
-
 	RINGMAP_FUNC_DEBUG(end); 
 
-	return (0);	
+	return (rm);	
 }
 
 
@@ -127,24 +133,28 @@
 
 	RINGMAP_FUNC_DEBUG(start);
 	
-	rm = get_ringmap_p (dev);
-	if (rm == NULL){
+	rm = dev2ringmap(dev);
+	if (rm == NULL) {
 		RINGMAP_WARN(Can not get pointer to ringmap structure);
 		return (-1);
 	}
 
-	/* Remove all capturing objects properly */
+	/* Remove all capturing objects associated with ringmap */
     while (!SLIST_EMPTY(&rm->object_list)) {
 	    co = SLIST_FIRST(&rm->object_list);
 	    SLIST_REMOVE_HEAD(&rm->object_list, objects);
 	    clear_capt_object((void *)co);
     }
 
+	/* Destroy char device associated with ringmap */
 	if (rm->cdev != NULL)
 		destroy_dev(rm->cdev);
-	
+
 	RINGMAP_LOCK_DESTROY(rm);
 
+	/* And remove ringmap from global list */
+	SLIST_REMOVE(&ringmap_list_head, rm, ringmap, entries);
+	
 	contigfree(rm, sizeof(struct ringmap), M_DEVBUF);
 
 	RINGMAP_FUNC_DEBUG(end);
@@ -172,8 +182,7 @@
 	printf(RINGMAP_PREFIX"[%s] pid = %d\n", __func__, td->td_proc->p_pid);
 #endif 
 
-	/* a little magic */
-	rm = get_ringmap_p(get_device_p(cdev));
+	rm = cdev2ringmap(cdev);
 	if ( rm == NULL ) {
 		RINGMAP_ERROR(Null pointer to ringmap structure);
 
@@ -189,20 +198,17 @@
 		err = EIO; goto out;
 	}
 
-	/* check: the current thread shouldn't open more than one time */
-	if (rm->open_cnt) {
-		SLIST_FOREACH(co, &rm->object_list, objects) {
-			if (co->td == td) {
-				RINGMAP_ERROR(Device is opened!);
-
-				err = EIO; goto out;
-			}
+	/* Only ONE open() per thread */
+	SLIST_FOREACH(co, &rm->object_list, objects) {
+		if (co->td == td) {
+			RINGMAP_ERROR(Device is opened!);
+			err = EIO; goto out;
 		}
 	}
 
 	/* 
-	 * Allocate memory for ring structure Use contigmalloc(9) to get PAGE_SIZE
-	 * alignment that is needed for memory mapping.  
+	 * Allocate memory for ring structure. Use contigmalloc(9) to get
+	 * PAGE_SIZE alignment that is needed for memory mapping.  
 	 */
 	ring = (struct ring *) contigmalloc (sizeof(struct ring), 
 			M_DEVBUF, M_ZERO, 0, -1L, PAGE_SIZE, 0);
@@ -220,7 +226,6 @@
 			sizeof(struct capt_object), M_DEVBUF, (M_ZERO | M_WAITOK));
 	if ( co == NULL ){
 		contigfree(ring, sizeof(struct ring), M_DEVBUF);
-
 		err = EIO; goto out;
 	}
 
@@ -236,17 +241,21 @@
 	/* Associate the capturing object with a queue */
 	if (rm->funcs->set_queue(co, DEFAULT_QUEUE) == -1) {
 		RINGMAP_ERROR(Can not associate que with the capturing object!);
+
 		contigfree(ring, sizeof(struct ring), M_DEVBUF);
+		FREE(co, M_DEVBUF);
 
 		err = EIO; goto out;
 	}
 #endif 
 
 	/* Init ring-slots  with mbufs and packets adrresses */
-	for (i = 0 ; i < SLOTS_NUMBER ; i++){
+	for (i = 0 ; i < SLOTS_NUMBER ; i++) {
 		if (rm->funcs->set_slot(co, i) == -1){
 			RINGMAP_ERROR(Ring initialization failed!);
+
 			contigfree(ring, sizeof(struct ring), M_DEVBUF);
+			FREE(co, M_DEVBUF);
 
 			err = EIO; goto out;
 		}
@@ -262,18 +271,18 @@
 	SLIST_INSERT_HEAD(&rm->object_list, co, objects);
 
 	/* 
-	 * Store capturing object as private date. So we can access our capturing
+	 * Store capturing object as private data. So we can access our capturing
 	 * object in other syscalls, e.g. read, close, etc... 
 	 */
 	if ( devfs_set_cdevpriv((void *)co, clear_capt_object) ) {
 		RINGMAP_ERROR(Can not set private data!);
+
+		contigfree(ring, sizeof(struct ring), M_DEVBUF);
 		FREE(co, M_DEVBUF);
-		contigfree(ring, sizeof(struct ring), M_DEVBUF);
 
 		err = EIO; goto out;
 	}
 
-	rm->funcs->sync_tail(co->que);
 	rm->open_cnt++;
 
 #if (__RINGMAP_DEB)
@@ -334,7 +343,7 @@
 	}
 	
 	if (rm->open_cnt)
-		rm->open_cnt--;
+		--rm->open_cnt;
 
 	RINGMAP_UNLOCK(rm);
 
@@ -342,6 +351,7 @@
 }
 
 
+/* 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)
@@ -359,7 +369,7 @@
 	RINGMAP_FUNC_DEBUG(start);
 
 
-	rm = get_ringmap_p(get_device_p(cdev));
+	rm = cdev2ringmap(cdev);
 	if ( rm == NULL ) {
 		RINGMAP_ERROR(Null pointer to ringmap structure);
 
@@ -407,7 +417,7 @@
 	RINGMAP_FUNC_DEBUG(start);
 
 	/* Get pointer to the ringmap structure */
-	rm = get_ringmap_p(get_device_p(cdev));
+	rm = cdev2ringmap(cdev);
 
 	if (devfs_get_cdevpriv((void **)&co)) {
 		RINGMAP_ERROR(Can not get capturing object);
@@ -448,30 +458,12 @@
 	printf("[%s] pid = %d\n", __func__, td->td_proc->p_pid);
 #endif 
 
-	/* Eliminate it. Use devfs_* funcs */
-	rm = get_ringmap_p(get_device_p(cdev));
-	if (rm == NULL) {
-		RINGMAP_ERROR(NULL pointer. ioctl can not be accomplished);
-
-		/* TODO: look whether ENODEV is a correctly for this case */
-		return(ENODEV);
-	}
-
-	RINGMAP_LOCK(rm);
 	if ( devfs_get_cdevpriv((void **)&co) ) {
-		RINGMAP_IOCTL(Error! Can not get private date!)
+		RINGMAP_IOCTL(Error! Can not get private date!);
 		return (ENODEV);
 	}
-	if (co->td != curthread){
 
-		RINGMAP_IOCTL(Wrong private data!);
-
-		SLIST_FOREACH(co, &rm->object_list, objects) {
-			if ( co->td == curthread)
-				break;
-		}
-	}
-	RINGMAP_UNLOCK(rm);
+	rm = co->rm;
 
 	switch( cmd ){
 
@@ -494,7 +486,7 @@
 			co->ring->user_wait_kern++;
 
 			/* Set adapter TAIL register */
-			rm->funcs->sync_tail(co->que);
+			rm->funcs->sync_tail(co);
 
 #if (__RINGMAP_DEB)
 			print_capt_obj(co);
@@ -543,3 +535,30 @@
 				(unsigned int)co->que);
 	}
 }
+
+
+struct ringmap *
+dev2ringmap(device_t dev)
+{
+	struct ringmap *rm = NULL;
+
+	SLIST_FOREACH(rm, &ringmap_list_head, entries) {
+		if (rm->dev == dev) 
+			return(rm);
+	}
+
+	return(rm);
+}
+
+
+struct ringmap *
+cdev2ringmap(struct cdev *cdev)
+{
+	struct ringmap *rm = NULL;
+	
+	SLIST_FOREACH(rm, &ringmap_list_head, entries) {
+		if (rm->cdev == cdev) 
+			return(rm);
+	}
+	return(rm);
+}

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

@@ -76,11 +76,11 @@
 };
 
 /*
- * This structure represents the packets ringbuffer.  The structure should be
+ * This structure represents the packets ringbuffer. The structure should be
  * mapped into the user-space to be visible and accessible from the user
  * capturing application. The ring contains the pointer to SLOTs array. Each
- * SLOT represents one packet. Additionaly, the structure contains 
- * ring-HEAD (kernrp) and ring-TAIL (userrp) poiners. 
+ * SLOT represents one packet. Additionaly, the structure contains ring-HEAD
+ * (kernrp) and ring-TAIL (userrp) poiners. 
  */
 struct ring {
 

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

@@ -24,10 +24,8 @@
 	/* Char device for communications between user and kernel spaces */
 	struct 	cdev 	*cdev;
 
-	/* 
-	 * Number of processes that opened cdev. 
-	 * A.K.A. number of capturing objects  
-	 */
+	/* Number of processes that opened cdev. 
+	 * A.K.A. number of capturing objects  */
 	uint32_t volatile open_cnt;
 	
 	/* Hardware dependent functions */
@@ -36,20 +34,18 @@
 	/* Mutex that should protect the data allocated in the ring */
 	struct mtx	ringmap_mtx;
 
+	/* Head of the list of capturing objects */
 	SLIST_HEAD(object_list, capt_object) object_list;
 
-	/* Counts number of hardware interrupts */
-	unsigned long long interrupts_counter;
+	/* Next ringmap in the list */
+	SLIST_ENTRY(ringmap) entries;
 };
 
+/* SLIST of ringmap structures */
+SLIST_HEAD(ringmap_global_list, ringmap);
+
 struct ringmap_functions {
 
-	/* 
-	 * Set pointer to the ringmap structure into the adapters
-	 * driver structure. 
-	 */
-	int (*set_ringmap_to_adapter)(device_t, struct ringmap*);
-
 	/*
 	 * In some situations it is safe to disable 
 	 * interrupts on adapter. 
@@ -66,7 +62,7 @@
 	/*
 	 * This function should be calld from delayed interrupt 
 	 * function. It can contain operations that must not be 
-	 * very fast.
+	 * very fast (can sleep).
 	 */
 	void (*delayed_isr)(void *);
 
@@ -81,8 +77,8 @@
 
 	/* 
 	 * Next functions synchronize the tail and head hardware registers
-	 * with head and tail software varibles which are also visible from 
-	 * user-space process. 
+	 * with head and tail software varibles visible in both  
+	 * kernel- and user-space. 
 	 *
 	 * Synchronisation rules:
 	 * 1. SYNC_HEAD: HARDWARE_HEAD => SOFTWARE_HEAD
@@ -90,28 +86,27 @@
 	 * 		HEAD-variable: ring->kernrp.  The User-space process shouldn't
 	 * 		touch the ring->kernrp variable. Only hardware increment the value
 	 * 		in the HEAD register onto adapters chip while receiving new
-	 * 		packets, and only driver (kernel) synchronize then hardware HEAD
+	 * 		packets, and only driver (kernel) synchronizes then hardware HEAD
 	 * 		with ring->kernrp.
 	 *
 	 * 2. SYNC_TAIL: SOFTWARE_TAIL => HARDWARE_TAIL
 	 *		set value from software TAIL-variable: ring->userrp into the
 	 *		hardware TAIL-register. Hardware shouldn't change the content of
-	 *		TAIL-register.  Software after reading one packet in RAM increments
-	 *		the value of ring->userrp. Kernel will check this value and set it
-	 *		into the hardware TAIL-register.
+	 *		TAIL-register.  Software after reading one packet in RAM
+	 *		increments the value of ring->userrp. Kernel will check this value
+	 *		(it is mapped - visible in kernel and user) and set it into the
+	 *		hardware TAIL-register.
 	 */
-	void (*sync_tail)(void *);
-	void (*sync_head)(void *);
+	void (*sync_tail)(struct capt_object *);
+	void (*sync_head)(struct capt_object *);
 
 	/* Initialize the ring slot */
 	int (*set_slot)(struct capt_object *, unsigned int);
 
-	/* Associate the capturing objec with a hardware queue */
+	/* Associate the capturing objec with a hardware queue. Usable ONLY
+	 * on controllers supported multiple queues */
 	int (*set_queue)(struct capt_object *, unsigned int);
 
-	struct ringmap *(*dev_to_ringmap)(device_t);
-
-	device_t (*cdev_to_dev)(struct cdev *);
 };
 
 /* MUTEX */

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


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


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


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




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