From nobody Sun Feb 8 08:27:34 2026 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8D5278F34 for ; Fri, 17 Jan 2025 14:27:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737124027; cv=none; b=YBKHIZcLkLMSqL6vbwXRu2jF3pYsZa4cAmOB7aRayt1h0Dm6HKWDq+nSlYdarrpjkQ2PKDZ3GxUlfCD+Z/CmWu1nFAukUdvDpai/m6JlEAG4Gh2xpnkruuah17hHJFoycVzfqwOIZjFRP5vXcOFPU6GsoeutCH1DBS3sz9i0G3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737124027; c=relaxed/simple; bh=uQXVhIWWq9pnBsrBB9j3Qi0tl2cwfBCXIM42jKN/KGk=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=JPMfbZu8DzTWP10AbsYSjkpuF4t6dTenvg354Fc1R8brkGSXK2kkIPd4ZaSW2SP9LEzVLkl96lpEsThvLPQYAPynG5bBJocHEA/ZRFU+vtMiSCfy7/UvgKWuTt7ilypqrCK/0OxiJz1NIOftRFjxw9UV6TuBAc/WYzi8X5Q1qNo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nWfYHMwE; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nWfYHMwE" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-216401de828so39896995ad.3 for ; Fri, 17 Jan 2025 06:27:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1737124025; x=1737728825; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=SbIm73+NIMigv6i1bsHTQ/rCOwqOkBgqTGxrJbjfOO8=; b=nWfYHMwEtnxUSQGgB/aiOQwKpcDCoYm042AG5ccD2yojYslmK+h8/DicYYT0AzQz4u a4TtIYuz6iM/wYy7lcB48NXtFZrxFSrV4Im3XScD5IkfxytdmKJZfuxMniHVXcTPwjMG mW3GRcqo8I7bprp0eCj1tftoT1M8YboCyrEm7ZSMllQ85qF6vL4VtjRfi+lNf+HrhN5m Fi/W59UbY/F9mV7BIlJ2e4cN9S4l4PCZ/rDf7ItQZBO69gbIxivIgLY/QRzqD27V8sJw ijPMPsAbya4SpMPuLbQVUkDIB90GJqH+qqt/k+3upvi5fLR2Kwgp1MettTTcU9mz3t5n +RqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1737124025; x=1737728825; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=SbIm73+NIMigv6i1bsHTQ/rCOwqOkBgqTGxrJbjfOO8=; b=ZFpaFHWMZQ0eKNQOlqLtqSjr/3wqaDOvmEt6WARhSeQOa2aumWhjWHr6hbLq9InExf TXeFgxceytKHSmkIkFSot2pvPkKBHqTgn/srkEL/WdBpJZquLjx5zQDsLrcp2fHgWd9f QsRvx8gETFY15Ws5kdawHZ3BKIzdpqJj3KrE6Alm0IMgkHlmGsc/XrWjcOdgqciOg3vR 8gq0ZKMYVRq8jXcIDqwNXdD9cGla2NdxnFtll+AXq5dkc0wTPQB+7CAvQ/HL3qeDtD0t iqFjXbt5M+qc33GeSI9WfBYrfIH23xKy3SJ1tTJSlwLDYihH0B1meeAvS5zgI1xnPyvc EzGw== X-Forwarded-Encrypted: i=1; AJvYcCXhL5/tofahTFFd6rV3secYOTS6dLkWZd78sr9Fg+B8y9z4+8mktS+BPEOtoDYqwcwIrkhTwji3zT6MYLw=@vger.kernel.org X-Gm-Message-State: AOJu0YzTY/WTNNALzYfwIrxbZdMCcz0x0QuEgnJdRlDksJhCHGhwko8c kSCOlRDjzgWr8LvmPredZlSACrMFCIWjh2Njs7tHrhoRuySzYN01 X-Gm-Gg: ASbGnctIy6ukBUjdi/fTwasQKsRQdkcDTECXBrTH6xR4eA1cPk6DxHhxD0whkvKA52H pq9iD+2sxvNCbt+p0jP+d8jSlmBH7z6zg3+epkienGMEYWpbxEgvByEaDvPUuig50qFf15Mwf9f 5ABixPjVik0yEY06dL9z2LS6Ae3daQcpMWIlulHPsmXW4dVyU6r11B0tmFyqk7hCg5gDULbkyOl 8+ubk/r/YmFWnZbfcJtcL03iL5nWmUY6zSivvmZ4A4RPZ/XRjtOlaWWGWwm7qy9X0LCLdNwD1iM RgoHeofsf2s= X-Google-Smtp-Source: AGHT+IFJgCYGsKvIByWTbBHkIUGFEHRqE6ld+HyC3jB5eXiQjDH/1/2vGJT9590AB5UtzPzkt+KjVw== X-Received: by 2002:a17:902:cf0b:b0:216:3436:b87e with SMTP id d9443c01a7336-21c355cc207mr55313075ad.44.1737124024895; Fri, 17 Jan 2025 06:27:04 -0800 (PST) Received: from visitorckw-System-Product-Name.. ([140.113.216.168]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21c2ce9ff2esm16698475ad.12.2025.01.17.06.27.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jan 2025 06:27:04 -0800 (PST) From: Kuan-Wei Chiu To: yury.norov@gmail.com Cc: linux@rasmusvillemoes.dk, richard120310@gmail.com, jserv@ccns.ncku.edu.tw, mark.rutland@arm.com, linux-kernel@vger.kernel.org, Kuan-Wei Chiu , Yu-Chun Lin Subject: [PATCH] cpumask: Optimize cpumask_any_but() Date: Fri, 17 Jan 2025 22:26:58 +0800 Message-Id: <20250117142658.297325-1-visitorckw@gmail.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The cpumask_any_but() function can avoid using a loop to determine the CPU index to return. If the first set bit in the cpumask is not equal to the specified CPU, we can directly return the index of the first set bit. Otherwise, we return the next set bit's index. This optimization replaces the loop with a single if statement, allowing the compiler to generate more concise and efficient code. As a result, the size of the bzImage built with x86 defconfig is reduced by 4096 bytes: * Before: $ size arch/x86/boot/bzImage text data bss dec hex filename 13537280 1024 0 13538304 ce9400 arch/x86/boot/bzIma= ge * After: $ size arch/x86/boot/bzImage text data bss dec hex filename 13533184 1024 0 13534208 ce8400 arch/x86/boot/bzIma= ge Co-developed-by: Yu-Chun Lin Signed-off-by: Yu-Chun Lin Signed-off-by: Kuan-Wei Chiu --- Not sure how to measure the efficiency difference, but I guess this patch might be slightly more efficient or nearly the same as before. If you have any good ideas for measuring efficiency, please let me know! include/linux/cpumask.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h index 9278a50d514f..b769fcdbaa10 100644 --- a/include/linux/cpumask.h +++ b/include/linux/cpumask.h @@ -404,10 +404,10 @@ unsigned int cpumask_any_but(const struct cpumask *ma= sk, unsigned int cpu) unsigned int i; =20 cpumask_check(cpu); - for_each_cpu(i, mask) - if (i !=3D cpu) - break; - return i; + i =3D find_first_bit(cpumask_bits(mask), small_cpumask_bits); + if (i !=3D cpu) + return i; + return find_next_bit(cpumask_bits(mask), small_cpumask_bits, i + 1); } =20 /** --=20 2.34.1