Skip to contentSkip to conversation

xen/trace: Treewide API cleanup

PATCH In review Andrew Cooper 4 participants 28 messages Mar 18, 2024 – Mar 21, 2024

lore
Share & tools
lore
#0 lore raw

cover xen/trace: Treewide API cleanup

Rework the trace API to unify it (remove the HVM specific obfuscation), and remove MISRA violations.

v3:
* Delete TRACE_PARAM64()

Andrew Cooper (7):
xen/trace: Introduce new API
xen/credit2: Clean up trace handling
xen/rt: Clean up trace handling
xen/sched: Clean up trace handling
xen: Switch to new TRACE() API
xen/trace: Update final {__,}trace_var() users to the new API xen/trace: Drop old trace API

 xen/arch/x86/acpi/cpu_idle.c           |  12 +-
 xen/arch/x86/compat.c                  |   4 +-
 xen/arch/x86/cpu/mwait-idle.c          |   6 +-
 xen/arch/x86/emul-i8254.c              |  14 +-
 xen/arch/x86/hvm/emulate.c             |  11 +-
 xen/arch/x86/hvm/hpet.c                |   7 +-
 xen/arch/x86/hvm/hvm.c                 |  20 +-
 xen/arch/x86/hvm/io.c                  |   1 -
 xen/arch/x86/hvm/rtc.c                 |  12 +-
 xen/arch/x86/hvm/svm/intr.c            |   7 +-
 xen/arch/x86/hvm/svm/svm.c             |  43 ++--
 xen/arch/x86/hvm/vlapic.c              |  52 +++--
 xen/arch/x86/hvm/vmx/intr.c            |   7 +-
 xen/arch/x86/hvm/vmx/vmx.c             |  57 +++--
 xen/arch/x86/hvm/vpic.c                |  13 +-
 xen/arch/x86/include/asm/hvm/trace.h   | 114 ----------
 xen/arch/x86/include/asm/hvm/vmx/vmx.h |   1 -
 xen/arch/x86/irq.c                     |  16 +-
 xen/arch/x86/mm/p2m-pod.c              |   8 +-
 xen/arch/x86/mm/p2m-pt.c               |   2 +-
 xen/arch/x86/mm/shadow/common.c        |   6 +-
 xen/arch/x86/mm/shadow/multi.c         |  10 +-
 xen/arch/x86/pv/trace.c                |  21 +-
 xen/arch/x86/traps.c                   |   2 +-
 xen/common/domain.c                    |   4 +-
 xen/common/grant_table.c               |   6 +-
 xen/common/memory.c                    |   2 +-
 xen/common/sched/core.c                |  56 +++--
 xen/common/sched/credit.c              |  70 +++---
 xen/common/sched/credit2.c             | 301 ++++++++++++-------------
 xen/common/sched/null.c                |  63 +++---
 xen/common/sched/rt.c                  |  99 ++++----
 xen/common/trace.c                     |   9 +-
 xen/drivers/cpufreq/utility.c          |   2 +-
 xen/include/xen/trace.h                |  67 ++----
 35 files changed, 493 insertions(+), 632 deletions(-)
 delete mode 100644 xen/arch/x86/include/asm/hvm/trace.h

base-commit: 62018f08708a5ff6ef8fc8ff2aaaac46e5a60430

Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/7 xen/trace: Introduce new API

trace() and trace_time(), in function form for struct arguments, and macro form for simple uint32_t list arguments.

This will be used to clean up the mess of macros which exists throughout the codebase, as well as eventually dropping __trace_var().

There is intentionally no macro to split a 64-bit parameter in the new API, for MISRA reasons.

---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Nicola Vetrini <[email protected]>
CC: [email protected] <[email protected]>

v3:
* Extend with trace() and trace_time()
* Delete TRACE_PARAM64() for MISRA reasons.

---
 xen/common/trace.c      |  5 +++++
 xen/include/xen/trace.h | 30 ++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)
xen/common/trace.c +5 -0
index 4e7b080e6154..c94ce1f7dc90 100644
@@ -808,6 +808,11 @@ void __trace_var(u32 event, bool cycles, unsigned int extra,
         tasklet_schedule(&trace_notify_dom0_tasklet);
 }
 
+void trace(uint32_t event, unsigned int extra, const void *extra_data)
+{
+    __trace_var(event, event & TRC_HD_CYCLE_FLAG, extra, extra_data);
+}
+
 void __trace_hypercall(uint32_t event, unsigned long op,
                        const xen_ulong_t *args)
 {
xen/include/xen/trace.h +30 -0
index 055883287e8c..f184844e1b55 100644
@@ -37,6 +37,9 @@ int tb_control(struct xen_sysctl_tbuf_op *tbc);
 
 int trace_will_trace_event(u32 event);
 
+/* Create a trace record, with pre-constructed additional parameters. */
+void trace(uint32_t event, unsigned int extra, const void *extra_data);
+
 void __trace_var(uint32_t event, bool cycles, unsigned int extra, const void *);
 
 static inline void trace_var(uint32_t event, bool cycles, unsigned int extra,
@@ -66,6 +69,9 @@ static inline int trace_will_trace_event(uint32_t event)
     return 0;
 }
 
+static inline void trace(
+    uint32_t event, unsigned int extra, const void *extra_data) {}
+
 static inline void trace_var(uint32_t event, bool cycles, unsigned int extra,
                              const void *extra_data) {}
 static inline void __trace_var(uint32_t event, bool cycles, unsigned int extra,
@@ -74,6 +80,30 @@ static inline void __trace_hypercall(uint32_t event, unsigned long op,
                                      const xen_ulong_t *args) {}
 #endif /* CONFIG_TRACEBUFFER */
 
+/* Create a trace record with time included. */
+static inline void trace_time(
+    uint32_t event, unsigned int extra, const void *extra_data)
+{
+    trace(event | TRC_HD_CYCLE_FLAG, extra, extra_data);
+}
+
+/*
+ * Create a trace record, packaging up to 7 additional parameters into a
+ * uint32_t array.
+ */
+#define TRACE(_e, ...)                                          \
+    do {                                                        \
+        if ( unlikely(tb_init_done) )                           \
+        {                                                       \
+            uint32_t _d[] = { __VA_ARGS__ };                    \
+            BUILD_BUG_ON(ARRAY_SIZE(_d) > TRACE_EXTRA_MAX);     \
+            trace(_e, sizeof(_d), sizeof(_d) ? _d : NULL);      \
+        }                                                       \
+    } while ( 0 )
+
+/* Create a trace record with time included. */
+#define TRACE_TIME(_e, ...) TRACE((_e) | TRC_HD_CYCLE_FLAG, ##__VA_ARGS__)
+
 /* Convenience macros for calling the trace function. */
 #define TRACE_0D(_e)                            \
     do {                                        \
Signature · 1 line
2.30.2
Reviewed-by on v1 1/7
#2 lore raw

Re: [PATCH 1/7] xen/trace: Introduce new API

Quoted 11 lines · Andrew Cooper

trace() and trace_time(), in function form for struct arguments, and macro form for simple uint32_t list arguments.

This will be used to clean up the mess of macros which exists throughout the codebase, as well as eventually dropping __trace_var().

There is intentionally no macro to split a 64-bit parameter in the new API, for MISRA reasons.

Thanks for doing this, it all looks good to me.

I'll note that last time this was posted, there were some questions. One was regarding underscores in the macro parameters. I don't care about this enough to stop it going in.

The other question was about the use of ##__VA_ARGS__. I don't actually understand what that comment was trying to say, as a quick Google search it appears that 1) this will do what I think it should do, and 2) it works both in gcc and clang.

We should give Jan a chance to explain his second point more clearly before checking it in; but:

#3 lore raw

Re: [PATCH 1/7] xen/trace: Introduce new API

Quoted 11 lines · George Dunlap
Quoted 10 lines · Andrew Cooper

trace() and trace_time(), in function form for struct arguments, and macro form for simple uint32_t list arguments.

This will be used to clean up the mess of macros which exists throughout the codebase, as well as eventually dropping __trace_var().

There is intentionally no macro to split a 64-bit parameter in the new API, for MISRA reasons.

Quoted 7 lines
Quoted 1 line

Thanks for doing this, it all looks good to me.

I'll note that last time this was posted, there were some questions. One was regarding underscores in the macro parameters. I don't care about this enough to stop it going in.

We ought to finally settle on our take on this, preferably recording the outcome in ./CODING_STYLE.

Quoted 7 lines

The other question was about the use of ##__VA_ARGS__. I don't actually understand what that comment was trying to say, as a quick Google search it appears that 1) this will do what I think it should do, and 2) it works both in gcc and clang.

We should give Jan a chance to explain his second point more clearly before checking it in;

Well. Gcc 13.2 documentation explicitly mentions this form; interestingly with a quick search I couldn't find the original extension's documentation anymore. It is possible that I didn't spot this 2.5 years ago. It is also possible the their doc has changed in the meantime. In any event, my view back at the time was that I'd preferably see us use the (long-standing) gcc extension (args...) or use __VA_ARGS__ in a standard compliant way. Yet with the original form no longer properly documented, maybe they have a plan to remove that at some point. So while my preference stays for the time being, I also don't mind if this code is left as is.

Jan

Quoted 3 lines

but:

#4 lore raw

PATCH 2/7 xen/credit2: Clean up trace handling

In reply to Andrew Cooper

There is no need for bitfields anywhere - use more sensible types. There is also no need to cast 'd' to (unsigned char *) before passing it to a function taking void *. Switch to new trace_time() API.

No functional change.

---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Dario Faggioli <[email protected]>
CC: Nicola Vetrini <[email protected]>
CC: [email protected] <[email protected]>

v2:
* Fix whitespace.
v3:
* Rebase over core API changes.

---
 xen/common/sched/credit2.c | 301 ++++++++++++++++++-------------------
 1 file changed, 146 insertions(+), 155 deletions(-)
xen/common/sched/credit2.c +146 -155
index c76330d79d3a..b7df9f2a9111 100644
@@ -1085,13 +1085,13 @@ static void update_max_weight(struct csched2_runqueue_data *rqd, int new_weight,
     if ( unlikely(tb_init_done) )
     {
         struct {
-            unsigned rqi:16, max_weight:16;
-        } d;
-        d.rqi = rqd->id;
-        d.max_weight = rqd->max_weight;
-        __trace_var(TRC_CSCHED2_RUNQ_MAX_WEIGHT, 1,
-                    sizeof(d),
-                    (unsigned char *)&d);
+            uint16_t rqi, max_weight;
+        } d = {
+            .rqi        = rqd->id,
+            .max_weight = rqd->max_weight,
+        };
+
+        trace_time(TRC_CSCHED2_RUNQ_MAX_WEIGHT, sizeof(d), &d);
     }
 }
 
@@ -1119,9 +1119,7 @@ _runq_assign(struct csched2_unit *svc, struct csched2_runqueue_data *rqd)
             .rqi  = rqd->id,
         };
 
-        __trace_var(TRC_CSCHED2_RUNQ_ASSIGN, 1,
-                    sizeof(d),
-                    (unsigned char *)&d);
+        trace_time(TRC_CSCHED2_RUNQ_ASSIGN, sizeof(d), &d);
     }
 
 }
@@ -1354,9 +1352,7 @@ update_runq_load(const struct scheduler *ops,
             .shift      = P,
         };
 
-        __trace_var(TRC_CSCHED2_UPDATE_RUNQ_LOAD, 1,
-                    sizeof(d),
-                    (unsigned char *)&d);
+        trace_time(TRC_CSCHED2_UPDATE_RUNQ_LOAD, sizeof(d), &d);
     }
 }
 
@@ -1406,16 +1402,16 @@ update_svc_load(const struct scheduler *ops,
     {
         struct {
             uint64_t v_avgload;
-            unsigned unit:16, dom:16;
-            unsigned shift;
-        } d;
-        d.dom = svc->unit->domain->domain_id;
-        d.unit = svc->unit->unit_id;
-        d.v_avgload = svc->avgload;
-        d.shift = P;
-        __trace_var(TRC_CSCHED2_UPDATE_UNIT_LOAD, 1,
-                    sizeof(d),
-                    (unsigned char *)&d);
+            uint16_t unit, dom;
+            uint32_t shift;
+        } d = {
+            .v_avgload = svc->avgload,
+            .unit      = svc->unit->unit_id,
+            .dom       = svc->unit->domain->domain_id,
+            .shift     = P,
+        };
+
+        trace_time(TRC_CSCHED2_UPDATE_UNIT_LOAD, sizeof(d), &d);
     }
 }
 
@@ -1424,7 +1420,7 @@ update_load(const struct scheduler *ops,
             struct csched2_runqueue_data *rqd,
             struct csched2_unit *svc, int change, s_time_t now)
 {
-    trace_var(TRC_CSCHED2_UPDATE_LOAD, 1, 0,  NULL);
+    TRACE_TIME(TRC_CSCHED2_UPDATE_LOAD);
 
     update_runq_load(ops, rqd, change, now);
     if ( svc )
@@ -1462,15 +1458,15 @@ static void runq_insert(struct csched2_unit *svc)
     if ( unlikely(tb_init_done) )
     {
         struct {
-            unsigned unit:16, dom:16;
-            unsigned pos;
-        } d;
-        d.dom = svc->unit->domain->domain_id;
-        d.unit = svc->unit->unit_id;
-        d.pos = pos;
-        __trace_var(TRC_CSCHED2_RUNQ_POS, 1,
-                    sizeof(d),
-                    (unsigned char *)&d);
+            uint16_t unit, dom;
+            uint32_t pos;
+        } d = {
+            .unit = svc->unit->unit_id,
+            .dom  = svc->unit->domain->domain_id,
+            .pos  = pos,
+        };
+
+        trace_time(TRC_CSCHED2_RUNQ_POS, sizeof(d), &d);
     }
 }
 
@@ -1563,16 +1559,16 @@ static s_time_t tickle_score(const struct scheduler *ops, s_time_t now,
     if ( unlikely(tb_init_done) )
     {
         struct {
-            unsigned unit:16, dom:16;
-            int credit, score;
-        } d;
-        d.dom = cur->unit->domain->domain_id;
-        d.unit = cur->unit->unit_id;
-        d.credit = cur->credit;
-        d.score = score;
-        __trace_var(TRC_CSCHED2_TICKLE_CHECK, 1,
-                    sizeof(d),
-                    (unsigned char *)&d);
+            uint16_t unit, dom;
+            uint32_t credit, score;
+        } d = {
+            .unit   = cur->unit->unit_id,
+            .dom    = cur->unit->domain->domain_id,
+            .credit = cur->credit,
+            .score  = score,
+        };
+
+        trace_time(TRC_CSCHED2_TICKLE_CHECK, sizeof(d), &d);
     }
 
     return score;
