From nobody Mon Feb 9 03:30:03 2026 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (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 C2F039476; Tue, 22 Apr 2025 08:44:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745311457; cv=none; b=qo+cVDVZ3murZYLLoIILSb6yDDN1WeIEie3M1TXk29DQ6SNj1H48rFmSj4P6zvRZxrQuy5j7lHHQTJCEv9It/ph9Sk6n6RO6wwp50q2INum9fQwMpw5NG1TM6QICN8B95r3/a2MH6h0KxeO9C2/Cg8rPiH/MMmoyIN8orcvhwbI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745311457; c=relaxed/simple; bh=NzKe9UFTjTcgyyRELTbJXX7B1r0GpqU+ALJBfKhlEic=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DAWyIm56fPGmWI7cg5RWQgLyoGTjwRAthLTC2dKHqME3EjGavoFK9T10LwagUbIoxZN9jNyFJ14e/OAsRv2qzxqyOZbQuZVrVKIy52vo4me7zQBg3jvjm5f+ZUskcZ1I/dsrmkXjmTHh9n04N6+z6H2LlIz3Zqxc2eySR4jgF4M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4ZhbMs6ydyz6L530; Tue, 22 Apr 2025 16:42:33 +0800 (CST) Received: from frapeml500003.china.huawei.com (unknown [7.182.85.28]) by mail.maildlp.com (Postfix) with ESMTPS id 9B2A51401F3; Tue, 22 Apr 2025 16:44:13 +0800 (CST) Received: from a2303103017.china.huawei.com (10.47.65.221) by frapeml500003.china.huawei.com (7.182.85.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 22 Apr 2025 10:44:13 +0200 From: Alireza Sanaee To: CC: , , , , , , Subject: [PATCH v1 1/5] DT: add infra for finding CPU id from phandle. Date: Tue, 22 Apr 2025 09:43:36 +0100 Message-ID: <20250422084340.457-2-alireza.sanaee@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250422084340.457-1-alireza.sanaee@huawei.com> References: <20250422084340.457-1-alireza.sanaee@huawei.com> 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 X-ClientProxiedBy: lhrpeml500010.china.huawei.com (7.191.174.240) To frapeml500003.china.huawei.com (7.182.85.28) Content-Type: text/plain; charset="utf-8" Get CPU id from phandle. Many drivers get do this by getting hold of CPU node first through a phandle and then find the CPU ID using the relevant function. This commit encapsulates cpu node finding and making driver code easier to cleaner. The API interface requires three parameters, 1) node, 2) pointer to CPU node, and 3) property which includes the phandle. API sets the pointer to the CPU node and allows the driver to play with the CPU itself, for logging purposes for instance. --- drivers/of/cpu.c | 40 ++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 3 +++ 2 files changed, 43 insertions(+) diff --git a/drivers/of/cpu.c b/drivers/of/cpu.c index 5214dc3d05ae..c2d729999a4e 100644 --- a/drivers/of/cpu.c +++ b/drivers/of/cpu.c @@ -173,6 +173,46 @@ int of_cpu_node_to_id(struct device_node *cpu_node) } EXPORT_SYMBOL(of_cpu_node_to_id); =20 +/** + * of_cpu_phandle_to_id: Get the logical CPU number for a given device_node + * + * @node: Pointer to the device_node containing CPU phandle. + * @cpu_np: Pointer to the device_node for CPU. + * @prop: String of property holding the phandle. + * + * Return: The logical CPU number of the given CPU device_node or -ENODEV = if + * the CPU is not found. If the property is not found, it returns -1. On + * success, cpu_np will always point to the retrieved CPU device_node. + */ +int of_cpu_phandle_to_id(const struct device_node *node, + const struct device_node *cpu_np, + const char * prop) +{ + bool found =3D false; + int cpu, ret; + struct device_node *np; + struct of_phandle_args args; + + if (!node || !prop) + return -1; + + ret =3D of_parse_phandle_with_args(node, prop, NULL, 0, &args); + if (ret < 0) + return ret; + + cpu_np =3D args.np; + for_each_possible_cpu(cpu) { + np =3D of_cpu_device_node_get(cpu); + found =3D (cpu_np =3D=3D np); + of_node_put(np); + if (found) + return cpu; + } + + return -ENODEV; +} +EXPORT_SYMBOL(of_cpu_phandle_to_id); + /** * of_get_cpu_state_node - Get CPU's idle state node at the given index * diff --git a/include/linux/of.h b/include/linux/of.h index eaf0e2a2b75c..5e51e57478b1 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -360,6 +360,9 @@ extern const void *of_get_property(const struct device_= node *node, extern struct device_node *of_get_cpu_node(int cpu, unsigned int *thread); extern struct device_node *of_cpu_device_node_get(int cpu); extern int of_cpu_node_to_id(struct device_node *np); +extern int of_cpu_phandle_to_id(const struct device_node *np, + const struct device_node *cpu_np, + const char *propname); extern struct device_node *of_get_next_cpu_node(struct device_node *prev); extern struct device_node *of_get_cpu_state_node(const struct device_node = *cpu_node, int index); --=20 2.43.0 From nobody Mon Feb 9 03:30:03 2026 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (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 E4CA726159B; Tue, 22 Apr 2025 08:44:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745311491; cv=none; b=ZlBN2uAUEZMttbWJRpW5QdslxYJ2ef6PDPX4or5ac/eyqFrd19pYAOmucFtQmRNTBuApEILUhBADNaPWh8DMzyggqAslxLjhDI2EfgYLjFPrYq2GE7FPgMBebhbcmnIf8xbHcpApczu3vm9A/govyC4yzsNxldp1c4q3h1MLY9g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745311491; c=relaxed/simple; bh=I86OdE3kOZHcryMKY1mnL6NG++435v7MmEkzYpOOFJo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=okTtF8F90IJDws/B6DPGXOR4s8Z3p+5hEaA1THmwpDrybHErOi46vl0G/qLZe1gh3KK5OiLExEeR+eqcEBBYbmXzYXBF/vnkKDwFaO9T6Nq7PxIzDmRFkF8Z30bXlQp9ocORujOtx+B0biAWlgLb6dT9NNqkfsDrQRnEIrBJdME= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4ZhbKD3xXpz6K9Nf; Tue, 22 Apr 2025 16:40:16 +0800 (CST) Received: from frapeml500003.china.huawei.com (unknown [7.182.85.28]) by mail.maildlp.com (Postfix) with ESMTPS id 54833140594; Tue, 22 Apr 2025 16:44:47 +0800 (CST) Received: from a2303103017.china.huawei.com (10.47.65.221) by frapeml500003.china.huawei.com (7.182.85.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 22 Apr 2025 10:44:46 +0200 From: Alireza Sanaee To: CC: , , , , , , Subject: [PATCH v1 2/5] arm64: of: handle multiple threads in ARM cpu node Date: Tue, 22 Apr 2025 09:43:37 +0100 Message-ID: <20250422084340.457-3-alireza.sanaee@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250422084340.457-1-alireza.sanaee@huawei.com> References: <20250422084340.457-1-alireza.sanaee@huawei.com> 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 X-ClientProxiedBy: lhrpeml500010.china.huawei.com (7.191.174.240) To frapeml500003.china.huawei.com (7.182.85.28) Content-Type: text/plain; charset="utf-8" Update `of_parse_and_init_cpus` to parse reg property of CPU node as an array based as per spec for SMT threads. Spec v0.4 Section 3.8.1: The value of reg is a that defines a unique CPU/thread id for the CPU/threads represented by the CPU node. **If a CPU supports more than one thread (i.e. multiple streams of execution) the reg property is an array with 1 element per thread**. The address-cells on the /cpus node specifies how many cells each element of the array takes. Software can determine the number of threads by dividing the size of reg by the parent node's address-cells. An accurate example of 1 core with 2 SMTs: cpus { #size-cells =3D <0x00>; #address-cells =3D <0x01>; cpu@0 { phandle =3D <0x8000>; **reg =3D <0x00 0x01>;** enable-method =3D "psci"; compatible =3D "arm,cortex-a57"; device_type =3D "cpu"; }; }; Instead of: cpus { #size-cells =3D <0x00>; #address-cells =3D <0x01>; cpu@0 { phandle =3D <0x8000>; reg =3D <0x00>; enable-method =3D "psci"; compatible =3D "arm,cortex-a57"; device_type =3D "cpu"; }; cpu@1 { phandle =3D <0x8001>; reg =3D <0x01>; enable-method =3D "psci"; compatible =3D "arm,cortex-a57"; device_type =3D "cpu"; }; }; which is **NOT** accurate. Signed-off-by: Alireza Sanaee --- arch/arm64/kernel/smp.c | 74 +++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 33 deletions(-) diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 3b3f6b56e733..8dd3b3c82967 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -689,53 +689,61 @@ static void __init acpi_parse_and_init_cpus(void) static void __init of_parse_and_init_cpus(void) { struct device_node *dn; + u64 hwid; + u32 tid; =20 for_each_of_cpu_node(dn) { - u64 hwid =3D of_get_cpu_hwid(dn, 0); + tid =3D 0; =20 - if (hwid & ~MPIDR_HWID_BITMASK) - goto next; + while (1) { + hwid =3D of_get_cpu_hwid(dn, tid++); + if (hwid =3D=3D ~0ULL) + break; =20 - if (is_mpidr_duplicate(cpu_count, hwid)) { - pr_err("%pOF: duplicate cpu reg properties in the DT\n", - dn); - goto next; - } + if (hwid & ~MPIDR_HWID_BITMASK) + goto next; =20 - /* - * The numbering scheme requires that the boot CPU - * must be assigned logical id 0. Record it so that - * the logical map built from DT is validated and can - * be used. - */ - if (hwid =3D=3D cpu_logical_map(0)) { - if (bootcpu_valid) { - pr_err("%pOF: duplicate boot cpu reg property in DT\n", - dn); + if (is_mpidr_duplicate(cpu_count, hwid)) { + pr_err("%pOF: duplicate cpu reg properties in the DT\n", + dn); goto next; } =20 - bootcpu_valid =3D true; - early_map_cpu_to_node(0, of_node_to_nid(dn)); - /* - * cpu_logical_map has already been - * initialized and the boot cpu doesn't need - * the enable-method so continue without - * incrementing cpu. + * The numbering scheme requires that the boot CPU + * must be assigned logical id 0. Record it so that + * the logical map built from DT is validated and can + * be used. */ - continue; - } + if (hwid =3D=3D cpu_logical_map(0)) { + if (bootcpu_valid) { + pr_err("%pOF: duplicate boot cpu reg property in DT\n", + dn); + goto next; + } + + bootcpu_valid =3D true; + early_map_cpu_to_node(0, of_node_to_nid(dn)); + + /* + * cpu_logical_map has already been + * initialized and the boot cpu doesn't need + * the enable-method so continue without + * incrementing cpu. + */ + continue; + } =20 - if (cpu_count >=3D NR_CPUS) - goto next; + if (cpu_count >=3D NR_CPUS) + goto next; =20 - pr_debug("cpu logical map 0x%llx\n", hwid); - set_cpu_logical_map(cpu_count, hwid); + pr_debug("cpu logical map 0x%llx\n", hwid); + set_cpu_logical_map(cpu_count, hwid); =20 - early_map_cpu_to_node(cpu_count, of_node_to_nid(dn)); + early_map_cpu_to_node(cpu_count, of_node_to_nid(dn)); next: - cpu_count++; + cpu_count++; + } } } =20 --=20 2.43.0 From nobody Mon Feb 9 03:30:03 2026 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (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 E08A51EB199; Tue, 22 Apr 2025 08:45:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745311524; cv=none; b=IWpQXruchXOhYSsaHoISV7rO8d/tpfnwFeWr0TG50+AJJT4RuxVYhN+AwomBC3FK6yWBLQ/xoCDQRct+ELfceU1SXB6DHDzBzrMS5/BmeD5ePCpDffYq2Q0dfT653fsYGbfs793fe4v+7VByX4tN4W20iPpj2EiVUheDZUUXnwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745311524; c=relaxed/simple; bh=COrlN25HZnO20YWMfJb/3b5Ae/h1Phh2+SBju7eLJmY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=QBKr9tdi5dEkpcIuuVIwzMuGlRJgHkPQ6M8flE/9Z/3tIYbPHJJEIS06c7E6bID6FuaRDV3qrwr1C8AcmIRxnfxoAaz5TLs/VBV465aR8A1nGbygUaWvlNailobMerITqvdqLDDxHRyxVBp50qu+gvj/YneadJX8HeQ5c40ek+g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4ZhbLK0RzYz6M4gc; Tue, 22 Apr 2025 16:41:13 +0800 (CST) Received: from frapeml500003.china.huawei.com (unknown [7.182.85.28]) by mail.maildlp.com (Postfix) with ESMTPS id AABD11402F3; Tue, 22 Apr 2025 16:45:20 +0800 (CST) Received: from a2303103017.china.huawei.com (10.47.65.221) by frapeml500003.china.huawei.com (7.182.85.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 22 Apr 2025 10:45:20 +0200 From: Alireza Sanaee To: CC: , , , , , , Subject: [PATCH v1 3/5] driver/base/arch_topology: update CPU map to use the new API. Date: Tue, 22 Apr 2025 09:43:38 +0100 Message-ID: <20250422084340.457-4-alireza.sanaee@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250422084340.457-1-alireza.sanaee@huawei.com> References: <20250422084340.457-1-alireza.sanaee@huawei.com> 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 X-ClientProxiedBy: lhrpeml500010.china.huawei.com (7.191.174.240) To frapeml500003.china.huawei.com (7.182.85.28) Content-Type: text/plain; charset="utf-8" Cleans up the cpu-map generation using the created API. Signed-off-by: Alireza Sanaee --- drivers/base/arch_topology.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 3ebe77566788..653a56625477 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -518,23 +518,23 @@ core_initcall(free_raw_capacity); */ static int __init get_cpu_for_node(struct device_node *node) { + struct device_node *cpu_node =3D NULL; int cpu; - struct device_node *cpu_node __free(device_node) =3D - of_parse_phandle(node, "cpu", 0); =20 - if (!cpu_node) - return -1; + cpu =3D of_cpu_phandle_to_id(node, cpu_node, "cpu"); =20 - cpu =3D of_cpu_node_to_id(cpu_node); if (cpu >=3D 0) topology_parse_cpu_capacity(cpu_node, cpu); - else + else if (cpu =3D=3D -ENODEV) pr_info("CPU node for %pOF exist but the possible cpu range is :%*pbl\n", cpu_node, cpumask_pr_args(cpu_possible_mask)); + else + return -1; =20 return cpu; } =20 + static int __init parse_core(struct device_node *core, int package_id, int cluster_id, int core_id) { --=20 2.43.0 From nobody Mon Feb 9 03:30:03 2026 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (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 4EFC61EE01F; Tue, 22 Apr 2025 08:45:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745311558; cv=none; b=p/xSgKe6dtA9TIKhe6Sx/D7Uv9jGf5ZqzBv2XtFC2/OOhxmJxBi8VqvgdjJxwv1QvFe8exVr90CWL6DDKEXRWEmDSSgdrun24QyZkFkN1QKcTs1S1b+rNc/im2gyHoj/AN8U9BJA6NbtKEWzfQgAiZJNPQSjYecniSD+npV0isE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745311558; c=relaxed/simple; bh=m4SCBTu6WuavCPl6m8tfaCMgYNX17NMKXBEztoh9e3o=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DLBnb2eLykROcGaqfhRfUwYtStHj7A9gpOaRxOwNryQ2QVpvnq5py53+tRuqRM3vo+05uxovWZWbu/QBTH/8iquTmcMV6jiBWB/jybMrpWZtvDGTywtrZrOFql+Mw+FSFty9deeg2zFtOT/+SyZSNziRpEgzongbcXX13UMm6rc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4ZhbPp3Ncwz6L56K; Tue, 22 Apr 2025 16:44:14 +0800 (CST) Received: from frapeml500003.china.huawei.com (unknown [7.182.85.28]) by mail.maildlp.com (Postfix) with ESMTPS id 18F24140594; Tue, 22 Apr 2025 16:45:54 +0800 (CST) Received: from a2303103017.china.huawei.com (10.47.65.221) by frapeml500003.china.huawei.com (7.182.85.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 22 Apr 2025 10:45:53 +0200 From: Alireza Sanaee To: CC: , , , , , , Subject: [PATCH v1 4/5] driver/hwtracing/coresight: Use of_cpu_phandle_to_id for grabbing CPU id. Date: Tue, 22 Apr 2025 09:43:39 +0100 Message-ID: <20250422084340.457-5-alireza.sanaee@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250422084340.457-1-alireza.sanaee@huawei.com> References: <20250422084340.457-1-alireza.sanaee@huawei.com> 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 X-ClientProxiedBy: lhrpeml500010.china.huawei.com (7.191.174.240) To frapeml500003.china.huawei.com (7.182.85.28) Content-Type: text/plain; charset="utf-8" Use the newly created API to grab CPU id. Signed-off-by: Alireza Sanaee --- .../hwtracing/coresight/coresight-cti-platform.c | 15 +++------------ drivers/hwtracing/coresight/coresight-platform.c | 14 ++------------ 2 files changed, 5 insertions(+), 24 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-cti-platform.c b/drivers= /hwtracing/coresight/coresight-cti-platform.c index d0ae10bf6128..6a6e84245112 100644 --- a/drivers/hwtracing/coresight/coresight-cti-platform.c +++ b/drivers/hwtracing/coresight/coresight-cti-platform.c @@ -41,21 +41,12 @@ */ static int of_cti_get_cpu_at_node(const struct device_node *node) { + struct device_node *dn =3D NULL; int cpu; - struct device_node *dn; =20 - if (node =3D=3D NULL) - return -1; - - dn =3D of_parse_phandle(node, "cpu", 0); - /* CTI affinity defaults to no cpu */ - if (!dn) - return -1; - cpu =3D of_cpu_node_to_id(dn); + cpu =3D of_cpu_phandle_to_id(node, dn,"cpu"); of_node_put(dn); - - /* No Affinity if no cpu nodes are found */ - return (cpu < 0) ? -1 : cpu; + return cpu; } =20 #else diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwt= racing/coresight/coresight-platform.c index 8192ba3279f0..cb953f25da82 100644 --- a/drivers/hwtracing/coresight/coresight-platform.c +++ b/drivers/hwtracing/coresight/coresight-platform.c @@ -167,19 +167,9 @@ of_coresight_get_output_ports_node(const struct device= _node *node) =20 static int of_coresight_get_cpu(struct device *dev) { - int cpu; - struct device_node *dn; - - if (!dev->of_node) - return -ENODEV; - - dn =3D of_parse_phandle(dev->of_node, "cpu", 0); - if (!dn) - return -ENODEV; - - cpu =3D of_cpu_node_to_id(dn); + struct device_node *dn =3D NULL; + int cpu =3D of_cpu_phandle_to_id(dev->of_node, dn, "cpu"); of_node_put(dn); - return cpu; } =20 --=20 2.43.0 From nobody Mon Feb 9 03:30:03 2026 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) (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 5386D266F0D; Tue, 22 Apr 2025 08:46:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.176.79.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745311591; cv=none; b=RcagBz6PGsghrap60Zx0hozAcyc4zTLOKnSbSS0YtDyH5r/VRiNhBSDMq1/xzsULwCriJ9Lw6BNnkVLZ+cD04egFWR8pm14gxIWPmxRqGKDv77ZE1bIcqW4MswbDPt4+4Wl5tT8Zsi9Ca5v3Fc93SDDY/HrsGdBLE8HXdLSbCsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745311591; c=relaxed/simple; bh=MRSFNtkiXxF2rLRCNQwIhpaDs/Mwc0t61v5PuBsLqUQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YT0wcNgntWrv8ipSRiqhWtFsrkJjMXdPAZqqyAlLqa2/pInf+iYXLOSBLUEAVrz41clsu3d65dgiU1USJWDndlH0KZVFbYhfYUGSqD8Nd5nCPdP9kS7djUMwUEgzzrgBPWtcbI7D4vj2KaOcF6G0bPauUbZthXhcnotoFsueYeA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=185.176.79.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.18.186.216]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4ZhbQR5kGNz6FCB6; Tue, 22 Apr 2025 16:44:47 +0800 (CST) Received: from frapeml500003.china.huawei.com (unknown [7.182.85.28]) by mail.maildlp.com (Postfix) with ESMTPS id 7195A1402F3; Tue, 22 Apr 2025 16:46:27 +0800 (CST) Received: from a2303103017.china.huawei.com (10.47.65.221) by frapeml500003.china.huawei.com (7.182.85.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Tue, 22 Apr 2025 10:46:26 +0200 From: Alireza Sanaee To: CC: , , , , , , Subject: [PATCH v1 5/5] DT: of_cpu_phandle_to_id to support SMT threads Date: Tue, 22 Apr 2025 09:43:40 +0100 Message-ID: <20250422084340.457-6-alireza.sanaee@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250422084340.457-1-alireza.sanaee@huawei.com> References: <20250422084340.457-1-alireza.sanaee@huawei.com> 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 X-ClientProxiedBy: lhrpeml500010.china.huawei.com (7.191.174.240) To frapeml500003.china.huawei.com (7.182.85.28) Content-Type: text/plain; charset="utf-8" Enhance the API to support SMT threads, this will allow sharing resources a= mong multiple SMT threads. Enabled the sharing of resources, such as L1 Cache and clocks, between SMT threads. It introduces a fix that uses thread IDs to match each CPU thread = in the register array within the cpu-node. This ensures that the cpu-map or any driver relying on this API is fine even when SMT threads share resources. Additionally, I have tested this for CPU based on the discussions in [1], I adopted the new cpu-map layout, where the first parameter is a phandle and = the second is the local thread index, as shown below: Used a new variable in CPU node "#cpu-cells", in which I describe the number of parameters when parsing the phandle with arg to find the local thread ID. This variable is not mandatory, and is indeed backward-compatible. The API first look for this particular variable, if it does not exists, it just assume thread 0, which is the existing appro= ach. core0 { thread0 { cpu =3D <&cpu0 0>; }; thread1 { cpu =3D <&cpu0 1>; }; }; [1] https://lore.kernel.org/devicetree-spec/CAL_JsqK1yqRLD9B+G7UUp=3DD8K++m= XHq0Rmv=3D1i6DL_jXyZwXAw@mail.gmail.com/ Signed-off-by: Alireza Sanaee --- drivers/of/cpu.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/of/cpu.c b/drivers/of/cpu.c index c2d729999a4e..2df07aea184e 100644 --- a/drivers/of/cpu.c +++ b/drivers/of/cpu.c @@ -189,21 +189,26 @@ int of_cpu_phandle_to_id(const struct device_node *no= de, const char * prop) { bool found =3D false; - int cpu, ret; + int cpu, ret =3D -1; + uint32_t local_thread, thread_index; struct device_node *np; struct of_phandle_args args; =20 if (!node || !prop) - return -1; - - ret =3D of_parse_phandle_with_args(node, prop, NULL, 0, &args); - if (ret < 0) return ret; =20 + ret =3D of_parse_phandle_with_args(node, prop, "#cpu-cells", 0, &args); + if (ret < 0) { + ret =3D of_parse_phandle_with_args(node, prop, NULL, 0, &args); + if (ret < 0) + return ret; + } + cpu_np =3D args.np; + thread_index =3D args.args_count =3D=3D 1 ? args.args[0] : 0; for_each_possible_cpu(cpu) { - np =3D of_cpu_device_node_get(cpu); - found =3D (cpu_np =3D=3D np); + np =3D of_get_cpu_node(cpu, &local_thread); + found =3D (cpu_np =3D=3D np) && (local_thread =3D=3D thread_index); of_node_put(np); if (found) return cpu; --=20 2.43.0