Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp1301039rdb; Sun, 8 Oct 2023 00:58:45 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEBeg8nc6VEhiC9dL/t4rnvPBTikk1k+7hUrxC6xVQJZ9+nRNe5n2RJgrIk+PnUpfvnAULH X-Received: by 2002:a05:6a00:b8b:b0:68f:d1a7:1a3a with SMTP id g11-20020a056a000b8b00b0068fd1a71a3amr15034880pfj.8.1696751924663; Sun, 08 Oct 2023 00:58:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696751924; cv=none; d=google.com; s=arc-20160816; b=VXLq8Kts7x4MLvsBUXdhdEgqByqvwqvHIDmjtpe0ruc3Z162DDoH8gW7MJaKPDzOSP /fqhXD54/TYXw5IKqRRl0huzsv4FeA9ArZpFalAhNy1k22cEbtcNILCJMHFLqahzE12w iGkgv4Gkt3axa7fbakdmZWsPgfIwgAzrsQvUgYahqEGIldOHMD80NyhGMa1xK6by4/x4 TbsndtbpbaA2aiIMYPh+U4huqhwcwCg3VNnzOilb0xK5Y9FnFbY8phFxXyPzDqGlXpfF 4FsOAWy1gcYhLeHSgQCH4geVj/GIUHEzYWvfk8q+Y1L9HNvq6pEvXcwJsu3jt/pA4+rP k7vA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=OANQrzeDaZ3SxHawCCHR/Cq77drwtT5/mR1FwArmWp0=; fh=FQFx3PKLDMXkbEXaz3PZ19ad1HPZwCxSOzWdKjhL1yo=; b=n9JGYXM9p/E43qESawerKzfqllohHzBs1UaZqNcqsgRRkSUu0zpDrPH3LqKPAB5j6q cospHRxHn9yiYyYGf+YaOLfdJmVBDwFeB9AlYmCVLRptYXQH+L+kd05cB/KScTmbxt0F 3Xl2KGBOGTK+5d1ebjGPNr8afeWz/l4bLIg5Ys2GB28nIgn2x/hyGGBIVxbyE3aTXd4U hhNuYAxOOo4n/AhzxkvPhGywF7j5g9ef/t0neQAvRsfyogm87i8awj+JV4JbTXhs5ZpP 8ycxF245J3KSo0JVqUdaZM698RpFCxcNBuixDSqTTpMP4foUTtZY6WVb3ztW6PD7Kumn P9Mg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id x6-20020a63fe46000000b00573f7e9d75asi7130425pgj.646.2023.10.08.00.58.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Oct 2023 00:58:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 8955A80657D3; Sun, 8 Oct 2023 00:58:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344459AbjJHH6h (ORCPT + 99 others); Sun, 8 Oct 2023 03:58:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229988AbjJHH6h (ORCPT ); Sun, 8 Oct 2023 03:58:37 -0400 Received: from wxsgout04.xfusion.com (wxsgout04.xfusion.com [36.139.87.180]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31727B9; Sun, 8 Oct 2023 00:58:32 -0700 (PDT) Received: from wuxshcsitd00600.xfusion.com (unknown [10.32.133.213]) by wxsgout04.xfusion.com (SkyGuard) with ESMTPS id 4S3Dxl1nCfz9xmcj; Sun, 8 Oct 2023 15:56:11 +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; Sun, 8 Oct 2023 15:58:27 +0800 Date: Sun, 8 Oct 2023 15:58:26 +0800 From: Wang Jinchao To: Steffen Klassert CC: Daniel Jordan , , , Subject: Re: [RFC/REFACT] Refactoring and significantly reducing code complexity Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: X-Originating-IP: [10.82.147.3] X-ClientProxiedBy: wuxshcsitd00601.xfusion.com (10.32.135.241) To wuxshcsitd00600.xfusion.com (10.32.133.213) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,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-crypto@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sun, 08 Oct 2023 00:58:43 -0700 (PDT) On Fri, Sep 29, 2023 at 07:47:22AM +0200, Steffen Klassert wrote: > On Thu, Sep 28, 2023 at 04:53:38PM +0800, Wang Jinchao wrote: > > This is a refactored version with the following main changes: > > > > - The parallel workqueue no longer uses the WQ_UNBOUND attribute > > - Removal of CPU-related logic, sysfs-related interfaces > > - removal of structures like padata_cpumask, and deletion of parallel_data > > - Using completion to maintain sequencing > > - no longer using lists > > - removing structures like padata_list and padata_serial_queue > > - Removal of padata_do_serial() > > This removes all the logic that is needed to ensure that > the parallelized objects return in the same order as > they were before the parallelization. This change makes > padata unusable for networking. Hello Steffen, I have constructed a scenario where parallel() time cost is forced to be reversed , and then ensured the order using serial(). The tests have passed on a 32-core machine. Can you please explain if my refactored approach guarantees the serial ordering? Here is the code: padata_test.c -------------- ```c #include #include #include struct request { struct padata_priv padata; int seq; struct completion done; }; #define TEST_ARRAY_SIZE 200 #define PARALLEL_BASE_TIME 10 static int serial_cnt; static int shuffled; struct request requests[TEST_ARRAY_SIZE]; void parallel(struct padata_priv *padata) { struct request *req = container_of(padata, struct request, padata); // The smaller the req->seq number, the longer the delay time // creating a reverse order. mdelay((TEST_ARRAY_SIZE - req->seq) * PARALLEL_BASE_TIME); msleep((TEST_ARRAY_SIZE - req->seq) * PARALLEL_BASE_TIME); } void serial(struct padata_priv *padata) { struct request *req = container_of(padata, struct request, padata); if (req->seq != serial_cnt) shuffled = 1; serial_cnt++; complete(&req->done); } struct padata_instance *pinst; struct padata_shell *ps; static int __init padata_test_init(void) { serial_cnt = 0; shuffled = 0; pinst = padata_alloc("padata_test"); if (!pinst) return -ENOMEM; ps = padata_alloc_shell(pinst); for (int i = 0; i < TEST_ARRAY_SIZE; i++) { requests[i].padata.parallel = parallel; requests[i].padata.serial = serial; requests[i].seq = i; init_completion(&requests[i].done); } for (int i = 0; i < TEST_ARRAY_SIZE; i++) { padata_do_parallel(ps, &requests[i].padata); } // only wait for the last one // if they were not done serially // the serial_cnt will not be TEST_ARRAY_SIZE // there was a shuffering int last = TEST_ARRAY_SIZE - 1; wait_for_completion(&requests[last].done); if (serial_cnt != TEST_ARRAY_SIZE) shuffled = 1; printk(KERN_INFO "padata_test: shuffled %d serial_cnt %d\n", shuffled, serial_cnt); return 0; } static void __exit padata_test_exit(void) { padata_free_shell(ps); padata_free(pinst); } module_init(padata_test_init); module_exit(padata_test_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("wangjinchao"); MODULE_DESCRIPTION("padata Test Module"); ``` Makefile --------- ```makefile obj-m += padata_test.o all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean ``` run.sh -------- ```bash make dmesg -C insmod padata_test.ko rmmod padata_test dmesg|grep serial_cnt ```