Skip to content

Thread preemption policy #1410

Description

@georgeklees

Currently on x86, a thread that gets unblocked is enqueued with scheduler_enqueue(). scheduler_enqueue() places it on a CPU's queue, where it will then be executed by that CPU once it invokes its scheduler (through yielding or a timer interrupt). But this behavior isn't always optimal, since if a higher priority thread gets scheduled on that CPU than what it's currently running, the higher priority thread should preempt it.

This preemption behavior should probably be added to scheduler_enqueue(). scheduler_enqueue() takes (or is planned to take) several factors into account to determine which CPU to schedule a thread on, and the priority of the currently running thread could be another. Once the function picks a CPU and adds it to the queue, it should check if preemption is necessary and apply it as follows:
-If the CPU chosen is the current one, reschedule immediately
-If a different CPU gets chosen, send a rescheduling IPI

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions