This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 23bceff629eced36119e68cd9410763165abbef2
Author: buxiasen <[email protected]>
AuthorDate: Mon Sep 15 12:02:53 2025 +0800

    sched: add PERCPU_METHOD to help improve the percpu locate & performance
    
    Currently we using array to expand the SMP_NCPUS, will not efficiency
    for cache line. Also if we bring bmp into kernel, need a section percpu
    dispatch method. We should add a common percpu method as a prefix.
    
    Signed-off-by: buxiasen <[email protected]>
---
 include/nuttx/percpu.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
 sched/Kconfig          |  9 ++++++++
 2 files changed, 68 insertions(+)

diff --git a/include/nuttx/percpu.h b/include/nuttx/percpu.h
new file mode 100644
index 00000000000..9b626e21b7b
--- /dev/null
+++ b/include/nuttx/percpu.h
@@ -0,0 +1,59 @@
+/****************************************************************************
+ * include/nuttx/percpu.h
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_PERCPU_H
+#define __INCLUDE_NUTTX_PERCPU_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+#include <nuttx/irq.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifdef CONFIG_PERCPU_ARRAY
+#  define DEFINE_PER_CPU(t, v)         t v[CONFIG_NCPUS]
+#  define DEFINE_PER_CPU_BSS(t, v)     t v[CONFIG_NCPUS]
+#  define DECLARE_PER_CPU(t, v)        extern t v[CONFIG_NCPUS]
+#  define per_cpu_var(v, c)            v[c]
+#  define this_cpu_var(v)              per_cpu_var(v, up_cpu_index())
+#endif
+
+#ifdef CONFIG_SMP
+#  define DEFINE_PER_CPU_SMP(t, v)     DEFINE_PER_CPU(t, v)
+#  define DEFINE_PER_CPU_BSS_SMP(t, v) DEFINE_PER_CPU_BSS(t, v)
+#  define DECLARE_PER_CPU_SMP(t, v)    DECLARE_PER_CPU(t, v)
+#  define per_cpu_var_smp(v, c)        per_cpu_var(v, c)
+#  define this_cpu_var_smp(v)          this_cpu_var(v)
+#else
+#  define DEFINE_PER_CPU_SMP(t, v)     t v[1]
+#  define DEFINE_PER_CPU_BSS_SMP(t, v) t v[1]
+#  define DECLARE_PER_CPU_SMP(t, v)    extern t v[1]
+#  define per_cpu_var_smp(v, c)        v[0]
+#  define this_cpu_var_smp(v)          v[0]
+#endif
+
+#endif
diff --git a/sched/Kconfig b/sched/Kconfig
index 2eb958d0ee5..efb021cb5bb 100644
--- a/sched/Kconfig
+++ b/sched/Kconfig
@@ -432,6 +432,15 @@ config SMP
                CPU0 IRQ handler use thread0's stack, but thread0 may switch to 
CPU1, that
                will caused IRQ handler stack corruption.
 
+choice PERCPU_METHOD
+       prompt "Support PERCPU expand method"
+       default PERCPU_ARRAY
+
+config PERCPU_ARRAY
+       bool "Expand PERCPU to ARRAY, for SMP by default"
+
+endchoice
+
 if SMP
 
 config SMP_NCPUS

Reply via email to