Re: [PATCH] clockevents/drivers/i8253: Do not zero timer counter in shutdown

From: Thomas Gleixner
Date: Thu Aug 01 2024 - 17:07:40 EST


On Thu, Aug 01 2024 at 16:22, David Woodhouse wrote:
> On Thu, 2024-08-01 at 10:00 +0100, David Woodhouse wrote:
> bool __init pit_timer_init(void)
> {
> - if (!use_pit())
> + if (!use_pit()) {
> + if (!hypervisor_is_type(X86_HYPER_NATIVE)) {
> + /*
> + * Don't just ignore the PIT. Ensure it's stopped,
> + * because VMMs otherwise steal CPU time just to
> + * pointlessly waggle the (masked) IRQ.
> + */
> + raw_spin_lock(&i8253_lock);
> + outb_p(0x30, PIT_MODE);
> +
> + /*
> + * It's not entirely clear from the datasheet, but some
> + * virtual implementations don't stop until the counter
> + * is actually written.
> + */
> + if (i8253_clear_counter_on_shutdown) {
> + outb_p(0, PIT_CH0);
> + outb_p(0, PIT_CH0);
> + }
> + raw_spin_unlock(&i8253_lock);
> + }
> return false;
> + }

That's just wrong. What we want is to have the underlying problem
fixed in the driver and then make:

> clockevent_i8253_init(true);

bool clockevent_i8253_init(bool enable, bool oneshot);

so it can invoke the shutdown sequence instead of registering the pile:

if (!enable) {
shutdown();
return false;
}
...
return true;

and the call site becomes:

if (!clockevent_i8253_init(use_pit(), true))
return false;

No?

Thanks,

tglx