[2/3] xen/trace: Implement TRACE_?D() in a more efficient fashon
diff mbox series

Message ID 20190718170716.22544-3-andrew.cooper3@citrix.com
State New
Headers show
Series
  • xen/trace: Misc improvements
Related show

Commit Message

Andrew Cooper July 18, 2019, 5:07 p.m. UTC
These can easily be expressed with a variadic macro. No functional change.

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

Interestingly, this results in fractionally different (but equally correct)
code generation in vlapic_update_timer().  Everywhere else is identical.
---
 xen/include/xen/trace.h | 99 +++++++++++++------------------------------------
 1 file changed, 26 insertions(+), 73 deletions(-)

Comments

George Dunlap July 18, 2019, 8:59 p.m. UTC | #1
> On Jul 18, 2019, at 6:07 PM, Andrew Cooper <andrew.cooper3@citrix.com> wrote:
> 
> These can easily be expressed with a variadic macro. No functional change.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> CC: George Dunlap <george.dunlap@eu.citrix.com>
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Wei Liu <wl@xen.org>
> CC: Roger Pau Monné <roger.pau@citrix.com>
> 
> Interestingly, this results in fractionally different (but equally correct)
> code generation in vlapic_update_timer().  Everywhere else is identical.
> ---
> xen/include/xen/trace.h | 99 +++++++++++++------------------------------------
> 1 file changed, 26 insertions(+), 73 deletions(-)
> 
> diff --git a/xen/include/xen/trace.h b/xen/include/xen/trace.h
> index e6a4ef93cc..7f5a904103 100644
> --- a/xen/include/xen/trace.h
> +++ b/xen/include/xen/trace.h
> @@ -81,80 +81,33 @@ static inline void __trace_hypercall(uint32_t event, unsigned long op,
>     do {                                        \
>         trace_var(_e, 1, 0, NULL);              \
>     } while ( 0 )
> -  
> -#define TRACE_1D(_e,d1)                                         \
> -    do {                                                        \
> -        if ( unlikely(tb_init_done) )                           \
> -        {                                                       \
> -            u32 _d[1];                                          \
> -            _d[0] = d1;                                         \
> -            __trace_var(_e, 1, sizeof(_d), _d);                 \
> -        }                                                       \
> -    } while ( 0 )
> - 
> -#define TRACE_2D(_e,d1,d2)                                      \
> -    do {                                                        \
> -        if ( unlikely(tb_init_done) )                           \
> -        {                                                       \
> -            u32 _d[2];                                          \
> -            _d[0] = d1;                                         \
> -            _d[1] = d2;                                         \
> -            __trace_var(_e, 1, sizeof(_d), _d);                 \
> -        }                                                       \
> -    } while ( 0 )
> - 
> -#define TRACE_3D(_e,d1,d2,d3)                                   \
> -    do {                                                        \
> -        if ( unlikely(tb_init_done) )                           \
> -        {                                                       \
> -            u32 _d[3];                                          \
> -            _d[0] = d1;                                         \
> -            _d[1] = d2;                                         \
> -            _d[2] = d3;                                         \
> -            __trace_var(_e, 1, sizeof(_d), _d);                 \
> -        }                                                       \
> -    } while ( 0 )
> - 
> -#define TRACE_4D(_e,d1,d2,d3,d4)                                \
> -    do {                                                        \
> -        if ( unlikely(tb_init_done) )                           \
> -        {                                                       \
> -            u32 _d[4];                                          \
> -            _d[0] = d1;                                         \
> -            _d[1] = d2;                                         \
> -            _d[2] = d3;                                         \
> -            _d[3] = d4;                                         \
> -            __trace_var(_e, 1, sizeof(_d), _d);                 \
> -        }                                                       \
> -    } while ( 0 )
> - 
> -#define TRACE_5D(_e,d1,d2,d3,d4,d5)                             \
> -    do {                                                        \
> -        if ( unlikely(tb_init_done) )                           \
> -        {                                                       \
> -            u32 _d[5];                                          \
> -            _d[0] = d1;                                         \
> -            _d[1] = d2;                                         \
> -            _d[2] = d3;                                         \
> -            _d[3] = d4;                                         \
> -            _d[4] = d5;                                         \
> -            __trace_var(_e, 1, sizeof(_d), _d);                 \
> -        }                                                       \
> -    } while ( 0 )
> 
> -#define TRACE_6D(_e,d1,d2,d3,d4,d5,d6)                             \
> -    do {                                                        \
> -        if ( unlikely(tb_init_done) )                           \
> -        {                                                       \
> -            u32 _d[6];                                          \
> -            _d[0] = d1;                                         \
> -            _d[1] = d2;                                         \
> -            _d[2] = d3;                                         \
> -            _d[3] = d4;                                         \
> -            _d[4] = d5;                                         \
> -            _d[5] = d6;                                         \
> -            __trace_var(_e, 1, sizeof(_d), _d);                 \
> -        }                                                       \
> +/* Common helper for TRACE_{1..6}D() below. */
> +#define TRACE_varD(_e, ...)                             \
> +    do {                                                \
> +        if ( unlikely(tb_init_done) )                   \
> +        {                                               \
> +            uint32_t _d[] = { __VA_ARGS__ };            \

Just to check — this will clip any larger values to uint32_t?

If so:

Acked-by: George Dunlap <george.dunlap@citrix.com>
Andrew Cooper July 19, 2019, 9:52 a.m. UTC | #2
On 18/07/2019 21:59, George Dunlap wrote:
>> +/* Common helper for TRACE_{1..6}D() below. */
>> +#define TRACE_varD(_e, ...)                             \
>> +    do {                                                \
>> +        if ( unlikely(tb_init_done) )                   \
>> +        {                                               \
>> +            uint32_t _d[] = { __VA_ARGS__ };            \
> Just to check — this will clip any larger values to uint32_t?

Yes.  Each array element will be truncated based on its type.

>
> If so:
>
> Acked-by: George Dunlap <george.dunlap@citrix.com>

Thanks,

~Andrew

Patch
diff mbox series

diff --git a/xen/include/xen/trace.h b/xen/include/xen/trace.h
index e6a4ef93cc..7f5a904103 100644
--- a/xen/include/xen/trace.h
+++ b/xen/include/xen/trace.h
@@ -81,80 +81,33 @@  static inline void __trace_hypercall(uint32_t event, unsigned long op,
     do {                                        \
         trace_var(_e, 1, 0, NULL);              \
     } while ( 0 )
-  
-#define TRACE_1D(_e,d1)                                         \
-    do {                                                        \
-        if ( unlikely(tb_init_done) )                           \
-        {                                                       \
-            u32 _d[1];                                          \
-            _d[0] = d1;                                         \
-            __trace_var(_e, 1, sizeof(_d), _d);                 \
-        }                                                       \
-    } while ( 0 )
- 
-#define TRACE_2D(_e,d1,d2)                                      \
-    do {                                                        \
-        if ( unlikely(tb_init_done) )                           \
-        {                                                       \
-            u32 _d[2];                                          \
-            _d[0] = d1;                                         \
-            _d[1] = d2;                                         \
-            __trace_var(_e, 1, sizeof(_d), _d);                 \
-        }                                                       \
-    } while ( 0 )
- 
-#define TRACE_3D(_e,d1,d2,d3)                                   \
-    do {                                                        \
-        if ( unlikely(tb_init_done) )                           \
-        {                                                       \
-            u32 _d[3];                                          \
-            _d[0] = d1;                                         \
-            _d[1] = d2;                                         \
-            _d[2] = d3;                                         \
-            __trace_var(_e, 1, sizeof(_d), _d);                 \
-        }                                                       \
-    } while ( 0 )
- 
-#define TRACE_4D(_e,d1,d2,d3,d4)                                \
-    do {                                                        \
-        if ( unlikely(tb_init_done) )                           \
-        {                                                       \
-            u32 _d[4];                                          \
-            _d[0] = d1;                                         \
-            _d[1] = d2;                                         \
-            _d[2] = d3;                                         \
-            _d[3] = d4;                                         \
-            __trace_var(_e, 1, sizeof(_d), _d);                 \
-        }                                                       \
-    } while ( 0 )
- 
-#define TRACE_5D(_e,d1,d2,d3,d4,d5)                             \
-    do {                                                        \
-        if ( unlikely(tb_init_done) )                           \
-        {                                                       \
-            u32 _d[5];                                          \
-            _d[0] = d1;                                         \
-            _d[1] = d2;                                         \
-            _d[2] = d3;                                         \
-            _d[3] = d4;                                         \
-            _d[4] = d5;                                         \
-            __trace_var(_e, 1, sizeof(_d), _d);                 \
-        }                                                       \
-    } while ( 0 )
 
-#define TRACE_6D(_e,d1,d2,d3,d4,d5,d6)                             \
-    do {                                                        \
-        if ( unlikely(tb_init_done) )                           \
-        {                                                       \
-            u32 _d[6];                                          \
-            _d[0] = d1;                                         \
-            _d[1] = d2;                                         \
-            _d[2] = d3;                                         \
-            _d[3] = d4;                                         \
-            _d[4] = d5;                                         \
-            _d[5] = d6;                                         \
-            __trace_var(_e, 1, sizeof(_d), _d);                 \
-        }                                                       \
+/* Common helper for TRACE_{1..6}D() below. */
+#define TRACE_varD(_e, ...)                             \
+    do {                                                \
+        if ( unlikely(tb_init_done) )                   \
+        {                                               \
+            uint32_t _d[] = { __VA_ARGS__ };            \
+            __trace_var(_e, true, sizeof(_d), _d);      \
+        }                                               \
     } while ( 0 )
 
+#define TRACE_1D(_e, d1) \
+    TRACE_varD(_e, d1)
+
+#define TRACE_2D(_e, d1, d2) \
+    TRACE_varD(_e, d1, d2)
+
+#define TRACE_3D(_e, d1, d2, d3) \
+    TRACE_varD(_e, d1, d2, d3)
+
+#define TRACE_4D(_e, d1, d2, d3, d4) \
+    TRACE_varD(_e, d1, d2, d3, d4)
+
+#define TRACE_5D(_e, d1, d2, d3, d4, d5) \
+    TRACE_varD(_e, d1, d2, d3, d4, d5)
+
+#define TRACE_6D(_e, d1, d2, d3, d4, d5, d6) \
+    TRACE_varD(_e, d1, d2, d3, d4, d5, d6)
+
 #endif /* __XEN_TRACE_H__ */