@@ -1610,17 +1606,16 @@ runq_tickle(const struct scheduler *ops, struct csched2_unit *new, s_time_t now)
     if ( unlikely(tb_init_done) )
     {
         struct {
-            unsigned unit:16, dom:16;
-            unsigned processor;
-            int credit;
-        } d;
-        d.dom = unit->domain->domain_id;
-        d.unit = unit->unit_id;
-        d.processor = cpu;
-        d.credit = new->credit;
-        __trace_var(TRC_CSCHED2_TICKLE_NEW, 1,
-                    sizeof(d),
-                    (unsigned char *)&d);
+            uint16_t unit, dom;
+            uint32_t processor, credit;
+        } d = {
+            .dom       = unit->domain->domain_id,
+            .unit      = unit->unit_id,
+            .processor = cpu,
+            .credit    = new->credit,
+        };
+
+        trace_time(TRC_CSCHED2_TICKLE_NEW, sizeof(d), &d);
     }
 
     /*
@@ -1759,12 +1754,12 @@ runq_tickle(const struct scheduler *ops, struct csched2_unit *new, s_time_t now)
     if ( unlikely(tb_init_done) )
     {
         struct {
-            unsigned cpu:16, pad:16;
-        } d;
-        d.cpu = ipid; d.pad = 0;
-        __trace_var(TRC_CSCHED2_TICKLE, 1,
-                    sizeof(d),
-                    (unsigned char *)&d);
+            uint16_t cpu, _pad;
+        } d = {
+            .cpu = ipid,
+        };
+
+        trace_time(TRC_CSCHED2_TICKLE, sizeof(d), &d);
     }
 
     tickle_cpu(ipid, rqd);
@@ -1840,16 +1835,16 @@ static void reset_credit(int cpu, s_time_t now, struct csched2_unit *snext)
         if ( unlikely(tb_init_done) )
         {
             struct {
-                unsigned unit:16, dom:16;
-                int credit_start, credit_end;
-            } d;
-            d.dom = svc->unit->domain->domain_id;
-            d.unit = svc->unit->unit_id;
-            d.credit_start = start_credit;
-            d.credit_end = svc->credit;
-            __trace_var(TRC_CSCHED2_CREDIT_RESET, 1,
-                        sizeof(d),
-                        (unsigned char *)&d);
+                uint16_t unit, dom;
+                uint32_t credit_start, credit_end;
+            } d = {
+                .unit         = svc->unit->unit_id,
+                .dom          = svc->unit->domain->domain_id,
+                .credit_start = start_credit,
+                .credit_end   = svc->credit,
+            };
+
+            trace_time(TRC_CSCHED2_CREDIT_RESET, sizeof(d), &d);
         }
     }
 
@@ -1895,18 +1890,17 @@ void burn_credits(struct csched2_runqueue_data *rqd,
     if ( unlikely(tb_init_done) )
     {
         struct {
-            unsigned unit:16, dom:16;
-            int credit, budget;
-            int delta;
-        } d;
-        d.dom = svc->unit->domain->domain_id;
-        d.unit = svc->unit->unit_id;
-        d.credit = svc->credit;
-        d.budget = has_cap(svc) ?  svc->budget : INT_MIN;
-        d.delta = delta;
-        __trace_var(TRC_CSCHED2_CREDIT_BURN, 1,
-                    sizeof(d),
-                    (unsigned char *)&d);
+            uint16_t unit, dom;
+            uint32_t credit, budget, delta;
+        } d = {
+            .unit   = svc->unit->unit_id,
+            .dom    = svc->unit->domain->domain_id,
+            .credit = svc->credit,
+            .budget = has_cap(svc) ? svc->budget : INT_MIN,
+            .delta  = delta,
+        };
+
+        trace_time(TRC_CSCHED2_CREDIT_BURN, sizeof(d), &d);
     }
 }
 
@@ -2551,17 +2545,17 @@ csched2_res_pick(const struct scheduler *ops, const struct sched_unit *unit)
     {
         struct {
             uint64_t b_avgload;
-            unsigned unit:16, dom:16;
-            unsigned rq_id:16, new_cpu:16;
-        } d;
-        d.dom = unit->domain->domain_id;
-        d.unit = unit->unit_id;
-        d.rq_id = min_rqd ? min_rqd->id : -1;
-        d.b_avgload = min_avgload;
-        d.new_cpu = new_cpu;
-        __trace_var(TRC_CSCHED2_PICKED_CPU, 1,
-                    sizeof(d),
-                    (unsigned char *)&d);
+            uint16_t unit, dom;
+            uint16_t rq_id, new_cpu;
+        } d = {
+            .b_avgload = min_avgload,
+            .unit      = unit->unit_id,
+            .dom       = unit->domain->domain_id,
+            .rq_id     = min_rqd ? min_rqd->id : -1,
+            .new_cpu   = new_cpu,
+        };
+
+        trace_time(TRC_CSCHED2_PICKED_CPU, sizeof(d), &d);
     }
 
     return get_sched_res(new_cpu);
@@ -2622,16 +2616,16 @@ static void migrate(const struct scheduler *ops,
     if ( unlikely(tb_init_done) )
     {
         struct {
-            unsigned unit:16, dom:16;
-            unsigned rqi:16, trqi:16;
-        } d;
-        d.dom = unit->domain->domain_id;
-        d.unit = unit->unit_id;
-        d.rqi = svc->rqd->id;
-        d.trqi = trqd->id;
-        __trace_var(TRC_CSCHED2_MIGRATE, 1,
-                    sizeof(d),
-                    (unsigned char *)&d);
+            uint16_t unit, dom;
+            uint16_t rqi, trqi;
+        } d = {
+            .unit = unit->unit_id,
+            .dom  = unit->domain->domain_id,
+            .rqi  = svc->rqd->id,
+            .trqi = trqd->id,
+        };
+
+        trace_time(TRC_CSCHED2_MIGRATE, sizeof(d), &d);
     }
 
     if ( svc->flags & CSFLAG_scheduled )
@@ -2768,15 +2762,15 @@ static void balance_load(const struct scheduler *ops, int cpu, s_time_t now)
         if ( unlikely(tb_init_done) )
         {
             struct {
-                unsigned lrq_id:16, orq_id:16;
-                unsigned load_delta;
-            } d;
-            d.lrq_id = st.lrqd->id;
-            d.orq_id = st.orqd->id;
-            d.load_delta = st.load_delta;
-            __trace_var(TRC_CSCHED2_LOAD_CHECK, 1,
-                        sizeof(d),
-                        (unsigned char *)&d);
+                uint16_t lrq_id, orq_id;
+                uint32_t load_delta;
+            } d = {
+                .lrq_id     = st.lrqd->id,
+                .orq_id     = st.orqd->id,
+                .load_delta = st.load_delta,
+            };
+
+            trace_time(TRC_CSCHED2_LOAD_CHECK, sizeof(d), &d);
         }
 
         /*
@@ -2820,9 +2814,7 @@ static void balance_load(const struct scheduler *ops, int cpu, s_time_t now)
             .orq_id     = st.orqd->id,
         };
 
-        __trace_var(TRC_CSCHED2_LOAD_BALANCE, 1,
-                    sizeof(d),
-                    (unsigned char *)&d);
+        trace_time(TRC_CSCHED2_LOAD_BALANCE, sizeof(d), &d);
     }
 
     SCHED_STAT_CRANK(acct_load_balance);
@@ -3407,15 +3399,15 @@ runq_candidate(struct csched2_runqueue_data *rqd,
         if ( unlikely(tb_init_done) )
         {
             struct {
-                unsigned unit:16, dom:16;
-                unsigned runtime;
-            } d;
-            d.dom = scurr->unit->domain->domain_id;
-            d.unit = scurr->unit->unit_id;
-            d.runtime = now - scurr->unit->state_entry_time;
-            __trace_var(TRC_CSCHED2_RATELIMIT, 1,
-                        sizeof(d),
-                        (unsigned char *)&d);
+                uint16_t unit, dom;
+                uint32_t runtime;
+            } d = {
+                .unit    = scurr->unit->unit_id,
+                .dom     = scurr->unit->domain->domain_id,
+                .runtime = now - scurr->unit->state_entry_time,
+            };
+
+            trace_time(TRC_CSCHED2_RATELIMIT, sizeof(d), &d);
         }
         return scurr;
     }
@@ -3468,13 +3460,13 @@ runq_candidate(struct csched2_runqueue_data *rqd,
         if ( unlikely(tb_init_done) )
         {
             struct {
-                unsigned unit:16, dom:16;
-            } d;
-            d.dom = svc->unit->domain->domain_id;
-            d.unit = svc->unit->unit_id;
-            __trace_var(TRC_CSCHED2_RUNQ_CAND_CHECK, 1,
-                        sizeof(d),
-                        (unsigned char *)&d);
+                uint16_t unit, dom;
+            } d = {
+                .unit = svc->unit->unit_id,
+                .dom  = svc->unit->domain->domain_id,
+            };
+
+            trace_time(TRC_CSCHED2_RUNQ_CAND_CHECK, sizeof(d), &d);
         }
 
         /*
@@ -3542,17 +3534,16 @@ runq_candidate(struct csched2_runqueue_data *rqd,
     if ( unlikely(tb_init_done) )
     {
         struct {
-            unsigned unit:16, dom:16;
-            unsigned tickled_cpu;
-            int credit;
-        } d;
-        d.dom = snext->unit->domain->domain_id;
-        d.unit = snext->unit->unit_id;
-        d.credit = snext->credit;
-        d.tickled_cpu = snext->tickled_cpu;
-        __trace_var(TRC_CSCHED2_RUNQ_CANDIDATE, 1,
-                    sizeof(d),
-                    (unsigned char *)&d);
+            uint16_t unit, dom;
+            uint32_t tickled_cpu, credit;
+        } d = {
+            .unit        = snext->unit->unit_id,
+            .dom         = snext->unit->domain->domain_id,
+            .tickled_cpu = snext->tickled_cpu,
+            .credit      = snext->credit,
+        };
+
+        trace_time(TRC_CSCHED2_RUNQ_CANDIDATE, sizeof(d), &d);
     }
 
     if ( unlikely(snext->tickled_cpu != -1 && snext->tickled_cpu != cpu) )
@@ -3608,18 +3599,18 @@ static void cf_check csched2_schedule(
     if ( unlikely(tb_init_done) )
     {
         struct {
-            unsigned cpu:16, rq_id:16;
-            unsigned tasklet:8, idle:8, smt_idle:8, tickled:8;
-        } d;
-        d.cpu = cur_cpu;
-        d.rq_id = c2r(sched_cpu);
-        d.tasklet = tasklet_work_scheduled;
-        d.idle = is_idle_unit(currunit);
-        d.smt_idle = cpumask_test_cpu(sched_cpu, &rqd->smt_idle);
-        d.tickled = tickled;
-        __trace_var(TRC_CSCHED2_SCHEDULE, 1,
-                    sizeof(d),
-                    (unsigned char *)&d);
+            uint16_t cpu, rq_id;
+            uint8_t tasklet, idle, smt_idle, tickled;
+        } d = {
+            .cpu      = cur_cpu,
+            .rq_id    = c2r(sched_cpu),
+            .tasklet  = tasklet_work_scheduled,
+            .idle     = is_idle_unit(currunit),
+            .smt_idle = cpumask_test_cpu(sched_cpu, &rqd->smt_idle),
+            .tickled  = tickled,
+        };
+
+        trace_time(TRC_CSCHED2_SCHEDULE, sizeof(d), &d);
     }
 
     /* Update credits (and budget, if necessary). */
@@ -3654,7 +3645,7 @@ static void cf_check csched2_schedule(
     if ( tasklet_work_scheduled )
     {
         __clear_bit(__CSFLAG_unit_yield, &scurr->flags);
-        trace_var(TRC_CSCHED2_SCHED_TASKLET, 1, 0, NULL);
+        TRACE_TIME(TRC_CSCHED2_SCHED_TASKLET);
         snext = csched2_unit(sched_idle_unit(sched_cpu));
     }
     else
Signature · 1 line
2.30.2
#5 lore raw

Re: [PATCH 2/7] xen/credit2: Clean up trace handling

Quoted 6 lines · Andrew Cooper

There is no need for bitfields anywhere - use more sensible types. There is also no need to cast 'd' to (unsigned char *) before passing it to a function taking void *. Switch to new trace_time() API.

No functional change.

Hey Andrew -- overall changes look great, thanks for doing this very detailed work.

One issue here is that you've changed a number of signed values to unsigned values; for example:

Quoted 6 lines
xen/common/sched/credit2.c +0 -2
@@ -1563,16 +1559,16 @@ static s_time_t tickle_score(const struct scheduler *ops, s_time_t now,
     if ( unlikely(tb_init_done) )
     {
         struct {
-            unsigned unit:16, dom:16;
-            int credit, score;

xen/common/sched/credit2.c static s_time_t tickle_score(const struct scheduler *ops, s_time_t now, · line 1563

Quoted 10 lines
xen/common/sched/credit2.c +2 -8
-        } d;
-        d.dom = cur->unit->domain->domain_id;
-        d.unit = cur->unit->unit_id;
-        d.credit = cur->credit;
-        d.score = score;
-        __trace_var(TRC_CSCHED2_TICKLE_CHECK, 1,
-                    sizeof(d),
-                    (unsigned char *)&d);
+            uint16_t unit, dom;
+            uint32_t credit, score;

...here you change int to unit32_t; but credit and score are both signed values, which may be negative. There are a number of other similar instances. In general, if there's a signed value, it was meant.

I don't want to delay this another 3 years, so if there's not a strong argument in favor of converting the signed types into uint32_t, I can make the change myself and re-submit the series.

(I'll probably end up making a change to xenalyze.c as well, to update the structure definitions there to match what's in Xen, so it wouldn't be any extra effort.)

-George

#6 lore raw

Re: [PATCH 2/7] xen/credit2: Clean up trace handling

Quoted 24 lines · George Dunlap
Quoted 5 lines · Andrew Cooper

There is no need for bitfields anywhere - use more sensible types. There is also no need to cast 'd' to (unsigned char *) before passing it to a function taking void *. Switch to new trace_time() API.

No functional change.

Hey Andrew -- overall changes look great, thanks for doing this very detailed work.

One issue here is that you've changed a number of signed values to unsigned values; for example:

Quoted 12 lines
xen/common/sched/credit2.c +0 -8
@@ -1563,16 +1559,16 @@ static s_time_t tickle_score(const struct scheduler *ops, s_time_t now,
     if ( unlikely(tb_init_done) )
     {
         struct {
-            unsigned unit:16, dom:16;
-            int credit, score;
-        } d;
-        d.dom = cur->unit->domain->domain_id;
-        d.unit = cur->unit->unit_id;
-        d.credit = cur->credit;
-        d.score = score;
-        __trace_var(TRC_CSCHED2_TICKLE_CHECK, 1,
Quoted 8 lines

xen/common/sched/credit2.c static s_time_t tickle_score(const struct scheduler *ops, s_time_t now, · line 1563

Quoted 4 lines
xen/common/sched/credit2.c +2 -2
-                    sizeof(d),
-                    (unsigned char *)&d);
+            uint16_t unit, dom;
+            uint32_t credit, score;

...here you change int to unit32_t; but credit and score are both signed values, which may be negative. There are a number of other similar instances. In general, if there's a signed value, it was meant.

Oh - this is a consequence of being reviewed that way in earlier iterations.

If they really can hold negative numbers, they can become int32_t's. What's important is that they have a clearly-specified width.

~Andrew

#7 lore raw

Re: [PATCH 2/7] xen/credit2: Clean up trace handling

Quoted 35 lines · Andrew Cooper
Quoted 24 lines · George Dunlap
Quoted 5 lines · Andrew Cooper

There is no need for bitfields anywhere - use more sensible types. There is also no need to cast 'd' to (unsigned char *) before passing it to a function taking void *. Switch to new trace_time() API.

No functional change.

Hey Andrew -- overall changes look great, thanks for doing this very detailed work.

One issue here is that you've changed a number of signed values to unsigned values; for example:

Quoted 12 lines
xen/common/sched/credit2.c +0 -8
@@ -1563,16 +1559,16 @@ static s_time_t tickle_score(const struct scheduler *ops, s_time_t now,
     if ( unlikely(tb_init_done) )
     {
         struct {
-            unsigned unit:16, dom:16;
-            int credit, score;
-        } d;
-        d.dom = cur->unit->domain->domain_id;
-        d.unit = cur->unit->unit_id;
-        d.credit = cur->credit;
-        d.score = score;
-        __trace_var(TRC_CSCHED2_TICKLE_CHECK, 1,
Quoted 8 lines

xen/common/sched/credit2.c static s_time_t tickle_score(const struct scheduler *ops, s_time_t now, · line 1563

Quoted 4 lines
xen/common/sched/credit2.c +2 -2
-                    sizeof(d),
-                    (unsigned char *)&d);
+            uint16_t unit, dom;
+            uint32_t credit, score;

...here you change int to unit32_t; but credit and score are both signed values, which may be negative. There are a number of other similar instances. In general, if there's a signed value, it was meant.

Quoted 4 lines

Oh - this is a consequence of being reviewed that way in earlier iterations.

If they really can hold negative numbers, they can become int32_t's. What's important is that they have a clearly-specified width.

Oh yes, sorry if that wasn't clear -- I was suggesting int32_t, unless there was some compelling reason to do otherwise. I just realize that the last time this series had some review comments, it took 3 years to come back around, and it would be a shame if that happened again; so I'm happy to go through and do the change.

-George

#8 lore raw

Re: [PATCH 2/7] xen/credit2: Clean up trace handling

In reply to Andrew Cooper
Quoted 34 lines · Andrew Cooper
Quoted 24 lines · George Dunlap
Quoted 5 lines · Andrew Cooper

There is no need for bitfields anywhere - use more sensible types. There is also no need to cast 'd' to (unsigned char *) before passing it to a function taking void *. Switch to new trace_time() API.

No functional change.

Hey Andrew -- overall changes look great, thanks for doing this very detailed work.

One issue here is that you've changed a number of signed values to unsigned values; for example:

Quoted 12 lines
xen/common/sched/credit2.c +0 -8
@@ -1563,16 +1559,16 @@ static s_time_t tickle_score(const struct scheduler *ops, s_time_t now,
     if ( unlikely(tb_init_done) )
     {
         struct {
-            unsigned unit:16, dom:16;
-            int credit, score;
-        } d;
-        d.dom = cur->unit->domain->domain_id;
-        d.unit = cur->unit->unit_id;
-        d.credit = cur->credit;
-        d.score = score;
-        __trace_var(TRC_CSCHED2_TICKLE_CHECK, 1,
Quoted 8 lines

xen/common/sched/credit2.c static s_time_t tickle_score(const struct scheduler *ops, s_time_t now, · line 1563

Quoted 4 lines
xen/common/sched/credit2.c +2 -2
-                    sizeof(d),
-                    (unsigned char *)&d);
+            uint16_t unit, dom;
+            uint32_t credit, score;

...here you change int to unit32_t; but credit and score are both signed values, which may be negative. There are a number of other similar instances. In general, if there's a signed value, it was meant.

Quoted 1 line

Oh - this is a consequence of being reviewed that way in earlier iterations.

Which in turn is a result of us still having way to many uses of plain int when signed quantities aren't meant. Plus my suggestion to make this explicit by saying "signed int" was rejected.

Quoted 2 lines

If they really can hold negative numbers, they can become int32_t's. What's important is that they have a clearly-specified width.

And please feel free to retain my R-b with any such adjustments.

Jan

#9 lore raw

Re: [PATCH 2/7] xen/credit2: Clean up trace handling

Quoted 36 lines · Jan Beulich
Quoted 34 lines · Andrew Cooper
Quoted 32 lines · George Dunlap
Quoted 5 lines · Andrew Cooper

There is no need for bitfields anywhere - use more sensible types. There is also no need to cast 'd' to (unsigned char *) before passing it to a function taking void *. Switch to new trace_time() API.

No functional change.

Hey Andrew -- overall changes look great, thanks for doing this very detailed work.

One issue here is that you've changed a number of signed values to unsigned values; for example:

Quoted 6 lines
xen/common/sched/credit2.c +0 -2
@@ -1563,16 +1559,16 @@ static s_time_t tickle_score(const struct scheduler *ops, s_time_t now,
     if ( unlikely(tb_init_done) )
     {
         struct {
-            unsigned unit:16, dom:16;
-            int credit, score;

xen/common/sched/credit2.c static s_time_t tickle_score(const struct scheduler *ops, s_time_t now, · line 1563

Quoted 10 lines
xen/common/sched/credit2.c +2 -8
-        } d;
-        d.dom = cur->unit->domain->domain_id;
-        d.unit = cur->unit->unit_id;
-        d.credit = cur->credit;
-        d.score = score;
-        __trace_var(TRC_CSCHED2_TICKLE_CHECK, 1,
-                    sizeof(d),
-                    (unsigned char *)&d);
+            uint16_t unit, dom;
+            uint32_t credit, score;

...here you change int to unit32_t; but credit and score are both signed values, which may be negative. There are a number of other similar instances. In general, if there's a signed value, it was meant.

Quoted 5 lines
Quoted 1 line

Oh - this is a consequence of being reviewed that way in earlier iterations.

Which in turn is a result of us still having way to many uses of plain int when signed quantities aren't meant. Plus my suggestion to make this explicit by saying "signed int" was rejected.

Not complaining, but just pointing out to maybe save some time in the
future: The vast majority of fields in the trace records in this file are unsigned; in fact, two of the fields in this structure are unsigned. That should have been a hint that being signed was likely to be intentional in this code, and to look at the context before removing it. (In this case, for example just above here there's an "if ( score < 0 )" showing that score might be negative.)

-George

#10 lore raw

Re: [PATCH 2/7] xen/credit2: Clean up trace handling

In reply to George Dunlap
Quoted 11 lines · George Dunlap
Quoted 6 lines · Andrew Cooper

There is no need for bitfields anywhere - use more sensible types. There is also no need to cast 'd' to (unsigned char *) before passing it to a function taking void *. Switch to new trace_time() API.

No functional change.

Hey Andrew -- overall changes look great, thanks for doing this very detailed work.

For my own posterity later:

I've done a close review of the rest of the patch and didn't see any issues other than the loss of sign in a handful of cases.

-George

#11 lore raw

PATCH 3/7 xen/rt: Clean up trace handling

In reply to Andrew Cooper

Most uses of bitfields and __packed are unnecessary. There is also no need to cast 'd' to (unsigned char *) before passing it to a function taking void *. Switch to new trace_time() API.

No functional change.

---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Dario Faggioli <[email protected]>
CC: Nicola Vetrini <[email protected]>
CC: [email protected] <[email protected]>

v2:
* New.
v3:
* Rebase over core API changes.

---
 xen/common/sched/rt.c | 99 ++++++++++++++++++++-----------------------
 1 file changed, 47 insertions(+), 52 deletions(-)
xen/common/sched/rt.c +47 -52
index b279f957f622..f368e0fdd5a5 100644
@@ -455,21 +455,21 @@ rt_update_deadline(s_time_t now, struct rt_unit *svc)
     svc->cur_budget = svc->budget;
     svc->priority_level = 0;
 
-    /* TRACE */
+    if ( unlikely(tb_init_done) )
     {
-        struct __packed {
-            unsigned unit:16, dom:16;
-            unsigned priority_level;
+        struct {
+            uint16_t unit, dom;
+            uint32_t priority_level;
             uint64_t cur_deadline, cur_budget;
-        } d;
-        d.dom = svc->unit->domain->domain_id;
-        d.unit = svc->unit->unit_id;
-        d.priority_level = svc->priority_level;
-        d.cur_deadline = (uint64_t) svc->cur_deadline;
-        d.cur_budget = (uint64_t) svc->cur_budget;
-        trace_var(TRC_RTDS_BUDGET_REPLENISH, 1,
-                  sizeof(d),
-                  (unsigned char *) &d);
+        } d = {
+            .dom            = svc->unit->domain->domain_id,
+            .unit           = svc->unit->unit_id,
+            .priority_level = svc->priority_level,
+            .cur_deadline   = svc->cur_deadline,
+            .cur_budget     = svc->cur_budget,
+        };
+
+        trace_time(TRC_RTDS_BUDGET_REPLENISH, sizeof(d), &d);
     }
 
     return;
@@ -986,7 +986,7 @@ burn_budget(const struct scheduler *ops, struct rt_unit *svc, s_time_t now)
         }
     }
 
-    /* TRACE */
+    if ( unlikely(tb_init_done) )
     {
         struct __packed {
             uint16_t unit, dom;
@@ -1003,9 +1003,7 @@ burn_budget(const struct scheduler *ops, struct rt_unit *svc, s_time_t now)
             .has_extratime  = !!(svc->flags & RTDS_extratime),
         };
 
-        trace_var(TRC_RTDS_BUDGET_BURN, 1,
-                  sizeof(d),
-                  (unsigned char *) &d);
+        trace_time(TRC_RTDS_BUDGET_BURN, sizeof(d), &d);
     }
 }
 
@@ -1040,22 +1038,19 @@ runq_pick(const struct scheduler *ops, const cpumask_t *mask, unsigned int cpu)
         break;
     }
 
-    /* TRACE */
+    if ( unlikely(tb_init_done) && svc )
     {
-        if( svc != NULL )
-        {
-            struct __packed {
-                unsigned unit:16, dom:16;
-                uint64_t cur_deadline, cur_budget;
-            } d;
-            d.dom = svc->unit->domain->domain_id;
-            d.unit = svc->unit->unit_id;
-            d.cur_deadline = (uint64_t) svc->cur_deadline;
-            d.cur_budget = (uint64_t) svc->cur_budget;
-            trace_var(TRC_RTDS_RUNQ_PICK, 1,
-                      sizeof(d),
-                      (unsigned char *) &d);
-        }
+        struct __packed {
+            uint16_t unit, dom;
+            uint64_t cur_deadline, cur_budget;
+        } d = {
+            .unit         = svc->unit->unit_id,
+            .dom          = svc->unit->domain->domain_id,
+            .cur_deadline = svc->cur_deadline,
+            .cur_budget   = svc->cur_budget,
+        };
+
+        trace_time(TRC_RTDS_RUNQ_PICK, sizeof(d), &d);
     }
 
     return svc;
@@ -1076,18 +1071,19 @@ rt_schedule(const struct scheduler *ops, struct sched_unit *currunit,
     struct rt_unit *snext = NULL;
     bool migrated = false;
 
-    /* TRACE */
+    if ( unlikely(tb_init_done) )
     {
-        struct __packed {
-            unsigned cpu:16, tasklet:8, tickled:4, idle:4;
-        } d;
-        d.cpu = cur_cpu;
-        d.tasklet = tasklet_work_scheduled;
-        d.tickled = cpumask_test_cpu(sched_cpu, &prv->tickled);
-        d.idle = is_idle_unit(currunit);
-        trace_var(TRC_RTDS_SCHEDULE, 1,
-                  sizeof(d),
-                  (unsigned char *)&d);
+        struct {
+            uint16_t cpu;
+            uint8_t tasklet, tickled:4, idle:4;
+        } d = {
+            .cpu     = cur_cpu,
+            .tasklet = tasklet_work_scheduled,
+            .tickled = cpumask_test_cpu(sched_cpu, &prv->tickled),
+            .idle    = is_idle_unit(currunit),
+        };
+
+        trace_time(TRC_RTDS_SCHEDULE, sizeof(d), &d);
     }
 
     /* clear ticked bit now that we've been scheduled */
@@ -1098,7 +1094,7 @@ rt_schedule(const struct scheduler *ops, struct sched_unit *currunit,
 
     if ( tasklet_work_scheduled )
     {
-        trace_var(TRC_RTDS_SCHED_TASKLET, 1, 0,  NULL);
+        TRACE_TIME(TRC_RTDS_SCHED_TASKLET);
         snext = rt_unit(sched_idle_unit(sched_cpu));
     }
     else
@@ -1250,16 +1246,15 @@ runq_tickle(const struct scheduler *ops, const struct rt_unit *new)
     SCHED_STAT_CRANK(tickled_no_cpu);
     return;
  out:
-    /* TRACE */
+    if ( unlikely(tb_init_done) )
     {
         struct {
-            unsigned cpu:16, pad:16;
-        } d;
-        d.cpu = cpu_to_tickle;
-        d.pad = 0;
-        trace_var(TRC_RTDS_TICKLE, 1,
-                  sizeof(d),
-                  (unsigned char *)&d);
+            uint16_t cpu, _pad;
+        } d = {
+            .cpu = cpu_to_tickle,
+        };
+
+        trace_time(TRC_RTDS_TICKLE, sizeof(d), &d);
     }
 
     cpumask_set_cpu(cpu_to_tickle, &prv->tickled);
Signature · 1 line
2.30.2
#13 lore raw

PATCH 4/7 xen/sched: Clean up trace handling

In reply to Andrew Cooper

There is no need for bitfields anywhere - use more sensible types. There is also no need to cast 'd' to (unsigned char *) before passing it to a function taking void *. Switch to new trace_time() API.

No functional change.

---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Dario Faggioli <[email protected]>
CC: Nicola Vetrini <[email protected]>
CC: [email protected] <[email protected]>

v2:
* New.
v3:
* Rebase over core API changes.

---
 xen/common/sched/core.c   | 56 +++++++++++++++----------------
 xen/common/sched/credit.c | 70 ++++++++++++++++++---------------------
 xen/common/sched/null.c   | 63 ++++++++++++++++++++---------------
 3 files changed, 97 insertions(+), 92 deletions(-)
xen/common/sched/core.c +27 -29
index 3e48da1cdd4e..cd662280bbad 100644
@@ -205,7 +205,7 @@ static inline struct scheduler *vcpu_scheduler(const struct vcpu *v)
 
 static inline void trace_runstate_change(const struct vcpu *v, int new_state)
 {
-    struct { uint32_t vcpu:16, domain:16; } d;
+    struct { uint16_t vcpu, domain; } d;
     uint32_t event;
 
     if ( likely(!tb_init_done) )
@@ -218,12 +218,12 @@ static inline void trace_runstate_change(const struct vcpu *v, int new_state)
     event |= ( v->runstate.state & 0x3 ) << 8;
     event |= ( new_state & 0x3 ) << 4;
 
-    __trace_var(event, 1/*tsc*/, sizeof(d), &d);
+    trace_time(event, sizeof(d), &d);
 }
 
 static inline void trace_continue_running(const struct vcpu *v)
 {
-    struct { uint32_t vcpu:16, domain:16; } d;
+    struct { uint16_t vcpu, domain; } d;
 
     if ( likely(!tb_init_done) )
         return;
@@ -231,7 +231,7 @@ static inline void trace_continue_running(const struct vcpu *v)
     d.vcpu = v->vcpu_id;
     d.domain = v->domain->domain_id;
 
-    __trace_var(TRC_SCHED_CONTINUE_RUNNING, 1/*tsc*/, sizeof(d), &d);
+    trace_time(TRC_SCHED_CONTINUE_RUNNING, sizeof(d), &d);
 }
 
 static inline void vcpu_urgent_count_update(struct vcpu *v)
@@ -872,7 +872,7 @@ int sched_init_domain(struct domain *d, unsigned int poolid)
         return ret;
 
     SCHED_STAT_CRANK(dom_init);
-    TRACE_1D(TRC_SCHED_DOM_ADD, d->domain_id);
+    TRACE_TIME(TRC_SCHED_DOM_ADD, d->domain_id);
 
     rcu_read_lock(&sched_res_rculock);
 
@@ -895,7 +895,7 @@ void sched_destroy_domain(struct domain *d)
     if ( d->cpupool )
     {
         SCHED_STAT_CRANK(dom_destroy);
-        TRACE_1D(TRC_SCHED_DOM_REM, d->domain_id);
+        TRACE_TIME(TRC_SCHED_DOM_REM, d->domain_id);
 
         rcu_read_lock(&sched_res_rculock);
 
@@ -936,7 +936,7 @@ void vcpu_sleep_nosync(struct vcpu *v)
     unsigned long flags;
     spinlock_t *lock;
 
-    TRACE_2D(TRC_SCHED_SLEEP, v->domain->domain_id, v->vcpu_id);
+    TRACE_TIME(TRC_SCHED_SLEEP, v->domain->domain_id, v->vcpu_id);
 
     rcu_read_lock(&sched_res_rculock);
 
@@ -965,7 +965,7 @@ void vcpu_wake(struct vcpu *v)
     spinlock_t *lock;
     struct sched_unit *unit = v->sched_unit;
 
-    TRACE_2D(TRC_SCHED_WAKE, v->domain->domain_id, v->vcpu_id);
+    TRACE_TIME(TRC_SCHED_WAKE, v->domain->domain_id, v->vcpu_id);
 
     rcu_read_lock(&sched_res_rculock);
 
@@ -1425,7 +1425,7 @@ void vcpu_block(void)
     }
     else
     {
-        TRACE_2D(TRC_SCHED_BLOCK, v->domain->domain_id, v->vcpu_id);
+        TRACE_TIME(TRC_SCHED_BLOCK, v->domain->domain_id, v->vcpu_id);
         raise_softirq(SCHEDULE_SOFTIRQ);
     }
 }
@@ -1498,7 +1498,7 @@ static long do_poll(const struct sched_poll *sched_poll)
     if ( sched_poll->timeout != 0 )
         set_timer(&v->poll_timer, sched_poll->timeout);
 
-    TRACE_2D(TRC_SCHED_BLOCK, d->domain_id, v->vcpu_id);
+    TRACE_TIME(TRC_SCHED_BLOCK, d->domain_id, v->vcpu_id);
     raise_softirq(SCHEDULE_SOFTIRQ);
 
     return 0;
@@ -1526,7 +1526,7 @@ long vcpu_yield(void)
 
     SCHED_STAT_CRANK(vcpu_yield);
 
-    TRACE_2D(TRC_SCHED_YIELD, current->domain->domain_id, current->vcpu_id);
+    TRACE_TIME(TRC_SCHED_YIELD, current->domain->domain_id, current->vcpu_id);
     raise_softirq(SCHEDULE_SOFTIRQ);
     return 0;
 }
@@ -1904,9 +1904,8 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         if ( copy_from_guest(&sched_shutdown, arg, 1) )
             break;
 
-        TRACE_3D(TRC_SCHED_SHUTDOWN,
-                 current->domain->domain_id, current->vcpu_id,
-                 sched_shutdown.reason);
+        TRACE_TIME(TRC_SCHED_SHUTDOWN, current->domain->domain_id,
+                   current->vcpu_id, sched_shutdown.reason);
         ret = domain_shutdown(current->domain, (u8)sched_shutdown.reason);
 
         break;
@@ -1921,8 +1920,8 @@ ret_t do_sched_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg)
         if ( copy_from_guest(&sched_shutdown, arg, 1) )
             break;
 
-        TRACE_3D(TRC_SCHED_SHUTDOWN_CODE,
-                 d->domain_id, current->vcpu_id, sched_shutdown.reason);
+        TRACE_TIME(TRC_SCHED_SHUTDOWN_CODE, d->domain_id, current->vcpu_id,
+                   sched_shutdown.reason);
 
         spin_lock(&d->shutdown_lock);
         if ( d->shutdown_code == SHUTDOWN_CODE_INVALID )
@@ -2085,7 +2084,7 @@ long sched_adjust(struct domain *d, struct xen_domctl_scheduler_op *op)
     rcu_read_lock(&sched_res_rculock);
 
     if ( (ret = sched_adjust_dom(dom_scheduler(d), d, op)) == 0 )
-        TRACE_1D(TRC_SCHED_ADJDOM, d->domain_id);
+        TRACE_TIME(TRC_SCHED_ADJDOM, d->domain_id);
 
     rcu_read_unlock(&sched_res_rculock);
 
@@ -2180,14 +2179,13 @@ static void sched_switch_units(struct sched_resource *sr,
         sr->curr = next;
         sr->prev = prev;
 
-        TRACE_3D(TRC_SCHED_SWITCH_INFPREV, prev->domain->domain_id,
-                 prev->unit_id, now - prev->state_entry_time);
-        TRACE_4D(TRC_SCHED_SWITCH_INFNEXT, next->domain->domain_id,
-                 next->unit_id,
-                 (next->vcpu_list->runstate.state == RUNSTATE_runnable) ?
-                 (now - next->state_entry_time) : 0, prev->next_time);
-        TRACE_4D(TRC_SCHED_SWITCH, prev->domain->domain_id, prev->unit_id,
-                 next->domain->domain_id, next->unit_id);
+        TRACE_TIME(TRC_SCHED_SWITCH_INFPREV, prev->domain->domain_id,
+                   prev->unit_id, now - prev->state_entry_time);
+        TRACE_TIME(TRC_SCHED_SWITCH_INFNEXT, next->domain->domain_id, next->unit_id,
+                   (next->vcpu_list->runstate.state == RUNSTATE_runnable) ?
+                   (now - next->state_entry_time) : 0, prev->next_time);
+        TRACE_TIME(TRC_SCHED_SWITCH, prev->domain->domain_id, prev->unit_id,
+                   next->domain->domain_id, next->unit_id);
 
         ASSERT(!unit_running(next));
 
@@ -2378,10 +2376,10 @@ static void sched_context_switch(struct vcpu *vprev, struct vcpu *vnext,
 {
     if ( unlikely(vprev == vnext) )
     {
-        TRACE_4D(TRC_SCHED_SWITCH_INFCONT,
-                 vnext->domain->domain_id, vnext->sched_unit->unit_id,
-                 now - vprev->runstate.state_entry_time,
-                 vprev->sched_unit->next_time);
+        TRACE_TIME(TRC_SCHED_SWITCH_INFCONT,
+                   vnext->domain->domain_id, vnext->sched_unit->unit_id,
+                   now - vprev->runstate.state_entry_time,
+                   vprev->sched_unit->next_time);
         sched_context_switched(vprev, vnext);
 
         /*
xen/common/sched/credit.c +33 -37

148 lines not on this page · raw message

xen/common/sched/null.c +37 -26

103 lines not on this page · raw message

Signature · 1 line
2.30.2
Reviewed-by on v1 4/7
#14 lore raw

Re: [PATCH 4/7] xen/sched: Clean up trace handling

Quoted 9 lines · Andrew Cooper

There is no need for bitfields anywhere - use more sensible types. There is also no need to cast 'd' to (unsigned char *) before passing it to a function taking void *. Switch to new trace_time() API.

No functional change.

#15 lore raw

PATCH 5/7 xen: Switch to new TRACE() API

In reply to Andrew Cooper

(Almost) no functional change.

irq_move_cleanup_interrupt() changes two smp_processor_id() calls to the 'me' local variable which manifests as a minor code improvement. All other differences in the compiled binary are to do with line numbers changing.

Some conversion notes:
* HVMTRACE_LONG_[234]D() and TRACE_2_LONG_[234]D() were latently buggy. They blindly discard extra parameters, but luckily no users are impacted. They are also obfuscated wrappers, depending on exactly one or two parameters being TRC_PAR_LONG() to compile successfully.
* HVMTRACE_LONG_1D() behaves unlike its named companions, and takes exactly one 64bit parameter which it splits manually. It's one user, vmx_cr_access()'s LMSW path, is gets adjusted.
* TRACE_?D() and TRACE_2_LONG_*() change to TRACE_TIME() as cycles is always enabled.
* HVMTRACE_ND() is opencoded for VMENTRY/VMEXIT records to include cycles. These are converted to TRACE_TIME(), with the old modifier parameter expressed as an OR at the callsite. One callsite, svm_vmenter_helper() had a nested tb_init_done check, which is dropped. (The optimiser also spotted this, which is why it doesn't manifest as a binary difference.)
* All uses of *LONG() are either opencoded or swapped to using a struct, to avoid MISRA issues.
* All HVMTRACE_?D() change to TRACE() as cycles is explicitly skipped.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: George Dunlap <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Nicola Vetrini <[email protected]>
CC: [email protected] <[email protected]>

v2.1:
* New
v3:
* Remove TRACE_PARAM64() for MISRA reasons.

---
 xen/arch/x86/acpi/cpu_idle.c  | 12 ++++----
 xen/arch/x86/compat.c         |  4 +--
 xen/arch/x86/cpu/mwait-idle.c |  6 ++--
 xen/arch/x86/emul-i8254.c     | 14 ++++-----
 xen/arch/x86/hvm/emulate.c    |  8 +++---
 xen/arch/x86/hvm/hpet.c       |  6 ++--
 xen/arch/x86/hvm/hvm.c        | 16 +++++------
 xen/arch/x86/hvm/rtc.c        | 12 ++++----
 xen/arch/x86/hvm/svm/intr.c   |  6 ++--
 xen/arch/x86/hvm/svm/svm.c    | 40 ++++++++++++--------------
 xen/arch/x86/hvm/vlapic.c     | 51 +++++++++++++++++++++++----------
 xen/arch/x86/hvm/vmx/intr.c   |  6 ++--
 xen/arch/x86/hvm/vmx/vmx.c    | 54 +++++++++++++++++------------------
 xen/arch/x86/hvm/vpic.c       | 13 ++++-----
 xen/arch/x86/irq.c            | 14 ++++-----
 xen/arch/x86/traps.c          |  2 +-
 xen/common/domain.c           |  4 +--
 xen/common/grant_table.c      |  6 ++--
 xen/drivers/cpufreq/utility.c |  2 +-
 19 files changed, 144 insertions(+), 132 deletions(-)
xen/arch/x86/acpi/cpu_idle.c +6 -6
index cfce4cc0408f..30094ff485b4 100644
@@ -767,7 +767,7 @@ static void cf_check acpi_processor_idle(void)
             /* Get start time (ticks) */
             t1 = alternative_call(cpuidle_get_tick);
             /* Trace cpu idle entry */
-            TRACE_4D(TRC_PM_IDLE_ENTRY, cx->idx, t1, exp, pred);
+            TRACE_TIME(TRC_PM_IDLE_ENTRY, cx->idx, t1, exp, pred);
 
             update_last_cx_stat(power, cx, t1);
 
@@ -777,8 +777,8 @@ static void cf_check acpi_processor_idle(void)
             t2 = alternative_call(cpuidle_get_tick);
             trace_exit_reason(irq_traced);
             /* Trace cpu idle exit */
-            TRACE_6D(TRC_PM_IDLE_EXIT, cx->idx, t2,
-                     irq_traced[0], irq_traced[1], irq_traced[2], irq_traced[3]);
+            TRACE_TIME(TRC_PM_IDLE_EXIT, cx->idx, t2,
+                       irq_traced[0], irq_traced[1], irq_traced[2], irq_traced[3]);
             /* Update statistics */
             update_idle_stats(power, cx, t1, t2);
             /* Re-enable interrupts */
@@ -798,7 +798,7 @@ static void cf_check acpi_processor_idle(void)
         /* Get start time (ticks) */
         t1 = alternative_call(cpuidle_get_tick);
         /* Trace cpu idle entry */
-        TRACE_4D(TRC_PM_IDLE_ENTRY, cx->idx, t1, exp, pred);
+        TRACE_TIME(TRC_PM_IDLE_ENTRY, cx->idx, t1, exp, pred);
 
         update_last_cx_stat(power, cx, t1);
 
@@ -853,8 +853,8 @@ static void cf_check acpi_processor_idle(void)
         cstate_restore_tsc();
         trace_exit_reason(irq_traced);
         /* Trace cpu idle exit */
-        TRACE_6D(TRC_PM_IDLE_EXIT, cx->idx, t2,
-                 irq_traced[0], irq_traced[1], irq_traced[2], irq_traced[3]);
+        TRACE_TIME(TRC_PM_IDLE_EXIT, cx->idx, t2,
+                   irq_traced[0], irq_traced[1], irq_traced[2], irq_traced[3]);
 
         /* Update statistics */
         update_idle_stats(power, cx, t1, t2);
xen/arch/x86/compat.c +2 -2
index a03106283028..217b5b1fcc41 100644
@@ -37,8 +37,8 @@ long do_sched_op_compat(int cmd, unsigned long arg)
         return do_sched_op(cmd, guest_handle_from_ptr(NULL, void));
 
     case SCHEDOP_shutdown:
-        TRACE_3D(TRC_SCHED_SHUTDOWN,
-                 current->domain->domain_id, current->vcpu_id, arg);
+        TRACE_TIME(TRC_SCHED_SHUTDOWN,
+                   current->domain->domain_id, current->vcpu_id, arg);
         domain_shutdown(current->domain, (u8)arg);
         break;
 
xen/arch/x86/cpu/mwait-idle.c +3 -3
index ff5c808bc952..ae6987117169 100644
@@ -962,7 +962,7 @@ static void cf_check mwait_idle(void)
 		lapic_timer_off();
 
 	before = alternative_call(cpuidle_get_tick);
-	TRACE_4D(TRC_PM_IDLE_ENTRY, cx->type, before, exp, pred);
+	TRACE_TIME(TRC_PM_IDLE_ENTRY, cx->type, before, exp, pred);
 
 	update_last_cx_stat(power, cx, before);
 
@@ -986,8 +986,8 @@ static void cf_check mwait_idle(void)
 
 	local_irq_enable();
 
-	TRACE_6D(TRC_PM_IDLE_EXIT, cx->type, after,
-		irq_traced[0], irq_traced[1], irq_traced[2], irq_traced[3]);
+	TRACE_TIME(TRC_PM_IDLE_EXIT, cx->type, after,
+		   irq_traced[0], irq_traced[1], irq_traced[2], irq_traced[3]);
 
 	if (!(lapic_timer_reliable_states & (1 << cx->type)))
 		lapic_timer_on();
xen/arch/x86/emul-i8254.c +7 -7
index 0191f80ba251..144aa168a3f0 100644
@@ -94,7 +94,7 @@ static void cf_check pit_time_fired(struct vcpu *v, void *priv)
 {
     uint64_t *count_load_time = priv;
 
-    TRACE_0D(TRC_HVM_EMUL_PIT_TIMER_CB);
+    TRACE_TIME(TRC_HVM_EMUL_PIT_TIMER_CB);
     *count_load_time = get_guest_time(v);
 }
 
@@ -128,19 +128,19 @@ static void pit_load_count(PITState *pit, int channel, int val)
     case 2:
     case 3:
         /* Periodic timer. */
-        TRACE_2D(TRC_HVM_EMUL_PIT_START_TIMER, period, period);
+        TRACE_TIME(TRC_HVM_EMUL_PIT_START_TIMER, period, period);
         create_periodic_time(v, &pit->pt0, period, period, 0, pit_time_fired,
                              &pit->count_load_time[channel], false);
         break;
     case 1:
     case 4:
         /* One-shot timer. */
-        TRACE_2D(TRC_HVM_EMUL_PIT_START_TIMER, period, 0);
+        TRACE_TIME(TRC_HVM_EMUL_PIT_START_TIMER, period, 0);
         create_periodic_time(v, &pit->pt0, period, 0, 0, pit_time_fired,
                              &pit->count_load_time[channel], false);
         break;
     default:
-        TRACE_0D(TRC_HVM_EMUL_PIT_STOP_TIMER);
+        TRACE_TIME(TRC_HVM_EMUL_PIT_STOP_TIMER);
         destroy_periodic_time(&pit->pt0);
         break;
     }
@@ -404,7 +404,7 @@ void pit_stop_channel0_irq(PITState *pit)
     if ( !has_vpit(current->domain) )
         return;
 
-    TRACE_0D(TRC_HVM_EMUL_PIT_STOP_TIMER);
+    TRACE_TIME(TRC_HVM_EMUL_PIT_STOP_TIMER);
     spin_lock(&pit->lock);
     destroy_periodic_time(&pit->pt0);
     spin_unlock(&pit->lock);
@@ -615,7 +615,7 @@ void pit_reset(struct domain *d)
 
     if ( is_hvm_domain(d) )
     {
-        TRACE_0D(TRC_HVM_EMUL_PIT_STOP_TIMER);
+        TRACE_TIME(TRC_HVM_EMUL_PIT_STOP_TIMER);
         destroy_periodic_time(&pit->pt0);
         pit->pt0.source = PTSRC_isa;
     }
@@ -660,7 +660,7 @@ void pit_deinit(struct domain *d)
 
     if ( is_hvm_domain(d) )
     {
-        TRACE_0D(TRC_HVM_EMUL_PIT_STOP_TIMER);
+        TRACE_TIME(TRC_HVM_EMUL_PIT_STOP_TIMER);
         destroy_periodic_time(&pit->pt0);
     }
 }
xen/arch/x86/hvm/emulate.c +4 -4
index ab1bc516839a..d8f36206a712 100644
@@ -2181,7 +2181,7 @@ static int cf_check hvmemul_read_cr(
     case 3:
     case 4:
         *val = current->arch.hvm.guest_cr[reg];
-        HVMTRACE_LONG_2D(CR_READ, reg, TRC_PAR_LONG(*val));
+        TRACE(TRC_HVM_CR_READ64, reg, *val, *val >> 32);
         return X86EMUL_OKAY;
     default:
         break;
@@ -2197,7 +2197,7 @@ static int cf_check hvmemul_write_cr(
 {
     int rc;
 
-    HVMTRACE_LONG_2D(CR_WRITE, reg, TRC_PAR_LONG(val));
+    TRACE(TRC_HVM_CR_WRITE64, reg, val, val >> 32);
     switch ( reg )
     {
     case 0:
@@ -2242,7 +2242,7 @@ static int cf_check hvmemul_read_xcr(
     int rc = x86emul_read_xcr(reg, val, ctxt);
 
     if ( rc == X86EMUL_OKAY )
-        HVMTRACE_LONG_2D(XCR_READ, reg, TRC_PAR_LONG(*val));
+        TRACE(TRC_HVM_XCR_READ64, reg, *val, *val >> 32);
 
     return rc;
 }
@@ -2252,7 +2252,7 @@ static int cf_check hvmemul_write_xcr(
     uint64_t val,
     struct x86_emulate_ctxt *ctxt)
 {
-    HVMTRACE_LONG_2D(XCR_WRITE, reg, TRC_PAR_LONG(val));
+    TRACE(TRC_HVM_XCR_WRITE64, reg, val, val >> 32);
 
     return x86emul_write_xcr(reg, val, ctxt);
 }
xen/arch/x86/hvm/hpet.c +3 -3
index 1db9c0b60ee0..0356ade5957b 100644
@@ -201,7 +201,7 @@ static void hpet_stop_timer(HPETState *h, unsigned int tn,
 {
     ASSERT(tn < HPET_TIMER_NUM);
     ASSERT(rw_is_write_locked(&h->lock));
-    TRACE_1D(TRC_HVM_EMUL_HPET_STOP_TIMER, tn);
+    TRACE_TIME(TRC_HVM_EMUL_HPET_STOP_TIMER, tn);
     destroy_periodic_time(&h->pt[tn]);
     /* read the comparator to get it updated so a read while stopped will
      * return the expected value. */
@@ -305,8 +305,8 @@ static void hpet_set_timer(HPETState *h, unsigned int tn,
     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(diff_ns), TRC_PAR_LONG(period_ns));
+    TRACE_TIME(TRC_HVM_EMUL_HPET_START_TIMER, tn, irq,
+               diff_ns, diff_ns >> 32, period_ns, period_ns >> 32);
 
     create_periodic_time(vhpet_vcpu(h), &h->pt[tn], diff_ns, period_ns,
                          irq, timer_level(h, tn) ? hpet_timer_fired : NULL,
xen/arch/x86/hvm/hvm.c +7 -9
index c75959588c0e..e8af42eb499d 100644
@@ -1699,7 +1699,7 @@ void hvm_hlt(unsigned int eflags)
 
     do_sched_op(SCHEDOP_block, guest_handle_from_ptr(NULL, void));
 
-    HVMTRACE_1D(HLT, /* pending = */ vcpu_runnable(curr));
+    TRACE(TRC_HVM_HLT, /* pending = */ vcpu_runnable(curr));
 }
 
 void hvm_triple_fault(void)
@@ -2153,7 +2153,7 @@ int hvm_mov_to_cr(unsigned int cr, unsigned int gpr)
     unsigned long val = *decode_gpr(guest_cpu_user_regs(), gpr);
     int rc;
 
-    HVMTRACE_LONG_2D(CR_WRITE, cr, TRC_PAR_LONG(val));
+    TRACE(TRC_HVM_CR_WRITE64, cr, val, val >> 32);
     HVM_DBG_LOG(DBG_LEVEL_1, "CR%u, value = %lx", cr, val);
 
     switch ( cr )
@@ -2218,7 +2218,7 @@ int hvm_mov_from_cr(unsigned int cr, unsigned int gpr)
     }
 
     *reg = val;
-    HVMTRACE_LONG_2D(CR_READ, cr, TRC_PAR_LONG(val));
+    TRACE(TRC_HVM_CR_READ64, cr, val, val >> 32);
     HVM_DBG_LOG(DBG_LEVEL_VMMU, "CR%u, value = %lx", cr, val);
 
     return X86EMUL_OKAY;
@@ -3508,7 +3508,7 @@ int hvm_vmexit_cpuid(struct cpu_user_regs *regs, unsigned int inst_len)
     }
 
     guest_cpuid(curr, leaf, subleaf, &res);
-    HVMTRACE_6D(CPUID, leaf, subleaf, res.a, res.b, res.c, res.d);
+    TRACE(TRC_HVM_CPUID, leaf, subleaf, res.a, res.b, res.c, res.d);
 
     regs->rax = res.a;
     regs->rbx = res.b;
@@ -3522,7 +3522,7 @@ void hvm_rdtsc_intercept(struct cpu_user_regs *regs)
 {
     msr_split(regs, hvm_get_guest_tsc(current));
 
-    HVMTRACE_2D(RDTSC, regs->eax, regs->edx);
+    TRACE(TRC_HVM_RDTSC, regs->eax, regs->edx);
 }
 
 int hvm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
@@ -3629,8 +3629,7 @@ int hvm_msr_read_intercept(unsigned int msr, uint64_t *msr_content)
     }
 
  out:
-    HVMTRACE_3D(MSR_READ, msr,
-                (uint32_t)*msr_content, (uint32_t)(*msr_content >> 32));
+    TRACE(TRC_HVM_MSR_READ, msr, *msr_content, *msr_content >> 32);
     return ret;
 
  gp_fault:
@@ -3646,8 +3645,7 @@ int hvm_msr_write_intercept(unsigned int msr, uint64_t msr_content,
     struct domain *d = v->domain;
     int ret;
 
-    HVMTRACE_3D(MSR_WRITE, msr,
-               (uint32_t)msr_content, (uint32_t)(msr_content >> 32));
+    TRACE(TRC_HVM_MSR_WRITE, msr, msr_content, msr_content >> 32);
 
     if ( may_defer && unlikely(monitored_msr(v->domain, msr)) )
     {
xen/arch/x86/hvm/rtc.c +6 -6
index 4b31382619f4..3ad5e4faba76 100644
@@ -91,7 +91,7 @@ static void cf_check rtc_pf_callback(struct vcpu *v, void *opaque)
          && ++(s->pt_dead_ticks) >= 10 )
     {
         /* VM is ignoring its RTC; no point in running the timer */
-        TRACE_0D(TRC_HVM_EMUL_RTC_STOP_TIMER);
+        TRACE_TIME(TRC_HVM_EMUL_RTC_STOP_TIMER);
         destroy_periodic_time(&s->pt);
         s->period = 0;
     }
@@ -154,7 +154,7 @@ static void rtc_timer_update(RTCState *s)
                     delta = period - ((now - s->start_time) % period);
                 if ( s->hw.cmos_data[RTC_REG_B] & RTC_PIE )
                 {
-                    TRACE_2D(TRC_HVM_EMUL_RTC_START_TIMER, delta, period);
+                    TRACE_TIME(TRC_HVM_EMUL_RTC_START_TIMER, delta, period);
                     create_periodic_time(v, &s->pt, delta, period,
                                          RTC_IRQ, rtc_pf_callback, s, false);
                 }
@@ -165,7 +165,7 @@ static void rtc_timer_update(RTCState *s)
         }
         /* fall through */
     default:
-        TRACE_0D(TRC_HVM_EMUL_RTC_STOP_TIMER);
+        TRACE_TIME(TRC_HVM_EMUL_RTC_STOP_TIMER);
         destroy_periodic_time(&s->pt);
         s->period = 0;
         break;
@@ -552,7 +552,7 @@ static int rtc_ioport_write(void *opaque, uint32_t addr, uint32_t data)
         rtc_update_irq(s);
         if ( (data ^ orig) & RTC_PIE )
         {
-            TRACE_0D(TRC_HVM_EMUL_RTC_STOP_TIMER);
+            TRACE_TIME(TRC_HVM_EMUL_RTC_STOP_TIMER);
             destroy_periodic_time(&s->pt);
             s->period = 0;
             rtc_timer_update(s);
@@ -806,7 +806,7 @@ void rtc_reset(struct domain *d)
     if ( !has_vrtc(d) )
         return;
 
-    TRACE_0D(TRC_HVM_EMUL_RTC_STOP_TIMER);
+    TRACE_TIME(TRC_HVM_EMUL_RTC_STOP_TIMER);
     destroy_periodic_time(&s->pt);
     s->period = 0;
     s->pt.source = PTSRC_isa;
@@ -891,7 +891,7 @@ void rtc_deinit(struct domain *d)
 
     spin_barrier(&s->lock);
 
-    TRACE_0D(TRC_HVM_EMUL_RTC_STOP_TIMER);
+    TRACE_TIME(TRC_HVM_EMUL_RTC_STOP_TIMER);
     destroy_periodic_time(&s->pt);
     kill_timer(&s->update_timer);
     kill_timer(&s->update_timer2);
xen/arch/x86/hvm/svm/intr.c +3 -3
index 4805c5567213..dc684fdc843e 100644
@@ -90,8 +90,8 @@ static void svm_enable_intr_window(struct vcpu *v, struct hvm_intack intack)
         }
     }
 
-    HVMTRACE_3D(INTR_WINDOW, intack.vector, intack.source,
-                vmcb->event_inj.v ? vmcb->event_inj.vector : -1);
+    TRACE(TRC_HVM_INTR_WINDOW, intack.vector, intack.source,
+          vmcb->event_inj.v ? vmcb->event_inj.vector : -1);
 
     /*
      * Create a dummy virtual interrupt to intercept as soon as the
@@ -206,7 +206,7 @@ void asmlinkage svm_intr_assist(void)
     }
     else
     {
-        HVMTRACE_2D(INJ_VIRQ, intack.vector, /*fake=*/ 0);
+        TRACE(TRC_HVM_INJ_VIRQ, intack.vector, /*fake=*/ 0);
         svm_inject_extint(v, intack.vector);
         pt_intr_post(v, intack);
     }
xen/arch/x86/hvm/svm/svm.c +19 -21
index b1ab0b568b85..09a79d761163 100644
@@ -1066,10 +1066,8 @@ void asmlinkage svm_vmenter_helper(void)
 
     svm_asid_handle_vmrun();
 
-    if ( unlikely(tb_init_done) )
-        HVMTRACE_ND(VMENTRY,
-                    nestedhvm_vcpu_in_guestmode(curr) ? TRC_HVM_NESTEDFLAG : 0,
-                    1/*cycles*/);
+    TRACE_TIME(TRC_HVM_VMENTRY |
+               (nestedhvm_vcpu_in_guestmode(curr) ? TRC_HVM_NESTEDFLAG : 0));
 
     svm_sync_vmcb(curr, vmcb_needs_vmsave);
 
@@ -1441,10 +1439,10 @@ static void cf_check svm_inject_event(const struct x86_event *event)
 
     if ( _event.vector == X86_EXC_PF &&
          _event.type == X86_EVENTTYPE_HW_EXCEPTION )
-        HVMTRACE_LONG_2D(PF_INJECT, _event.error_code,
-                         TRC_PAR_LONG(_event.cr2));
+        TRACE(TRC_HVM_PF_INJECT64, _event.error_code,
+              _event.cr2, _event.cr2 >> 32);
     else
-        HVMTRACE_2D(INJ_EXC, _event.vector, _event.error_code);
+        TRACE(TRC_HVM_INJ_EXC, _event.vector, _event.error_code);
 }
 
 static bool cf_check svm_event_pending(const struct vcpu *v)
@@ -1751,7 +1749,7 @@ static void svm_dr_access(struct vcpu *v, struct cpu_user_regs *regs)
 {
     struct vmcb_struct *vmcb = vcpu_nestedhvm(v).nv_n1vmcx;
 
-    HVMTRACE_0D(DR_WRITE);
+    TRACE(TRC_HVM_DR_WRITE);
     __restore_debug_registers(vmcb, v);
 }
 
@@ -2402,7 +2400,7 @@ static void svm_invlpga_intercept(
 
 static void svm_invlpg_intercept(unsigned long linear)
 {
-    HVMTRACE_LONG_2D(INVLPG, 0, TRC_PAR_LONG(linear));
+    TRACE(TRC_HVM_INVLPG64, 0, linear, linear >> 32);
     paging_invlpg(current, linear);
 }
 
@@ -2629,11 +2627,11 @@ void asmlinkage svm_vmexit_handler(void)
     exit_reason = vmcb->exitcode;
 
     if ( hvm_long_mode_active(v) )
-        HVMTRACE_ND(VMEXIT64, vcpu_guestmode ? TRC_HVM_NESTEDFLAG : 0,
-                    1/*cycles*/, exit_reason, TRC_PAR_LONG(regs->rip));
+        TRACE_TIME(TRC_HVM_VMEXIT64 | (vcpu_guestmode ? TRC_HVM_NESTEDFLAG : 0),
+                   exit_reason, regs->rip, regs->rip >> 32);
     else
-        HVMTRACE_ND(VMEXIT, vcpu_guestmode ? TRC_HVM_NESTEDFLAG : 0,
-                    1/*cycles*/, exit_reason, regs->eip);
+        TRACE_TIME(TRC_HVM_VMEXIT | (vcpu_guestmode ? TRC_HVM_NESTEDFLAG : 0),
+                   exit_reason, regs->eip);
 
     if ( vcpu_guestmode )
     {
@@ -2728,17 +2726,17 @@ void asmlinkage svm_vmexit_handler(void)
     {
     case VMEXIT_INTR:
         /* Asynchronous event, handled when we STGI'd after the VMEXIT. */
-        HVMTRACE_0D(INTR);
+        TRACE(TRC_HVM_INTR);
         break;
 
     case VMEXIT_NMI:
         /* Asynchronous event, handled when we STGI'd after the VMEXIT. */
-        HVMTRACE_0D(NMI);
+        TRACE(TRC_HVM_NMI);
         break;
 
     case VMEXIT_SMI:
         /* Asynchronous event, handled when we STGI'd after the VMEXIT. */
-        HVMTRACE_0D(SMI);
+        TRACE(TRC_HVM_SMI);
         break;
 
     case VMEXIT_ICEBP:
@@ -2826,9 +2824,9 @@ void asmlinkage svm_vmexit_handler(void)
             if ( trace_will_trace_event(TRC_SHADOW) )
                 break;
             if ( hvm_long_mode_active(v) )
-                HVMTRACE_LONG_2D(PF_XEN, regs->error_code, TRC_PAR_LONG(va));
+                TRACE(TRC_HVM_PF_XEN64, regs->error_code, va, va >> 32);
             else
-                HVMTRACE_2D(PF_XEN, regs->error_code, va);
+                TRACE(TRC_HVM_PF_XEN, regs->error_code, va);
             break;
         }
 
@@ -2837,7 +2835,7 @@ void asmlinkage svm_vmexit_handler(void)
     }
 
     case VMEXIT_EXCEPTION_AC:
-        HVMTRACE_1D(TRAP, X86_EXC_AC);
+        TRACE(TRC_HVM_TRAP, X86_EXC_AC);
         hvm_inject_hw_exception(X86_EXC_AC, vmcb->ei.exc.ec);
         break;
 
@@ -2847,7 +2845,7 @@ void asmlinkage svm_vmexit_handler(void)
 
     /* Asynchronous event, handled when we STGI'd after the VMEXIT. */
     case VMEXIT_EXCEPTION_MC:
-        HVMTRACE_0D(MCE);
+        TRACE(TRC_HVM_MCE);
         svm_vmexit_mce_intercept(v, regs);
         break;
 
@@ -2993,7 +2991,7 @@ void asmlinkage svm_vmexit_handler(void)
         if ( (insn_len = svm_get_insn_len(v, INSTR_VMCALL)) == 0 )
             break;
         BUG_ON(vcpu_guestmode);
-        HVMTRACE_1D(VMMCALL, regs->eax);
+        TRACE(TRC_HVM_VMMCALL, regs->eax);
 
         if ( hvm_hypercall(regs) == HVM_HCALL_completed )
             __update_guest_eip(regs, insn_len);
xen/arch/x86/hvm/vlapic.c +36 -15

111 lines not on this page · raw message

xen/arch/x86/hvm/vmx/intr.c +3 -3
index 8beeaab1517b..d36498d83104 100644
@@ -67,8 +67,8 @@ static void vmx_enable_intr_window(struct vcpu *v, struct hvm_intack intack)
         unsigned long intr;
 
         __vmread(VM_ENTRY_INTR_INFO, &intr);
-        HVMTRACE_3D(INTR_WINDOW, intack.vector, intack.source,
-                    (intr & INTR_INFO_VALID_MASK) ? intr & 0xff : -1);
+        TRACE(TRC_HVM_INTR_WINDOW, intack.vector, intack.source,
+              (intr & INTR_INFO_VALID_MASK) ? intr & 0xff : -1);
     }
 
     if ( (intack.source == hvm_intsrc_nmi) && cpu_has_vmx_vnmi )
@@ -390,7 +390,7 @@ void asmlinkage vmx_intr_assist(void)
     }
     else
     {
-        HVMTRACE_2D(INJ_VIRQ, intack.vector, /*fake=*/ 0);
+        TRACE(TRC_HVM_INJ_VIRQ, intack.vector, /*fake=*/ 0);
         vmx_inject_extint(intack.vector, intack.source);
         pt_intr_post(v, intack);
     }
xen/arch/x86/hvm/vmx/vmx.c +26 -28

174 lines not on this page · raw message

xen/arch/x86/hvm/vpic.c +6 -7
index 4e23247a464a..7c3b5c7254a8 100644
@@ -99,8 +99,7 @@ static void vpic_update_int_output(struct hvm_hw_vpic *vpic)
     ASSERT(vpic_is_locked(vpic));
 
     irq = vpic_get_highest_priority_irq(vpic);
-    TRACE_3D(TRC_HVM_EMUL_PIC_INT_OUTPUT, vpic->int_output, vpic->is_master,
-             irq);
+    TRACE_TIME(TRC_HVM_EMUL_PIC_INT_OUTPUT, vpic->int_output, vpic->is_master, irq);
     if ( vpic->int_output == (!vpic->init_state && irq >= 0) )
         return;
 
@@ -119,7 +118,7 @@ static void vpic_update_int_output(struct hvm_hw_vpic *vpic)
 
             if ( v != NULL )
             {
-                TRACE_1D(TRC_HVM_EMUL_PIC_KICK, irq);
+                TRACE_TIME(TRC_HVM_EMUL_PIC_KICK, irq);
                 vcpu_kick(v);
             }
         }
@@ -144,7 +143,7 @@ static void __vpic_intack(struct hvm_hw_vpic *vpic, int irq)
 
     ASSERT(vpic_is_locked(vpic));
 
-    TRACE_2D(TRC_HVM_EMUL_PIC_INTACK, vpic->is_master, irq);
+    TRACE_TIME(TRC_HVM_EMUL_PIC_INTACK, vpic->is_master, irq);
     /* Edge-triggered: clear the IRR (forget the edge). */
     if ( !(vpic->elcr & mask) )
         vpic->irr &= ~mask;
@@ -526,7 +525,7 @@ void vpic_irq_positive_edge(struct domain *d, int irq)
     ASSERT(irq <= 15);
     ASSERT(vpic_is_locked(vpic));
 
-    TRACE_1D(TRC_HVM_EMUL_PIC_POSEDGE, irq);
+    TRACE_TIME(TRC_HVM_EMUL_PIC_POSEDGE, irq);
     if ( irq == 2 )
         return;
 
@@ -544,7 +543,7 @@ void vpic_irq_negative_edge(struct domain *d, int irq)
     ASSERT(irq <= 15);
     ASSERT(vpic_is_locked(vpic));
 
-    TRACE_1D(TRC_HVM_EMUL_PIC_NEGEDGE, irq);
+    TRACE_TIME(TRC_HVM_EMUL_PIC_NEGEDGE, irq);
     if ( irq == 2 )
         return;
 
@@ -562,7 +561,7 @@ int vpic_ack_pending_irq(struct vcpu *v)
 
     accept = vlapic_accept_pic_intr(v);
 
-    TRACE_2D(TRC_HVM_EMUL_PIC_PEND_IRQ_CALL, accept, vpic->int_output);
+    TRACE_TIME(TRC_HVM_EMUL_PIC_PEND_IRQ_CALL, accept, vpic->int_output);
     if ( !accept || !vpic->int_output )
         return -1;
 
xen/arch/x86/irq.c +6 -8
index 0487f734a5d2..2c1f858d3e64 100644
@@ -229,7 +229,7 @@ static void _clear_irq_vector(struct irq_desc *desc)
         for_each_cpu(cpu, tmp_mask)
         {
             ASSERT(per_cpu(vector_irq, cpu)[old_vector] == irq);
-            TRACE_3D(TRC_HW_IRQ_MOVE_FINISH, irq, old_vector, cpu);
+            TRACE_TIME(TRC_HW_IRQ_MOVE_FINISH, irq, old_vector, cpu);
             per_cpu(vector_irq, cpu)[old_vector] = ~irq;
         }
 
@@ -796,13 +796,11 @@ void cf_check irq_move_cleanup_interrupt(void)
                 goto unlock;
             }
             send_IPI_self(IRQ_MOVE_CLEANUP_VECTOR);
-            TRACE_3D(TRC_HW_IRQ_MOVE_CLEANUP_DELAY,
-                     irq, vector, smp_processor_id());
+            TRACE_TIME(TRC_HW_IRQ_MOVE_CLEANUP_DELAY, irq, vector, me);
             goto unlock;
         }
 
-        TRACE_3D(TRC_HW_IRQ_MOVE_CLEANUP,
-                 irq, vector, smp_processor_id());
+        TRACE_TIME(TRC_HW_IRQ_MOVE_CLEANUP, irq, vector, me);
 
         per_cpu(vector_irq, me)[vector] = ~irq;
         desc->arch.move_cleanup_count--;
@@ -1943,7 +1941,7 @@ void do_IRQ(struct cpu_user_regs *regs)
                     spin_unlock(&desc->lock);
                 }
             }
-            TRACE_1D(TRC_HW_IRQ_UNMAPPED_VECTOR, vector);
+            TRACE_TIME(TRC_HW_IRQ_UNMAPPED_VECTOR, vector);
         }
         goto out_no_unlock;
     }
@@ -1984,7 +1982,7 @@ void do_IRQ(struct cpu_user_regs *regs)
 
         tsc_in = tb_init_done ? get_cycles() : 0;
         do_IRQ_guest(desc, vector);
-        TRACE_3D(TRC_HW_IRQ_HANDLED, irq, tsc_in, get_cycles());
+        TRACE_TIME(TRC_HW_IRQ_HANDLED, irq, tsc_in, get_cycles());
         goto out_no_end;
     }
 
@@ -2008,7 +2006,7 @@ void do_IRQ(struct cpu_user_regs *regs)
 
         tsc_in = tb_init_done ? get_cycles() : 0;
         action->handler(irq, action->dev_id);
-        TRACE_3D(TRC_HW_IRQ_HANDLED, irq, tsc_in, get_cycles());
+        TRACE_TIME(TRC_HW_IRQ_HANDLED, irq, tsc_in, get_cycles());
 
         spin_lock_irq(&desc->lock);
     }
xen/arch/x86/traps.c +1 -1
index d554c9d41edd..468a03608102 100644
@@ -1899,7 +1899,7 @@ void asmlinkage do_device_not_available(struct cpu_user_regs *regs)
         curr->arch.pv.ctrlreg[0] &= ~X86_CR0_TS;
     }
     else
-        TRACE_0D(TRC_PV_MATH_STATE_RESTORE);
+        TRACE_TIME(TRC_PV_MATH_STATE_RESTORE);
 #else
     ASSERT_UNREACHABLE();
 #endif
xen/common/domain.c +2 -2
index 1f0d23a1e09b..fe8a216d29b6 100644
@@ -625,7 +625,7 @@ struct domain *domain_create(domid_t domid,
         hardware_domain = d;
     }
 
-    TRACE_1D(TRC_DOM0_DOM_ADD, d->domain_id);
+    TRACE_TIME(TRC_DOM0_DOM_ADD, d->domain_id);
 
     lock_profile_register_struct(LOCKPROF_TYPE_PERDOM, d, domid);
 
@@ -1222,7 +1222,7 @@ void domain_destroy(struct domain *d)
     if ( atomic_cmpxchg(&d->refcnt, 0, DOMAIN_DESTROYED) != 0 )
         return;
 
-    TRACE_1D(TRC_DOM0_DOM_REM, d->domain_id);
+    TRACE_TIME(TRC_DOM0_DOM_REM, d->domain_id);
 
     /* Delete from task list and task hashtable. */
     spin_lock(&domlist_update_lock);
xen/common/grant_table.c +3 -3
index 77089308829b..8d34c8815f05 100644
@@ -1307,7 +1307,7 @@ map_grant_ref(
             goto undo_out;
     }
 
-    TRACE_1D(TRC_MEM_PAGE_GRANT_MAP, op->dom);
+    TRACE_TIME(TRC_MEM_PAGE_GRANT_MAP, op->dom);
 
     /*
      * All maptrack entry users check mt->flags first before using the
@@ -1434,7 +1434,7 @@ unmap_common(
         return;
     }
 
-    TRACE_1D(TRC_MEM_PAGE_GRANT_UNMAP, dom);
+    TRACE_TIME(TRC_MEM_PAGE_GRANT_UNMAP, dom);
 
     rgt = rd->grant_table;
 
@@ -2445,7 +2445,7 @@ gnttab_transfer(
         put_gfn(d, gop.mfn);
 #endif
 
-        TRACE_1D(TRC_MEM_PAGE_GRANT_TRANSFER, e->domain_id);
+        TRACE_TIME(TRC_MEM_PAGE_GRANT_TRANSFER, e->domain_id);
 
         /* Tell the guest about its new page frame. */
         grant_read_lock(e->grant_table);
xen/drivers/cpufreq/utility.c +1 -1
index dbf8985969b2..ede22650a387 100644
@@ -368,7 +368,7 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
         retval = alternative_call(cpufreq_driver.target,
                                   policy, target_freq, relation);
         if ( retval == 0 )
-            TRACE_2D(TRC_PM_FREQ_CHANGE, prev_freq/1000, policy->cur/1000);
+            TRACE_TIME(TRC_PM_FREQ_CHANGE, prev_freq / 1000, policy->cur / 1000);
     }
 
     return retval;
Signature · 1 line
2.30.2
#16 lore raw

Re: [PATCH 5/7] xen: Switch to new TRACE() API

Quoted 10 lines · Andrew Cooper
xen/arch/x86/hvm/vlapic.c +3 -3
@@ -736,9 +736,19 @@ static void vlapic_update_timer(struct vlapic *vlapic, uint32_t lvtt,
             delta = delta * vlapic->hw.timer_divisor / old_divisor;
         }
 
-        TRACE_2_LONG_3D(TRC_HVM_EMUL_LAPIC_START_TIMER, TRC_PAR_LONG(delta),
-                        TRC_PAR_LONG(is_periodic ? period : 0),
-                        vlapic->pt.irq);
+        if ( unlikely(tb_init_done) )
+        {
+            struct {

xen/arch/x86/hvm/vlapic.c static void vlapic_update_timer(struct vlapic *vlapic, uint32_t lvtt, · line 751

Quoted 10 lines
xen/arch/x86/hvm/vlapic.c +10 -0
+                uint64_t delta, period;
+                uint32_t irq;
+            } __packed d = {
+                .delta = delta,
+                .period = is_periodic ? period : 0,
+                .irq = vlapic->pt.irq,
+            };
+
+            trace_time(TRC_HVM_EMUL_LAPIC_START_TIMER, sizeof(d), &d);
+        }

Instead of this open-coding, how about

if ( is_periodic )
TRACE_TIME(TRC_HVM_EMUL_LAPIC_START_TIMER, delta, delta >> 32,
period, period >> 32, vlapic->pt.irq);
else
TRACE_TIME(TRC_HVM_EMUL_LAPIC_START_TIMER, delta, delta >> 32,
0, 0, vlapic->pt.irq);

thus improving similarity / grep-ability with ...

Quoted 12 lines
xen/arch/x86/hvm/vlapic.c +2 -2
@@ -1208,8 +1218,8 @@ void vlapic_tdt_msr_set(struct vlapic *vlapic, uint64_t value)
 
         vlapic->hw.tdt_msr = value;
         /* .... reprogram tdt timer */
-        TRACE_2_LONG_3D(TRC_HVM_EMUL_LAPIC_START_TIMER, TRC_PAR_LONG(delta),
-                        TRC_PAR_LONG(0LL), vlapic->pt.irq);
+        TRACE_TIME(TRC_HVM_EMUL_LAPIC_START_TIMER, delta, delta >> 32,
+                   0, 0, vlapic->pt.irq);
         create_periodic_time(v, &vlapic->pt, delta, 0,
                              vlapic->pt.irq, vlapic_tdt_pt_cb,
                              &vlapic->timer_last_update, false);

xen/arch/x86/hvm/vlapic.c void vlapic_tdt_msr_set(struct vlapic *vlapic, uint64_t value) · line 1239

Quoted 10 lines
xen/arch/x86/hvm/vlapic.c +2 -2
@@ -1222,8 +1232,8 @@ void vlapic_tdt_msr_set(struct vlapic *vlapic, uint64_t value)
         /* trigger a timer event if needed */
         if ( value > 0 )
         {
-            TRACE_2_LONG_3D(TRC_HVM_EMUL_LAPIC_START_TIMER, TRC_PAR_LONG(0LL),
-                            TRC_PAR_LONG(0LL), vlapic->pt.irq);
+            TRACE_TIME(TRC_HVM_EMUL_LAPIC_START_TIMER, 0, 0,
+                       0, 0, vlapic->pt.irq);
             create_periodic_time(v, &vlapic->pt, 0, 0,
                                  vlapic->pt.irq, vlapic_tdt_pt_cb,
                                  &vlapic->timer_last_update, false);

... these.

Quoted 9 lines
xen/arch/x86/hvm/vlapic.c +3 -2
@@ -1476,8 +1486,19 @@ static void lapic_rearm(struct vlapic *s)
               (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(is_periodic ? period : 0LL), s->pt.irq);
+    if ( unlikely(tb_init_done) )
+    {
+         struct {

xen/arch/x86/hvm/vlapic.c static void lapic_rearm(struct vlapic *s) · line 1501

Quoted 10 lines
xen/arch/x86/hvm/vlapic.c +10 -0
+             uint64_t delta, period;
+             uint32_t irq;
+        } __packed d = {
+             .delta = period,
+             .period = is_periodic ? period : 0,
+             .irq = s->pt.irq,
+        };
+
+        trace_time(TRC_HVM_EMUL_LAPIC_START_TIMER, sizeof(d), &d);
+    }

Same here then.

Other than that you had an ack from me for this already, which you may very well retain / reinstate.

Jan

Reviewed-by
#17 lore raw

Re: [PATCH 5/7] xen: Switch to new TRACE() API

Quoted 25 lines · Jan Beulich
Quoted 10 lines · Andrew Cooper
(quoted diff) +3 -3
@@ -736,9 +736,19 @@ static void vlapic_update_timer(struct vlapic *vlapic, uint32_t lvtt,
             delta = delta * vlapic->hw.timer_divisor / old_divisor;
         }
 
-        TRACE_2_LONG_3D(TRC_HVM_EMUL_LAPIC_START_TIMER, TRC_PAR_LONG(delta),
-                        TRC_PAR_LONG(is_periodic ? period : 0),
-                        vlapic->pt.irq);
+        if ( unlikely(tb_init_done) )
+        {
+            struct {

Review static void vlapic_update_timer(struct vlapic *vlapic, uint32_t lvtt, · line 751

Quoted 10 lines
(quoted diff) +10 -0
+                uint64_t delta, period;
+                uint32_t irq;
+            } __packed d = {
+                .delta = delta,
+                .period = is_periodic ? period : 0,
+                .irq = vlapic->pt.irq,
+            };
+
+            trace_time(TRC_HVM_EMUL_LAPIC_START_TIMER, sizeof(d), &d);
+        }

Instead of this open-coding, how about

Quoted 8 lines

if ( is_periodic )
TRACE_TIME(TRC_HVM_EMUL_LAPIC_START_TIMER, delta, delta >> 32,
period, period >> 32, vlapic->pt.irq);
else
TRACE_TIME(TRC_HVM_EMUL_LAPIC_START_TIMER, delta, delta >> 32,
0, 0, vlapic->pt.irq);

thus improving similarity / grep-ability with ...

Yuck -- I'm not keen on breaking the similarity, but I'm *really* not a fan of duplicating code. Both are kind of "code smell"-y to me, but I think the second seems worse.

It sort of looks to me like the source of the problem is that the period variable is overloaded somehow; in that it's used to update some calculation even if !is_periodic, and so the two places it's used as an actual period (the trace code, and the call to create_periodic_time()) need to figure out if periodic is for them to use or not.

What about adding a variable, "timer_period" for that purpose? Something like the following?

xen/arch/x86/hvm/vlapic.c +0 -0
index dcbcf4a1fe..ea14fc1587 100644
@@ -729,6 +729,8 @@ static void vlapic_update_timer(struct vlapic

*vlapic, uint32_t lvtt,

     if ( delta && (is_oneshot || is_periodic) )
     {
+        uint64_t timer_period = 0;
+
         if ( vlapic->hw.timer_divisor != old_divisor )
         {
             period = (uint64_t)vlapic_get_reg(vlapic, APIC_TMICT)
@@ -736,12 +738,15 @@ static void vlapic_update_timer(struct vlapic
*vlapic, uint32_t lvtt,
             delta = delta * vlapic->hw.timer_divisor / old_divisor;
         }

- TRACE_2_LONG_3D(TRC_HVM_EMUL_LAPIC_START_TIMER, TRC_PAR_LONG(delta),
- TRC_PAR_LONG(is_periodic ? period : 0),
- vlapic->pt.irq);
+ if ( is_periodic )
+ timer_period = period;
+
+ TRACE_TIME(TRC_HVM_EMUL_LAPIC_START_TIMER, delta, delta >> 32,
+ timer_period, timer_period >> 32,
+ vlapic->pt.irq);

         create_periodic_time(current, &vlapic->pt, delta,

- is_periodic ? period : 0, vlapic->pt.irq,
+ timer_period, vlapic->pt.irq,
is_periodic ? vlapic_pt_cb : NULL, &vlapic->timer_last_update, false);

As with Jan, I'd be OK with checking it in the way it is if you prefer, so:

#18 lore raw

Re: [PATCH 5/7] xen: Switch to new TRACE() API

Quoted 33 lines · George Dunlap
Quoted 32 lines · Jan Beulich
Quoted 10 lines · Andrew Cooper
(quoted diff) +3 -3
@@ -736,9 +736,19 @@ static void vlapic_update_timer(struct vlapic *vlapic, uint32_t lvtt,
             delta = delta * vlapic->hw.timer_divisor / old_divisor;
         }
 
-        TRACE_2_LONG_3D(TRC_HVM_EMUL_LAPIC_START_TIMER, TRC_PAR_LONG(delta),
-                        TRC_PAR_LONG(is_periodic ? period : 0),
-                        vlapic->pt.irq);
+        if ( unlikely(tb_init_done) )
+        {
+            struct {

Review static void vlapic_update_timer(struct vlapic *vlapic, uint32_t lvtt, · line 751

Quoted 10 lines
(quoted diff) +10 -0
+                uint64_t delta, period;
+                uint32_t irq;
+            } __packed d = {
+                .delta = delta,
+                .period = is_periodic ? period : 0,
+                .irq = vlapic->pt.irq,
+            };
+
+            trace_time(TRC_HVM_EMUL_LAPIC_START_TIMER, sizeof(d), &d);
+        }

Instead of this open-coding, how about

if ( is_periodic )
TRACE_TIME(TRC_HVM_EMUL_LAPIC_START_TIMER, delta, delta >> 32,
period, period >> 32, vlapic->pt.irq);
else
TRACE_TIME(TRC_HVM_EMUL_LAPIC_START_TIMER, delta, delta >> 32,
0, 0, vlapic->pt.irq);

Quoted 4 lines
Quoted 1 line

thus improving similarity / grep-ability with ...

Yuck -- I'm not keen on breaking the similarity, but I'm *really* not a fan of duplicating code.

Neither am I, just that ...

Quoted 1 line

Both are kind of "code smell"-y to me, but I think the second seems worse.

... it was the other way around to me.

Quoted 9 lines

It sort of looks to me like the source of the problem is that the period variable is overloaded somehow; in that it's used to update some calculation even if !is_periodic, and so the two places it's used as an actual period (the trace code, and the call to create_periodic_time()) need to figure out if periodic is for them to use or not.

What about adding a variable, "timer_period" for that purpose? Something like the following?

Yeah, why not.

Jan

Quoted 39 lines
xen/arch/x86/hvm/vlapic.c +2 -0
index dcbcf4a1fe..ea14fc1587 100644
@@ -729,6 +729,8 @@ static void vlapic_update_timer(struct vlapic
 *vlapic, uint32_t lvtt,
 
     if ( delta && (is_oneshot || is_periodic) )
     {
+        uint64_t timer_period = 0;
+
         if ( vlapic->hw.timer_divisor != old_divisor )
         {

period = (uint64_t)vlapic_get_reg(vlapic, APIC_TMICT)

xen/arch/x86/hvm/vlapic.c +7 -4
@@ -736,12 +738,15 @@ static void vlapic_update_timer(struct vlapic
 *vlapic, uint32_t lvtt,
             delta = delta * vlapic->hw.timer_divisor / old_divisor;
         }
 
-        TRACE_2_LONG_3D(TRC_HVM_EMUL_LAPIC_START_TIMER, TRC_PAR_LONG(delta),
-                        TRC_PAR_LONG(is_periodic ? period : 0),
-                        vlapic->pt.irq);
+        if ( is_periodic )
+            timer_period = period;
+
+        TRACE_TIME(TRC_HVM_EMUL_LAPIC_START_TIMER, delta, delta >> 32,
+                   timer_period, timer_period >> 32,
+                   vlapic->pt.irq);
 
         create_periodic_time(current, &vlapic->pt, delta,
-                             is_periodic ? period : 0, vlapic->pt.irq,
+                             timer_period, vlapic->pt.irq,
                              is_periodic ? vlapic_pt_cb : NULL,
                              &vlapic->timer_last_update, false);

As with Jan, I'd be OK with checking it in the way it is if you prefer, so:

#19 lore raw

Re: [PATCH 5/7] xen: Switch to new TRACE() API

In reply to Andrew Cooper
Quoted 6 lines · Andrew Cooper

(Almost) no functional change.

irq_move_cleanup_interrupt() changes two smp_processor_id() calls to the 'me' local variable which manifests as a minor code improvement. All other differences in the compiled binary are to do with line numbers changing.

Probably also worth noting that (as Jan points out in 7/7) by bypassing HTMTRACE_ND, we're also bypassing the whole DEFAULT_HVM_* and DO_TRC_HVM_* thing, which in theory could streamline the code by causing the compiler to elide certain trace points.

-George

#20 lore raw

PATCH 6/7 xen/trace: Update final {__,}trace_var() users to the new API

In reply to Andrew Cooper

This logically drops the cycles parameter, as it's now encoded directly in the event code.

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: George Dunlap <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Nicola Vetrini <[email protected]>
CC: [email protected] <[email protected]>

v3:
* New

---
 xen/arch/x86/hvm/emulate.c      |  2 +-
 xen/arch/x86/hvm/hvm.c          |  3 +--
 xen/arch/x86/hvm/svm/svm.c      |  2 +-
 xen/arch/x86/hvm/vmx/vmx.c      |  2 +-
 xen/arch/x86/irq.c              |  2 +-
 xen/arch/x86/mm/p2m-pod.c       |  8 ++++----
 xen/arch/x86/mm/p2m-pt.c        |  2 +-
 xen/arch/x86/mm/shadow/common.c |  6 +++---
 xen/arch/x86/mm/shadow/multi.c  | 10 +++++-----
 xen/arch/x86/pv/trace.c         | 21 +++++++++++----------
 xen/common/memory.c             |  2 +-
 xen/common/trace.c              |  2 +-
 12 files changed, 31 insertions(+), 31 deletions(-)
xen/arch/x86/hvm/emulate.c +1 -1
index d8f36206a712..a37525316c6e 100644
@@ -67,7 +67,7 @@ static void hvmtrace_io_assist(const ioreq_t *p)
         size *= 2;
     }
 
-    trace_var(event, 0/*!cycles*/, size, buffer);
+    trace(event, size, buffer);
 }
 
 static int cf_check null_read(
xen/arch/x86/hvm/hvm.c +1 -2
index e8af42eb499d..bb4eda4ecde2 100644
@@ -5136,8 +5136,7 @@ long do_hvm_op(unsigned long op, XEN_GUEST_HANDLE_PARAM(void) arg)
             return -EINVAL;
 
         /* Cycles will be taken at the vmexit and vmenter */
-        trace_var(tr.event | TRC_GUEST, 0 /*!cycles*/,
-                  tr.extra_bytes, tr.extra);
+        trace(tr.event | TRC_GUEST, tr.extra_bytes, tr.extra);
         break;
     }
 
xen/arch/x86/hvm/svm/svm.c +1 -1
index 09a79d761163..2d0c8762359f 100644
@@ -1681,7 +1681,7 @@ static void svm_do_nested_pgfault(struct vcpu *v,
         _d.mfn = mfn_x(mfn);
         _d.p2mt = p2mt;
 
-        __trace_var(TRC_HVM_NPF, 0, sizeof(_d), &_d);
+        trace(TRC_HVM_NPF, sizeof(_d), &_d);
     }
 
     switch ( ret )
xen/arch/x86/hvm/vmx/vmx.c +1 -1
index ac73f58798ed..255c97f18162 100644
@@ -3767,7 +3767,7 @@ static void ept_handle_violation(ept_qual_t q, paddr_t gpa)
         _d.qualification = q.raw;
         _d.mfn = mfn_x(get_gfn_query_unlocked(d, gfn, &_d.p2mt));
 
-        __trace_var(TRC_HVM_NPF, 0, sizeof(_d), &_d);
+        trace(TRC_HVM_NPF, sizeof(_d), &_d);
     }
 
     if ( q.gla_valid )
xen/arch/x86/irq.c +1 -1
index 2c1f858d3e64..45a74c6a0256 100644
@@ -135,7 +135,7 @@ static void _trace_irq_mask(uint32_t event, int irq, int vector,
 
     memcpy(d.mask, mask,
            min(sizeof(d.mask), BITS_TO_LONGS(nr_cpu_ids) * sizeof(long)));
-    trace_var(event, 1, sizeof(d), &d);
+    trace_time(event, sizeof(d), &d);
 }
 
 static void trace_irq_mask(uint32_t event, int irq, int vector,
xen/arch/x86/mm/p2m-pod.c +4 -4
index 65d31e552305..79a016682f1d 100644
@@ -854,7 +854,7 @@ p2m_pod_zero_check_superpage(struct p2m_domain *p2m, gfn_t gfn)
         t.d = d->domain_id;
         t.order = 9;
 
-        __trace_var(TRC_MEM_POD_ZERO_RECLAIM, 0, sizeof(t), &t);
+        trace(TRC_MEM_POD_ZERO_RECLAIM, sizeof(t), &t);
     }
 
     /*
@@ -1022,7 +1022,7 @@ p2m_pod_zero_check(struct p2m_domain *p2m, const gfn_t *gfns, unsigned int count
                 t.d = d->domain_id;
                 t.order = 0;
 
-                __trace_var(TRC_MEM_POD_ZERO_RECLAIM, 0, sizeof(t), &t);
+                trace(TRC_MEM_POD_ZERO_RECLAIM, sizeof(t), &t);
             }
 
             /* Add to cache, and account for the new p2m PoD entry */
@@ -1262,7 +1262,7 @@ p2m_pod_demand_populate(struct p2m_domain *p2m, gfn_t gfn,
         t.d = d->domain_id;
         t.order = order;
 
-        __trace_var(TRC_MEM_POD_POPULATE, 0, sizeof(t), &t);
+        trace(TRC_MEM_POD_POPULATE, sizeof(t), &t);
     }
 
     pod_unlock_and_flush(p2m);
@@ -1307,7 +1307,7 @@ p2m_pod_demand_populate(struct p2m_domain *p2m, gfn_t gfn,
         t.d = d->domain_id;
         t.order = order;
 
-        __trace_var(TRC_MEM_POD_SUPERPAGE_SPLINTER, 0, sizeof(t), &t);
+        trace(TRC_MEM_POD_SUPERPAGE_SPLINTER, sizeof(t), &t);
     }
 
     return true;
xen/arch/x86/mm/p2m-pt.c +1 -1
index 348130d0dd3b..666abd46be16 100644
@@ -608,7 +608,7 @@ p2m_pt_set_entry(struct p2m_domain *p2m, gfn_t gfn_, mfn_t mfn,
         t.d = d->domain_id;
         t.order = page_order;
 
-        __trace_var(TRC_MEM_SET_P2M_ENTRY, 0, sizeof(t), &t);
+        trace(TRC_MEM_SET_P2M_ENTRY, sizeof(t), &t);
     }
 
     /* Carry out any eventually pending earlier changes first. */
xen/arch/x86/mm/shadow/common.c +3 -3
index 8aa7b698f879..1303aec85918 100644
@@ -433,7 +433,7 @@ static inline void trace_resync(int event, mfn_t gmfn)
         /* Convert gmfn to gfn */
         gfn_t gfn = mfn_to_gfn(current->domain, gmfn);
 
-        __trace_var(event, 0/*!tsc*/, sizeof(gfn), &gfn);
+        trace(event, sizeof(gfn), &gfn);
     }
 }
 
@@ -910,7 +910,7 @@ static inline void trace_shadow_prealloc_unpin(struct domain *d, mfn_t smfn)
 
         ASSERT(mfn_valid(smfn));
         gfn = mfn_to_gfn(d, backpointer(mfn_to_page(smfn)));
-        __trace_var(TRC_SHADOW_PREALLOC_UNPIN, 0/*!tsc*/, sizeof(gfn), &gfn);
+        trace(TRC_SHADOW_PREALLOC_UNPIN, sizeof(gfn), &gfn);
     }
 }
 
@@ -1808,7 +1808,7 @@ static inline void trace_shadow_wrmap_bf(mfn_t gmfn)
         /* Convert gmfn to gfn */
         gfn_t gfn = mfn_to_gfn(current->domain, gmfn);
 
-        __trace_var(TRC_SHADOW_WRMAP_BF, 0/*!tsc*/, sizeof(gfn), &gfn);
+        trace(TRC_SHADOW_WRMAP_BF, sizeof(gfn), &gfn);
     }
 }
 
xen/arch/x86/mm/shadow/multi.c +5 -5
index 90cf0ceaa367..bcd02b2d0037 100644
@@ -1979,7 +1979,7 @@ static inline void trace_shadow_gen(u32 event, guest_va_t va)
     if ( tb_init_done )
     {
         event |= (GUEST_PAGING_LEVELS-2)<<8;
-        __trace_var(event, 0/*!tsc*/, sizeof(va), &va);
+        trace(event, sizeof(va), &va);
     }
 }
 
@@ -2003,7 +2003,7 @@ static inline void trace_shadow_fixup(guest_l1e_t gl1e,
         d.va = va;
         d.flags = this_cpu(trace_shadow_path_flags);
 
-        __trace_var(event, 0/*!tsc*/, sizeof(d), &d);
+        trace(event, sizeof(d), &d);
     }
 }
 
