Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2339766imm; Sat, 28 Jul 2018 14:58:52 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfJDlAPtDogE6RysyrMTKWITkpclIbgenovgyzqKGOxFMI3V3SlLW2j9jXRWe00cxN4dAkY X-Received: by 2002:a17:902:201:: with SMTP id 1-v6mr11101864plc.310.1532815132587; Sat, 28 Jul 2018 14:58:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532815132; cv=none; d=google.com; s=arc-20160816; b=F9cAyBnv/JAxAPucHJrrbOQJ8oH+3Cc93Cv+C6k0+6NkKxiCIBhsEy7VRDKZB0QK7m Oa+Bn1ul8+A6gASU7H/gutIPuTw+pWE+TcCBWwfgGU3fuCTGT371aNzQWoHXPHvl1Mrl XCckzUgdgGeExQt4vMDEzElHhbXArIypMR+i8WWQRpNdLW9ZyBuqlGNWWB/RGdJzGSnp 0DyajbguWW2tIDNWmHWfZY2LpCx1oWSkIH2ZTHVSLAi5uiOWkGgzwSEJzQRud4bnggs1 +re0JjLuVWXUdVZnOub7r4IvRRw/VDOLdzq5ztIfNxPyrjDxTjY6MkxCtT6LYVpUS3hy +mNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=I+2c836UzYT4izxX7vpOb2TQIEwkFfQvT5wRXpafkOs=; b=eNNaAKlfUPvp8Z6lvLlg0DZSb0QC5k1FaETEeLBmUGZXbj6eGDOQOCGAyLh9wQ/e1K gwkZQZjs6mlfuNtBKLKRZgRCsfIDJbBRYT0/Z+LXh/jquZSu7bL5eMhXe6lo3TzOx/h6 huG35LWs/3QcymnBSW7Q2JDS3ooXfSUqEmO1c2oXOuu6Id7BNdZTMfdSR49BSOw97V8Q eiT2cZkoa4F/Njxazac8T6Zofe02ps/yRN9XPCNoQqyCGjTgsIBdCZTELFgOPFVl22Oo 7AOwUGuIVBQ+DLH+fUOYxUCO4oSsz5bNDD4YLt7lTDXd+RLjHWjzNir926bYuOI/q1MH qgZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h11-v6si7973592pfe.102.2018.07.28.14.58.38; Sat, 28 Jul 2018 14:58:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731549AbeG1XXC (ORCPT + 99 others); Sat, 28 Jul 2018 19:23:02 -0400 Received: from shelob.surriel.com ([96.67.55.147]:44138 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731349AbeG1XWU (ORCPT ); Sat, 28 Jul 2018 19:22:20 -0400 Received: from imladris.surriel.com ([96.67.55.152]) by shelob.surriel.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1fjXA0-0000QZ-Ld; Sat, 28 Jul 2018 17:54:00 -0400 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: kernel-team@fb.com, peterz@infradead.org, luto@kernel.org, x86@kernel.org, vkuznets@redhat.com, mingo@kernel.org, efault@gmx.de, dave.hansen@intel.com, will.daecon@arm.com, catalin.marinas@arm.com, benh@kernel.crashing.org, Rik van Riel Subject: [PATCH 03/10] smp,cpumask: introduce on_each_cpu_cond_mask Date: Sat, 28 Jul 2018 17:53:50 -0400 Message-Id: <20180728215357.3249-4-riel@surriel.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20180728215357.3249-1-riel@surriel.com> References: <20180728215357.3249-1-riel@surriel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Introduce a variant of on_each_cpu_cond that iterates only over the CPUs in a cpumask, in order to avoid making callbacks for every single CPU in the system when we only need to test a subset. Signed-off-by: Rik van Riel --- include/linux/smp.h | 4 ++++ kernel/smp.c | 17 +++++++++++++---- kernel/up.c | 14 +++++++++++--- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/include/linux/smp.h b/include/linux/smp.h index 9fb239e12b82..a56f08ff3097 100644 --- a/include/linux/smp.h +++ b/include/linux/smp.h @@ -53,6 +53,10 @@ void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info), smp_call_func_t func, void *info, bool wait, gfp_t gfp_flags); +void on_each_cpu_cond_mask(bool (*cond_func)(int cpu, void *info), + smp_call_func_t func, void *info, bool wait, + gfp_t gfp_flags, const struct cpumask *mask); + int smp_call_function_single_async(int cpu, call_single_data_t *csd); #ifdef CONFIG_SMP diff --git a/kernel/smp.c b/kernel/smp.c index 2dbc842dd385..f4cf1b0bb3b8 100644 --- a/kernel/smp.c +++ b/kernel/smp.c @@ -667,9 +667,9 @@ EXPORT_SYMBOL(on_each_cpu_mask); * You must not call this function with disabled interrupts or * from a hardware interrupt handler or from a bottom half handler. */ -void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info), +void on_each_cpu_cond_mask(bool (*cond_func)(int cpu, void *info), smp_call_func_t func, void *info, bool wait, - gfp_t gfp_flags) + gfp_t gfp_flags, const struct cpumask *mask) { cpumask_var_t cpus; int cpu, ret; @@ -678,7 +678,7 @@ void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info), if (likely(zalloc_cpumask_var(&cpus, (gfp_flags|__GFP_NOWARN)))) { preempt_disable(); - for_each_online_cpu(cpu) + for_each_cpu(cpu, mask) if (cond_func(cpu, info)) __cpumask_set_cpu(cpu, cpus); on_each_cpu_mask(cpus, func, info, wait); @@ -690,7 +690,7 @@ void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info), * just have to IPI them one by one. */ preempt_disable(); - for_each_online_cpu(cpu) + for_each_cpu(cpu, mask) if (cond_func(cpu, info)) { ret = smp_call_function_single(cpu, func, info, wait); @@ -699,6 +699,15 @@ void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info), preempt_enable(); } } +EXPORT_SYMBOL(on_each_cpu_cond_mask); + +void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info), + smp_call_func_t func, void *info, bool wait, + gfp_t gfp_flags) +{ + on_each_cpu_cond_mask(cond_func, func, info, wait, gfp_flags, + cpu_online_mask); +} EXPORT_SYMBOL(on_each_cpu_cond); static void do_nothing(void *unused) diff --git a/kernel/up.c b/kernel/up.c index 42c46bf3e0a5..ff536f9cc8a2 100644 --- a/kernel/up.c +++ b/kernel/up.c @@ -68,9 +68,9 @@ EXPORT_SYMBOL(on_each_cpu_mask); * Preemption is disabled here to make sure the cond_func is called under the * same condtions in UP and SMP. */ -void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info), - smp_call_func_t func, void *info, bool wait, - gfp_t gfp_flags) +void on_each_cpu_cond_mask(bool (*cond_func)(int cpu, void *info), + smp_call_func_t func, void *info, bool wait, + gfp_t gfp_flags, const struct cpumask *mask) { unsigned long flags; @@ -82,6 +82,14 @@ void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info), } preempt_enable(); } +EXPORT_SYMBOL(on_each_cpu_cond_mask); + +void on_each_cpu_cond(bool (*cond_func)(int cpu, void *info), + smp_call_func_t func, void *info, bool wait, + gfp_t gfp_flags) +{ + on_each_cpu_cond_mask(cond_func, func, info, wait, gfp_flags, NULL); +} EXPORT_SYMBOL(on_each_cpu_cond); int smp_call_on_cpu(unsigned int cpu, int (*func)(void *), void *par, bool phys) -- 2.14.4