Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp926867rwl; Wed, 12 Apr 2023 06:10:36 -0700 (PDT) X-Google-Smtp-Source: AKy350b5HuARnjSzx8GzTSgqQxvH/JGL6pN7M2RJd8mElsY5VipkXZU1PWx1hvuMrFZGgmOTq84V X-Received: by 2002:a05:6a20:2da7:b0:eb:a8c9:635c with SMTP id bf39-20020a056a202da700b000eba8c9635cmr2090494pzb.32.1681305036589; Wed, 12 Apr 2023 06:10:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681305036; cv=none; d=google.com; s=arc-20160816; b=xTKhnGAlCQLujq0VXSIpVJnhRHRaIp6zfnF0qiz0BTmTj9QpJM3UPbmwYpS9vIRy6K +jyrl+hPIMDsbeGDybq7P3zazpYnY/dcu8OD8YdWLWvoWq1Z+A/g1w1OnUDcgvu/O6Ig pmFxY90070FPT5VDQJOHA5xTlpkNdgZJmsweNus9eCEuaVXaq0TRg8r/WCLCywCcnEYJ 8Ewl0GL2c16NpESEO3jpAc5lBeix9GjsNLfqGGOglu5LGxEp79nWWjJ36TVvA/jCnMvw aCW1n744M79ap7LUIMoQVO3aDM2UpdIiVDIArVZfK8I5uS7y1X8bpT8S+qCA1ot+Ud4f E5+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:message-id:in-reply-to :date:references:subject:cc:to:from:dkim-signature; bh=CU11Rol/8tSlI8fR4/aFXB3eggXkH5IA8LcFK49wq5Q=; b=BkytRvzBmTgAQfCkiMGSgfPrgiselVL1wcTFpdubwVvsxnpmzPUBZhx8B9m+uvmZNa 3mG5duI3ay4dKY4Ds8c52DY5HwbuNBK8wVyIVaMrURScLS79lN8WT5b4+ncEG5nc1NSp XtlKkX4hyf4YrmS6d9hqueFAL1U9zmAq5tx+zeQnd7t67xavJ/wgYGHpnHGRhVo1UrgT EY/4B/c7c/l3wewp9MVL7C7TYeB1X91DdQrZtMto5kij3JXJ1SwZyQb6xgqrAbXqIxzP kKKN4ezcjTDaU3uvo+gvQshcvu7YKuoRnqq5nPbcIaHUDwudMF5OjR4BgnudGOkGnNst C2aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Fe3sNzZU; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a184-20020a624dc1000000b005a8ec89de5fsi15776011pfb.236.2023.04.12.06.10.24; Wed, 12 Apr 2023 06:10:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Fe3sNzZU; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229814AbjDLNAd (ORCPT + 61 others); Wed, 12 Apr 2023 09:00:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbjDLNAc (ORCPT ); Wed, 12 Apr 2023 09:00:32 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7746BC0 for ; Wed, 12 Apr 2023 06:00:31 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0EA4763132 for ; Wed, 12 Apr 2023 13:00:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 82923C433EF; Wed, 12 Apr 2023 13:00:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681304430; bh=qlGbQmaFkeUZea4Edcnrn7PLgWR7fNj/3t1cgsC08Bg=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=Fe3sNzZUg1TC8CSnRmJHJfBoVhsr2DCUFoPFKfAcX7KVkJXFx7XCzI2rYHfwoeiRc 8m3lIcJuMCRCPg5Y9MxMUdMHC7PZtMM60KmXuJIS+1Ir+xNsgVRsWVGIyZkfkllOzA RZ7zBXBzB3Kgl1/byzK0n+pCOilQm+7KP9TFDo0RTTBPRkCpN2u5N7k+1FFGK0z9BT an0I6biENSLQN+Dy5bvR2EpkommZrXV5FcTEmWKcuSs+N8RDnLSjjhNlU5L6iAJ4F2 MB2olORtLD1rzk3x+3K5VuYaXTjxHbYd6naM+eaZv7480YHGacpf3gmN81RG1H5BpQ 1BOwnJoVHaJ8Q== From: Kalle Valo To: Ping-Ke Shih Cc: "linux-wireless\@vger.kernel.org" , "Bernie Huang" Subject: Re: [PATCH 2/5] wifi: rtw89: add function to wait for completion of TX skbs References: <20230310034631.45299-1-pkshih@realtek.com> <20230310034631.45299-3-pkshih@realtek.com> <87v8j2mmqt.fsf@kernel.org> <360e6dd64e3645c68742fc4c603b3c2b@realtek.com> <875yadb6i1.fsf@kernel.org> <761e605b96d734881dc51be4679f3a04c75abb89.camel@realtek.com> <56831ba4f216daee09b3d9c9a7deaf5810cade34.camel@realtek.com> Date: Wed, 12 Apr 2023 16:00:27 +0300 In-Reply-To: <56831ba4f216daee09b3d9c9a7deaf5810cade34.camel@realtek.com> (Ping-Ke Shih's message of "Tue, 11 Apr 2023 13:01:36 +0000") Message-ID: <8735558dck.fsf@kernel.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Ping-Ke Shih writes: > On Tue, 2023-04-04 at 10:37 +0800, Ping-Ke Shih wrote: > >> On Mon, 2023-04-03 at 13:32 +0300, Kalle Valo wrote: >> > I would expect that there's polling if you are waiting something from >> > hardware, or maybe when implementing a spin lock, but not when waiting >> > for another kernel thread. This just doesn't feel right but I don't have >> > time to propose a good alternative either, sorry. >> > >> >> I have found a solution that uses an owner variable with a spin lock >> to determine which side to free completion object. Simply show two use >> cases below: >> >> Use case 1: (normal case; free completion object by work 1) >> work 1 work 2 >> wait >> (spin_lock) >> complete >> check & set owner --> owner = work1 >> (spin_unlock) >> wait ok >> (spin_lock) >> check & check owner --> free by work 1 >> (spin_unlock) >> free completion >> >> >> Use case 2: (timeout case; free completion object by work 2) >> work 1 work 2 >> wait >> wait timeout >> (spin_lock) >> check & set owner --> owner = work 2 >> (spin_unlock) >> (spin_lock) >> completion >> check & set owner --> free by work 2 >> (spin_unlock) >> free completion >> >> I will apply this by v5. >> > > We have a better idea that use kfree_rcu() to free completion, so no > need spin_lock(). Then, the use cases become below, and I have sent > this change by v6. > > Use case 1: (normal case) > work 1 work 2 > (rcu_assign_pointer(wait)) > wait > (rcu_read_lock) > wait = rcu_dereference(); > if (wait) --> wait != NULL > complete > (rcu_read_unlock) > wait ok > (rcu_assign_pointer(NULL)) > kfree_rcu(completion) > > > Use case 2: (timeout case) > work 1 work 2 > (rcu_assign_pointer(wait)) > wait > wait timeout > (rcu_assign_pointer(NULL)) > kfree_rcu(completion) > (rcu_read_lock) > wait = rcu_dereference(); > if (wait) --> wait == NULL > complete > (rcu_read_unlock) Thanks, I haven't had a chance to look at v6 yet (nor v5 for that matter) but at least based on this mail your idea looks much better than polling. -- https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches