RTOS 的进程控制块类型是什么?

发布于 2024-09-12 22:40:45 字数 127 浏览 4 评论 0原文

我正在设计一个 RTOS,它使用基于优先级的抢占式调度程序。 PCB 包含什么?我只能提出这些项目

1)PID 2)优先级 3)程序计数器 4)状态寄存器 5)一些标志

我还应该包括截止日期吗?或任何其他字段

Im designing an RTOS which uses a priority based preemptive scheduler. What would the PCB contain? Ive only been able to come up with these items

1)PID
2)Priority
3)Program counter
4)Status registers
5)Some flags

Should I also include a deadline?Or any other fields

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

那小子欠揍 2024-09-19 22:40:45

这在某种程度上取决于您编写此代码的架构。

您需要所有寄存器[1],而不仅仅是状态寄存器。

堆栈指针。也许堆栈大小。

中断屏蔽状态

如果您的操作系统支持浮点并且您的 CPU 有浮点单元,请不要忘记也保存这些寄存器。

[1] 除非您是为 ARM 之类的东西编写此代码,因为它有多个寄存器组。此时,您只需保存正常操作时使用的银行即可。

This is somewhat dependent on the architecture you are writing this for.

You need all the registers[1], not just the status registers.

Stack pointer. Perhaps stack size.

Interrupt mask state

If your OS supports floating point and your CPU has a floating point unit, don't forget to save those registers also.

[1] Unless you are writing this for something like ARM, which has several banks of registers. In that case, you only need to save the bank used in normal operation.

第几種人 2024-09-19 22:40:45

完整的寄存器组通常保存在线程的堆栈上,这意味着您可能只需要一个堆栈指针来存储程序计数器、状态寄存器以及需要上下文切换的任何其他寄存器。

是我几个月前开源的 RTOS 的真实示例 TCB/PCB (Atomthreads)

typedef struct atom_tcb
{
    /* Thread's current stack pointer */
    POINTER sp_save_ptr;

    /* Thread priority (0-255) */
    uint8_t priority;

    /* Thread entry point and parameter */
    void (*entry_point)(uint32_t);
    uint32_t entry_param;

    /* Queue pointers */
    struct atom_tcb *prev_tcb;    /* Previous TCB in doubly-linked TCB list */
    struct atom_tcb *next_tcb;    /* Next TCB in doubly-linked list */

    /* Suspension data */
    uint8_t suspended;            /* TRUE if task is currently suspended */
    uint8_t suspend_wake_status;  /* Status returned to woken suspend calls */
    ATOM_TIMER *suspend_timo_cb;  /* Callback registered for suspension timeouts */

} ATOM_TCB;

以下 从堆栈指针来看,我需要的关键元素如下:

  • 优先级
  • 链表指针:为简单的基于队列的调度程序管理就绪队列中的线程,或处理队列等待特定信号量的线程数等。
  • 挂起状态:用于处理信号量上的挂起等操作。它们用于注册挂起超时时要调用的回调函数(例如,可以是队列库中的超时处理程序)并将状态代码传递回唤醒的线程。

这不是唯一的方法。当您开始设计 RTOS 并实现各种操作系统原语(信号量、队列等)时,您会发现自己的特定需求变得清晰。

The full register set is often saved on the thread's stack, which means that one stack pointer may be all you need to store the program counter, status registers, and any other registers which need to be context-switched.

Here is a real-world example TCB/PCB from an RTOS I open-sourced a few months ago (Atomthreads):

typedef struct atom_tcb
{
    /* Thread's current stack pointer */
    POINTER sp_save_ptr;

    /* Thread priority (0-255) */
    uint8_t priority;

    /* Thread entry point and parameter */
    void (*entry_point)(uint32_t);
    uint32_t entry_param;

    /* Queue pointers */
    struct atom_tcb *prev_tcb;    /* Previous TCB in doubly-linked TCB list */
    struct atom_tcb *next_tcb;    /* Next TCB in doubly-linked list */

    /* Suspension data */
    uint8_t suspended;            /* TRUE if task is currently suspended */
    uint8_t suspend_wake_status;  /* Status returned to woken suspend calls */
    ATOM_TIMER *suspend_timo_cb;  /* Callback registered for suspension timeouts */

} ATOM_TCB;

Apart from the stack pointer, the key elements I needed were as follows:

  • Priority
  • Linked list pointers: To manage threads in the ready queue for simple queue-based schedulers, or handle queues of threads waiting on a particular semaphore etc.
  • Suspension status: For handling actions like pending on a semaphore. These are used to register the callback function to be called if a suspension times out (which could be the timeout handler in the queue library for example) and to pass status codes back to the woken thread.

This is not the only way to do it. You will find that your own particular requirements become clear as you set out on the design of the RTOS, and implement the various OS primitives (semaphores, queues etc).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文