All of lore.kernel.org
 help / color / mirror / Atom feed
From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: xen-devel@lists.xensource.com
Subject: [XEN-UNSTABLE] Provide a routine to print the active grant table entries.
Date: Mon, 14 Sep 2009 11:40:34 -0400	[thread overview]
Message-ID: <20090914154034.GA5284@phenom.dumpdata.com> (raw)

As part of hunting down a race-condition with SWIOTLB, I resurrected this
patch from Virtual Iron's patchset to help me along. It didn't help that much
(still working on the bug), but this might be useful for other situations

Here it is:

    Provided a routine to print the active grant table entries.
    This can be called by command 'g' from the xen console.
    Also, provided a command (invoked by 'G' from the xen console)
    to forcibly increment the pin count of some arbitrary
    grant table entry.  This can be used to test the
    printing feature.

Authored-By: Robert Phillips
Signed-off-By: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>

diff -r 8b0f1f37e145 xen/common/grant_table.c
--- a/xen/common/grant_table.c	Sun Aug 16 08:46:08 2009 +0100
+++ b/xen/common/grant_table.c	Mon Sep 14 11:33:32 2009 -0400
@@ -1857,6 +1857,119 @@
     d->grant_table = NULL;
 }
 
+#define GNTTAB_USAGE_PROFILE
+#ifdef  GNTTAB_USAGE_PROFILE
+
+#include <xen/keyhandler.h>
+
+void gnttab_usage_print(struct domain *rd)
+{
+    int first = 1;
+    grant_ref_t ref;
+    printk("      -------- active --------       -------- shared --------\n");
+    printk("[ref] localdom mfn      pin          localdom gmfn     flags\n");
+
+    spin_lock(&rd->grant_table->lock);
+    for (ref = 0; ref != nr_grant_entries(rd->grant_table); ref++) {
+        struct active_grant_entry *act;
+        struct grant_entry   *sha;
+        act = &active_entry(rd->grant_table, ref);
+        sha = &shared_entry(rd->grant_table, ref);
+        if (act->pin) {
+            if (first) {
+                printk("grant-table for remote domain:%5d\n", rd->domain_id);
+                first = 0;
+            }
+            //      [ddd]    ddddd 0xXXXXXX 0xXXXXXXXX      ddddd 0xXXXXXX 0xXX
+            printk("[%3d]    %5d 0x%06lx 0x%08x      %5d 0x%06x 0x%02x\n",
+                   ref, act->domid, act->frame, act->pin, sha->domid, sha->frame, sha->flags);
+        }
+    }
+    spin_unlock(&rd->grant_table->lock);
+    if (first)
+        printk("grant-table for remote domain:%5d ... no active grant table entries\n", rd->domain_id);
+}
+
+static void gnttab_usage_print_all(unsigned char key)
+{
+    struct domain *d;
+    printk("%s [ key '%c' pressed\n", __FUNCTION__, key);
+    for_each_domain(d) {
+        gnttab_usage_print(d);
+    }
+    printk("%s ] done\n", __FUNCTION__);
+}
+
+static int gnttab_incr_pin_one(struct domain *rd)
+{
+    int first = 1;
+    grant_ref_t ref;
+    printk("      -------- active --------       -------- shared --------\n");
+    printk("[ref] localdom mfn      pin          localdom gmfn     flags\n");
+
+    spin_lock(&rd->grant_table->lock);
+    for (ref = 0; ref != nr_grant_entries(rd->grant_table); ref++) {
+        struct active_grant_entry *act;
+        struct grant_entry   *sha;
+        act = &active_entry(rd->grant_table, ref);
+        sha = &shared_entry(rd->grant_table, ref);
+        if (act->pin) {
+            printk("grant-table for remote domain:%5d\n", rd->domain_id);
+            first = 0;
+            //      [ddd]    ddddd 0xXXXXXX 0xXXXXXXXX      ddddd 0xXXXXXX 0xXX
+            printk("[%3d]    %5d 0x%06lx 0x%08x      %5d 0x%06x 0x%02x <== BEFORE\n",
+                   ref, act->domid, act->frame, act->pin, sha->domid, sha->frame, sha->flags);
+            act->pin++;
+            get_page(mfn_to_page(act->frame), rd);
+            printk("[%3d]    %5d 0x%06lx 0x%08x      %5d 0x%06x 0x%02x <== AFTER\n",
+                   ref, act->domid, act->frame, act->pin, sha->domid, sha->frame, sha->flags);
+            break;
+        }
+    }
+    spin_unlock(&rd->grant_table->lock);
+    if (first) {
+        printk("grant-table for remote domain:%5d ... no active grant table entries\n", rd->domain_id);
+        return 0;
+    }
+    return 1;
+}
+
+static void gnttab_incr_pin(unsigned char key)
+{
+    struct domain *d;
+    printk("%s [ key '%c' pressed\n", __FUNCTION__, key);
+    for_each_domain(d) {
+        if (gnttab_incr_pin_one(d))
+            break;
+    }
+    printk("%s ] done\n", __FUNCTION__);
+}
+static struct keyhandler gnttab_usage_print_all_keyhandler = {
+    .diagnostic = 1,
+    .u.fn = gnttab_usage_print_all,
+    .desc = "print grant table usage"
+};
+
+
+static struct keyhandler gnttab_incr_pin_keyhandler = {
+    .diagnostic = 1,
+    .u.fn = gnttab_incr_pin,
+    .desc = "force +1 in grant table pin entry"
+};
+
+
+static int __init gnttab_usage_init(void)
+{
+    register_keyhandler('g', &gnttab_usage_print_all_keyhandler);
+    register_keyhandler('G', &gnttab_incr_pin_keyhandler);
+    return 0;
+}
+
+__initcall(gnttab_usage_init);
+
+#endif
+
+
 /*
  * Local variables:
  * mode: C

                 reply	other threads:[~2009-09-14 15:40 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20090914154034.GA5284@phenom.dumpdata.com \
    --to=konrad.wilk@oracle.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

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

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