From patchwork Mon Nov 2 10:10:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Mladek X-Patchwork-Id: 11873363 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3FE5A92C for ; Mon, 2 Nov 2020 10:10:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CE8F522400 for ; Mon, 2 Nov 2020 10:10:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=suse.com header.i=@suse.com header.b="FjLzR2S6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CE8F522400 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id BC8716B005C; Mon, 2 Nov 2020 05:10:49 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B79D76B0068; Mon, 2 Nov 2020 05:10:49 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8E5B6B0070; Mon, 2 Nov 2020 05:10:49 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0205.hostedemail.com [216.40.44.205]) by kanga.kvack.org (Postfix) with ESMTP id 7835E6B005C for ; Mon, 2 Nov 2020 05:10:49 -0500 (EST) Received: from smtpin11.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 17EA0180AD807 for ; Mon, 2 Nov 2020 10:10:49 +0000 (UTC) X-FDA: 77439059418.11.toys81_2b0ffb1272af Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin11.hostedemail.com (Postfix) with ESMTP id E7431180F8B80 for ; Mon, 2 Nov 2020 10:10:48 +0000 (UTC) X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,pmladek@suse.com,,RULES_HIT:30029:30034:30051:30054:30069,0,RBL:195.135.220.15:@suse.com:.lbl8.mailshell.net-62.2.6.2 64.100.201.201;04yfb7qa7wwirmg6pkuoc77xqd97jypmzi5eo1jqrycfksra7ea6hzkw95scaxh.axi4p7qou4o6jtcmbr88gueo8bg46b7g8awo3utdyo5x8en9wrukmzpdu1uajhd.a-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:71,LUA_SUMMARY:none X-HE-Tag: toys81_2b0ffb1272af X-Filterd-Recvd-Size: 3768 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Mon, 2 Nov 2020 10:10:48 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1604311847; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=VredqEs3zsL7zVXAU6Nag2b9EtiI2PI84vk+sy0mICQ=; b=FjLzR2S6zs90AlezIG3wQfjvLX7BCp9tUV4Sns3f0aMoq9GlhSTIw4pXXzIuiMs3jHUtE1 FJldsBRijVKj26LakHUO6N7Db9V7f6toTAen1iVrCrfPs8a+fawUb48TN2KCeN5iJYJo22 vE+vtvQ6PauCRNSjlwotPa8AI3WtSJE= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 20F8BACA0; Mon, 2 Nov 2020 10:10:47 +0000 (UTC) From: Petr Mladek To: Andrew Morton , Tejun Heo , Thomas Gleixner Cc: Zhang Qiang , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Petr Mladek Subject: [PATCH] kthread_worker: Document CPU hotplug handling Date: Mon, 2 Nov 2020 11:10:39 +0100 Message-Id: <20201102101039.19227-1-pmladek@suse.com> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: The kthread worker API is simple. In short, it allows to create, use, and destroy workers. kthread_create_worker_on_cpu() just allows to bind a newly created worker to a given CPU. It is up to the API user how to handle CPU hotplug. They have to decide how to handle pending work items, prevent queuing new ones, and restore the functionality when the CPU goes off and on. There are few catches: + The CPU affinity gets lost when it is scheduled on an offline CPU. + The worker might not exist when the CPU was off when the user created the workers. A good practice is to implement two CPU hotplug callbacks and destroy/create the worker when CPU goes down/up. Mention this in the function description. Link: https://lore.kernel.org/r/20201028073031.4536-1-qiang.zhang@windriver.com Reported-by: Zhang Qiang Signed-off-by: Petr Mladek --- kernel/kthread.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/kernel/kthread.c b/kernel/kthread.c index e29773c82b70..fd3deae3afde 100644 --- a/kernel/kthread.c +++ b/kernel/kthread.c @@ -786,7 +786,25 @@ EXPORT_SYMBOL(kthread_create_worker); * A good practice is to add the cpu number also into the worker name. * For example, use kthread_create_worker_on_cpu(cpu, "helper/%d", cpu). * - * Returns a pointer to the allocated worker on success, ERR_PTR(-ENOMEM) + * CPU hotplug: + * The kthread worker API is simple and generic. It just provides a way + * how to create, use, and destroy workers. + * + * It is up to the API user how to handle CPU hotplug. They have to decide + * how to handle pending work items, prevent queuing new ones, and + * restore the functionality when the CPU goes off and on. There are + * few catches: + * + * - CPU affinity gets lost when it is scheduled on an offline CPU. + * + * - The worker might not exist when the CPU was off when the user + * created the workers. + * + * A good practice is to implement two CPU hotplug callbacks and + * destroy/create the worker when CPU goes down/up. + * + * Return: + * The pointer to the allocated worker on success, ERR_PTR(-ENOMEM) * when the needed structures could not get allocated, and ERR_PTR(-EINTR) * when the worker was SIGKILLed. */