Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1269395pxb; Thu, 21 Oct 2021 20:00:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwPNbx3IviTwEwMG+OnU0aqpo3KxImUB4pGL9L7zaa6MEeRell8UTvnVtLHcws2meK45BxE X-Received: by 2002:a17:90b:3850:: with SMTP id nl16mr11054853pjb.127.1634871656970; Thu, 21 Oct 2021 20:00:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634871656; cv=none; d=google.com; s=arc-20160816; b=OpJKgzlfgrLFsChlL12bws9V+fz4TpR+KQtha6UbFJVO/Idkt9dMNugrFvMIxbA9UW NiN8CuhVz/CeNaq751vS9wyw5GJTlA4kOOU37BNXdjvIy+xevQDiTUp5xznWd2gfpeD3 Rr2+FyMWPhjYCdfrCeFdEx2lCgtoJSYIZsdXbV0DdBzblLYiSFVRisOszIznxQ7WxOxF pgpX6sACVD2bIhYQAu74btxzfvulwYBQ3dogVXxsWjaUN6P0GkWziAy2mKF4PWScnB+N yJiVKRX5LK18uvL9bmBJTGQTsJmjaGQ5bRTSAl/NLXkk65+8Xv+eOKVS35CiTYLx3hWv nEAw== 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=nkivVVXlzrT1ai83D2pzwwqUmDOtbRCVGS9YhafkUw8=; b=nqC9ECYbgspO2tSdgKRlUPQOTmUEovHCo3DZgxm0Yw8P93ROFhj0sHmZNm7Hfl/dVB 71Zj3haA7ERVLexOm9A06zq7GB8bBQfSfOSCdr72BHd9B/+3bMLqVw1EOm5Ndk+9r2iu SZD0AxTWjJifN+YZgngwZJ+gc7ODPosRahLG5QsR/99fe7nBN5BGdpBWB684tLXAKmgf DcICKVycE6jh0zrsGVfHgBareVe8eu6r2kYatkAIGaGGYXugTIUzXv0RUl11wV2sv8Dw U+HivjPF1lzLr9Vb0TDlMpKnRWOUz62rfuCPHS4C6ndoUFiFvzUx1N3LI5dKMQwConyl bahA== 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 ob5si10741274pjb.158.2021.10.21.20.00.41; Thu, 21 Oct 2021 20:00:56 -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 S232685AbhJVDBf (ORCPT + 99 others); Thu, 21 Oct 2021 23:01:35 -0400 Received: from mx22.baidu.com ([220.181.50.185]:50378 "EHLO baidu.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232613AbhJVDBc (ORCPT ); Thu, 21 Oct 2021 23:01:32 -0400 Received: from BC-Mail-Ex09.internal.baidu.com (unknown [172.31.51.49]) by Forcepoint Email with ESMTPS id E763CEC8D8E4ACBD5A29; Fri, 22 Oct 2021 10:59:04 +0800 (CST) Received: from BJHW-MAIL-EX27.internal.baidu.com (10.127.64.42) by BC-Mail-Ex09.internal.baidu.com (172.31.51.49) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2242.12; Fri, 22 Oct 2021 10:59:04 +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; Fri, 22 Oct 2021 10:59:03 +0800 From: Cai Huoqing To: CC: Cai Huoqing , 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: [PATCH v3 1/6] kthread: Add the helper function kthread_run_on_cpu() Date: Fri, 22 Oct 2021 10:57:04 +0800 Message-ID: <20211022025711.3673-2-caihuoqing@baidu.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211022025711.3673-1-caihuoqing@baidu.com> References: <20211022025711.3673-1-caihuoqing@baidu.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [172.31.63.8] X-ClientProxiedBy: BC-Mail-Ex28.internal.baidu.com (172.31.51.22) 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 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. Signed-off-by: Cai Huoqing --- v1->v2: *Remove cpu_to_node from kthread_create_on_cpu params. *Updated the macro description comment. v2->v3: *Convert this helper macro to static inline function *Fix typo in changelog v1 link: https://lore.kernel.org/lkml/20211021120135.3003-2-caihuoqing@baidu.com/ v2 link: https://lore.kernel.org/lkml/20211021122758.3092-2-caihuoqing@baidu.com/ include/linux/kthread.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/include/linux/kthread.h b/include/linux/kthread.h index 346b0f269161..db47aae7c481 100644 --- a/include/linux/kthread.h +++ b/include/linux/kthread.h @@ -56,6 +56,31 @@ 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_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); -- 2.25.1