From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95541C433FE for ; Fri, 14 Jan 2022 22:02:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E87586B0073; Fri, 14 Jan 2022 17:02:55 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E363C6B0074; Fri, 14 Jan 2022 17:02:55 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D25EE6B0075; Fri, 14 Jan 2022 17:02:55 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0098.hostedemail.com [216.40.44.98]) by kanga.kvack.org (Postfix) with ESMTP id C645B6B0073 for ; Fri, 14 Jan 2022 17:02:55 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 8705D998CB for ; Fri, 14 Jan 2022 22:02:55 +0000 (UTC) X-FDA: 79030268310.08.A7A72DF Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by imf21.hostedemail.com (Postfix) with ESMTP id 17D741C0003 for ; Fri, 14 Jan 2022 22:02:54 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id EDD0361FE5; Fri, 14 Jan 2022 22:02:53 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C67BCC36AE9; Fri, 14 Jan 2022 22:02:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1642197773; bh=M50U5r7x5oJoUWEw7VcxXcqN6SqJM1Cm+EW7ABDoeLE=; h=Date:From:To:Subject:In-Reply-To:From; b=sHIIGvx31y98h6JICGIIcuLf02izC5wXBQYoayVZMMwo7ZCC1f3T4YIeslTa6W5c0 ntQ6QYHK1dQ+WWCrcJZLD2WK7pj6NQP/z2FgHsvER+Lr58I0TWLPLBVbsidMtCX+b1 C87JhHXX7VcoZy0+j4XaU5d3pQ0e2oXaGvgK71i0= Date: Fri, 14 Jan 2022 14:02:52 -0800 From: Andrew Morton To: akpm@linux-foundation.org, bmt@zurich.ibm.com, bristot@kernel.org, caihuoqing@baidu.com, dave@stgolabs.net, dledford@redhat.com, jgg@ziepe.ca, jiangshanlai@gmail.com, joel@joelfernandes.org, josh@joshtriplett.org, linux-mm@kvack.org, mathieu.desnoyers@efficios.com, mingo@redhat.com, mm-commits@vger.kernel.org, paulmck@kernel.org, rostedt@goodmis.org, torvalds@linux-foundation.org Subject: [patch 001/146] kthread: add the helper function kthread_run_on_cpu() Message-ID: <20220114220252.FkLY1R14S%akpm@linux-foundation.org> In-Reply-To: <20220114140222.6b14f0061194d3200000c52d@linux-foundation.org> User-Agent: s-nail v14.8.16 X-Rspamd-Queue-Id: 17D741C0003 X-Stat-Signature: f6ifgtb6ytaigtaz4c1co3ndhz6r8br5 Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=sHIIGvx3; dmarc=none; spf=pass (imf21.hostedemail.com: domain of akpm@linux-foundation.org designates 139.178.84.217 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org X-Rspamd-Server: rspam02 X-HE-Tag: 1642197774-473203 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: From: Cai Huoqing Subject: kthread: add the helper function kthread_run_on_cpu() the helper function kthread_run_on_cpu() includes kthread_create_on_cpu/wake_up_process(). In some cases, use kthread_run_on_cpu() directly instead of kthread_create_on_node/kthread_bind/wake_up_process() or kthread_create_on_cpu/wake_up_process() or kthreadd_create/kthread_bind/wake_up_process() to simplify the code. [akpm@linux-foundation.org: export kthread_create_on_cpu to modules] Link: https://lkml.kernel.org/r/20211022025711.3673-2-caihuoqing@baidu.com Signed-off-by: Cai Huoqing Cc: Bernard Metzler Cc: Cai Huoqing Cc: Daniel Bristot de Oliveira Cc: Davidlohr Bueso Cc: Doug Ledford Cc: Ingo Molnar Cc: Jason Gunthorpe Cc: Joel Fernandes (Google) Cc: Josh Triplett Cc: Lai Jiangshan Cc: Mathieu Desnoyers Cc: "Paul E . McKenney" Cc: Steven Rostedt Signed-off-by: Andrew Morton --- include/linux/kthread.h | 25 +++++++++++++++++++++++++ kernel/kthread.c | 1 + 2 files changed, 26 insertions(+) --- a/include/linux/kthread.h~kthread-add-the-helper-function-kthread_run_on_cpu +++ a/include/linux/kthread.h @@ -56,6 +56,31 @@ bool kthread_is_per_cpu(struct task_stru __k; \ }) +/** + * kthread_run_on_cpu - create and wake a cpu bound thread. + * @threadfn: the function to run until signal_pending(current). + * @data: data ptr for @threadfn. + * @cpu: The cpu on which the thread should be bound, + * @namefmt: printf-style name for the thread. Format is restricted + * to "name.*%u". Code fills in cpu number. + * + * Description: Convenient wrapper for kthread_create_on_cpu() + * followed by wake_up_process(). Returns the kthread or + * ERR_PTR(-ENOMEM). + */ +static inline struct task_struct * +kthread_run_on_cpu(int (*threadfn)(void *data), void *data, + unsigned int cpu, const char *namefmt) +{ + struct task_struct *p; + + p = kthread_create_on_cpu(threadfn, data, cpu, namefmt); + if (!IS_ERR(p)) + wake_up_process(p); + + return p; +} + void free_kthread_struct(struct task_struct *k); void kthread_bind(struct task_struct *k, unsigned int cpu); void kthread_bind_mask(struct task_struct *k, const struct cpumask *mask); --- a/kernel/kthread.c~kthread-add-the-helper-function-kthread_run_on_cpu +++ a/kernel/kthread.c @@ -523,6 +523,7 @@ struct task_struct *kthread_create_on_cp to_kthread(p)->cpu = cpu; return p; } +EXPORT_SYMBOL(kthread_create_on_cpu); void kthread_set_per_cpu(struct task_struct *k, int cpu) { _