All of lore.kernel.org
 help / color / mirror / Atom feed
* Re: high cpu usage in idle state
       [not found] <CABip9V9nwDNAEg-620hG2r5pyhw_rig+2nf9Ja3s=WA-wmH=jQ@mail.gmail.com>
@ 2021-09-15  9:07 ` Philippe Mathieu-Daudé
  2021-09-18  8:11   ` Ali Vatankhah
  0 siblings, 1 reply; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-15  9:07 UTC (permalink / raw)
  To: Ali Vatankhah, qemu-discuss, qemu-ppc, qemu-devel

On 9/15/21 9:46 AM, Ali Vatankhah wrote:
> Dear qemu developers
> I built an image for e5500 cpu with yocto and run with qemu ppce500 machine:
> qemu-system-ppc64 -nographic -M ppce500 -cpu e5500 -kernel uImage
> -initrd core-image-minimal.rootfs.ext2.gz -append 'root=/dev/ram rw' 
> It works well, but as the emulated guest is in idle state, in the host
> it consumes 100% cpu on one core. 
> Is this cpu usage due to guest idle instruction emulated on the host? is
> it possible to correct that?

It depends of:

- is your CPU able wait when there is no workload
  (Old CPUs don't have this ability and just keep running
   wasting cycles. Newer have instructions such "wait for
   interrupt or something" or "idle")

- is your guest using such instruction, or doing a while(true)
  loop while idling?


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

* Re: high cpu usage in idle state
  2021-09-15  9:07 ` high cpu usage in idle state Philippe Mathieu-Daudé
@ 2021-09-18  8:11   ` Ali Vatankhah
  2021-09-19 18:06     ` Peter Maydell
  0 siblings, 1 reply; 5+ messages in thread
From: Ali Vatankhah @ 2021-09-18  8:11 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé; +Cc: qemu-ppc, qemu-devel, qemu-discuss

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

Hi Philippe, Thank for your email

I investigated your advice,

first checked the CPU's programmer's reference manual and it has wait for
interrupt instruction.

then to check what instructions are executing I run this command:

qemu-system-ppc64 -nographic -M ppce500 -cpu e5500 -kernel uImage
-singlestep -d in_asm -D target_asm.log

Obviously this results in a Kernel panic, but the point is that after panic
there is no guest
 instruction running as there is no more log in the file but still CPU
usage is 100.

also run this command to check generated host assembly code:

qemu-system-ppc64 -nographic -M ppce500 -cpu e5500 -kernel uImage
-singlestep -d out_asm -D host_asm.log

and the result was the same, after Kernel panic there are no more
instructions to run
(though there are some nop instructions in tb slow paths + alignment
section at
the end of some TBs but I think it's not relevant).

in another test I run the complete working command with log options and
after login kill all
 services except init:

qemu-system-ppc64 -nographic -m 256 -M ppce500 -cpu e5500 -kernel uImage
-initrd rootfs.ext2.gz
         -append 'root=/dev/ram rw ramdisk_size=150000' -singlestep -d
out_asm -D  host_asm.log

it logs in the file once in a while but still CPU usage is 100% constantly.

Thanks. Regards

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

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

* Re: high cpu usage in idle state
  2021-09-18  8:11   ` Ali Vatankhah
@ 2021-09-19 18:06     ` Peter Maydell
  2021-09-19 18:46       ` Philippe Mathieu-Daudé
  0 siblings, 1 reply; 5+ messages in thread
From: Peter Maydell @ 2021-09-19 18:06 UTC (permalink / raw)
  To: Ali Vatankhah
  Cc: qemu-discuss, qemu-ppc, Philippe Mathieu-Daudé, qemu-devel

On Sat, 18 Sept 2021 at 09:12, Ali Vatankhah <alivatankhah72@gmail.com> wrote:
> then to check what instructions are executing I run this command:
>
> qemu-system-ppc64 -nographic -M ppce500 -cpu e5500 -kernel uImage -singlestep -d in_asm -D target_asm.log
>
> Obviously this results in a Kernel panic, but the point is that after panic there is no guest
>  instruction running as there is no more log in the file but still CPU usage is 100.

The lack of further in_asm logging does not mean that guest instructions
are not running. in_asm logging happens at *translate* time,
which is to say the first time QEMU encounters any particular instruction.
After translation, QEMU can re-execute the translated code for that
instruction many times, and it will not show up in in_asm logs again.
In particular, if the guest CPU is doing either of:
 * a tight loop
 * an infinite loop of taking exceptions
it will just be re-running code that has been seen before.
Probably the code the kernel runs after it panic()s is just a loop.

If you want to log execution, you need to add 'exec' and/or 'cpu' to
your -d logging. (Warning: this can generate a lot of logging output
and massively slow down execution as a result.)

> also run this command to check generated host assembly code:
>
> qemu-system-ppc64 -nographic -M ppce500 -cpu e5500 -kernel uImage -singlestep -d out_asm -D host_asm.log

out_asm also is logged only at translate time, not at execution time.

-- PMM


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

* Re: high cpu usage in idle state
  2021-09-19 18:06     ` Peter Maydell
@ 2021-09-19 18:46       ` Philippe Mathieu-Daudé
  2021-09-20  7:30         ` Ali Vatankhah
  0 siblings, 1 reply; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-19 18:46 UTC (permalink / raw)
  To: Peter Maydell, Ali Vatankhah; +Cc: qemu-ppc, qemu-devel, qemu-discuss

On 9/19/21 20:06, Peter Maydell wrote:
> On Sat, 18 Sept 2021 at 09:12, Ali Vatankhah <alivatankhah72@gmail.com> wrote:
>> then to check what instructions are executing I run this command:
>>
>> qemu-system-ppc64 -nographic -M ppce500 -cpu e5500 -kernel uImage -singlestep -d in_asm -D target_asm.log
>>
>> Obviously this results in a Kernel panic, but the point is that after panic there is no guest
>>  instruction running as there is no more log in the file but still CPU usage is 100.
> 
> The lack of further in_asm logging does not mean that guest instructions
> are not running. in_asm logging happens at *translate* time,
> which is to say the first time QEMU encounters any particular instruction.
> After translation, QEMU can re-execute the translated code for that
> instruction many times, and it will not show up in in_asm logs again.
> In particular, if the guest CPU is doing either of:
>  * a tight loop
>  * an infinite loop of taking exceptions
> it will just be re-running code that has been seen before.
> Probably the code the kernel runs after it panic()s is just a loop.
> 
> If you want to log execution, you need to add 'exec' and/or 'cpu' to
> your -d logging. (Warning: this can generate a lot of logging output
> and massively slow down execution as a result.)

In the "infinite loop exception" case, '-d int' might be sufficient,
before using 'exec/cpu', since you'll see the exception raise over
and over.

>> also run this command to check generated host assembly code:
>>
>> qemu-system-ppc64 -nographic -M ppce500 -cpu e5500 -kernel uImage -singlestep -d out_asm -D host_asm.log
> 
> out_asm also is logged only at translate time, not at execution time.
> 
> -- PMM
> 


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

* Re: high cpu usage in idle state
  2021-09-19 18:46       ` Philippe Mathieu-Daudé
@ 2021-09-20  7:30         ` Ali Vatankhah
  0 siblings, 0 replies; 5+ messages in thread
From: Ali Vatankhah @ 2021-09-20  7:30 UTC (permalink / raw)
  To: Peter Maydell, Mathieu-Daudé; +Cc: qemu-ppc, qemu-devel, qemu-discuss

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

Thank a lot Peter and Philippe

On 9/19/21 20:46, Philippe Mathieu-Daudé wrote:
> In the "infinite loop exception" case, '-d int' might be sufficient,
> before using 'exec/cpu', since you'll see the exception raise over
> and over.

I tried -d int and see that a lot of exceptions are rising in idle state
and during boot:

Raise exception at 000000000fd841e4 => 0000000a (00)
Raise exception at 00000000100074cc => 0000000a (00)
....

Can anyone please help me to find why these executions are rising?
Is it kernel configuration mismatch with machine settings? how to debug it?

Best Regards

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

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

end of thread, other threads:[~2021-09-20  7:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CABip9V9nwDNAEg-620hG2r5pyhw_rig+2nf9Ja3s=WA-wmH=jQ@mail.gmail.com>
2021-09-15  9:07 ` high cpu usage in idle state Philippe Mathieu-Daudé
2021-09-18  8:11   ` Ali Vatankhah
2021-09-19 18:06     ` Peter Maydell
2021-09-19 18:46       ` Philippe Mathieu-Daudé
2021-09-20  7:30         ` Ali Vatankhah

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.