From owner-p4-projects@FreeBSD.ORG Mon Oct 18 17:56:44 2010 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 2C24F106566B; Mon, 18 Oct 2010 17:56:44 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E2C4C1065675 for ; Mon, 18 Oct 2010 17:56:43 +0000 (UTC) (envelope-from afiveg@FreeBSD.org) Received: from skunkworks.freebsd.org (skunkworks.freebsd.org [IPv6:2001:4f8:fff6::2d]) by mx1.freebsd.org (Postfix) with ESMTP id CE3A98FC20 for ; Mon, 18 Oct 2010 17:56:43 +0000 (UTC) Received: from skunkworks.freebsd.org (localhost [127.0.0.1]) by skunkworks.freebsd.org (8.14.4/8.14.4) with ESMTP id o9IHuhJb054718 for ; Mon, 18 Oct 2010 17:56:43 GMT (envelope-from afiveg@FreeBSD.org) Received: (from perforce@localhost) by skunkworks.freebsd.org (8.14.4/8.14.4/Submit) id o9IHuh42054715 for perforce@freebsd.org; Mon, 18 Oct 2010 17:56:43 GMT (envelope-from afiveg@FreeBSD.org) Date: Mon, 18 Oct 2010 17:56:43 GMT Message-Id: <201010181756.o9IHuh42054715@skunkworks.freebsd.org> X-Authentication-Warning: skunkworks.freebsd.org: perforce set sender to afiveg@FreeBSD.org using -f From: Alexandre Fiveg To: Perforce Change Reviews Precedence: bulk Cc: Subject: PERFORCE change 184865 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 18 Oct 2010 17:56:44 -0000 http://p4web.freebsd.org/@@184865?ac=10 Change 184865 by afiveg@cottonmouth on 2010/10/18 17:55:43 Initialization of ring and association it with the capturing object is moved to ioctl IOCTL_ATTACH_RING. I've done it in order make it easier the attachment of certain queues to the capturing object in case if we have to do with multiqueue controller. Affected function: ringmap_ioctl. Two new ioctls: IOCTL_GETQUEUE_NUM, IOCTL_ATTACH_RING. Affected files ... .. //depot/projects/soc2010/ringmap/current/contrib/libpcap/ringmap_pcap.c#35 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.c#36 edit .. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.c#51 edit .. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.h#50 edit .. //depot/projects/soc2010/ringmap/current/sys/net/ringmap_kernel.h#20 edit .. //depot/projects/soc2010/ringmap/scripts/build_ringmap.sh#33 edit .. //depot/projects/soc2010/ringmap/scripts/set_ringmap.sh#34 edit .. //depot/projects/soc2010/ringmap/scripts/tailf_ringmap_msgs.sh#28 edit Differences ... ==== //depot/projects/soc2010/ringmap/current/contrib/libpcap/ringmap_pcap.c#35 (text+ko) ==== @@ -43,7 +43,7 @@ int init_mmapped_capturing(const char *device, pcap_t *p) { - int devmem_fd, i; + int devmem_fd, i, queue_num; void *tmp_addr; char dev_path[1024]; off_t memoffset = 0; @@ -70,7 +70,7 @@ } /** - ** !!! Very important piece of code !!! + ** !!! Very important !!! ** ** Here we map the ring structure into the ** memory space of current process. @@ -80,6 +80,11 @@ 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 @@ -101,10 +106,6 @@ RINGMAP_ERROR("Wrong size of ring buffer!"); return -1; } - if (p->ring->pid != getpid() ){ - RINGMAP_ERROR(Wrong ring was mapped! Exit!); - return (-1); - } #if (__RINGMAP_DEB) printf("Virtual address of ring is 0x%X\n", p->ring); ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.c#36 (text+ko) ==== @@ -25,7 +25,7 @@ struct mbuf * rm_8254_get_mbuf(void *buffer_area, unsigned int num); vm_offset_t rm_8254_get_packet(void *buffer_area, unsigned int num); vm_offset_t rm8254_get_rx_desc(void * rx_desc_area, unsigned int num); - +int rm_8245_get_queuesnum(void); extern devclass_t em_devclass; @@ -41,6 +41,7 @@ .get_packet = rm_8254_get_packet, .set_queue = rm_8254_set_queue, .pkt_filter = NULL, + .get_queuesnum = rm_8245_get_queuesnum, }; @@ -52,6 +53,13 @@ } +int +rm_8245_get_queuesnum() +{ + return (1); +} + + vm_offset_t rm_8254_get_packet(void *buffer_area, unsigned int num) { ==== //depot/projects/soc2010/ringmap/current/sys/net/ringmap.c#51 (text+ko) ==== @@ -263,40 +263,12 @@ } ring->size = SLOTS_NUMBER; - ring->pid = td->td_proc->p_pid; /* Unneeded thing. TODO: Replace it with somth more resonable */ co->ring = ring; co->td = td; co->rm = rm; - /* The next should be probably done in the ioctl() */ -#ifdef DEFAULT_QUEUE - /* 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++) { - if (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; - } -#if (__RINGMAP_DEB) - PRINT_SLOT(ring, i); -#endif - } - /* * Insert the capturing object in the single linked list */ @@ -487,7 +459,7 @@ ringmap_ioctl (struct cdev *cdev, u_long cmd, caddr_t data, int fflag, struct thread *td) { - int err = 0, err_sleep = err_sleep, size, flen; + int err = 0, err_sleep = err_sleep, size, flen, qn, i; struct ringmap *rm = NULL; struct capt_object *co; @@ -576,6 +548,37 @@ co->rm->funcs->pkt_filter = ringmap_bpf_filter; break; + /* Tell to user how many queues we have */ + case IOCTL_GETQUEUE_NUM: + qn = rm->funcs->get_queuesnum(); + *(int *)data = qn; + break; + + /* Associate the ring/queue with the capturing object */ + case IOCTL_ATTACH_RING: + qn = *(int *)data; + + /* Associate the capturing object with a queue */ + if (rm->funcs->set_queue(co, qn) == -1) { + RINGMAP_ERROR(Queue attachment failed!); + err = EINVAL; + goto out; + } + + /* Init ring-slots with mbufs and packets adrresses */ + for (i = 0 ; i < SLOTS_NUMBER ; i++) { + if (set_slot(co, i) == -1){ + RINGMAP_ERROR(Ring initialization failed!); + err = EINVAL; + goto out; + } +#if (__RINGMAP_DEB) + PRINT_SLOT(co->ring, i); +#endif + } + break; + + default: RINGMAP_ERROR("Undefined command!"); err = ENODEV; @@ -599,9 +602,12 @@ printf("[%s] Set slot: %d\n", __func__, slot_num); #endif - /* Now if everything is Ok, we can initialize ring pointers */ ring->slot[slot_num].mbuf.kern = (vm_offset_t)rm->funcs->get_mbuf(co->rx_buffers, slot_num); + + if (ring->slot[slot_num].mbuf.kern == 0) + return (-1); + ring->slot[slot_num].mbuf.phys = (bus_addr_t)vtophys(ring->slot[slot_num].mbuf.kern); ==== //depot/projects/soc2010/ringmap/current/sys/net/ringmap.h#50 (text+ko) ==== @@ -132,10 +132,6 @@ unsigned long long intr_num; - /* Ring identification. Should be initialized with process ID */ - /* TODO: use other ID. Using PID is a wrong way */ - unsigned int pid; - /* Array of slots (A.K.A packet buffers) */ struct ring_slot volatile slot[SLOTS_NUMBER]; }; @@ -179,7 +175,18 @@ */ #define IOCTL_SETFILTER _IOW(RINGMAP_IOC_MAGIC, 6, struct bpf_program) +/* + * Returns the number of available queues (A.K.A. rings) + */ +#define IOCTL_GETQUEUE_NUM _IOR(RINGMAP_IOC_MAGIC, 7, int) +/* + * Associate user-space capturing process with a queue + */ +#define IOCTL_ATTACH_RING _IOW(RINGMAP_IOC_MAGIC, 8, int) + + + /********************************************** * Arithmetic in Ring Buffer **********************************************/ @@ -338,10 +345,8 @@ #define PRINT_RING_PTRS(ring) \ do { \ - printf("\n=+= [%s] pid = %d\n", __func__, ring->pid); \ PRINT_TAIL(ring) \ PRINT_HEAD(ring) \ - printf("\n"); \ } while (0); ==== //depot/projects/soc2010/ringmap/current/sys/net/ringmap_kernel.h#20 (text+ko) ==== @@ -116,6 +116,10 @@ */ void (*pkt_filter)(struct capt_object *, int); + /* Retunrns the number of available queues */ + int (*get_queuesnum)(void); + + /* * Set timestamp for packet placed in the slot. If ts != NULL set ts as * timestamp. Else compute timestamp calling getmicrotime(9) or take ==== //depot/projects/soc2010/ringmap/scripts/build_ringmap.sh#33 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/scripts/set_ringmap.sh#34 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/scripts/tailf_ringmap_msgs.sh#28 (text+ko) ====