Use rendez for sleep/wakeup/etc
authorBarret Rhoden <brho@cs.berkeley.edu>
Fri, 17 Jan 2014 18:47:18 +0000 (10:47 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Fri, 17 Jan 2014 18:47:18 +0000 (10:47 -0800)
I put rendez.cocci in the PATCHPLAN9 script.  That old .cocci made this
much easier, especially the second time around.

17 files changed:
kern/include/ns.h
kern/src/net/arp.c
kern/src/net/bootp.c
kern/src/net/devip.c
kern/src/net/dhcp.c
kern/src/net/ethermedium.c
kern/src/net/igmp.c
kern/src/net/ihbootp.c
kern/src/net/loopbackmedium.c
kern/src/net/netdevmedium.c
kern/src/net/netlog.c
kern/src/net/ppp.c
kern/src/net/pppmedium.c
kern/src/net/rudp.c
kern/src/net/tcp.c
kern/src/ns/qio.c
scripts/PATCHPLAN9

index 445e14c..de7a7f0 100644 (file)
@@ -825,7 +825,6 @@ void                ready(struct proc*);
 void           renameproguser( char *unused_char_p_t, char*);
 void           renameuser( char *unused_char_p_t, char*);
 void           resrcwait( char *unused_char_p_t);
-int            return0(void*);
 struct proc*           runproc(void);
 void           sched(void);
 void           schedinit(void);
@@ -837,7 +836,6 @@ void                setmalloctag(void*, uint32_t);
 int            setpri(int);
 void           setrealloctag(void*, uint32_t);
 char*          skipslash( char *unused_char_p_t);
-void           sleep(struct rendez*, int(*)(void*), void*);
 void*          smalloc(uint32_t);
 int            splhi(void);
 int            spllo(void);
@@ -855,7 +853,6 @@ void                todinit(void);
 void           todset(int64_t, int64_t, int);
 int            tready(void*);
 struct block*          trimblock(struct block*, int unused_int, int);
-void           tsleep(struct rendez*, int (*)(void*), void*, int);
 int            uartgetc(void);
 void           uartputc(int);
 void           uartputs( char *unused_char_p_t, int);
@@ -866,7 +863,6 @@ uint32_t            userpc(void);
 void           validname( char *unused_char_p_t, int);
 void           validstat( uint8_t *unused_uint8_p_t, int);
 void           validwstatname( char *unused_char_p_t);
-int            wakeup(struct rendez*);
 int            walk(struct chan**, char **unused_char_pp_t, int unused_int, int, int*);
 void           werrstr( char *unused_char_p_t, ...);
 void*          xalloc(uint32_t);
index a21029b..b77cf7a 100644 (file)
@@ -109,7 +109,7 @@ newarp6(struct arp *arp, uint8_t *ip, struct Ipifc *ifc, int addrxt)
                        for(next = xp->list; next; next = next->list)
                                xp = next;
                        arp->dropl = xp;
-                       wakeup(&arp->rxmtq);
+                       rendez_wakeup(&arp->rxmtq);
                }
        }
 
@@ -155,7 +155,7 @@ newarp6(struct arp *arp, uint8_t *ip, struct Ipifc *ifc, int addrxt)
                }
                *l = a;
                if(empty) 
-                       wakeup(&arp->rxmtq);
+                       rendez_wakeup(&arp->rxmtq);
        }
 
        a->nextrxt = NULL;
@@ -691,9 +691,9 @@ rxmitproc(void *v)
        for(;;){
                wakeupat = rxmitsols(arp);
                if(wakeupat == 0) 
-                       sleep(&arp->rxmtq, rxready, v); 
+                       rendez_sleep(&arp->rxmtq, rxready, v); 
                else if(wakeupat > ReTransTimer/4) 
-                       tsleep(&arp->rxmtq, return0, 0, wakeupat); 
+                       udelay_sched(wakeupat * 1000); 
        }
 }
 
index b7d3fcd..78bba83 100644 (file)
@@ -103,7 +103,7 @@ rcvbootp(void *a)
        rcvprocp = nil;
 
        recv = 1;
-       wakeup(&bootpr);
+       rendez_wakeup(&bootpr);
        pexit("", 0);
 }
 
@@ -165,7 +165,7 @@ rbootp(Ipifc *ifc)
                if(kwrite(dfd, &req, sizeof(req)) < 0)
                        print("bootp: write: %s\n", commonerror());
 
-               tsleep(&bootpr, return0, 0, 1000);
+               udelay_sched(1000 * 1000);
                if(++tries > 10) {
                        print("bootp: timed out\n");
                        break;
index 570194c..5fd11bc 100644 (file)
@@ -495,7 +495,7 @@ ipopen(struct chan* c, int omode)
                        }
 
                        /* wait for a connect */
