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

[Xen-changelog] [xen staging] xen/vsprintf: Introduce %pd formatter for domains



commit 5c28a3c6814cc3a054fde133c0f6ef77d80c0412
Author:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
AuthorDate: Wed Aug 29 16:16:50 2018 +0000
Commit:     Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
CommitDate: Mon Oct 1 12:37:45 2018 +0100

    xen/vsprintf: Introduce %pd formatter for domains
    
    This allows all system domids to be printed by name, rather than special
    casing the idle vcpus alone.
    
    Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
    Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
---
 docs/misc/printk-formats.txt | 14 ++++++++--
 xen/common/vsprintf.c        | 66 ++++++++++++++++++++++++++++++++++----------
 2 files changed, 63 insertions(+), 17 deletions(-)

diff --git a/docs/misc/printk-formats.txt b/docs/misc/printk-formats.txt
index 525108f86c..b5570bc1f1 100644
--- a/docs/misc/printk-formats.txt
+++ b/docs/misc/printk-formats.txt
@@ -28,5 +28,15 @@ Symbol/Function pointers:
 
 Domain and vCPU information:
 
-       %pv     Domain and vCPU ID from a 'struct vcpu *' (printed as
-               "d<domid>v<vcpuid>")
+       %pd     Domain from a 'struct domain *'
+
+               Regular domains are printed with their ID in decimal.  System
+               domains are printed with their name.
+                 e.g.  d0
+                       d[IDLE]
+
+       %pv     Domain and vCPU ID from a 'struct vcpu *'
+
+               The domain part as above, with the vcpu_id printed in decimal.
+                 e.g.  d0v1
+                       d[IDLE]v0
diff --git a/xen/common/vsprintf.c b/xen/common/vsprintf.c
index f92fb675e6..b0ff00c883 100644
--- a/xen/common/vsprintf.c
+++ b/xen/common/vsprintf.c
@@ -264,6 +264,52 @@ static char *string(char *str, char *end, const char *s,
     return str;
 }
 
+/* Print a domain id, using names for system domains.  (e.g. d0 or d[IDLE]) */
+static char *print_domain(char *str, char *end, const struct domain *d)
+{
+    const char *name = NULL;
+
+    /* Some debugging may have an optionally-NULL pointer. */
+    if ( unlikely(!d) )
+        return string(str, end, "NULL", -1, -1, 0);
+
+    switch ( d->domain_id )
+    {
+    case DOMID_IO:   name = "[IO]";   break;
+    case DOMID_XEN:  name = "[XEN]";  break;
+    case DOMID_COW:  name = "[COW]";  break;
+    case DOMID_IDLE: name = "[IDLE]"; break;
+        /*
+         * In principle, we could ASSERT_UNREACHABLE() in the default case.
+         * However, this path is used to print out crash information, which
+         * risks recursing infinitely and not printing any useful information.
+         */
+    }
+
+    if ( str < end )
+        *str = 'd';
+
+    if ( name )
+        return string(str + 1, end, name, -1, -1, 0);
+    else
+        return number(str + 1, end, d->domain_id, 10, -1, -1, 0);
+}
+
+/* Print a vcpu id.  (e.g. d0v1 or d[IDLE]v0) */
+static char *print_vcpu(char *str, char *end, const struct vcpu *v)
+{
+    /* Some debugging may have an optionally-NULL pointer. */
+    if ( unlikely(!v) )
+        return string(str, end, "NULL", -1, -1, 0);
+
+    str = print_domain(str, end, v->domain);
+
+    if ( str < end )
+        *str = 'v';
+
+    return number(str + 1, end, v->vcpu_id, 10, -1, -1, 0);
+}
+
 static char *pointer(char *str, char *end, const char **fmt_ptr,
                      const void *arg, int field_width, int precision,
                      int flags)
@@ -273,6 +319,10 @@ static char *pointer(char *str, char *end, const char 
**fmt_ptr,
     /* Custom %p suffixes. See XEN_ROOT/docs/misc/printk-formats.txt */
     switch ( fmt[1] )
     {
+    case 'd': /* Domain ID from a struct domain *. */
+        ++*fmt_ptr;
+        return print_domain(str, end, arg);
+
     case 'h': /* Raw buffer as hex string. */
     {
         const uint8_t *hex_buffer = arg;
@@ -370,22 +420,8 @@ static char *pointer(char *str, char *end, const char 
**fmt_ptr,
     }
 
     case 'v': /* d<domain-id>v<vcpu-id> from a struct vcpu */
-    {
-        const struct vcpu *v = arg;
-
         ++*fmt_ptr;
-        if ( unlikely(v->domain->domain_id == DOMID_IDLE) )
-            str = string(str, end, "IDLE", -1, -1, 0);
-        else
-        {
-            if ( str < end )
-                *str = 'd';
-            str = number(str + 1, end, v->domain->domain_id, 10, -1, -1, 0);
-        }
-        if ( str < end )
-            *str = 'v';
-        return number(str + 1, end, v->vcpu_id, 10, -1, -1, 0);
-    }
+        return print_vcpu(str, end, arg);
     }
 
     if ( field_width == -1 )
--
generated by git-patchbot for /home/xen/git/xen.git#staging

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/xen-changelog

 


Rackspace

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