mirror of
https://github.com/hanzoai/visor.git
synced 2026-09-24 17:04:14 +00:00
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