[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] x86: increase NMI timer frequency if necessary


  • To: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Wed, 20 Mar 2024 08:28:23 +0100
  • Autocrypt: addr=jbeulich@xxxxxxxx; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJuMBS8rnNg22uyfAgmBKNLpLgAGVRMZGaGoJObGf72s6TeIqKJo/LtggAS9qAUiuKVnygo 3wjfkS9A3DRO+SpU7JqWdsveeIQyeyEJ/8PTowmSQLakF+3fote9ybzd880fSmFuIEJldWxp Y2ggPGpiZXVsaWNoQHN1c2UuY29tPsJgBBMRAgAgBQJZN5xEAhsDBgsJCAcDAgQVAggDBBYC AwECHgECF4AACgkQoDSui/t3IH4J+wCfQ5jHdEjCRHj23O/5ttg9r9OIruwAn3103WUITZee e7Sbg12UgcQ5lv7SzsFNBFk3nEQQCACCuTjCjFOUdi5Nm244F+78kLghRcin/awv+IrTcIWF hUpSs1Y91iQQ7KItirz5uwCPlwejSJDQJLIS+QtJHaXDXeV6NI0Uef1hP20+y8qydDiVkv6l IreXjTb7DvksRgJNvCkWtYnlS3mYvQ9NzS9PhyALWbXnH6sIJd2O9lKS1Mrfq+y0IXCP10eS FFGg+Av3IQeFatkJAyju0PPthyTqxSI4lZYuJVPknzgaeuJv/2NccrPvmeDg6Coe7ZIeQ8Yj t0ARxu2xytAkkLCel1Lz1WLmwLstV30g80nkgZf/wr+/BXJW/oIvRlonUkxv+IbBM3dX2OV8 AmRv1ySWPTP7AAMFB/9PQK/VtlNUJvg8GXj9ootzrteGfVZVVT4XBJkfwBcpC/XcPzldjv+3 HYudvpdNK3lLujXeA5fLOH+Z/G9WBc5pFVSMocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL
  • Cc: Wei Liu <wl@xxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • Delivery-date: Wed, 20 Mar 2024 07:28:33 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 19.03.2024 21:51, Andrew Cooper wrote:
> On 25/01/2024 4:55 pm, Jan Beulich wrote:
>> Since the performance counters used for the NMI watchdog count non-
>> halted cycles, they may count at a rate higher than cpu_khz.
> 
> Is this in theory, or observed in practice?

It's been over two months since doing the experiments, so I can only go
from memory, but my recollection is that I actually observed higher
rates, just not high enough (yet) for the watchdog (without this change)
to start malfunctioning.

> It is my understanding that perf counters count in P0 reference cycles,
> and not at the Turbo/CBS rate.
> 
>>  Thus the
>> watchdog tick may occur more frequently than invocations of the timer
>> if we don't account for the ratio between nominal and maximum CPU clock
>> speeds, which would be a problem in particular when "watchdog_timeout=1"
>> is in effect (for high enough ratios even larger timout values may pose
>> a problem).
>>
>> Leverage the so far display-only data we collect on newer Intel and AMD
>> CPUs. On older CPUs we just have to (continue to) hope that the default
>> frequency of 1 Hz is okay(-ish) to use.
>>
>> While adding the new variable, also move the (now adjacent) cpu_khz to
>> .data.ro_after_init.
>>
>> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
>> ---
>> This renders the "log" in the function names somewhat stale, but I don't
>> think this strictly warrants renaming the functions right away.
> 
> I'm not comfortable with this change.  It's adding to a complicated
> timing problem, rather than simplifying it.

The actual change to the watchdog logic is minimal - a build-time constant
is replaced by a boot-time determined value.

> The real problem we've got is that the NMI handler is guessing at the
> timeout by counting NMIs, not by actually counting time.  There are
> several ways to fix this even with the current rendezvous logic.  When
> the NMI handler can actually say "if ( NOW() - last > timeout )", then
> the exact frequently of NMIs becomes far less important.

But that would come with its own downsides: The logic within the NMI
handler should be as simple as possible, involving as little as possible
other code. NOW(), for example, cannot really be used there without
first fiddling with the time rendezvous (to make sure an NMI hitting in
the middle of an update to the scaling values will know how to use
consistent data; that could e.g. be done by flip-flopping between two
instances of the data, with a "selector" always flipped last).

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.