Skip to contentSkip to conversation

xen/vsprintf: Introduce %pd formatter for domains

PATCH In review Andrew Cooper 2 participants 8 messages Sep 28, 2018 – Oct 1, 2018

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 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.

---
CC: George Dunlap <[email protected]>
CC: Jan Beulich <[email protected]>
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Tim Deegan <[email protected]>
CC: Wei Liu <[email protected]>
CC: Julien Grall <[email protected]>

v2:
* Render system names in square brackets.
* Drop DOMID_{SELF,INVALID} names because there are no struct domain *'s for them.
* Cope with NULL pointers.
* Fix a length-counting bug.

---
 docs/misc/printk-formats.txt | 14 ++++++++--
 xen/common/vsprintf.c        | 61 +++++++++++++++++++++++++++++++++-----------
 2 files changed, 58 insertions(+), 17 deletions(-)
docs/misc/printk-formats.txt +12 -2
index 525108f..b5570bc 100644
@@ -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
xen/common/vsprintf.c +46 -15

80 lines not on this page · raw message

Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v2 1/1
#1 lore raw
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 28.09.18 at 19:22, <[email protected]> wrote:
xen/common/vsprintf.c +8 -0
@@ -264,6 +264,47 @@ 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);

xen/common/vsprintf.c static char *string(char *str, char *end, const char *s, · line 284

Quoted 10 lines
xen/common/vsprintf.c +10 -0
+
+    if ( str < end )
+        *str = 'd';
+
+    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;
    default: ASSERT_UNREACHABLE();

?

xen/common/vsprintf.c static char *string(char *str, char *end, const char *s, · line 285

Quoted 1 line
xen/common/vsprintf.c +1 -0
+    }

Perhaps the insertion of 'd' might better live here, to make a better connection between the lack of a ++ there and the + 1 below?

xen/common/vsprintf.c static char *string(char *str, char *end, const char *s, · line 291

Quoted 5 lines
xen/common/vsprintf.c +5 -0
+    if ( name )
+        return string(str + 1, end, name, -1, -1, 0);
+    else
+        return number(str + 1, end, d->domain_id, 10, -1, -1, 0);
+}

Anyway, even without the adjustments

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#2 lore raw
Quoted 27 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 28.09.18 at 19:22, <[email protected]> wrote:
xen/common/vsprintf.c +8 -0
@@ -264,6 +264,47 @@ 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);

xen/common/vsprintf.c static char *string(char *str, char *end, const char *s, · line 284

Quoted 10 lines
xen/common/vsprintf.c +10 -0
+
+    if ( str < end )
+        *str = 'd';
+
+    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;
    default: ASSERT_UNREACHABLE();
Quoted 1 line

?

No - specifically not in this case.

This path is used when printing crash information, and falling back to a number is better behaviour than falling into an infinite loop, overflowing the primary stack, then taking a #DF (which escalates to triple fault on AMD), without printing anything useful.

In general, we cannot have BUG/WARN/ASSERTs in the middle vsprintf() path.

Quoted 5 lines

xen/common/vsprintf.c static char *string(char *str, char *end, const char *s, · line 285

Quoted 2 lines
xen/common/vsprintf.c +1 -0
+    }

Perhaps the insertion of 'd' might better live here, to make a better connection between the lack of a ++ there and the + 1 below?

Will move.

Quoted 8 lines

xen/common/vsprintf.c static char *string(char *str, char *end, const char *s, · line 291

Quoted 6 lines
xen/common/vsprintf.c +5 -0
+    if ( name )
+        return string(str + 1, end, name, -1, -1, 0);
+    else
+        return number(str + 1, end, d->domain_id, 10, -1, -1, 0);
+}

Anyway, even without the adjustments

Thanks,

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw
Quoted 22 lines
Quoted 1 line
Quoted 1 line · On 01.10.18 at 12:02, <[email protected]> wrote:
Quoted 20 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 28.09.18 at 19:22, <[email protected]> wrote:
xen/common/vsprintf.c +7 -0
+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);

xen/common/vsprintf.c static char *string(char *str, char *end, const char *s, · line 284

Quoted 10 lines
xen/common/vsprintf.c +10 -0
+
+    if ( str < end )
+        *str = 'd';
+
+    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;
    default: ASSERT_UNREACHABLE();
Quoted 8 lines
Quoted 1 line

?

No - specifically not in this case.

This path is used when printing crash information, and falling back to a number is better behaviour than falling into an infinite loop, overflowing the primary stack, then taking a #DF (which escalates to triple fault on AMD), without printing anything useful.

Ah, good point. Perhaps worth a brief comment instead of a "default:" then?

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw
Quoted 23 lines · Jan Beulich
Quoted 23 lines
Quoted 1 line
Quoted 1 line · On 01.10.18 at 12:02, <[email protected]> wrote:
Quoted 21 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 28.09.18 at 19:22, <[email protected]> wrote:
(quoted diff) +7 -0
+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);

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+    if ( str < end )
+        *str = 'd';
+
+    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;
    default: ASSERT_UNREACHABLE();

