Date: Sat, 3 Jul 2010 05:15:13 GMT From: Alexandre Fiveg <afiveg@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 180424 for review Message-ID: <201007030515.o635FDtk052344@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@180424?ac=10 Change 180424 by afiveg@cottonmouth on 2010/07/03 05:14:42 Multithreading for ringmap alsmost ready. Cosmetic fixes remain. Affected files ... .. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-bpf.c#5 edit .. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-int.h#5 edit .. //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap.c#7 edit .. //depot/projects/soc2010/ringmap/current/contrib/libpcap/ringmap_pcap.c#12 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_80003es2lan.c#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_80003es2lan.h#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82540.c#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82541.c#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82541.h#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82542.c#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82543.c#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82543.h#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82571.c#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82571.h#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82575.c#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82575.h#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_api.c#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_api.h#6 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_defines.h#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_hw.h#8 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_ich8lan.c#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_ich8lan.h#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_mac.c#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_mac.h#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_manage.c#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_manage.h#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_nvm.c#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_nvm.h#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_osdep.c#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_osdep.h#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_phy.c#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_phy.h#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_regs.h#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_em.c#9 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_em.h#7 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_igb.c#7 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_igb.h#5 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.c#20 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.h#18 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.c#19 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.h#17 edit .. //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_e1000.h#9 edit .. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.c#23 edit .. //depot/projects/soc2010/ringmap/current/sys/net/ringmap.h#23 edit .. //depot/projects/soc2010/ringmap/scripts/build_ringmap.sh#7 edit .. //depot/projects/soc2010/ringmap/scripts/set_ringmap.sh#8 edit .. //depot/projects/soc2010/ringmap/scripts/tailf_ringmap_msgs.sh#3 edit Differences ... ==== //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-bpf.c#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap-int.h#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/contrib/libpcap/pcap.c#7 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/contrib/libpcap/ringmap_pcap.c#12 (text+ko) ==== @@ -131,12 +131,8 @@ return (-1); } -#if (__RINGMAP_DEB) - printf("[%s] Number of descriptors: %d \n", __func__, SLOTS_NUMBER); -#endif - if (ringmap_cdev_fd < 0){ - RINGMAP_ERROR(ringmap char device seems tgo be not open); + RINGMAP_ERROR(ringmap char device is not open); return (-1); } tmp_addr = mmap(0, sizeof(struct ring), PROT_WRITE|PROT_READ, MAP_SHARED, ringmap_cdev_fd, 0); @@ -299,13 +295,12 @@ // if (tmp_res == -1) // printf(ERR_PREFIX"[%s] Error by unmapping of statistic structure %d\n", __func__, i); //} - +out: if (ringmap_cdev_fd >= 0){ if ( close(ringmap_cdev_fd) == -1 ) perror("close()"); } -out: RINGMAP_FUNC_DEBUG(end); } @@ -337,8 +332,8 @@ again: #ifdef __RINGMAP_DEB - printf("[%s] user to kern distance = %d\n", __func__, - SW_TAIL_TO_HEAD_DIST(ring)); +// printf("[%s] user to kern distance = %d\n", __func__, + // SW_TAIL_TO_HEAD_DIST(ring)); #endif if ( RING_IS_EMPTY(ring) ) { @@ -432,10 +427,6 @@ 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->ring->pkt_counter) / (p->ring->interrupts_counter))); - return (err); } ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_80003es2lan.c#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_80003es2lan.h#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82540.c#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82541.c#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82541.h#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82542.c#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82543.c#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82543.h#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82571.c#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82571.h#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82575.c#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_82575.h#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_api.c#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_api.h#6 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_defines.h#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_hw.h#8 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_ich8lan.c#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_ich8lan.h#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_mac.c#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_mac.h#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_manage.c#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_manage.h#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_nvm.c#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_nvm.h#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_osdep.c#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_osdep.h#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_phy.c#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_phy.h#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/e1000_regs.h#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_em.c#9 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_em.h#7 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_igb.c#7 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_igb.h#5 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.c#20 (text+ko) ==== @@ -1389,7 +1389,7 @@ 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, adapter->rm->ring); + adapter->rm->funcs->sync_head(adapter->dev); wakeup(adapter->rm); } @@ -3574,15 +3574,8 @@ if (accept_frame) { #ifdef RINGMAP - if (adapter->rm != NULL) { - RINGMAP_LOCK(adapter->rm); - adapter->rm->funcs->delayed_isr_per_packet(adapter->rm->ring, - i); -#ifdef __RINGMAP_DEB - PRINT_SLOT((adapter->rm->ring), (i), (adapter)); -#endif - RINGMAP_UNLOCK(adapter->rm); - } + if (adapter->rm != NULL) + adapter->rm->funcs->delayed_isr_per_packet(adapter->dev, i); #endif #ifndef RINGMAP ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/if_lem.h#18 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.c#19 (text+ko) ==== @@ -27,11 +27,11 @@ int rm_8254_set_slot(struct ring *, struct adapter *, unsigned int); void rm_8254_interrupt(void *); void rm_8254_delayed_interrupt(void *); -int rm_8254_print_ring_pointers(struct adapter *); +int rm_8254_print_ring_pointers(struct adapter *, struct ring *); void rm_8254_sync_head_tail(device_t, struct ring *); void rm_8254_sync_tail(device_t, struct ring *); -void rm_8254_sync_head(device_t, struct ring *); -void rm_8254_delayed_interrupt_per_packet(struct ring *, int); +void rm_8254_sync_head(device_t); +void rm_8254_delayed_interrupt_per_packet(device_t, int); struct ring *rm_8254_alloc_ring(device_t); extern devclass_t em_devclass; @@ -41,53 +41,6 @@ -struct ring * -rm_8254_alloc_ring(device_t dev) -{ - struct ring *ring; - - /* - * 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); - if (ring == NULL) { - RINGMAP_ERROR(Can not allocate space for ring structure); - - return (NULL); - } - - - if (rm_8254_init_slots(ring, dev) == -1) { - RINGMAP_ERROR(The ring is not initialized. Device will not be opened!); - contigfree(ring, sizeof(struct ring), M_DEVBUF); - - return (NULL); - } - - return (ring); -} - -void -rm_8254_delayed_interrupt_per_packet(struct ring *ring, int slot_num) -{ - RINGMAP_INTR(start); - - 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 = ring->last_ts; -#endif - } - - RINGMAP_INTR(end); -} - /* * This function synchronize the tail and head hardware registers @@ -102,7 +55,7 @@ rm_8254_sync_head_tail(device_t dev, struct ring *ring) { rm_8254_sync_tail(dev, ring); - rm_8254_sync_head(dev, ring); + rm_8254_sync_head(dev); } @@ -112,24 +65,26 @@ struct adapter *adapter; adapter = (struct adapter *)device_get_softc(dev); - RINGMAP_LOCK(adapter->rm); - if (ring != NULL) { - RINGMAP_HW_SYNC_TAIL(adapter, ring); /* SW_TAIL ==> HW_TAIL */ - } - RINGMAP_UNLOCK(adapter->rm); + RINGMAP_HW_SYNC_TAIL(adapter, ring); /* SW_TAIL ==> HW_TAIL */ } void -rm_8254_sync_head(device_t dev, struct ring *ring) +rm_8254_sync_head(device_t dev) { + struct capt_instance *ci = NULL; struct adapter *adapter; + adapter = (struct adapter *)device_get_softc(dev); RINGMAP_LOCK(adapter->rm); - if (ring != NULL) { - RINGMAP_HW_SYNC_HEAD(adapter, ring); /* SW_TAIL ==> HW_HEAD */ + + SLIST_FOREACH(ci, &adapter->rm->instance_list, next_instance) { + if (ci->ring != NULL) { + RINGMAP_HW_SYNC_HEAD(adapter, ci->ring); /* SW_TAIL ==> HW_HEAD */ + } } + RINGMAP_UNLOCK(adapter->rm); } @@ -144,33 +99,100 @@ struct adapter *adapter = (struct adapter *) arg; /* count interrupts */ - if ( (adapter->rm != NULL) && (adapter->rm->ring != NULL) && - adapter->rm->ring->td != NULL) { + if ( adapter->rm->open_cnt > 0 ) + adapter->rm->interrupts_counter++; +} + + +void +rm_8254_delayed_interrupt(void *context) +{ + struct adapter *adapter = (struct adapter *)context; + struct capt_instance *ci = NULL; + +// RINGMAP_INTR(start); - adapter->rm->ring->interrupts_counter++; + RINGMAP_LOCK(adapter->rm); + SLIST_FOREACH(ci, &adapter->rm->instance_list, next_instance) { +#ifdef __RINGMAP_DEB + printf("[%s] Ring Kernel Addr:0x%X\n", __func__, (unsigned int)ci->ring); +#endif + if (ci->ring != NULL) { + /* TODO: find the next ring */ + rm_8254_sync_tail(adapter->dev, ci->ring); +#ifdef RINGMAP_TIMESTAMP + getmicrotime(&ci->ring->last_ts); +#endif + } } + + RINGMAP_UNLOCK(adapter->rm); + +// RINGMAP_INTR(end); } void -rm_8254_delayed_interrupt(void *context) +rm_8254_delayed_interrupt_per_packet(device_t dev, int slot_num) { - struct adapter *adapter = (struct adapter *)context; + struct capt_instance *ci = NULL; + struct adapter *adapter = NULL; + struct ringmap *rm = NULL; + + adapter = (struct adapter *)device_get_softc(dev); + rm = adapter->rm; - RINGMAP_INTR(start); + //RINGMAP_INTR(start); - rm_8254_sync_tail(adapter->dev, adapter->rm->ring); + RINGMAP_LOCK(rm); + SLIST_FOREACH(ci, &rm->instance_list, next_instance) { + if ( ci->ring != NULL ) { + ci->ring->cur_slot_kern = slot_num; + ci->ring->slot[slot_num].is_ok = 1; + ci->ring->slot[slot_num].intr_num = rm->interrupts_counter; #ifdef RINGMAP_TIMESTAMP - RINGMAP_LOCK(adapter->rm); - if (adapter->rm->ring != NULL) { - getmicrotime(&adapter->rm->ring->last_ts); + ci->ring->slot[slot_num].ts = ci->ring->last_ts; +#endif + +#ifdef __RINGMAP_DEB + PRINT_SLOT((ci->ring), (slot_num), adapter); +#endif + } + } + RINGMAP_UNLOCK(rm); + + //RINGMAP_INTR(end); +} + + +struct ring * +rm_8254_alloc_ring(device_t dev) +{ + struct ring *ring; + + /* + * 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); + if (ring == NULL) { + RINGMAP_ERROR(Can not allocate space for ring structure); + + return (NULL); } - RINGMAP_UNLOCK(adapter->rm); -#endif + + if (rm_8254_init_slots(ring, dev) == -1) { + RINGMAP_ERROR(The ring is not initialized. Device will not be opened!); + contigfree(ring, sizeof(struct ring), M_DEVBUF); + + return (NULL); + } - RINGMAP_INTR(end); + return (ring); } @@ -215,6 +237,9 @@ RINGMAP_ERROR(Ring initialization failed!); return (-1); } +#if (__RINGMAP_DEB) + ringmap_print_slot(ring, slot_num); +#endif } RINGMAP_FUNC_DEBUG(end); @@ -262,9 +287,6 @@ ring->slot[slot_num].descriptor.phys = (bus_addr_t)vtophys(GET_DESCRIPTOR_P(adapter, slot_num)); -#if (__RINGMAP_DEB) - ringmap_print_slot(ring, slot_num); -#endif return (0); fail: @@ -355,7 +377,7 @@ int -rm_8254_print_ring_pointers(struct adapter *adapter) +rm_8254_print_ring_pointers(struct adapter *adapter, struct ring *ring) { unsigned int rdt, rdh; struct ringmap *rm = NULL; @@ -372,7 +394,7 @@ /* -> Critical Section: begin */ RINGMAP_LOCK(rm); - if ( (rm == NULL) || (rm->ring == NULL) ) + if ( (rm == NULL) || (ring == NULL) ) goto out; rdh = RINGMAP_HW_READ_HEAD(adapter); @@ -382,8 +404,8 @@ printf("== + HW HEAD = %d (KERN POINTER)\n", rdh); printf("== + HW TAIL = %d (USER POINTER)\n", rdt); printf("== +\n"); - printf("== + kernrp = %d \n", rm->ring->kernrp); - printf("== + userrp = %d \n", rm->ring->userrp); + printf("== + kernrp = %d \n", ring->kernrp); + printf("== + userrp = %d \n", ring->userrp); printf("== ++++++++++++++++++++++++++++++++++++++ \n\n"); out: ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_8254.h#17 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/dev/e1000/ringmap_e1000.h#9 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/current/sys/net/ringmap.c#23 (text+ko) ==== @@ -39,6 +39,7 @@ int set_ringmap_funcs (struct ringmap *, unsigned int); void ringmap_close_cb (void *data); void ringmap_print_slot(struct ring *, unsigned int); +void clear_capt_instance(void *); struct ringmap *(*get_ringmap_p)(device_t); device_t (*get_device_p)(struct cdev *); @@ -52,8 +53,8 @@ extern void rm_8254_delayed_interrupt(void *); extern void rm_8254_sync_head_tail(device_t, struct ring *); extern void rm_8254_sync_tail(device_t, struct ring *); -extern void rm_8254_sync_head(device_t, struct ring *); -extern void rm_8254_delayed_interrupt_per_packet(struct ring *, int); +extern void rm_8254_sync_head(device_t); +extern void rm_8254_delayed_interrupt_per_packet(device_t, int); extern struct ring *rm_8254_alloc_ring(device_t); d_open_t ringmap_open; @@ -206,6 +207,9 @@ /* Store adapters device structure */ rm->dev = dev; + /* Initialize our list of capturing instances */ + SLIST_INIT(&rm->instance_list); + /* Init the mutex to protecting our data */ RINGMAP_LOCK_INIT(rm, device_get_nameunit(dev)); @@ -222,6 +226,7 @@ ringmap_detach(device_t dev) { struct ringmap *rm = NULL; + struct capt_instance *ci = NULL; RINGMAP_FUNC_DEBUG(start); @@ -231,6 +236,12 @@ return (-1); } + while (!SLIST_EMPTY(&rm->instance_list)) { + ci = SLIST_FIRST(&rm->instance_list); + SLIST_REMOVE_HEAD(&rm->instance_list, next_instance); + clear_capt_instance((void *)ci); + } + destroy_dev(rm->cdev); RINGMAP_LOCK_DESTROY(rm); @@ -238,8 +249,6 @@ contigfree(rm->funcs, sizeof(struct ringmap_functions), M_DEVBUF); contigfree(rm, sizeof(struct ringmap), M_DEVBUF); - rm = NULL; - RINGMAP_FUNC_DEBUG(end); return (0); @@ -257,6 +266,7 @@ { int err = 0; struct ringmap *rm = NULL; + struct capt_instance *ci = NULL; RINGMAP_FUNC_DEBUG(start); @@ -273,54 +283,48 @@ return (EIO); } + MALLOC(ci, struct capt_instance *, + sizeof(struct capt_instance), M_DEVBUF, (M_ZERO | M_WAITOK)); + if ( ci == NULL ){ + return (EIO); + } + /* * I think it is safe to disable interupts while we allocate * allocate memory for oure structures */ rm->funcs->disable_intr(rm->dev); - /* -> Critical Section: begin */ RINGMAP_LOCK(rm); - - if ( rm->dev == NULL ) { - RINGMAP_ERROR(Null pointer to device structure of adapter); - - err = EIO; goto out; - } /* Allocate ring */ - rm->ring = rm->funcs->alloc_ring(rm->dev); - - /* Check for any cases */ - if ( rm->ring == NULL ) { + ci->ring = rm->funcs->alloc_ring(rm->dev); + if ( ci->ring == NULL ) { RINGMAP_ERROR(Error! Please debug!); err = EIO; goto out; } - - /* Set ring fields in the initial state */ - rm->ring->kern_wait_user = 0; - rm->ring->user_wait_kern = 0; - rm->ring->interrupts_counter = 0; - rm->ring->pkt_counter = 0; - rm->ring->size = SLOTS_NUMBER; + ci->ring->size = SLOTS_NUMBER; + ci->td = td; + ci->rm = rm; - /* Store pointer to the thread */ - rm->ring->td = td; - - /* - * 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); + SLIST_INSERT_HEAD(&rm->instance_list, ci, next_instance); + if ( devfs_set_cdevpriv((void *)ci, clear_capt_instance) ) { + RINGMAP_ERROR(Ooooooooooooooohhhhhhhh !!!!!); err = EIO; goto out; } + + rm->open_cnt++; +#ifdef __RINGMAP_DEB + printf("[%s] currthread->proc->pid: %d \n", __func__, curthread->td_proc->p_pid); + printf("[%s] ci->td->proc->pid: %d\n", __func__, ci->td->td_proc->p_pid); + + printf("[%s] Ring Kernel Addr:0x%X\n", __func__, (unsigned int)ci->ring); +#endif out: RINGMAP_UNLOCK(rm); - /* -> Critical Section: end */ rm->funcs->enable_intr(rm->dev); @@ -333,32 +337,43 @@ int ringmap_close(struct cdev *cdev, int flag, int otyp, struct thread *td) { + struct capt_instance *ci = NULL; + struct capt_instance *ki = NULL; struct ringmap *rm = NULL; RINGMAP_FUNC_DEBUG(start); rm = get_ringmap_p(get_device_p(cdev)); - if (rm == NULL){ - RINGMAP_ERROR(Can not get pointer to ringmap structure); - /* TODO: Fix it! */ - return (0); - } + RINGMAP_LOCK(rm); - rm->funcs->disable_intr(rm->dev); + devfs_get_cdevpriv((void **)&ci); - atomic_readandclear_int(&rm->open_cnt); +#ifdef __RINGMAP_DEB + printf("[%s] currthread->proc->pid: %d \n", __func__, curthread->td_proc->p_pid); + printf("[%s] ci->td->proc->pid: %d\n", __func__, ci->td->td_proc->p_pid); - /* -> Critical Section: begin */ - RINGMAP_LOCK(rm); + printf("[%s] Ring Kernel Addr:0x%X\n", __func__, (unsigned int)ci->ring); +#endif +// if (ci->ring != NULL) +// contigfree(ci->ring, sizeof(struct ring), M_DEVBUF); +// ci->ring = NULL; +// +// /* Remove the capturing instance from list */ +// SLIST_REMOVE(&rm->instance_list, ci, capt_instance, next_instance); +// FREE(ci, M_DEVBUF); +// ci = NULL; +// rm->open_cnt--; - if (rm->ring != NULL) - contigfree(rm->ring, sizeof(struct ring), M_DEVBUF); + SLIST_FOREACH(ki, &rm->instance_list, next_instance) { +#ifdef __RINGMAP_DEB + printf("[%s] Aufter dealocation: ", __func__); + printf("[%s] ki->td->proc->pid: %d\n", __func__, ki->td->td_proc->p_pid); + printf("[%s] Ring Kernel Addr:0x%X\n", __func__, (unsigned int)ki->ring); +#endif + } - rm->ring = NULL; - RINGMAP_UNLOCK(rm); - /* -> Critical Section: end */ RINGMAP_FUNC_DEBUG(end); @@ -372,27 +387,16 @@ { int err = 0; struct ringmap *rm = NULL; + struct capt_instance *ci = NULL; + pid_t pid = 0; + + pid = curthread->td_proc->p_pid; RINGMAP_FUNC_DEBUG(start); /* Get pointer to the ringmap structure */ rm = get_ringmap_p(get_device_p(cdev)); - - /* Check pointers: rm and rm->ring should be allocated */ - if (rm == NULL){ - RINGMAP_ERROR(Can not get pointer to ringmap structure); - return (ENXIO); - } - - /* -> Critical Section: begin */ - RINGMAP_LOCK(rm); - - if (rm->ring == NULL){ - RINGMAP_ERROR(Can not get pointer to ring structure); - - err = ENXIO; goto out; - } - + /* Check protections */ if (nprot & PROT_EXEC) { RINGMAP_WARN("PROT_EXEC ist set"); @@ -400,11 +404,20 @@ err = ERESTART; goto out; } - *paddr = vtophys(rm->ring); + /* -> Critical Section: begin */ + RINGMAP_LOCK(rm); + + if (devfs_get_cdevpriv((void **)&ci)) { + SLIST_FOREACH(ci, &rm->instance_list, next_instance) { + if ( ci->td == curthread) + break; + } + } + + *paddr = vtophys(ci->ring); out: RINGMAP_UNLOCK(rm); - /* -> Critical Section: end */ RINGMAP_FUNC_DEBUG(end); @@ -418,18 +431,23 @@ { int err = 0, err_sleep = err_sleep; struct ringmap *ringmap = NULL; + struct capt_instance *ci; - RINGMAP_IOCTL(start); +// 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)){ + if ( ringmap == NULL ){ RINGMAP_ERROR(NULL pointer. ioctl can not be accomplished); /* TODO: look if ENODEV is a correctly for this case */ return(ENODEV); } + if ( devfs_get_cdevpriv((void **)&ci) ) { + RINGMAP_IOCTL(Error! Can not get private date!) + return (ENODEV); + } + switch( cmd ){ /* Enable Interrupts */ @@ -444,30 +462,30 @@ RINGMAP_IOCTL(interrupts schould be disabled); break; - /* Sleep and wait for new frames */ + /* Sleep and wait for new packets */ case IOCTL_SLEEP_WAIT: - RINGMAP_IOCTL(Sleep and wait for new packets); +// RINGMAP_IOCTL(Sleep and wait for new packets); - ringmap->ring->user_wait_kern++; - ringmap->funcs->sync_head_tail(get_device_p(cdev), ringmap->ring); + ci->ring->user_wait_kern++; + ringmap->funcs->sync_head_tail(ringmap->dev, ci->ring); /* * In the time: from user has called ioctl() until now could * come the new packets. It means, before we are going to sleep * it makes a sence to check if we really must do it :) */ - if (RING_IS_EMPTY(ringmap->ring)) { + if (RING_IS_EMPTY(ci->ring)) { err_sleep = tsleep(ringmap, (PRI_MIN) | PCATCH, "ioctl", 0); } break; case IOCTL_SYNC_HEAD_TAIL: - ringmap->funcs->sync_head_tail(get_device_p(cdev), ringmap->ring); + ringmap->funcs->sync_head_tail(ringmap->dev, ci->ring); break; /* Synchronize sowftware ring-tail with hardware-ring-tail (RDT) */ case IOCTL_SYNC_TAIL: - ringmap->funcs->sync_tail(get_device_p(cdev), ringmap->ring); + ringmap->funcs->sync_tail(ringmap->dev, ci->ring); break; default: @@ -475,11 +493,42 @@ return (ENODEV); } - RINGMAP_IOCTL(end); +// RINGMAP_IOCTL(end); return (err); } + +void +clear_capt_instance(void * data) +{ + struct capt_instance *ci = NULL; + + RINGMAP_FUNC_DEBUG(start); + + if ( data != NULL ) { + ci = (struct capt_instance *)data; + RINGMAP_LOCK(ci->rm); +#ifdef __RINGMAP_DEB + printf("[%s] ci->td->proc->pid: %d\n", __func__, ci->td->td_proc->p_pid); + printf("[%s] Ring Kernel Addr:0x%X\n", __func__, (unsigned int)ci->ring); +#endif + + if ( ci->ring != NULL ){ + contigfree(ci->ring, sizeof(struct ring), M_DEVBUF); + SLIST_REMOVE(&ci->rm->instance_list, ci, capt_instance, next_instance); + FREE(ci, M_DEVBUF); + data = NULL; + } + } else { + RINGMAP_FUNC_DEBUG(NULL pointer to the capturing instance!); + } + + RINGMAP_UNLOCK(ci->rm); + + RINGMAP_FUNC_DEBUG(end); +} + void ringmap_print_slot(struct ring *ring, unsigned int slot_number) { ==== //depot/projects/soc2010/ringmap/current/sys/net/ringmap.h#23 (text+ko) ==== @@ -101,9 +101,6 @@ /* Values from adapters statistic registers */ struct address hw_stats; - /* Capturing thread */ - struct thread *td; - /* * Number of times kernel (hardware) waits for user process. More * specifically, this is the number of times that the write pointer (HEAD) @@ -120,8 +117,6 @@ */ unsigned long long user_wait_kern; - /* Counts number of hardware interrupts */ - unsigned long long interrupts_counter; /* * Slot which currently processed by driver in context of @@ -157,6 +152,16 @@ unsigned int controller_type; }; +struct capt_instance { + struct thread *td; + struct ring *ring; + struct ringmap *rm; + void *private_data; + + SLIST_ENTRY(capt_instance) next_instance; +}; + + /* * This structure will be visible only in the kernel. It contains * the pointers to the ring that should be mapped in user-space, @@ -179,8 +184,10 @@ /* Mutex that should protect the data allocated in the ring */ struct mtx ringmap_mtx; - /* Our ring that have to be mapped in space of user process */ - struct ring *ring; + SLIST_HEAD(instance_list, capt_instance) instance_list; + + /* Counts number of hardware interrupts */ + unsigned long long interrupts_counter; }; struct ringmap_functions { @@ -224,7 +231,7 @@ * should be called from this cycle, so it will be called * per packet. */ - void (*delayed_isr_per_packet)(struct ring *, int); + void (*delayed_isr_per_packet)(device_t, int); /* * Next functions synchronize the tail and head hardware registers @@ -249,7 +256,7 @@ */ void (*sync_head_tail)(device_t, struct ring *); void (*sync_tail)(device_t, struct ring *); - void (*sync_head)(device_t, struct ring *); + void (*sync_head)(device_t); /* Alloc memory for our ring and initialize the slots */ struct ring *(*alloc_ring)(device_t); ==== //depot/projects/soc2010/ringmap/scripts/build_ringmap.sh#7 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/scripts/set_ringmap.sh#8 (text+ko) ==== ==== //depot/projects/soc2010/ringmap/scripts/tailf_ringmap_msgs.sh#3 (text+ko) ====
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201007030515.o635FDtk052344>