All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: [Qemu-devel] TCG flow vs dyngen
@ 2011-01-16 14:46 Raphael Lefevre
  2011-01-16 15:21 ` Stefano Bonifazi
  0 siblings, 1 reply; 43+ messages in thread
From: Raphael Lefevre @ 2011-01-16 14:46 UTC (permalink / raw)
  To: stefboombastic; +Cc: blauwirbel, qemu-devel

[-- Attachment #1: Type: text/plain, Size: 2733 bytes --]

On Wed, Dec 15, 2010 at 4:17 AM, Stefano Bonifazi <stefboombastic@gmail.com> wrote:

> On 12/11/2010 03:44 PM, Blue Swirl wrote:

> 

> Hi!

> Thank you very much! Knowing exactly where I should check, in a so big

> project helped me very much!!

> Anyway after having spent more than 2 days on that code I still can't

> understand how it works the real execution:

> 

> in cpu-exec.c : cpu_exec_nocache i find:

> 

>> /* execute the generated code */

>>    next_tb = tcg_qemu_tb_exec(tb->tc_ptr);

> 

> and in cpu-exec.c : cpu_exec

> 

>> /* execute the generated code */

>> 

>>                    next_tb = tcg_qemu_tb_exec(tc_ptr);

> 

> so I thought tcg_qemu_tb_exec "function" should do the work of executing the

> translated binary in the host.

> But then I found out it is just a define in tcg.h:

> 

>> #define tcg_qemu_tb_exec(tb_ptr) ((long REGPARM (*)(void

>> *))code_gen_prologue)(tb_ptr)

> 

> and again in exec.c

> 

>> uint8_t code_gen_prologue[1024] code_gen_section;

> 

> Maybe I have some problems with that C syntax, but I really don't understand

> what happens there.. how the execution happens!

> 

> Here instead  with QEMU/TCG I understood that at runtime the target binary

> is translated into host binary (somehow) .. but then.. how can this new host

> binary be run? Shall the host code at runtime do some sort of (assembly

> speaking) branch jump to an area of memory with new host binary instructions

> .. and then jump back to the old process binary code?

 

1. As I know, the host codes translated from the target instructions exist by the format of object file, that’s why they can be executed directly.

2. I think you catch the right concept in some point of view, one part of the internal of QEMU does such jump & back works certainly.

 

> If so, can you explain me how this happens in those lines of code?

 

I only can give a rough profile, the code you listed do a simple thing:

Modify the pointer of the host code execution to point the next address that the host processor should continue to execute.

 

> I am just a student.. unluckily at university they just tell you that a cpu

> follows some sort of "fetch ->decode->execute" flow .. but then you open

> QEMU.. and wow there is a huge gap for understanding it, and no books where

> to study it! ;)

 

The QEMU is not used to simulate the every details of the processor should behave, it just try to approximate the necessary operations what a machine should be!

“fetch->decode->execute” flow only need to be concerned when you involve into the hardware design.

 

Raphaël Lefèvre


[-- Attachment #2: Type: text/html, Size: 11197 bytes --]

^ permalink raw reply	[flat|nested] 43+ messages in thread
* [Qemu-devel] TCG flow vs dyngen
@ 2010-12-10 21:26 Stefano Bonifazi
  2010-12-11 11:02 ` Blue Swirl
  0 siblings, 1 reply; 43+ messages in thread
From: Stefano Bonifazi @ 2010-12-10 21:26 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 2636 bytes --]

Hi all!
  From the technical documentation 
