Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1303862pxa; Sat, 15 Aug 2020 15:08:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBDJEEJS0oLGihOAEwvKQ3VQzfDZxNCfs2PKZelepNK4ewLg0qyjMoD1UoJW06ttV0eVAQ X-Received: by 2002:a50:ed84:: with SMTP id h4mr8590954edr.278.1597529301687; Sat, 15 Aug 2020 15:08:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597529301; cv=none; d=google.com; s=arc-20160816; b=yF2LdFJXI+8KA4OWyCfBYSRu9EPdNA+ZUVjv8xP0OX0G/4x1QDaKdjwh6JgPd14acL fStkVLDJuaFU2eO8ac9xuCMKd8L5UFN9DgnI9VFa1vw1jQTrbZcoS60dfUtsVcDZg8Fd +qnRJaAtEwaLFFxKtVYvCjglQy7BdM06zLY81h3KgtsEiO90M1hOrkpm7F7ZRiB8CBxu HaRBrkWxowj+tdZwEQQISmyxW2GQwS6WzklIkkJtUKKHxNEpqjrPTyafw2N82KO66ien q1Gr7AGeEytAG3MhcWtsBzxysIxw0hUs/BuXtfSJV+ybNhjmLvXGGOQtye/Q9anbcGmx iD4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sz9J9n5LJAX7KClHXQuFpMY4XStGHjRFIOCICHV1+xA=; b=IWcdo5T/5Ptl0DxCO/m0zpVpbVNCD4uO29v7gJaGSTosIrJtvM/7296lcxuTOZ/ArI 00c7/f11hXer92lK7vebGq1WENs2ZsLO1gsnOxSkbgiaLrJ+6yzMTZ+0//ODQHB32x+r 6MxY8GQdBgFsjiVgAQrKS7BMQ+vuYn+D454vXn7iacMYrDUXQFjqHaCjO6DDEWqktMqr MaLBd4dZBfOmFxd+7AafsMJ6V1ZpHn+fhM5VhdckFtKm3IrBfJ8bNg6GDAxPRbOu0Glg hvJgfTSidj0NT2xi0+ivqMVUfIeUTKE78nljggMA3sFWQhl1mxIwD+akNCwYkEVSMxjQ oFng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=DBYuSEfa; 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 p15si7883623ejx.297.2020.08.15.15.07.58; Sat, 15 Aug 2020 15:08:21 -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; dkim=pass header.i=@joelfernandes.org header.s=google header.b=DBYuSEfa; 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 S1729799AbgHOWGv (ORCPT + 99 others); Sat, 15 Aug 2020 18:06:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728390AbgHOVus (ORCPT ); Sat, 15 Aug 2020 17:50:48 -0400 Received: from mail-qv1-xf43.google.com (mail-qv1-xf43.google.com [IPv6:2607:f8b0:4864:20::f43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A140C061379 for ; Fri, 14 Aug 2020 20:19:32 -0700 (PDT) Received: by mail-qv1-xf43.google.com with SMTP id l13so5230015qvt.10 for ; Fri, 14 Aug 2020 20:19:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sz9J9n5LJAX7KClHXQuFpMY4XStGHjRFIOCICHV1+xA=; b=DBYuSEfaGrHBZ6Ox30YL3/iF80Lbym84DzzCTT44BqXZbCQrCWIHiVVstkjiPp5D3D 0Yc0zxknsWLouhfVyupvLylPPu3mlSvCJ5Bk3JVOHGtboT8kJHczbvJJyeBgQgbt2mKm OvZouILkJD+chgktd8mY35fv05p4iyQsNd3Qw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sz9J9n5LJAX7KClHXQuFpMY4XStGHjRFIOCICHV1+xA=; b=gdI9z1vOdBqP2GNy5V2RKiZUK/rZOom8u4wjZ4KqYW/nGe8KRfqNr+NrfQo4s71PXX anf4vx4M0clpffg2XTn1vjGYHLihomOk6CQgvQobbMUnhWjv3FE0q6bLMfkWpIreITeA omQo/bvq7KHWoG22hJHyfjkl/MatXOwb/uyex51C9y93Z1wlkRPgJWHIfUWbgC7PfXQQ z9KDTqF7DGUzW0B7cyQyKqGmopsNY9W7wgMMucDEkLzHMAacpNPGPAFi8SMvvAcHDGyM bj8BVO56DqqBSPcN5EFVy6b00KOZFJm/orRJdVQ+tTh8gaVjig6OYX8lYzotkXBb+NaE WTHw== X-Gm-Message-State: AOAM533aYd99z0NINb+AiRRPfpm3I1bbz529LUdkN2Lwyr4V5fuRatxm 6vMHuciM9KQiLgTAz+zVrku5MqF5EmLHJA== X-Received: by 2002:a0c:b310:: with SMTP id s16mr5320090qve.5.1597461571554; Fri, 14 Aug 2020 20:19:31 -0700 (PDT) Received: from joelaf.cam.corp.google.com ([2620:15c:6:12:cad3:ffff:feb3:bd59]) by smtp.gmail.com with ESMTPSA id p12sm10055199qkk.118.2020.08.14.20.19.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 20:19:31 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: Vineeth Pillai , Joel Fernandes , Aaron Lu , Aubrey Li , Julien Desfossez , Kees Cook , "Paul E. McKenney" , Paul Turner , Peter Zijlstra , Steven Rostedt , Thomas Gleixner , Tim Chen , Tim Chen , Vincent Guittot , x86@kernel.org (maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)), fweisbec@gmail.com, kerrnel@google.com, Phil Auld , Valentin Schneider , Paolo Bonzini , Chen Yu , Christian Brauner Subject: [PATCH RFC 08/12] cpumask: Introduce a new iterator for_each_cpu_wrap_or Date: Fri, 14 Aug 2020 23:19:04 -0400 Message-Id: <20200815031908.1015049-9-joel@joelfernandes.org> X-Mailer: git-send-email 2.28.0.220.ged08abb693-goog In-Reply-To: <20200815031908.1015049-1-joel@joelfernandes.org> References: <20200815031908.1015049-1-joel@joelfernandes.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Vineeth Pillai Hotplug fixes to core-scheduling require a new cpumask iterator which iterates through all online cpus in both the given cpumasks. This patch introduces it. Signed-off-by: Vineeth Pillai Signed-off-by: Joel Fernandes (Google) --- include/linux/cpumask.h | 42 ++++++++++++++++++++++++++++++++ lib/cpumask.c | 53 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index f0d895d6ac39..03e8c57c6ca6 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -207,6 +207,10 @@ static inline int cpumask_any_and_distribute(const struct cpumask *src1p, for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask, (void)(start)) #define for_each_cpu_and(cpu, mask1, mask2) \ for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask1, (void)mask2) +#define for_each_cpu_or(cpu, mask1, mask2) \ + for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask1, (void)mask2) +#define for_each_cpu_wrap_or(cpu, mask1, mask2, start) \ + for ((cpu) = 0; (cpu) < 1; (cpu)++, (void)mask1, (void)mask2, (void)(start)) #else /** * cpumask_first - get the first cpu in a cpumask @@ -248,6 +252,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp) } int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *); +int cpumask_next_or(int n, const struct cpumask *, const struct cpumask *); int cpumask_any_but(const struct cpumask *mask, unsigned int cpu); unsigned int cpumask_local_spread(unsigned int i, int node); int cpumask_any_and_distribute(const struct cpumask *src1p, @@ -278,6 +283,8 @@ int cpumask_any_and_distribute(const struct cpumask *src1p, (cpu) < nr_cpu_ids;) extern int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap); +extern int cpumask_next_wrap_or(int n, const struct cpumask *mask1, + const struct cpumask *mask2, int start, bool wrap); /** * for_each_cpu_wrap - iterate over every cpu in a mask, starting at a specified location @@ -294,6 +301,22 @@ extern int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool (cpu) < nr_cpumask_bits; \ (cpu) = cpumask_next_wrap((cpu), (mask), (start), true)) +/** + * for_each_cpu_wrap_or - iterate over every cpu in both masks, starting at a specified location + * @cpu: the (optionally unsigned) integer iterator + * @mask1: the first cpumask pointer + * @mask2: the second cpumask pointer + * @start: the start location + * + * The implementation does not assume any bit both masks are set (including @start). + * + * After the loop, cpu is >= nr_cpu_ids. + */ +#define for_each_cpu_wrap_or(cpu, mask1, mask2, start) \ + for ((cpu) = cpumask_next_wrap_or((start)-1, (mask1), (mask2), (start), false); \ + (cpu) < nr_cpumask_bits; \ + (cpu) = cpumask_next_wrap_or((cpu), (mask1), (mask2), (start), true)) + /** * for_each_cpu_and - iterate over every cpu in both masks * @cpu: the (optionally unsigned) integer iterator @@ -312,6 +335,25 @@ extern int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool for ((cpu) = -1; \ (cpu) = cpumask_next_and((cpu), (mask1), (mask2)), \ (cpu) < nr_cpu_ids;) + +/** + * for_each_cpu_or - iterate over every cpu in both masks + * @cpu: the (optionally unsigned) integer iterator + * @mask1: the first cpumask pointer + * @mask2: the second cpumask pointer + * + * This saves a temporary CPU mask in many places. It is equivalent to: + * struct cpumask tmp; + * cpumask_and(&tmp, &mask1, &mask2); + * for_each_cpu(cpu, &tmp) + * ... + * + * After the loop, cpu is >= nr_cpu_ids. + */ +#define for_each_cpu_or(cpu, mask1, mask2) \ + for ((cpu) = -1; \ + (cpu) = cpumask_next_or((cpu), (mask1), (mask2)), \ + (cpu) < nr_cpu_ids;) #endif /* SMP */ #define CPU_BITS_NONE \ diff --git a/lib/cpumask.c b/lib/cpumask.c index fb22fb266f93..0a5cdbd4eb6a 100644 --- a/lib/cpumask.c +++ b/lib/cpumask.c @@ -42,6 +42,25 @@ int cpumask_next_and(int n, const struct cpumask *src1p, } EXPORT_SYMBOL(cpumask_next_and); +/** + * cpumask_next_or - get the next cpu in *src1p | *src2p + * @n: the cpu prior to the place to search (ie. return will be > @n) + * @src1p: the first cpumask pointer + * @src2p: the second cpumask pointer + * + * Returns >= nr_cpu_ids if no further cpus set in both. + */ +int cpumask_next_or(int n, const struct cpumask *src1p, + const struct cpumask *src2p) +{ + /* -1 is a legal arg here. */ + if (n != -1) + cpumask_check(n); + return find_next_or_bit(cpumask_bits(src1p), cpumask_bits(src2p), + nr_cpumask_bits, n + 1); +} +EXPORT_SYMBOL(cpumask_next_or); + /** * cpumask_any_but - return a "random" in a cpumask, but not this one. * @mask: the cpumask to search @@ -94,6 +113,40 @@ int cpumask_next_wrap(int n, const struct cpumask *mask, int start, bool wrap) } EXPORT_SYMBOL(cpumask_next_wrap); +/** + * cpumask_next_wrap_or - helper to implement for_each_cpu_wrap_or + * @n: the cpu prior to the place to search + * @mask1: first cpumask pointer + * @mask2: second cpumask pointer + * @start: the start point of the iteration + * @wrap: assume @n crossing @start terminates the iteration + * + * Returns >= nr_cpu_ids on completion + * + * Note: the @wrap argument is required for the start condition when + * we cannot assume @start is set in @mask. + */ +int cpumask_next_wrap_or(int n, const struct cpumask *mask1, const struct cpumask *mask2, + int start, bool wrap) +{ + int next; + +again: + next = cpumask_next_or(n, mask1, mask2); + + if (wrap && n < start && next >= start) { + return nr_cpumask_bits; + + } else if (next >= nr_cpumask_bits) { + wrap = true; + n = -1; + goto again; + } + + return next; +} +EXPORT_SYMBOL(cpumask_next_wrap_or); + /* These are not inline because of header tangles. */ #ifdef CONFIG_CPUMASK_OFFSTACK /** -- 2.28.0.220.ged08abb693-goog