Received: by 2002:ab2:6203:0:b0:1f5:f2ab:c469 with SMTP id o3csp420750lqt; Thu, 18 Apr 2024 22:33:00 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXaCEvxJFO5+4vV7CK9wUjfTgH24os3zx3+Y4LBxXcdQ0BJ3dBLq2TJRsRdn2KBHOqsMOafN27QxBwVbKADZ3ZV7InnXgiPmwNcXKgySg== X-Google-Smtp-Source: AGHT+IFLsxgFx67VQ8JDDZ8XSgUoxTlCli/SMYR0A7vu1dTwbM2ncZBuV7e9p924n6UYJ0dxNlGx X-Received: by 2002:a17:902:f70f:b0:1e8:ccef:9c0f with SMTP id h15-20020a170902f70f00b001e8ccef9c0fmr1220380plo.20.1713504780078; Thu, 18 Apr 2024 22:33:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713504780; cv=pass; d=google.com; s=arc-20160816; b=PY81dXNT8gpr/ToCBqsW4I38CBO9ZD+KbxzXLqppQ4iNCrD/Sfma8gj9ftbTd4vVDN ElJQIWxvAcEYc44yJXmA8fbr3Vk/5gBPHdlzcgs6Grne36LDXgSrmDW3n8eHQZaD7iWV u6Cq6MDlBEFBUTDYcdVh1lsaqHNLxgADhuAFAkqYpVGDQkq8AxKy0xRZi1oaDuB5H6xx Epj55Gzy8DpspYJz024FNJLdJ3YOtXo8jrwwPZb8dJjQt5j6FH0gkvkjAx1mF3McydWg ybHwQY5313wFLg+XSDwE4xYfykojwcB4AmnME6LD6oiFcxFu/+cEpSOvTsXI1yK1i+u9 1TxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:in-reply-to:subject:cc:to:dkim-signature :dkim-signature:from; bh=Nb8+/9xalraZGLP1jk5h6zvK+UIIvcAHinrH+94E1xA=; fh=8quHhK5UPqAQb9983NbPjzZdQoO3zb+Ae6y9SLhUxiU=; b=v3r5Vk19AVG1t5u8p6jDEnGeHDJq03REvxkQXYgSK6OGe/ghMo580Ys8HP4nERy9Hw PIbcLALCmm9BhpUNtpuKqf/XlVpKu3A5Fk/yAuev4b0u7HDIYAQxldoqjP4Hp1eCUHaM WykekJde+R6CdU/CjqdobCgDDyU7DMgVX6WaMkLm5vAQQcBeZNtSHDKhCt9pbdlBKl/c 6hdfRPBSBXuFg5JKtBpRS2ovhmbmBZh5ALFFaC1Jm7+RxjdOy7ponqqP3tS42/mJGx5p 9ss3qvHjClxTs4fkKTwRFA7xRLrCkYUjdhXnTX8+KNs/1CncDq/LKq1/n0TY+DVwtQzk 8jMA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="I/vOOf//"; dkim=neutral (no key) header.i=@linutronix.de; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-151013-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151013-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id p1-20020a170902e74100b001e3e64ed055si2733107plf.624.2024.04.18.22.32.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 22:33:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-151013-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="I/vOOf//"; dkim=neutral (no key) header.i=@linutronix.de; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-151013-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-151013-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8EF0D28504F for ; Fri, 19 Apr 2024 05:32:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8BDE5BA31; Fri, 19 Apr 2024 05:32:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="I/vOOf//"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="jeE955Xm" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 612CC748E for ; Fri, 19 Apr 2024 05:32:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713504773; cv=none; b=XgCjrYw1YYFnl+n+vpdQKmAoKcGaiFyY4U+ebsYNDBigFVUG9IcO5t6xO7pRmTs8aziDWwuxj+0c8RoLL0idSZd9HPYc0HQ+XLqLoL8JaiyI0cn6DEz9SivPOgcoszQXsPVEWzSuMO5Q+s2q9ZtClcIlmtrP7sT1TPtbpDcFZhQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713504773; c=relaxed/simple; bh=tuDYbVXL8Fha/njy5SFGrSPhj94DhUTTeOjcn1j8YEI=; h=From:To:Cc:Subject:In-Reply-To:Date:Message-ID:MIME-Version: Content-Type; b=TaDn3lC+Pyv5htlWBszFIy8+2s2UuUMkDBDdQG5o4pivFVojFHG+KztxjdMx3chZfwDyKX5Turs1BHaGbpUjk5W1D0J+jw0I3/VPkj0oJbpGwbqQB0Wk9tUWLFRIIkfBrJ3beDl5jtcbij8X7l/o9/ww/IWgCkCMaVu/9wP1EdY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=I/vOOf//; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=jeE955Xm; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de From: Thomas Gleixner DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1713504770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=Nb8+/9xalraZGLP1jk5h6zvK+UIIvcAHinrH+94E1xA=; b=I/vOOf///FF7BJ5TQcjgQ0rC/mQnk+tNg8vUPcF1ga9dg+pMCdLb1KKbKTQ+yqPLP97Gum Xo6AZsZNM55cL4+8r13/c1Jt/YyR+l3zECQvE4HFA4a2QFDbQQkJVrBTSRfkzKLHaLELt/ XFW7PEYR01Slpd/bfyl8zrz2g3K2JZCmgxrhfmhDpQWK69/FWrAJ2/ZdlOBTrMri+pMFNM qIYMPEE8yQ4iStw5idzpDHTuG1mvzWBhjvX/ECLBP2h12KrTFBUXyf7Wbe703L2YC1/LP/ 3tgsgHT8URt3Sramh2gf9OqCkboZoIScKx3VOJm5gDDser5mk1ezIvjVttWSIQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1713504770; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=Nb8+/9xalraZGLP1jk5h6zvK+UIIvcAHinrH+94E1xA=; b=jeE955XmubM1zgYFBeZuLUAVsiKAwLfD6nD+A/OmERb5W4cPua3eom1tMAIZa8jAcCo1mm 3JJGGRBobn+NgFCQ== To: Alexey Dobriyan , peterz@infradead.org Cc: adobriyan@gmail.com, yury.norov@gmail.com, linux@rasmusvillemoes.dk, akpm@linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] cpu: memoise number of possible cpus In-Reply-To: <20240418041927.3903-1-adobriyan@gmail.com> Date: Fri, 19 Apr 2024 07:32:43 +0200 Message-ID: <8734rhyl1g.ffs@tglx> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On Thu, Apr 18 2024 at 07:19, Alexey Dobriyan wrote: memoise? > cpu_possible_mask is fixed after boot, so it makes sense > to calculate number of possible cpus to The kernel calculates the number of possible CPUs already today, no? > a) make num_possible_cpus() faster (distros ship with _large_ NR_CPUS), > b) unscrew codegen elsewhere replacing function call > with simple memory load. Can we please have complete sentences which use precise technical wording to describe the changes? > diff --git a/init/main.c b/init/main.c > index 881f6230ee59..fe0291b44d78 100644 > --- a/init/main.c > +++ b/init/main.c > @@ -904,6 +904,9 @@ void start_kernel(void) > setup_boot_config(); > setup_command_line(command_line); > setup_nr_cpu_ids(); > +#if NR_CPUS > 1 > + num_possible_cpus = cpumask_weight(cpu_possible_mask); > +#endif setup_nr_cpu_ids() does exactly the same thing despite using a different algorithm. So why not do the obvious and have: #define num_possible_cpus() nr_cpu_ids and make nr_cpu_ids __ro_after_init? Which made me look at CONFIG_FORCE_NR_CPUS. That's simply broken because: static inline void set_nr_cpu_ids(unsigned int nr) { #if (NR_CPUS == 1) || defined(CONFIG_FORCE_NR_CPUS) WARN_ON(nr != nr_cpu_ids); #else nr_cpu_ids = nr; #endif } So if num_possible_cpus() != nr_cpu_ids then everything after that becomes lottery. If that hard-coded NR_CPUS is actually worth it then this WARN_ON() is just wrong. The only sensible solution to that is to make it a BUG_ON(). Thanks, tglx