-                       sleep(&cv->listenr, incoming, cv);
+                       rendez_sleep(&cv->listenr, incoming, cv);
 
                        qlock(&cv->qlock);
                        nc = cv->incall;
@@ -970,7 +970,7 @@ connectctlmsg(struct Proto *x, struct conv *c, struct cmdbuf *cb)
                qlock(&c->qlock);
                nexterror();
        }
-       sleep(&c->cr, connected, c);
+       rendez_sleep(&c->cr, connected, c);
        qlock(&c->qlock);
        poperror();
 
@@ -1023,7 +1023,7 @@ announcectlmsg(struct Proto *x, struct conv *c, struct cmdbuf *cb)
                qlock(&c->qlock);
                nexterror();
        }
-       sleep(&c->cr, announced, c);
+       rendez_sleep(&c->cr, announced, c);
        qlock(&c->qlock);
        poperror();
 
@@ -1346,7 +1346,7 @@ Fsconnected(struct conv* c, char* msg)
                break;
        }
 
-       wakeup(&c->cr);
+       rendez_wakeup(&c->cr);
        return 0;
 }
 
@@ -1402,7 +1402,7 @@ Fsnewcall(struct conv *c, uint8_t *raddr, uint16_t rport, uint8_t *laddr,
 
        qunlock(&c->qlock);
 
-       wakeup(&c->listenr);
+       rendez_wakeup(&c->listenr);
 
        return nc;
 }
index 639e51b..6447c73 100644 (file)
@@ -230,7 +230,7 @@ rcvbootp(void *a)
                        if(dhcpmsgtype < dhcp){
                                dhcpmsgtype=dhcp;
                                recv = 1;
-                               wakeup(&bootpr);
+                               rendez_wakeup(&bootpr);
                                if(dhcp==0 || dhcp ==5 || dhcp == 6 )
                                        break;
                        }
@@ -315,7 +315,7 @@ rbootp(Ipifc *ifc)
                        if(kwrite(dfd, &req, sizeof(req))<0)    /* SEND DHCPDISCOVER */
                                print("DHCPDISCOVER: %r");
                
-                       tsleep(&bootpr, return0, 0, 1000);      /* wait DHCPOFFER */
+                       udelay_sched(1000 * 1000);      /* wait DHCPOFFER */
                        if(debug)
                                print("[DHCP] DISCOVER: msgtype = %d\n", dhcpmsgtype);
 
@@ -360,7 +360,7 @@ rbootp(Ipifc *ifc)
                        print("DHCPREQUEST: %r");
                        continue;
                }
-               tsleep(&bootpr, return0, 0, 2000);
+               udelay_sched(2000 * 1000);
                if(dhcpmsgtype==5)              /* wait for DHCPACK */
                        break;
                else
index c7cca2f..3b559af 100644 (file)
@@ -278,8 +278,7 @@ etherunbind(struct Ipifc *ifc)
        /* wait for readers to die */
        while(er->arpp != 0 || er->read4p != 0 || er->read6p != 0)
                ;
-#warning tsleep
-       //      tsleep(&up->sleep, return0, 0, 300);
+       udelay_sched(300 * 1000);
 
        if(er->mchan4 != NULL)
                cclose(er->mchan4);
index 109df30..316e696 100644 (file)
@@ -117,7 +117,7 @@ igmpproc(void *a)
        USED(a);
 
        for(;;){
-               sleep(&igmpalloc.r, isreport, 0);
+               rendez_sleep(&igmpalloc.r, isreport, 0);
                for(;;){
                        lock(&igmpalloc);
 
@@ -158,7 +158,7 @@ igmpproc(void *a)
                                continue;
                        }
 
-                       tsleep(&up->sleep, return0, 0, MSPTICK);
+                       udelay_sched(MSPTICK * 1000);
                }
                unlock(&igmpalloc);
        }
@@ -222,7 +222,7 @@ igmpiput(Media *m, Ipifc *, Block *bp)
                rp->next = igmpalloc.reports;
                igmpalloc.reports = rp;
 
-               wakeup(&igmpalloc.r);
+               rendez_wakeup(&igmpalloc.r);
 
                break;
        case IGMPreport:
index 68b14b1..5eb6671 100644 (file)
@@ -193,7 +193,7 @@ rcvbootp(void *a)
        rcvprocp = nil;
 
        recv = 1;
-       wakeup(&bootpr);
+       rendez_wakeup(&bootpr);
        pexit("", 0);
 }
 
@@ -255,7 +255,7 @@ rbootp(Ipifc *ifc)
                if(kwrite(dfd, &req, sizeof(req)) < 0)
                        print("bootp: write: %r");
 
