From nobody Mon Feb 9 07:36:01 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D429860B96 for ; Thu, 11 Apr 2024 01:05:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797521; cv=none; b=Gi9Wsa8KEi5NPR8kH59DmKkgJFiaMKgJfhkbrUosWsm+s6CyRGpzjsa2qFJTGeBVgc1GENbVIkq+5dEvJW+OuBfGhzGPjkEtT7vdgFDuBzFZtfzqjN/kCECCL5KCSZ9E3+HjQ/2rpYcgdsZm/fwWFJG6QNuyw+egUnMjzqP1/x8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797521; c=relaxed/simple; bh=NeuRh8D5vX5nUv9iOk2eSOKmIKgQFNfWLUUhe4orCWM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B5llM12hBQ2Zup5gy0L4xC0I5PFxEPrDuEn2qfGRscCGdGkdZPeQnmbAYCs7GxFK2jPC5rtc3V4w4PJmY3WW2vKqW3qWo1W9mo7HX0ll+G9CXO4tPQ3siVSQcJiGRVV1xjebg+CiLcNNqzIDW0s7Zmv7/HaEP/06wdJkh9BHrtk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8AxjrtLNxdm6JAlAA--.6451S3; Thu, 11 Apr 2024 09:05:15 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxhhFHNxdmnrx3AA--.22869S3; Thu, 11 Apr 2024 09:05:14 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Thomas Gleixner , Arnd Bergmann , Marc Zyngier Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, loongson-kernel@lists.loongnix.cn Subject: [PATCH v3 1/4] LoongArch: Move CONFIG_HAVE_SETUP_PER_CPU_AREA related code to smp.c Date: Thu, 11 Apr 2024 09:05:07 +0800 Message-ID: <20240411010510.22135-2-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240411010510.22135-1-yangtiezhu@loongson.cn> References: <20240411010510.22135-1-yangtiezhu@loongson.cn> 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-CM-TRANSID: AQAAf8AxhhFHNxdmnrx3AA--.22869S3 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW3Jw4fZw4kZrW8XFW3Cr48uFX_yoW7ArW3pr WfC39xtrW3W3s8J398t3yDury5Jr1kK3yxXa13CFWru3W7ZFn8Wr4vvryDXFWUWaykWa1F vFZ5GF4UWF48JwbCm3ZEXasCq-sJn29KB7ZKAUJUUUUx529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r126r13M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Gr0_Xr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUAVWUtwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWr XwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxkF7I0En4kS14v26r126r1DMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMxCIbckI1I0E14v26r126r1DMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwV AFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv2 0xvE14v26r1I6r4UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4 v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AK xVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU8Gii3UUUUU== Content-Type: text/plain; charset="utf-8" Currently, if CONFIG_NUMA is not set but CONFIG_SMP is set, the arch specified setup_per_cpu_areas() in arch/loongarch/kernel/numa.c will not be built and the generic setup_per_cpu_areas() in mm/percpu.c is actually used, this is not reasonable and does not work as intended. Let us select HAVE_SETUP_PER_CPU_AREA unconditionally and then move CONFIG_HAVE_SETUP_PER_CPU_AREA related code from numa.c to smp.c to avoid this problem. Signed-off-by: Tiezhu Yang --- arch/loongarch/Kconfig | 2 +- arch/loongarch/kernel/numa.c | 58 ----------------------------------- arch/loongarch/kernel/smp.c | 59 ++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+), 59 deletions(-) diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index a5f300ec6f28..64052ae2c2af 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -151,7 +151,7 @@ config LOONGARCH select HAVE_RUST select HAVE_SAMPLE_FTRACE_DIRECT select HAVE_SAMPLE_FTRACE_DIRECT_MULTI - select HAVE_SETUP_PER_CPU_AREA if NUMA + select HAVE_SETUP_PER_CPU_AREA select HAVE_STACK_VALIDATION if HAVE_OBJTOOL select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS diff --git a/arch/loongarch/kernel/numa.c b/arch/loongarch/kernel/numa.c index 8fe21f868f72..49dc1d932ce2 100644 --- a/arch/loongarch/kernel/numa.c +++ b/arch/loongarch/kernel/numa.c @@ -48,64 +48,6 @@ EXPORT_SYMBOL(__cpuid_to_node); =20 nodemask_t numa_nodes_parsed __initdata; =20 -#ifdef CONFIG_HAVE_SETUP_PER_CPU_AREA -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly; -EXPORT_SYMBOL(__per_cpu_offset); - -static int __init pcpu_cpu_to_node(int cpu) -{ - return early_cpu_to_node(cpu); -} - -static int __init pcpu_cpu_distance(unsigned int from, unsigned int to) -{ - if (early_cpu_to_node(from) =3D=3D early_cpu_to_node(to)) - return LOCAL_DISTANCE; - else - return REMOTE_DISTANCE; -} - -void __init pcpu_populate_pte(unsigned long addr) -{ - populate_kernel_pte(addr); -} - -void __init setup_per_cpu_areas(void) -{ - unsigned long delta; - unsigned int cpu; - int rc =3D -EINVAL; - - if (pcpu_chosen_fc =3D=3D PCPU_FC_AUTO) { - if (nr_node_ids >=3D 8) - pcpu_chosen_fc =3D PCPU_FC_PAGE; - else - pcpu_chosen_fc =3D PCPU_FC_EMBED; - } - - /* - * Always reserve area for module percpu variables. That's - * what the legacy allocator did. - */ - if (pcpu_chosen_fc !=3D PCPU_FC_PAGE) { - rc =3D pcpu_embed_first_chunk(PERCPU_MODULE_RESERVE, - PERCPU_DYNAMIC_RESERVE, PMD_SIZE, - pcpu_cpu_distance, pcpu_cpu_to_node); - if (rc < 0) - pr_warn("%s allocator failed (%d), falling back to page size\n", - pcpu_fc_names[pcpu_chosen_fc], rc); - } - if (rc < 0) - rc =3D pcpu_page_first_chunk(PERCPU_MODULE_RESERVE, pcpu_cpu_to_node); - if (rc < 0) - panic("cannot initialize percpu area (err=3D%d)", rc); - - delta =3D (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start; - for_each_possible_cpu(cpu) - __per_cpu_offset[cpu] =3D delta + pcpu_unit_offsets[cpu]; -} -#endif - /* * Get nodeid by logical cpu number. * __cpuid_to_node maps phyical cpu id to node, so we diff --git a/arch/loongarch/kernel/smp.c b/arch/loongarch/kernel/smp.c index aabee0b280fe..88b9c6b68d1e 100644 --- a/arch/loongarch/kernel/smp.c +++ b/arch/loongarch/kernel/smp.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -717,3 +718,61 @@ void flush_tlb_one(unsigned long vaddr) on_each_cpu(flush_tlb_one_ipi, (void *)vaddr, 1); } EXPORT_SYMBOL(flush_tlb_one); + +#ifdef CONFIG_HAVE_SETUP_PER_CPU_AREA +unsigned long __per_cpu_offset[NR_CPUS] __read_mostly; +EXPORT_SYMBOL(__per_cpu_offset); + +static int __init pcpu_cpu_to_node(int cpu) +{ + return early_cpu_to_node(cpu); +} + +static int __init pcpu_cpu_distance(unsigned int from, unsigned int to) +{ + if (early_cpu_to_node(from) =3D=3D early_cpu_to_node(to)) + return LOCAL_DISTANCE; + else + return REMOTE_DISTANCE; +} + +void __init pcpu_populate_pte(unsigned long addr) +{ + populate_kernel_pte(addr); +} + +void __init setup_per_cpu_areas(void) +{ + unsigned long delta; + unsigned int cpu; + int rc =3D -EINVAL; + + if (pcpu_chosen_fc =3D=3D PCPU_FC_AUTO) { + if (nr_node_ids >=3D 8) + pcpu_chosen_fc =3D PCPU_FC_PAGE; + else + pcpu_chosen_fc =3D PCPU_FC_EMBED; + } + + /* + * Always reserve area for module percpu variables. That's + * what the legacy allocator did. + */ + if (pcpu_chosen_fc !=3D PCPU_FC_PAGE) { + rc =3D pcpu_embed_first_chunk(PERCPU_MODULE_RESERVE, + PERCPU_DYNAMIC_RESERVE, PMD_SIZE, + pcpu_cpu_distance, pcpu_cpu_to_node); + if (rc < 0) + pr_warn("%s allocator failed (%d), falling back to page size\n", + pcpu_fc_names[pcpu_chosen_fc], rc); + } + if (rc < 0) + rc =3D pcpu_page_first_chunk(PERCPU_MODULE_RESERVE, pcpu_cpu_to_node); + if (rc < 0) + panic("cannot initialize percpu area (err=3D%d)", rc); + + delta =3D (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start; + for_each_possible_cpu(cpu) + __per_cpu_offset[cpu] =3D delta + pcpu_unit_offsets[cpu]; +} +#endif --=20 2.42.0 From nobody Mon Feb 9 07:36:01 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 202B23201 for ; Thu, 11 Apr 2024 01:05:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797521; cv=none; b=Grw/6IY1XgMtuoYy6OQNC6Djtiv8rv/xH9r74NWyiWmkuGk/BT7PdOK/E9Gg6LE44XkCDcpv178D0GrkkwZYvT06p1mLmzdvo3syPs2U+qwd/5AWiLa4qBf7GG/oYuiMkVFU/0i/x24cHGOJcUvvlMMSpB2HefR03RVKtoqvS1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797521; c=relaxed/simple; bh=xo0Llg4p1LxmuJODEJTVpjH3Ymlve9IafDDhoC7HqB0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PUZO8eowuLQvxI/I5SIpkAZd3lVEexDSA8B8g+v00O5vpcULv28oLEqerndPEj+5/YWLnyqs8YGKCKYFNzW+6F7tw9ChRdyfreWD+x+i0ODvZK/MvmXjBHB3xlSgqkLrB7JEFkLjlvObrlYMKecrJQ0AgUnN3802SclFtTdO4Fc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8AxhrlMNxdm9JAlAA--.4978S3; Thu, 11 Apr 2024 09:05:16 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxhhFHNxdmnrx3AA--.22869S4; Thu, 11 Apr 2024 09:05:15 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Thomas Gleixner , Arnd Bergmann , Marc Zyngier Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, loongson-kernel@lists.loongnix.cn Subject: [PATCH v3 2/4] LoongArch: Refactor get_acpi_id_for_cpu() related code Date: Thu, 11 Apr 2024 09:05:08 +0800 Message-ID: <20240411010510.22135-3-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240411010510.22135-1-yangtiezhu@loongson.cn> References: <20240411010510.22135-1-yangtiezhu@loongson.cn> 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-CM-TRANSID: AQAAf8AxhhFHNxdmnrx3AA--.22869S4 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW7uFWkuFyxWrW3Kw1kZF4rCrX_yoW8tF15pF nFyryDJrW8WFySkrWDJw4fWry5Jw1DCa4Sq3W2ka45AF47ur15Xr93tryqgFWqgw4rKw4S vrn3JF1YkFWUXwcCm3ZEXasCq-sJn29KB7ZKAUJUUUUx529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1a6r1DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUAVWUtwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWr XwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxkF7I0En4kS14v26r126r1DMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMxCIbckI1I0E14v26r126r1DMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwV AFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv2 0xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4 v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AK xVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU14v3UUUUUU== Content-Type: text/plain; charset="utf-8" Currently, cpu_logical_map(cpu) is defined as __cpu_logical_map[cpu] in arch/loongarch/include/asm/smp.h and __cpu_logical_map[] is defined in arch/loongarch/kernel/smp.c, that is to say, cpu_logical_map(cpu) is vaild only under CONFIG_SMP, the implementation of get_acpi_id_for_cpu() which calls cpu_logical_map(cpu) is not suitable for the case of non-SMP, so refactor get_acpi_id_for_cpu() related code to make it work well for both SMP and non-SMP. Signed-off-by: Tiezhu Yang --- arch/loongarch/include/asm/acpi.h | 7 ++++++- arch/loongarch/kernel/acpi.c | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/arch/loongarch/include/asm/acpi.h b/arch/loongarch/include/asm= /acpi.h index 49e29b29996f..a4ad3f75bd60 100644 --- a/arch/loongarch/include/asm/acpi.h +++ b/arch/loongarch/include/asm/acpi.h @@ -39,9 +39,14 @@ extern struct acpi_madt_core_pic acpi_core_pic[MAX_CORE_= PIC]; =20 extern int __init parse_acpi_topology(void); =20 +static inline struct acpi_madt_core_pic *acpi_cpu_get_core_pic(int cpu) +{ + return &acpi_core_pic[cpu]; +} + static inline u32 get_acpi_id_for_cpu(unsigned int cpu) { - return acpi_core_pic[cpu_logical_map(cpu)].processor_id; + return acpi_cpu_get_core_pic(cpu)->processor_id; } =20 #endif /* !CONFIG_ACPI */ diff --git a/arch/loongarch/kernel/acpi.c b/arch/loongarch/kernel/acpi.c index 5cf59c617126..ccfa90faf0ea 100644 --- a/arch/loongarch/kernel/acpi.c +++ b/arch/loongarch/kernel/acpi.c @@ -98,8 +98,15 @@ acpi_parse_processor(union acpi_subtable_headers *header= , const unsigned long en return -EINVAL; =20 acpi_table_print_madt_entry(&header->common); + + /* + * When CONFIG_SMP is disabled, mapping won't be created for all cpus. + * CPUs more than num_possible_cpus will be ignored. + */ + if (processor->core_id >=3D 0 && processor->core_id < num_possible_cpus()) + acpi_core_pic[processor->core_id] =3D *processor; + #ifdef CONFIG_SMP - acpi_core_pic[processor->core_id] =3D *processor; set_processor_mask(processor->core_id, processor->flags); #endif =20 --=20 2.42.0 From nobody Mon Feb 9 07:36:01 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DCFE360B9D for ; Thu, 11 Apr 2024 01:05:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797522; cv=none; b=aaAkKoOQEDSp4XEgf/zlZ2VCff9GoAbwXI2zwNSktG2fDjpRquKR6No/IyRL37LCDngGAecyKtTcP2leIBLLKrhuJCKK/n1i2w/jepctjJWHroWWnwxx8FYr1Y74g+tO4bHMHaGnUyWMDIYUoxSCWkoWS6J9xJo7oPAk24C8gbg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797522; c=relaxed/simple; bh=uLjUWodJ/mW4SI5I2DSTZyWJ+aNR+7qDAvJxBsFdLtQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HBb8qQXbplr2YaayKO5O70yG/X1S51VoK+Q/w4QqJkF63gpvL3CTcaxR3kdGaQA1wWDr6/2Hp28t9XMhjfyJrxnvsGHIghVGruTn5AgMl5GTkaMFr3i6KDnM/hCT0F7x4Ye2vblPgX/u1XZPJ4eoPMton8wjU08SP4w9r7sjfwM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8AxhrlMNxdm9pAlAA--.4979S3; Thu, 11 Apr 2024 09:05:16 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxhhFHNxdmnrx3AA--.22869S5; Thu, 11 Apr 2024 09:05:15 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Thomas Gleixner , Arnd Bergmann , Marc Zyngier Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, loongson-kernel@lists.loongnix.cn Subject: [PATCH v3 3/4] LoongArch: Save and restore PERCPU_BASE_KS for ACPI S3 state Date: Thu, 11 Apr 2024 09:05:09 +0800 Message-ID: <20240411010510.22135-4-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240411010510.22135-1-yangtiezhu@loongson.cn> References: <20240411010510.22135-1-yangtiezhu@loongson.cn> 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-CM-TRANSID: AQAAf8AxhhFHNxdmnrx3AA--.22869S5 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW7WFyxAF4UCw13tFW8JF43Arc_yoW8CrWUpr 9FyFWDKw48tFn7CF90qa1UXr1UZ39agrWIqF9Fk3yj9rnrXry8Wr4rK3Z8XF10qwn5ua10 v3ySya4avF1UGwcCm3ZEXasCq-sJn29KB7ZKAUJUUUUx529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r126r13M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUAVWUtwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWr XwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxkF7I0En4kS14v26r126r1DMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMxCIbckI1I0E14v26r126r1DMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwV AFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv2 0xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4 v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AK xVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU8Gii3UUUUU== Content-Type: text/plain; charset="utf-8" Currently, per_cpu_offset(x) is defined as __per_cpu_offset[x]) only under CONFIG_SMP in include/asm-generic/percpu.h, that is to say, the implementation of loongarch_common_resume() which calls per_cpu_offset(0) is not suitable for the case of non-SMP, so do not write per_cpu_offset(0) to PERCPU_BASE_KS when resume, just save the value of PERCPU_BASE_KS when suspend and restore it when resume to make it work well for both SMP and non-SMP. Tested with the command "rtcwake -d rtc1 -s 20 -m mem -v", dmesg shows that "PM: suspend entry (deep)" and "PM: suspend exit". Signed-off-by: Tiezhu Yang --- arch/loongarch/power/suspend.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/loongarch/power/suspend.c b/arch/loongarch/power/suspend.c index 166d9e06a64b..7a97949ddade 100644 --- a/arch/loongarch/power/suspend.c +++ b/arch/loongarch/power/suspend.c @@ -16,6 +16,7 @@ #include =20 u64 loongarch_suspend_addr; +static u64 saved_pcpu_base; =20 struct saved_registers { u32 ecfg; @@ -36,6 +37,7 @@ void loongarch_common_suspend(void) saved_regs.pwctl1 =3D csr_read32(LOONGARCH_CSR_PWCTL1); saved_regs.ecfg =3D csr_read32(LOONGARCH_CSR_ECFG); saved_regs.euen =3D csr_read32(LOONGARCH_CSR_EUEN); + saved_pcpu_base =3D csr_read64(PERCPU_BASE_KS); =20 loongarch_suspend_addr =3D loongson_sysconf.suspend_addr; } @@ -44,7 +46,7 @@ void loongarch_common_resume(void) { sync_counter(); local_flush_tlb_all(); - csr_write64(per_cpu_offset(0), PERCPU_BASE_KS); + csr_write64(saved_pcpu_base, PERCPU_BASE_KS); csr_write64(eentry, LOONGARCH_CSR_EENTRY); csr_write64(eentry, LOONGARCH_CSR_MERRENTRY); csr_write64(tlbrentry, LOONGARCH_CSR_TLBRENTRY); --=20 2.42.0 From nobody Mon Feb 9 07:36:01 2026 Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 65B4E60EDC for ; Thu, 11 Apr 2024 01:05:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=114.242.206.163 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797523; cv=none; b=Elq3HudpSzfBWTF+bsBfb7zOjiWAJrJ33S/Ncqm4eOaxmsew9k4Lhl1kDfsAJFXtjvcuoKGjr1xEl9+S+a8+3cqIYusCw+d9dTpx0SccFalC0ogaatsn9X22wNDUJ+Cp+bAStDoQmGQM8+aDxioXy5/bG40Mw1qUficwFZJ4oqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712797523; c=relaxed/simple; bh=bUZXht1r8Me2Bybf8H3aka3zwa4D+6HaPcSWY3c8kLQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RFHYd5R8KU9XPVtfdlKF+bX/lCc9QqFNAS5E6rZzFpUJZAcn7i0WAAmBv+ftub8xrCbayirMLdGiEk5iYdMf6Wv5bS/nbzfDAXzV7KqUW7BbdL/fCb7TK6ub7+BLyF2n7mYmDNFfjx4R1Bflz4ZZDGJix0YQZSPOe1kQSgODSUk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn; spf=pass smtp.mailfrom=loongson.cn; arc=none smtp.client-ip=114.242.206.163 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=loongson.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=loongson.cn Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8BxuvBPNxdm_pAlAA--.20590S3; Thu, 11 Apr 2024 09:05:19 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxhhFHNxdmnrx3AA--.22869S6; Thu, 11 Apr 2024 09:05:16 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , Thomas Gleixner , Arnd Bergmann , Marc Zyngier Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org, loongson-kernel@lists.loongnix.cn Subject: [PATCH v3 4/4] LoongArch: Give chance to build under !CONFIG_SMP Date: Thu, 11 Apr 2024 09:05:10 +0800 Message-ID: <20240411010510.22135-5-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240411010510.22135-1-yangtiezhu@loongson.cn> References: <20240411010510.22135-1-yangtiezhu@loongson.cn> 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-CM-TRANSID: AQAAf8AxhhFHNxdmnrx3AA--.22869S6 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBj93XoW3Jr4UKFWDJw4kZF13Xw4DZFc_yoW7uF4UpF WDAr4DJr4rWr1vyryqy3yfWr98Jr1kGay2qF17Cay8JFsrX34UXr1kKwnFqFyUKwsYgFWI qFn3W3WaqF45AwbCm3ZEXasCq-sJn29KB7ZKAUJUUUUx529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3Ic02F40EFcxC0VAKzVAqx4xG6I80ebIjqfuFe4nvWSU5nxnvy29KBjDU 0xBIdaVrnRJUUUBYb4IE77IF4wAFF20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2 IYs7xG6rWj6s0DM7CIcVAFz4kK6r1Y6r17M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48v e4kI8wA2z4x0Y4vE2Ix0cI8IcVAFwI0_Xr0_Ar1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI 0_Gr0_Cr1l84ACjcxK6I8E87Iv67AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_ Gr0_Gr1UM2kKe7AKxVWUAVWUtwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYI kI8VC2zVCFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUtVWr XwAv7VC2z280aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI4 8JMxkF7I0En4kS14v26r126r1DMxAIw28IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j 6r4UMxCIbckI1I0E14v26r126r1DMI8I3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwV AFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv2 0xvE14v26ryj6F1UMIIF0xvE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwCI42IY6xAIw20EY4 v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Gr0_Cr1lIxAIcVC2z280aVCY1x0267AK xVW8JVW8JrUvcSsGvfC2KfnxnUUI43ZEXa7IU8_gA5UUUUU== Content-Type: text/plain; charset="utf-8" In the current code, SMP is selected in Kconfig for LoongArch, the users can not unset it, this is reasonable for a multiprocessor machine. But as the help info of config SMP said, if you have a system with only one CPU, say N. On a uniprocessor machine, the kernel will run faster if you say N here. The Loongson-2K0500 is a single-core CPU for applications like industrial control, printing terminals, and BMC (Baseboard Management Controller), there are many development boards, products and solutions on the market, so it is better and necessary to give a chance to build under !CONFIG_SMP for a uniprocessor machine. First of all, do not select SMP for config LOONGARCH in Kconfig to make it possible to unset CONFIG_SMP. Then, do some changes to fix the warnings and errors if CONFIG_SMP is not set. (1) Define get_ipi_irq() only if CONFIG_SMP is set to fix the warning: arch/loongarch/kernel/irq.c:90:19: warning: 'get_ipi_irq' defined but not u= sed [-Wunused-function] (2) Add "#ifdef CONFIG_SMP" in asm/smp.h to fix the warning: ./arch/loongarch/include/asm/smp.h:49:9: warning: "raw_smp_processor_id" re= defined 49 | #define raw_smp_processor_id raw_smp_processor_id | ^~~~~~~~~~~~~~~~~~~~ ./include/linux/smp.h:198:9: note: this is the location of the previous def= inition 198 | #define raw_smp_processor_id() 0 (3) Define machine_shutdown() as empty under !CONFIG_SMP to fix the error: arch/loongarch/kernel/machine_kexec.c: In function 'machine_shutdown': arch/loongarch/kernel/machine_kexec.c:233:25: error: implicit declaration o= f function 'cpu_device_up'; did you mean 'put_device'? [-Wimplicit-function= -declaration] (4) Make config SCHED_SMT depends on SMP to fix many errors such as: kernel/sched/core.c: In function 'sched_core_find': kernel/sched/core.c:310:43: error: 'struct rq' has no member named 'cpu' (5) Define cpu_logical_map(cpu) as read_csr_cpuid() under !CONFIG_SMP in asm/smp.h and then include asm/smp.h in asm/acpi.h (because acpi.h is included in linux/irq.h indirectly) to fix many build errors under drivers/irqchip such as: drivers/irqchip/irq-loongson-eiointc.c: In function 'cpu_to_eio_node': drivers/irqchip/irq-loongson-eiointc.c:59:16: error: implicit declaration o= f function 'cpu_logical_map' [-Wimplicit-function-declaration] When running the UnixBench tests with "-c 1" single-streamed pass, the improvement in performance is about 9 percent with this patch. By the way, it is helpful to debug and analysis the kernel issue of multi-core system under !CONFIG_SMP. Signed-off-by: Tiezhu Yang --- arch/loongarch/Kconfig | 2 +- arch/loongarch/include/asm/acpi.h | 1 + arch/loongarch/include/asm/smp.h | 5 +++++ arch/loongarch/kernel/irq.c | 2 ++ arch/loongarch/kernel/machine_kexec.c | 2 +- 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig index 64052ae2c2af..8946945daf34 100644 --- a/arch/loongarch/Kconfig +++ b/arch/loongarch/Kconfig @@ -174,7 +174,6 @@ config LOONGARCH select PCI_QUIRKS select PERF_USE_VMALLOC select RTC_LIB - select SMP select SPARSE_IRQ select SYSCTL_ARCH_UNALIGN_ALLOW select SYSCTL_ARCH_UNALIGN_NO_WARN @@ -420,6 +419,7 @@ config EFI_STUB =20 config SCHED_SMT bool "SMT scheduler support" + depends on SMP default y help Improves scheduler's performance when there are multiple diff --git a/arch/loongarch/include/asm/acpi.h b/arch/loongarch/include/asm= /acpi.h index a4ad3f75bd60..5174063ad08e 100644 --- a/arch/loongarch/include/asm/acpi.h +++ b/arch/loongarch/include/asm/acpi.h @@ -8,6 +8,7 @@ #ifndef _ASM_LOONGARCH_ACPI_H #define _ASM_LOONGARCH_ACPI_H =20 +#include #include =20 #ifdef CONFIG_ACPI diff --git a/arch/loongarch/include/asm/smp.h b/arch/loongarch/include/asm/= smp.h index f81e5f01d619..1ec11b57e60c 100644 --- a/arch/loongarch/include/asm/smp.h +++ b/arch/loongarch/include/asm/smp.h @@ -6,6 +6,7 @@ #ifndef __ASM_SMP_H #define __ASM_SMP_H =20 +#ifdef CONFIG_SMP #include #include #include @@ -101,4 +102,8 @@ static inline void __cpu_die(unsigned int cpu) } #endif =20 +#else /* !CONFIG_SMP */ +#define cpu_logical_map(cpu) read_csr_cpuid() +#endif /* CONFIG_SMP */ + #endif /* __ASM_SMP_H */ diff --git a/arch/loongarch/kernel/irq.c b/arch/loongarch/kernel/irq.c index 883e5066ae44..e791fa275ec5 100644 --- a/arch/loongarch/kernel/irq.c +++ b/arch/loongarch/kernel/irq.c @@ -87,6 +87,7 @@ static void __init init_vec_parent_group(void) acpi_table_parse(ACPI_SIG_MCFG, early_pci_mcfg_parse); } =20 +#ifdef CONFIG_SMP static int __init get_ipi_irq(void) { struct irq_domain *d =3D irq_find_matching_fwnode(cpuintc_handle, DOMAIN_= BUS_ANY); @@ -96,6 +97,7 @@ static int __init get_ipi_irq(void) =20 return -EINVAL; } +#endif =20 void __init init_IRQ(void) { diff --git a/arch/loongarch/kernel/machine_kexec.c b/arch/loongarch/kernel/= machine_kexec.c index 2dcb9e003657..8ae641dc53bb 100644 --- a/arch/loongarch/kernel/machine_kexec.c +++ b/arch/loongarch/kernel/machine_kexec.c @@ -225,6 +225,7 @@ void crash_smp_send_stop(void) =20 void machine_shutdown(void) { +#ifdef CONFIG_SMP int cpu; =20 /* All CPUs go to reboot_code_buffer */ @@ -232,7 +233,6 @@ void machine_shutdown(void) if (!cpu_online(cpu)) cpu_device_up(get_cpu_device(cpu)); =20 -#ifdef CONFIG_SMP smp_call_function(kexec_shutdown_secondary, NULL, 0); #endif } --=20 2.42.0