Skip to content

Commit 290dae4

Browse files
committed
cpu: move interrupt handling out of translate-common.c
translate-common.c will not be available anymore with --disable-tcg, so we cannot leave cpu_interrupt_handler there. Move the TCG-specific handler to accel/tcg/tcg-all.c, and adopt KVM's handler as the default one, since it works just as well for Xen and qtest. Signed-off-by: Paolo Bonzini <[email protected]>
1 parent a0be0c5 commit 290dae4

File tree

5 files changed

+46
-65
lines changed

5 files changed

+46
-65
lines changed

accel/kvm/kvm-all.c

-11
Original file line numberDiff line numberDiff line change
@@ -981,15 +981,6 @@ static MemoryListener kvm_io_listener = {
981981
.priority = 10,
982982
};
983983

984-
static void kvm_handle_interrupt(CPUState *cpu, int mask)
985-
{
986-
cpu->interrupt_request |= mask;
987-
988-
if (!qemu_cpu_is_self(cpu)) {
989-
qemu_cpu_kick(cpu);
990-
}
991-
}
992-
993984
int kvm_set_irq(KVMState *s, int irq, int level)
994985
{
995986
struct kvm_irq_level event;
@@ -1774,8 +1765,6 @@ static int kvm_init(MachineState *ms)
17741765

17751766
s->many_ioeventfds = kvm_check_many_ioeventfds();
17761767

1777-
cpu_interrupt_handler = kvm_handle_interrupt;
1778-
17791768
return 0;
17801769

17811770
err:

accel/tcg/Makefile.objs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
obj-$(CONFIG_SOFTMMU) += tcg-all.o
22
obj-$(CONFIG_SOFTMMU) += cputlb.o
3-
obj-y += cpu-exec.o cpu-exec-common.o translate-all.o translate-common.o
3+
obj-y += cpu-exec.o cpu-exec-common.o translate-all.o

accel/tcg/tcg-all.c

+32
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,45 @@
2727
#include "sysemu/accel.h"
2828
#include "sysemu/sysemu.h"
2929
#include "qom/object.h"
30+
#include "qemu-common.h"
31+
#include "qom/cpu.h"
32+
#include "sysemu/cpus.h"
33+
#include "qemu/main-loop.h"
3034

3135
unsigned long tcg_tb_size;
3236
static bool tcg_allowed = true;
3337

38+
#ifndef CONFIG_USER_ONLY
39+
/* mask must never be zero, except for A20 change call */
40+
static void tcg_handle_interrupt(CPUState *cpu, int mask)
41+
{
42+
int old_mask;
43+
g_assert(qemu_mutex_iothread_locked());
44+
45+
old_mask = cpu->interrupt_request;
46+
cpu->interrupt_request |= mask;
47+
48+
/*
49+
* If called from iothread context, wake the target cpu in
50+
* case its halted.
51+
*/
52+
if (!qemu_cpu_is_self(cpu)) {
53+
qemu_cpu_kick(cpu);
54+
} else {
55+
cpu->icount_decr.u16.high = -1;
56+
if (use_icount &&
57+
!cpu->can_do_io
58+
&& (mask & ~old_mask) != 0) {
59+
cpu_abort(cpu, "Raised interrupt while not in I/O function");
60+
}
61+
}
62+
}
63+
#endif
64+
3465
static int tcg_init(MachineState *ms)
3566
{
3667
tcg_exec_init(tcg_tb_size * 1024 * 1024);
68+
cpu_interrupt_handler = tcg_handle_interrupt;
3769
return 0;
3870
}
3971

accel/tcg/translate-common.c

-53
This file was deleted.

qom/cpu.c

+13
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
#include "hw/qdev-properties.h"
3333
#include "trace-root.h"
3434

35+
CPUInterruptHandler cpu_interrupt_handler;
36+
3537
bool cpu_exists(int64_t id)
3638
{
3739
CPUState *cpu;
@@ -417,6 +419,17 @@ static vaddr cpu_adjust_watchpoint_address(CPUState *cpu, vaddr addr, int len)
417419
return addr;
418420
}
419421

422+
static void generic_handle_interrupt(CPUState *cpu, int mask)
423+
{
424+
cpu->interrupt_request |= mask;
425+
426+
if (!qemu_cpu_is_self(cpu)) {
427+
qemu_cpu_kick(cpu);
428+
}
429+
}
430+
431+
CPUInterruptHandler cpu_interrupt_handler = generic_handle_interrupt;
432+
420433
static void cpu_class_init(ObjectClass *klass, void *data)
421434
{
422435
DeviceClass *dc = DEVICE_CLASS(klass);

0 commit comments

Comments
 (0)