?

Quoted 8 lines
Quoted 6 lines

No - specifically not in this case.

This path is used when printing crash information, and falling back to a number is better behaviour than falling into an infinite loop, overflowing the primary stack, then taking a #DF (which escalates to triple fault on AMD), without printing anything useful.

Ah, good point. Perhaps worth a brief comment instead of a "default:" then?

This incremental diff?

xen/common/vsprintf.c +0 -0
index cd2d7d9..b0ff00c 100644
@@ -279,6 +279,11 @@ static char *print_domain(char *str, char *end,

const struct domain *d)
     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 )

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 01.10.18 at 12:23, <[email protected]> wrote:
Quoted 25 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 01.10.18 at 12:02, <[email protected]> wrote:
Quoted 20 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 28.09.18 at 19:22, <[email protected]> wrote:
(quoted diff) +7 -0
+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);

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+    if ( str < end )
+        *str = 'd';
+
+    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;
    default: ASSERT_UNREACHABLE();
Quoted 1 line

?

No - specifically not in this case.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

This path is used when printing crash information, and falling back to a number is better behaviour than falling into an infinite loop, overflowing the primary stack, then taking a #DF (which escalates to triple fault on AMD), without printing anything useful.

Ah, good point. Perhaps worth a brief comment instead of a "default:" then?

This incremental diff?

LGTM, thanks.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw
Quoted 27 lines · Jan Beulich
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 01.10.18 at 12:23, <[email protected]> wrote:
Quoted 25 lines · Jan Beulich
Quoted 25 lines
Quoted 1 line
Quoted 1 line · On 01.10.18 at 12:02, <[email protected]> wrote:
Quoted 20 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 28.09.18 at 19:22, <[email protected]> wrote:
(quoted diff) +7 -0
+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);

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+    if ( str < end )
+        *str = 'd';
+
+    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;
    default: ASSERT_UNREACHABLE();
Quoted 1 line

?

No - specifically not in this case.

Quoted 8 lines
Quoted 7 lines
Quoted 6 lines
Quoted 4 lines

This path is used when printing crash information, and falling back to a number is better behaviour than falling into an infinite loop, overflowing the primary stack, then taking a #DF (which escalates to triple fault on AMD), without printing anything useful.

Ah, good point. Perhaps worth a brief comment instead of a "default:" then?

This incremental diff?

LGTM, thanks.

I've committed this now, but its just occurred to me that we couldn't possibly have had a default case, because that is the common case for most domains.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw
Quoted 33 lines
Quoted 1 line
Quoted 1 line · On 01.10.18 at 15:55, <[email protected]> wrote:
Quoted 31 lines · Jan Beulich
Quoted 31 lines
Quoted 1 line
Quoted 1 line · On 01.10.18 at 12:23, <[email protected]> wrote:
Quoted 29 lines · Jan Beulich
Quoted 29 lines
Quoted 1 line
Quoted 1 line · On 01.10.18 at 12:02, <[email protected]> wrote:
Quoted 20 lines · Jan Beulich
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 28.09.18 at 19:22, <[email protected]> wrote:
(quoted diff) +7 -0
+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);

Review

Quoted 10 lines
(quoted diff) +10 -0
+
+    if ( str < end )
+        *str = 'd';
+
+    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;
    default: ASSERT_UNREACHABLE();
Quoted 1 line

?

No - specifically not in this case.

This path is used when printing crash information, and falling back to a number is better behaviour than falling into an infinite loop, overflowing the primary stack, then taking a #DF (which escalates to triple fault on AMD), without printing anything useful.

Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Quoted 2 lines

Ah, good point. Perhaps worth a brief comment instead of a "default:" then?

This incremental diff?

LGTM, thanks.

I've committed this now, but its just occurred to me that we couldn't possibly have had a default case, because that is the common case for most domains.

Oh, indeed, but still, while the "unreachable" part of my suggestion was indeed wrong, but it still could have been ASSERT(d->domain_id < DOMID_FIRST_RESERVED). But I agree this wouldn't have been overly helpful.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel