From 9a3ca3513e07aa1ec2cabc3ecb449456f9ee94ea Mon Sep 17 00:00:00 2001 From: s00909737 Date: Mon, 3 Nov 2025 10:26:35 +0800 Subject: [PATCH] Improve core binding strategy by dynamic params --- Makefile | 2 +- core/smc_smp.c | 21 +++++++++++++-------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 3a557e3..1c5c30a 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,7 @@ ifeq ($(CROSS_DOMAIN_PERF), y) EXTRA_CFLAGS += -DCROSS_DOMAIN_PERF endif ifeq ($(CPU_GROUP_BINDING), y) -EXTRA_CFLAGS += -DCONFIG_CPU_GROUP_BINDING -DCONFIG_NUM_DIE=4 -DCONFIG_NUM_PHY_CORE_PER_DIE=40 -DCONFIG_NUM_TEE_PHY_CORE_PER_DIE=32 -DCONFIG_MAX_TEE_CORE=128 +EXTRA_CFLAGS += -DCONFIG_CPU_GROUP_BINDING -DCONFIG_NUM_TEE_DIE=4 -DCONFIG_NUM_TEE_PHY_CORE_PER_DIE=32 endif all: diff --git a/core/smc_smp.c b/core/smc_smp.c index 0fb6c39..4d292fa 100644 --- a/core/smc_smp.c +++ b/core/smc_smp.c @@ -651,21 +651,26 @@ static int set_cpumask_aff(struct cpumask *mask) { unsigned int i; # ifdef CONFIG_CPU_GROUP_BINDING - unsigned int j, threads_per_core; + unsigned int j, threads_per_core, nr_dies, phy_core_per_die; + unsigned int nr_die_binded, nr_core_binded; # endif # ifdef CONFIG_CPU_GROUP_BINDING /** - * Kunpeng 920B might contains 160 physical cores (320 logical cores with SMP on) or more. - * CCOS does not support so many cores up to now. - * Identify by num of CPU cores; bind to specific cores. + * iTrustee-Server supports only 4 dies, 32 phy cores per die and 2 threads per phy core. + * Identify by num of CPU cores and cpu topology; bind to those specific cores when detected redundance. */ threads_per_core = cpumask_weight(topology_sibling_cpumask(smp_processor_id())); - if (nr_cpu_ids > CONFIG_MAX_TEE_CORE * threads_per_core) { + nr_dies = num_possible_nodes(); + phy_core_per_die = nr_cpu_ids / nr_dies / threads_per_core; + if (phy_core_per_die > CONFIG_NUM_TEE_PHY_CORE_PER_DIE || nr_dies > CONFIG_NUM_TEE_DIE) { + nr_die_binded = nr_dies < CONFIG_NUM_TEE_DIE ? nr_dies : CONFIG_NUM_TEE_DIE; + nr_core_binded = phy_core_per_die < CONFIG_NUM_TEE_PHY_CORE_PER_DIE ? phy_core_per_die : + CONFIG_NUM_TEE_PHY_CORE_PER_DIE; cpumask_clear(mask); - for (j = 0; j < CONFIG_NUM_DIE; j++) - for (i = 0; i < CONFIG_NUM_TEE_PHY_CORE_PER_DIE * threads_per_core; i++) - cpumask_set_cpu(i + j * CONFIG_NUM_PHY_CORE_PER_DIE * threads_per_core, mask); + for (j = 0; j < nr_die_binded; j++) + for (i = 0; i < nr_core_binded * threads_per_core; i++) + cpumask_set_cpu(i + j * phy_core_per_die * threads_per_core, mask); return 1; } # endif -- Gitee