Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp7649842ioo; Fri, 3 Jun 2022 10:35:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyp+3VFVARQkv/GjDloydJBi4bjhgInOMvpOwwzWfmh+MofAKKzpbfLYT4solaPG5b7RLey X-Received: by 2002:a05:6402:5413:b0:42a:adef:b360 with SMTP id ev19-20020a056402541300b0042aadefb360mr12250498edb.122.1654277737357; Fri, 03 Jun 2022 10:35:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654277737; cv=none; d=google.com; s=arc-20160816; b=yoEzcgCB4ZC/ApZqMTYL5aw/B5vdcrBv7rMQ6UlHlMtaj+5vZ/9DPKAvyCtbeLNWqt uMijz9UqiHf3Fwcdv10zigoGxgI8jij7ximMemGWQfA70LKehTsOFjqT3HEJ1Ndi0RWL B2s7MU8CD+NztQMcQK2o0gaAfn/sBUDp6+OR0W1q7ggQ/U6G/gYFiabHnBPTpCC9Jey3 qa+/5p9LqIABy9XMMPNfNm3PSMzXof3Ik9P+RDmRATc7W0m6i/5HdG1cbiZTg+50yYj5 7rAhe6jouGCdHujRaaMiszPGi9k7/5ViGvhQTaGfswJb7r+/qHLmV9sQcD6yrnO7u9Db xLvw== 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:date:subject:cc:to:from :dkim-signature; bh=IFZErQoe8ZlF0OjWg65tXnT3I6llghGKYUzn30c9kfg=; b=p3u/iWIDYbuS3oNLImRZKYZkuThnXYM8WOVmYxCAg8kd4uEn0eXbFe/3YM6cfFDCvi uRq/pswhMPr2hrWM29RAMFxEuksVy3IEQnWAZPeQQSMFxRy4DILOyVyuWu4SWvJKVm7N X+mBLeZbuhTBRmEQXEFeFAHDdzYgPGCG0r42+a2lMO4RAz1Pd3+HRzl/prYlvDAXLo1p J9iQaUEraUi1hiJW9u88WHvxI4u+nXWCx4ZLOfWhGZ7ACyL8smkd+pjmuLv/eXgLuZKr 0VGRFdmTmIPlCphkCzPX69M1eB48OZraK9x+/rU9ixSAZjOyr2CrQr1IwQEqobT15SaJ FAkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@svanheule.net header.s=mail1707 header.b="1/aKNVrz"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=svanheule.net Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz38-20020a1709077da600b0070ee7b77482si2038957ejc.782.2022.06.03.10.35.10; Fri, 03 Jun 2022 10:35:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@svanheule.net header.s=mail1707 header.b="1/aKNVrz"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=svanheule.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239351AbiFBVEt (ORCPT + 99 others); Thu, 2 Jun 2022 17:04:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239332AbiFBVEm (ORCPT ); Thu, 2 Jun 2022 17:04:42 -0400 Received: from polaris.svanheule.net (polaris.svanheule.net [84.16.241.116]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3B7735260 for ; Thu, 2 Jun 2022 14:04:41 -0700 (PDT) Received: from terra.. (unknown [IPv6:2a02:a03f:eaf9:8401:aa9f:5d01:1b2a:e3cd]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: sander@svanheule.net) by polaris.svanheule.net (Postfix) with ESMTPSA id CA7D92E19A9; Thu, 2 Jun 2022 23:04:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=svanheule.net; s=mail1707; t=1654203876; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IFZErQoe8ZlF0OjWg65tXnT3I6llghGKYUzn30c9kfg=; b=1/aKNVrzxd2vONtqJF3vP2mISEf+qR8ATq+lcQK3V9mVqcO8bMg8VosuZanJpdHuIqPKVR w6sMHR8UGO3lsyCdJg1QQuVp1cOXySGJU3yY51swvpwKiQJmYMgAHHEo0wnYKkwwvzTBoc K/tB2HP9LHz74sLhdaLhqv4hcRIQjOxAhd6Obv9EDx5EB097S4b8NgjkeETDvuwP3fcOUv +w/MX30lcsgg+wxMjK/PD1jzvCiuHML1ORSKmZ+7oiC6UtUj+P6DSjUgoXY1kuVRp0LzPY dcGmifcsMZuD1syUDbwhVRrmxNzzYHiLzMXByijECbfxy+6sV1+9w6etMGySdQ== From: Sander Vanheule To: Peter Zijlstra , Yury Norov , Andrew Morton , Valentin Schneider , Thomas Gleixner , Greg Kroah-Hartman , Marco Elver , Barry Song Cc: linux-kernel@vger.kernel.org, Andy Shevchenko , Sander Vanheule Subject: [PATCH v1 2/2] cpumask: Add UP optimised for_each_*_cpu loops Date: Thu, 2 Jun 2022 23:04:20 +0200 Message-Id: X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On uniprocessor builds, the following loops will always run over a mask that contains one enabled CPU (cpu0): - for_each_possible_cpu - for_each_online_cpu - for_each_present_cpu Provide uniprocessor-specific macros for these loops, that always run exactly once. Signed-off-by: Sander Vanheule --- include/linux/cpumask.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index ce8c7b27f6c9..8af37cd603e3 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -806,9 +806,16 @@ extern const DECLARE_BITMAP(cpu_all_bits, NR_CPUS); /* First bits of cpu_bit_bitmap are in fact unset. */ #define cpu_none_mask to_cpumask(cpu_bit_bitmap[0]) +#if NR_CPUS == 1 +/* Uniprocessor: the possible/online/present masks are always "1" */ +#define for_each_possible_cpu(cpu) for ((cpu) = 0; (cpu) < 1; (cpu)++) +#define for_each_online_cpu(cpu) for ((cpu) = 0; (cpu) < 1; (cpu)++) +#define for_each_present_cpu(cpu) for ((cpu) = 0; (cpu) < 1; (cpu)++) +#else #define for_each_possible_cpu(cpu) for_each_cpu((cpu), cpu_possible_mask) #define for_each_online_cpu(cpu) for_each_cpu((cpu), cpu_online_mask) #define for_each_present_cpu(cpu) for_each_cpu((cpu), cpu_present_mask) +#endif /* Wrappers for arch boot code to manipulate normally-constant masks */ void init_cpu_present(const struct cpumask *src); -- 2.36.1