mirror of
https://github.com/clearlinux/kvmtool.git
synced 2026-08-26 08:07:00 +00:00
kvm: Cleanup interrupt timer logic
This patch moves the interrupt timer logic to kvm.c and cleans it up. Signed-off-by: Pekka Enberg <penberg@kernel.org>
This commit is contained in:
committed by
Will Deacon
parent
369c01c0e7
commit
ce79f1ca45
@@ -7,11 +7,13 @@
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <time.h>
|
||||
|
||||
struct kvm {
|
||||
int sys_fd; /* For system ioctls(), i.e. /dev/kvm */
|
||||
int vm_fd; /* For VM ioctls() */
|
||||
int vcpu_fd; /* For VCPU ioctls() */
|
||||
timer_t timerid; /* Posix timer for interrupts */
|
||||
struct kvm_run *kvm_run;
|
||||
|
||||
struct disk_image *disk_image;
|
||||
@@ -40,6 +42,7 @@ bool kvm__load_kernel(struct kvm *kvm, const char *kernel_filename,
|
||||
const char *initrd_filename, const char *kernel_cmdline);
|
||||
void kvm__reset_vcpu(struct kvm *self);
|
||||
void kvm__setup_mem(struct kvm *self);
|
||||
void kvm__start_timer(struct kvm *self);
|
||||
void kvm__run(struct kvm *self);
|
||||
void kvm__irq_line(struct kvm *self, int irq, int level);
|
||||
bool kvm__emulate_io(struct kvm *self, uint16_t port, void *data, int direction, int size, uint32_t count);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "kvm/kvm.h"
|
||||
|
||||
#include "kvm/interrupt.h"
|
||||
#include "kvm/cpufeature.h"
|
||||
#include "kvm/interrupt.h"
|
||||
#include "kvm/e820.h"
|
||||
#include "kvm/util.h"
|
||||
|
||||
@@ -12,16 +12,18 @@
|
||||
#include <sys/ioctl.h>
|
||||
#include <inttypes.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <time.h>
|
||||
|
||||
/*
|
||||
* Compatibility code. Remove this when we move to tools/kvm.
|
||||
@@ -606,6 +608,46 @@ void kvm__setup_mem(struct kvm *self)
|
||||
};
|
||||
}
|
||||
|
||||
#define TIMER_INTERVAL_NS 1000000 /* 1 msec */
|
||||
|
||||
static void alarm_handler(int sig)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
void kvm__start_timer(struct kvm *self)
|
||||
{
|
||||
struct itimerspec its;
|
||||
struct sigaction sa;
|
||||
struct sigevent sev;
|
||||
|
||||
sigfillset(&sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
sa.sa_handler = alarm_handler;
|
||||
|
||||
sigaction(SIGALRM, &sa, NULL);
|
||||
|
||||
memset(&sev, 0, sizeof(struct sigevent));
|
||||
sev.sigev_value.sival_int = 0;
|
||||
sev.sigev_notify = SIGEV_SIGNAL;
|
||||
sev.sigev_signo = SIGALRM;
|
||||
|
||||
if (timer_create(CLOCK_REALTIME, &sev, &self->timerid) < 0)
|
||||
die("timer_create()");
|
||||
|
||||
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;
|
||||
|
||||
if (timer_settime(self->timerid, 0, &its, NULL) < 0)
|
||||
die("timer_settime()");
|
||||
}
|
||||
|
||||
void kvm__run(struct kvm *self)
|
||||
{
|
||||
int err;
|
||||
|
||||
@@ -8,13 +8,12 @@
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <termios.h>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <time.h>
|
||||
|
||||
extern bool ioport_debug;
|
||||
|
||||
@@ -91,46 +90,6 @@ static bool option_matches(char *arg, const char *option)
|
||||
return !strncmp(arg, option, strlen(option));
|
||||
}
|
||||
|
||||
#define TIMER_INTERVAL_NS 1000000 /* 1 msec */
|
||||
|
||||
static void alarm_handler(int sig)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
static void setup_timer(void)
|
||||
{
|
||||
struct itimerspec its;
|
||||
struct sigaction sa;
|
||||
struct sigevent sev;
|
||||
timer_t timerid;
|
||||
|
||||
sigfillset(&sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
sa.sa_handler = alarm_handler;
|
||||
|
||||
sigaction(SIGALRM, &sa, NULL);
|
||||
|
||||
memset(&sev, 0, sizeof(struct sigevent));
|
||||
sev.sigev_value.sival_int = 0;
|
||||
sev.sigev_notify = SIGEV_SIGNAL;
|
||||
sev.sigev_signo = SIGALRM;
|
||||
|
||||
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;
|
||||
if (timer_create(CLOCK_MONOTONIC, &sev, &timerid) < 0)
|
||||
die("timer_create()");
|
||||
|
||||
if (timer_settime(timerid, 0, &its, NULL) < 0)
|
||||
die("timer_settime()");
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *kernel_filename = NULL;
|
||||
@@ -222,7 +181,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
blk_virtio__init(kvm);
|
||||
|
||||
setup_timer();
|
||||
kvm__start_timer(kvm);
|
||||
|
||||
tty_set_canon_flag(fileno(stdin), 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user