@@ -2027,7 +2027,7 @@ static inline void trace_not_shadow_fault(guest_l1e_t gl1e,
         d.va = va;
         d.flags = this_cpu(trace_shadow_path_flags);
 
-        __trace_var(event, 0/*!tsc*/, sizeof(d), &d);
+        trace(event, sizeof(d), &d);
     }
 }
 
@@ -2053,7 +2053,7 @@ static inline void trace_shadow_emulate_other(u32 event,
         d.gfn=gfn_x(gfn);
         d.va = va;
 
-        __trace_var(event, 0/*!tsc*/, sizeof(d), &d);
+        trace(event, sizeof(d), &d);
     }
 }
 
@@ -2106,7 +2106,7 @@ static inline void trace_shadow_emulate(guest_l1e_t gl1e, unsigned long va)
 #endif
         d.flags = this_cpu(trace_shadow_path_flags);
 
-        __trace_var(event, 0/*!tsc*/, sizeof(d), &d);
+        trace(event, sizeof(d), &d);
     }
 }
 #endif /* CONFIG_HVM */
xen/arch/x86/pv/trace.c +11 -10
index cf3897061e1f..70f426f2095c 100644
@@ -19,7 +19,7 @@ void __trace_pv_trap(int trapnr, unsigned long eip,
             .error_code     = error_code,
         };
 
-        __trace_var(TRC_PV_TRAP, 1, sizeof(d), &d);
+        trace_time(TRC_PV_TRAP, sizeof(d), &d);
     }
     else
     {
@@ -35,7 +35,7 @@ void __trace_pv_trap(int trapnr, unsigned long eip,
             .error_code     = error_code,
         };
 
-        __trace_var(TRC_PV_TRAP | TRC_64_FLAG, 1, sizeof(d), &d);
+        trace_time(TRC_PV_TRAP | TRC_64_FLAG, sizeof(d), &d);
     }
 }
 
@@ -53,7 +53,7 @@ void __trace_pv_page_fault(unsigned long addr, unsigned error_code)
             .error_code = error_code,
         };
 
-        __trace_var(TRC_PV_PAGE_FAULT, 1, sizeof(d), &d);
+        trace_time(TRC_PV_PAGE_FAULT, sizeof(d), &d);
     }
     else
     {
@@ -66,7 +66,7 @@ void __trace_pv_page_fault(unsigned long addr, unsigned error_code)
             .error_code = error_code,
         };
 
-        __trace_var(TRC_PV_PAGE_FAULT | TRC_64_FLAG, 1, sizeof(d), &d);
+        trace_time(TRC_PV_PAGE_FAULT | TRC_64_FLAG, sizeof(d), &d);
     }
 }
 
