From: Jonathan Austin <jonathan.austin@arm.com>
To: kvm@vger.kernel.org
Cc: penberg@kernel.org, marc.zyngier@arm.com, will.deacon@arm.com,
Matt.Evans@arm.com, Jonathan Austin <jonathan.austin@arm.com>
Subject: [PATCH v2 2/3] kvm tools: remove periodic tick in favour of a polling thread
Date: Wed, 4 Sep 2013 14:25:47 +0100 [thread overview]
Message-ID: <1378301148-18823-3-git-send-email-jonathan.austin@arm.com> (raw)
In-Reply-To: <1378301148-18823-1-git-send-email-jonathan.austin@arm.com>
Currently the only use of the periodic timer tick in kvmtool is to
handle reading from stdin. Though functional, this periodic tick can be
problematic on slow (eg FPGA) platforms and can cause low interactivity or
even stop the execution from progressing at all.
This patch removes the periodic tick in favour of a dedicated thread blocked
waiting for input from the console. In order to reflect the new behaviour,
the old 'kvm__arch_periodic_tick' function is renamed to 'kvm__arch_read_term'.
Signed-off-by: Jonathan Austin <jonathan.austin@arm.com>
Acked-by: Marc Zyngier <marc.zyngier@arm.com>
---
tools/kvm/arm/kvm.c | 2 +-
tools/kvm/builtin-run.c | 13 -----------
tools/kvm/include/kvm/kvm.h | 2 +-
tools/kvm/kvm.c | 50 -------------------------------------------
tools/kvm/powerpc/kvm.c | 2 +-
tools/kvm/term.c | 31 +++++++++++++++++++++++++++
tools/kvm/x86/kvm.c | 2 +-
7 files changed, 35 insertions(+), 67 deletions(-)
diff --git a/tools/kvm/arm/kvm.c b/tools/kvm/arm/kvm.c
index 27e6cf4..008b7fe 100644
--- a/tools/kvm/arm/kvm.c
+++ b/tools/kvm/arm/kvm.c
@@ -46,7 +46,7 @@ void kvm__arch_delete_ram(struct kvm *kvm)
munmap(kvm->arch.ram_alloc_start, kvm->arch.ram_alloc_size);
}
-void kvm__arch_periodic_poll(struct kvm *kvm)
+void kvm__arch_read_term(struct kvm *kvm)
{
if (term_readable(0)) {
serial8250__update_consoles(kvm);
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 4d7fbf9d..da95d71 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -165,13 +165,6 @@ void kvm_run_set_wrapper_sandbox(void)
OPT_END() \
};
-static void handle_sigalrm(int sig, siginfo_t *si, void *uc)
-{
- struct kvm *kvm = si->si_value.sival_ptr;
-
- kvm__arch_periodic_poll(kvm);
-}
-
static void *kvm_cpu_thread(void *arg)
{
char name[16];
@@ -487,17 +480,11 @@ static struct kvm *kvm_cmd_run_init(int argc, const char **argv)
{
static char real_cmdline[2048], default_name[20];
unsigned int nr_online_cpus;
- struct sigaction sa;
struct kvm *kvm = kvm__new();
if (IS_ERR(kvm))
return kvm;
- sa.sa_flags = SA_SIGINFO;
- sa.sa_sigaction = handle_sigalrm;
- sigemptyset(&sa.sa_mask);
- sigaction(SIGALRM, &sa, NULL);
-
nr_online_cpus = sysconf(_SC_NPROCESSORS_ONLN);
kvm->cfg.custom_rootfs_name = "default";
diff --git a/tools/kvm/include/kvm/kvm.h b/tools/kvm/include/kvm/kvm.h
index ad53ca7..d05b936 100644
--- a/tools/kvm/include/kvm/kvm.h
+++ b/tools/kvm/include/kvm/kvm.h
@@ -103,7 +103,7 @@ void kvm__arch_delete_ram(struct kvm *kvm);
int kvm__arch_setup_firmware(struct kvm *kvm);
int kvm__arch_free_firmware(struct kvm *kvm);
bool kvm__arch_cpu_supports_vm(void);
-void kvm__arch_periodic_poll(struct kvm *kvm);
+void kvm__arch_read_term(struct kvm *kvm);
void *guest_flat_to_host(struct kvm *kvm, u64 offset);
u64 host_to_guest_flat(struct kvm *kvm, void *ptr);
diff --git a/tools/kvm/kvm.c b/tools/kvm/kvm.c
index cfd30dd..d7d2e84 100644
--- a/tools/kvm/kvm.c
+++ b/tools/kvm/kvm.c
@@ -393,56 +393,6 @@ found_kernel:
return ret;
}
-#define TIMER_INTERVAL_NS 1000000 /* 1 msec */
-
-/*
- * This function sets up a timer that's used to inject interrupts from the
- * userspace hypervisor into the guest at periodical intervals. Please note
- * that clock interrupt, for example, is not handled here.
- */
-int kvm_timer__init(struct kvm *kvm)
-{
- struct itimerspec its;
- struct sigevent sev;
- int r;
-
- memset(&sev, 0, sizeof(struct sigevent));
- sev.sigev_value.sival_int = 0;
- sev.sigev_notify = SIGEV_THREAD_ID;
- sev.sigev_signo = SIGALRM;
- sev.sigev_value.sival_ptr = kvm;
- sev._sigev_un._tid = syscall(__NR_gettid);
-
- r = timer_create(CLOCK_REALTIME, &sev, &kvm->timerid);
- if (r < 0)
- return r;
-
- its.it_value.tv_sec = TIMER_INTERVAL_NS / 1000000000;
- its.it_value.tv_nsec = TIMER_INTERVAL_NS % 1000000000;
- its.it_interval.tv_sec = its.it_value.tv_sec;
- its.it_interval.tv_nsec = its.it_value.tv_nsec;
-
- r = timer_settime(kvm->timerid, 0, &its, NULL);
- if (r < 0) {
- timer_delete(kvm->timerid);
- return r;
- }
-
- return 0;
-}
-firmware_init(kvm_timer__init);
-
-int kvm_timer__exit(struct kvm *kvm)
-{
- if (kvm->timerid)
- if (timer_delete(kvm->timerid) < 0)
- die("timer_delete()");
-
- kvm->timerid = 0;
-
- return 0;
-}
-firmware_exit(kvm_timer__exit);
void kvm__dump_mem(struct kvm *kvm, unsigned long addr, unsigned long size, int debug_fd)
{
diff --git a/tools/kvm/powerpc/kvm.c b/tools/kvm/powerpc/kvm.c
index b4b9f82..c1712cf 100644
--- a/tools/kvm/powerpc/kvm.c
+++ b/tools/kvm/powerpc/kvm.c
@@ -151,7 +151,7 @@ void kvm__irq_trigger(struct kvm *kvm, int irq)
kvm__irq_line(kvm, irq, 0);
}
-void kvm__arch_periodic_poll(struct kvm *kvm)
+void kvm__arch_read_term(struct kvm *kvm)
{
/* FIXME: Should register callbacks to platform-specific polls */
spapr_hvcons_poll(kvm);
diff --git a/tools/kvm/term.c b/tools/kvm/term.c
index ac9c7cc..5c3e543 100644
--- a/tools/kvm/term.c
+++ b/tools/kvm/term.c
@@ -25,6 +25,8 @@ bool term_got_escape = false;
int term_fds[TERM_MAX_DEVS][2];
+static pthread_t term_poll_thread;
+
int term_getc(struct kvm *kvm, int term)
{
unsigned char c;
@@ -91,6 +93,30 @@ bool term_readable(int term)
return poll(&pollfd, 1, 0) > 0;
}
+static void *term_poll_thread_loop(void *param)
+{
+ struct pollfd fds[TERM_MAX_DEVS];
+ struct kvm *kvm = (struct kvm *) param;
+
+ int i;
+
+ for (i = 0; i < TERM_MAX_DEVS; i++) {
+ fds[i].fd = term_fds[i][TERM_FD_IN];
+ fds[i].events = POLLIN;
+ fds[i].revents = 0;
+ }
+
+ while (1) {
+ /* Poll with infinite timeout */
+ if(poll(fds, TERM_MAX_DEVS, -1) < 1)
+ break;
+ kvm__arch_read_term(kvm);
+ }
+
+ die("term_poll_thread_loop: error polling device fds %d\n", errno);
+ return NULL;
+}
+
static void term_cleanup(void)
{
int i;
@@ -161,6 +187,11 @@ int term_init(struct kvm *kvm)
term.c_lflag &= ~(ICANON | ECHO | ISIG);
tcsetattr(STDIN_FILENO, TCSANOW, &term);
+
+ /* Use our own blocking thread to read stdin, don't require a tick */
+ if(pthread_create(&term_poll_thread, NULL, term_poll_thread_loop,kvm))
+ die("Unable to create console input poll thread\n");
+
signal(SIGTERM, term_sig_cleanup);
atexit(term_cleanup);
diff --git a/tools/kvm/x86/kvm.c b/tools/kvm/x86/kvm.c
index 9b46772..d285d1d 100644
--- a/tools/kvm/x86/kvm.c
+++ b/tools/kvm/x86/kvm.c
@@ -374,7 +374,7 @@ int kvm__arch_free_firmware(struct kvm *kvm)
return 0;
}
-void kvm__arch_periodic_poll(struct kvm *kvm)
+void kvm__arch_read_term(struct kvm *kvm)
{
serial8250__update_consoles(kvm);
virtio_console__inject_interrupt(kvm);
--
1.7.9.5
next prev parent reply other threads:[~2013-09-04 13:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-04 13:25 [PATCH v2 0/3] kvm tools: remove periodic tick Jonathan Austin
2013-09-04 13:25 ` [PATCH v2 1/3] kvm tools: use #define for maximum number of terminal devices Jonathan Austin
2013-09-04 13:25 ` Jonathan Austin [this message]
2013-09-04 15:58 ` [PATCH v2 2/3] kvm tools: remove periodic tick in favour of a polling thread Pekka Enberg
2013-09-04 17:40 ` Jonathan Austin
2013-09-04 17:48 ` Pekka Enberg
2013-09-04 18:01 ` Sasha Levin
2013-09-05 16:39 ` Jonathan Austin
2013-09-07 17:21 ` Sasha Levin
2013-09-04 13:25 ` [PATCH v2 3/3] kvm tools: stop virtio console doing unnecessary input handling Jonathan Austin
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=1378301148-18823-3-git-send-email-jonathan.austin@arm.com \
--to=jonathan.austin@arm.com \
--cc=Matt.Evans@arm.com \
--cc=kvm@vger.kernel.org \
--cc=marc.zyngier@arm.com \
--cc=penberg@kernel.org \
--cc=will.deacon@arm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox