You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
kernel: periodically preempt tasks when platform max concurrency is exceeded
Add a new method `ConcurrencyCount()` to the `platform.Platform` interface. This
method returns the maximum number of tasks that can run in parallel on the
platform. For most platforms, this is effectively infinite (math.MaxInt). For
the KVM platform, this is the number of available vCPUs.
Introduce a new method `Preempt()` to the `platform.Context` interface. The CPU
clock ticker now checks if the number of running tasks is greater than
Platform.ConcurrencyCount(). If it is, it calls `t.p.Preempt()` on each running
task to trigger a preemption.
This mechanism ensures that on platforms with a fixed number of execution units,
like KVM with a limited number of vCPUs, tasks are periodically preempted to
allow other runnable tasks to be scheduled. This prevents any single task from
monopolizing a vCPU and improves overall fairness and responsiveness.
The `Preempt()` implementation in most platforms is a no-op. In the KVM
platform, `Preempt()` is implemented by leveraging the existing interrupt
mechanism, effectively signaling the vCPU to exit.
PiperOrigin-RevId: 805926296
0 commit comments