Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp551346pxb; Thu, 21 Oct 2021 05:04:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwa3KBCgCft2nxXOXRFPQtCFYv8lcwm27iAURWbjUFA3tT7MI4v0TME/edAZ6pjvZdv5M2/ X-Received: by 2002:a63:b448:: with SMTP id n8mr4125511pgu.31.1634817842054; Thu, 21 Oct 2021 05:04:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634817842; cv=none; d=google.com; s=arc-20160816; b=SUZqiMIfEof+XTkq3izDqD2MW6eTFD3CjJC3K2jQNhm+KeHUWbq9iUyBIfAz4N8h07 SxsNoPEMxzM+s49xE4qmjYsjWcFxiuE9drrByu6LoJunEUESqc/1WX0xBIcGc/GvSoii 3bmQtHhfUJaprY4UHC90Rg0i9mEMWPKz/Z6EgJ1BKqJEQcT7PqgVxrcKyoBj9UaKHzvO dDFkSStxW5eLUXY8BheO77FhQqYdsq9OXTj7CeDoooGJE4RNquLyHDJAdiNAmuke3cCL PSC8nRWJWgyZiqbLzFzISWoqicUL4dkLp/f+FqchT/8UWpWCxerlKsJeh0PuOfhPrNjD /FYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=Snia81OqKlPihacy5xlzdBy19QssPM0lWxz8CsbtSDI=; b=bOyCGGRv5hfLk1sbRloQZd6sxA3PL07R+VdmVO+NscI/cr0fyG8Na1oCQUJzKK3v+C 9BDpUin2jx3ig8FyWn8LpeIYZrN+nKAW1yxp9wjjyeNlacDWVCjvPkTeb8S79AH5/vWD OX+IRn4h7TcVoWMwkrc7IXG9cJwbRLMGN3/wWsup8xE84d33oBKAPUsCjKhryCz77rta VQE6bW9fsUzMS3HuARTp2AGfU2V046uCGj7zS15G3xyfjs72Hfpv+2m8WktHAwmV/AdZ 4C9h+XWuMo05Q9wi7HV7vd5h/FJThmqOT5iIwgppAXthIf5+RzWMGDzkda4XziDX9+9y EcFw== 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 k34si7665315pgi.535.2021.10.21.05.03.43; Thu, 21 Oct 2021 05:04:02 -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 S231203AbhJUMEL (ORCPT + 99 others); Thu, 21 Oct 2021 08:04:11 -0400 Received: from mx24.baidu.com ([111.206.215.185]:42282 "EHLO baidu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230340AbhJUMEI (ORCPT ); Thu, 21 Oct 2021 08:04:08 -0400 Received: from BC-Mail-Ex12.internal.baidu.com (unknown [172.31.51.52]) by Forcepoint Email with ESMTPS id 6A62C8AEA37A7E74DBA6; Thu, 21 Oct 2021 20:01:46 +0800 (CST) Received: from BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) by BC-Mail-Ex12.internal.baidu.com (172.31.51.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2242.12; Thu, 21 Oct 2021 20:01:46 +0800 Received: from LAPTOP-UKSR4ENP.internal.baidu.com (172.31.63.8) by BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2308.14; Thu, 21 Oct 2021 20:01:44 +0800 From: Cai Huoqing To: CC: Bernard Metzler , Doug Ledford , Jason Gunthorpe , Davidlohr Bueso , "Paul E. McKenney" , Josh Triplett , "Steven Rostedt" , Mathieu Desnoyers , Lai Jiangshan , Joel Fernandes , Ingo Molnar , Daniel Bristot de Oliveira , , , Subject: [PATCH 1/6] kthread: Add the helper macro kthread_run_on_cpu() Date: Thu, 21 Oct 2021 20:01:30 +0800 Message-ID: <20211021120135.3003-2-caihuoqing@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211021120135.3003-1-caihuoqing@baidu.com> References: <20211021120135.3003-1-caihuoqing@baidu.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.31.63.8] X-ClientProxiedBy: BC-Mail-EX04.internal.baidu.com (172.31.51.44) To BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org the helper macro kthread_run_on_cpu() inculdes 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) \ +({ \ + 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); -- 2.25.1