From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49D4FC33CB6 for ; Wed, 22 Jan 2020 12:25:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1D4C224684 for ; Wed, 22 Jan 2020 12:25:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579695955; bh=je9USN9BiKBD2a8LbBbkjaZgJTkQpSP3DKuo9Wl87WU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:List-ID:From; b=hrhvb6wc9s3kCHKqwxCo4qjZSZ2hiuHTPZKe5V317eM0QE2GoJ7e5rjpdIpAy5sIo eYX9X4sBDG3Ni3WMafg464Gu9//M1AeA0xH19kTG3JPU5aljI8grj05E4NsuagaN4l mDygQXllOh5ofAUiMxc36IjR4+LXzW/j5UyldRC0= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728981AbgAVMZy (ORCPT ); Wed, 22 Jan 2020 07:25:54 -0500 Received: from mail.kernel.org ([198.145.29.99]:37056 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728912AbgAVMZy (ORCPT ); Wed, 22 Jan 2020 07:25:54 -0500 Received: from localhost (unknown [213.57.247.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0885A2467A; Wed, 22 Jan 2020 12:25:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579695952; bh=je9USN9BiKBD2a8LbBbkjaZgJTkQpSP3DKuo9Wl87WU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=QmaydLUvbb4HIZ4emOqxviXJniGOkWS2PCLwKcDbj9J6pwvhAH/gjJGy+4fQKIDuL 04hiPi2SKmU5H8PZWyNwthZLAjD8PcCd6Ozxj2Z5lLLYWDMy/qJxt8DUNXQCFtO1kE 1H826A0RLk7ChmbLvl5K0DfTriWjFZWTvdH6iO6Q= Date: Wed, 22 Jan 2020 14:25:48 +0200 From: Leon Romanovsky To: Jinpu Wang Cc: Jack Wang , linux-block@vger.kernel.org, linux-rdma@vger.kernel.org, Jens Axboe , Christoph Hellwig , Sagi Grimberg , Bart Van Assche , Doug Ledford , Jason Gunthorpe , Danil Kipnis , Roman Penyaev Subject: Re: [PATCH v7 17/25] block/rnbd: client: main functionality Message-ID: <20200122122548.GB7018@unreal> References: <20200116125915.14815-1-jinpuwang@gmail.com> <20200116125915.14815-18-jinpuwang@gmail.com> <20200120134815.GH51881@unreal> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org On Wed, Jan 22, 2020 at 12:22:43PM +0100, Jinpu Wang wrote: > > > +/** > > > + * rnbd_get_cpu_qlist() - finds a list with HW queues to be rerun > > > + * @sess: Session to find a queue for > > > + * @cpu: Cpu to start the search from > > > + * > > > + * Description: > > > + * Each CPU has a list of HW queues, which needs to be rerun. If a list > > > + * is not empty - it is marked with a bit. This function finds first > > > + * set bit in a bitmap and returns corresponding CPU list. > > > + */ > > > +static struct rnbd_cpu_qlist * > > > +rnbd_get_cpu_qlist(struct rnbd_clt_session *sess, int cpu) > > > +{ > > > + int bit; > > > + > > > + /* First half */ > > > + bit = find_next_bit(sess->cpu_queues_bm, nr_cpu_ids, cpu); > > > > Is it protected by any lock? > We hold requeue_lock when set/clear bit, and disable preemption via > get_cpu_ptr when find_next_bit. > even it fails to get latest bit, it just cause an rerun the queue. It is not clear here at all. > > > > > + if (bit < nr_cpu_ids) { > > > + return per_cpu_ptr(sess->cpu_queues, bit); > > > + } else if (cpu != 0) { > > > + /* Second half */ > > > + bit = find_next_bit(sess->cpu_queues_bm, cpu, 0); > > > + if (bit < cpu) > > > + return per_cpu_ptr(sess->cpu_queues, bit); > > > + } > > > + > > > + return NULL; > > > +} > > > + > > > +static inline int nxt_cpu(int cpu) > > > +{ > > > + return (cpu + 1) % nr_cpu_ids; > > > +} > > > + > > > +/** > > > + * rnbd_rerun_if_needed() - rerun next queue marked as stopped > > > + * @sess: Session to rerun a queue on > > > + * > > > + * Description: > > > + * Each CPU has it's own list of HW queues, which should be rerun. > > > + * Function finds such list with HW queues, takes a list lock, picks up > > > + * the first HW queue out of the list and requeues it. > > > + * > > > + * Return: > > > + * True if the queue was requeued, false otherwise. > > > + * > > > + * Context: > > > + * Does not matter. > > > + */ > > > +static inline bool rnbd_rerun_if_needed(struct rnbd_clt_session *sess) > > > > No inline function in C files. > First time saw such request, there are so many inline functions in C 15) The inline disease https://elixir.bootlin.com/linux/latest/source/Documentation/process/coding-style.rst#L882 > files across the tree > grep inline drivers/infiniband/core/*.c > drivers/infiniband/core/addr.c:static inline bool > ib_nl_is_good_ip_resp(const struct nlmsghdr *nlh) > drivers/infiniband/core/cma.c:static inline u8 cma_get_ip_ver(const > struct cma_hdr *hdr) > drivers/infiniband/core/cma.c:static inline void cma_set_ip_ver(struct > cma_hdr *hdr, u8 ip_ver) > drivers/infiniband/core/cma.c:static inline void release_mc(struct kref *kref) > drivers/infiniband/core/cma.c:static inline struct sockaddr > *cma_src_addr(struct rdma_id_private *id_priv) > drivers/infiniband/core/cma.c:static inline struct sockaddr > *cma_dst_addr(struct rdma_id_private *id_priv) > > > > > > +{ > > > + struct rnbd_queue *q = NULL; > > > + struct rnbd_cpu_qlist *cpu_q; > > > + unsigned long flags; > > > + int *cpup; > > > + > > > + /* > > > + * To keep fairness and not to let other queues starve we always > > > + * try to wake up someone else in round-robin manner. That of course > > > + * increases latency but queues always have a chance to be executed. > > > + */ > > > + cpup = get_cpu_ptr(sess->cpu_rr); > > > + for (cpu_q = rnbd_get_cpu_qlist(sess, nxt_cpu(*cpup)); cpu_q; > > > + cpu_q = rnbd_get_cpu_qlist(sess, nxt_cpu(cpu_q->cpu))) { > > > + if (!spin_trylock_irqsave(&cpu_q->requeue_lock, flags)) > > > + continue; > > > + if (likely(test_bit(cpu_q->cpu, sess->cpu_queues_bm))) { > > > > Success oriented approach please. > sorry, I don't quite get your point. The flows are better to be written: if (err) return or conitnue <...> do_something in your case if (!test_bit(...)) continue; do_work_here. > > Thanks Leon for review.