* [Qemu-devel] qemu_clock_get_ns does not take into account icount_time_shift
@ 2018-07-25 19:25 Humberto "SilverOne" Carvalho
2018-07-25 20:34 ` Humberto "SilverOne" Carvalho
0 siblings, 1 reply; 2+ messages in thread
From: Humberto "SilverOne" Carvalho @ 2018-07-25 19:25 UTC (permalink / raw)
To: qemu-devel
Hello,
When using icount with shift, virtual time is defined as icount << N.
However, qemu_clock_get_ns simply returns cpu_get_icount, thereby returning
icount instead of icount << N.
If you check the qemu/util/qemu-timer.c file you will find the following
function:
597: int64_t qemu_clock_get_ns(QEMUClockType type)
598: {
....
602: switch (type) {
....
606: case QEMU_CLOCK_VIRTUAL:
607: if (use_icount) {
608: return cpu_get_icount();
Now on line 606, in case we requested QEMU_CLOCK_VIRTUAL, and we are using
icount, the value of cpu_get_icount(); will be returned.
However if I understand correctly, in order to convert icount to ns, you
must take into account the icount shift -- as defined in the documentation:
"The virtual cpu will execute one instruction every 2^N ns of virtual
time.".
Therefor, the correct value to return would be
cpu_icount_to_ns(cpu_get_icount()), where cpu_icount_to_ns is defined in
cpus.c:
296: int64_t cpu_icount_to_ns(int64_t icount)
297: {
298: return icount << icount_time_shift;
299: }
Best Regards,
Humberto "SilverOne" Carvalho
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] qemu_clock_get_ns does not take into account icount_time_shift
2018-07-25 19:25 [Qemu-devel] qemu_clock_get_ns does not take into account icount_time_shift Humberto "SilverOne" Carvalho
@ 2018-07-25 20:34 ` Humberto "SilverOne" Carvalho
0 siblings, 0 replies; 2+ messages in thread
From: Humberto "SilverOne" Carvalho @ 2018-07-25 20:34 UTC (permalink / raw)
To: qemu-devel
Hello,
Actually this is incorrect because cpu_get_icount() invokes
cpu_icount_to_ns later on. i apologize for the spam.
Best Regards,
Humberto "SilverOne" Carvalho
On Wed, Jul 25, 2018 at 8:25 PM Humberto "SilverOne" Carvalho <
silveronemi@gmail.com> wrote:
> Hello,
>
> When using icount with shift, virtual time is defined as icount << N.
> However, qemu_clock_get_ns simply returns cpu_get_icount, thereby returning
> icount instead of icount << N.
>
> If you check the qemu/util/qemu-timer.c file you will find the following
> function:
>
> 597: int64_t qemu_clock_get_ns(QEMUClockType type)
> 598: {
> ....
> 602: switch (type) {
> ....
> 606: case QEMU_CLOCK_VIRTUAL:
> 607: if (use_icount) {
> 608: return cpu_get_icount();
>
> Now on line 606, in case we requested QEMU_CLOCK_VIRTUAL, and we are using
> icount, the value of cpu_get_icount(); will be returned.
>
> However if I understand correctly, in order to convert icount to ns, you
> must take into account the icount shift -- as defined in the documentation:
> "The virtual cpu will execute one instruction every 2^N ns of virtual
> time.".
>
> Therefor, the correct value to return would be
> cpu_icount_to_ns(cpu_get_icount()), where cpu_icount_to_ns is defined in
> cpus.c:
>
> 296: int64_t cpu_icount_to_ns(int64_t icount)
> 297: {
> 298: return icount << icount_time_shift;
> 299: }
>
> Best Regards,
> Humberto "SilverOne" Carvalho
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-07-25 20:35 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-25 19:25 [Qemu-devel] qemu_clock_get_ns does not take into account icount_time_shift Humberto "SilverOne" Carvalho
2018-07-25 20:34 ` Humberto "SilverOne" Carvalho
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).