@@ -75,10 +75,11 @@ void __trace_trap_one_addr(unsigned event, unsigned long va)
     if ( is_pv_32bit_vcpu(current) )
     {
         u32 d = va;
-        __trace_var(event, 1, sizeof(d), &d);
+
+        trace_time(event, sizeof(d), &d);
     }
     else
-        __trace_var(event | TRC_64_FLAG, 1, sizeof(va), &va);
+        trace_time(event | TRC_64_FLAG, sizeof(va), &va);
 }
 
 void __trace_trap_two_addr(unsigned event, unsigned long va1,
@@ -93,7 +94,7 @@ void __trace_trap_two_addr(unsigned event, unsigned long va1,
             .va2 = va2,
         };
 
-        __trace_var(event, 1, sizeof(d), &d);
+        trace_time(event, sizeof(d), &d);
     }
     else
     {
@@ -104,7 +105,7 @@ void __trace_trap_two_addr(unsigned event, unsigned long va1,
             .va2 = va2,
         };
 
-        __trace_var(event | TRC_64_FLAG, 1, sizeof(d), &d);
+        trace_time(event | TRC_64_FLAG, sizeof(d), &d);
     }
 }
 
@@ -123,7 +124,7 @@ void __trace_ptwr_emulation(unsigned long addr, l1_pgentry_t npte)
             .eip  = eip,
         };
 
