Sign in
Sign up
Explore
Enterprise
Education
Search
Help
Terms of use
About Us
Explore
Enterprise
Education
Gitee Premium
Gitee AI
AI teammates
Sign in
Sign up
Fetch the repository succeeded.
Open Source
>
Other
>
Operation System
&&
Donate
Please sign in before you donate.
Cancel
Sign in
Scan WeChat QR to Pay
Cancel
Complete
Prompt
Switch to Alipay.
OK
Cancel
Watch
Unwatch
Watching
Releases Only
Ignoring
15
Star
118
Fork
30
GVP
TenonOS
/
Tenon
Code
Issues
4
Pull Requests
4
Wiki
Insights
Pipelines
Service
Quality Analysis
Jenkins for Gitee
Tencent CloudBase
Tencent Cloud Serverless
悬镜安全
Aliyun SAE
Codeblitz
SBOM
DevLens
Don’t show this again
Update failed. Please try again later!
Remove this flag
Content Risk Flag
This task is identified by
as the content contains sensitive information such as code security bugs, privacy leaks, etc., so it is only accessible to contributors of this repository.
[Enhancement]: 重构lcpu结构体
Done
#IA6W8A
孙昊一
Opened this issue
2024-06-20 12:34
### 这个问题是否已经存在? - [x] 未搜索到类似问题 ### 问题描述 - tenon现状 - 共维护了三个per_cpu变量,均按cpu维护了不同的信息 1、lcpu_irqntrap_sp:存放中断栈和异常栈 2、__uk_sched_thread_current:存放当前运行线程信息 3、lcpus:存放cpu信息 - lcpus目前存放信息说明 | 成员 | 含义 | |----------------------|---------------------------------------------------------| | state | 用于记录cpu的运行状态,在start、init、halt等流程中都会更新 | | idx | lcpu变量在lcpus数组中的下标 | | id | 硬件id,如arm64中mpidr_el1的值 | | s_args、fn、error_code | cpu启动阶段使用的入口点、参数、错误码。这部分只会在启动阶段使用一次| | auxsp | 辅助栈,这里保存的是引用,实际的辅助栈在线程结构体中维护| | arch | 一般的操作系统都会提供一个架构特用的结构体,在不同的arch下自行定义,完成一些架构特有功能。默认是空结构体。 | - **重构前lcpu数据结构** ``` struct __align(CACHE_LINE_SIZE) lcpu { /* Current CPU state (LCPU_STATE_*). * Working on it with atomic instructions - must be 8-byte aligned */ volatile int state __align(8); __lcpuidx idx; __lcpuid id; union { /* Startup arguments * Only valid in LCPU_STATE_INIT */ struct lcpu_sargs s_args; /* Remote function to execute * Only valid in LCPU_STATE_IDLE and busy states */ #ifdef struct ukplat_lcpu_func fn; #endif /* CONFIG_HAVE_SMP */ /* Error code indicating the halt reason * Only valid in LCPU_STATE_HALTED */ int error_code; }; /* Auxiliary stack pointer of the thread currently executing on LCPU */ __uptr auxsp; /* Architecture-dependent part */ struct lcpu_arch arch; }; ``` ### 改进建议 - **目标** 使用lcpus,存放运行阶段所需的信息 - **可优化点** 1. 新增当前运行线程信息维护入lcpu结构体中,去除__uk_sched_thread_current变量的维护。 2. 新增中断栈、异常栈维护入lcpu结构体中。 3. 新增临界区嵌套、中断嵌套、上下文切换请求标识字段,维护入lcpu结构体中。 4. 去除auxsp引用 : 辅助栈本身维护在线程中,lcpu变量中存放的仅为引用,目前tenon的线程库、调度库绑定(即不开启调度器,则不存在线程结构体),为了适配没有调度器的场景,将辅助栈的指针存放在lcpu结构体中。 5. 去除cpu启动相关的参数:该项为启动阶段所使用的参数,在运行阶段不会被使用,所以从lcpu结构体中移除,单独维护启动参数的per_cpu变量boot_args 。 6. 去除idx号维护:由于硬件CPUID可以通过系统寄存器查询,所以该项无需维护在lcpu结构体中 - **更新lcpu结构体成员列表** | 成员 | 含义 | |------------------|----------------| | current_thread | 当前运行线程的线程结构体指针 | | critical_nested | 临界区嵌套层数 | | interrupt_nested | 中断嵌套层数 | | exception_sp | 异常栈 | | interrupt_sp | 中断栈 | | idle_thread | idle线程结构体指针 | | pending_switch | 上下文切换请求标识位 | | id | cpu数组下标 | | arch | 在不同的arch下自行定义,完成一些架构特有功能。默认是空结构体。| | state | 用于记录cpu的运行状态,在start、init、halt等流程中都会更新| - **重构后lcpu数据结构** ``` struct __align(CACHE_LINE_SIZE) lcpu { /* point to the thread currently running on this lcpu */ struct uk_thread * current_thread; /* counter for critical region */ uint32_t critical_nested; /* counter for interrupt */ uint32_t interrupt_nested; /* stack point for exception*/ uintptr_t exception_sp; /* stack point for interrupt*/ uintptr_t interrupt_sp; /* idle thread */ struct uk_thread *idle_thread; /* there's pending context switch request */ uint8_t pending_switch; /* backup of CPU ID in system register */ __lcpuid id; /* Architecture-dependent part */ struct lcpu_arch arch; /* Current CPU state (LCPU_STATE_*). * Working on it with atomic instructions - must be 8-byte aligned */ volatile int state __align(8); }; ``` ### 版本 Tenon v0.2.0
### 这个问题是否已经存在? - [x] 未搜索到类似问题 ### 问题描述 - tenon现状 - 共维护了三个per_cpu变量,均按cpu维护了不同的信息 1、lcpu_irqntrap_sp:存放中断栈和异常栈 2、__uk_sched_thread_current:存放当前运行线程信息 3、lcpus:存放cpu信息 - lcpus目前存放信息说明 | 成员 | 含义 | |----------------------|---------------------------------------------------------| | state | 用于记录cpu的运行状态,在start、init、halt等流程中都会更新 | | idx | lcpu变量在lcpus数组中的下标 | | id | 硬件id,如arm64中mpidr_el1的值 | | s_args、fn、error_code | cpu启动阶段使用的入口点、参数、错误码。这部分只会在启动阶段使用一次| | auxsp | 辅助栈,这里保存的是引用,实际的辅助栈在线程结构体中维护| | arch | 一般的操作系统都会提供一个架构特用的结构体,在不同的arch下自行定义,完成一些架构特有功能。默认是空结构体。 | - **重构前lcpu数据结构** ``` struct __align(CACHE_LINE_SIZE) lcpu { /* Current CPU state (LCPU_STATE_*). * Working on it with atomic instructions - must be 8-byte aligned */ volatile int state __align(8); __lcpuidx idx; __lcpuid id; union { /* Startup arguments * Only valid in LCPU_STATE_INIT */ struct lcpu_sargs s_args; /* Remote function to execute * Only valid in LCPU_STATE_IDLE and busy states */ #ifdef struct ukplat_lcpu_func fn; #endif /* CONFIG_HAVE_SMP */ /* Error code indicating the halt reason * Only valid in LCPU_STATE_HALTED */ int error_code; }; /* Auxiliary stack pointer of the thread currently executing on LCPU */ __uptr auxsp; /* Architecture-dependent part */ struct lcpu_arch arch; }; ``` ### 改进建议 - **目标** 使用lcpus,存放运行阶段所需的信息 - **可优化点** 1. 新增当前运行线程信息维护入lcpu结构体中,去除__uk_sched_thread_current变量的维护。 2. 新增中断栈、异常栈维护入lcpu结构体中。 3. 新增临界区嵌套、中断嵌套、上下文切换请求标识字段,维护入lcpu结构体中。 4. 去除auxsp引用 : 辅助栈本身维护在线程中,lcpu变量中存放的仅为引用,目前tenon的线程库、调度库绑定(即不开启调度器,则不存在线程结构体),为了适配没有调度器的场景,将辅助栈的指针存放在lcpu结构体中。 5. 去除cpu启动相关的参数:该项为启动阶段所使用的参数,在运行阶段不会被使用,所以从lcpu结构体中移除,单独维护启动参数的per_cpu变量boot_args 。 6. 去除idx号维护:由于硬件CPUID可以通过系统寄存器查询,所以该项无需维护在lcpu结构体中 - **更新lcpu结构体成员列表** | 成员 | 含义 | |------------------|----------------| | current_thread | 当前运行线程的线程结构体指针 | | critical_nested | 临界区嵌套层数 | | interrupt_nested | 中断嵌套层数 | | exception_sp | 异常栈 | | interrupt_sp | 中断栈 | | idle_thread | idle线程结构体指针 | | pending_switch | 上下文切换请求标识位 | | id | cpu数组下标 | | arch | 在不同的arch下自行定义,完成一些架构特有功能。默认是空结构体。| | state | 用于记录cpu的运行状态,在start、init、halt等流程中都会更新| - **重构后lcpu数据结构** ``` struct __align(CACHE_LINE_SIZE) lcpu { /* point to the thread currently running on this lcpu */ struct uk_thread * current_thread; /* counter for critical region */ uint32_t critical_nested; /* counter for interrupt */ uint32_t interrupt_nested; /* stack point for exception*/ uintptr_t exception_sp; /* stack point for interrupt*/ uintptr_t interrupt_sp; /* idle thread */ struct uk_thread *idle_thread; /* there's pending context switch request */ uint8_t pending_switch; /* backup of CPU ID in system register */ __lcpuid id; /* Architecture-dependent part */ struct lcpu_arch arch; /* Current CPU state (LCPU_STATE_*). * Working on it with atomic instructions - must be 8-byte aligned */ volatile int state __align(8); }; ``` ### 版本 Tenon v0.2.0
Comments (
0
)
Sign in
to comment
Status
Done
Backlog
Doing
Done
Canceled
Assignees
Not set
Labels
enhancement
release-v0.3.0
Not set
Projects
Unprojected
Unprojected
Milestones
Tenon_v0.3.0
No related milestones
Pull Requests
None yet
None yet
Successfully merging a pull request will close this issue.
Branches
No related branch
Branches (
-
)
Tags (
-
)
Planed to start   -   Planed to end
-
Top level
Not Top
Top Level: High
Top Level: Medium
Top Level: Low
Priority
Not specified
Serious
Main
Secondary
Unimportant
Duration
(hours)
参与者(1)
C
1
https://gitee.com/tenonos/tenon.git
git@gitee.com:tenonos/tenon.git
tenonos
tenon
Tenon
Going to Help Center
Search
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
Comment
Repository Report
Back to the top
Login prompt
This operation requires login to the code cloud account. Please log in before operating.
Go to login
No account. Register