All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xenproject.org>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Jan Beulich" <JBeulich@suse.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>, "Wei Liu" <wl@xen.org>
Subject: [PATCH v2 05/12] x86/hvm: Remove duplicate calls caused by tracing
Date: Mon, 20 Sep 2021 18:25:22 +0100	[thread overview]
Message-ID: <20210920172529.24932-6-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <20210920172529.24932-1-andrew.cooper3@citrix.com>

1) vpic_ack_pending_irq() calls vlapic_accept_pic_intr() twice, once in the
   TRACE_2D() instantiation and once "for real".  Make the call only once.

2) vlapic_accept_pic_intr() similarly calls __vlapic_accept_pic_intr() twice,
   although this is more complicated to disentangle.

   v cannot be NULL because it has already been dereferenced in the function,
   causing the ternary expression to always call __vlapic_accept_pic_intr().
   However, the return expression of the function takes care to skip the call
   if this vCPU isn't the PIC target.  As __vlapic_accept_pic_intr() is far
   from trivial, make the TRACE_2D() semantics match the return semantics by
   only calling __vlapic_accept_pic_intr() when the vCPU is the PIC target.

3) hpet_set_timer() duplicates calls to hpet_tick_to_ns().  Pull the logic out
   which simplifies both the TRACE and create_periodic_time() calls.

4) lapic_rearm() makes multiple calls to vlapic_lvtt_period().  Pull it out
   into a local variable.

vlapic_accept_pic_intr() is called on every VMEntry, so this is a reduction in
VMEntry complexity across the board.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Wei Liu <wl@xen.org>

v2:
 * New
---
 xen/arch/x86/hvm/hpet.c   | 15 +++++++++------
 xen/arch/x86/hvm/vlapic.c | 23 +++++++++++++++--------
 xen/arch/x86/hvm/vpic.c   |  9 +++++----
 3 files changed, 29 insertions(+), 18 deletions(-)

