Re: [Qemu-devel] fixing qemu busy wait

2013-04-18 Thread Orr Dvory
is this better?

diff -uprN qemu-1.4.1/gdbstub.c qemu-1.4.1-fix/gdbstub.c
--- qemu-1.4.1/gdbstub.c2013-04-15 23:25:18.0 +0300
+++ qemu-1.4.1-fix/gdbstub.c2013-04-18 21:35:00.0 +0300
@@ -379,17 +379,22 @@ static void put_buffer(GDBState *s, cons
 {
 #ifdef CONFIG_USER_ONLY
 int ret;
-
+int fd_flags = fcntl (s-fd, F_GETFL, 0);
+fcntl (s-fd, F_SETFL, fd_flags  ~O_NONBLOCK);
 while (len  0) {
 ret = send(s-fd, buf, len, 0);
 if (ret  0) {

 if (errno != EINTR  errno != EAGAIN)
+{
+fcntl (s-fd, F_SETFL, fd_flags);
 return;
+}
 } else {
 buf += ret;
 len -= ret;
 }
 }
+fcntl (s-fd, F_SETFL, fd_flags);
 #else
 qemu_chr_fe_write(s-chr, buf, len);
 #endif
@@ -2775,6 +2780,7 @@ gdb_handlesig (CPUArchState *env, int si
   GDBState *s;
   char buf[256];
   int n;
+  int fd_flags;

   s = gdbserver_state;
   if (gdbserver_fd  0 || s-fd  0)
@@ -2793,7 +2799,8 @@ gdb_handlesig (CPUArchState *env, int si
  connection.  */
   if (s-fd  0)
   return sig;
-
+  fd_flags = fcntl (s-fd, F_GETFL, 0);
+  fcntl (s-fd, F_SETFL, fd_flags  ~O_NONBLOCK);
   sig = 0;
   s-state = RS_IDLE;
   s-running_state = 0;
@@ -2810,9 +2817,11 @@ gdb_handlesig (CPUArchState *env, int si
 {
   /* XXX: Connection closed.  Should probably wait for another
  connection before continuing.  */
+  fcntl (s-fd, F_SETFL, fd_flags);
   return sig;
 }
   }
+  fcntl (s-fd, F_SETFL, fd_flags);
   sig = s-signal;
   s-signal = 0;
   return sig;


On Thu, Apr 18, 2013 at 9:46 PM, Orr Dvory gid...@gmail.com wrote:

 is this better?

 diff -uprN qemu-1.4.1/gdbstub.c qemu-1.4.1-fix/gdbstub.c
 --- qemu-1.4.1/gdbstub.c2013-04-15 23:25:18.0 +0300
 +++ qemu-1.4.1-fix/gdbstub.c2013-04-18 21:35:00.0 +0300
 @@ -379,17 +379,22 @@ static void put_buffer(GDBState *s, cons
  {
  #ifdef CONFIG_USER_ONLY
  int ret;
 -
 +int fd_flags = fcntl (s-fd, F_GETFL, 0);
 +fcntl (s-fd, F_SETFL, fd_flags  ~O_NONBLOCK);
  while (len  0) {
  ret = send(s-fd, buf, len, 0);
  if (ret  0) {

  if (errno != EINTR  errno != EAGAIN)
 +{
 +fcntl (s-fd, F_SETFL, fd_flags);
  return;
 +}
  } else {
  buf += ret;
  len -= ret;
  }
  }
 +fcntl (s-fd, F_SETFL, fd_flags);
  #else
  qemu_chr_fe_write(s-chr, buf, len);
  #endif
 @@ -2775,6 +2780,7 @@ gdb_handlesig (CPUArchState *env, int si
GDBState *s;
char buf[256];
int n;
 +  int fd_flags;

s = gdbserver_state;
if (gdbserver_fd  0 || s-fd  0)
 @@ -2793,7 +2799,8 @@ gdb_handlesig (CPUArchState *env, int si
   connection.  */
if (s-fd  0)
return sig;
 -
 +  fd_flags = fcntl (s-fd, F_GETFL, 0);
 +  fcntl (s-fd, F_SETFL, fd_flags  ~O_NONBLOCK);
sig = 0;
s-state = RS_IDLE;
s-running_state = 0;
 @@ -2810,9 +2817,11 @@ gdb_handlesig (CPUArchState *env, int si
  {
/* XXX: Connection closed.  Should probably wait for another
   connection before continuing.  */
 +  fcntl (s-fd, F_SETFL, fd_flags);
return sig;
  }
}
 +  fcntl (s-fd, F_SETFL, fd_flags);
sig = s-signal;
s-signal = 0;
return sig;


 On Wed, Feb 20, 2013 at 10:38 PM, Paolo Bonzini pbonz...@redhat.comwrote:

 Il 20/02/2013 20:39, Orr Dvory ha scritto:
   if (errno != EINTR  errno != EAGAIN)
  +/* there's no need to restore the
  +O_NONBLOCK option. */
   return;
  +

 But it's cleaner to do it anyway. :)

 Paolo





Re: [Qemu-devel] fixing qemu busy wait

2013-02-20 Thread Orr Dvory
the new patch is attached...


On Sun, Feb 17, 2013 at 6:32 PM, Orr Dvory gid...@gmail.com wrote:

 Yes it would :)
 Should I do that? or that you already fixed the issue?


 On Sun, Feb 17, 2013 at 12:06 AM, Richard Henderson r...@twiddle.netwrote:

 On 2013-02-15 03:12, Orr Dvory wrote:

 when debugging with qemu(user mode), qemu waits in infinite loop to read
 a signal from gdb (when it waits on breakpoint for example).
 I added sleeps to reduce the cpu usage from 100% to about ~0%.


 Wouldn't it be better to toggle the O_NONBLOCK state of the file
 descriptor across this loop?


 r~





qemu-busy-wait.patch
Description: Binary data


[Qemu-devel] fixing qemu busy wait

2013-02-15 Thread Orr Dvory
when debugging with qemu(user mode), qemu waits in infinite loop to read a
signal from gdb (when it waits on breakpoint for example).
I added sleeps to reduce the cpu usage from 100% to about ~0%.


qemu-busy-wait.patch
Description: Binary data