Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp174302pxf; Wed, 24 Mar 2021 02:12:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxfLPG1uyBeHdRyRpiALE8l5gCY+Q/F9X6fIPlKJ9IdSjO0LJ/7yZqncj2ofWWwQY7FUtVB X-Received: by 2002:a17:906:14d0:: with SMTP id y16mr2596060ejc.242.1616577158334; Wed, 24 Mar 2021 02:12:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616577158; cv=none; d=google.com; s=arc-20160816; b=nRQZcmn0t5EQTTT88HfWO9jFJvdJAeEaZYozcze3J4UJ9JgWC7mAJiNDwBbZYD5zgC uBBS8PMm6i+HFHrWQ7bHsK0T8PPrF8hCsU+4MzwQVg+VCubm/TmeSLN2gz3UU8doY7G1 L5KA6PWKJSBKB9tzphoVrFSAvzH89W0C2wnDV0T/0KNbjkADjNHh6618Gc01yt5FRwYN Od6/Ou651bBJqp7+TapCEGlb9WbAbdMCxJEFWi7rtfIeRi5chPjaOmLlAoZNSy++Yb4U flvuaW+7h8CV7SMUU3CwOvF0InVXwAkPzbTBbB5ABaCu62sUxPUtiXHF+nRXnjnOv3h2 h9Yg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Kcc6sYOncKNza4pyjGfSR1hgCICN528qKEruGPFUaW0=; b=dAaHFDlQbWmRNbCE7/GtIs8SGZ5uG0A+V6a98nDC3Kjdcf0ld2vKAslqiIs+aWQEpV cM0iOu3cR8G0MSIWAxFQpMFs6qtdhf6aIIoZ5FtDc976yMVAqrR/92A6qB5ktyIU3ArS tbBYQmM6FbC6q+RlnAADZXBqP6ijQQ66GT1FngwRAM8tM3tvzUTvBQQnmB2/yj6RTQBb D4RK5n/9fyXfCCaRZ+IsOrhVFU+POXXPyfXViENKxM1+EU4IbC5BG7lmicnv18uqcxS4 N8intuVA0dXPN4si/7On++wRet8m7mteC6q6y6z9DNAuXSjdbA/JvgfmK7Hb0Jae/qGS j/5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="i/K/lP2E"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hc43si1456372ejc.529.2021.03.24.02.12.15; Wed, 24 Mar 2021 02:12:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="i/K/lP2E"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234618AbhCXBtd (ORCPT + 99 others); Tue, 23 Mar 2021 21:49:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234526AbhCXBtS (ORCPT ); Tue, 23 Mar 2021 21:49:18 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A105BC061765; Tue, 23 Mar 2021 18:49:18 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id j6-20020a17090adc86b02900cbfe6f2c96so348024pjv.1; Tue, 23 Mar 2021 18:49:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=Kcc6sYOncKNza4pyjGfSR1hgCICN528qKEruGPFUaW0=; b=i/K/lP2EMNf5mL/ks+jU5qNCAiaM+A4q5Dbzv8tWCoJNfyhniaLAG+lOI7DnGGOst8 E/cXZbjoQkNuMSz8fGShcDE5oyVMUfE/nxZ8uhcjhI+qwA5u2x9UUFXqzoEc3XclHswI 8eK8ukUX4NXRS+uvPtt7q91dDlMMo9U73FrLrIYDygxtdwgS2zOmzZxk4TQkqADUNQgA AHMBAeG5P1uzR57lXRyXfoC8Yv09xGfjylKRafhs3/H8K1oHng2zTNoNbm+rvv/KYsao Bnkwmgd6KGMgpVatkM/uCyQo52FUYJaarkVNahNbVv4+Gu2cqUSSYJ/RhT2UxDhVtNxh Jg0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=Kcc6sYOncKNza4pyjGfSR1hgCICN528qKEruGPFUaW0=; b=okc/WnaoRRP7URWrL5jIDwcCF+dXJYvE5KQxt2+a4S3Y5bHqPlEGwipm2EbrY6bxGk FK/KeMJizIffHaja6hrAQwiWILIFg7Hh39jLyW7rtHgCTBtbxV9T3zdjbI03EMSWrBXv krP3EtUgjDK43kNkcWdnMv1TlwRnl2EgkuTznAHi5z6BizWYU8YwKq/TY+6SbDPc2ExZ Z7jy/hDw9kBMNMgRCO8ryGrW7AOehjGPuWOByH7YWkvlKti+M4OqfcOFU8GqYSgmg0NJ 6lg1NDcoGC/NE2F7BA+qUatzX1F1nv7sv4fQdEBccNMRuV+hIH0YrOwIkLUEB9vKepiz vWFA== X-Gm-Message-State: AOAM531uNhO3RK5dU/JKnNTxhk+Qy3ZRiWEoLj608MpxxNtL/TMk5hvl 8uiOrwUb/lnZWmD8JJleWECn8QaMTiUgVaqxOeM= X-Received: by 2002:a17:90a:7061:: with SMTP id f88mr937998pjk.56.1616550557213; Tue, 23 Mar 2021 18:49:17 -0700 (PDT) MIME-Version: 1.0 References: <1615603667-22568-1-git-send-email-linyunsheng@huawei.com> <1615777818-13969-1-git-send-email-linyunsheng@huawei.com> <20210315115332.1647e92b@kicinski-fedora-pc1c0hjn.dhcp.thefacebook.com> <87eegddhsj.fsf@toke.dk> <3bae7b26-9d7f-15b8-d466-ff5c26d08b35@huawei.com> <9d045462-051e-0cde-24d0-349dd397e2b7@huawei.com> In-Reply-To: <9d045462-051e-0cde-24d0-349dd397e2b7@huawei.com> From: Cong Wang Date: Tue, 23 Mar 2021 18:49:06 -0700 Message-ID: Subject: Re: [Linuxarm] Re: [RFC v2] net: sched: implement TCQ_F_CAN_BYPASS for lockless qdisc To: Yunsheng Lin Cc: "Jason A. Donenfeld" , =?UTF-8?B?VG9rZSBIw7hpbGFuZC1Kw7hyZ2Vuc2Vu?= , Jakub Kicinski , David Miller , Vladimir Oltean , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eric Dumazet , Wei Wang , "Cong Wang ." , Taehee Yoo , Linux Kernel Network Developers , LKML , linuxarm@openeuler.org, Marc Kleine-Budde , linux-can@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 21, 2021 at 5:55 PM Yunsheng Lin wrote= : > > On 2021/3/20 2:15, Cong Wang wrote: > > On Thu, Mar 18, 2021 at 12:33 AM Yunsheng Lin = wrote: > >> > >> On 2021/3/17 21:45, Jason A. Donenfeld wrote: > >>> On 3/17/21, Toke H=C3=B8iland-J=C3=B8rgensen wrote: > >>>> Cong Wang writes: > >>>> > >>>>> On Mon, Mar 15, 2021 at 2:07 PM Jakub Kicinski wr= ote: > >>>>>> > >>>>>> I thought pfifo was supposed to be "lockless" and this change > >>>>>> re-introduces a lock between producer and consumer, no? > >>>>> > >>>>> It has never been truly lockless, it uses two spinlocks in the ring > >>>>> buffer > >>>>> implementation, and it introduced a q->seqlock recently, with this = patch > >>>>> now we have priv->lock, 4 locks in total. So our "lockless" qdisc e= nds > >>>>> up having more locks than others. ;) I don't think we are going to = a > >>>>> right direction... > >>>> > >>>> Just a thought, have you guys considered adopting the lockless MSPC = ring > >>>> buffer recently introduced into Wireguard in commit: > >>>> > >>>> 8b5553ace83c ("wireguard: queueing: get rid of per-peer ring buffers= ") > >>>> > >>>> Jason indicated he was willing to work on generalising it into a > >>>> reusable library if there was a use case for it. I haven't quite tho= ugh > >>>> through the details of whether this would be such a use case, but > >>>> figured I'd at least mention it :) > >>> > >>> That offer definitely still stands. Generalization sounds like a lot = of fun. > >>> > >>> Keep in mind though that it's an eventually consistent queue, not an > >>> immediately consistent one, so that might not match all use cases. It > >>> works with wg because we always trigger the reader thread anew when i= t > >>> finishes, but that doesn't apply to everyone's queueing setup. > >> > >> Thanks for mentioning this. > >> > >> "multi-producer, single-consumer" seems to match the lockless qdisc's > >> paradigm too, for now concurrent enqueuing/dequeuing to the pfifo_fast= 's > >> queues() is not allowed, it is protected by producer_lock or consumer_= lock. > >> > >> So it would be good to has lockless concurrent enqueuing, while dequeu= ing > >> can be protected by qdisc_lock() or q->seqlock, which meets the "multi= -producer, > >> single-consumer" paradigm. > > > > I don't think so. Usually we have one queue for each CPU so we can expe= ct > > each CPU has a lockless qdisc assigned, but we can not assume this in > > the code, so we still have to deal with multiple CPU's sharing a lockle= ss qdisc, > > and we usually enqueue and dequeue in process context, so it means we c= ould > > have multiple producers and multiple consumers. > > For lockless qdisc, dequeuing is always within the qdisc_run_begin() and > qdisc_run_end(), so multiple consumers is protected with each other by > q->seqlock . So are you saying you will never go lockless for lockless qdisc? I thought you really want to go lockless with Jason's proposal of MPMC ring buffer code. > > For enqueuing, multiple consumers is protected by producer_lock, see > pfifo_fast_enqueue() -> skb_array_produce() -> ptr_ring_produce(). I think you seriously misunderstand how we classify MPMC or MPSC, it is not about how we lock them, it is about whether we truly have a single or multiple consumers regardless of locks used, because the goal is to go lockless. > I am not sure if lockless MSPC can work with the process context, but > even if not, the enqueuing is also protected by rcu_read_lock_bh(), > which provides some kind of atomicity, so that producer_lock can be > reomved when lockless MSPC is used. Not sure if I can even understand what you are saying here, Jason's code only disables preemption with busy wait, I can't see why it can not be used in the process context. Thanks.