From nobody Wed Dec 17 08:58:26 2025 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 E9DEC257434; Mon, 12 May 2025 08:07:52 +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=1747037275; cv=none; b=no63GvTR04/2Ok/BVlMpupwfCh6Z+hESqAgzl24wwWjYACIdYe5WRw5BqBYXTDAwn9f9E96oYVIV1NdLNs6V5iL0tPsLL3zVJlzJ2aO3uDJZgYwTX0Uk1p84VPgps3EKnQnzCoOKJ/AaQpHAglt+XxikN+1zOLOwjAeE0vfezw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747037275; c=relaxed/simple; bh=+Bkrbf8JC8XOlzKL+Xal4nNMV4lUwDPuoUt0WTb4lnQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JCv8PJPkSsOOOqz0u3SEGmZZ9i9M6U48t3qmPYqqVBXPAhup30XS7yMM8GLjqI1TAZOgdpJeBbHWIjlJQmFp1Tg8rfelMhsatTdzrCqrTrh+iYxhKyLylJzUbI8LvuI5iIh2phJf92oRDLwMIlPrL2l0fzJDvbm1uZv16DiGRmo= 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.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4ZwsbR33MNz6L578; Mon, 12 May 2025 16:05:07 +0800 (CST) Received: from frapeml500003.china.huawei.com (unknown [7.182.85.28]) by mail.maildlp.com (Postfix) with ESMTPS id CDCCF140145; Mon, 12 May 2025 16:07:49 +0800 (CST) Received: from a2303103017.china.huawei.com (10.47.30.10) 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; Mon, 12 May 2025 10:07:48 +0200 From: Alireza Sanaee To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 1/7] of: add infra for finding CPU id from phandle Date: Mon, 12 May 2025 09:07:09 +0100 Message-ID: <20250512080715.82-2-alireza.sanaee@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250512080715.82-1-alireza.sanaee@huawei.com> References: <20250512080715.82-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: lhrpeml500001.china.huawei.com (7.191.163.213) 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 improves readability. The API interface requires two parameters, 1) node, 2) pointer to CPU node. API sets the pointer to the CPU node and allows the driver to play with the CPU itself, for logging purposes for instance. Signed-off-by: Alireza Sanaee --- drivers/of/cpu.c | 29 +++++++++++++++++++++++++++++ include/linux/of.h | 9 +++++++++ 2 files changed, 38 insertions(+) diff --git a/drivers/of/cpu.c b/drivers/of/cpu.c index 5214dc3d05ae..fba17994fc20 100644 --- a/drivers/of/cpu.c +++ b/drivers/of/cpu.c @@ -173,6 +173,35 @@ 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. + * @cpu_idx: The index of the CPU in the list of CPUs. + * + * Return: The logical CPU number of the given CPU device_node or -ENODEV = if + * the CPU is not found, or if the node is NULL, it returns -1. On success, + * cpu_np will always point to the retrieved CPU device_node with refcount + * incremented, use of_node_put() on it when done. + */ +int of_cpu_phandle_to_id(const struct device_node *node, + struct device_node **cpu_np, + uint8_t cpu_idx) +{ + if (!node) + return -1; + + *cpu_np =3D of_parse_phandle(node, "cpu", 0); + if (!*cpu_np) + *cpu_np =3D of_parse_phandle(node, "cpus", cpu_idx); + if (!*cpu_np) + return -ENODEV; + + return of_cpu_node_to_id(*cpu_np); +} +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..194f1cb0f6c6 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -360,6 +360,8 @@ 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, + struct device_node **cpu_np, uint8_t cpu_idx); 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); @@ -662,6 +664,13 @@ static inline int of_cpu_node_to_id(struct device_node= *np) return -ENODEV; } =20 +static inline int of_cpu_phandle_to_id(const struct device_node *np, + struct device_node **cpu_np, + uint8_t cpu_idx) +{ + return -ENODEV; +} + static inline struct device_node *of_get_next_cpu_node(struct device_node = *prev) { return NULL; --=20 2.34.1 From nobody Wed Dec 17 08:58:26 2025 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 EC7852571D5; Mon, 12 May 2025 08:08:23 +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=1747037305; cv=none; b=Z2Lz+tF3cue09WIG4sW/VOQB+XOfGIEkThscHh91SK0z7+SApYt/fFAKQd8jjPTnU+RQzRewQ6dX1LFwLns8Er1UY3rFfqb6nj1v+WfMJXfJpbMtc6lkps+huRT5sLMrFgtHPjgyKFOPqnOCfAEfv0dZeQgXlNVZuXCqYUJG8S8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747037305; c=relaxed/simple; bh=eF1yfF+FebAl2O4ISeOH9vYT5R/HY3HCYjCHSmtiBAU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l1H5U6znc/dEj7R1NpauXRMHVOUKlcXf/gffvOcVtJv5VH82Q1R3OU2KaREJ1DTCytagbYPKy6q16nc0K2ZCrINiPWWl5LRykvxLznCL/mnu3IZPICY8OsGp0XJTDNC5QpbpP5aZI2qu3odnBJRDVr3Qz211DoCOzW6+/lN8c3k= 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 4Zwsc31vLpz6L4wH; Mon, 12 May 2025 16:05:39 +0800 (CST) Received: from frapeml500003.china.huawei.com (unknown [7.182.85.28]) by mail.maildlp.com (Postfix) with ESMTPS id A473F1402FC; Mon, 12 May 2025 16:08:21 +0800 (CST) Received: from a2303103017.china.huawei.com (10.47.30.10) 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; Mon, 12 May 2025 10:08:20 +0200 From: Alireza Sanaee To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 2/7] arch_topology: update CPU map to use the new API Date: Mon, 12 May 2025 09:07:10 +0100 Message-ID: <20250512080715.82-3-alireza.sanaee@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250512080715.82-1-alireza.sanaee@huawei.com> References: <20250512080715.82-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: lhrpeml500001.china.huawei.com (7.191.163.213) 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..88970f13f684 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 __free(device_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, 0); =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.34.1 From nobody Wed Dec 17 08:58:26 2025 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 D9A80257432; Mon, 12 May 2025 08:08: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=1747037337; cv=none; b=BiSfm9w5St33sAhKCxaL6GHUzuXP7Lx4B2Q0yjuFpZAVqKuS6NgenhUH5g81QsQquUW/NS3DN0KlQBoLBk/qADGatzSDSztG7DXoLMkMzIywyKWEenfFERby2od1Z0aUL/4fOhegOGFAOVj1jC59duGzMqkHzER+Gj2mhJabIhM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747037337; c=relaxed/simple; bh=H+X+r317beI8ScvSsUNB9Kq/c/yryvAfMBuE5VgT33Y=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=MpKDYJCI/mPeQZJDcmqxBYBUAOywkM2IrtwUPzHXHJefR90d3klhUo4Pt1zlIj+ZezS74IeD9tKuAB/mokRIBrQDla4Jh7uRNBED9wQp4D/7ULgwYl6aw/YSryciq6zy+rXvwoEnXpsXkHBOHtLyX7yntgcq0nFRjFI98p/0Ro4= 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.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4ZwsZR13dnz6M4hn; Mon, 12 May 2025 16:04:15 +0800 (CST) Received: from frapeml500003.china.huawei.com (unknown [7.182.85.28]) by mail.maildlp.com (Postfix) with ESMTPS id B7CD614050C; Mon, 12 May 2025 16:08:53 +0800 (CST) Received: from a2303103017.china.huawei.com (10.47.30.10) 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; Mon, 12 May 2025 10:08:52 +0200 From: Alireza Sanaee To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 3/7] coresight: cti: Use of_cpu_phandle_to_id for grabbing CPU id Date: Mon, 12 May 2025 09:07:11 +0100 Message-ID: <20250512080715.82-4-alireza.sanaee@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250512080715.82-1-alireza.sanaee@huawei.com> References: <20250512080715.82-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: lhrpeml500001.china.huawei.com (7.191.163.213) 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 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-cti-platform.c b/drivers= /hwtracing/coresight/coresight-cti-platform.c index d0ae10bf6128..cd821e926792 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, 0); of_node_put(dn); - - /* No Affinity if no cpu nodes are found */ - return (cpu < 0) ? -1 : cpu; + return cpu; } =20 #else --=20 2.34.1 From nobody Wed Dec 17 08:58:26 2025 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 81D5B255F4A; Mon, 12 May 2025 08:09:27 +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=1747037368; cv=none; b=tbsY+ozt2r4zQd2kjGv1f6PEcfJA9YiDm9vzg41h0P4pLVzIXy4+WorniWAIZR2KN7J4qnCPKm8gscd9atJtN4rbAGDZYRrolPQWoM+jso/VS+lnYiEwGorQCUy3eQOIzOHPFnCV8rUPhSmXfn3DRfLUOxBWEdOQivRkUhNt6p0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747037368; c=relaxed/simple; bh=UrH3ED4Pu+Ili7BvuZS5cyi1gmb7vjgRoTa1ak0bRSg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=OL6P/LYNavcs5Bkx53ijCt6yYYqmMOJ2IGGuynCZKVYN7+H+hZFGFFssSUICpta+D1dem4Ufu9PJj5y/Kl3wI7lp4vWWnI3mlRjxRqW3SGTK9zgthQ6LwQ/+nNVv8nEfXmsi7pw5Ah2fS6+YrlAO7OeXJesR6AXiU3uT+A/DEqs= 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 4ZwsdH1LFwz6L540; Mon, 12 May 2025 16:06:43 +0800 (CST) Received: from frapeml500003.china.huawei.com (unknown [7.182.85.28]) by mail.maildlp.com (Postfix) with ESMTPS id 91F021400DC; Mon, 12 May 2025 16:09:25 +0800 (CST) Received: from a2303103017.china.huawei.com (10.47.30.10) 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; Mon, 12 May 2025 10:09:24 +0200 From: Alireza Sanaee To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 4/7] coresight: Use of_cpu_phandle_to_id for grabbing CPU id Date: Mon, 12 May 2025 09:07:12 +0100 Message-ID: <20250512080715.82-5-alireza.sanaee@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250512080715.82-1-alireza.sanaee@huawei.com> References: <20250512080715.82-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: lhrpeml500001.china.huawei.com (7.191.163.213) 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 --- drivers/hwtracing/coresight/coresight-platform.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/drivers/hwtracing/coresight/coresight-platform.c b/drivers/hwt= racing/coresight/coresight-platform.c index 8192ba3279f0..f032fdbe959b 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, 0); of_node_put(dn); - return cpu; } =20 --=20 2.34.1 From nobody Wed Dec 17 08:58:26 2025 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 72547257420; Mon, 12 May 2025 08:09:59 +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=1747037400; cv=none; b=PLpTKCgI+8zU3wK5u5o6pahozF57UNI/B/IC5as6BmdlPh3KCRL3FTsfw0EhfqjAsbkhESzhzLKtTioFQCpRIShnGupT4JSidFAuJOh44jIdZqip60K0wl8QTzbSuRBY1ST3h1ssg5xFP73k2tspiuyYO4y2byXFaKaFcyfIffI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747037400; c=relaxed/simple; bh=86RFJGgsvzEJQpRgYjnhLJ6ByzoyLTPc5oOuzezqwWc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=t6XWCXWRNn+AhKZYX1o7txRYUjzq/pfAxgeuNp/Vlq0hg8Q/9a20vj4YSwd4tfu9e5DZ3o2qVUKl9WFwBeFVWcGkI2zBCGE7fxNar2xOtsXbtQDGxG1V6/e10htZTddjolRM407mYXvr2P0IgRAU4ViN5Siu/oiVGWElUyHPQVo= 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 4Zwsbf6JXNz6M4jB; Mon, 12 May 2025 16:05:18 +0800 (CST) Received: from frapeml500003.china.huawei.com (unknown [7.182.85.28]) by mail.maildlp.com (Postfix) with ESMTPS id 6469C1402F4; Mon, 12 May 2025 16:09:57 +0800 (CST) Received: from a2303103017.china.huawei.com (10.47.30.10) 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; Mon, 12 May 2025 10:09:56 +0200 From: Alireza Sanaee To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 5/7] perf/arm-dsu: refactor cpu id retrieval via new API of_cpu_phandle_to_id Date: Mon, 12 May 2025 09:07:13 +0100 Message-ID: <20250512080715.82-6-alireza.sanaee@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250512080715.82-1-alireza.sanaee@huawei.com> References: <20250512080715.82-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: lhrpeml500001.china.huawei.com (7.191.163.213) To frapeml500003.china.huawei.com (7.182.85.28) Content-Type: text/plain; charset="utf-8" Update arm-dsu to use the new API, where both "cpus" and "cpu" properties are supported. Signed-off-by: Alireza Sanaee --- drivers/perf/arm_dsu_pmu.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/perf/arm_dsu_pmu.c b/drivers/perf/arm_dsu_pmu.c index cb4fb59fe04b..7ef204d39173 100644 --- a/drivers/perf/arm_dsu_pmu.c +++ b/drivers/perf/arm_dsu_pmu.c @@ -596,11 +596,9 @@ static int dsu_pmu_dt_get_cpus(struct device *dev, cpu= mask_t *mask) n =3D of_count_phandle_with_args(dev->of_node, "cpus", NULL); if (n <=3D 0) return -ENODEV; + for (; i < n; i++) { - cpu_node =3D of_parse_phandle(dev->of_node, "cpus", i); - if (!cpu_node) - break; - cpu =3D of_cpu_node_to_id(cpu_node); + cpu =3D of_cpu_phandle_to_id(dev->of_node, &cpu_node, i); of_node_put(cpu_node); /* * We have to ignore the failures here and continue scanning --=20 2.34.1 From nobody Wed Dec 17 08:58:26 2025 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 3721025743F; Mon, 12 May 2025 08:10:31 +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=1747037433; cv=none; b=UHEKINbCLCPXJEYZWY+6DttwyP4O19H3oKA6xp8NYJ4OJ/yXydSSX90YLH9QkJhWKOm+qqluetw4evrF6t759jpaYsNAfrdMiBbgHGFh3Q8e2Bkg/EaZgm/fmFn7I4689Z/UrN3AemjTjH2dkZVolWwnAByGnd/xkx4Z3KuiTrk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747037433; c=relaxed/simple; bh=PLhj8XRRcFobgNY8IKrQl05mOUEVDT1ZaUSUY1pOwWo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=dbrteebwW5YTyC8bsQ6tkJGs7tieNJfAoJUWw5bFMX2E3YmZ0LzosYfuNMzWGRRORVT/r9b/pzLeRhMGvDc4VvXsXWTg5u1HEO8AkcQEaiEdSSTn3gTJ0R46v/2QBDVFcIbWziTO4Nvxv7aVNjYGurcRA5oSJgPKL3Urw4Cq+3w= 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 4ZwsfW0mLTz6L57s; Mon, 12 May 2025 16:07:47 +0800 (CST) Received: from frapeml500003.china.huawei.com (unknown [7.182.85.28]) by mail.maildlp.com (Postfix) with ESMTPS id 7DF321402FC; Mon, 12 May 2025 16:10:29 +0800 (CST) Received: from a2303103017.china.huawei.com (10.47.30.10) 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; Mon, 12 May 2025 10:10:28 +0200 From: Alireza Sanaee To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 6/7] arm64: of: handle multiple threads in ARM cpu node Date: Mon, 12 May 2025 09:07:14 +0100 Message-ID: <20250512080715.82-7-alireza.sanaee@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250512080715.82-1-alireza.sanaee@huawei.com> References: <20250512080715.82-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: lhrpeml500001.china.huawei.com (7.191.163.213) 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.34.1 From nobody Wed Dec 17 08:58:26 2025 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 88A692561B8; Mon, 12 May 2025 08:11:03 +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=1747037465; cv=none; b=evZZnJUz92LLVfgP8+6EnUcW6HJOUxXF+0ZF0QuHqeyVdbNxU/ZiKaz7VPILuNIapbDUCkSi6jdM2KmsS4YJ542U5ytnELhgT3hw6ap4/mMp8+6LsCqSeGkiIInCiKiVkgNNl2B3dc5MOmCto9IGZ0c814Og8DEPfxXmqkxz/LQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1747037465; c=relaxed/simple; bh=9Wo1EwJxutD9p3npSM18IZGR8PNKr7fkce/EAjiUTQo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=W8PAleS703vSs2IGt26wm1k/U18OOPq6HUxGckRmkvuYcfgFzVK38362+1G0X91esXzSxNE0bfVpUM1+R+2qFZsMBCNu69Xd4DBRP4r/TWXyJaaesQTk7CLLwatzZYVnwGPfbLGnTuS7xOBhHwh8YfnWZCUPsKNu0F2Svaw/10E= 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 4Zwscv1Lntz6M4gh; Mon, 12 May 2025 16:06:23 +0800 (CST) Received: from frapeml500003.china.huawei.com (unknown [7.182.85.28]) by mail.maildlp.com (Postfix) with ESMTPS id BE8E41402F4; Mon, 12 May 2025 16:11:01 +0800 (CST) Received: from a2303103017.china.huawei.com (10.47.30.10) 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; Mon, 12 May 2025 10:11:00 +0200 From: Alireza Sanaee To: CC: , , , , , , , , , , , , , , , , , , Subject: [PATCH v3 7/7] of: of_cpu_phandle_to_id to support SMT threads Date: Mon, 12 May 2025 09:07:15 +0100 Message-ID: <20250512080715.82-8-alireza.sanaee@huawei.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250512080715.82-1-alireza.sanaee@huawei.com> References: <20250512080715.82-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: lhrpeml500001.china.huawei.com (7.191.163.213) 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 among 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: core0 { thread0 { cpu =3D <&cpu0 0>; }; thread1 { cpu =3D <&cpu0 1>; }; }; Also, there are devices such as below that are a bit different. arm_dsu@0 { compatible =3D "arm,dsu"; cpus =3D <&cpu0 &cpu1 &cpu2 &cpu3>; } In these cases, we can also point to a CPU thread as well like the following: arm_dsu@0 { compatible =3D "arm,dsu"; cpus =3D <&cpu0 5 &cpu1 9 &cpu2 1 &cpu3 0>; } It should be possible to know how many arguments a phandle might require, and this information is encoded in another variable in the dt called #cpu-cells in cpu node. Signed-off-by: Alireza Sanaee [1] https://lore.kernel.org/devicetree-spec/CAL_JsqK1yqRLD9B+G7UUp=3DD8K++m= XHq0Rmv=3D1i6DL_jXyZwXAw@mail.gmail.com/ --- drivers/of/cpu.c | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/drivers/of/cpu.c b/drivers/of/cpu.c index fba17994fc20..cf54ef47f029 100644 --- a/drivers/of/cpu.c +++ b/drivers/of/cpu.c @@ -189,16 +189,41 @@ int of_cpu_phandle_to_id(const struct device_node *no= de, struct device_node **cpu_np, uint8_t cpu_idx) { + bool found =3D false; + int cpu, ret =3D -1, i, j; + uint32_t local_thread, thread_index; + struct device_node *np; + struct of_phandle_args args; + static const char * const phandle_names[] =3D { "cpus", "cpu" }; + static const char * const cpu_cells[] =3D { "#cpu-cells", NULL }; + if (!node) - return -1; + return ret; =20 - *cpu_np =3D of_parse_phandle(node, "cpu", 0); - if (!*cpu_np) - *cpu_np =3D of_parse_phandle(node, "cpus", cpu_idx); - if (!*cpu_np) - return -ENODEV; + for (i =3D 0; i < ARRAY_SIZE(phandle_names); i++) { + for (j =3D 0; j < ARRAY_SIZE(cpu_cells); j++) { + ret =3D of_parse_phandle_with_args(node, phandle_names[i], + cpu_cells[j], cpu_idx, + &args); + if (ret >=3D 0) + goto success; + } + } =20 - return of_cpu_node_to_id(*cpu_np); + if (ret < 0) + return ret; +success: + *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_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; + } + + return -ENODEV; } EXPORT_SYMBOL(of_cpu_phandle_to_id); =20 @@ -206,7 +231,7 @@ EXPORT_SYMBOL(of_cpu_phandle_to_id); * of_get_cpu_state_node - Get CPU's idle state node at the given index * * @cpu_node: The device node for the CPU - * @index: The index in the list of the idle states +g* @index: The index in the list of the idle states * * Two generic methods can be used to describe a CPU's idle states, either= via * a flattened description through the "cpu-idle-states" binding or via the --=20 2.34.1