fix xsegbd to work with the new scheme. needs further testing
authorUser <user@snf-1286.(none)>
Thu, 6 Sep 2012 13:34:04 +0000 (16:34 +0300)
committerUser <user@snf-1286.(none)>
Thu, 6 Sep 2012 13:34:04 +0000 (16:34 +0300)
also fix xhash shrink bug and xpool exports

14 files changed:
xseg/drivers/kernel/xseg_pthread.c
xseg/drivers/user/xseg_segdev.c
xseg/launch
xseg/peers/kernel/xsegbd.c
xseg/peers/kernel/xsegbd.h
xseg/peers/user/xseg-tool.c
xseg/sys/kernel/segdev.c
xseg/sys/user/Makefile
xseg/xseg/xseg.c
xseg/xtypes/xhash.c
xseg/xtypes/xheap.c
xseg/xtypes/xpool.c
xseg/xtypes/xpool.h
xseg/xtypes/xpool_exports.h [new file with mode: 0644]

index 3a470a5..5a6b7fb 100644 (file)
@@ -22,6 +22,7 @@
 #include <xseg/xseg.h>
 #include <sys/kernel/segdev.h>
 #include <sys/util.h>
+#include <xtypes/xpool.h>
 
 MODULE_DESCRIPTION("xseg_pthread");
 MODULE_AUTHOR("XSEG");
index b6d24aa..cb24666 100644 (file)
@@ -71,6 +71,8 @@ static long segdev_allocate(const char *name, uint64_t size)
                }
        }
 
