On 1 August 2024 22:07:25 BST, Thomas Gleixner <t...@linutronix.de> wrote:
>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?

Yes. Well, kind of. The way I actually did it was by exposing the shutdown 
function instead of an "init" function which optionally did the opposite. But 
yes,  I left the hardware-bashing in precisely once place, in the driver.


Reply via email to