Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp19785rdg; Wed, 11 Oct 2023 19:07:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGtLMSjNX1lzmBCfRwTP/cJuK0r499QUMnZDw06hvtrYSpT2V8vFkAf9r4m9SOcCbkdParF X-Received: by 2002:a05:6a20:1608:b0:14b:887a:6d70 with SMTP id l8-20020a056a20160800b0014b887a6d70mr25193996pzj.15.1697076425444; Wed, 11 Oct 2023 19:07:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697076425; cv=none; d=google.com; s=arc-20160816; b=iZQhMZ6+Un8/PPnKWVRjxJDKpwaB/TUx2RGdjTVNQrZPaTvhe5OFXpmD9L3NtVhq9d yUzxBRqwSfAs2U+6ow1DS6vilFPVclDkHXZ9M5CE3LDw2l4+qaiqZY4qiaIDaRAGqU3I eISknh0UA/VC5dpp/0Cg93MZxmYKkxiK6UTWJDDO5O04Jidurop2ODURrMRfgoCypAby KuwjSJKCCHMRx+GIg3qcVdM9QzLUMaLU7nJTZP9nNi8xQkshOrgUFW099FhrbzWMa1fs 0q/mAIlMWl+ox5In9wF1VK9qMHTKr+boDqb/gmnVYIzeHDg3WQwaBe8WNUcScH/Rolfn ZqmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date; bh=IKTMq0MxIcxbzq/0TmKrbFhf8XHsElQYNffvsYrEvtU=; fh=7F+ruHH5QcOTmRba7j1bGKOB4p1lK5yntKtecISCuVs=; b=r1Z0CCzzhwvMM7nhv/cpvViAxdClaVrr2WuwKLSxPiW8QbvuAm6+q7qKCt/TJmA/0r JvyeqTIePqEtLj9f8XE7Im3MwQ/lYrtzJrGVlV40Cl3zJTrPJ9LBdrALBUFqRBnBJAkB mmlA6QjH7kGIRZikjaXYM2VGEiueRqZwG9yw4B4X7yHFLMFMI/5Q1up5+xFgb3fGHVBT Ifed/lAnKd7XuVllaTm/uUDX4TI0qyG8qgMXPRRP6Qwyka15MdAljwYSqhyAsDnc7ObN iIs27scr6B0wVVgVZ/qsYPPljFr/vH0+nIdyHNMtAWx2VfgZ3C5KDbKigKHW5vHz8Vsn /R2Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id e8-20020a170902b78800b001c73f364120si1046423pls.407.2023.10.11.19.07.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 19:07:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id 9E87D8157DEA; Wed, 11 Oct 2023 19:07:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233966AbjJLCGv (ORCPT + 99 others); Wed, 11 Oct 2023 22:06:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233794AbjJLCGu (ORCPT ); Wed, 11 Oct 2023 22:06:50 -0400 Received: from wxsgout04.xfusion.com (wxsgout04.xfusion.com [36.139.87.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C441F98; Wed, 11 Oct 2023 19:06:46 -0700 (PDT) Received: from wuxshcsitd00600.xfusion.com (unknown [10.32.133.213]) by wxsgout04.xfusion.com (SkyGuard) with ESMTPS id 4S5Xxw36Vvz9y7xl; Thu, 12 Oct 2023 10:04:20 +0800 (CST) Received: from localhost (10.82.147.3) by wuxshcsitd00600.xfusion.com (10.32.133.213) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.23; Thu, 12 Oct 2023 10:06:40 +0800 Date: Thu, 12 Oct 2023 10:06:40 +0800 From: Wang Jinchao To: Steffen Klassert , Daniel Jordan , , CC: Subject: [RFC v2] padata: Simplify sysfs cpumask and sequencing logic Message-ID: <202310121006-wangjinchao@xfusion.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline X-Originating-IP: [10.82.147.3] X-ClientProxiedBy: wuxshcsitd00603.xfusion.com (10.32.134.231) To wuxshcsitd00600.xfusion.com (10.32.133.213) X-Spam-Status: No, score=2.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 11 Oct 2023 19:07:02 -0700 (PDT) X-Spam-Level: ** Hi, I've identified several potential optimizations for padata. I'd appreciate it if you could take a look at my ideas to see if they are feasible. Utilizing the WQ_SYSFS from workqueue to support sysfs ====================================================== Padata relies on workqueue, and since workqueue has already implemented support for cpumask through WQ_SYSFS, we can reuse this functionality and avoid redundant implementation. Link: https://docs.kernel.org/core-api/workqueue.html#affinity-scopes Using completion to ensure the sequencing of the 'serial()' =========================================================== In the current implementation, to ensure the sequencing of 'serial()', we've used seq_nr, reorder_list, padata_serial_queue, reorder_work... which has made the logic quite complex. These operations can be simplified by using 'completion'. Specifically: 1. in padata_do_parallel() 1. init_completion(parallel_done) **before** queue_work 2. queue_work(serial_work) 2. in padata_parallel_worker 1. complete(parallel_done) **after** parallel(padata) 3. in padata_serial_worker 1. wait_for_completion(parallel_done) **before** serial(padata) Here's a simplified code snippet: ```c struct padata_priv { struct completion parallel_done; struct work_struct parallel_work; struct work_struct serial_work; void (*parallel)(struct padata_priv *padata); void (*serial)(struct padata_priv *padata); } void padata_do_parallel(struct padata_priv *padata) { ... init_completion(&padata->parallel_done); queue_work(pinst->serial_wq, &padata->serial_work); queue_work(pinst->parallel_wq, &padata->parallel_work); ... } static void padata_parallel_worker(struct work_struct *parallel_work) { struct padata_priv *padata = container_of(parallel_work, struct padata_priv, parallel_work); padata->parallel(padata); // notify serial_worker to do serial() complete(&padata->parallel_done); } static void padata_serial_worker(struct work_struct *serial_work) { struct padata_priv *padata = container_of(serial_work, struct padata_priv, serial_work); wait_for_completion(&padata->parallel_done); padata->serial(padata); } ```