Re: Timer calculation for hypervisor
Stanislav Shwartsman <[email protected]> Sun, 17 Jul 2022 15:05:38 +0300
| Newsgroups | gmane.comp.emulators.bochs.devel |
|---|---|
| Message-ID | <CAAAheh3=MaHWJ_mcxvNmbZ179xYpDdez5bTR90Jq4R-GQxjibg@mail.gmail.com> |
--===============6554632626317160765== Content-Type: multipart/alternative; boundary="00000000000075885405e3ff1220" --00000000000075885405e3ff1220 Content-Type: text/plain; charset="UTF-8" You want to be tickn as big as you can. But not sure you know how big it can be. Sometimes when you have no external events expected - you may VMEXIT and call tickn after 100M instructions. But sometimes events emerge during the instructions themselves, like store actually wrote to APIC ICR and caused IPI - you need to be able to handle it within reasonable time. If you delay the VMEXIT and tickn you may break your guest. But I cannot tell what are the conditions for breaking/not breaking the guest ... Stanislav On Sun, Jul 17, 2022 at 12:57 PM nick <[email protected]> wrote: > Hi, > > Thanks for the reply. My couple of nanoseconds is 0x3000(vmx timer) and > then i call `bx_pc_system.tickn(0x3000)`. Initially my thought process > behind this is that the minimum timer(excluding hpet vdev) is around > 0x3000, so instead doing a vm exit after every instruction and call the > bochs tickn(), I thought it would be faster to do it for a minimum event > needed time. I noticed that if I change the vmx timer to `100` and the > tickn to a big number like `1000000` the execution is way faster. So I > am trying to figure out what would be the fastest execution. Are you > suggesting that I should call tick1() after every executed guest > instruction? I thought that there should be a way based on my host cpu > to calculate the right timer values. > > Thanks, > > On 7/17/2022 7:37 AM, [email protected] wrote: > > Couple of nanoseconds might be several execution cycles on your host. > > Single cache miss with DRAM access is ~10ns. > > How much is your "couple"? > > > > In general Bochs is trying to be as reproducible as possible and > therefore its time is defined according to x86 instructions execution. > > 1 tick = 1 instructions. > > For rep string flows 1 tick = 1 iteration of the repeat. > > This models machine with exactly 1 IPC > > > > -----Original Message----- > > From: nick <[email protected]> > > Sent: Sunday, 17 July 2022 2:21 > > To: [email protected] > > Subject: [Bochs-developers] Timer calculation for hypervisor > > > > Greetings, > > > > I am doing a fun project, where I am replacing the cpu emulator of bochs > with a hypervisor(intel vmx). > > > > There are virtual devices, like the keyboard controller, that are using > a timer for certain events. > > > > The way I am handling it with the hypervisor is to use a vmx timer > exit(VMX-preemption timer) every couple nanoseconds and then handle it in > bochs by calling `bx_pc_system.tickn(timer)`. > > > > I noticed that there is a significant execution delay based on the value > of the timers. I was wondering what is the right way to calculate the timer > for the fastest execution(both the VMX and the value in bochs). > > > > My cpu is `i7-6700K CPU @ 4.00GHz` if that somehow helps with the > calculation. > > > > Thank you, > > > > > > > > > > > > _______________________________________________ > > bochs-developers mailing list > > [email protected] > > https://lists.sourceforge.net/lists/listinfo/bochs-developers > > > --00000000000075885405e3ff1220 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">You want to be tickn as big as you can.<div>But not sure y= ou know how big it can be.</div><div>Sometimes when you have no external ev= ents expected - you may VMEXIT and call tickn=C2=A0after 100M instructions.= </div><div>But sometimes events emerge during=C2=A0the instructions themsel= ves, like store actually wrote to APIC ICR and caused IPI - you need to be = able to handle it within reasonable time.</div><div>If you delay the VMEXIT= and tickn=C2=A0you may break your guest. But I cannot tell what are the co= nditions for breaking/not breaking the guest ...</div><div><br></div><div>S= tanislav</div><div><br><div><br></div></div></div><br><div class=3D"gmail_q= uote"><div dir=3D"ltr" class=3D"gmail_attr">On Sun, Jul 17, 2022 at 12:57 P= M nick <<a href=3D"mailto:[email protected]">stixoima.codebomb= @gmail.com</a>> wrote:<br></div><blockquote class=3D"gmail_quote" style= =3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding= -left:1ex">Hi,<br> <br> Thanks for the reply. My couple of nanoseconds is 0x3000(vmx timer) and <br= > then i call `bx_pc_system.tickn(0x3000)`. Initially my thought process <br> behind this is that the minimum timer(excluding hpet vdev) is around <br> 0x3000, so instead doing a vm exit after every instruction and call the <br= > bochs tickn(), I thought it would be faster to do it for a minimum event <b= r> needed time. I noticed that if I change the vmx timer to `100` and the <br> tickn to a big number like `1000000` the execution is way faster. So I <br> am trying to figure out what would be the fastest execution. Are you <br> suggesting that I should call tick1() after every executed guest <br> instruction? I thought that there should be a way based on my host cpu <br> to calculate the right timer values.<br> <br> Thanks,<br> <br> On 7/17/2022 7:37 AM, <a href=3D"mailto:[email protected]" target=3D"_blan= k">[email protected]</a> wrote:<br> > Couple of nanoseconds might be several execution cycles on your host.<= br> > Single cache miss with DRAM access is ~10ns.<br> > How much is your "couple"?<br> ><br> > In general Bochs is trying to be as reproducible as possible and there= fore its time is defined according to x86 instructions execution.<br> > 1 tick =3D 1 instructions.<br> > For rep string flows 1 tick =3D 1 iteration of the repeat.<br> > This models machine with exactly 1 IPC<br> ><br> > -----Original Message-----<br> > From: nick <<a href=3D"mailto:[email protected]" target= =3D"_blank">[email protected]</a>><br> > Sent: Sunday, 17 July 2022 2:21<br> > To: <a href=3D"mailto:[email protected]" target= =3D"_blank">[email protected]</a><br> > Subject: [Bochs-developers] Timer calculation for hypervisor<br> ><br> > Greetings,<br> ><br> > I am doing a fun project, where I am replacing the cpu emulator of boc= hs with a hypervisor(intel vmx).<br> ><br> > There are virtual devices, like the keyboard controller, that are usin= g a timer for certain events.<br> ><br> > The way I am handling it with the hypervisor is to use a vmx timer exi= t(VMX-preemption timer) every couple nanoseconds and then handle it in boch= s by calling `bx_pc_system.tickn(timer)`.<br> ><br> > I noticed that there is a significant execution delay based on the val= ue of the timers. I was wondering what is the right way to calculate the ti= mer for the fastest execution(both the VMX and the value in bochs).<br> ><br> > My cpu is `i7-6700K CPU @ 4.00GHz` if that somehow helps with the calc= ulation.<br> ><br> > Thank you,<br> ><br> ><br> ><br> ><br> ><br> > _______________________________________________<br> > bochs-developers mailing list<br> > <a href=3D"mailto:[email protected]" target=3D"_b= lank">[email protected]</a><br> > <a href=3D"https://lists.sourceforge.net/lists/listinfo/bochs-develope= rs" rel=3D"noreferrer" target=3D"_blank">https://lists.sourceforge.net/list= s/listinfo/bochs-developers</a><br> ><br> </blockquote></div> --00000000000075885405e3ff1220-- --===============6554632626317160765== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --===============6554632626317160765== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ bochs-developers mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/bochs-developers --===============6554632626317160765==--