qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <rth@twiddle.net>
Subject: [Qemu-devel] [PATCH v2 2/9] target-i386: Re-introduce optimal breakpoint removal
Date: Fri, 16 Oct 2015 13:23:32 -0300	[thread overview]
Message-ID: <1445012619-23772-3-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1445012619-23772-1-git-send-email-ehabkost@redhat.com>

From: Richard Henderson <rth@twiddle.net>

Before the last patch, we had an efficient loop that disabled
local breakpoints on task switch.  Re-add that, but in a more
general way that handles changes to the global enable bits too.

Signed-off-by: Richard Henderson <rth@twiddle.net>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v1 -> v2:
* Included fix from Paolo to make sure dr7 is updated after
  hw_breakpoint_remove() call and before hw_breakpoint_insert()
  call
---
 target-i386/bpt_helper.c | 34 ++++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)

diff --git a/target-i386/bpt_helper.c b/target-i386/bpt_helper.c
index f14788a..23ce828 100644
--- a/target-i386/bpt_helper.c
+++ b/target-i386/bpt_helper.c
@@ -82,14 +82,36 @@ static void hw_breakpoint_remove(CPUX86State *env, int index)
 
 void cpu_x86_update_dr7(CPUX86State *env, uint32_t new_dr7)
 {
+    target_ulong old_dr7 = env->dr[7];
     int i;
 
-    for (i = 0; i < DR7_MAX_BP; i++) {
-        hw_breakpoint_remove(env, i);
-    }
-    env->dr[7] = new_dr7;
-    for (i = 0; i < DR7_MAX_BP; i++) {
-        hw_breakpoint_insert(env, i);
+    /* If nothing is changing except the global/local enable bits,
+       then we can make the change more efficient.  */
+    if (((old_dr7 ^ new_dr7) & ~0xff) == 0) {
+        /* Fold the global and local enable bits together into the
+           global fields, then xor to show which registers have
+           changed collective enable state.  */
+        int mod = ((old_dr7 | old_dr7 * 2) ^ (new_dr7 | new_dr7 * 2)) & 0xff;
+
+        for (i = 0; i < DR7_MAX_BP; i++) {
+            if ((mod & (2 << i * 2)) && !hw_breakpoint_enabled(new_dr7, i)) {
+                hw_breakpoint_remove(env, i);
+            }
+        }
+        env->dr[7] = new_dr7;
+        for (i = 0; i < DR7_MAX_BP; i++) {
+            if (mod & (2 << i * 2) && hw_breakpoint_enabled(new_dr7, i)) {
+                hw_breakpoint_insert(env, i);
+            }
+        }
+    } else {
+        for (i = 0; i < DR7_MAX_BP; i++) {
+            hw_breakpoint_remove(env, i);
+        }
+        env->dr[7] = new_dr7;
+        for (i = 0; i < DR7_MAX_BP; i++) {
+            hw_breakpoint_insert(env, i);
+        }
     }
 }
 #endif
-- 
2.1.0

  parent reply	other threads:[~2015-10-16 16:23 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-16 16:23 [Qemu-devel] [PATCH v2 0/9] target-i386: Implement debug extensions Eduardo Habkost
2015-10-16 16:23 ` [Qemu-devel] [PATCH v2 1/9] target-i386: Introduce cpu_x86_update_dr7 Eduardo Habkost
2015-10-16 16:23 ` Eduardo Habkost [this message]
2015-10-16 16:23 ` [Qemu-devel] [PATCH v2 3/9] target-i386: Ensure bit 10 on DR7 is never cleared Eduardo Habkost
2015-10-18 22:58   ` Richard Henderson
2015-10-16 16:23 ` [Qemu-devel] [PATCH v2 4/9] target-i386: Move hw_*breakpoint_* functions Eduardo Habkost
2015-10-16 16:23 ` [Qemu-devel] [PATCH v2 5/9] target-i386: Optimize setting dr[0-3] Eduardo Habkost
2015-10-16 16:23 ` [Qemu-devel] [PATCH v2 6/9] target-i386: Handle I/O breakpoints Eduardo Habkost
2015-10-19 17:30   ` Eduardo Habkost
2015-10-19 17:46     ` Richard Henderson
2015-10-19 17:57       ` Eduardo Habkost
2015-10-20 12:04         ` Paolo Bonzini
2015-10-16 16:23 ` [Qemu-devel] [PATCH v2 7/9] target-i386: Check CR4[DE] for processing DR4/DR5 Eduardo Habkost
2015-10-16 16:23 ` [Qemu-devel] [PATCH v2 8/9] target-i386: Ensure always-1 bits on DR6 can't be cleared Eduardo Habkost
2015-10-18 23:05   ` Richard Henderson
2015-10-16 16:23 ` [Qemu-devel] [PATCH v2 9/9] target-i386: Add DE to TCG_FEATURES Eduardo Habkost
2015-10-18 23:06   ` Richard Henderson

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=1445012619-23772-3-git-send-email-ehabkost@redhat.com \
    --to=ehabkost@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).