Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2B10C00A89 for ; Mon, 2 Nov 2020 10:10:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30B24222E8 for ; Mon, 2 Nov 2020 10:10:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="FjLzR2S6" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728429AbgKBKKt (ORCPT ); Mon, 2 Nov 2020 05:10:49 -0500 Received: from mx2.suse.de ([195.135.220.15]:42842 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728005AbgKBKKs (ORCPT ); Mon, 2 Nov 2020 05:10:48 -0500 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. */ -- 2.26.2