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

Re: [PATCH v3 2/2] x86/mwait-idle: squash stats update when not actually entering C-state


  • To: Jan Beulich <jbeulich@xxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Tue, 1 Feb 2022 12:04:23 +0100
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=tRk7Pr9VrtrcE+pq75pNFroRdOWz6kG2YK+mKpsPAWs=; b=KmzvKGyBtbQCM2xxGUEx9sHbhhbavSdc5iHl9iioJPwq7t2prTaMtscRS2xN539fgfSqBZPJbST72F/04GCGVM3gb+hqFiMHU0VU3WCDgHcN0IYvJn+R6UG4NdRLjNdqFAFe8nFwryaxiS7605ry+KbPbtUsdJ2jvzLDp0IX22raZl6Al547kcT4QL2m9SSBeOtoTTRUkJP5BiGk676QFBGuR6qwiMGkg8C0d8PhfhS6awapbYCWnlMLsyK4vhQR/DelOcrTZnY0HCJSjLLsW3ArxEAbitdnDCYz+L6dREUt4TtJzxM2X3r0bW9BfGWZODs7R/rawYU9VY0J2o66ew==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WjlUgElF5Se8UGHM+Jo6PE4TgEr3JOtvI3VcOrSO5jVGHUCDTxK2U4qX3ENeST8iA+pitP8xIXWDmuKMtecC2w39eMzcL+KcTgBrd0B9i8cswyFrbzgCaLRRxEfnrlw5RvUUPbu7PYdTOL1dV2dyt0EspLTxXfsyiSBRq7TwaGp6niiGJfLJNb8MHIFNPGRMUewRRV0/PcrUeFprysEzC666HxvySa08XHEZ1El1jLAK3V7LC9GKlnMU+0I90RSb18CAcOiXAONBJaqnPVaV0E1SQ2ZK/62mke/B6jbXukHjrmEh/5ppoEfOTCPz62hioe7IueGYEFbR2yBtHRhmDw==
  • Authentication-results: esa3.hc3370-68.iphmx.com; dkim=pass (signature verified) header.i=@citrix.onmicrosoft.com
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, "Andrew Cooper" <andrew.cooper3@xxxxxxxxxx>, Wei Liu <wl@xxxxxxx>
  • Delivery-date: Tue, 01 Feb 2022 11:04:48 +0000
  • Ironport-data: A9a23:M5epDauCFEH5mRuX4GrhbeOt2OfnVLBZMUV32f8akzHdYApBsoF/q tZmKTjVPqmNYmL1Lt0lb4qx/E8GvZ7dy99qHgtlrSA0Fn8R+JbJXdiXEBz9bniYRiHhoOOLz Cm8hv3odp1coqr0/0/1WlTZQP0VOZigHtIQMsadUsxKbVIiGHdJZS5LwbZj2NYy2YHhWmthh PupyyHhEA79s9JLGjp8B5Kr8HuDa9yr5Vv0FnRnDRx6lAe2e0s9VfrzFonoR5fMeaFGH/bSe gr25OrRElU1XfsaIojNfr7TKiXmS1NJVOSEoiI+t6OK2nCuqsGuu0qS2TV1hUp/0l20c95NJ Npl7oehTTYlIqL3nr4keUF5TXxaGp909+qSSZS/mZT7I0zudnLtx7NlDV0sPJ1e8eFyaY1M3 aVGcnZXNEnF3r/ohuLgIgVvrp1LwM3DJoQQt2sm1TjEJf0nXYrCU+PB4towMDIY2JsURa+CO JtxhTxHcwnMWDdlIHorV48mwbuOv3CmL2xykQfAzUYwyzeKl1EguFT3C/LKfvSaSMMTmVyXz krW8mK8DhwEOdi3zTue7mnqluLJhTn8Wo8ZCPu/7PECqF+Zy3EXCRYWfUCmuvT/gUm7M++zM GRNpHBo9/JrshX2EJ+tBHVUvUJooDZHQMtUIuEm5zqLkJP+uyfHW0wjfAxOPYlOWNANeRQm0 VqAntXMDDNpsaGIRX/1yop4vQ9eKgBOczZcOHZ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Wd9dP0E/M 323Ls5m9PsQwVdUu2LQl0+G8TTrdzCk5zrJTYAGh4c8QGLyRel8qTzHRS01goXF2on+8ZuzU H11yjCoomzufCyzRHRk0fV8pRtgdPkjv9OHtaFhMQ5IijlziyoeINicbufuy1dmpDk1H8a1P 335zswNcV67H3cOkmzvBvWwgHllA0j7nfzoGXo90fLkIjcfnYXGsBBjYVWfl/y8Ew7puxx16 pNwiawq4dXJQmoplWy2/H4EzVR0makq3srluAey1ZFV5EFVbNXpYsDuGtIDZY7Gj7g4oxPKp ggMCjl3ocXTbqmVQGbgoE2q+bcHEjbXy32DnTqg/blkgS/xxtCvg4lLM92pAZ2yHtycegB2w 3+CNUaqFh5dL5jUUtMPpZwfSKJMB2+ffvtChPaHb21LtBOB5ryw6SHlYndotvaP6A18A==
  • Ironport-sdr: og8U2H0Qz3Gt9cOgeyWeD5F5UaDEBgaT85D9acbasBiXAOuy5o67OjXMlvywlHziER66or8uWO mJuwf9Csjd8VVj56Lw6uPzXqNbmE/9CdEqVDVNWqFTlyMdSrSzQBcePuNcMxYZaCufxO7sURo7 KvS5EX+TgSxBwsclNkPBkavDpBytuSoGAnlRNlLKOBKyTDyE9x4VdmbOGLAreUVyf0Dh1bgx1E c5lKVZpLTNAmqb2SJCWekFr/szExQQDSB3cgecm/cpmJtJomVGA9d406RyIf5tVZ2S3XL/dYcx MqldsFafLhq8jMmznxk2W/7c
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Thu, Jan 27, 2022 at 04:13:47PM +0100, Jan Beulich wrote:
> While we don't want to skip calling update_idle_stats(), arrange for it
> to not increment the overall time spent in the state we didn't really
> enter.
> 
> Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
> ---
> RFC: If we wanted to also move the tracing, then I think the part ahead
>      of the if() also would need moving. At that point we could as well
>      move update_last_cx_stat(), too, which afaict would allow skipping
>      update_idle_stats() on the "else" path (which therefore would go
>      away). Yet then, with the setting of power->safe_state moved up a
>      little (which imo it should have been anyway) the two
>      cpu_is_haltable() invocations would only have the lapic_timer_off()
>      invocation left in between. This would then seem to call for simply
>      ditching the 2nd one - acpi-idle also doesn't have a 2nd instance.

