Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp7102743rwr; Wed, 10 May 2023 04:04:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4hFU0z0z5Ykz/7TUOLiu2xArg+XlX6WwIBkSzK/AUTMdPcsTGKnpjkwQNc/eeLBW/dJOLe X-Received: by 2002:a17:90a:70cf:b0:24e:59d2:6f with SMTP id a15-20020a17090a70cf00b0024e59d2006fmr16954117pjm.11.1683716643465; Wed, 10 May 2023 04:04:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683716643; cv=none; d=google.com; s=arc-20160816; b=e/wT+5V580QKOuiH2Yjt46tvoKx35Tkj2lvUy+grLtlUm3JT4S9MmPOrE9PiBMIOk+ F2sN9EZtYviw1C+US+A+srkLmdpB7cNhj8ZtpEZuKhZwUyVNbN31rTSNeSUuMvhu69y5 mFT+QF6nFf6vsgUXUfsnAU66GzmX324xPtZfWmi1ZpA7yJ2asIM2Wo6bna25qcprFHGR HHOpFNMW1kjec1YxEo4t+Abv70apAmACvUG90CR4SuSOGlX15cGbV1YpzjJ8AuAdj8ZW zgGxyUp/J4kST7IxcSft0ZIwdH7Au/LcSvuR+r7+RJov9fu4D6Y+y25ZHWSMwL7wUgoZ IDlg== 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 :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=whokt5//vygFHy1Ckdo8X6MwMjdU2MsaxJEikZwrvKw=; b=05f1WwSeKbwKlPsGPHmHSler0/rGO3Pe+24pI9woxcbmxa8wq+hvD75Dk9KmGYL1TO ry6cp+43wefjY5AZw/C9DenQmVyMRcLZ2xbBGs5F/zfbXYKWS9FxmBXF9SnUIBWlvxta SbxqdSxFEV7F5mqGOjkf3Pv2fCD9WXA4Sozlg4loj/s14OZ2aFtFGNIqI2nj9v16whr1 7LZNQ8oW0Sr/9I55fuOGxInQwakd+Oa8M9E8733cfCKngWC0jO2uw9D5dRG/E2t53WfF opnMJ8VnHi+i4gtTQQidfYS242DLf5nmtohdCsYeDd29tx6Hm8P3lm5B8uiqwQ4wQHiV bY6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b=dLaiG4Er; 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=REJECT dis=NONE) header.from=sipsolutions.net Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j23-20020a637a57000000b00525064abb6csi3461572pgn.240.2023.05.10.04.03.53; Wed, 10 May 2023 04:04:03 -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=@sipsolutions.net header.s=mail header.b=dLaiG4Er; 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=REJECT dis=NONE) header.from=sipsolutions.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236290AbjEJK6u (ORCPT + 62 others); Wed, 10 May 2023 06:58:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235609AbjEJK6t (ORCPT ); Wed, 10 May 2023 06:58:49 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73F7819B for ; Wed, 10 May 2023 03:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=MIME-Version:Content-Transfer-Encoding: Content-Type:References:In-Reply-To:Date:Cc:To:From:Subject:Message-ID:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=whokt5//vygFHy1Ckdo8X6MwMjdU2MsaxJEikZwrvKw=; t=1683716328; x=1684925928; b=dLaiG4Erec90gEQ73u59BpTfMjJO/c3rf+HmY3Ol0tOoqoz CeqoRazVkEnRm3C8i7/bX881F/cS9oAsa1wt3H5bi2R89wwh8hEW07qZ+UxXQ9r9UCl1L32r05XGf uJKHt0BNfe7x+sHe7UGP/x6J5oJvmuI0OZJYu3qyt/D6fBEx5itIRv5srnd1BGb38yxnR8muoc3oi VP576Sl1W2E7fKQx2MBgroFX8h5z3nsFUEuSpE/9/4vdGlKzlknBYmeKYpy3k9nyhKHLq7Fo2BfF6 wJ9iYXUJpMIhCU71LhcAwpW0x5pWvIjRzwLEXMTdCQs300os6JDG85SVSR8zVzcQ==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.96) (envelope-from ) id 1pwhWu-005MRc-2L; Wed, 10 May 2023 12:58:44 +0200 Message-ID: <12d77a1427cb4c0888783d8544772e3c2d1a8908.camel@sipsolutions.net> Subject: Re: wireless locking simplifications From: Johannes Berg To: Tejun Heo Cc: linux-wireless@vger.kernel.org, Lai Jiangshan , Benjamin Berg Date: Wed, 10 May 2023 12:58:43 +0200 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.46.4 (3.46.4-1.fc37) MIME-Version: 1.0 X-malware-bazaar: not-scanned X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 Hi Tejun, > There isn't currently but workqueue already does something similar for > freezing by temporarily setting max_active to zero, so if you apply a pat= ch > like the following Thanks for that! I came up with a bit of a different patch, see below. Does that seem more or less reasonable? johannes diff --git a/include/linux/workqueue.h b/include/linux/workqueue.h index ac551b8ee7d9..5e2413017a89 100644 --- a/include/linux/workqueue.h +++ b/include/linux/workqueue.h @@ -340,6 +340,7 @@ enum { __WQ_ORDERED =3D 1 << 17, /* internal: workqueue is ordered */ __WQ_LEGACY =3D 1 << 18, /* internal: create*_workqueue() */ __WQ_ORDERED_EXPLICIT =3D 1 << 19, /* internal: alloc_ordered_workqueue()= */ + __WQ_PAUSED =3D 1 << 20, /* internal: workqueue_pause() */ =20 WQ_MAX_ACTIVE =3D 512, /* I like 512, better ideas? */ WQ_MAX_UNBOUND_PER_CPU =3D 4, /* 4 * #cpus for unbound wq */ @@ -474,6 +475,31 @@ extern void print_worker_info(const char *log_lvl, str= uct task_struct *task); extern void show_all_workqueues(void); extern void show_one_workqueue(struct workqueue_struct *wq); extern void wq_worker_comm(char *buf, size_t size, struct task_struct *tas= k); +extern void __workqueue_pause_resume(struct workqueue_struct *wq, bool pau= se); + +/** + * workqueue_pause - pause a workqueue + * @wq: workqueue to pause + * + * Pause (and flush) the given workqueue so it's not executing any + * work structs and won't until workqueue_resume() is called. + */ +static inline void workqueue_pause(struct workqueue_struct *wq) +{ + __workqueue_pause_resume(wq, true); +} + +/** + * workqueue_resume - resume a paused workqueue + * @wq: workqueue to resume + * + * Resume the given workqueue that was paused previously to + * make it run work structs again. + */ +static inline void workqueue_resume(struct workqueue_struct *wq) +{ + __workqueue_pause_resume(wq, false); +} =20 /** * queue_work - queue work on a workqueue diff --git a/kernel/workqueue.c b/kernel/workqueue.c index b8b541caed48..418d99ff8325 100644 --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -3863,10 +3863,16 @@ static void pwq_adjust_max_active(struct pool_workq= ueue *pwq) struct workqueue_struct *wq =3D pwq->wq; bool freezable =3D wq->flags & WQ_FREEZABLE; unsigned long flags; + int new_max_active; =20 - /* for @wq->saved_max_active */ + /* for @wq->saved_max_active and @wq->flags */ lockdep_assert_held(&wq->mutex); =20 + if (wq->flags & __WQ_PAUSED) + new_max_active =3D 0; + else + new_max_active =3D wq->saved_max_active; + /* fast exit for non-freezable wqs */ if (!freezable && pwq->max_active =3D=3D wq->saved_max_active) return; @@ -4642,6 +4648,25 @@ void workqueue_set_max_active(struct workqueue_struc= t *wq, int max_active) } EXPORT_SYMBOL_GPL(workqueue_set_max_active); =20 +void __workqueue_pause_resume(struct workqueue_struct *wq, bool pause) +{ + struct pool_workqueue *pwq; + + mutex_lock(&wq->mutex); + if (pause) + wq->flags |=3D __WQ_PAUSED; + else + wq->flags &=3D ~__WQ_PAUSED; + + for_each_pwq(pwq, wq) + pwq_adjust_max_active(pwq); + mutex_unlock(&wq->mutex); + + if (pause) + flush_workqueue(wq); +} +EXPORT_SYMBOL_GPL(__workqueue_pause_resume); + /** * current_work - retrieve %current task's work struct *