Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751826AbdG0OmD (ORCPT ); Thu, 27 Jul 2017 10:42:03 -0400 Received: from aserp1040.oracle.com ([141.146.126.69]:45924 "EHLO aserp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751788AbdG0OmB (ORCPT ); Thu, 27 Jul 2017 10:42:01 -0400 Subject: Re: [PATCH v2 05/13] xen/pvcalls: implement bind command To: Stefano Stabellini References: <1501017730-12797-1-git-send-email-sstabellini@kernel.org> <1501017730-12797-5-git-send-email-sstabellini@kernel.org> <5978AD87.20504@oracle.com> Cc: xen-devel@lists.xen.org, linux-kernel@vger.kernel.org, jgross@suse.com, Stefano Stabellini From: Boris Ostrovsky Message-ID: Date: Thu, 27 Jul 2017 10:43:28 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Source-IP: aserv0021.oracle.com [141.146.126.233] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1705 Lines: 49 >> This all looks very similar to previous patches. Can it be factored out? > You are right that the pattern is the same for all commands: > - get a request > - fill the request > - possibly do something else > - wait > however each request is different, the struct and fields are different. > There are spin_lock and spin_unlock calls intermingled. I am not sure I > can factor out much of this. Maybe I could create a static inline or > macro as a syntactic sugar to replace the wait call, but that's pretty > much it I think. Maybe you could factor out common fragments, not necessarily the whole thing at once? For example, static inline int get_request(*bedata, int *req_id) { *req_id = bedata->ring.req_prod_pvt & (RING_SIZE(&bedata->ring) - 1); if (RING_FULL(&bedata->ring) || READ_ONCE(bedata->rsp[*req_id].req_id) != PVCALLS_INVALID_ID) { return -EAGAIN; return 0; } (or some such) > > >> Also, you've used wait_event_interruptible in socket() implementation. Why not >> here (and connect())? > My intention was to use wait_event to wait for replies everywhere but I > missed some of them in the conversion (I used to use > wait_event_interruptible in early versions of the code). > > The reason to use wait_event is that it makes it easier to handle the > rsp slot in bedata (bedata->rsp[req_id]): in case of EINTR the response > in bedata->rsp would not be cleared by anybody. If we use wait_event > there is no such problem, and the backend could still return EINTR and > we would handle it just fine as any other responses. I was actually wondering about this myself when I was looking at socket() but then I somehow convinced myself (incorrectly!) that it was OK. -boris