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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EA5EC433EF for ; Sat, 2 Apr 2022 18:31:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245025AbiDBSdK (ORCPT ); Sat, 2 Apr 2022 14:33:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37812 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231178AbiDBSdH (ORCPT ); Sat, 2 Apr 2022 14:33:07 -0400 Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 792A521809; Sat, 2 Apr 2022 11:31:14 -0700 (PDT) Received: from mail-wr1-f52.google.com ([209.85.221.52]) by mrelayeu.kundenserver.de (mreue010 [213.165.67.97]) with ESMTPSA (Nemesis) id 1MXXhv-1nW8CN2sud-00YxDO; Sat, 02 Apr 2022 20:31:12 +0200 Received: by mail-wr1-f52.google.com with SMTP id b19so8553791wrh.11; Sat, 02 Apr 2022 11:31:12 -0700 (PDT) X-Gm-Message-State: AOAM5319j6kWjF5/v3am3fkZ/D+hDKh5bbIW7eksoqUsTNPierwopnXx y9Z29B/ZdCL1TVrpUqLgaGkbstVX9sh7SoAXbS0= X-Google-Smtp-Source: ABdhPJxXeRBLN1ONxP6bjTAJFl4VK2LisOlNtuuiDZwD1HmyapvUcRapW/HdMhWyARa4Q7Topnt9ATX3Riix9x+xc68= X-Received: by 2002:a5d:66ca:0:b0:203:fb72:a223 with SMTP id k10-20020a5d66ca000000b00203fb72a223mr11517977wrw.12.1648924272343; Sat, 02 Apr 2022 11:31:12 -0700 (PDT) MIME-Version: 1.0 References: <20220321165049.35985-1-sven@svenpeter.dev> <20220321165049.35985-6-sven@svenpeter.dev> <3166b80d-d8a6-45d5-9e3b-2f9998aca0d3@www.fastmail.com> In-Reply-To: <3166b80d-d8a6-45d5-9e3b-2f9998aca0d3@www.fastmail.com> From: Arnd Bergmann Date: Sat, 2 Apr 2022 20:30:56 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 5/9] soc: apple: Add RTKit IPC library To: Sven Peter Cc: Arnd Bergmann , Hector Martin , Alyssa Rosenzweig , Rob Herring , Keith Busch , "axboe@fb.com" , "hch@lst.de" , "sagi@grimberg.me" , Marc Zyngier , DTML , Linux ARM , Linux Kernel Mailing List , linux-nvme@lists.infradead.org Content-Type: text/plain; charset="UTF-8" X-Provags-ID: V03:K1:lvDJJbjN0pkxrwEZ0rhM+kJtjSIYljW0mLHlIlnog5Bgc8qmWA3 9p2Ugkrag/2XVf0s68xp4q5iRmYZT3w5hIqB5AYLAUjICla2tmhSKJSi8XIRmyNsMc4yNJ9 49SO2fwaPEgNIW7l1NLvwEhGqm4m/iH0ONCpOTX2Os5GW1UcEmN4SMNhdc+aOwwvfdGrtO8 EtoCFsowTj/I3WEHQozbQ== X-UI-Out-Filterresults: notjunk:1;V03:K0:eR2O3ZL9wiE=:dEjxpD1zZgLViDkpqbQ8Jo HM3ofhCIxlDCjegz8mvTSMtlThRkMmhbGG4T/S863lpLxI9oXqo+vFZfcL7dMwknQCOoSdLTQ ts7X7TYHgM8P1saZ++Lh0ElCSjNv63ae1cX1Ns4j3CogxHEAU7I7v0LYFIfV+q1eq6AU3QG/D Xnvy6ARU01j8jsDzL6cjpkJgU0VU6GZ+kBk9OZhpiO1EBCSp6o2QCCUvYPub5ahuzgFYMGKJz dSJyERE5R3WRlkocHABIfsrTsAHPoTsq0ROOBb2ux9nt+rjWYvWkPsmq3XxXUHkEdAQbnVxRC VRODgCaDZPJZfxA8+12ZSh4BumnLTf4kzcGwLTlgNGKpNiRR3Tuae0MIQc1cEE4/ey9Ua00+t 924n+xynOeQL0Z6NMKRTgk0/4Q20TRCmKykkNQL4CQ/tDytmGzmHZV5uBP9vyYIqEauFY9P2v wuoDgQ2DOe9b7boAr/Cg/2gtUVmov0QZNZ+ObcgD3OJjus1QXsOeER+CxCdRCCNi9uwZyDmR+ bzd4tD552kpGPq7p4u1qqIc1NLC9wa5F+34xdo9QqAmBg6FvreI6Yxzsltv3tBNjy5LPLiL6u QM/Z546molSRCb7fRz6ixTlvhL/DaivJUYAJieZgSey92ar2p0NwezsgPcRfl2YD/WsxCk9/q /pxioLFDv6In49wOhsOR1rMr/2TSFQCFLp6NugOX8H9sYlHolQ3YIEIBxMV3y8FNGw6k= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Apr 2, 2022 at 2:56 PM Sven Peter wrote: > On Tue, Mar 22, 2022, at 14:13, Arnd Bergmann wrote: > >> +static int apple_rtkit_worker(void *data) > >> +{ > >> + struct apple_rtkit *rtk = data; > >> + struct apple_rtkit_work work; > >> + > >> + while (!kthread_should_stop()) { > >> + wait_event_interruptible(rtk->wq, > >> + kfifo_len(&rtk->work_fifo) > 0 || > >> + kthread_should_stop()); > >> + > >> + if (kthread_should_stop()) > >> + break; > >> + > >> + while (kfifo_out_spinlocked(&rtk->work_fifo, &work, 1, > >> + &rtk->work_lock) == 1) { > >> + switch (work.type) { > >> + case APPLE_RTKIT_WORK_MSG: > >> + apple_rtkit_rx(rtk, &work.msg); > >> + break; > >> + case APPLE_RTKIT_WORK_REINIT: > >> + apple_rtkit_do_reinit(rtk); > >> + break; > >> + } > >> + } > > > > It looks like you add quite a bit of complexity by using a custom > > worker thread implementation. Can you explain what this is > > needed for? Isn't this roughly the same thing that one would > > get more easily with create_singlethread_workqueue()? > > I originally had just a workqueue here but I can only put > one instance of e.g. APPLE_RTKIT_WORK_MSG onto these. > There could however be a new incoming message while the previous > one is still being handled and I couldn't figure out a way > to handle that with workqueues without introducing a race. Are you trying to avoid dynamic allocation of the messages then and have no other place that you can embed it in? If you kmalloc() a messages that embeds a work_struct, you can enqueue as many of those as you want, but the allocation adds complexity through the need for error handling etc. I wonder if you can change the mailbox driver to use a threaded irq handler, which I think should ensure that the callback here is run in process context, avoiding the need to defer execution within the rtkit driver. Arnd 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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 5AE8AC433EF for ; Sat, 2 Apr 2022 18:32:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: In-Reply-To:References:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=GPJJK7wsqoYIx839TqkejI7raxj6yEzUvxXjmJ1+hGs=; b=1Adp2k1RTqLoqi SW4lV2ugixeVfq7CVEGhZ2uMwWc/YRAxH1rhlzUThjeEpBBAPz9qx6M7thUFz/E5WEhNmk59tIx/K VRgE0if7EGdPSXh1BLl0NVH3m1xwPOWUbsh+bzg3JwvXEVI2pkcoOF8b1ecHicnL69pp9/d9FBUbY AzqSKuq975g6znJIpBMFUI1KXG2r6k78w58U4cytZ69OqqKnKnltF8JclQph9vpXxidlD0U9VZA/k lItILDLnxv7E3Kz+RaMD4VvunYOWMkWyJ37P4klTSjkRt2hSOLWgElAX5dlo/8S+oVsC+chLmoNj1 rrMPpx+Geq4qrexOUcvg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1naiX1-009n2i-0l; Sat, 02 Apr 2022 18:31:27 +0000 Received: from mout.kundenserver.de ([212.227.126.131]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1naiWt-009mzW-GC; Sat, 02 Apr 2022 18:31:21 +0000 Received: from mail-wr1-f54.google.com ([209.85.221.54]) by mrelayeu.kundenserver.de (mreue012 [213.165.67.97]) with ESMTPSA (Nemesis) id 1N0qmr-1ny0Ae0OtZ-00wjdj; Sat, 02 Apr 2022 20:31:13 +0200 Received: by mail-wr1-f54.google.com with SMTP id d29so2523203wra.10; Sat, 02 Apr 2022 11:31:12 -0700 (PDT) X-Gm-Message-State: AOAM533QIkL+3CaEQzIa53CNzA/5aGx/TI2xxb+5hbDIDY7M2U3UOUI2 Rd+9CeJGIyxsU0vo+gOLKxB9oJ0Psbw2rP8zkTQ= X-Google-Smtp-Source: ABdhPJxXeRBLN1ONxP6bjTAJFl4VK2LisOlNtuuiDZwD1HmyapvUcRapW/HdMhWyARa4Q7Topnt9ATX3Riix9x+xc68= X-Received: by 2002:a5d:66ca:0:b0:203:fb72:a223 with SMTP id k10-20020a5d66ca000000b00203fb72a223mr11517977wrw.12.1648924272343; Sat, 02 Apr 2022 11:31:12 -0700 (PDT) MIME-Version: 1.0 References: <20220321165049.35985-1-sven@svenpeter.dev> <20220321165049.35985-6-sven@svenpeter.dev> <3166b80d-d8a6-45d5-9e3b-2f9998aca0d3@www.fastmail.com> In-Reply-To: <3166b80d-d8a6-45d5-9e3b-2f9998aca0d3@www.fastmail.com> From: Arnd Bergmann Date: Sat, 2 Apr 2022 20:30:56 +0200 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 5/9] soc: apple: Add RTKit IPC library To: Sven Peter Cc: Arnd Bergmann , Hector Martin , Alyssa Rosenzweig , Rob Herring , Keith Busch , "axboe@fb.com" , "hch@lst.de" , "sagi@grimberg.me" , Marc Zyngier , DTML , Linux ARM , Linux Kernel Mailing List , linux-nvme@lists.infradead.org X-Provags-ID: V03:K1:1Qo9pSaYUfD1P/OrQ76lQEFBU7th0d11apRn+HVUC7yFh/eAUY9 9w0+W5TqyXJrHjm9w9oso7h6rXvIu9dO8HNjnyAWHydmHvsV26BDIGngaTUaukDNNdcTA9h QWTjSF2uSLIkYAAThXzvEL1aAIkgJk5bSUajsLfqU5c3HwajYBtmJ8Jp10AaK92WfJQGfRl oB8huaVej9ZNNpNdY9Fiw== X-UI-Out-Filterresults: notjunk:1;V03:K0:RGXVQXWBbnQ=:VY8c8fzahoH6T7q9U9keG2 IX75UtNsacGiIYKzptpHwQFlqhWB+wtGBuzsHNWglkHutsFfFO8Yd8Vc388/QygMs+Ct9Rmp8 euOldxwUDaKKk7Fha5zTvfTi4DYWJFLe9bm1QOchz8IqMnzYr00JEWk835b6YNfEAzYMr1T40 GQAv96cK2HxPwDp4iyA9u0Pp7SYytwnHkZ7nzwgTtuX3Muqtzy0MZopx8ASoDKhip27+QbTzb plMqMy1BLb9FkozmLKdmUq38HiZaVwckBpDjIrXZ6CqmAgVlLyMVyfj0DHSGjODO5LsJQ9eqB CDGFLdlumVhxvOpCdRmKU1rtBm5N3KRqqn0N4HbFLe9S20oehzPF8c7dRycS2AMKsiVKOQuvQ /a/uVNtm5bg3iEPJfKPBgCZPTnwcWAdcgxvRr7Vm0vUD0inTGoCKMaE9TbXhmcfixmurSsfc7 UOI6smSKVLLKD07J7PrROB2aIcLM8oq6HrcBuyb2aXqtRqK5QZi6uSj211UEIojHp0DxoUQqM jqTAQ65Jtz77reqWy+ywKFcxZ8lzo6h/qu9hReBspSAdtkPibzSW8E7C8jFA+Zau2iYj2RGW2 7jP+VcBZiulpbsj4sntcpoAIaOAdDExKmzpn2swAUYYyjU/mTpQLB094XS7RVI2b6FaXkrz29 cq/YCbZSOZhjl8DuLzsXbvjSCkafo6TIc56P/7PktuTiokZpZSHqUSaCOBtNmZGF+o4U= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220402_113119_861921_95C9DB19 X-CRM114-Status: GOOD ( 23.21 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Sat, Apr 2, 2022 at 2:56 PM Sven Peter wrote: > On Tue, Mar 22, 2022, at 14:13, Arnd Bergmann wrote: > >> +static int apple_rtkit_worker(void *data) > >> +{ > >> + struct apple_rtkit *rtk = data; > >> + struct apple_rtkit_work work; > >> + > >> + while (!kthread_should_stop()) { > >> + wait_event_interruptible(rtk->wq, > >> + kfifo_len(&rtk->work_fifo) > 0 || > >> + kthread_should_stop()); > >> + > >> + if (kthread_should_stop()) > >> + break; > >> + > >> + while (kfifo_out_spinlocked(&rtk->work_fifo, &work, 1, > >> + &rtk->work_lock) == 1) { > >> + switch (work.type) { > >> + case APPLE_RTKIT_WORK_MSG: > >> + apple_rtkit_rx(rtk, &work.msg); > >> + break; > >> + case APPLE_RTKIT_WORK_REINIT: > >> + apple_rtkit_do_reinit(rtk); > >> + break; > >> + } > >> + } > > > > It looks like you add quite a bit of complexity by using a custom > > worker thread implementation. Can you explain what this is > > needed for? Isn't this roughly the same thing that one would > > get more easily with create_singlethread_workqueue()? > > I originally had just a workqueue here but I can only put > one instance of e.g. APPLE_RTKIT_WORK_MSG onto these. > There could however be a new incoming message while the previous > one is still being handled and I couldn't figure out a way > to handle that with workqueues without introducing a race. Are you trying to avoid dynamic allocation of the messages then and have no other place that you can embed it in? If you kmalloc() a messages that embeds a work_struct, you can enqueue as many of those as you want, but the allocation adds complexity through the need for error handling etc. I wonder if you can change the mailbox driver to use a threaded irq handler, which I think should ensure that the callback here is run in process context, avoiding the need to defer execution within the rtkit driver. Arnd _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel