From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 960672DF132 for ; Wed, 25 Feb 2026 16:40:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.92.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772037654; cv=none; b=RkEgspf9tSU2m/oFCC6eHOupDPc+ict+5FwtlgZUSJ6+709ErXYZ2utt5AUSaIafs/0tSic0VPNTlDfy3txuEH57URYSdwBGnpiIGsDgfGOa+dma067UuO6cd0WxYieEqQs0KR3ODco4P1/XSB1RnVg0rIKP279ES72cYusyWUk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772037654; c=relaxed/simple; bh=BTImDwZ78yAOwl9qFqp+oodQNWSBjPYLW9uF+bqHeHM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=maa66T66MTncD9FDY6cQLBZ1jbY2qpFAeDAEJ5n9fBuq7qAL4DMYww+yPBfNuHZtN3Vk2QUtXLJkjj4UVuR4cO9rgmS4I05N5MGTyNv6MlDn6tAjjWaXR5u/S1rrPFT/lqwI4G5XTHcvnZ8S9u3t9MCN2uYKkwulBSfV0+Y/n3I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=bahqn1sS; arc=none smtp.client-ip=90.155.92.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="bahqn1sS" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=L2JszRQ3ucEDBeRQ+HZBnmo+ZA4zwDcBiKpONUDGhcE=; b=bahqn1sS8rN0IerDtfn++SQ1jT 3ZE1nKAsvOTZf5TewjDGK5pwDqLwQ3v9zppGlsy+2y2Q8f/LmKezo5yxC1w2vpU0Sr1jnXlY4vuuR zkT8fxJMEEresPfNAUY66A6bONSraYpBOhgBhpNsxCvU0SGj2HJEg6tZ0NEFi547jC8np/iCgs+Pw gKWmNntDvRJ083tBbFeFYx+bSlL/DubbrLOxIMBUjBIGkzcsN/eeXGD/c11e2/c2IyTeEx1chK70V 8+gjSKbHmX7CkynngzhJ8TXyreyxaPYg+rFEJLRT9WodqS3QMJJXwWGJfy/YGQNsRwjN7jUcRA/la Nq03NEPA==; Received: from 77-249-17-252.cable.dynamic.v4.ziggo.nl ([77.249.17.252] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.98.2 #2 (Red Hat Linux)) id 1vvHwG-00000009SG5-2IrQ; Wed, 25 Feb 2026 16:40:40 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id 9FA84301BD5; Wed, 25 Feb 2026 17:40:34 +0100 (CET) Date: Wed, 25 Feb 2026 17:40:34 +0100 From: Peter Zijlstra To: "Chen, Yu C" Cc: Kyle Meyer , tim.c.chen@linux.intel.com, bp@alien8.de, dave.hansen@linux.intel.com, mingo@redhat.com, tglx@kernel.org, vinicius.gomes@intel.com, brgerst@gmail.com, hpa@zytor.com, kprateek.nayak@amd.com, linux-kernel@vger.kernel.org, patryk.wlazlyn@linux.intel.com, rafael.j.wysocki@intel.com, russ.anderson@hpe.com, x86@kernel.org, zhao1.liu@intel.com Subject: Re: [PATCH v2] sched/topology: Check average distances to remote packages Message-ID: <20260225164034.GY1395416@noisy.programming.kicks-ass.net> References: <20260223170314.GU1395266@noisy.programming.kicks-ass.net> <20260225123052.GN3016024@noisy.programming.kicks-ass.net> <20260225154409.GD1282955@noisy.programming.kicks-ass.net> <20260225163246.GX1395416@noisy.programming.kicks-ass.net> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260225163246.GX1395416@noisy.programming.kicks-ass.net> On Wed, Feb 25, 2026 at 05:32:46PM +0100, Peter Zijlstra wrote: > +static bool slit_cluster_symmetric(int i, int j, int n) > { > + WARN_ON_ONCE((i % n) || (j % n)); > > + for (int k = i; k < i + n; k++) { > + for (int l = k; l < j + n; l++) { > + if (node_distance(k, l) != node_distance(k, l)) > + return false; > } > } > > + return true; > +} > + > +static bool slit_cluster_match(int i, int j, int x, int y, int n) > +{ > + WARN_ON_ONCE((i % n) || (j % n) || (x % n) || (y % n)); > + > + for (int k = 0; k < n; k++) { > + for (int l = k; l < n; l++) { > + if (node_distance(i + k, j + l) != node_distance(x + k, y + l)) > + return false; > + } > + } > + > + return true; > +} > + > +/* > + * Find the largest symmetric,repeating cluster in an attempt to identify the > + * unit size. > + */ > +static int slit_cluster_size(void) > +{ > + int nodes = num_possible_nodes(); > + > + /* > + * There are at least 2 packages; so half-nodes is the largest > + * possible unit, go down from that. > + */ > + for (int u = nodes / 2; u; u--) { nodes / topology_max_packages() might also do. And I worry about num_possible_nodes(), if that includes CXL or other such nonsense then we're up a creek. But as stated before, ideally the hardware can actually just tell us the right number. > + /* > + * If u doesn't divide nodes, it can't be a unit. > + */ > + if (nodes % u) > + continue; > + > + /* > + * Unit must be symmetric, > + */ > + if (!slit_cluster_symmetric(0, 0, u)) > + continue; > + > + /* > + * and repeating. > + */ > + if (slit_cluster_match(0, 0, u, u, u)) > + return u; > + } > + > + return nodes; > +} > + > +static int slit_cluster_distance(int i, int j) > +{ > + static int u = 0; > + long d = 0; > + int x, y; > + > + if (!u) > + u = slit_cluster_size(); > + > + /* > + * Is this a unit cluster on the trace? > + */ > + if ((i / u) == (j / u)) > + return node_distance(i, j); > + > + /* > + * Off-trace cluster, return average of the cluster to force symmetry. > + */ > + x = i - (i % u); > + y = j - (j % u); > + > + for (i = x; i < x + u; i++) { > + for (j = y; j < y + u; j++) { > + d += node_distance(i, j); > + d += node_distance(j, i); > + } > + } > + > + return d / (2*u*u); > } Note that I changed this to average over the symmetric pair of off-trace clusters. Because if some BIOS monkey is really taking bong-hits, there is absolutely no guarantee the just the one cluster average will result in a symmetric system in the end.