From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail.linutronix.de (146.0.238.70:993) by crypto-ml.lab.linutronix.de with IMAP4-SSL for ; 12 Jun 2018 10:31:58 -0000 Received: from smtp.eu.citrix.com ([185.25.65.24]) by Galois.linutronix.de with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1fSgaj-0004xE-KN for speck@linutronix.de; Tue, 12 Jun 2018 12:31:57 +0200 Subject: [MODERATED] Re: [patch V2 02/12] x86/smp: Provide topology_is_primary_thread() References: <20180606192714.754943543@linutronix.de> <20180606192807.093672737@linutronix.de> <20180611193245.GB25607@char.us.oracle.com> From: Andrew Cooper Message-ID: <1fce67a1-7eb8-7d08-6d0c-e97309cb5fff@citrix.com> Date: Tue, 12 Jun 2018 11:31:50 +0100 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit Content-Language: en-GB To: speck@linutronix.de List-ID: On 12/06/18 09:05, speck for Thomas Gleixner wrote: > On Mon, 11 Jun 2018, speck for Konrad Rzeszutek Wilk wrote: >> On Wed, Jun 06, 2018 at 09:27:16PM +0200, speck for Thomas Gleixner wrote: >> Anyhow if we did have four siblings, the mask would end up with 11b >> (see below): >> >> smp_num_siblings fls -1 1<< -1 >> 1 (001b) 1 0 1 0 >> 2 (010b) 2 1 2 01b >> 4 (100b) 3 2 4 11b > That's what I intended :) > >>> + return !(apicid & mask); >> So with an normal 2-sibling, say APICID 0x76 and 0x77 with mask 1b: >> >> 0x76 01110110b & 01 -> !0 -> return 1 >> 0x77 01110111b & 01 -> !1 -> return 0 >> >> that looks good. >> >> If this is a 4 thread. APICID 0x4, 0x5, and 0x6 >> >> 0x4 0100 & 11b -> 00 -> !0 -> return 1 >> 0x5 0101 & 11b -> 01 -> !1 -> return 0 >> 0x6 0110 & 11b -> 10 -> !1111..1101 -> return 0xffff..which cast to bool is 'true' [BAD] >> >> That is the 3rd sibling would be incorrectly identified as primary thread. >> >> I think? I would welcome somebody checking my logic over, but then >> perhaps this is non-issue-b/c-we-don-do more than 2 so go away. > You are somehow confusing '!' and '~' The original logic looks correct to me, and matches my equivalent in Xen. ~Andrew