It's possible for lapic_timer_off to take a non-trivial amount of time
when virtualized, but it's likely we won't be using mwait in that
case, so not sure it matter much to have the two cpu_is_haltable calls
if there's just a lapic_timer_off between them.

> TBD: For the tracing I wonder if that really needs to come ahead of the
>      local_irq_enable(). Maybe trace_exit_reason() needs to, but quite
>      certainly TRACE_6D() doesn't.

Would be good if it could be moved after the local_irq_enable call, as
it's not as trivial as I've expected, and will just add latency to any
pending interrupt waiting to be serviced. FWIW, I haven't spotted a
need to call it with interrupt disabled.

> ---
> v3: Also move cstate_restore_tsc() invocation and split ones to
>     update_idle_stats().
> v2: New.
> 
> --- a/xen/arch/x86/cpu/mwait-idle.c
> +++ b/xen/arch/x86/cpu/mwait-idle.c
> @@ -854,17 +854,23 @@ static void mwait_idle(void)
>               mwait_idle_with_hints(cx->address, MWAIT_ECX_INTERRUPT_BREAK);
>  
>               local_irq_disable();
> -     }
>  
> -     after = alternative_call(cpuidle_get_tick);
> +             after = alternative_call(cpuidle_get_tick);
> +
> +             cstate_restore_tsc();
> +
> +             /* Now back in C0. */
> +             update_idle_stats(power, cx, before, after);
> +     } else {
> +             /* Never left C0. */
> +             after = alternative_call(cpuidle_get_tick);
> +             update_idle_stats(power, cx, after, after);

While adjusting this, could you also modify update_idle_stats to avoid
increasing cx->usage if before == after (or !sleep_ticks). I don't
think it's fine to increase the state counter if we never actually
entered it.

I was also going to suggest that you don't set 'after' and just use
update_idle_stats(power, cx, before, before); but seeing as TRACE_6D
also makes use of 'after' there's not much point without further
rework. I also see the RFC note at the top, so while I think this is
an improvement, I agree it would be nice to avoid the trace altogether
if we never actually enter the state. If you want to rework the patch
or send a followup that's fine for me.

Thanks, Roger.



 


Rackspace

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