Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1302386pxa; Sat, 15 Aug 2020 15:04:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwgeJnGUeap3uRDVJe9ebJcvVHxfhuGMHY1VdTeB68jRIcm7dbHEcNLY3KQcT43srma4Xcc X-Received: by 2002:aa7:d948:: with SMTP id l8mr8591601eds.371.1597529094742; Sat, 15 Aug 2020 15:04:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597529094; cv=none; d=google.com; s=arc-20160816; b=FeQ4qjYMrUcORWEqW5LwBHO1wYBvdi8MlcIU8olMGD3sIwV5W4CA/sbLr4BuLc2PY7 CF+v8FqHY8p+s8/FW4lrB6d0xrTHY0MiCotnBwKSxsTt0M3YuZ2WsjkgEOaW5glmIML0 LoBWottN9YOCqkF+yMgu+9poDyJR7nD5Eg9CnwxOnQVuHlfTSo1IBU9e46e52Vq3ERvb oPhmqv/VyPu1Usv9g9wf3RwI5dmUGtd4OLYvoYeVjghdDG//KeNz9uUNWIpp5pP0Ikps UWOlSKXzIfeJWJfpboS4WfEu+2OmGAaRdTN7EIQImvJBpkEu/bq7amv+D80FQWJz1ilq tHVQ== 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=ropbXLmQVQLM4HRBV4KUOHOQ9FtvbqlRpYjRFgviYHA=; b=Q9GS22WsqcIgJzKd8lwj8ZadD7LeJHl24GELRqsYK7cz5LsBphC3rDkIv/+NHohp9k ThR1uZHlUoDD2utvqyGfvf7X9ICDaw4J2u1dQ5nIuF+oL4az67IJ2Dp9ocZBkdxrzFoB GnG1NDWhvvvS75cw3PotMTr6cnqfgpvsYs9AYXXuIi1m9liKT3/M5aELSd+Zkj8O0Cvf q5wuRMmYI4xr2FS7wXqQJGVtW/CWa3vpi/S4GmsxEseRlCbEe7AWyImiQ+KZbcWkOoys Yco+AV68KoVTenC460KBAVuaqqZ44ro+rI+ST/Ob1nPMsrYuncghRjV/J1QowtOMkQR8 J9Ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=T3NVoYc8; 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 d24si8210259edz.145.2020.08.15.15.04.31; Sat, 15 Aug 2020 15:04:54 -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=T3NVoYc8; 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 S1726708AbgHOWCv (ORCPT + 99 others); Sat, 15 Aug 2020 18:02:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45648 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726855AbgHOVvW (ORCPT ); Sat, 15 Aug 2020 17:51:22 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09BD0C061378 for ; Fri, 14 Aug 2020 20:19:32 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id 62so10193588qkj.7 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=ropbXLmQVQLM4HRBV4KUOHOQ9FtvbqlRpYjRFgviYHA=; b=T3NVoYc8bWCtji6Ke4d8PuhZQgU5UXRz3E6yI6gJyHrCwafzlXCwOvFqlh6KWH2Sfc mYWnDwj+LJkamj9/sjoaEp+OI5vvIjOpev6t1S+yYDtIaag/kFvOvDWHHKASOgzOrDCq Fh7NbNuXyUHB+qoMVL2G1g+c6KsDjdaPBaI0Y= 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=ropbXLmQVQLM4HRBV4KUOHOQ9FtvbqlRpYjRFgviYHA=; b=G5pJOsgMqeI+7KghjqUnekK9BZ6c6S9KuWyz/ID9nd2HamiJMD7dAdH9dwF+dXOW+X CvvNQjdD4EyTO5AeLP6vQ7Wnn6cnFltpIbAWb7dIfSSqGk1N9/rq12l7dMfKk1VzFiuD Cm9lDgA1ghLhpMICxOI/FT0xKnBOSMLqqKcu7gOV9ERLeZZlsFz1LWrqsOm9l+gO9sZ+ UV0ZVdwi20S5wVhOBchWDI5V3jLeiy2B4RtDkxMbLCzvXsvbYr9U7ABP2BaQV64ipdQn ArBvJzb0dQTEaJ5663U9L36H8Pk6sd7bMu7mY7qOhWuj7qHzNQJClKM2QPWzkL6nusFo j1ew== X-Gm-Message-State: AOAM5307gFBfAgWSCIg9wkEhZGFrMVwCiPeoIBzRELAM2BL9OOrErpoL PZJrsSzRB+hvkyB8uKUuqBTFmxXdsLuxjw== X-Received: by 2002:a05:620a:1424:: with SMTP id k4mr4772841qkj.2.1597461570404; Fri, 14 Aug 2020 20:19:30 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 20:19:30 -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 07/12] bitops: Introduce find_next_or_bit Date: Fri, 14 Aug 2020 23:19:03 -0400 Message-Id: <20200815031908.1015049-8-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 bitops API. Introduce a new API find_next_or_bit() which returns the bit number of the next set bit in OR-ed bit masks of the given bit masks. Signed-off-by: Vineeth Pillai Signed-off-by: Joel Fernandes (Google) --- include/asm-generic/bitops/find.h | 16 +++++++++ lib/find_bit.c | 56 +++++++++++++++++++++++++------ 2 files changed, 61 insertions(+), 11 deletions(-) diff --git a/include/asm-generic/bitops/find.h b/include/asm-generic/bitops/find.h index 9fdf21302fdf..0b476ca0d665 100644 --- a/include/asm-generic/bitops/find.h +++ b/include/asm-generic/bitops/find.h @@ -32,6 +32,22 @@ extern unsigned long find_next_and_bit(const unsigned long *addr1, unsigned long offset); #endif +#ifndef find_next_or_bit +/** + * find_next_or_bit - find the next set bit in any memory regions + * @addr1: The first address to base the search on + * @addr2: The second address to base the search on + * @offset: The bitnumber to start searching at + * @size: The bitmap size in bits + * + * Returns the bit number for the next set bit + * If no bits are set, returns @size. + */ +extern unsigned long find_next_or_bit(const unsigned long *addr1, + const unsigned long *addr2, unsigned long size, + unsigned long offset); +#endif + #ifndef find_next_zero_bit /** * find_next_zero_bit - find the next cleared bit in a memory region diff --git a/lib/find_bit.c b/lib/find_bit.c index 49f875f1baf7..2eca8e2b16b1 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -19,7 +19,14 @@ #if !defined(find_next_bit) || !defined(find_next_zero_bit) || \ !defined(find_next_bit_le) || !defined(find_next_zero_bit_le) || \ - !defined(find_next_and_bit) + !defined(find_next_and_bit) || !defined(find_next_or_bit) + +typedef enum { + FNB_AND = 0, + FNB_OR = 1, + FNB_MAX = 2 +} fnb_bwops_t; + /* * This is a common helper function for find_next_bit, find_next_zero_bit, and * find_next_and_bit. The differences are: @@ -29,7 +36,8 @@ */ static unsigned long _find_next_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long nbits, - unsigned long start, unsigned long invert, unsigned long le) + unsigned long start, unsigned long invert, + fnb_bwops_t type, unsigned long le) { unsigned long tmp, mask; @@ -37,8 +45,16 @@ static unsigned long _find_next_bit(const unsigned long *addr1, return nbits; tmp = addr1[start / BITS_PER_LONG]; - if (addr2) - tmp &= addr2[start / BITS_PER_LONG]; + if (addr2) { + switch (type) { + case FNB_AND: + tmp &= addr2[start / BITS_PER_LONG]; + break; + case FNB_OR: + tmp |= addr2[start / BITS_PER_LONG]; + break; + } + } tmp ^= invert; /* Handle 1st word. */ @@ -56,8 +72,16 @@ static unsigned long _find_next_bit(const unsigned long *addr1, return nbits; tmp = addr1[start / BITS_PER_LONG]; - if (addr2) - tmp &= addr2[start / BITS_PER_LONG]; + if (addr2) { + switch (type) { + case FNB_AND: + tmp &= addr2[start / BITS_PER_LONG]; + break; + case FNB_OR: + tmp |= addr2[start / BITS_PER_LONG]; + break; + } + } tmp ^= invert; } @@ -75,7 +99,7 @@ static unsigned long _find_next_bit(const unsigned long *addr1, unsigned long find_next_bit(const unsigned long *addr, unsigned long size, unsigned long offset) { - return _find_next_bit(addr, NULL, size, offset, 0UL, 0); + return _find_next_bit(addr, NULL, size, offset, 0UL, FNB_AND, 0); } EXPORT_SYMBOL(find_next_bit); #endif @@ -84,7 +108,7 @@ EXPORT_SYMBOL(find_next_bit); unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, unsigned long offset) { - return _find_next_bit(addr, NULL, size, offset, ~0UL, 0); + return _find_next_bit(addr, NULL, size, offset, ~0UL, FNB_AND, 0); } EXPORT_SYMBOL(find_next_zero_bit); #endif @@ -94,11 +118,21 @@ unsigned long find_next_and_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long size, unsigned long offset) { - return _find_next_bit(addr1, addr2, size, offset, 0UL, 0); + return _find_next_bit(addr1, addr2, size, offset, 0UL, FNB_AND, 0); } EXPORT_SYMBOL(find_next_and_bit); #endif +#if !defined(find_next_or_bit) +unsigned long find_next_or_bit(const unsigned long *addr1, + const unsigned long *addr2, unsigned long size, + unsigned long offset) +{ + return _find_next_bit(addr1, addr2, size, offset, 0UL, FNB_OR, 0); +} +EXPORT_SYMBOL(find_next_or_bit); +#endif + #ifndef find_first_bit /* * Find the first set bit in a memory region. @@ -161,7 +195,7 @@ EXPORT_SYMBOL(find_last_bit); unsigned long find_next_zero_bit_le(const void *addr, unsigned long size, unsigned long offset) { - return _find_next_bit(addr, NULL, size, offset, ~0UL, 1); + return _find_next_bit(addr, NULL, size, offset, ~0UL, FNB_AND, 1); } EXPORT_SYMBOL(find_next_zero_bit_le); #endif @@ -170,7 +204,7 @@ EXPORT_SYMBOL(find_next_zero_bit_le); unsigned long find_next_bit_le(const void *addr, unsigned long size, unsigned long offset) { - return _find_next_bit(addr, NULL, size, offset, 0UL, 1); + return _find_next_bit(addr, NULL, size, offset, 0UL, FNB_AND, 1); } EXPORT_SYMBOL(find_next_bit_le); #endif -- 2.28.0.220.ged08abb693-goog