From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56213) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cT6ek-00027K-3g for qemu-devel@nongnu.org; Mon, 16 Jan 2017 07:45:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cT6eg-0002zk-7o for qemu-devel@nongnu.org; Mon, 16 Jan 2017 07:45:02 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42462) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cT6eg-0002zP-2B for qemu-devel@nongnu.org; Mon, 16 Jan 2017 07:44:58 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 24BB231B305 for ; Mon, 16 Jan 2017 12:44:58 +0000 (UTC) Date: Mon, 16 Jan 2017 20:44:53 +0800 From: Fam Zheng Message-ID: <20170116124453.GA10221@lemon.Home> References: <20170113131731.1246-1-pbonzini@redhat.com> <20170113131731.1246-2-pbonzini@redhat.com> <20170116110942.GB14226@lemon.Home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Qemu-devel] [PATCH 01/16] aio: introduce aio_co_schedule and aio_co_wake List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: qemu-devel@nongnu.org, stefanha@redhat.com On Mon, 01/16 13:19, Paolo Bonzini wrote: > >> +static void co_schedule_bh_cb(void *opaque) > >> +{ > >> + AioContext *ctx = opaque; > >> + QSLIST_HEAD(, Coroutine) straight, reversed; > >> + > >> + QSLIST_MOVE_ATOMIC(&reversed, &ctx->scheduled_coroutines); > >> + QSLIST_INIT(&straight); > > > > Worth special casing 1 element case? > > Sounds like premature optimization; the QSLIST_MOVE_ATOMIC is going to > be pretty expensive anyway. Do you mean something like: > > if (QSLIST_EMPTY(&reversed)) { > return; > } > Coroutine *co = QSLIST_FIRST(&reversed); > if (!QSLIST_NEXT(co, co_scheduled_next)) { > straight = reversed; > } else { > do { > ... > } while (!QSLIST_EMPTY(&reversed); > } > > do { > ... > } while (!QSLIST_EMPTY(&straight); > > ? Looks a but busy. However, removing the QSLIST_EMPTY case and then > using do/while may be a nice middle. I think QSLIST_EMPTY is very unusual. I don't know if these are premature or not, just asked because the !QSLIST_NEXT() case will be the most common one. Fam