-               tsleep(&bootpr, return0, 0, 1000);
+               udelay_sched(1000 * 1000);
                if(++tries > 10) {
                        print("bootp: timed out\n");
                        break;
index e5a6766..35e3b5d 100644 (file)
@@ -49,14 +49,15 @@ loopbackunbind(struct Ipifc *ifc)
 {
        LB *lb = ifc->arg;
 
+       printk("%s is messed up, shouldn't track procs\n", __FUNCTION__);
+
        /*if(lb->readp)
          postnote(lb->readp, 1, "unbind", 0);
        */
 
        /* wait for reader to die */
-#warning "how to sleep 5 minutes"
-//     while(lb->readp != 0)
-//             tsleep(&current->sleep, return0, 0, 300);
+       while(lb->readp != 0)
+               udelay_sched(300 * 1000);
 
        /* clean up */
        qfree(lb->q);
index 090292b..c201656 100644 (file)
@@ -75,9 +75,10 @@ netdevunbind(struct Ipifc *ifc)
        if(er->readp != NULL)
                postnote(er->readp, 1, "unbind", 0);
 */
-       /* wait for readers to die *
+       printk("%s is messed up, shouldn't track procs\n", __FUNCTION__);
+       /* wait for readers to die */
        while(er->readp != NULL)
-       tsleep(&up->sleep, return0, 0, 300);*/
+               udelay_sched(300 * 1000);
 
        if(er->mchan != NULL)
                cclose(er->mchan);
index 3ee200f..083825d 100644 (file)
@@ -156,7 +156,7 @@ netlogread(Fs *f, void *a, ulong, long n)
                else
                        unlock(f->alog);
 
-               sleep(f->alog, netlogready, f);
+               rendez_sleep(f->alog, netlogready, f);
        }
 
        qunlock(f->alog);
@@ -259,5 +259,5 @@ netlog(Fs *f, int mask, char *fmt, ...)
        }
        unlock(f->alog);
 
-       wakeup(f->alog);
+       rendez_wakeup(f->alog);
 }
index 73885ad..bf4a188 100644 (file)
@@ -1040,7 +1040,7 @@ ppptimer(void *arg)
                pexit("hangup", 1);
        }
        for(;;){
-               tsleep(&up->sleep, return0, nil, Period);
+               udelay_sched(Period * 1000);
                if(ppp->pppup){
                        qlock(ppp);
 
index 2354728..ed4aec2 100644 (file)
@@ -146,7 +146,7 @@ pppunbind(Ipifc *ifc)
 
        /* wait for kprocs to die */
        while(ppp->readp != 0 || ppp->timep != 0)
-               tsleep(&up->sleep, return0, 0, 300);
+               udelay_sched(300 * 1000);
 
        pppclose(ppp);
        qclose(ifc->conv->eq);
index a1a70e9..15b69b5 100644 (file)
@@ -470,7 +470,7 @@ rudpkick(void *x)
        qlock(&r->lock);
        if(UNACKED(r) > Maxunacked){
                r->blocked = 1;
-               sleep(&r->vous, flow, r);
+               rendez_sleep(&r->vous, flow, r);
                r->blocked = 0;
        }
 
@@ -764,7 +764,7 @@ relackproc(void *a)
        rudp = (Proto *)a;
 
 loop:
-       tsleep(&up->sleep, return0, 0, Rudptickms);
+       udelay_sched(Rudptickms * 1000);
 
        for(s = rudp->conv; *s; s++) {
                c = *s;
@@ -937,7 +937,7 @@ reliput(Conv *c, Block *bp, uchar *addr, ushort port)
 
                /* flow control */
                if(UNACKED(r) < Maxunacked/8 && r->blocked)
-                       wakeup(&r->vous);
+                       rendez_wakeup(&r->vous);
 
                /*
                 *  retransmit next packet if the acked packet
@@ -1057,7 +1057,7 @@ relhangup(Conv *c, Reliable *r)
        r->ackrcvd = 0;
        r->xmits = 0;
        r->timeout = 0;
-       wakeup(&r->vous);
+       rendez_wakeup(&r->vous);
 }
 
 /*
index c6e0a54..c05756f 100644 (file)
@@ -647,7 +647,7 @@ tcpackproc(void *a)
        priv = tcp->priv;
 
        for(;;) {
-               tsleep(&up->sleep, return0, 0, MSPTICK);
+               udelay_sched(MSPTICK * 1000);
 
                qlock(&priv->tl);
                timeo = nil;
@@ -738,7 +738,7 @@ localclose(Conv *s, char *reason)   /* called with tcb locked */
        if(tcb->state == Syn_sent)
                Fsconnected(s, reason);
        if(s->state == Announced)
-               wakeup(&s->listenr);
+               rendez_wakeup(&s->listenr);
 
        qhangup(s->rq, reason);
        qhangup(s->wq, reason);
index e2d477c..bef61df 100644 (file)
@@ -434,7 +434,7 @@ qget(struct queue *q)
        spin_unlock_irqsave(&q->lock);
 
        if(dowakeup)
-               wakeup(&q->wr);
+               rendez_wakeup(&q->wr);
 
        return b;
 }
@@ -488,7 +488,7 @@ qdiscard(struct queue *q, int len)
        spin_unlock_irqsave(&q->lock);
 
        if(dowakeup)
-               wakeup(&q->wr);
+               rendez_wakeup(&q->wr);
 
        return sofar;
 }
@@ -556,7 +556,7 @@ qconsume(struct queue *q, void *vp, int len)
        spin_unlock_irqsave(&q->lock);
 
        if(dowakeup)
-               wakeup(&q->wr);
+               rendez_wakeup(&q->wr);
 
        if(tofree != NULL)
                freeblist(tofree);
@@ -612,7 +612,7 @@ qpass(struct queue *q, struct block *b)
        spin_unlock_irqsave(&q->lock);
 
        if(dowakeup)
-               wakeup(&q->rr);
+               rendez_wakeup(&q->rr);
 
        return len;
 }
