Received: by 2002:a25:ef43:0:0:0:0:0 with SMTP id w3csp963038ybm; Wed, 27 May 2020 12:18:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTFwDoo+5D5a9OM1E1LzL7TErUjWJNycgV2XlJ1KAONExjDZTWAO6Dj3T28Afjqz2U+RUI X-Received: by 2002:aa7:c4da:: with SMTP id p26mr25252355edr.184.1590607083309; Wed, 27 May 2020 12:18:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590607083; cv=none; d=google.com; s=arc-20160816; b=o6k8UEtAF7EDVq5SXLe9em/sA7aGi6PA77YiuFUAOOdCaBPsbgUbPBUjOoAiTgnwfv Rkrj1AUlrLFYQHIWp3ia9CTejSXShk1jc8aYKAgpZkO0I6Bi9n0qf4kLuayeYLp0Gj9e n3t0N6pGfoXke4mROjJPYrPa6NVKjX2uC8Ijk6Kx2Zl9pexvuKj8VqKCIH8exnnhM4tH Suh+a7d73/s5kbUNes5l+97PvYMaToT1zTISlJkgV7dYonBjYHOTz5xmmn5tcY9hhVeq YgaOgX04uFKryHp93VKretJxFOFnq9YVy/QZFMnUhC6z3ouMsQO3+6MoOVqFth+SAdLQ nXZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=i/6XgwHHHOgoW5TU+a/aVclmsApnQYa1z6EDveHJZOY=; b=m4R13G7t37ttdafO2aMnIw371kqBteHrTFx+5sXl3f3fK4Z/pVZ6DcxiAS7pEmsiwV TOu1BLgIL3Wd1M1iLtfFRVAYIa1WyyY/pXjw/QOyEW795xvR4aMbUXNbWTkFi/TGlkfm bSnl8iWIL+bC8JMH9pt8ilkFpS0NdEbJOqisFviMdNXjMo/CPXVecW+a47zz1zSX13MG 6Qqfywa0pnWyMu4+sldD8tHzblEB1T82jScOwMP+4OhCvVeZU+YLF5Ycx96RzJ+5eLUI VfvGm/EUp+xsoHYH4F9h/CV70QMcHpil96iA6wF3yFLxwJUzk1M/q5mNKMK0iFtK2hl2 dL9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=aYPx7daN; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c18si2599576ejr.84.2020.05.27.12.17.39; Wed, 27 May 2020 12:18:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=aYPx7daN; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2403846AbgE0Rho (ORCPT + 99 others); Wed, 27 May 2020 13:37:44 -0400 Received: from aserp2120.oracle.com ([141.146.126.78]:59324 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403842AbgE0Rhn (ORCPT ); Wed, 27 May 2020 13:37:43 -0400 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 04RHSRtE066275; Wed, 27 May 2020 17:36:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2020-01-29; bh=i/6XgwHHHOgoW5TU+a/aVclmsApnQYa1z6EDveHJZOY=; b=aYPx7daNvdWh1SteBGYuCo3aP0mPn56fA8eCky3L0YZ3J+CXbm344uPti2Pcb930sz/m aD18jOEtXBMLjiCLVBuqTch+QKSTWWX5GyG2aK6xiFFlWgwqDhC+nAG/qNOhBLbVst1C 36bhTB/wrIuLgdLKibdqUXXEtbOHHOR5ZIfRSTA30cvhiRQSJywhRcuh3lgvpeBWgyld 0fszqEapBamiaE+VOApwXSwqnVvl4iruf/RuJlZRHO1TLTJbKF/EPwPGimUjZl4COvnx XhB9u1wf72kFAwRgIMcDHlEOyCIHtSTVlo1MMaOeKmG874IqN07GmRFCBICOrj+QQJ7E nQ== Received: from aserp3030.oracle.com (aserp3030.oracle.com [141.146.126.71]) by aserp2120.oracle.com with ESMTP id 318xe1gubs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 27 May 2020 17:36:36 +0000 Received: from pps.filterd (aserp3030.oracle.com [127.0.0.1]) by aserp3030.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 04RHX4lq195410; Wed, 27 May 2020 17:36:36 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserp3030.oracle.com with ESMTP id 317ddr6jyg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 27 May 2020 17:36:36 +0000 Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 04RHaYCm012759; Wed, 27 May 2020 17:36:34 GMT Received: from localhost.localdomain (/98.229.125.203) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 27 May 2020 10:36:33 -0700 From: Daniel Jordan To: Andrew Morton , Herbert Xu , Steffen Klassert Cc: Alex Williamson , Alexander Duyck , Dan Williams , Dave Hansen , David Hildenbrand , Jason Gunthorpe , Jonathan Corbet , Josh Triplett , Kirill Tkhai , Michal Hocko , Pavel Machek , Pavel Tatashin , Peter Zijlstra , Randy Dunlap , Robert Elliott , Shile Zhang , Steven Sistare , Tejun Heo , Zi Yan , linux-crypto@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-s390@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Daniel Jordan Subject: [PATCH v3 8/8] padata: document multithreaded jobs Date: Wed, 27 May 2020 13:36:08 -0400 Message-Id: <20200527173608.2885243-9-daniel.m.jordan@oracle.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200527173608.2885243-1-daniel.m.jordan@oracle.com> References: <20200527173608.2885243-1-daniel.m.jordan@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9633 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 bulkscore=0 mlxscore=0 phishscore=0 adultscore=0 suspectscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005270137 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9633 signatures=668686 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 adultscore=0 cotscore=-2147483648 mlxscore=0 bulkscore=0 priorityscore=1501 phishscore=0 lowpriorityscore=0 malwarescore=0 clxscore=1015 impostorscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005270136 Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org Add Documentation for multithreaded jobs. Signed-off-by: Daniel Jordan Tested-by: Josh Triplett --- Documentation/core-api/padata.rst | 41 +++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/Documentation/core-api/padata.rst b/Documentation/core-api/padata.rst index 9a24c111781d9..0830e5b0e8211 100644 --- a/Documentation/core-api/padata.rst +++ b/Documentation/core-api/padata.rst @@ -4,23 +4,26 @@ The padata parallel execution mechanism ======================================= -:Date: December 2019 +:Date: May 2020 Padata is a mechanism by which the kernel can farm jobs out to be done in -parallel on multiple CPUs while retaining their ordering. It was developed for -use with the IPsec code, which needs to be able to perform encryption and -decryption on large numbers of packets without reordering those packets. The -crypto developers made a point of writing padata in a sufficiently general -fashion that it could be put to other uses as well. +parallel on multiple CPUs while optionally retaining their ordering. -Usage -===== +It was originally developed for IPsec, which needs to perform encryption and +decryption on large numbers of packets without reordering those packets. This +is currently the sole consumer of padata's serialized job support. + +Padata also supports multithreaded jobs, splitting up the job evenly while load +balancing and coordinating between threads. + +Running Serialized Jobs +======================= Initializing ------------ -The first step in using padata is to set up a padata_instance structure for -overall control of how jobs are to be run:: +The first step in using padata to run serialized jobs is to set up a +padata_instance structure for overall control of how jobs are to be run:: #include @@ -162,6 +165,24 @@ functions that correspond to the allocation in reverse:: It is the user's responsibility to ensure all outstanding jobs are complete before any of the above are called. +Running Multithreaded Jobs +========================== + +A multithreaded job has a main thread and zero or more helper threads, with the +main thread participating in the job and then waiting until all helpers have +finished. padata splits the job into units called chunks, where a chunk is a +piece of the job that one thread completes in one call to the thread function. + +A user has to do three things to run a multithreaded job. First, describe the +job by defining a padata_mt_job structure, which is explained in the Interface +section. This includes a pointer to the thread function, which padata will +call each time it assigns a job chunk to a thread. Then, define the thread +function, which accepts three arguments, ``start``, ``end``, and ``arg``, where +the first two delimit the range that the thread operates on and the last is a +pointer to the job's shared state, if any. Prepare the shared state, which is +typically allocated on the main thread's stack. Last, call +padata_do_multithreaded(), which will return once the job is finished. + Interface ========= -- 2.26.2