diff --git a/xen/arch/x86/hvm/hpet.c b/xen/arch/x86/hvm/hpet.c
index ee756abb824d..475c3f8bf471 100644
--- a/xen/arch/x86/hvm/hpet.c
+++ b/xen/arch/x86/hvm/hpet.c
@@ -240,6 +240,7 @@ static void hpet_set_timer(HPETState *h, unsigned int tn,
     uint64_t tn_cmp, cur_tick, diff;
     unsigned int irq;
     unsigned int oneshot;
+    s_time_t diff_ns, period_ns = 0;
 
     ASSERT(tn < HPET_TIMER_NUM);
     ASSERT(rw_is_write_locked(&h->lock));
@@ -311,13 +312,15 @@ static void hpet_set_timer(HPETState *h, unsigned int tn,
      * status register) before another interrupt can be delivered.
      */
     oneshot = !timer_is_periodic(h, tn) || timer_level(h, tn);
+    diff_ns = hpet_tick_to_ns(h, diff);
+    if ( !oneshot )
+        period_ns = hpet_tick_to_ns(h, h->hpet.period[tn]);
+
     TRACE_2_LONG_4D(TRC_HVM_EMUL_HPET_START_TIMER, tn, irq,
-                    TRC_PAR_LONG(hpet_tick_to_ns(h, diff)),
-                    TRC_PAR_LONG(oneshot ? 0LL :
-                                 hpet_tick_to_ns(h, h->hpet.period[tn])));
-    create_periodic_time(vhpet_vcpu(h), &h->pt[tn],
-                         hpet_tick_to_ns(h, diff),
-                         oneshot ? 0 : hpet_tick_to_ns(h, h->hpet.period[tn]),
+                    TRC_PAR_LONG(diff_ns),
+                    TRC_PAR_LONG(period_ns));
+
+    create_periodic_time(vhpet_vcpu(h), &h->pt[tn], diff_ns, period_ns,
                          irq, timer_level(h, tn) ? hpet_timer_fired : NULL,
                          timer_level(h, tn) ? (void *)(unsigned long)tn : NULL,
                          timer_level(h, tn));
diff --git a/xen/arch/x86/hvm/vlapic.c b/xen/arch/x86/hvm/vlapic.c
index 5e21fb4937d9..b8c84458ffdc 100644
--- a/xen/arch/x86/hvm/vlapic.c
+++ b/xen/arch/x86/hvm/vlapic.c
@@ -1267,15 +1267,18 @@ static int __vlapic_accept_pic_intr(struct vcpu *v)
 
 int vlapic_accept_pic_intr(struct vcpu *v)
 {
+    bool target, accept = false;
+
     if ( vlapic_hw_disabled(vcpu_vlapic(v)) || !has_vpic(v->domain) )
         return 0;
 
-    TRACE_2D(TRC_HVM_EMUL_LAPIC_PIC_INTR,
-             (v == v->domain->arch.hvm.i8259_target),
-             v ? __vlapic_accept_pic_intr(v) : -1);
+    target = v == v->domain->arch.hvm.i8259_target;
+    if ( target )
+        accept = __vlapic_accept_pic_intr(v);
+
+    TRACE_2D(TRC_HVM_EMUL_LAPIC_PIC_INTR, target, accept);
 
-    return ((v == v->domain->arch.hvm.i8259_target) &&
-            __vlapic_accept_pic_intr(v));
+    return target && accept;
 }
 
 void vlapic_adjust_i8259_target(struct domain *d)
@@ -1449,6 +1452,7 @@ static void lapic_rearm(struct vlapic *s)
 {
     unsigned long tmict;
     uint64_t period, tdt_msr;
+    bool is_periodic;
 
     s->pt.irq = vlapic_get_reg(s, APIC_LVTT) & APIC_VECTOR_MASK;
 
@@ -1464,12 +1468,15 @@ static void lapic_rearm(struct vlapic *s)
 
     period = ((uint64_t)APIC_BUS_CYCLE_NS *
               (uint32_t)tmict * s->hw.timer_divisor);
+    is_periodic = vlapic_lvtt_period(s);
+
     TRACE_2_LONG_3D(TRC_HVM_EMUL_LAPIC_START_TIMER, TRC_PAR_LONG(period),
-             TRC_PAR_LONG(vlapic_lvtt_period(s) ? period : 0LL), s->pt.irq);
+             TRC_PAR_LONG(is_periodic ? period : 0LL), s->pt.irq);
+
     create_periodic_time(vlapic_vcpu(s), &s->pt, period,
-                         vlapic_lvtt_period(s) ? period : 0,
+                         is_periodic ? period : 0,
                          s->pt.irq,
-                         vlapic_lvtt_period(s) ? vlapic_pt_cb : NULL,
+                         is_periodic ? vlapic_pt_cb : NULL,
                          &s->timer_last_update, false);
     s->timer_last_update = s->pt.last_plt_gtime;
 }
