From owner-svn-src-user@FreeBSD.ORG Wed Mar 11 03:00:41 2009 Return-Path: Delivered-To: svn-src-user@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 2A063106564A; Wed, 11 Mar 2009 03:00:41 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 1722B8FC13; Wed, 11 Mar 2009 03:00:41 +0000 (UTC) (envelope-from lstewart@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n2B30e26082022; Wed, 11 Mar 2009 03:00:40 GMT (envelope-from lstewart@svn.freebsd.org) Received: (from lstewart@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n2B30e7k082020; Wed, 11 Mar 2009 03:00:40 GMT (envelope-from lstewart@svn.freebsd.org) Message-Id: <200903110300.n2B30e7k082020@svn.freebsd.org> From: Lawrence Stewart Date: Wed, 11 Mar 2009 03:00:40 +0000 (UTC) To: src-committers@freebsd.org, svn-src-user@freebsd.org X-SVN-Group: user MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r189674 - in user/lstewart/alq_varlen_8.x: sys/kern tools/test/alq X-BeenThere: svn-src-user@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the experimental " user" src tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 Mar 2009 03:00:41 -0000 Author: lstewart Date: Wed Mar 11 03:00:40 2009 New Revision: 189674 URL: http://svn.freebsd.org/changeset/base/189674 Log: kern_alq.c: - Remove cruft that's not really needed anymore. - Simplify/improve accounting in alq_doio(). - Fix a bug in alq_writen()'s accounting. alqtest.c: - General improvements to the output. Modified: user/lstewart/alq_varlen_8.x/sys/kern/kern_alq.c user/lstewart/alq_varlen_8.x/tools/test/alq/alqtest.c Modified: user/lstewart/alq_varlen_8.x/sys/kern/kern_alq.c ============================================================================== --- user/lstewart/alq_varlen_8.x/sys/kern/kern_alq.c Wed Mar 11 02:39:02 2009 (r189673) +++ user/lstewart/alq_varlen_8.x/sys/kern/kern_alq.c Wed Mar 11 03:00:40 2009 (r189674) @@ -61,10 +61,6 @@ struct alq { struct mtx aq_mtx; /* Queue lock */ struct vnode *aq_vp; /* Open vnode handle */ struct ucred *aq_cred; /* Credentials of the opening thread */ - //struct ale *aq_first; /* First ent */ - //struct ale *aq_entfree; /* First free ent */ - //struct ale *aq_entvalid; /* First ent valid for writing */ - void (*doio_debugcallback)(void); LIST_ENTRY(alq) aq_act; /* List of active queues */ LIST_ENTRY(alq) aq_link; /* List of all queues */ }; @@ -291,7 +287,6 @@ alq_doio(struct alq *alq) int totlen; int iov; int vfslocked; - int prev_writehead = alq->aq_writehead; KASSERT((ALQ_HAS_PENDING_DATA(alq)), ("%s: queue emtpy!", __func__) @@ -311,6 +306,9 @@ alq_doio(struct alq *alq) if (alq->aq_writetail < alq->aq_writehead) { /* Buffer not wrapped */ totlen = aiov[0].iov_len = alq->aq_writehead - alq->aq_writetail; + } else if (alq->aq_writehead == 0) { + /* Buffer not wrapped (special case to avoid an empty iov) */ + totlen = aiov[0].iov_len = alq->aq_buflen - alq->aq_writetail;; } else { /* * Buffer wrapped, requires 2 aiov entries: @@ -325,14 +323,6 @@ alq_doio(struct alq *alq) } alq->aq_flags |= AQ_FLUSHING; - - /*printf("pre: alq->aq_writehead=%d,alq->aq_writetail=%d,totlen=%d,iov=%d\n", alq->aq_writehead, alq->aq_writetail, totlen, iov);*/ - - if (alq->doio_debugcallback != NULL) - alq->doio_debugcallback(); - - /*printf("flushing %d bytes\n", totlen);*/ - ALQ_UNLOCK(alq); auio.uio_iov = &aiov[0]; @@ -364,14 +354,8 @@ alq_doio(struct alq *alq) ALQ_LOCK(alq); alq->aq_flags &= ~AQ_FLUSHING; - /*printf("finished flushing %d bytes\n", totlen);*/ - /* Adjust writetail as required, taking into account wrapping. */ - if (iov == 2) - alq->aq_writetail = prev_writehead; - else - alq->aq_writetail = (alq->aq_writetail + totlen) % alq->aq_buflen; - + alq->aq_writetail = (alq->aq_writetail + totlen) % alq->aq_buflen; alq->aq_freebytes += totlen; /* @@ -382,15 +366,10 @@ alq_doio(struct alq *alq) if (!ALQ_HAS_PENDING_DATA(alq)) alq->aq_writehead = alq->aq_writetail = 0; - /*printf("post: alq->aq_writehead=%d,alq->aq_writetail=%d,totlen=%d,iov=%d\n", alq->aq_writehead, alq->aq_writetail, totlen, iov);*/ - KASSERT((alq->aq_writetail >= 0 && alq->aq_writetail < alq->aq_buflen), ("%s: aq_writetail < 0 || aq_writetail >= aq_buflen", __func__) ); - if (alq->doio_debugcallback != NULL) - alq->doio_debugcallback(); - if (alq->aq_flags & AQ_WANTED) { alq->aq_flags &= ~AQ_WANTED; return (1); @@ -467,8 +446,6 @@ alq_open(struct alq **alqp, const char * alq->aq_writehead = alq->aq_writetail = 0; - alq->doio_debugcallback = NULL; - if ((error = ald_add(alq)) != 0) return (error); *alqp = alq; @@ -544,10 +521,13 @@ alq_writen(struct alq *alq, void *data, if ((alq->aq_buflen - alq->aq_writehead) < len) copy = alq->aq_buflen - alq->aq_writehead; - /* Copy (part of) message to the buffer. */ + /* Copy message (or part thereof if wrap required) to the buffer. */ bcopy(data, alq->aq_entbuf + alq->aq_writehead, copy); alq->aq_writehead += copy; + if (alq->aq_writehead == alq->aq_buflen) + alq->aq_writehead = 0; + if (copy != len) { /* * Wrap the buffer by copying the remainder of our message Modified: user/lstewart/alq_varlen_8.x/tools/test/alq/alqtest.c ============================================================================== --- user/lstewart/alq_varlen_8.x/tools/test/alq/alqtest.c Wed Mar 11 02:39:02 2009 (r189673) +++ user/lstewart/alq_varlen_8.x/tools/test/alq/alqtest.c Wed Mar 11 03:00:40 2009 (r189674) @@ -144,29 +144,26 @@ alqtest_writen(struct sbuf *s, struct sb for (i = 0; i < sizeof(buf); i++) buf[i] = alqtest_randchar(); - alqtest_printf(s, 0, "-- msglen==1,buflen=%d\n", buflen); - alq_writen(testalq, buf, 1, ALQ_WAITOK | ALQ_NOACTIVATE); + alqtest_printf(s, 0, "-- nmsgs==1,msglen==1,buflen=%d,flags==ALQ_WAITOK|ALQ_NOACTIVATE\n", buflen); + alq_writen(testalq, buf, 1, ALQ_WAITOK|ALQ_NOACTIVATE); if ((buflen-1 != testalq->aq_freebytes) && (1 != testalq->aq_writehead) && (0 != testalq->aq_writetail)) { errors++; - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_freebytes", buflen-1, testalq->aq_freebytes ); - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_writehead", 1, testalq->aq_writehead ); - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_writetail", 0, @@ -180,22 +177,19 @@ alqtest_writen(struct sbuf *s, struct sb (0 != testalq->aq_writehead) && (0 != testalq->aq_writetail)) { errors++; - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_freebytes", buflen, testalq->aq_freebytes ); - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_writehead", 0, testalq->aq_writehead ); - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_writetail", 0, @@ -203,29 +197,26 @@ alqtest_writen(struct sbuf *s, struct sb ); } - alqtest_printf(s, 0, "-- msglen==%d,buflen=%d\n", buflen, buflen); + alqtest_printf(s, 0, "-- nmsgs==1,msglen==%d,buflen=%d,flags==ALQ_WAITOK|ALQ_NOACTIVATE\n", buflen, buflen); alq_writen(testalq, buf, buflen, ALQ_WAITOK | ALQ_NOACTIVATE); if ((0 != testalq->aq_freebytes) && (0 != testalq->aq_writehead) && (0 != testalq->aq_writetail)) { errors++; - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_freebytes", 0, testalq->aq_freebytes ); - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_writehead", 0, testalq->aq_writehead ); - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_writetail", 0, @@ -239,22 +230,19 @@ alqtest_writen(struct sbuf *s, struct sb (0 != testalq->aq_writehead) && (0 != testalq->aq_writetail)) { errors++; - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_freebytes", buflen, testalq->aq_freebytes ); - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_writehead", 0, testalq->aq_writehead ); - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_writetail", 0, @@ -274,8 +262,7 @@ alqtest_writen(struct sbuf *s, struct sb for (i = 0; i < NMSGS; i++) { n = alqtest_rand(1,buflen); - alqtest_printf( s, - 0, + sbuf_printf( debug, "--- msg==%d,msglen==%d\n", i, n @@ -283,27 +270,24 @@ alqtest_writen(struct sbuf *s, struct sb alq_writen(testalq, buf, n, ALQ_WAITOK|ALQ_NOACTIVATE); alq_flush(testalq); - + if ((buflen != testalq->aq_freebytes) && (0 != testalq->aq_writehead) && (0 != testalq->aq_writetail)) { errors++; - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_freebytes", buflen, testalq->aq_freebytes ); - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_writehead", 0, testalq->aq_writehead ); - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_writetail", 0, @@ -322,8 +306,7 @@ alqtest_writen(struct sbuf *s, struct sb for (i = 0; i < NMSGS; i++) { n = alqtest_rand(1,buflen); - alqtest_printf( s, - 0, + sbuf_printf( s, "--- msg==%d,msglen==%d\n", i, n @@ -358,8 +341,7 @@ alqtest_open(struct sbuf *s, struct sbuf if (0 != testalq->aq_entmax) { errors++; - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_entmax", 0, @@ -369,8 +351,7 @@ alqtest_open(struct sbuf *s, struct sbuf if (0 != testalq->aq_entlen) { errors++; - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_entlen", 0, @@ -380,8 +361,7 @@ alqtest_open(struct sbuf *s, struct sbuf if (buflen != testalq->aq_freebytes) { errors++; - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_freebytes", buflen, @@ -391,8 +371,7 @@ alqtest_open(struct sbuf *s, struct sbuf if (buflen != testalq->aq_buflen) { errors++; - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_buflen", buflen, @@ -402,8 +381,7 @@ alqtest_open(struct sbuf *s, struct sbuf if (0 != testalq->aq_writehead) { errors++; - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_writehead", 0, @@ -413,8 +391,7 @@ alqtest_open(struct sbuf *s, struct sbuf if (0 != testalq->aq_writetail) { errors++; - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_writetail", 0, @@ -424,8 +401,7 @@ alqtest_open(struct sbuf *s, struct sbuf if (0 != testalq->aq_flags) { errors++; - alqtest_printf( debug, - 0, + sbuf_printf( debug, "alq->%-15s\texpected=%d\tactual=%d\n", "aq_flags", 0,