Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4509964imm; Fri, 18 May 2018 06:22:08 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrR+5AEzSwWELSVNXnBfpBWOnk0FSBiojmprSVRs2LyMy1HTRMU3RKKx9vW6xUp041U95gP X-Received: by 2002:a62:399c:: with SMTP id u28-v6mr9440731pfj.95.1526649728231; Fri, 18 May 2018 06:22:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526649728; cv=none; d=google.com; s=arc-20160816; b=Ir8CL3+VQTf2d6DyD/PNA3HY3G0zm5GJFy9PLUlsVtdFHg4DL5QyawuUG6obYzDsPc ohPuVlu9hAjZtASWwnyMW9a1E3uH63Hqu+Ej3FOjtQznlx1/woxoH9k5v9XsMT/EB+iF PK4ksuRg7g4dBPmOZKvEYQnUToxNZpKviJ17IYgxJzHCV4QdIBb53JfRNIwl5n5k/2k8 rThiasdQmED29y9dRuTUZoyPLm2XxCpgXPJyn3LX9BBZlpThhR/erO0wBQ+ZyZwqu8m+ wrw39Z1Re9lJPmdXb+OeKpGbkdx2q619ZzDlzHYVkVzSk3ASVI/HgEDr5TdYn4UD9qQR FmJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:arc-authentication-results; bh=zy0wQ3qcYON+n1VcjWo9ukz/9II7BBE+WoCy5MW3TwE=; b=Zoy786Oe+1CIDUl3LkVpgqyRZ3GznVKSQ5fMKabSuHjMJuSxc7ZMAXtcYUjohdmMIx 8cSUI4utuxbaLF3mV3XlEHD++xHtFzcYTIAtEYiWKQo4mpgYNHLpzCfJbsopY+BoccxS weuAYkALZ2v5h8R3bzMeVUyIehU3+nm9/GBOaQ+zRpBzxEZQnJgCzW2XU09qLzgvJVFb y0LTzwSsHa+pnPh0jDTFJ1KAWyuI5XDc1K3pznUzFG1/m8Fju6M00zEvK7ZHVBQxATHA rE4oHflUE6wZTSEsHU3DUml+FXCbf/jPEszATSwyElUHsGqU7Tuz8Ddj54oV5T+RSL/8 ZSkw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 61-v6si7318184plz.290.2018.05.18.06.21.54; Fri, 18 May 2018 06:22:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752407AbeERNVZ (ORCPT + 99 others); Fri, 18 May 2018 09:21:25 -0400 Received: from ozlabs.org ([203.11.71.1]:44369 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751601AbeERNVY (ORCPT ); Fri, 18 May 2018 09:21:24 -0400 Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPSA id 40nTMk3rqMz9s0y; Fri, 18 May 2018 23:21:22 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ellerman.id.au From: Michael Ellerman To: "Gautham R. Shenoy" , Benjamin Herrenschmidt , Michael Neuling , Vaidyanathan Srinivasan , Akshay Adiga , Shilpasri G Bhat , Balbir Singh , Oliver O'Halloran , Nicholas Piggin Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, "Gautham R. Shenoy" Subject: Re: [PATCH 1/2] powerpc: Detect the presence of big-core with interleaved threads In-Reply-To: <1526037444-22876-2-git-send-email-ego@linux.vnet.ibm.com> References: <1526037444-22876-1-git-send-email-ego@linux.vnet.ibm.com> <1526037444-22876-2-git-send-email-ego@linux.vnet.ibm.com> Date: Fri, 18 May 2018 23:21:22 +1000 Message-ID: <87h8n5xfot.fsf@concordia.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org "Gautham R. Shenoy" writes: > diff --git a/arch/powerpc/kernel/setup-common.c b/arch/powerpc/kernel/setup-common.c > index 0af5c11..884dff2 100644 > --- a/arch/powerpc/kernel/setup-common.c > +++ b/arch/powerpc/kernel/setup-common.c > @@ -436,8 +438,56 @@ static void __init cpu_init_thread_core_maps(int tpc) > printk(KERN_DEBUG " (thread shift is %d)\n", threads_shift); > } > > - > u32 *cpu_to_phys_id = NULL; > +/* > + * check_for_interleaved_big_core - Checks if the core represented by > + * dn is a big-core whose threads are interleavings of the > + * threads of the component small cores. > + * > + * @dn: device node corresponding to the core. > + * > + * Returns true if the core is a interleaved big-core. > + * Returns false otherwise. > + */ > +static inline bool check_for_interleaved_big_core(struct device_node *dn) > +{ > + int len, nr_groups, threads_per_group; > + const __be32 *thread_groups; > + __be32 *thread_list, *first_cpu_idx; > + int cur_cpu, next_cpu, i, j; > + > + thread_groups = of_get_property(dn, "ibm,thread-groups", &len); > + if (!thread_groups) > + return false; There are better device tree APIs than bare of_get_property() these days, can you try to use those? > + nr_groups = be32_to_cpu(*(thread_groups + 1)); > + if (nr_groups <= 1) > + return false; eg. this would be of_property_read_u32_index() > + > + threads_per_group = be32_to_cpu(*(thread_groups + 2)); > + thread_list = (__be32 *)thread_groups + 3; > + > + /* > + * In case of an interleaved big-core, the thread-ids of the > + * big-core can be obtained by interleaving the the thread-ids > + * of the component small > + * > + * Eg: On a 8-thread big-core with two SMT4 small cores, the > + * threads of the two component small cores will be > + * {0, 2, 4, 6} and {1, 3, 5, 7}. > + */ > + for (i = 0; i < nr_groups; i++) { > + first_cpu_idx = thread_list + i * threads_per_group; > + > + for (j = 0; j < threads_per_group - 1; j++) { > + cur_cpu = be32_to_cpu(*(first_cpu_idx + j)); > + next_cpu = be32_to_cpu(*(first_cpu_idx + j + 1)); > + if (next_cpu != cur_cpu + nr_groups) > + return false; > + } > + } > + return true; > +} > > /** > * setup_cpu_maps - initialize the following cpu maps: > @@ -565,7 +615,16 @@ void __init smp_setup_cpu_maps(void) > vdso_data->processorCount = num_present_cpus(); > #endif /* CONFIG_PPC64 */ > > - /* Initialize CPU <=> thread mapping/ > + dn = of_find_node_by_type(NULL, "cpu"); > + if (dn) { > + if (check_for_interleaved_big_core(dn)) { > + has_interleaved_big_core = true; > + pr_info("Detected interleaved big-cores\n"); > + } > + of_node_put(dn); > + } This is a bit untidy, given how unlikely it is that you would have no CPUs :) You should be able to do the lookup of the property and the setting of has_interleaved_big_core all inside check_for_interleaved_big_core(). cheers