qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] TB chaining


From: 陳韋任
Subject: Re: [Qemu-devel] TB chaining
Date: Thu, 22 Sep 2011 10:15:53 +0800
User-agent: Mutt/1.5.21 (2010-09-15)

> I am new to QEMU, can anyone please tell me where the TB chaining code is in
> QEMU ?

  struct TranslationBlock has fields used to to block chaining. You also
need to look into it.

cpu_exec (cpu-exec.c)

  It's the main execution loop where the interrupt/exception is handled
, and translared TB is found then executed.

  /* prepare setjmp context for exception handling */
  for(;;) {
      if (setjmp(env->jmp_env) == 0) {
          /* if an exception is pending, we execute it here */
      }

      next_tb = 0; /* force lookup of first TB */
      for(;;) {
          interrupt_request = env->interrupt_request;
          if (unlikely(interrupt_request)) {

          }

          tb = tb_find_fast(env);

          if (next_tb != 0 && tb->page_addr[1] == -1) {
              tb_add_jump((TranslationBlock *)(next_tb & ~3), next_tb & 3, tb);
          }

          if (likely(!env->exit_request)) {
                tc_ptr = tb->tc_ptr;
              /* execute the generated code */
                next_tb = tcg_qemu_tb_exec(env, tc_ptr);
          } 
      }
  }

tb_add_jump does block chaining. The variable names next_tb and tb
could be misleading here. tb_add_jump will link next_tb to tb, i.e.,
next_tb -> tb. And QEMU use the last two bit of the pointer to
TranslationBlock to encode the direction of the block chaining.
For example, next_tb[0] might be the if branch, and next_tb[1]
might be the else branch.

  Block chaining can be done direct or indirect. Direct means you patch
the translated code in the tranlation code cache, so that it'll jump
to next translated code block then executed. Indirect means you use
TranslationBlock tb_next field to point to next translated code block
in the tranlation code cache. On host like x86 and arm, direct block
chaining is used.

  Also note that while QEMU generate host binary from TCG IR, it will
leave some space for further block chaining to do the patch.


Regards,
chenwj

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]