+       XSEGLOG("creating segment of size %llu\n", size);
+
        if (ioctl(fd, SEGDEV_IOC_CREATESEG, size)) {
                XSEGLOG("Failed to create segment");
                closedev();
index bb5e2e8..24d8caf 100755 (executable)
@@ -25,7 +25,7 @@ function parse_config {
        [ -z "${XSEG_HOME}" ] && XSEG_HOME="/root/archip/xseg"
        [ -z "${MODULES_DIR}" ] && MODULES_DIR="${XSEG_HOME}/lib/kernel"
        #type:name:nr_ports:nr_requests:request_size:extra_size:page_shift
-       [ -z "${SPEC}" ] && SPEC="segdev:xsegbd:16:1024:12"
+       [ -z "${SPEC}" ] && SPEC="segdev:xsegbd:4:1024:12"
        [ -z "${REQS}" ] && REQS=512
        [ -z "${PORTS}" ] && PORTS=16
        [ -z "${IMAGES}" ] && IMAGES="/srv/archip/images"
@@ -79,7 +79,7 @@ function load_all {
 # @param $2            xseg port
 
 function spawn_filed {
-       "${XSEG_HOME}/peers/user/filed" "$1" -p "$2" -g "${SPEC}" -n ${NR_OPS} &> "${XSEG_LOGS}/filed-${HOSTNAME}" &
+       "${XSEG_HOME}/peers/user/filed" "$1" -p "$2" -g "${SPEC}" -n ${NR_OPS} -v &> "${XSEG_LOGS}/filed-${HOSTNAME}" &
 }
 
 # map_volume - Map a volume to an xsegbd device
@@ -144,12 +144,12 @@ filed)
                mk_chardev
                load_all
                spawn_filed ${IMAGES} 1
-               map_volume xsegvol 0 1
+#              map_volume xsegvol 0 1
                ;;
        stop)
                pkill -f peers/user/filed
                sleep 0.5
-               unmap_device 0
+#              unmap_device 0
                rm ${CHRDEV_NAME}
                unload_all
                ;;
index fd303b9..0618451 100644 (file)
@@ -448,6 +448,7 @@ static int xsegbd_get_size(struct xsegbd_device *xsegbd_dev)
        struct xsegbd_pending *pending;
        struct completion comp;
        xport p;
+       void *data;
        int ret = -EBUSY, r;
        xreq = xseg_get_request(xsegbd_dev->xseg, xsegbd_dev->src_portno,
                        xsegbd_dev->dst_portno, X_ALLOC);
@@ -474,6 +475,7 @@ static int xsegbd_get_size(struct xsegbd_device *xsegbd_dev)
        spin_unlock(&xsegbd_dev->reqdatalock);
        if (r < 0)
                goto out_queue;
+       XSEGLOG("for req: %lx, set data %llu (lx: %lx)", xreq, blkreq_idx, (void *) blkreq_idx);
 
        target = xseg_get_target(xsegbd_dev->xseg, xreq);
        strncpy(target, xsegbd_dev->target, xsegbd_dev->targetlen);
@@ -488,8 +490,12 @@ static int xsegbd_get_size(struct xsegbd_device *xsegbd_dev)
         */
 
        xseg_prepare_wait(xsegbd_dev->xseg, xsegbd_dev->src_portno);
-       BUG_ON((p = xseg_submit(xsegbd_dev->xseg, xreq, 
-                                       xsegbd_dev->src_portno, X_ALLOC)) == NoPort);
+       p = xseg_submit(xsegbd_dev->xseg, xreq, 
+                               xsegbd_dev->src_portno, X_ALLOC);
+       BUG_ON(p == NoPort);
+       if ( p == NoPort) {
+               goto out_data;
+       }
        WARN_ON(xseg_signal(xsegbd_dev->xseg, p) < 0);
 
        wait_for_completion_interruptible(&comp);
@@ -500,6 +506,10 @@ out:
        BUG_ON(xseg_put_request(xsegbd_dev->xseg, xreq, xsegbd_dev->src_portno) < 0);
        return ret;
 
+out_data:
+       spin_lock(&xsegbd_dev->reqdatalock);
+       r = xseg_get_req_data(xsegbd_dev->xseg, xreq, &data);
+       spin_unlock(&xsegbd_dev->reqdatalock);
 out_queue:
        xq_append_head(&xsegbd_dev->blk_queue_pending, blkreq_idx, 1);
        
@@ -531,6 +541,7 @@ static void xseg_callback(struct xseg *xseg, xport portno)
                spin_lock(&xsegbd_dev->reqdatalock);
                err = xseg_get_req_data(xsegbd_dev->xseg, xreq, &data); 
                spin_unlock(&xsegbd_dev->reqdatalock);
+               XSEGLOG("for req: %lx, got data %llu (lx %lx)", xreq, (xqindex) data, data);
                if (err < 0) {
                        WARN_ON(2);
                        //maybe put request?
index 9d74466..aa9a75e 100644 (file)
@@ -35,7 +35,8 @@ struct xsegbd_device {
        int major;
        sector_t sectors;
        uint64_t segsize;
-       uint32_t src_portno, dst_portno, nr_requests;
+       xport src_portno, dst_portno;
+       uint32_t  nr_requests;
        struct xq blk_queue_pending;
        struct xsegbd *xsegbd;
        struct xsegbd_pending *blk_req_pending;
index 41194cc..16c09be 100644 (file)
@@ -794,7 +794,7 @@ int cmd_report(uint32_t portno)
        rq = xseg_get_queue(xseg, port, request_queue);
        pq = xseg_get_queue(xseg, port, reply_queue);
        fprintf(stderr, "port %u:\n"
-               "   requests: %llu/%llu  src gw: %lu  dst gw: %lu\n"
+               "   requests: %llu/%llu  src gw: %u  dst gw: %u\n"
                "       free_queue [%p] count : %u\n"
                "    request_queue [%p] count : %u\n"
                "      reply_queue [%p] count : %u\n",
index ee06869..fa75992 100644 (file)
@@ -21,7 +21,7 @@
 #include <linux/vmalloc.h>
 #include <linux/spinlock.h>
 #include <linux/wait.h>
-
+#include <sys/util.h>
 #include "segdev.h"
 
 static struct segdev segdev;
@@ -39,6 +39,7 @@ int segdev_create_segment(struct segdev *dev, u64 segsize, char reserved)
 
        /* vmalloc can handle large sizes */
        ret = -ENOMEM;
+       XSEGLOG("creating segment of size %llu\n", segsize);
        segment = vmalloc(segsize);
        if (!segment)
                goto out_unlock;
index 39d4a66..1242477 100644 (file)
@@ -19,7 +19,6 @@ all: libxseg.a libxseg.so
        make -C xhash all
        make -C xheap all
        make -C xobj all
-       make -C python all
 
 COMMA=,
 _initialize.c: drivers
index b274ecc..dfdee2f 100644 (file)
@@ -551,6 +551,7 @@ int xseg_create(struct xseg_config *cfg)
 
        xops = &type->ops;
        cfg->name[XSEG_NAMESIZE-1] = 0;
+       XSEGLOG("creating segment of size %llu\n", size);
        r = xops->allocate(cfg->name, size);
        if (r) {
                XSEGLOG("cannot allocate segment!\n");
@@ -1148,16 +1149,20 @@ xport xseg_submit (struct xseg *xseg, struct xseg_request *xreq,
        struct xseg_port *port;
 
        /* discover next and current ports */
-       if (!__validate_port(xseg, xreq->src_transit_portno))
+       if (!__validate_port(xseg, xreq->src_transit_portno)){
+               XSEGLOG("couldn't validate src_transit_portno");
                return NoPort;
+       }
        next = xseg->src_gw[xreq->src_transit_portno];
        if (next != xreq->src_portno) {
                cur = xreq->src_transit_portno;
                goto submit;
        }
        
-       if (!__validate_port(xseg, xreq->dst_transit_portno))
+       if (!__validate_port(xseg, xreq->dst_transit_portno)){
+               XSEGLOG("couldn't validate dst_transit_portno");
                return NoPort;
+       }
        next = xseg->dst_gw[xreq->dst_transit_portno];
        if (xreq->dst_transit_portno == xreq->dst_portno)
                cur = xreq->src_transit_portno; 
@@ -1167,8 +1172,10 @@ xport xseg_submit (struct xseg *xseg, struct xseg_request *xreq,
 
 submit:
        port = xseg_get_port(xseg, next);
-       if (!port)
-               goto out;
+       if (!port){
+               XSEGLOG("couldnt get port (next :%u)", next);
+               return NoPort;
+       }
 
        __update_timestamp(xreq);
        
@@ -1177,6 +1184,7 @@ submit:
        /* add current port to path */
        serial = __xq_append_head(&xreq->path, cur);
        if (serial == Noneidx){
+               XSEGLOG("couldn't append path head");
                return NoPort;
        }
 
@@ -1185,6 +1193,7 @@ submit:
        serial = __xq_append_tail(q, xqi);
        if (flags & X_ALLOC && serial == Noneidx) {
                /* double up queue size */
+               XSEGLOG("trying to double up queue");
                newq = __alloc_queue(xseg, xq_size(q)*2);
                if (!newq)
                        goto out_rel;
@@ -1200,8 +1209,11 @@ submit:
 
 out_rel:
        xlock_release(&port->rq_lock);
-       if (serial == Noneidx)
+       if (serial == Noneidx){
+               XSEGLOG("couldn't append request to queue");
                __xq_pop_head(&xreq->path);
+               next = NoPort;
+       }
 out:
        return next;
        
@@ -1364,23 +1376,26 @@ int xseg_set_req_data(struct xseg *xseg, struct xseg_request *xreq, void *data)
 
 int xseg_get_req_data(struct xseg *xseg, struct xseg_request *xreq, void **data)
 {
-       int r;
+       int r1, r;
        ul_t val;
        xhash_t *req_data = xseg->priv->req_data;
-       r = xhash_lookup(req_data, (ul_t) xreq, &val);
+       r1 = xhash_lookup(req_data, (ul_t) xreq, &val);
        *data = (void *) val;
-       if (r >= 0) {
+       XSEGLOG("xhash_lookup returned r: %d", r1);
+       if (r1 >= 0) {
                // delete or update to NULL ?
                r = xhash_delete(req_data, (ul_t) xreq);
+               XSEGLOG("xhash_delete returned r: %d", r);
                if (r == -XHASH_ERESIZE) {
                        req_data = xhash_resize(req_data, shrink_size_shift(req_data), NULL);
                        if (req_data){
                                xseg->priv->req_data = req_data;
                                r = xhash_delete(req_data, (ul_t) xreq);
+                               XSEGLOG("xhash_delete2 returned r: %d", r);
                        }
                }
        }
-       return r;
+       return r1;
 }
 
 /*
index 6533aa4..dab483d 100644 (file)
@@ -280,7 +280,7 @@ shrink_check(xhash_t *xhash)
     ul_t size_shift = xhash->size_shift;
     ul_t size = (ul_t)1<<size_shift;
     ul_t u = xhash->used;
-    return (4*u < size && size_shift >= xhash->minsize_shift) ? true : false;
+    return (4*u < size && size_shift > xhash->minsize_shift) ? true : false;
 }
 
 
index 94b530b..cc645ff 100644 (file)
@@ -43,7 +43,7 @@ static inline int __get_index(struct xheap *heap, uint64_t bytes)
        uint32_t alignment_unit = heap->alignment_unit;
        bytes = __get_alloc_bytes(heap, bytes) - sizeof(struct xheap_header);
 
-       if (bytes < (1<<alignment_unit + SMALL_LIMIT))
+       if (bytes < (1<<(alignment_unit + SMALL_LIMIT)))
                r = bytes >> alignment_unit;
        else if (bytes < 1 << (alignment_unit + MEDIUM_LIMIT)) {
                r = 1 << SMALL_LIMIT;
@@ -53,7 +53,7 @@ static inline int __get_index(struct xheap *heap, uint64_t bytes)
                r += bytes >> (alignment_unit + MEDIUM_AL_UNIT);
        }
        else {
-               r = 1 << SMALL_LIMIT + 1 << MEDIUM_LIMIT;
+               r = (1 << SMALL_LIMIT) + (1 << MEDIUM_LIMIT);
                r -= 1 << (SMALL_LIMIT - MEDIUM_AL_UNIT);
                r -= 1 << (MEDIUM_LIMIT - (LARGE_AL_UNIT - MEDIUM_AL_UNIT));
                r += bytes >> (alignment_unit + MEDIUM_AL_UNIT);
index 40fdae4..36cf6f9 100644 (file)
@@ -1,7 +1,4 @@
 #include <xtypes/xpool.h>
-//#include <xpool.h>
-//#include <xseg/xseg.h>
-
 
 static inline int __validate_idx(struct xpool *xp, xpool_index idx) 
 {
@@ -314,3 +311,9 @@ xpool_index xpool_set_idx(struct xpool *xp, xpool_index idx, xpool_data data, ui
        xlock_release(&xp->lock);
        return ret;
 }
+
+
+#ifdef __KERNEL__
+#include <linux/module.h>
+#include <xtypes/xpool_exports.h>
+#endif
index 75ba2c8..f2e0ce4 100644 (file)
@@ -3,7 +3,6 @@
 
 #include <sys/util.h>
 #include <xtypes/xlock.h>
-//#include <xseg/xseg.h>
 
 typedef uint64_t xpool_index;
 typedef uint64_t xpool_data;
diff --git a/xseg/xtypes/xpool_exports.h b/xseg/xtypes/xpool_exports.h
new file mode 100644 (file)
index 0000000..13b09cf
--- /dev/null
@@ -0,0 +1,16 @@
+EXPORT_SYMBOL(xpool_init);
+EXPORT_SYMBOL(xpool_clear);
+EXPORT_SYMBOL(xpool_add);
+EXPORT_SYMBOL(xpool_remove);
+EXPORT_SYMBOL(xpool_peek);
+EXPORT_SYMBOL(xpool_peek_idx);
+EXPORT_SYMBOL(xpool_peek_and_fwd);
+EXPORT_SYMBOL(xpool_set_idx);
+
+EXPORT_SYMBOL(__xpool_clear);
+EXPORT_SYMBOL(__xpool_add);
+EXPORT_SYMBOL(__xpool_remove);
+EXPORT_SYMBOL(__xpool_peek);
+EXPORT_SYMBOL(__xpool_peek_idx);
+EXPORT_SYMBOL(__xpool_peek_and_fwd);
+EXPORT_SYMBOL(__xpool_set_idx);