Skip to contentSkip to conversation

When do we need to do TB unchaining?

Qemu-devel 陳韋任 2 participants 3 messages Sep 29, 2011 – Sep 30, 2011

lore
Share & tools
lore

陳韋任

author
#0 lore raw

Hi, all

I am looking for when TB unchaining is needed. Currently, I
can only see there are three spots (take i386-softmmu as an example):

1. cpu_interrupt:

When virtual devices raise interrupts, eventually apic_local_deliver
(apic.c) will call cpu_interrupt. cpu_interrupt will set up env->interrupt_request, then call cpu_unlink_tb to unlink env's TBs.

Here I have a question. I though cpu_interrupt is only used
in system mode to deliever virtual devices' interrupt. But it seems process mode also has cpu_interrupt.

I have ran some small programs in process mode under GDB, but
I never see cpu_interrupt is called. Do I have to run something bigger to see when cpu_interrupt is called in process mode? Or cpu_interrupt in process mode is only used in some rare cases?

2. cpu_exit:

QEMU will register a host SIGALRM handler, host_alarm_handler
(qemu-timer.c), when initialize the enviroment in system mode. Then when host OS delivers SIGALRM to QEMU, host_alarm_handler calls qemu_notify_event -> cpu_exit. cpu_exit raise env->exit_request , then call cpu_unlink_tb to unlink env's TBs.

There are other places where cpu_exit is called, like

- cpu_signal: I think this is used when IOTHREAD is enabled.

- DMA_init: I guess cpu_exit is called when DMA is done so that control is gave back to QEMU from the code cache.

- gdb_do_syscall: Don't know when it get called.

- vm_stop -> cpu_stop_current: Don't know when it get called.

3. tb_phys_invalidate:

QEMU will invalidate TBs related to a guest page which is
done by tb_invalidate_phys_page_range (exec.c), then tb_invalidate_phys_page_range calls tb_phys_invalidate to invalidate a TB and unlink links to the TB.

Please correct me if I am wrong or something miss. Thanks!

Regards,
chenwj

Signature · 4 lines
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
#1 lore raw
Quoted 13 lines · 陳韋任

Hi, all

 I am looking for when TB unchaining is needed. Currently, I can only see there are three spots (take i386-softmmu as an example):

1. cpu_interrupt:

 When virtual devices raise interrupts, eventually apic_local_deliver (apic.c) will call cpu_interrupt. cpu_interrupt will set up env->interrupt_request, then call cpu_unlink_tb to unlink env's TBs.

Quoted 8 lines

 Here I have a question. I though cpu_interrupt is only used in system mode to deliever virtual devices' interrupt. But it seems process mode also has cpu_interrupt.

 I have ran some small programs in process mode under GDB, but I never see cpu_interrupt is called. Do I have to run something bigger to see when cpu_interrupt is called in process mode? Or cpu_interrupt in process mode is only used in some rare cases?

I don't think it is possible. The only non-device cases for x86 are tb_invalidate_phys_page_range(), cpu_x86_set_a20() and do_inject_x86_mce(), none of which should be reachable from user emulator.

Maybe these should be #ifdeffed out from user emulator builds.

Quoted 8 lines

2. cpu_exit:

 QEMU will register a host SIGALRM handler, host_alarm_handler (qemu-timer.c),  when initialize the enviroment in system mode. Then when host OS delivers SIGALRM to QEMU, host_alarm_handler calls qemu_notify_event -> cpu_exit. cpu_exit raise env->exit_request , then call cpu_unlink_tb to unlink env's TBs.

Quoted 7 lines

 There are other places where cpu_exit is called, like

 - cpu_signal: I think this is used when IOTHREAD is enabled.

 - DMA_init: I guess cpu_exit is called when DMA is done so that control is gave back to QEMU from the code cache.

Yes, this is a questionable hack to improve performance. Maybe it's also not needed anymore since I/O thread was enabled.

Quoted 3 lines

 - gdb_do_syscall: Don't know when it get called.

 - vm_stop -> cpu_stop_current: Don't know when it get called.

grep -r is your friend.

Quoted 21 lines

3. tb_phys_invalidate:

 QEMU will invalidate TBs related to a guest page which is done by tb_invalidate_phys_page_range (exec.c), then tb_invalidate_phys_page_range calls tb_phys_invalidate to invalidate a TB and unlink links to the TB.

 Please correct me if I am wrong or something miss. Thanks!

Regards,
chenwj

--
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667

author
#2 lore raw

Hi, Blue

Quoted 6 lines

I don't think it is possible. The only non-device cases for x86 are tb_invalidate_phys_page_range(), cpu_x86_set_a20() and do_inject_x86_mce(), none of which should be reachable from user emulator.

Maybe these should be #ifdeffed out from user emulator builds.

I am not sure if SMC will use tb_invalidate_phys_page_range. Currently,
QEMU defines tcg_handle_interrupt (replace original cpu_interrupt) and cpu_interrupt for system and process mode separately. Perhaps this should leave to x86 experts to judge.

Quoted 16 lines
Quoted 8 lines

2. cpu_exit:

 QEMU will register a host SIGALRM handler, host_alarm_handler (qemu-timer.c),  when initialize the enviroment in system mode. Then when host OS delivers SIGALRM to QEMU, host_alarm_handler calls qemu_notify_event -> cpu_exit. cpu_exit raise env->exit_request , then call cpu_unlink_tb to unlink env's TBs.

Quoted 7 lines

 There are other places where cpu_exit is called, like

 - cpu_signal: I think this is used when IOTHREAD is enabled.

 - DMA_init: I guess cpu_exit is called when DMA is done so that control is gave back to QEMU from the code cache.

Quoted 8 lines

Yes, this is a questionable hack to improve performance. Maybe it's also not needed anymore since I/O thread was enabled.

Quoted 3 lines

 - gdb_do_syscall: Don't know when it get called.

 - vm_stop -> cpu_stop_current: Don't know when it get called.

grep -r is your friend.

I'll dig into it. Thanks. :)

Regards,
chenwj

Signature · 4 lines
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667