Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp611192pxb; Thu, 21 Oct 2021 06:13:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTnhEhXBQ1LajQuSJeMxr7MwDCdQA1JAI5kauEZcc0EbMrivN2is4QV5HdbgcTjrLka/HV X-Received: by 2002:a05:6a00:1a8e:b0:44c:5f27:e971 with SMTP id e14-20020a056a001a8e00b0044c5f27e971mr5583213pfv.72.1634821984167; Thu, 21 Oct 2021 06:13:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634821984; cv=none; d=google.com; s=arc-20160816; b=zosVHtvrAtc046D+8nzBkD99G7uoo46ptomACeAeRyUDknN9tEw9KL6S5uSN1msfKB stHRfvUda3mGvDoc5UhP++thI1btxyn1sd3qfCZB+kkgahwhNWOPAHz9vEtMjXTc1IQ8 JuJj5TWpVfs8vYo6mI0ZOattZDgzhJDV/Vv5CVuiBiZjngQSfQU38Q3DHkGVjdedCvQj SmSD6eLre2SS+FlXLZqTCBhpNJBCE33yRvC85jCkVz73eOctofhZ0a77dPwf1njxnnS6 M2gwm7Awa33GFatyoOd8/eNxJbCDpCRYjpS2C4zIXvQd2Bhjicw4mFdHPklI/2SFcNq7 ga6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=FPTZEaXv4hJv4SBXHbNkcRdv9n8c4umMdckpTU2scJA=; b=hnFUW7bhfgBjUnFBGoNrTmZv5d3E3Naf67MwK+pInBOo9kaliu7Rha4+n42/XA9VOE q28IXosRhOqs8wU4dX8/5Fe9OInagVQHYyfOanK/+5mHR5XKVm11/cwtAEoqFjCL2Esl AVrNhsxL2ZzFdjq9UgztXeMv5CFXob3eeiRnC6581xJJLOcUhTLQBaBXrColKvnsyeaf x1h3V7QEsL/h4TDdTg3EY3+wNhLCinUw5Zlr/J8CcQOlqpm2e80dSmxqRUXI03cbYPih 8bCH3ih3WHBNPgy75FIpvoA+2INoEaC9vm2VYJ+VXtj4Yw0vUwB4ZiuOMAP9Q+bR1MK5 NUUA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o11si8729650pfu.316.2021.10.21.06.12.50; Thu, 21 Oct 2021 06:13:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231477AbhJUNMW (ORCPT + 99 others); Thu, 21 Oct 2021 09:12:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:51738 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231346AbhJUNMV (ORCPT ); Thu, 21 Oct 2021 09:12:21 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 547BF60ED5; Thu, 21 Oct 2021 13:10:04 +0000 (UTC) Date: Thu, 21 Oct 2021 09:10:01 -0400 From: Steven Rostedt To: Cai Huoqing Cc: Bernard Metzler , Doug Ledford , Jason Gunthorpe , Davidlohr Bueso , "Paul E. McKenney" , Josh Triplett , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes , Ingo Molnar , Daniel Bristot de Oliveira , , , Subject: Re: [PATCH 1/6] kthread: Add the helper macro kthread_run_on_cpu() Message-ID: <20211021091001.26c24d5b@gandalf.local.home> In-Reply-To: <20211021120135.3003-2-caihuoqing@baidu.com> References: <20211021120135.3003-1-caihuoqing@baidu.com> <20211021120135.3003-2-caihuoqing@baidu.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 21 Oct 2021 20:01:30 +0800 Cai Huoqing wrote: > the helper macro kthread_run_on_cpu() inculdes "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. > > Signed-off-by: Cai Huoqing > --- > include/linux/kthread.h | 22 ++++++++++++++++++++++ > 1 file changed, 22 insertions(+) > > diff --git a/include/linux/kthread.h b/include/linux/kthread.h > index 346b0f269161..dfd125523aa9 100644 > --- a/include/linux/kthread.h > +++ b/include/linux/kthread.h > @@ -56,6 +56,28 @@ bool kthread_is_per_cpu(struct task_struct *k); > __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_node() > + * followed by wake_up_process(). Returns the kthread or > + * ERR_PTR(-ENOMEM). > + */ > +#define kthread_run_on_cpu(threadfn, data, cpu, namefmt) \ Why is this a macro and not a static inline function? -- Steve > +({ \ > + struct task_struct *__k \ > + = kthread_create_on_cpu(threadfn, data, cpu_to_node(cpu), \ > + namefmt); \ > + if (!IS_ERR(__k)) \ > + wake_up_process(__k); \ > + __k; \ > +}) > + > 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);