@@ -660,7 +660,7 @@ qpassnolim(struct queue *q, struct block *b)
        spin_unlock_irqsave(&q->lock);
 
        if(dowakeup)
-               wakeup(&q->rr);
+               rendez_wakeup(&q->rr);
 
        return len;
 }
@@ -742,7 +742,7 @@ qproduce(struct queue *q, void *vp, int len)
        spin_unlock_irqsave(&q->lock);
 
        if(dowakeup)
-               wakeup(&q->rr);
+               rendez_wakeup(&q->rr);
 
        return len;
 }
@@ -869,7 +869,7 @@ qwait(struct queue *q)
 
                q->state |= Qstarve;    /* flag requesting producer to wake me */
                spin_unlock_irqsave(&q->lock);
-               sleep(&q->rr, notempty, q);
+               rendez_sleep(&q->rr, notempty, q);
                spin_lock_irqsave(&q->lock);
        }
        return 1;
@@ -1010,7 +1010,7 @@ qwakeup_iunlock(struct queue *q)
        if(dowakeup){
                if(q->kick)
                        q->kick(q->arg);
-               wakeup(&q->wr);
+               rendez_wakeup(&q->wr);
        }
 }
 
@@ -1236,7 +1236,7 @@ qbwrite(struct queue *q, struct block *b)
 
        /* wakeup anyone consuming at the other end */
        if(dowakeup)
-               wakeup(&q->rr);
+               rendez_wakeup(&q->rr);
 
        /*
         *  flow control, wait for queue to get below the limit
@@ -1257,7 +1257,7 @@ qbwrite(struct queue *q, struct block *b)
                spin_lock_irqsave(&q->lock);
                q->state |= Qflow;
                spin_unlock_irqsave(&q->lock);
-               sleep(&q->wr, qnotfull, q);
+               rendez_sleep(&q->wr, qnotfull, q);
        }
 
        qunlock(&q->wlock);
@@ -1348,7 +1348,7 @@ qiwrite(struct queue *q, void *vp, int len)
                if(dowakeup){
                        if(q->kick)
                                q->kick(q->arg);
-                       wakeup(&q->rr);
+                       rendez_wakeup(&q->rr);
                }
 
                sofar += n;
@@ -1396,8 +1396,8 @@ qclose(struct queue *q)
        freeblist(bfirst);
 
        /* wake up readers/writers */
-       wakeup(&q->rr);
-       wakeup(&q->wr);
+       rendez_wakeup(&q->rr);
+       rendez_wakeup(&q->wr);
 }
 
 /*
@@ -1417,8 +1417,8 @@ qhangup(struct queue *q, char *msg)
        spin_unlock_irqsave(&q->lock);
 
        /* wake up readers/writers */
-       wakeup(&q->rr);
-       wakeup(&q->wr);
+       rendez_wakeup(&q->rr);
+       rendez_wakeup(&q->wr);
 }
 
 /*
@@ -1514,7 +1514,7 @@ qflush(struct queue *q)
        freeblist(bfirst);
 
        /* wake up readers/writers */
-       wakeup(&q->wr);
+       rendez_wakeup(&q->wr);
 }
 
 int
index 829c4dc..464a328 100644 (file)
@@ -25,6 +25,7 @@ spatch --sp-file scripts/spatch/plan9.cocci --in-place $1
 spatch --sp-file scripts/spatch/scalar.cocci --in-place $1
 spatch --sp-file scripts/spatch/typedef.cocci --in-place $1
 spatch --sp-file scripts/spatch/locks.cocci --in-place $1
+spatch --sp-file scripts/spatch/rendez.cocci --in-place $1
 # include fixing. Idempotent. 
 sh scripts/fixincludes $1
 # Scalars. Idempotent.