Skip to contentSkip to conversation

char: Send out OPENED events only on char dev open; not on qemu initial reset

Qemu-devel Superseded Amit Shah 1 participant 5 messages Oct 7, 2009

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Amit Shah

author
#0 lore raw

Hello,

These patches rename the CHR_EVENT_RESET event to CHR_EVENT_OPENED, which is what it really is.

The check for initial_reset_issued was not really necessary, so that has been done away with.

Finally, this event is now only sent when a char dev is opened instead of the current behaviour of also sending it when qemu does its early init of char state. The consumers of the event shouldn't be interested in this anyway.

I've tested this with the monitor.

author
#1 lore raw

PATCH 1/3 char: check for initial_reset_issued unnecessary

At init, qemu_chr_reset is always called with initial_reset_issued set to 1. So checking for it to be set is not necessary.

A later patch will make use of initial_reset_issued to send the reset event only if the char device is opened instead of each time when qemu resets it

---
 qemu-char.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
qemu-char.c +2 -3
index 8084a67..99ab471 100644
@@ -127,7 +127,7 @@ static void qemu_chr_reset_bh(void *opaque)
 
 void qemu_chr_reset(CharDriverState *s)
 {
-    if (s->bh == NULL && initial_reset_issued) {
+    if (s->bh == NULL) {
 	s->bh = qemu_bh_new(qemu_chr_reset_bh, s);
 	qemu_bh_schedule(s->bh);
     }
@@ -137,11 +137,10 @@ void qemu_chr_initial_reset(void)
 {
     CharDriverState *chr;
 
-    initial_reset_issued = 1;
-
     QTAILQ_FOREACH(chr, &chardevs, next) {
         qemu_chr_reset(chr);
     }
+    initial_reset_issued = 1;
 }
 
 int qemu_chr_write(CharDriverState *s, const uint8_t *buf, int len)
Signature · 1 line
1.6.2.5
author
#2 lore raw

PATCH 2/3 char: rename CHR_EVENT_RESET to CHR_EVENT_OPENED

The char event RESET is emitted when a char device is opened. Give it a better name.

---
 gdbstub.c       |    2 +-
 hw/baum.c       |    2 +-
 hw/usb-serial.c |    2 +-
 monitor.c       |    2 +-
 qemu-char.c     |    2 +-
 qemu-char.h     |    2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)
gdbstub.c +1 -1
index 315f606..055093f 100644
@@ -2447,7 +2447,7 @@ static void gdb_chr_receive(void *opaque, const uint8_t *buf, int size)
 static void gdb_chr_event(void *opaque, int event)
 {
     switch (event) {
-    case CHR_EVENT_RESET:
+    case CHR_EVENT_OPENED:
         vm_stop(EXCP_INTERRUPT);
         gdb_has_xml = 0;
         break;
hw/baum.c +1 -1
index 665deab..c66e737 100644
@@ -475,7 +475,7 @@ static void baum_send_event(CharDriverState *chr, int event)
     switch (event) {
     case CHR_EVENT_BREAK:
         break;
-    case CHR_EVENT_RESET:
+    case CHR_EVENT_OPENED:
         /* Reset state */
         baum->in_buf_used = 0;
         break;
hw/usb-serial.c +1 -1
index e2379c4..d02f6b2 100644
@@ -516,7 +516,7 @@ static void usb_serial_event(void *opaque, int event)
             break;
         case CHR_EVENT_FOCUS:
             break;
-        case CHR_EVENT_RESET:
+        case CHR_EVENT_OPENED:
             usb_serial_reset(s);
             /* TODO: Reset USB port */
             break;
monitor.c +1 -1
index f105a2e..692b696 100644
@@ -3139,7 +3139,7 @@ static void monitor_event(void *opaque, int event)
         mon->mux_out = 1;
         break;
 
-    case CHR_EVENT_RESET:
+    case CHR_EVENT_OPENED:
         monitor_printf(mon, "QEMU %s monitor - type 'help' for more "
                        "information\n", QEMU_VERSION);
         if (!mon->mux_out) {
qemu-char.c +1 -1
index 99ab471..8fde8cf 100644
@@ -120,7 +120,7 @@ static void qemu_chr_event(CharDriverState *s, int event)
 static void qemu_chr_reset_bh(void *opaque)
 {
     CharDriverState *s = opaque;
-    qemu_chr_event(s, CHR_EVENT_RESET);
+    qemu_chr_event(s, CHR_EVENT_OPENED);
     qemu_bh_delete(s->bh);
     s->bh = NULL;
 }
qemu-char.h +1 -1
index c0654bc..05fe15d 100644
@@ -10,7 +10,7 @@
 
 #define CHR_EVENT_BREAK   0 /* serial break char */
 #define CHR_EVENT_FOCUS   1 /* focus to this terminal (modal input needed) */
-#define CHR_EVENT_RESET   2 /* new connection established */
+#define CHR_EVENT_OPENED  2 /* new connection established */
 #define CHR_EVENT_MUX_IN  3 /* mux-focus was set to this terminal */
 #define CHR_EVENT_MUX_OUT 4 /* mux-focus will move on */
 #define CHR_EVENT_CLOSED  5 /* connection closed */
Signature · 1 line
1.6.2.5
author
#3 lore raw

PATCH 3/3 char: emit the OPENED event only when a new char connection is opened

The OPENED event gets sent also when qemu resets its state initially. The consumers of the event aren't interested in receiving this event on reset.

---
 qemu-char.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
qemu-char.c +4 -1
index 8fde8cf..02c096c 100644
@@ -120,7 +120,10 @@ static void qemu_chr_event(CharDriverState *s, int event)
 static void qemu_chr_reset_bh(void *opaque)
 {
     CharDriverState *s = opaque;
-    qemu_chr_event(s, CHR_EVENT_OPENED);
+
+    if (initial_reset_issued) {
+        qemu_chr_event(s, CHR_EVENT_OPENED);
+    }
     qemu_bh_delete(s->bh);
     s->bh = NULL;
 }
Signature · 1 line
1.6.2.5
author
#4 lore raw

[Qemu-devel] Re: [PATCH 1/3] char: check for initial_reset_issued unnecessary

In reply to Amit Shah
Quoted 25 lines · Amit Shah

At init, qemu_chr_reset is always called with initial_reset_issued set to 1. So checking for it to be set is not necessary.

A later patch will make use of initial_reset_issued to send the reset event only if the char device is opened instead of each time when qemu resets it

---
 qemu-char.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
qemu-char.c +1 -1
index 8084a67..99ab471 100644
@@ -127,7 +127,7 @@ static void qemu_chr_reset_bh(void *opaque)
 
 void qemu_chr_reset(CharDriverState *s)
 {
-    if (s->bh == NULL && initial_reset_issued) {
+    if (s->bh == NULL) {
 	s->bh = qemu_bh_new(qemu_chr_reset_bh, s);
 	qemu_bh_schedule(s->bh);
     }

qemu-char.c void qemu_chr_initial_reset(void) · line 144

Quoted 10 lines
qemu-char.c +1 -2
@@ -137,11 +137,10 @@ void qemu_chr_initial_reset(void)
 {
     CharDriverState *chr;
 
-    initial_reset_issued = 1;
-
     QTAILQ_FOREACH(chr, &chardevs, next) {
         qemu_chr_reset(chr);
     }
+    initial_reset_issued = 1;
 }

Actually this won't work since the actual reset is done in a bh_schedule.

I'll have to find out another way of doing this.

Amit