Skip to content

Conversation

copybara-service[bot]
Copy link

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.

@copybara-service copybara-service bot added the exported Issue was exported automatically label Sep 11, 2025
@copybara-service copybara-service bot force-pushed the test/cl805619701 branch 4 times, most recently from 1ca3ad8 to e612003 Compare September 11, 2025 18:04
…xceeded

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
@copybara-service copybara-service bot merged commit 57697a8 into master Sep 11, 2025
@copybara-service copybara-service bot deleted the test/cl805619701 branch September 11, 2025 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
exported Issue was exported automatically
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant