Skip to contentSkip to conversation

QEMU+Aarch64: in_asm log skips instructions of loop-programs

Qemu-devel Sergey Smolov 3 participants 7 messages Sep 2, 2015 – Sep 3, 2015

lore
Share & tools
lore
#0 lore raw

Hello, List!

I've found that while running Aarch64 assembler programs on QEMU with "-d in_asm" option enabled I receive not complete logs. For example, on the following assembler program which contains a loop :

[assembler]
.globl _start
bl _start
_start:
label1:
movz x0, 10
subs x0, x0, 1
b.eq label2
b label1
label2:
hlt #57005
[/assembler]

I receive the following log which does not include "loop unrolling":
[log]
----------------
IN:
0x0000000000000000: 94000001 bl #+0x4 (addr 0x4)

----------------
IN:
0x0000000000000004: d2800140 mov x0, #0xa

----------------
IN:
0x0000000000000008: f1000400 subs x0, x0, #0x1 (1)

----------------
IN:
0x000000000000000c: 54000040 b.eq #+0x8 (addr 0x14)

----------------
IN:
0x0000000000000010: 17fffffd b #-0xc (addr 0x4)

[/log]

It seems that QEMU skips some internal instructions when generates "in_asm" log. How to eliminate this?

Thanks in advance!

Sincerely yours,
Sergey Smolov

#1 lore raw

02.09.2015 16:55, Sergey Smolov пишет:

Quoted 40 lines

Hello, List!

I've found that while running Aarch64 assembler programs on QEMU with "-d in_asm" option enabled I receive not complete logs. For example, on the following assembler program which contains a loop :

[assembler]
.globl _start
bl _start
_start:
label1:
movz x0, 10
subs x0, x0, 1
b.eq label2
b label1
label2:
hlt #57005
[/assembler]

I receive the following log which does not include "loop unrolling":
[log]
----------------
IN:
0x0000000000000000: 94000001 bl #+0x4 (addr 0x4)

----------------
IN:
0x0000000000000004: d2800140 mov x0, #0xa

----------------
IN:
0x0000000000000008: f1000400 subs x0, x0, #0x1 (1)

----------------
IN:
0x000000000000000c: 54000040 b.eq #+0x8 (addr 0x14)

----------------
IN:
0x0000000000000010: 17fffffd b #-0xc (addr 0x4)

Quoted 8 lines

[/log]

It seems that QEMU skips some internal instructions when generates "in_asm" log. How to eliminate this?

Thanks in advance!

Sincerely yours,
Sergey Smolov

Sorry, the correct assembler code is:

.globl _start
bl _start
_start:
movz x0, 10
label1:
subs x0, x0, 1
b.eq label2
b label1
label2:
hlt #57005

#2 lore raw
Quoted 3 lines · Sergey Smolov

02.09.2015 16:55, Sergey Smolov пишет:

Quoted 2 lines

It seems that QEMU skips some internal instructions when generates "in_asm" log. How to eliminate this?

It might help if you said what you thought was missing.

-- PMM

#3 lore raw

Peter Maydell писал 2015-09-02 19:39:

Quoted 8 lines · Sergey Smolov
Quoted 3 lines

02.09.2015 16:55, Sergey Smolov пишет:

Quoted 2 lines

It seems that QEMU skips some internal instructions when generates "in_asm" log. How to eliminate this?

It might help if you said what you thought was missing.

-- PMM

I mean that in this example QEMU does not write to log "intermediate" SUBS instructions which appear in loop-unrolling process. For me it woulb be ok if QEMU generate the following in_asm log:

[log]
IN:
0x0000000000000000: 94000001 bl #+0x4 (addr 0x4)

----------------
IN:
0x0000000000000004: d2800140 mov x0, #0xa

----------------
IN:
0x0000000000000008: f1000400 subs x0, x0, #0x1 (1)

----------------
IN:
0x000000000000000c: 54000040 b.eq #+0x8 (addr 0x14)

----------------
IN:
0x0000000000000008: f1000400 subs x0, x0, #0x1 (1)

----------------
IN:
0x000000000000000c: 54000040 b.eq #+0x8 (addr 0x14)

----------------
IN:
0x0000000000000008: f1000400 subs x0, x0, #0x1 (1)

----------------
IN:
0x000000000000000c: 54000040 b.eq #+0x8 (addr 0x14)

...
<repeat SUBS and B.EQ 8 times, if we enable also "cpu" logging mode here we will see that X1 register value decrements on each iteration>
...
----------------
IN:
0x0000000000000010: 17fffffd b #-0xc (addr 0x4)
[/log]

In terms of functional programming languages (like C), my idea is to generate for the following program:

for (i = 0; i < 2; i++) {
func(i);
}

the log like:
func(0)
func(1)

but QEMU generates log that contains exactly one call of "func".

Sergey Smolov

#4 lore raw
Quoted 16 lines · Sergey Smolov

I mean that in this example QEMU does not write to log "intermediate" SUBS instructions which appear in loop-unrolling process.
For me it woulb be ok if QEMU generate the following in_asm log:

[log]
IN:
0x0000000000000000: 94000001 bl #+0x4 (addr 0x4)

----------------
IN:
0x0000000000000004: d2800140 mov x0, #0xa

----------------
IN:
0x0000000000000008: f1000400 subs x0, x0, #0x1 (1)

Quoted 7 lines

----------------
IN:
0x000000000000000c: 54000040 b.eq #+0x8 (addr 0x14)

----------------
IN:
0x0000000000000008: f1000400 subs x0, x0, #0x1 (1)

QEMU's in_asm logging doesn't work like that. We log the instructions that we *translate*, not instructions that we *execute*. Generally we translate basic blocks and then cache them so they can be executed multiple times. (It's not actually guaranteed that a translated block will ever be executed, though it almost always will be.) The logging of input instructions happens at the translate phase. When we execute we don't have any information about the guest instructions involved.

This has nothing to do with "loop-unrolling", which QEMU doesn't try to do at all.

You might find the 'exec' logging helpful for tracking which translated blocks get executed.

thanks
-- PMM

#5 lore raw

03.09.2015 10:33, Peter Maydell пишет:

Quoted 34 lines · Sergey Smolov
Quoted 16 lines

I mean that in this example QEMU does not write to log "intermediate" SUBS instructions which appear in loop-unrolling process.
For me it woulb be ok if QEMU generate the following in_asm log:

[log]
IN:
0x0000000000000000: 94000001 bl #+0x4 (addr 0x4)

----------------
IN:
0x0000000000000004: d2800140 mov x0, #0xa

----------------
IN:
0x0000000000000008: f1000400 subs x0, x0, #0x1 (1)

Quoted 7 lines

----------------
IN:
0x000000000000000c: 54000040 b.eq #+0x8 (addr 0x14)

----------------
IN:
0x0000000000000008: f1000400 subs x0, x0, #0x1 (1)

QEMU's in_asm logging doesn't work like that. We log the instructions that we *translate*, not instructions that we *execute*. Generally we translate basic blocks and then cache them so they can be executed multiple times. (It's not actually guaranteed that a translated block will ever be executed, though it almost always will be.) The logging of input instructions happens at the translate phase. When we execute we don't have any information about the guest instructions involved.

Quoted 9 lines

This has nothing to do with "loop-unrolling", which QEMU doesn't try to do at all.

You might find the 'exec' logging helpful for tracking which translated blocks get executed.

thanks
-- PMM

Peter,

Thank you for your answer!

I've tested 'exec' logging and it does not contain unrolled llops too. For my sample it looks like:

[log]
Trace 0x7f999385a000 [0000000000000000]
Trace 0x7f999385a050 [0000000000000004]
Trace 0x7f999385a090 [*0000000000000008*]
Trace 0x7f999385a120 [000000000000000c]
Trace 0x7f999385a190 [0000000000000010]
Trace 0x7f999385a090 [*0000000000000008*]
Trace 0x7f999385a1d0 [0000000000000014]
Trace 0x7f999385a210 [0000000000000200]
Trace 0x7f999385a210 [0000000000000200]
...
[/log]

and contains only two records related to 'subs' instruction (it is situated on 0x0000000000000008 addresses whcih i've highlighted).

Also, is it true that after translation to internal representation (TCG-representation, yes?) there is no possibility at all to restore guest instructions?

Thanks,

Sergey Smolov

#6 lore raw
In reply to Peter Maydell
Quoted 2 lines · Peter Maydell

You might find the 'exec' logging helpful for tracking which translated blocks get executed.

Even then you will of course only log the head of unlinked chains of blocks.

r~