mirror of
https://github.com/qemu/qemu.git
synced 2024-11-25 03:43:37 +08:00
monitor: rename out_lock to mon_lock
The out_lock is protecting a few Monitor fields. In the future the monitor code will start to run in multiple threads. We are going to turn it into a bigger lock to protect not only the out buffer but also most of the rest. Since at it, rearrange the Monitor struct a bit. Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Peter Xu <peterx@redhat.com> Message-Id: <20180608035511.7439-2-peterx@redhat.com> Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
2ef2f16781
commit
dc7cbcd8fa
53
monitor.c
53
monitor.c
@ -206,15 +206,6 @@ struct Monitor {
|
|||||||
int suspend_cnt; /* Needs to be accessed atomically */
|
int suspend_cnt; /* Needs to be accessed atomically */
|
||||||
bool skip_flush;
|
bool skip_flush;
|
||||||
bool use_io_thr;
|
bool use_io_thr;
|
||||||
|
|
||||||
/* We can't access guest memory when holding the lock */
|
|
||||||
QemuMutex out_lock;
|
|
||||||
QString *outbuf;
|
|
||||||
guint out_watch;
|
|
||||||
|
|
||||||
/* Read under either BQL or out_lock, written with BQL+out_lock. */
|
|
||||||
int mux_out;
|
|
||||||
|
|
||||||
ReadLineState *rs;
|
ReadLineState *rs;
|
||||||
MonitorQMP qmp;
|
MonitorQMP qmp;
|
||||||
gchar *mon_cpu_path;
|
gchar *mon_cpu_path;
|
||||||
@ -223,6 +214,20 @@ struct Monitor {
|
|||||||
mon_cmd_t *cmd_table;
|
mon_cmd_t *cmd_table;
|
||||||
QLIST_HEAD(,mon_fd_t) fds;
|
QLIST_HEAD(,mon_fd_t) fds;
|
||||||
QTAILQ_ENTRY(Monitor) entry;
|
QTAILQ_ENTRY(Monitor) entry;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The per-monitor lock. We can't access guest memory when holding
|
||||||
|
* the lock.
|
||||||
|
*/
|
||||||
|
QemuMutex mon_lock;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Fields that are protected by the per-monitor lock.
|
||||||
|
*/
|
||||||
|
QString *outbuf;
|
||||||
|
guint out_watch;
|
||||||
|
/* Read under either BQL or mon_lock, written with BQL+mon_lock. */
|
||||||
|
int mux_out;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Let's add monitor global variables to this struct. */
|
/* Let's add monitor global variables to this struct. */
|
||||||
@ -365,14 +370,14 @@ static gboolean monitor_unblocked(GIOChannel *chan, GIOCondition cond,
|
|||||||
{
|
{
|
||||||
Monitor *mon = opaque;
|
Monitor *mon = opaque;
|
||||||
|
|
||||||
qemu_mutex_lock(&mon->out_lock);
|
qemu_mutex_lock(&mon->mon_lock);
|
||||||
mon->out_watch = 0;
|
mon->out_watch = 0;
|
||||||
monitor_flush_locked(mon);
|
monitor_flush_locked(mon);
|
||||||
qemu_mutex_unlock(&mon->out_lock);
|
qemu_mutex_unlock(&mon->mon_lock);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Called with mon->out_lock held. */
|
/* Called with mon->mon_lock held. */
|
||||||
static void monitor_flush_locked(Monitor *mon)
|
static void monitor_flush_locked(Monitor *mon)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
@ -410,9 +415,9 @@ static void monitor_flush_locked(Monitor *mon)
|
|||||||
|
|
||||||
void monitor_flush(Monitor *mon)
|
void monitor_flush(Monitor *mon)
|
||||||
{
|
{
|
||||||
qemu_mutex_lock(&mon->out_lock);
|
qemu_mutex_lock(&mon->mon_lock);
|
||||||
monitor_flush_locked(mon);
|
monitor_flush_locked(mon);
|
||||||
qemu_mutex_unlock(&mon->out_lock);
|
qemu_mutex_unlock(&mon->mon_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* flush at every end of line */
|
/* flush at every end of line */
|
||||||
@ -420,7 +425,7 @@ static void monitor_puts(Monitor *mon, const char *str)
|
|||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
|
|
||||||
qemu_mutex_lock(&mon->out_lock);
|
qemu_mutex_lock(&mon->mon_lock);
|
||||||
for(;;) {
|
for(;;) {
|
||||||
c = *str++;
|
c = *str++;
|
||||||
if (c == '\0')
|
if (c == '\0')
|
||||||
@ -433,7 +438,7 @@ static void monitor_puts(Monitor *mon, const char *str)
|
|||||||
monitor_flush_locked(mon);
|
monitor_flush_locked(mon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
qemu_mutex_unlock(&mon->out_lock);
|
qemu_mutex_unlock(&mon->mon_lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
|
void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap)
|
||||||
@ -724,7 +729,7 @@ static void monitor_data_init(Monitor *mon, bool skip_flush,
|
|||||||
bool use_io_thr)
|
bool use_io_thr)
|
||||||
{
|
{
|
||||||
memset(mon, 0, sizeof(Monitor));
|
memset(mon, 0, sizeof(Monitor));
|
||||||
qemu_mutex_init(&mon->out_lock);
|
qemu_mutex_init(&mon->mon_lock);
|
||||||
qemu_mutex_init(&mon->qmp.qmp_queue_lock);
|
qemu_mutex_init(&mon->qmp.qmp_queue_lock);
|
||||||
mon->outbuf = qstring_new();
|
mon->outbuf = qstring_new();
|
||||||
/* Use *mon_cmds by default. */
|
/* Use *mon_cmds by default. */
|
||||||
@ -744,7 +749,7 @@ static void monitor_data_destroy(Monitor *mon)
|
|||||||
}
|
}
|
||||||
readline_free(mon->rs);
|
readline_free(mon->rs);
|
||||||
qobject_unref(mon->outbuf);
|
qobject_unref(mon->outbuf);
|
||||||
qemu_mutex_destroy(&mon->out_lock);
|
qemu_mutex_destroy(&mon->mon_lock);
|
||||||
qemu_mutex_destroy(&mon->qmp.qmp_queue_lock);
|
qemu_mutex_destroy(&mon->qmp.qmp_queue_lock);
|
||||||
monitor_qmp_cleanup_req_queue_locked(mon);
|
monitor_qmp_cleanup_req_queue_locked(mon);
|
||||||
monitor_qmp_cleanup_resp_queue_locked(mon);
|
monitor_qmp_cleanup_resp_queue_locked(mon);
|
||||||
@ -776,13 +781,13 @@ char *qmp_human_monitor_command(const char *command_line, bool has_cpu_index,
|
|||||||
handle_hmp_command(&hmp, command_line);
|
handle_hmp_command(&hmp, command_line);
|
||||||
cur_mon = old_mon;
|
cur_mon = old_mon;
|
||||||
|
|
||||||
qemu_mutex_lock(&hmp.out_lock);
|
qemu_mutex_lock(&hmp.mon_lock);
|
||||||
if (qstring_get_length(hmp.outbuf) > 0) {
|
if (qstring_get_length(hmp.outbuf) > 0) {
|
||||||
output = g_strdup(qstring_get_str(hmp.outbuf));
|
output = g_strdup(qstring_get_str(hmp.outbuf));
|
||||||
} else {
|
} else {
|
||||||
output = g_strdup("");
|
output = g_strdup("");
|
||||||
}
|
}
|
||||||
qemu_mutex_unlock(&hmp.out_lock);
|
qemu_mutex_unlock(&hmp.mon_lock);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
monitor_data_destroy(&hmp);
|
monitor_data_destroy(&hmp);
|
||||||
@ -4381,9 +4386,9 @@ static void monitor_event(void *opaque, int event)
|
|||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case CHR_EVENT_MUX_IN:
|
case CHR_EVENT_MUX_IN:
|
||||||
qemu_mutex_lock(&mon->out_lock);
|
qemu_mutex_lock(&mon->mon_lock);
|
||||||
mon->mux_out = 0;
|
mon->mux_out = 0;
|
||||||
qemu_mutex_unlock(&mon->out_lock);
|
qemu_mutex_unlock(&mon->mon_lock);
|
||||||
if (mon->reset_seen) {
|
if (mon->reset_seen) {
|
||||||
readline_restart(mon->rs);
|
readline_restart(mon->rs);
|
||||||
monitor_resume(mon);
|
monitor_resume(mon);
|
||||||
@ -4403,9 +4408,9 @@ static void monitor_event(void *opaque, int event)
|
|||||||
} else {
|
} else {
|
||||||
atomic_inc(&mon->suspend_cnt);
|
atomic_inc(&mon->suspend_cnt);
|
||||||
}
|
}
|
||||||
qemu_mutex_lock(&mon->out_lock);
|
qemu_mutex_lock(&mon->mon_lock);
|
||||||
mon->mux_out = 1;
|
mon->mux_out = 1;
|
||||||
qemu_mutex_unlock(&mon->out_lock);
|
qemu_mutex_unlock(&mon->mon_lock);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CHR_EVENT_OPENED:
|
case CHR_EVENT_OPENED:
|
||||||
|
Loading…
Reference in New Issue
Block a user