(http://www.usenix.org/publications/library/proceedings/usenix05/tech/freenix/bellard.html) 
I read:

> The first step is to split each target CPU instruction into fewer 
> simpler instructions called /micro operations/. Each micro operation 
> is implemented by a small piece of C code. This small C source code is 
> compiled by GCC to an object file. The micro operations are chosen so 
> that their number is much smaller (typically a few hundreds) than all 
> the combinations of instructions and operands of the target CPU. The 
> translation from target CPU instructions to micro operations is done 
> entirely with hand coded code. 
> A compile time tool called dyngen uses the object file containing the 
> micro operations as input to generate a dynamic code generator. This 
> dynamic code generator is invoked at runtime to generate a complete 
> host function which concatenates several micro operations. 
instead from wikipedia(http://en.wikipedia.org/wiki/QEMU) and other 
sources I read:

> The Tiny Code Generator (TCG) aims to remove the shortcoming of 
> relying on a particular version of GCC 
> <http://en.wikipedia.org/wiki/GNU_Compiler_Collection> or any 
> compiler, instead incorporating the compiler (code generator) into 
> other tasks performed by QEMU in run-time. The whole translation task 
> thus consists of two parts: blocks of target code (/TBs/) being 
> rewritten in *TCG ops* - a kind of machine-independent intermediate 
> notation, and subsequently this notation being compiled for the host's 
> architecture by TCG. Optional optimisation passes are performed 
> between them.
- So, I think that the technical documentation is now obsolete, isn't it?

- The "old way" used much offline (compile time) work compiling the 
micro operations into host machine code, while if I understand well, TCG 
does everything in run-time(please correct me if I am wrong!).. so I 
wonder, how can it be as fast as the previous method (or even faster)?

- If I understand well, TGC runtime flow is the following:
     - TCG takes the target binary, and splits it into target blocks
     - if the TB is not cached, TGC translates it (or better the target 
instructions it is composed by) into TCG micro ops,
     - TGC compiles TGC uops into host object code,
     - TGC caches the TB,
     - TGC tries to chain the block with others,
     - TGC copies the TB into the execution buffer
     - TGC runs it
Am I right? Please correct me, whether I am wrong, as I wanna use that 
flow scheme for trying to understand the code..
Thank you very much in advance!
Stefano B.



[-- Attachment #2: Type: text/html, Size: 3664 bytes --]

^ permalink raw reply	[flat|nested] 43+ messages in thread

end of thread, other threads:[~2011-01-25  9:31 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-01-16 14:46 [Qemu-devel] TCG flow vs dyngen Raphael Lefevre
2011-01-16 15:21 ` Stefano Bonifazi
2011-01-16 16:01   ` Raphaël Lefèvre
2011-01-16 16:43     ` Stefano Bonifazi
2011-01-16 18:29       ` Peter Maydell
2011-01-16 19:02         ` Stefano Bonifazi
2011-01-16 19:24           ` Peter Maydell
2011-01-24 13:20             ` [Qemu-devel] " Stefano Bonifazi
2011-01-16 20:50           ` [Qemu-devel] " Stefano Bonifazi
2011-01-16 21:08             ` Raphaël Lefèvre
2011-01-24 12:35               ` [Qemu-devel] " Stefano Bonifazi
2011-01-17 11:59             ` [Qemu-devel] " Lluís
2011-01-24 12:31               ` [Qemu-devel] " Stefano Bonifazi
2011-01-24 13:36                 ` Lluís
2011-01-24 14:00                   ` Stefano Bonifazi
2011-01-24 15:06                     ` Lluís
2011-01-24 17:23                       ` Stefano Bonifazi
2011-01-24 18:12                         ` Lluís
2011-01-16 19:16       ` [Qemu-devel] " Raphaël Lefèvre
2011-01-23 21:50     ` Rob Landley
2011-01-23 22:25       ` Stefano Bonifazi
2011-01-23 23:40         ` Rob Landley
2011-01-24 10:17           ` Stefano Bonifazi
2011-01-24 18:20             ` Rob Landley
2011-01-24 21:16               ` Stefano Bonifazi
2011-01-25  1:19                 ` Rob Landley
2011-01-25  8:53                   ` Stefano Bonifazi
2011-01-24 14:32       ` Peter Maydell
2011-01-24 14:56         ` Stefano Bonifazi
2011-01-24 15:15           ` Lluís
2011-01-24 18:02           ` Dushyant Bansal
2011-01-24 19:38             ` Stefano Bonifazi
2011-01-25  7:56               ` Dushyant Bansal
2011-01-25  9:04                 ` Stefano Bonifazi
2011-01-25  9:05                   ` Edgar E. Iglesias
2011-01-25  9:28                     ` Stefano Bonifazi
  -- strict thread matches above, loose matches on Subject: below --
2010-12-10 21:26 Stefano Bonifazi
2010-12-11 11:02 ` Blue Swirl
2010-12-11 12:29   ` Stefano Bonifazi
2010-12-11 13:11     ` Blue Swirl
2010-12-11 14:32       ` Stefano Bonifazi
2010-12-11 14:44         ` Blue Swirl
2010-12-14 20:17           ` Stefano Bonifazi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.