-        __trace_var(TRC_PV_PTWR_EMULATION_PAE, 1, sizeof(d), &d);
+        trace_time(TRC_PV_PTWR_EMULATION_PAE, sizeof(d), &d);
     }
     else
     {
@@ -136,6 +137,6 @@ void __trace_ptwr_emulation(unsigned long addr, l1_pgentry_t npte)
             .rip  = eip,
         };
 
-        __trace_var(TRC_PV_PTWR_EMULATION | TRC_64_FLAG, 1, sizeof(d), &d);
+        trace_time(TRC_PV_PTWR_EMULATION | TRC_64_FLAG, sizeof(d), &d);
     }
 }
xen/common/memory.c +1 -1
index b3b05c2ec090..3cecfdee9518 100644
@@ -483,7 +483,7 @@ static void decrease_reservation(struct memop_args *a)
             t.d = a->domain->domain_id;
             t.order = a->extent_order;
         
-            __trace_var(TRC_MEM_DECREASE_RESERVATION, 0, sizeof(t), &t);
+            trace(TRC_MEM_DECREASE_RESERVATION, sizeof(t), &t);
         }
 
         /* See if populate-on-demand wants to handle this */
xen/common/trace.c +1 -1
index c94ce1f7dc90..27c8a19f0549 100644
@@ -868,7 +868,7 @@ void __trace_hypercall(uint32_t event, unsigned long op,
         break;
     }
 
