Fix signal handling of peers
authorAlex Pyrgiotis <apyrgio@grnet.gr>
Wed, 20 Feb 2013 22:16:55 +0000 (00:16 +0200)
committerFilippos Giannakos <philipgian@grnet.gr>
Mon, 11 Mar 2013 09:52:30 +0000 (11:52 +0200)
xseg/drivers/user/xseg_posix.c
xseg/peers/user/bench-xseg.c
xseg/peers/user/peer.c

index 69b4783..7c24670 100644 (file)
@@ -174,7 +174,7 @@ static void posix_remote_signal_quit(void)
 static int posix_prepare_wait(struct xseg *xseg, uint32_t portno)
 {
        struct xseg_port *port = xseg_get_port(xseg, portno);
-       if (!port) 
+       if (!port)
                return -1;
        struct posix_signal_desc *psd = xseg_get_signal_desc(xseg, port);
        if (!psd)
@@ -186,7 +186,7 @@ static int posix_prepare_wait(struct xseg *xseg, uint32_t portno)
 static int posix_cancel_wait(struct xseg *xseg, uint32_t portno)
 {
        struct xseg_port *port = xseg_get_port(xseg, portno);
-       if (!port) 
+       if (!port)
                return -1;
        struct posix_signal_desc *psd = xseg_get_signal_desc(xseg, port);
        if (!psd)
@@ -217,14 +217,15 @@ static int posix_wait_signal(struct xseg *xseg, uint32_t usec_timeout)
 static int posix_signal(struct xseg *xseg, uint32_t portno)
 {
        struct xseg_port *port = xseg_get_port(xseg, portno);
-       if (!port) 
+       if (!port)
                return -1;
        struct posix_signal_desc *psd = xseg_get_signal_desc(xseg, port);
        if (!psd)
                return -1;
        pid_t cue = (pid_t)psd->waitcue;
        if (!cue)
-               return 0;
+               //HACKY!
+               return -2;
 
        /* FIXME: Make calls to xseg_signal() check for errors */
        return syscall(SYS_tkill, cue, SIGIO);
@@ -262,7 +263,7 @@ void posix_quit_signal_desc(struct xseg *xseg, void *sd)
 
 void * posix_alloc_data(struct xseg *xseg)
 {
-       struct xobject_h *sd_h = xseg_get_objh(xseg, MAGIC_POSIX_SD, 
+       struct xobject_h *sd_h = xseg_get_objh(xseg, MAGIC_POSIX_SD,
                        sizeof(struct posix_signal_desc));
        return sd_h;
 }
index ba8586b..32bd26e 100644 (file)
@@ -431,13 +431,11 @@ static int send_request(struct peerd *peer, struct bench *prefs)
        }
        timer_stop(prefs, prefs->sub_tm, NULL);
 
-       //Send SIGIO to the process that has binded this port to inform that
+       //Send SIGIO to the process that has bound this port to inform that
        //IO is possible
        r = xseg_signal(xseg, p);
-       if (r == -1)
-               XSEGLOG2(&lc, W, "Could not associate destination peer\n");
-       else if (r == -2)
-               XSEGLOG2(&lc, W, "Could signal destination peer\n");
+       if (r < 0)
+               XSEGLOG2(&lc, W, "Cannot signal destination peer (reason %d)\n", r);
 
        return 0;
 
@@ -491,7 +489,7 @@ int custom_peerd_loop(void *arg)
 send_request:
                while (CAN_SEND_REQUEST(prefs)) {
                        xseg_cancel_wait(xseg, peer->portno_start);
-                       XSEGLOG2(&lc, D, "Because %lu < %lu && %lu < %lu\n",
+                       XSEGLOG2(&lc, D, "...because %lu < %lu && %lu < %lu\n",
                                        prefs->sub_tm->completed - prefs->rec_tm->completed,
                                        prefs->iodepth, prefs->sub_tm->completed,
                                        prefs->max_requests);
@@ -502,6 +500,9 @@ send_request:
                }
                //Heart of peerd_loop. This loop is common for everyone.
                for (loops = threshold; loops > 0; loops--) {
+                       if (loops == 1)
+                               xseg_prepare_wait(xseg, peer->portno_start);
+
                        if (check_ports(peer)) {
                                //If an old request has just been acked, the most sensible
                                //thing to do is to immediately send a new one
@@ -511,8 +512,12 @@ send_request:
                                        return 0;
                        }
                }
-               XSEGLOG2(&lc, I, "%s goes to sleep\n",id);
-               xseg_prepare_wait(xseg, peer->portno_start);
+               //struct xseg_port *port = xseg_get_port(xseg, portno_start);
+               //struct xq *q;
+               //q = XPTR_TAKE(port->request_queue, xseg->segment);
+               //XSEGLOG2(&lc, I, "%s goes to sleep with %u requests pending\n",
+               //              id, xq_count(q));
+               XSEGLOG2(&lc, I, "%s goes to sleep\n", id);
 #ifdef ST_THREADS
                if (ta){
                        st_sleep(0);
index 2c2a3ba..fd79a27 100644 (file)
@@ -282,6 +282,8 @@ void complete(struct peerd *peer, struct peer_req *pr)
 {
        struct xseg_request *req = pr->req;
        uint32_t p;
+       int r;
+
        req->state |= XS_SERVED;
        //xseg_set_req_data(peer->xseg, pr->req, NULL);
        //gettimeofday(&resp_start, NULL);
@@ -291,7 +293,9 @@ void complete(struct peerd *peer, struct peer_req *pr)
        //timersub(&resp_end, &resp_start, &resp_end);
        //timeradd(&resp_end, &resp_accum, &resp_accum);
        //printf("xseg_signal: %u\n", p);
-       xseg_signal(peer->xseg, p);
+       r = xseg_signal(peer->xseg, p);
+       if (r < 0)
+               XSEGLOG2(&lc, W, "Cannot signal destination peer (reason %d)\n", r);
        free_peer_req(peer, pr);
 #ifdef MT
        wake_up_next_thread(peer);
@@ -555,10 +559,11 @@ static int generic_peerd_loop(void *arg)
 #endif
                //Heart of peerd_loop. This loop is common for everyone.
                for(loops = threshold; loops > 0; loops--) {
+                       if (loops == 1)
+                               xseg_prepare_wait(xseg, peer->portno_start);
                        if (check_ports(peer))
                                loops = threshold;
                }
-               xseg_prepare_wait(xseg, peer->portno_start);
 #ifdef ST_THREADS
                if (ta){
                        st_sleep(0);