diff --git a/xen/arch/x86/hvm/vpic.c b/xen/arch/x86/hvm/vpic.c
index af988a868c8a..91c2c6983393 100644
--- a/xen/arch/x86/hvm/vpic.c
+++ b/xen/arch/x86/hvm/vpic.c
@@ -512,14 +512,15 @@ void vpic_irq_negative_edge(struct domain *d, int irq)
 
 int vpic_ack_pending_irq(struct vcpu *v)
 {
-    int irq;
+    int irq, accept;
     struct hvm_hw_vpic *vpic = &v->domain->arch.hvm.vpic[0];
 
     ASSERT(has_vpic(v->domain));
 
-    TRACE_2D(TRC_HVM_EMUL_PIC_PEND_IRQ_CALL, vlapic_accept_pic_intr(v),
-             vpic->int_output);
-    if ( !vlapic_accept_pic_intr(v) || !vpic->int_output )
+    accept = vlapic_accept_pic_intr(v);
+
+    TRACE_2D(TRC_HVM_EMUL_PIC_PEND_IRQ_CALL, accept, vpic->int_output);
+    if ( !accept || !vpic->int_output )
         return -1;
 
     irq = vpic_intack(vpic);
-- 
2.11.0



  parent reply	other threads:[~2021-09-20 17:25 UTC|newest]

Thread overview: 52+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-20 17:25 [PATCH v2 00/12] xen/trace: Fix leakage of uninitialised stack into the tracebuffer Andrew Cooper
2021-09-20 17:25 ` [PATCH v2 01/12] xen/trace: Don't over-read trace objects Andrew Cooper
2021-09-21  6:53   ` Jan Beulich
2021-09-21 17:51     ` Andrew Cooper
2021-09-22  7:01       ` Jan Beulich
2021-09-22 12:58         ` Andrew Cooper
2021-09-22 13:32           ` Jan Beulich
2021-09-24 14:35           ` Dario Faggioli
2021-09-24 14:51   ` Dario Faggioli
2021-09-27  7:51     ` Jan Beulich
2021-09-30  8:07       ` Dario Faggioli
2021-12-03 16:29         ` Andrew Cooper
2021-09-20 17:25 ` [PATCH v2 02/12] xen/memory: Remove tail padding from TRC_MEM_* records Andrew Cooper
2021-09-24 16:50   ` Dario Faggioli
2021-09-20 17:25 ` [PATCH v2 03/12] xen/credit2: Remove tail padding from TRC_CSCHED2_* records Andrew Cooper
2021-09-24 16:54   ` Dario Faggioli
2021-09-20 17:25 ` [PATCH v2 04/12] x86/hvm: Reduce stack usage from HVMTRACE_ND() Andrew Cooper
2021-09-21 11:00   ` Jan Beulich
2021-09-21 15:38     ` Andrew Cooper
2021-09-21 15:40       ` Jan Beulich
2021-09-20 17:25 ` Andrew Cooper [this message]
2021-09-21 12:18   ` [PATCH v2 05/12] x86/hvm: Remove duplicate calls caused by tracing Jan Beulich
2021-09-21 18:04     ` Andrew Cooper
2021-09-20 17:25 ` [PATCH v2 06/12] xen/credit2: Clean up trace handling Andrew Cooper
2021-09-24 16:55   ` Dario Faggioli
2021-09-20 17:25 ` [PATCH v2 07/12] xen/rt: " Andrew Cooper
2021-09-24 16:56   ` Dario Faggioli
2021-09-20 17:25 ` [PATCH v2 08/12] xen/sched: " Andrew Cooper
2021-09-24 16:57   ` Dario Faggioli
2021-09-20 17:25 ` [PATCH v2 09/12] xen/trace: Minor code cleanup Andrew Cooper
2021-09-21 11:03   ` Jan Beulich
2021-09-24 15:16     ` Dario Faggioli
2021-09-20 17:25 ` [PATCH v2 10/12] x86/pv: Move x86/trace.c to x86/pv/trace.c Andrew Cooper
2021-09-21 15:58   ` Jan Beulich
2021-09-20 17:25 ` [PATCH v2 11/12] xen/arch: Drop asm-*/trace.h Andrew Cooper
2021-09-21 16:01   ` Jan Beulich
2021-10-12 12:31   ` Julien Grall
2021-09-20 17:25 ` [PATCH v2 12/12] x86/trace: Clean up trace handling Andrew Cooper
2021-09-21 16:08   ` Jan Beulich
2021-09-21 18:34     ` Andrew Cooper
2021-09-20 19:29 ` [PATCH v2.1 13/12] xen/trace: Introduce new API Andrew Cooper
2021-09-24 13:21   ` Jan Beulich
2021-09-20 19:32 ` [PATCH v2.1 14/12] xen: Switch to new TRACE() API Andrew Cooper
2021-09-24 13:34   ` Jan Beulich
2021-09-24 15:30   ` Dario Faggioli
2021-09-20 19:33 ` [PATCH v2.1 15/12] xen/trace: Drop old trace macros Andrew Cooper
2021-09-24 13:31   ` Jan Beulich
2021-09-20 19:40 ` [PATCH v2.1 16/12] xen/trace: Restrict CONFIG_TRACEBUFFER to x86 PV Andrew Cooper
2021-09-21  1:10   ` Julien Grall
2021-09-21 20:08 ` [PATCH v2.1 RFC 17/12] xen/trace: Drop cycles parameter Andrew Cooper
2021-09-22  7:03   ` Jan Beulich
2021-09-22  9:38     ` Andrew Cooper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210920172529.24932-6-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=roger.pau@citrix.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.