-    __trace_var(event, 1, sizeof(uint32_t) * (1 + (a - d.args)), &d);
+    trace_time(event, sizeof(uint32_t) * (1 + (a - d.args)), &d);
 }
 
 /*
Signature · 1 line
2.30.2
Reviewed-by on v1 6/7
#21 lore raw

Re: [PATCH 6/7] xen/trace: Update final {__,}trace_var() users to the new API

Quoted 2 lines · Andrew Cooper

This logically drops the cycles parameter, as it's now encoded directly in the event code.

That encoding is an internal detail of the new API; for the purposes of the callers the pattern looks to be that ...

xen/arch/x86/hvm/emulate.c static void hvmtrace_io_assist(const ioreq_t *p) · line 70

Quoted 8 lines
xen/arch/x86/hvm/emulate.c +1 -1
@@ -67,7 +67,7 @@ static void hvmtrace_io_assist(const ioreq_t *p)
         size *= 2;
     }
 
-    trace_var(event, 0/*!cycles*/, size, buffer);
+    trace(event, size, buffer);

... the respective parameter being 0 translates to trace(), while ...

xen/arch/x86/irq.c static void _trace_irq_mask(uint32_t event, int irq, int vector, · line 138

Quoted 8 lines
xen/arch/x86/irq.c +1 -1
@@ -135,7 +135,7 @@ static void _trace_irq_mask(uint32_t event, int irq, int vector,
 
     memcpy(d.mask, mask,
            min(sizeof(d.mask), BITS_TO_LONGS(nr_cpu_ids) * sizeof(long)));
-    trace_var(event, 1, sizeof(d), &d);
+    trace_time(event, sizeof(d), &d);

... the parameter being 1 translates to trace_time(). Imo the description would better express it that way. Irrespective, assuming that pattern is what is meant to hold,

Jan

Reviewed-by on v1 6/7
#22 lore raw

Re: [PATCH 6/7] xen/trace: Update final {__,}trace_var() users to the new API

In reply to Andrew Cooper
Quoted 3 lines · Andrew Cooper

This logically drops the cycles parameter, as it's now encoded directly in the event code.

So to make Jan's comment more specific, what about something like this:

This primarily consists of converting the cycles parameter into the appropriate function: 0 -> trace(), 1 -> trace_time().

Quoted 3 lines

No functional change.

#23 lore raw

PATCH 7/7 xen/trace: Drop old trace API

In reply to Andrew Cooper

With all users updated to the new API, drop the old API. This includes all of asm/hvm/trace.h, which allows us to drop some includes.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: George Dunlap <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Nicola Vetrini <[email protected]>
CC: [email protected] <[email protected]>

v2.1:
* New
v3:
* Extend to drop __trace_var() too

---
 xen/arch/x86/hvm/emulate.c             |   1 -
 xen/arch/x86/hvm/hpet.c                |   1 -
 xen/arch/x86/hvm/hvm.c                 |   1 -
 xen/arch/x86/hvm/io.c                  |   1 -
 xen/arch/x86/hvm/svm/intr.c            |   1 -
 xen/arch/x86/hvm/svm/svm.c             |   1 -
 xen/arch/x86/hvm/vlapic.c              |   1 -
 xen/arch/x86/hvm/vmx/intr.c            |   1 -
 xen/arch/x86/hvm/vmx/vmx.c             |   1 -
 xen/arch/x86/include/asm/hvm/trace.h   | 114 -------------------------
 xen/arch/x86/include/asm/hvm/vmx/vmx.h |   1 -
 xen/common/trace.c                     |  12 +--
 xen/include/xen/trace.h                |  47 ----------
 13 files changed, 3 insertions(+), 180 deletions(-)
 delete mode 100644 xen/arch/x86/include/asm/hvm/trace.h
xen/arch/x86/hvm/emulate.c +0 -1
index a37525316c6e..02e378365b40 100644
@@ -22,7 +22,6 @@
 #include <asm/hvm/emulate.h>
 #include <asm/hvm/hvm.h>
 #include <asm/hvm/monitor.h>
-#include <asm/hvm/trace.h>
 #include <asm/hvm/support.h>
 #include <asm/iocap.h>
 #include <asm/vm_event.h>
xen/arch/x86/hvm/hpet.c +0 -1
index 0356ade5957b..dd85e46d4001 100644
@@ -8,7 +8,6 @@
 #include <asm/hvm/vpt.h>
 #include <asm/hvm/io.h>
 #include <asm/hvm/save.h>
-#include <asm/hvm/trace.h>
 #include <asm/current.h>
 #include <asm/hpet.h>
 #include <asm/mc146818rtc.h>
xen/arch/x86/hvm/hvm.c +0 -1
index bb4eda4ecde2..cedaf428b400 100644
@@ -51,7 +51,6 @@
 #include <asm/hvm/vpt.h>
 #include <asm/hvm/support.h>
 #include <asm/hvm/cacheattr.h>
-#include <asm/hvm/trace.h>
 #include <asm/hvm/nestedhvm.h>
 #include <asm/hvm/monitor.h>
 #include <asm/hvm/viridian.h>
xen/arch/x86/hvm/io.c +0 -1
index 06283b41c463..db726b38177b 100644
@@ -28,7 +28,6 @@
 #include <asm/hvm/vpt.h>
 #include <asm/hvm/vpic.h>
 #include <asm/hvm/vlapic.h>
-#include <asm/hvm/trace.h>
 #include <asm/hvm/emulate.h>
 #include <public/sched.h>
 #include <xen/iocap.h>
xen/arch/x86/hvm/svm/intr.c +0 -1
index dc684fdc843e..780c7e178a52 100644
@@ -24,7 +24,6 @@
 #include <xen/kernel.h>
 #include <public/hvm/ioreq.h>
 #include <xen/domain_page.h>
-#include <asm/hvm/trace.h>
 
 #include "nestedhvm.h"
 
xen/arch/x86/hvm/svm/svm.c +0 -1
index 2d0c8762359f..c94b83dc22f7 100644
@@ -28,7 +28,6 @@
 #include <asm/hvm/svm/svm.h>
 #include <asm/hvm/svm/svmdebug.h>
 #include <asm/hvm/svm/vmcb.h>
-#include <asm/hvm/trace.h>
 #include <asm/iocap.h>
 #include <asm/i387.h>
 #include <asm/monitor.h>
xen/arch/x86/hvm/vlapic.c +0 -1
index 65e171d4751f..7a971470537e 100644
@@ -27,7 +27,6 @@
 #include <asm/hvm/io.h>
 #include <asm/hvm/support.h>
 #include <asm/hvm/nestedhvm.h>
-#include <asm/hvm/trace.h>
 #include <asm/hvm/viridian.h>
 #include <public/hvm/ioreq.h>
 #include <public/hvm/params.h>
xen/arch/x86/hvm/vmx/intr.c +0 -1
index d36498d83104..1a4dfb499bcd 100644
@@ -24,7 +24,6 @@
 #include <asm/hvm/vlapic.h>
 #include <asm/hvm/nestedhvm.h>
 #include <public/hvm/ioreq.h>
-#include <asm/hvm/trace.h>
 #include <asm/vm_event.h>
 
 /*
xen/arch/x86/hvm/vmx/vmx.c +0 -1
index 255c97f18162..3fbbd44a6b45 100644
@@ -37,7 +37,6 @@
 #include <asm/x86_emulate.h>
 #include <asm/hvm/vpt.h>
 #include <public/hvm/save.h>
-#include <asm/hvm/trace.h>
 #include <asm/hvm/monitor.h>
 #include <asm/xenoprof.h>
 #include <asm/gdbsx.h>
xen/arch/x86/include/asm/hvm/trace.h deleted +0 -114

114 lines not on this page · raw message

xen/arch/x86/include/asm/hvm/vmx/vmx.h +0 -1
index 8ffab7d94c26..1489dd05c2a1 100644
@@ -15,7 +15,6 @@
 #include <asm/processor.h>
 #include <asm/p2m.h>
 #include <asm/i387.h>
-#include <asm/hvm/trace.h>
 #include <asm/hvm/vmx/vmcs.h>
 
 extern int8_t opt_ept_exec_sp;
xen/common/trace.c +3 -9
index 27c8a19f0549..c9c555094bf7 100644
@@ -666,22 +666,21 @@ static DECLARE_SOFTIRQ_TASKLET(trace_notify_dom0_tasklet,
                                trace_notify_dom0, NULL);
 
 /**
- * __trace_var - Enters a trace tuple into the trace buffer for the current CPU.
+ * trace - Enters a trace tuple into the trace buffer for the current CPU.
  * @event: the event type being logged
- * @cycles: include tsc timestamp into trace record
  * @extra: size of additional trace data in bytes
  * @extra_data: pointer to additional trace data
  *
  * Logs a trace record into the appropriate buffer.
  */
-void __trace_var(u32 event, bool cycles, unsigned int extra,
-                 const void *extra_data)
+void trace(uint32_t event, unsigned int extra, const void *extra_data)
 {
     struct t_buf *buf;
     unsigned long flags;
     u32 bytes_to_tail, bytes_to_wrap;
     unsigned int rec_size, total_size;
     bool started_below_highwater;
+    bool cycles = event & TRC_HD_CYCLE_FLAG;
 
     if( !tb_init_done )
         return;
@@ -808,11 +807,6 @@ void __trace_var(u32 event, bool cycles, unsigned int extra,
         tasklet_schedule(&trace_notify_dom0_tasklet);
 }
 
-void trace(uint32_t event, unsigned int extra, const void *extra_data)
-{
-    __trace_var(event, event & TRC_HD_CYCLE_FLAG, extra, extra_data);
-}
-
 void __trace_hypercall(uint32_t event, unsigned long op,
                        const xen_ulong_t *args)
 {
xen/include/xen/trace.h +0 -47

63 lines not on this page · raw message

Signature · 1 line
2.30.2
Acked-by on v1 7/7
#24 lore raw

Re: [PATCH 7/7] xen/trace: Drop old trace API

Quoted 13 lines · Andrew Cooper

With all users updated to the new API, drop the old API. This includes all of asm/hvm/trace.h, which allows us to drop some includes.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: George Dunlap <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Nicola Vetrini <[email protected]>
CC: [email protected] <[email protected]>

Quoted 4 lines

v2.1:
* New
v3:
* Extend to drop __trace_var() too

And still

(with the never responded to remark in [1] still holding)

Jan

[1] https://lists.xen.org/archives/html/xen-devel/2021-09/msg02154.html

#26 lore raw
In reply to Andrew Cooper
Quoted 6 lines · Andrew Cooper

Rework the trace API to unify it (remove the HVM specific obfuscation), and remove MISRA violations.

v3:
* Delete TRACE_PARAM64()

Quoted 8 lines

Andrew Cooper (7):
xen/trace: Introduce new API
xen/credit2: Clean up trace handling
xen/rt: Clean up trace handling
xen/sched: Clean up trace handling
xen: Switch to new TRACE() API
xen/trace: Update final {__,}trace_var() users to the new API xen/trace: Drop old trace API

Hi Andrew,

thanks for the series. I'll run it trough ECLAIR when I have some spare time, so that we can assess the impact especially on Rule 20.7.

Signature · 2 lines
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)
#27 lore raw
Quoted 16 lines · Nicola Vetrini
Quoted 6 lines · Andrew Cooper

Rework the trace API to unify it (remove the HVM specific obfuscation), and remove MISRA violations.

v3:
* Delete TRACE_PARAM64()

Quoted 8 lines

Andrew Cooper (7):
xen/trace: Introduce new API
xen/credit2: Clean up trace handling
xen/rt: Clean up trace handling
xen/sched: Clean up trace handling
xen: Switch to new TRACE() API
xen/trace: Update final {__,}trace_var() users to the new API xen/trace: Drop old trace API

Quoted 3 lines

Hi Andrew,

thanks for the series. I'll run it trough ECLAIR when I have some spare time, so that we can assess the impact especially on Rule 20.7.

Everything is fine for Rule 20.7 in a differential run with respect to yesterday's staging branch

Signature · 2 lines
Nicola Vetrini, BSc
Software Engineer, BUGSENG srl (https://bugseng.com)