Prevent one cause of "MP-BIOS bug: 8254 timer"... message from linux
v2 cover Prevent one cause of "MP-BIOS bug: 8254 timer"... message from linux
Changes v1 to v2:
Drop the patch "hpet: Act more like real hardware" from v1 for several reasons:
1) Only "fixes" less then 50% of the problem: diff < 0 or diff > too many periods.
2) I have a better fix in #2 "hvm/hpet: Only call guest_time_hpet(h) one time per action."
3) Reverts a previous bug fix.
So all these patches are new and fix various bugs.
#1 "hvm/hpet: Add manual unit test code.":
Is optional. I used it to validate the changes did what I expected.
v1: info that still applies
Based on the proposed fix in QEMU:
http://marc.info/?l=qemu-devel&m=139304386331192&w=2
That was provided for:
http://marc.info/?l=qemu-devel&m=139295851107140&w=2
Which is very close to a bug I have been looking into and asked some questions about in:
http://lists.xen.org/archives/html/xen-devel/2014-02/msg01787.html
Don Slutz (10):
hvm/hpet: Add manual unit test code.
hvm/hpet: Only call guest_time_hpet(h) one time per action. hvm/hpet: Only set comparator or period not both. hvm/hpet: In hpet_save, correctly compute mc64. hvm/hpet: Init comparator64 like comparator.
hvm/hpet: comparator can only change when master clock is enabled. hvm/hpet: Call hpet_get_comparator during hpet_save. hvm/hpet: Prevent master clock equal to comparator while enabled hvm/hpet: Correctly limit period to a maximum. hvm/hpet: handle 1st period special
tools/tests/vhpet/.gitignore | 4 + tools/tests/vhpet/emul.h | 405 +++++++++++++++++++++++++++++++ tools/tests/vhpet/main.c | 541 ++++++++++++++++++++++++++++++++++++++++++ xen/arch/x86/hvm/hpet.c | 161 ++++++++++--- xen/include/asm-x86/hvm/vpt.h | 2 + 5 files changed, 1074 insertions(+), 39 deletions(-) create mode 100644 tools/tests/vhpet/.gitignore create mode 100644 tools/tests/vhpet/emul.h create mode 100644 tools/tests/vhpet/main.c
Signature · 1 line
1.8.4
PATCH v2 1/10 hvm/hpet: Add manual unit test code.
Add the code at tools/tests/vhpet.
Does repro the bug:
..MP-BIOS bug: 8254 timer not connected to IO-APIC
--- tools/tests/vhpet/.gitignore | 4 + tools/tests/vhpet/emul.h | 405 ++++++++++++++++++++++++++++++++ tools/tests/vhpet/main.c | 541 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 950 insertions(+) create mode 100644 tools/tests/vhpet/.gitignore create mode 100644 tools/tests/vhpet/emul.h create mode 100644 tools/tests/vhpet/main.c
tools/tests/vhpet/.gitignore new file +4 -0
@@ -0,0 +1,4 @@ +test_vhpet +hpet.h +hpet.c +foo
tools/tests/vhpet/emul.h new file +405 -0
405 lines not on this page · raw message
tools/tests/vhpet/main.c new file +541 -0
541 lines not on this page · raw message
Signature · 1 line
1.8.4
Re: [PATCH v2 01/10] hvm/hpet: Add manual unit test code.
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 16:24, <[email protected]> wrote:
Add the code at
tools/tests/vhpet.Does repro the bug:
Quoted 7 lines
..MP-BIOS bug: 8254 timer not connected to IO-APIC
Signed-off-by Don Slutz <[email protected]>--- tools/tests/vhpet/.gitignore | 4 + tools/tests/vhpet/emul.h | 405 ++++++++++++++++++++++++++++++++ tools/tests/vhpet/main.c | 541 +++++++++++++++++++++++++++++++++++++++++++
So I'm having difficulty understanding what this is good for, or how it is supposed to be used: You don't add or change any Makefile, and don't say anything to explain how this code is reproducing the bug you mention above. Please be a little more verbose.
Jan
Re: [PATCH v2 01/10] hvm/hpet: Add manual unit test code.
Quoted 12 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 16:24, <[email protected]> wrote:
Add the code at
tools/tests/vhpet.Does repro the bug:
Quoted 7 lines
..MP-BIOS bug: 8254 timer not connected to IO-APIC
Signed-off-by Don Slutz <[email protected]>--- tools/tests/vhpet/.gitignore | 4 + tools/tests/vhpet/emul.h | 405 ++++++++++++++++++++++++++++++++ tools/tests/vhpet/main.c | 541 +++++++++++++++++++++++++++++++++++++++++++
Quoted 7 lines
So I'm having difficulty understanding what this is good for, or how it is supposed to be used: You don't add or change any
Makefile, and don't say anything to explain how this code is reproducing the bug you mention above. Please be a little more verbose.Jan
Ok.
In a xen source tree (with this patch applied):
cd tools/tests/vhpet
xen_source=../../..
sed -e "/#include/d" -e "1i#include \"emul.h\"\n" <$xen_source/xen/arch/x86/hvm/hpet.c >hpet.c cp $xen_source/xen/include/asm-x86/hpet.h .
gcc -g -o test_vhpet hpet.c main.c
./test_vhpet >foo
Most of this is in main.c's comment. Will add to commit message also.
-Don Slutz
Re: [PATCH v2 01/10] hvm/hpet: Add manual unit test code.
Quoted 21 lines
Quoted 1 line
Quoted 1 line · On 09.04.14 at 20:35, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 16:24, <[email protected]> wrote:
Add the code at
tools/tests/vhpet.Does repro the bug:
Quoted 7 lines
..MP-BIOS bug: 8254 timer not connected to IO-APIC
Signed-off-by Don Slutz <[email protected]>--- tools/tests/vhpet/.gitignore | 4 + tools/tests/vhpet/emul.h | 405 ++++++++++++++++++++++++++++++++ tools/tests/vhpet/main.c | 541 +++++++++++++++++++++++++++++++++++++++++++Quoted 4 lines
So I'm having difficulty understanding what this is good for, or how it is supposed to be used: You don't add or change any
Makefile, and don't say anything to explain how this code is reproducing the bug you mention above. Please be a little more verbose.In a xen source tree (with this patch applied):
Quoted 7 lines
cd tools/tests/vhpet xen_source=../../.. sed -e "/#include/d" -e "1i#include \"emul.h\"\n" <$xen_source/xen/arch/x86/hvm/hpet.c >hpet.c cp $xen_source/xen/include/asm-x86/hpet.h . gcc -g -o test_vhpet hpet.c main.c
At least up to here this clearly should be in a Makefile, just like e.g. done for the x86 instruction emulator test.
Quoted 4 lines
./test_vhpet >foo
Most of this is in main.c's comment. Will add to commit message also.
Just referring to the comments there would be enough I guess. But I'm still struggling to see how this would reproduce the Linux side issue, and not just some random problem manifesting in similar symptoms.
Jan
Re: [PATCH v2 01/10] hvm/hpet: Add manual unit test code.
Quoted 6 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 09.04.14 at 20:35,<[email protected]> wrote:
In a xen source tree (with this patch applied):
cd
tools/tests/vhpet
Quoted 7 lines
Quoted 5 lines
xen_source=../../.. sed -e "/#include/d" -e "1i#include \"emul.h\"\n" <$xen_source/xen/arch/x86/hvm/hpet.c >hpet.c cp $xen_source/xen/include/asm-x86/hpet.h . gcc -g -o test_vhpet hpet.c main.cAt least up to here this clearly should be in a
Makefile, just like e.g. done for the x86 instruction emulator test.
Opps, I just noticed that the "optional" got dropped. I had not planned on this being required to get these patches applied. I have not found a simple way to use git-format-patch and have just 1 subject different.
Will work on using a makefile. I will be happy to make this into a much better test case. Since that will not happen quickly, it make sense to me to drop just this 1 patch and start a new set that includes it.
I have no real clue on how to get it to be part of "normal" testing.
This is because "make test" gives me:
...
building 'checkpoint' extension
gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I../../tools/include -I../../tools/libxc -I../../tools/xenstore -I/usr/include/python2.7 -c xen/lowlevel/checkpoint/checkpoint.c -o build/temp.linux-x86_64-2.7/xen/lowlevel/checkpoint/checkpoint.o -fno-strict-aliasing -Werror gcc -pthread -fno-strict-aliasing -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic -D_GNU_SOURCE -fPIC -fwrapv -fPIC -I../../tools/include -I../../tools/libxc -I../../tools/xenstore -I/usr/include/python2.7 -c xen/lowlevel/checkpoint/libcheckpoint.c -o build/temp.linux-x86_64-2.7/xen/lowlevel/checkpoint/libcheckpoint.o -fno-strict-aliasing -Werror xen/lowlevel/checkpoint/libcheckpoint.c: In function 'stop_suspend_thread':xen/lowlevel/checkpoint/libcheckpoint.c:842:7: error: variable 'err' set but not used [-Werror=unused-but-set-variable]
cc1: all warnings being treated as errors
error: command 'gcc' failed with exit status 1
Build failed 0x100
make[1]: *** [test] Error 1
make[1]: Leaving directory `/home/don/xen/tools/python'
make: *** [test] Error 2
dcs-xen-54:~/xen>make tests
make: *** No rule to make target `tests'. Stop.
dcs-xen-54:~/xen>make check
make: *** No rule to make target `check'. Stop.
dcs-xen-54:~/xen>e Makefile
dcs-xen-54:~/xen>make -C tools test
make: Entering directory `/home/don/xen/tools'
make: *** No rule to make target `test'. Stop.
make: Leaving directory `/home/don/xen/tools'
And 4.3.1 on CentOS 5.10:
...
======================================================================
ERROR: Invalid Test (xen.xm.tests.test_create)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test.py", line 634, in get_suite
mod = package_import(modname)
File "test.py", line 608, in package_import
mod = __import__(modname)
File
"/home/don/xen-4.3.1/tools/python/build/lib.linux-x86_64-2.4/xen/xm/tests/test_create.py", line 6, in ?
import xen.xend.XendOptions
File
"/home/don/xen-4.3.1/tools/python/build/lib.linux-x86_64-2.4/xen/xend/XendOptions.py", line 35, in ?
from xen.util import auxbin
File
"/home/don/xen-4.3.1/tools/python/build/lib.linux-x86_64-2.4/xen/util/auxbin.py", line 22, in ?
from xen.util.path import *
ImportError: No module named path
----------------------------------------------------------------------
Ran 5 tests in 0.048s
FAILED (errors=3)
make[1]: Leaving directory `/home/don/xen-4.3.1/tools/python'
Quoted 8 lines
Quoted 4 lines
./test_vhpet >foo
Most of this is in main.c's comment. Will add to commit message also.
Just referring to the comments there would be enough I guess. But I'm still struggling to see how this would reproduce the Linux side issue, and not just some random problem manifesting in similar symptoms.
I will attempt to answer this.
During my looking for what was happening, I added debug code that would allow me to force "diff" to selected values. This was how I found out that "-diff > HPET_TINY_TIME_SPAN" would cause linux to report this and crash. On closer looking into this, I was able to determine that the use extInt path would also fail even if I got xen to provide this interrupt. The reason being that
(uint32_t)(-HPET_TINY_TIME_SPAN-1)
Sets the "delta" (ns) to more then 60 seconds in the future. And the timer test happens in the 1st 5 seconds of a linux boot on my test server.
So I send out the v1 patch.
Later I found out that any value that is > ~3 seconds would also cause a linux crash even if xen is changed to provide extInt interrupts. (And you said in:
http://lists.xen.org/archives/html/xen-devel/2014-02/msg01857.html
But in the end I think you're barking up the wrong tree: All of this code would be of no interest at all if Linux didn't for some reason go into that fallback code. And with that fallback code existing mainly (if not exclusively) to deal with (half-)broken hardware/firmware, we should really make sure our emulation isn't broken (i.e. the fallback never being made use of). So finding the "TBD reason" is what is really needed.
(This e-mail also has the way I was able to get xen to "handle" extInt. and so far this "adjustment" to xen is not ready to be posted as a fix; including a good reason to add the code.)
This caused me to send lots of time reading the hpet spec and hopefully understanding most of it. At the same time (and while waiting for a longer running test of Windows Vista) I would add additional debug output and trace output along with changes. The the turn around time was slow enough that it made sense to me to take the code and run it standalone.
This is what this code does. It allows you to use an almost unmodified copy of hpet.c in a stand alone mode that needs nothing else from the xen source tree nor even have xen installed.
Also during the long test time I noticed that using xen-hvmctx the output of cmp was not changing, but master clock was. This is what leads me to patch #7:
hvm/hpet: Call hpet_get_comparator during hpet_save.
Which is not needed do to the way hpet_get_comparator() works until patch #10:
hvm/hpet: handle 1st period special
Which will not work correctly without patch #7.
Also during the long time run I found out using "xentrace: Add TRC_HVM_EMUL" (at the testing time it was TRC_HW_VCHIP, but that is mostly a rename) and some hvm_debug code I had added showed that the delta between guest_time_hpet() was offten ~200. However I would some times get much larger values.
I also found out that linux expects that "delta" should be "period".
This was the key to finding the issue that patch #3:
hvm/hpet: Only set comparator or period not both
Fixes. However since the spec says that "delta" can be any relation to "period"; using what linux wanted ("delta" should never be greater then "period") would be a bad change.
Since the server that would report:
..MP-BIOS bug: 8254 timer..
Stopped doing this, and we were unable to reproduce this anywhere else; the best I could do was guess that some how the delta between the 2 calls to guest_time_hpet() in:
tn_cmp = hpet_get_comparator(h, tn);
cur_tick = hpet_read_maincounter(h);Would be a possible cause. It was not until patches #2 to #9 had been coded and tested and I was still looking for a good way to do patch #10 (most of my attempts would break something else) was I able to find the right set of conditions to get the test code to report on a bad "delta".
I am not sure at what time I noticed patch #9:
hvm/hpet: Correctly limit period to a maximum.
This patch set order is not in the order of issues found. Just one that makes sense to me and was easy to separate into only 1 change per patch.
-Don Slutz
Quoted 2 lines
Jan
Re: [PATCH v2 01/10] hvm/hpet: Add manual unit test code.
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 11.04.14 at 04:53, <[email protected]> wrote:
This is because "make test" gives me:
I don't think you need to be worried about this failing - just make sure "make -C .../tools/tests/hpet" works, and ideally (again just like the x86 emulator one) also have a "run" target in the Makefile.
Quoted 13 lines
During my looking for what was happening, I added debug code that would allow me to force "diff" to selected values. This was how I found out that "-diff >
HPET_TINY_TIME_SPAN" would cause linux to report this and crash. On closer looking into this, I was able to determine that the use extInt path would also fail even if I got xen to provide this interrupt. The reason being that(uint32_t)(-HPET_TINY_TIME_SPAN-1)
Sets the "delta" (ns) to more then 60 seconds in the future. And the timer test happens in the 1st 5 seconds of a linux boot on my test server.
Quoted 5 lines
So I send out the v1 patch.
Later I found out that any value that is > ~3 seconds would also cause a linux crash even if xen is changed to provide extInt interrupts.
But Linux expectations shouldn't matter in this discussion at all, except for verifying that changes don't break things. I.e. any change you propose should be explained comparing with real hardware behavior, not with what Linux (or Windows, or ...) expect. OS expectation should become a reason for a change only if there is something that we absolutely can't make behave hardware like.
Jan
Re: [PATCH optional v2 01/10] hvm/hpet: Add manual unit test code.
Quoted 5 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 11.04.14 at 04:53, <[email protected]> wrote:
This is because "make test" gives me:
I don't think you need to be worried about this failing - just make sure "make -C .../tools/tests/hpet" works, and ideally (again just like the x86 emulator one) also have a "run" target in the
Makefile.
I see that that test is not passing:
make -C tools/tests/x86_emulator run
...
Testing daa/das (all inputs)... skipped Testing movq %mm3,(%ecx)... okay Testing movq (%edx),%mm5... okay Testing movdqu %xmm2,(%ecx)... okay Testing movdqu (%edx),%xmm4... okay Testing vmovdqu %ymm2,(%ecx)... failed!
make: *** [run] Error 1
make: Leaving directory `/home/don/xen/tools/tests/x86_emulator'
But I will use it as a guide.
The code is still missing many checks. Including the fixes in later patches. Most of this checking is not simple to implement. Will add just a basic Makefile.
Quoted 18 lines
Quoted 13 lines
During my looking for what was happening, I added debug code that would allow me to force "diff" to selected values. This was how I found out that "-diff >
HPET_TINY_TIME_SPAN" would cause linux to report this and crash. On closer looking into this, I was able to determine that the use extInt path would also fail even if I got xen to provide this interrupt. The reason being that(uint32_t)(-HPET_TINY_TIME_SPAN-1)Sets the "delta" (ns) to more then 60 seconds in the future. And the timer test happens in the 1st 5 seconds of a linux boot on my test server.
Quoted 5 lines
So I send out the v1 patch.
Later I found out that any value that is > ~3 seconds would also cause a linux crash even if xen is changed to provide extInt interrupts.
Quoted 7 lines
But Linux expectations shouldn't matter in this discussion at all, except for verifying that changes don't break things. I.e. any change you propose should be explained comparing with real hardware behavior, not with what Linux (or Windows, or ...) expect. OS expectation should become a reason for a change only if there is something that we absolutely can't make behave hardware like.
I fully agree. That is why none of commit messages after #2 have anything about linux. And in #2 I do not think it is used as a Linux expectation.
From #2:
The software-developers-hpet-spec-1-0a.pdf does not say how long it takes after the main clock is enabled before the first change of the master clock. Therefore multiple calls to guest_time_hpet(h) are not needed. Since each timer is started by a loop, each ones start time will change on the multple calls. In the real hardware, there is not delta based on which timer.
Is what I think you are looking for.
-Don Slutz
Quoted 2 lines
Jan
Re: [PATCH optional v2 01/10] hvm/hpet: Add manual unit test code.
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 11.04.14 at 13:57, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 11.04.14 at 04:53, <[email protected]> wrote:
This is because "make test" gives me:
I don't think you need to be worried about this failing - just make sure "make -C .../tools/tests/hpet" works, and ideally (again just like the x86 emulator one) also have a "run" target in the
Makefile.I see that that test is not passing:
Quoted 8 lines
make -C
tools/tests/x86_emulatorrun
...Testing daa/das (all inputs)... skipped Testing movq %mm3,(%ecx)... okay Testing movq (%edx),%mm5... okay Testing movdqu %xmm2,(%ecx)... okay Testing movdqu (%edx),%xmm4... okay Testing vmovdqu %ymm2,(%ecx)... failed!
Odd - it worked the last time I tried. Was that perhaps on an AVX- incapable system?
Jan
Re: [PATCH optional v2 01/10] hvm/hpet: Add manual unit test code.
Quoted 12 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 11.04.14 at 13:57, <[email protected]> wrote:
I see that that test is not passing:
Quoted 8 lines
make -C
tools/tests/x86_emulatorrun
...Testing daa/das (all inputs)... skipped Testing movq %mm3,(%ecx)... okay Testing movq (%edx),%mm5... okay Testing movdqu %xmm2,(%ecx)... okay Testing movdqu (%edx),%xmm4... okay Testing vmovdqu %ymm2,(%ecx)... failed!
Quoted 2 lines
Odd - it worked the last time I tried. Was that perhaps on an AVX- incapable system?
Is avx from /proc/cpuinfo:
dcs-xen-54:~/xen>lscpu
Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian CPU(s): 8 On-line CPU(s) list: 0-7 Thread(s) per core: 2 Core(s) per socket: 4 Socket(s): 1 NUMA node(s): 1 Vendor ID: GenuineIntel CPU family: 6 Model: 42 Stepping: 7 CPU MHz: 2400.080 BogoMIPS: 4800.16 Hypervisor vendor: Xen Virtualization type: none L1d cache: 32K L1i cache: 32K L2 cache: 256K L3 cache: 8192K NUMA node0 CPU(s): 0-7
dcs-xen-54:~/xen>cat /proc/cpuinfo
processor : 0vendor_id : GenuineIntel
cpu family : 6
model : 42
model name : Intel(R) Xeon(R) CPU E31265L @ 2.40GHz
stepping : 7
microcode : 0x17
cpu MHz : 2400.080
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 0
cpu cores : 4
apicid : 0
initial apicid : 0
fpu : yesfpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu de tsc msr pae mce cx8 apic sep mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl nonstop_tsc eagerfpu pni pclmulqdq monitor est ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx hypervisor lahf_lm ida arat epb xsaveopt pln pts dtherm
bogomips : 4800.16
clflush size : 64cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
processor : 1vendor_id : GenuineIntel
cpu family : 6
model : 42
model name : Intel(R) Xeon(R) CPU E31265L @ 2.40GHz
stepping : 7
microcode : 0x17
cpu MHz : 2400.080
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 0
cpu cores : 4
apicid : 1
initial apicid : 1
fpu : yesfpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu de tsc msr pae mce cx8 apic sep mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl nonstop_tsc eagerfpu pni pclmulqdq monitor est ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx hypervisor lahf_lm ida arat epb xsaveopt pln pts dtherm
bogomips : 4800.16
clflush size : 64cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
processor : 2vendor_id : GenuineIntel
cpu family : 6
model : 42
model name : Intel(R) Xeon(R) CPU E31265L @ 2.40GHz
stepping : 7
microcode : 0x17
cpu MHz : 2400.080
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 1
cpu cores : 4
apicid : 2
initial apicid : 2
fpu : yesfpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu de tsc msr pae mce cx8 apic sep mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl nonstop_tsc eagerfpu pni pclmulqdq monitor est ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx hypervisor lahf_lm ida arat epb xsaveopt pln pts dtherm
bogomips : 4800.16
clflush size : 64cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
processor : 3vendor_id : GenuineIntel
cpu family : 6
model : 42
model name : Intel(R) Xeon(R) CPU E31265L @ 2.40GHz
stepping : 7
microcode : 0x17
cpu MHz : 2400.080
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 1
cpu cores : 4
apicid : 3
initial apicid : 3
fpu : yesfpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu de tsc msr pae mce cx8 apic sep mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl nonstop_tsc eagerfpu pni pclmulqdq monitor est ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx hypervisor lahf_lm ida arat epb xsaveopt pln pts dtherm
bogomips : 4800.16
clflush size : 64cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
processor : 4vendor_id : GenuineIntel
cpu family : 6
model : 42
model name : Intel(R) Xeon(R) CPU E31265L @ 2.40GHz
stepping : 7
microcode : 0x17
cpu MHz : 2400.080
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 2
cpu cores : 4
apicid : 4
initial apicid : 4
fpu : yesfpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu de tsc msr pae mce cx8 apic sep mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl nonstop_tsc eagerfpu pni pclmulqdq monitor est ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx hypervisor lahf_lm ida arat epb xsaveopt pln pts dtherm
bogomips : 4800.16
clflush size : 64cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
processor : 5vendor_id : GenuineIntel
cpu family : 6
model : 42
model name : Intel(R) Xeon(R) CPU E31265L @ 2.40GHz
stepping : 7
microcode : 0x17
cpu MHz : 2400.080
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 2
cpu cores : 4
apicid : 5
initial apicid : 5
fpu : yesfpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu de tsc msr pae mce cx8 apic sep mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl nonstop_tsc eagerfpu pni pclmulqdq monitor est ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx hypervisor lahf_lm ida arat epb xsaveopt pln pts dtherm
bogomips : 4800.16
clflush size : 64cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
processor : 6vendor_id : GenuineIntel
cpu family : 6
model : 42
model name : Intel(R) Xeon(R) CPU E31265L @ 2.40GHz
stepping : 7
microcode : 0x17
cpu MHz : 2400.080
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 3
cpu cores : 4
apicid : 6
initial apicid : 6
fpu : yesfpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu de tsc msr pae mce cx8 apic sep mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl nonstop_tsc eagerfpu pni pclmulqdq monitor est ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx hypervisor lahf_lm ida arat epb xsaveopt pln pts dtherm
bogomips : 4800.16
clflush size : 64cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
processor : 7vendor_id : GenuineIntel
cpu family : 6
model : 42
model name : Intel(R) Xeon(R) CPU E31265L @ 2.40GHz
stepping : 7
microcode : 0x17
cpu MHz : 2400.080
cache size : 8192 KB
physical id : 0
siblings : 8
core id : 3
cpu cores : 4
apicid : 7
initial apicid : 7
fpu : yesfpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu de tsc msr pae mce cx8 apic sep mca cmov pat clflush acpi mmx fxsr sse sse2 ss ht syscall nx lm constant_tsc rep_good nopl nonstop_tsc eagerfpu pni pclmulqdq monitor est ssse3 cx16 sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx hypervisor lahf_lm ida arat epb xsaveopt pln pts dtherm
bogomips : 4800.16
clflush size : 64cache_alignment : 64
address sizes : 36 bits physical, 48 bits virtual
power management:
-Don Slutz
Quoted 2 lines
Jan
Re: [PATCH optional v2 01/10] hvm/hpet: Add manual unit test code.
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 11.04.14 at 14:48, <[email protected]> wrote:
Quoted 12 lines · Jan Beulich
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 11.04.14 at 13:57, <[email protected]> wrote:
I see that that test is not passing:
make -C
tools/tests/x86_emulatorrun
...Testing daa/das (all inputs)... skipped Testing movq %mm3,(%ecx)... okay Testing movq (%edx),%mm5... okay Testing movdqu %xmm2,(%ecx)... okay Testing movdqu (%edx),%xmm4... okay Testing vmovdqu %ymm2,(%ecx)... failed!
Quoted 4 lines
Quoted 2 lines
Odd - it worked the last time I tried. Was that perhaps on an AVX- incapable system?
Is avx from
/proc/cpuinfo:
Interesting - I just tried it again, and it works for me. Could of course be an issue with your glibc clobbering %ymm2 - I always wondered for how long we would get away with this not really correct register usage. But otoh I would have expected the earlier test using %xmm2 to fail then too...
Jan
Re: [PATCH optional v2 01/10] hvm/hpet: Add manual unit test code.
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 11.04.14 at 14:48, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 11.04.14 at 13:57, <[email protected]> wrote:
I see that that test is not passing:
make -C
tools/tests/x86_emulatorrun
...Testing daa/das (all inputs)... skipped Testing movq %mm3,(%ecx)... okay Testing movq (%edx),%mm5... okay Testing movdqu %xmm2,(%ecx)... okay Testing movdqu (%edx),%xmm4... okay Testing vmovdqu %ymm2,(%ecx)... failed!
Quoted 8 lines
Quoted 3 lines
Quoted 2 lines
Odd - it worked the last time I tried. Was that perhaps on an AVX- incapable system?
Is avx from
/proc/cpuinfo:Interesting - I just tried it again, and it works for me. Could of course be an issue with your glibc clobbering %ymm2 - I always wondered for how long we would get away with this not really correct register usage. But otoh I would have expected the earlier test using %xmm2 to fail then too...
Not sure what I can do to help. A quick gdb says:
Testing movzxwd (%%eax),%%ecx... okay Testing xadd %%ax,(%%ecx)... okay Testing dec %%ax... okay Testing lea 8(%%ebp),%%eax... okay Testing daa/das (all inputs)... skipped Testing movq %mm3,(%ecx)... okay Testing movq (%edx),%mm5... okay
Breakpoint 4, main (argc=<optimized out>, argv=<optimized out>) at test_x86_emulator.c:610
610 if ( (rc != X86EMUL_OKAY) || memcmp(res, res + 8, 32) )
(gdb) p rc
$3 = 0
(gdb) c
Continuing.
Testing movdqu %xmm2,(%ecx)... okay
Testing movdqu (%edx),%xmm4... okay
Breakpoint 3, main (argc=<optimized out>, argv=<optimized out>) at test_x86_emulator.c:661
661 if ( (rc != X86EMUL_OKAY) || memcmp(res, res + 16, 64) )
(gdb) p rc
$4 = 7
(gdb) q
This is from 4.3.1...
-Don Slutz
Quoted 2 lines
Jan
Re: [PATCH optional v2 01/10] hvm/hpet: Add manual unit test code.
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 11.04.14 at 19:40, <[email protected]> wrote:
Testing movdqu %xmm2,(%ecx)... okay
Testing movdqu (%edx),%xmm4... okayBreakpoint 3, main (argc=<optimized out>, argv=<optimized out>) at test_x86_emulator.c:661
661 if ( (rc !=X86EMUL_OKAY) ||memcmp(res, res + 16, 64))
(gdb) p rc
$4 = 7
(gdb) q
I don't see how a return code of 7 could ever be observed here. But It's then apparently not the suspected XMM register clobbering.
Quoted 1 line
This is from 4.3.1...
I.e. not really meaningful if not proven to behave the same on -unstable. And anyway, if you're not up to debugging this, I don't think there's much we can do.
Jan
test_x86_emulator (was Re: [PATCH optional v2 01/10] hvm/hpet: Add manual unit test code.)
Quoted 4 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 11.04.14 at 19:40, <[email protected]> wrote:
Testing movdqu %xmm2,(%ecx)... okay
Testing movdqu (%edx),%xmm4... okay
Quoted 8 lines
Quoted 6 lines
Breakpoint 3, main (argc=<optimized out>, argv=<optimized out>) at test_x86_emulator.c:661
661 if ( (rc !=X86EMUL_OKAY) ||memcmp(res, res + 16, 64))
(gdb) p rc
$4 = 7
(gdb) qI don't see how a return code of 7 could ever be observed here. But It's then apparently not the suspected XMM register clobbering.
On ac0f56a + All these patches (which should not effect this)
It is more complex then it appears at 1st look.
-O1:
...
Testing movdqu (%edx),%xmm4... okay Testing vmovdqu %ymm2,(%ecx)... skipped Testing vmovdqu (%edx),%ymm4... skipped Testing movsd %xmm5,(%ecx)... okay Testing movaps (%edx),%xmm7... okay
...
-O2:
...
Testing movdqu (%edx),%xmm4... okay
Testing vmovdqu %ymm2,(%ecx)... failed!
make: *** [run] Error 1
How I got here:
...
Testing movq (%edx),%mm5... okay Testing movdqu %xmm2,(%ecx)... okay Testing movdqu (%edx),%xmm4... okay
Breakpoint 1, main (argc=<optimized out>, argv=<optimized out>) at test_x86_emulator.c:702
702 printf("%-40s", "Testing vmovdqu %ymm2,(%ecx)...");
(gdb) c
Continuing.
Breakpoint 3, x86_emulate (ctxt=ctxt@entry=0x7fffffffdb80, ops=ops@entry=0x6152a0 <emulops>)
at x86_emulate/x86_emulate.c:4164
4164 get_fpu(X86EMUL_FPU_ymm, &fic);
(gdb) p rc
$2 = 0
(gdb) sget_fpu (exception_callback=0x402a60 <fpu_handle_exception>, exception_callback_arg=0x7fffffffd7d0,
type=X86EMUL_FPU_ymm, ctxt=0x7fffffffdb80) at test_x86_emulator.c:138
138 switch ( type )
(gdb) n
137 {
(gdb)
138 switch ( type )
(gdb)
154 return X86EMUL_OKAY;
(gdb)
138 switch ( type )
(gdb)
152 return X86EMUL_UNHANDLEABLE;
(gdb)
138 switch ( type )
(gdb)
132 int get_fpu(
(gdb)
155 }
(gdb)x86_emulate (ctxt=ctxt@entry=0x7fffffffdb80, ops=ops@entry=0x6152a0 <emulops>) at x86_emulate/x86_emulate.c:4525
4525 }
(gdb)
main (argc=<optimized out>, argv=<optimized out>) at test_x86_emulator.c:719
719 if ( (rc != X86EMUL_OKAY) || memcmp(res, res + 16, 64) )
(gdb)
934 printf("failed!\n");
And so I tried at the lower -O1, and "it works".
Quoted 4 lines
Quoted 1 line
This is from 4.3.1...
I.e. not really meaningful if not proven to behave the same on -unstable. And anyway, if you're not up to debugging this, I don't think there's much we can do.
Since I know almost nothing about both AVX instructions and x86_emulate, it is hard for me to quickly help.
-Don Slutz
Quoted 2 lines
Jan
Re: test_x86_emulator
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 14.04.14 at 19:29, <[email protected]> wrote:
It is more complex then it appears at 1st look.
-O1:
...Testing movdqu (%edx),%xmm4... okay Testing vmovdqu %ymm2,(%ecx)... skipped Testing vmovdqu (%edx),%ymm4... skipped Testing movsd %xmm5,(%ecx)... okay Testing movaps (%edx),%xmm7... okay
Quoted 7 lines
...
-O2:
...
Testing movdqu (%edx),%xmm4... okay
Testing vmovdqu %ymm2,(%ecx)... failed!
make: *** [run] Error 1
Now that's of course very interesting - looks more like a problem with test_x86_emulator.c's use of CPUID then (because you said you do this on an AVX-capable system, the -O1 test shouldn't skip these).
Quoted 12 lines
get_fpu(exception_callback=0x402a60 <fpu_handle_exception>, exception_callback_arg=0x7fffffffd7d0,type=X86EMUL_FPU_ymm, ctxt=0x7fffffffdb80) at test_x86_emulator.c:138138 switch ( type )
(gdb) n
137 {
(gdb)
138 switch ( type )
(gdb)
154 returnX86EMUL_OKAY;
(gdb)
138 switch ( type )
Quoted 8 lines
(gdb)
152 returnX86EMUL_UNHANDLEABLE;
(gdb)
138 switch ( type )
(gdb)
132 int get_fpu(
(gdb)
155 }
Or a code generation problem: An input of X86EMUL_FPU_ymm should obviously result in execution making to the respective case statement, yet the steps above lead directly to the default one.
What gcc version are you using? And could you perhaps make both binaries (-O1 and -O2) available for inspection?
Jan
Re: test_x86_emulator
Quoted 42 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 14.04.14 at 19:29, <[email protected]> wrote:
It is more complex then it appears at 1st look.
-O1:
...Testing movdqu (%edx),%xmm4... okay Testing vmovdqu %ymm2,(%ecx)... skipped Testing vmovdqu (%edx),%ymm4... skipped Testing movsd %xmm5,(%ecx)... okay Testing movaps (%edx),%xmm7... okayQuoted 7 lines
...
-O2:
...
Testing movdqu (%edx),%xmm4... okay
Testing vmovdqu %ymm2,(%ecx)... failed!
make: *** [run] Error 1Now that's of course very interesting - looks more like a problem with test_x86_emulator.c's use of CPUID then (because you said you do this on an AVX-capable system, the -O1 test shouldn't skip these).
Quoted 12 lines
get_fpu(exception_callback=0x402a60 <fpu_handle_exception>, exception_callback_arg=0x7fffffffd7d0,type=X86EMUL_FPU_ymm, ctxt=0x7fffffffdb80) at test_x86_emulator.c:138138 switch ( type )
(gdb) n
137 {
(gdb)
138 switch ( type )
(gdb)
154 returnX86EMUL_OKAY;
(gdb)
138 switch ( type )Quoted 8 lines
(gdb)
152 returnX86EMUL_UNHANDLEABLE;
(gdb)
138 switch ( type )
(gdb)
132 int get_fpu(
(gdb)
155 }
Quoted 6 lines
Or a code generation problem: An input of
X86EMUL_FPU_ymmshould obviously result in execution making to the respective case statement, yet the steps above lead directly to the default one.What gcc version are you using? And could you perhaps make both binaries (-O1 and -O2) available for inspection?
dcs-xen-54:~/xen/tools/tests/x86_emulator>gcc --version gcc (GCC) 4.7.2 20120921 (Red Hat 4.7.2-2)
Attached are the binaries.
-Don Slutz
Quoted 2 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Re: test_x86_emulator
Quoted 3 lines
Quoted 3 lines
Quoted 1 line · On 15.04.14 at 16:24, <[email protected]> wrote:
What gcc version are you using? And could you perhaps make both binaries (-O1 and -O2) available for inspection?
So it's indeed a compiler version difference, with both us and them not being fully correct. The patch below should make things work.
Jan
x86: fix instruction emulator test's xgetbv constraints
The "A" constraint, while documented up to gcc 4.5 as "The a and d registers, as a pair (for instructions that return half the result in one and half in the other)," never really behaved that (natural) way, but always meant (and is now also documented so) %eax _or_ %edx (%rax _or_ %rdx on x86-64) unless the operand was wide enough to require both (i.e. more than 32 bits on ix86 and more than 64 bits on x86-64).
Interestingly something internal to the compiler changed between 4.4 and 4.5 to actually expose the difference - up to gcc 4.4 I was unable to construct a case where, when only the low half of the result is actually looked at, the result would be considered to be in %edx/%rdx (and %eax/%rax would be treated as unmodified by the instruction).
tools/tests/x86_emulator/test_x86_emulator.c +3 -3
@@ -102,11 +102,11 @@ static int cpuid(static inline uint64_t xgetbv (uint32_t xcr) { -uint64_t res; +uint32_t lo, hi; - asm (".byte 0x0f, 0x01, 0xd0" :"=A" (res) :"c" (xcr) ); + asm (".byte 0x0f, 0x01, 0xd0" :"=a" (lo),"=d" (hi) :"c" (xcr) ); -return res; +return ((uint64_t )hi <<32 ) | lo; }#define cpu_has_avx ({ \
x86: fix instruction emulator test's xgetbv constraints
The "A" constraint, while documented up to gcc 4.5 as "The a and d registers, as a pair (for instructions that return half the result in one and half in the other)," never really behaved that (natural) way, but always meant (and is now also documented so) %eax _or_ %edx (%rax _or_ %rdx on x86-64) unless the operand was wide enough to require both (i.e. more than 32 bits on ix86 and more than 64 bits on x86-64).
Interestingly something internal to the compiler changed between 4.4 and 4.5 to actually expose the difference - up to gcc 4.4 I was unable to construct a case where, when only the low half of the result is actually looked at, the result would be considered to be in %edx/%rdx (and %eax/%rax would be treated as unmodified by the instruction).
tools/tests/x86_emulator/test_x86_emulator.c +3 -3
@@ -102,11 +102,11 @@ static int cpuid(static inline uint64_t xgetbv (uint32_t xcr) { -uint64_t res; +uint32_t lo, hi; - asm (".byte 0x0f, 0x01, 0xd0" :"=A" (res) :"c" (xcr) ); + asm (".byte 0x0f, 0x01, 0xd0" :"=a" (lo),"=d" (hi) :"c" (xcr) ); -return res; +return ((uint64_t )hi <<32 ) | lo; }#define cpu_has_avx ({ \
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Keir Fraser
Acked-byRe: test_x86_emulator
Quoted 9 lines · Jan Beulich
x86: fix instruction emulator test's xgetbv constraints
The "A" constraint, while documented up to gcc4.5 as "The a and d registers, as a pair (for instructions that return half the result in one and half in the other)," never really behaved that (natural) way, but always meant (and is now also documented so) %eax_or_ %edx (%rax _or_ %rdx on x86-64) unless the operand was wide enough to require both (i.e. more than 32 bits on ix86 and more than 64 bits on x86-64).
Quoted 7 lines
Interestingly something internal to the compiler changed between4.4 and4.5 to actually expose the difference - up to gcc4.4 I was unable to construct a case where, when only the low half of the result is actually looked at, the result would be considered to be in %edx/%rdx (and %eax/%rax would be treated as unmodified by the instruction).
Signed-off-by Jan Beulich<[email protected]>
Don Slutz
Tested-byRe: test_x86_emulator
Quoted 16 lines · Keir Fraser
Quoted 15 lines · Jan Beulich
x86: fix instruction emulator test's xgetbv constraints
The "A" constraint, while documented up to gcc4.5 as "The a and d registers, as a pair (for instructions that return half the result in one and half in the other)," never really behaved that (natural) way, but always meant (and is now also documented so) %eax_or_ %edx (%rax _or_ %rdx on x86-64) unless the operand was wide enough to require both (i.e. more than 32 bits on ix86 and more than 64 bits on x86-64).
Interestingly something internal to the compiler changed between4.4 and4.5 to actually expose the difference - up to gcc4.4 I was unable to construct a case where, when only the low half of the result is actually looked at, the result would be considered to be in %edx/%rdx (and %eax/%rax would be treated as unmodified by the instruction).
Quoted 3 lines
Quoted 1 line
Signed-off-by Jan Beulich<[email protected]>Acked-by Keir Fraser <[email protected]>
And it works for me so:
-Don Slutz
PATCH v2 2/10 hvm/hpet: Only call guest_time_hpet(h) one time per action.
In reply to Don SlutzThis call is expensive and will cause extra time to pass.
The software-developers-hpet-spec-1-0a.pdf does not say how long it takes after the main clock is enabled before the first change of the master clock. Therefore multiple calls to guest_time_hpet(h) are not needed. Since each timer is started by a loop, each ones start time will change on the multple calls. In the real hardware, there is not delta based on which timer.
Without this change it is possible for an HVM guest running linux to get the message:
..MP-BIOS bug: 8254 timer not connected to IO-APIC
On the guest console(s); and the guest will panic.
Also Xen hypervisor console with be flooded with:
vioapic.c:352:d1 Unsupported delivery mode 7
vioapic.c:352:d1 Unsupported delivery mode 7
vioapic.c:352:d1 Unsupported delivery mode 7
--- xen/arch/x86/hvm/hpet.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-)
xen/arch/x86/hvm/hpet.c +22 -12
@@ -73,17 +73,18 @@ ((timer_config (h, n) &HPET_TN_INT_ROUTE_CAP_MASK ) \ >> HPET_TN_INT_ROUTE_CAP_SHIFT) -static inline uint64_t hpet_read_maincounter (HPETState *h) +static inline uint64_t hpet_read_maincounter (HPETState *h,uint64_t guest_time) {ASSERT (spin_is_locked (&h->lock));if (hpet_enabled (h) ) -return guest_time_hpet (h) + h->mc_offset; +return guest_time + h->mc_offset;else return h->hpet.mc64; } -static uint64_t hpet_get_comparator (HPETState *h,unsigned int tn) +static uint64_t hpet_get_comparator (HPETState *h,unsigned int tn, +uint64_t guest_time) {uint64_t comparator;uint64_t elapsed;
@@ -95,7 +96,8 @@ static uint64_t hpet_get_comparator(HPETState *h, unsigned int tn)uint64_t period = h->hpet.period[tn];if (period) { - elapsed =hpet_read_maincounter (h) + period -1 - comparator; + elapsed =hpet_read_maincounter (h, guest_time) + + period -1 - comparator; comparator += (elapsed / period) * period; h->hpet.comparator64[tn] = comparator; }
@@ -120,7 +122,7 @@ static inline uint64_t hpet_read64(HPETState *h, unsigned long addr)case HPET_STATUS :return h->hpet.isr;case HPET_COUNTER : -return hpet_read_maincounter (h); +return hpet_read_maincounter (h,guest_time_hpet (h));case HPET_Tn_CFG (0 ):case HPET_Tn_CFG (1 ):case HPET_Tn_CFG (2 ):
@@ -128,7 +130,7 @@ static inline uint64_t hpet_read64(HPETState *h, unsigned long addr)case HPET_Tn_CMP (0 ):case HPET_Tn_CMP (1 ):case HPET_Tn_CMP (2 ): -return hpet_get_comparator (h,HPET_TN (CMP , addr)); +return hpet_get_comparator (h,HPET_TN (CMP , addr),guest_time_hpet (h));case HPET_Tn_ROUTE (0 ):case HPET_Tn_ROUTE (1 ):case HPET_Tn_ROUTE (2 ):
@@ -194,18 +196,19 @@ static void hpet_stop_timer(HPETState *h, unsigned int tn)destroy_periodic_time (&h->pt[tn]);/* read the comparator to get it updated so a read while stopped will * return the expected value. */ -hpet_get_comparator (h, tn); +hpet_get_comparator (h, tn,guest_time_hpet (h)); }/* the number of HPET tick that stands for * 1/(2^10) second, namely, 0.9765625 milliseconds */ #define HPET_TINY_TIME_SPAN ((h->stime_freq >> 10) / STIME_PER_HPET_TICK) -static void hpet_set_timer (HPETState *h,unsigned int tn) +static void hpet_set_timer (HPETState *h,unsigned int tn,int mc_starting) {uint64_t tn_cmp, cur_tick, diff;unsigned int irq;unsigned int oneshot; +uint64_t guest_time;ASSERT (tn <HPET_TIMER_NUM );ASSERT (spin_is_locked (&h->lock));
@@ -220,8 +223,13 @@ static void hpet_set_timer(HPETState *h, unsigned int tn)if ( !timer_enabled (h, tn) )return ; - tn_cmp =hpet_get_comparator (h, tn); - cur_tick =hpet_read_maincounter (h); +if ( mc_starting ) + guest_time = h->hpet.mc64 - h->mc_offset; +else + guest_time =guest_time_hpet (h); + + tn_cmp =hpet_get_comparator (h, tn, guest_time); + cur_tick =hpet_read_maincounter (h, guest_time);if (timer_is_32bit (h, tn) ) { tn_cmp = (uint32_t )tn_cmp;
@@ -283,6 +291,7 @@ static int hpet_write(#define set_stop_timer (n) (__set_bit((n), &stop_timers))#define set_start_timer (n) (__set_bit((n), &start_timers))#define set_restart_timer (n) (set_stop_timer(n),set_start_timer(n)) +int mc_starting =0 ; addr &=HPET_MMAP_SIZE -1 ;
@@ -307,6 +316,7 @@ static int hpet_write( {/* Enable main counter and interrupt generation. */ h->mc_offset = h->hpet.mc64 -guest_time_hpet (h); + mc_starting =1 ;for ( i =0 ; i <HPET_TIMER_NUM ; i++ ) { h->hpet.comparator64[i] =
@@ -441,7 +451,7 @@ static int hpet_write( { i =find_first_set_bit (start_timers);__clear_bit (i, &start_timers); -hpet_set_timer (h, i); +hpet_set_timer (h, i, mc_starting); }#undef set_stop_timer
@@ -562,7 +572,7 @@ static int hpet_load(struct domain *d, hvm_domain_context_t *h)if (hpet_enabled (hp) )for ( i =0 ; i <HPET_TIMER_NUM ; i++ )if (timer_enabled (hp, i) ) -hpet_set_timer (hp, i); +hpet_set_timer (hp, i,1 );spin_unlock (&hp->lock);
Signature · 1 line
1.8.4
Re: [PATCH v2 02/10] hvm/hpet: Only call guest_time_hpet(h) one time per action.
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 08.04.14 at 16:24, <[email protected]> wrote:
This looks good to me, just a minor comment:
xen/arch/x86/hvm/hpet.c static void hpet_stop_timer(HPETState *h, unsigned int tn) · line 206
Quoted 2 lines
xen/arch/x86/hvm/hpet.c +1
-1-static void hpet_set_timer (HPETState *h,unsigned int tn) +static void hpet_set_timer (HPETState *h,unsigned int tn,int mc_starting)
This as well as ...
xen/arch/x86/hvm/hpet.c static int hpet_write( · line 294
Quoted 5 lines
xen/arch/x86/hvm/hpet.c +1
-0@@ -283,6 +291,7 @@ static int hpet_write(#define set_stop_timer (n) (__set_bit((n), &stop_timers))#define set_start_timer (n) (__set_bit((n), &start_timers))#define set_restart_timer (n) (set_stop_timer(n),set_start_timer(n)) +int mc_starting =0 ;
... this wants to be bool_t. Or alternatively you might want to see whether just like in the other case you could pass guest_time in.
With that adjusted,
Jan
Re: [PATCH v2 02/10] hvm/hpet: Only call guest_time_hpet(h) one time per action.
Quoted 7 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 08.04.14 at 16:24, <[email protected]> wrote:
This looks good to me, just a minor comment:
xen/arch/x86/hvm/hpet.c static void hpet_stop_timer(HPETState *h, unsigned int tn) · line 206
Quoted 2 lines
xen/arch/x86/hvm/hpet.c +1
-1-static void hpet_set_timer (HPETState *h,unsigned int tn) +static void hpet_set_timer (HPETState *h,unsigned int tn,int mc_starting)This as well as ...
Quoted 7 lines
xen/arch/x86/hvm/hpet.c static int hpet_write( · line 294
Quoted 5 lines
xen/arch/x86/hvm/hpet.c +1
-0@@ -283,6 +291,7 @@ static int hpet_write(#define set_stop_timer (n) (__set_bit((n), &stop_timers))#define set_start_timer (n) (__set_bit((n), &start_timers))#define set_restart_timer (n) (set_stop_timer(n),set_start_timer(n)) +int mc_starting =0 ;... this wants to be
bool_t. Or alternatively you might want to see whether just like in the other case you could passguest_timein.
Will change to bool_t.
Quoted 2 lines
With that adjusted,
Reviewed-by Jan Beulich <[email protected]>
-Don Slutz
Quoted 2 lines
Jan
PATCH v2 3/10 hvm/hpet: Only set comparator or period not both.
In reply to Don SlutzThe current code sets both. If setting the comparator also set comparator64 (the hidden version).
Based on:
software-developers-hpet-spec-1-0a.pdf
A write call should only change comparator or period, not both.
--- xen/arch/x86/hvm/hpet.c | 58 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 20 deletions(-)
xen/arch/x86/hvm/hpet.c +38 -20
@@ -399,30 +399,48 @@ static int hpet_write( tn =HPET_TN (CMP , addr);if (timer_is_32bit (h, tn) ) new_val = (uint32_t )new_val; - h->hpet.timers[tn].cmp = new_val; -if ( h->hpet.timers[tn].config &HPET_TN_SETVAL ) -/* -* When SETVAL is one, software is able to "directly set a periodic -* timer's accumulator." That is, set the comparator without -* adjusting the period. Much the same as just setting the -* comparator on an enabled one-shot timer. -* -* This configuration bit clears when the comparator is written. -*/ - h->hpet.timers[tn].config &= ~HPET_TN_SETVAL ; -else if (timer_is_periodic (h, tn) ) +if (timer_is_periodic (h, tn) ) + { +if ( h->hpet.timers[tn].config &HPET_TN_SETVAL ) + { +/* +* When SETVAL is one, software is able to "directly +* set a periodic timer's accumulator." That is, +* set the comparator without adjusting the period. +* Much the same as just setting the comparator on +* an enabled one-shot timer. +* +* This configuration bit clears when the comparator +* is written. +*/ + h->hpet.timers[tn].config &= ~HPET_TN_SETVAL ; + h->hpet.timers[tn].cmp = new_val; + h->hpet.comparator64[tn] = new_val; + } +else + { +/* +* Clamp period to reasonable min/max values: +* - minimum is 100us, same as timers controlled by vpt.c +* - maximum is to prevent overflow in time_after() +* calculations +*/ +if (hpet_tick_to_ns (h, new_val) <MICROSECS (100 ) ) + new_val = (MICROSECS (100 ) <<10 ) / h->hpet_to_ns_scale; + new_val &= (timer_is_32bit (h, tn) ? ~0u : ~0ull ) >>1 ; + h->hpet.period[tn] = new_val; + } + } +else {/* -* Clamp period to reasonable min/max values: -* - minimum is 100us, same as timers controlled by vpt.c -* - maximum is to prevent overflow in time_after() calculations +* The spec says "do not use", but clear if specified. */ -if (hpet_tick_to_ns (h, new_val) <MICROSECS (100 ) ) - new_val = (MICROSECS (100 ) <<10 ) / h->hpet_to_ns_scale; - new_val &= (timer_is_32bit (h, tn) ? ~0u : ~0ull ) >>1 ; - h->hpet.period[tn] = new_val; +if ( h->hpet.timers[tn].config &HPET_TN_SETVAL ) + h->hpet.timers[tn].config &= ~HPET_TN_SETVAL ; + h->hpet.timers[tn].cmp = new_val; + h->hpet.comparator64[tn] = new_val; } - h->hpet.comparator64[tn] = new_val;if (hpet_enabled (h) &&timer_enabled (h, tn) )set_restart_timer (tn);break ;
Signature · 1 line
1.8.4
Re: [PATCH v2 03/10] hvm/hpet: Only set comparator or period not both.
Quoted 37 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 16:24, <[email protected]> wrote:
xen/arch/x86/hvm/hpet.c +33
-1+if (timer_is_periodic (h, tn) ) + { +if ( h->hpet.timers[tn].config &HPET_TN_SETVAL ) + { +/* +* When SETVAL is one, software is able to "directly +* set a periodic timer's accumulator." That is, +* set the comparator without adjusting the period. +* Much the same as just setting the comparator on +* an enabled one-shot timer. +* +* This configuration bit clears when the comparator +* is written. +*/ + h->hpet.timers[tn].config &= ~HPET_TN_SETVAL ; + h->hpet.timers[tn].cmp = new_val; + h->hpet.comparator64[tn] = new_val; + } +else + { +/* +* Clamp period to reasonable min/max values: +* - minimum is 100us, same as timers controlled by vpt.c +* - maximum is to prevent overflow in time_after() +* calculations +*/ +if (hpet_tick_to_ns (h, new_val) <MICROSECS (100 ) ) + new_val = (MICROSECS (100 ) <<10 ) / h->hpet_to_ns_scale; + new_val &= (timer_is_32bit (h, tn) ? ~0u : ~0ull ) >>1 ; + h->hpet.period[tn] = new_val; + } + } +else {/* -* Clamp period to reasonable min/max values:
xen/arch/x86/hvm/hpet.c static int hpet_write( · line 440
Quoted 10 lines
xen/arch/x86/hvm/hpet.c +3
-6-* - minimum is 100us, same as timers controlled by vpt.c -* - maximum is to prevent overflow in time_after() calculations +* The spec says "do not use", but clear if specified. */ -if (hpet_tick_to_ns (h, new_val) <MICROSECS (100 ) ) - new_val = (MICROSECS (100 ) <<10 ) / h->hpet_to_ns_scale; - new_val &= (timer_is_32bit (h, tn) ? ~0u : ~0ull ) >>1 ; - h->hpet.period[tn] = new_val; +if ( h->hpet.timers[tn].config &HPET_TN_SETVAL ) + h->hpet.timers[tn].config &= ~HPET_TN_SETVAL ;
The if() is clearly unnecessary here, and with it removed I don't see any difference left with the inner if() path above. Hence I guess they should be folded. Once that's done, new_val as calculated before the outer if() isn't needed in the inner "else" path, and hence its truncation could be moved inside the if(). Which in turn allows you to fix the comparator64 related bug here too: All other code stores the non-truncated value there, just the code here doesn't.
Jan
Re: [PATCH v2 03/10] hvm/hpet: Only set comparator or period not both.
Quoted 11 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 08.04.14 at 16:24, <[email protected]> wrote:
The
if()is clearly unnecessary here, and with it removed I don't see any difference left with the innerif()path above. Hence I guess they should be folded. Once that's done,new_valas calculated before the outerif()isn't needed in the inner "else" path, and hence its truncation could be moved inside theif(). Which in turn allows you to fix the comparator64 related bug here too: All other code stores the non-truncated value there, just the code here doesn't.
Quoted 1 line
Jan
If I understand this correctly, this leads to the following change (Hopefully not line wrapped):
xen/arch/x86/hvm/hpet.c +21 -15
@@ -404,20 +404,8 @@ static int hpet_write(case HPET_Tn_CMP (1 ):case HPET_Tn_CMP (2 ): tn =HPET_TN (CMP , addr); -if (timer_is_32bit (h, tn) ) - new_val = (uint32_t )new_val; - h->hpet.timers[tn].cmp = new_val; -if ( h->hpet.timers[tn].config &HPET_TN_SETVAL ) -/* -* When SETVAL is one, software is able to "directly set a periodic -* timer's accumulator." That is, set the comparator without -* adjusting the period. Much the same as just setting the -* comparator on an enabled one-shot timer. -* -* This configuration bit clears when the comparator is written. -*/ - h->hpet.timers[tn].config &= ~HPET_TN_SETVAL ; -else if (timer_is_periodic (h, tn) ) +if (timer_is_periodic (h, tn) && + !(h->hpet.timers[tn].config &HPET_TN_SETVAL ) ) {/* * Clamp period to reasonable min/max values:
@@ -429,7 +417,25 @@ static int hpet_write( new_val &= (timer_is_32bit (h, tn) ? ~0u : ~0ull ) >>1 ; h->hpet.period[tn] = new_val; } - h->hpet.comparator64[tn] = new_val; +else + { +/* +* When SETVAL is one, software is able to "directly set +* a periodic timer's accumulator." That is, set the +* comparator without adjusting the period. Much the +* same as just setting the comparator on an enabled +* one-shot timer. +* +* This configuration bit clears when the comparator is +* written. +*/ + h->hpet.timers[tn].config &= ~HPET_TN_SETVAL ; + h->hpet.comparator64[tn] = new_val; +if (timer_is_32bit (h, tn) ) + h->hpet.timers[tn].cmp = (uint32_t )new_val; +else + h->hpet.timers[tn].cmp = new_val; + }if (hpet_enabled (h) &&timer_enabled (h, tn) )set_restart_timer (tn);break ;
I am still testing that this re-write still does the "right thing". Which is why it is yet to be a v3. This preview is sent to check that I did correctly do the requested change.
-Don Slutz
Re: [PATCH v2 03/10] hvm/hpet: Only set comparator or period not both.
Quoted 13 lines
Quoted 1 line
Quoted 1 line · On 15.04.14 at 00:53, <[email protected]> wrote:
Quoted 10 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 08.04.14 at 16:24, <[email protected]> wrote:
The
if()is clearly unnecessary here, and with it removed I don't see any difference left with the innerif()path above. Hence I guess they should be folded. Once that's done,new_valas calculated before the outerif()isn't needed in the inner "else" path, and hence its truncation could be moved inside theif(). Which in turn allows you to fix the comparator64 related bug here too: All other code stores the non-truncated value there, just the code here doesn't.
Quoted 2 lines
If I understand this correctly, this leads to the following change (Hopefully not line wrapped):
Yes, with a minor comment.
Quoted 38 lines
xen/arch/x86/hvm/hpet.c +10
-15@@ -404,20 +404,8 @@ static int hpet_write(case HPET_Tn_CMP (1 ):case HPET_Tn_CMP (2 ): tn =HPET_TN (CMP , addr); -if (timer_is_32bit (h, tn) ) - new_val = (uint32_t )new_val; - h->hpet.timers[tn].cmp = new_val; -if ( h->hpet.timers[tn].config &HPET_TN_SETVAL ) -/* -* When SETVAL is one, software is able to "directly set a periodic -* timer's accumulator." That is, set the comparator without -* adjusting the period. Much the same as just setting the -* comparator on an enabled one-shot timer. -* -* This configuration bit clears when the comparator is written. -*/ - h->hpet.timers[tn].config &= ~HPET_TN_SETVAL ; -else if (timer_is_periodic (h, tn) ) +if (timer_is_periodic (h, tn) && + !(h->hpet.timers[tn].config &HPET_TN_SETVAL ) ) {/* * Clamp period to reasonable min/max values: @@ -429,7 +417,25 @@ static int hpet_write( new_val &= (timer_is_32bit (h, tn) ? ~0u : ~0ull ) >>1 ; h->hpet.period[tn] = new_val; } - h->hpet.comparator64[tn] = new_val; +else + { +/* +* When SETVAL is one, software is able to "directly set +* a periodic timer's accumulator." That is, set the +* comparator without adjusting the period. Much the +* same as just setting the comparator on an enabled +* one-shot timer.
xen/arch/x86/hvm/hpet.c static int hpet_write( · line 437
Quoted 10 lines
xen/arch/x86/hvm/hpet.c +10
-0+* +* This configuration bit clears when the comparator is +* written. +*/ + h->hpet.timers[tn].config &= ~HPET_TN_SETVAL ; + h->hpet.comparator64[tn] = new_val; +if (timer_is_32bit (h, tn) ) + h->hpet.timers[tn].cmp = (uint32_t )new_val; +else + h->hpet.timers[tn].cmp = new_val;
I'd continue to do the truncation on new_val, and write just once (as the old code did).
Jan
Re: [PATCH v2 03/10] hvm/hpet: Only set comparator or period not both.
Quoted 2 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 15.04.14 at 00:53, <[email protected]> wrote:
Yes, with a minor comment.
...
Quoted 6 lines
xen/arch/x86/hvm/hpet.c static int hpet_write( · line 437
Quoted 4 lines
xen/arch/x86/hvm/hpet.c +4
-0+if (timer_is_32bit (h, tn) ) + h->hpet.timers[tn].cmp = (uint32_t )new_val; +else + h->hpet.timers[tn].cmp = new_val;I'd continue to do the truncation on
new_val, and write just once (as the old code did).
Will do in v3.
-Don Slutz
Quoted 2 lines
Jan
PATCH v2 4/10 hvm/hpet: In hpet_save, correctly compute mc64.
In reply to Don SlutzWhen the master clock is not enabled, mc64 has the right value.
Basicly do the same thing as hpet_read_maincounter().
--- xen/arch/x86/hvm/hpet.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/hpet.c +2 -1
@@ -504,7 +504,8 @@ static int hpet_save(struct domain *d, hvm_domain_context_t *h)spin_lock (&hp->lock);/* Write the proper value into the main counter */ - hp->hpet.mc64 = hp->mc_offset +guest_time_hpet (hp); +if (hpet_enabled (hp) ) + hp->hpet.mc64 = hp->mc_offset +guest_time_hpet (hp);/* Save the HPET registers */ rc =_hvm_init_entry (h,HVM_SAVE_CODE (HPET ),0 ,HVM_SAVE_LENGTH (HPET ));
Signature · 1 line
1.8.4
PATCH v2 5/10 hvm/hpet: Init comparator64 like comparator.
In reply to Don SlutzThe software-developers-hpet-spec-1-0a.pdf says that the comparator starts as all 1's. Also make the hidden register comparator64 the same.
Since only the hidden register comparator64 is used by hpet_save, it needs to start out with the right value.
--- xen/arch/x86/hvm/hpet.c | 1 + 1 file changed, 1 insertion(+)
xen/arch/x86/hvm/hpet.c +1 -0
@@ -627,6 +627,7 @@ void hpet_init(struct vcpu *v) h->hpet.timers[i].config =HPET_TN_INT_ROUTE_CAP |HPET_TN_64BIT_CAP |HPET_TN_PERIODIC_CAP ; h->hpet.timers[i].cmp = ~0ULL ; + h->hpet.comparator64[i] = ~0ULL ; h->pt[i].source = PTSRC_isa; } }
Signature · 1 line
1.8.4
PATCH v2 6/10 hvm/hpet: comparator can only change when master clock is enabled.
In reply to Don SlutzThis is based on software-developers-hpet-spec-1-0a.pdf saying:
When the main counter value matches the value in the timer's comparator register, an interrupt can be generated. The hardware will then automatically increase the value in the compare register by the last value written to that register.
And since interrupt can only be generated when the master clock is enabled.
--- xen/arch/x86/hvm/hpet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/hvm/hpet.c +1 -1
@@ -90,7 +90,7 @@ static uint64_t hpet_get_comparator(HPETState *h, unsigned int tn,uint64_t elapsed; comparator = h->hpet.comparator64[tn]; -if (timer_is_periodic (h, tn) ) +if (hpet_enabled (h) &&timer_is_periodic (h, tn) ) {/* update comparator by number of periods elapsed since last update */ uint64_t period = h->hpet.period[tn];
Signature · 1 line
1.8.4
Re: [PATCH v2 06/10] hvm/hpet: comparator can only change when master clock is enabled.
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 16:24, <[email protected]> wrote:
This is based on software-developers-hpet-spec-1-0a.pdf saying:
When the main counter value matches the value in the timer's comparator register, an interrupt can be generated. The hardware will then automatically increase the value in the compare register by the last value written to that register.
And since interrupt can only be generated when the master clock is enabled.
This last sentence looks truncated.
As to the change - I'm not sure: The quoted description from the specification cal also be read to mean that interrupt generation is optional, but comparator increment will always happen. As long as this can't be clarified, I'd prefer to stay with the code as is.
Jan
Re: [PATCH v2 06/10] hvm/hpet: comparator can only change when master clock is enabled.
Quoted 11 lines · Jan Beulich
Quoted 10 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 16:24, <[email protected]> wrote:
This is based on software-developers-hpet-spec-1-0a.pdf saying:
When the main counter value matches the value in the timer's comparator register, an interrupt can be generated. The hardware will then automatically increase the value in the compare register by the last value written to that register.
And since interrupt can only be generated when the master clock is enabled.
This last sentence looks truncated.
It is. I think I had:
And since interrupt can only be generated when the master clock is enabled, the compare register should also change only then.
Which looks too complex to me now.
From the spec:
ENABLE_CNF
Overall Enable:
This bit must be set to enable any of the timers to generate interrupts. If this bit is 0, then the main counter will halt (will not increment) and no interrupts will be caused by any of these timers.
• 0 – Halt main count and disable all timer interrupts
• 1 – allow main counter to run, and allow timer interrupts if enabled
I think a better statement would be:
When the overall enable is off (the main count is halted), none of the compare registers should change.
So I will change this in the commit message.
Quoted 4 lines
As to the change - I'm not sure: The quoted description from the specification cal also be read to mean that interrupt generation is optional, but comparator increment will always happen. As long as this can't be clarified, I'd prefer to stay with the code as is.
I think the code needs to change to match the spec.
#define timer_enabled(h, n) (timer_config(h, n) & HPET_TN_ENABLE)
vs
#define hpet_enabled(h) (h->hpet.config & HPET_CFG_ENABLE)
The change uses hpet_enabled() (I.E. Overall Enable).
-Don Slutz
Quoted 3 lines
Jan
Re: [PATCH v2 06/10] hvm/hpet: comparator can only change when master clock is enabled.
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 14.04.14 at 21:50, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
As to the change - I'm not sure: The quoted description from the specification cal also be read to mean that interrupt generation is optional, but comparator increment will always happen. As long as this can't be clarified, I'd prefer to stay with the code as is.
I think the code needs to change to match the spec.
Quoted 8 lines
#define
timer_enabled(h, n)(timer_config(h, n)&HPET_TN_ENABLE)vs
#define
hpet_enabled(h)(h->hpet.config&HPET_CFG_ENABLE)The change uses
hpet_enabled()(I.E. Overall Enable).
Correct. But do we really need this? When the HPET is globally disabled, hpet_read_maincounter() returns a fixed value, and hence - due to the comparators not changing either - hpet_get_comparator() will too even without the addition. So if at all, the change would be mostly for documentation purposes.
Jan
Re: [PATCH v2 06/10] hvm/hpet: comparator can only change when master clock is enabled.
Quoted 15 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 14.04.14 at 21:50, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
As to the change - I'm not sure: The quoted description from the specification cal also be read to mean that interrupt generation is optional, but comparator increment will always happen. As long as this can't be clarified, I'd prefer to stay with the code as is.
I think the code needs to change to match the spec.
#define
timer_enabled(h, n)(timer_config(h, n)&HPET_TN_ENABLE)vs
#define
hpet_enabled(h)(h->hpet.config&HPET_CFG_ENABLE)
Quoted 6 lines
Quoted 1 line
The change uses
hpet_enabled()(I.E. Overall Enable).Correct. But do we really need this? When the HPET is globally disabled,
hpet_read_maincounter()returns a fixed value, and hence - due to the comparators not changing either -hpet_get_comparator()will too even without the addition. So if at all, the change would be mostly for documentation purposes.
We do need this. hpet_get_comparator() does not return a fixed value. Without this change it will always adjust to hpet_read_maincounter(). Here is an example using the manual test code:
dcs-xen-54:~/xen/tools/tests/vhpet>gdb --args ./test_vhpet 0 3 0 1 0x13
GNU gdb (GDB) 7.6.2.20140108-cvs
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-unknown-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/don/xen/tools/tests/vhpet/test_vhpet...done.
(gdb) b hpet.c:128
Breakpoint 1 at 0x400ac1: file hpet.c, line 128.
(gdb) r
Starting program: /home/don/xen/tools/tests/vhpet/./test_vhpet 0 3 0 1 0x13
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffd000 test_vhpet 1.0
hvm_clock_cost=0 hpet_mult=3 hpet_add=0 tick_count=1 debug=0x13
skip_load=1
HPET: capability 0xf424008086a201 config 0()
isr 0 counter 0(0)
timer0 config 0xf0000000000030() cmp 0xffffffffffffffff(-1)
timer0 period 0(0) fsb 0
timer1 config 0xf0000000000030() cmp 0xffffffffffffffff(-1)
timer1 period 0(0) fsb 0
timer2 config 0xf0000000000030() cmp 0xffffffffffffffff(-1)
timer2 period 0(0) fsb 0
HPET: capability 0xf424008086a201 config 0()
isr 0 counter 0(0)
timer0 config 0xf0000000000030() cmp 0xffffffffffffffff(-1)
timer0 period 0(0) fsb 0
timer1 config 0xf0000000000030() cmp 0xffffffffffffffff(-1)
timer1 period 0(0) fsb 0
timer2 config 0xf0000000000030() cmp 0xffffffffffffffff(-1)
timer2 period 0(0) fsb 0
skip_load
HPET: capability 0xf424008086a201 config 0()
isr 0 counter 0(0)
timer0 config 0xf0000000000030() cmp 0xffffffffffffffff(-1)
timer0 period 0(0) fsb 0
timer1 config 0xf0000000000030() cmp 0xffffffffffffffff(-1)
timer1 period 0(0) fsb 0
timer2 config 0xf0000000000030() cmp 0xffffffffffffffff(-1)
timer2 period 0(0) fsb 0mc64=0x108a8(67,752) mc_offset=0x10898(67,736)
hvm_guest_time=0x10(16)
HPET: capability 0xf424008086a201 config 0()
isr 0 counter 0x108a8(67,752)
timer0 config 0xf0000000000030() cmp 0xffffffffffffffff(-1)
timer0 period 0(0) fsb 0
timer1 config 0xf0000000000030() cmp 0xffffffffffffffff(-1)
timer1 period 0(0) fsb 0
timer2 config 0xf0000000000030() cmp 0xffffffffffffffff(-1)
timer2 period 0(0) fsb 0
HPET: capability 0xf424008086a201 config 0()
isr 0 counter 0x108a8(67,752)
timer0 config 0xf0000000000030() cmp 0xffffffffffffffff(-1)
timer0 period 0(0) fsb 0
timer1 config 0xf0000000000030() cmp 0xffffffffffffffff(-1)
timer1 period 0(0) fsb 0
timer2 config 0xf0000000000030() cmp 0xffffffffffffffff(-1)
timer2 period 0(0) fsb 0
skip_load
HPET: capability 0xf424008086a201 config 0()
isr 0 counter 0x108a8(67,752)
timer0 config 0xf0000000000030() cmp 0xffffffffffffffff(-1)
timer0 period 0(0) fsb 0
timer1 config 0xf0000000000030() cmp 0xffffffffffffffff(-1)
timer1 period 0(0) fsb 0
timer2 config 0xf0000000000030() cmp 0xffffffffffffffff(-1)
timer2 period 0(0) fsb 0Breakpoint 1, hpet_read64 (h=0x604d68 <dom1+8>, addr=264) at hpet.c:128
128 return hpet_get_comparator(h, HPET_TN(CMP, addr), guest_time_hpet(h));
(gdb) c
Continuing.hpet_writel: HPET_TN_SETVAL cmp=0x3e514(255,252) timer=0
Breakpoint 1, hpet_read64 (h=0x604d68 <dom1+8>, addr=264) at hpet.c:128
128 return hpet_get_comparator(h, HPET_TN(CMP, addr), guest_time_hpet(h));
(gdb) c
Continuing.hpet_writel: period=0xf424(62,500) timer=0
Breakpoint 1, hpet_read64 (h=0x604d68 <dom1+8>, addr=264) at hpet.c:128
128 return hpet_get_comparator(h, HPET_TN(CMP, addr), guest_time_hpet(h));
(gdb) b hpet_get_comparator
Breakpoint 2 at 0x400839: file hpet.c, line 87.
(gdb) c
Continuing.
Breakpoint 2, hpet_get_comparator (h=0x604d68 <dom1+8>, tn=0, guest_time=1) at hpet.c:87
87 comparator = h->hpet.comparator64[tn];
(gdb) n
88 if ( timer_is_periodic(h, tn) )
(gdb)
91 uint64_t period = h->hpet.period[tn];
(gdb)
92 if (period)
(gdb)
94 elapsed = hpet_read_maincounter(h, guest_time) +
(gdb)
95 period - 1 - comparator;
(gdb)
94 elapsed = hpet_read_maincounter(h, guest_time) +
(gdb)
96 comparator += (elapsed / period) * period;
(gdb) p comparator
$1 = 255252
(gdb) p/x comparator
$2 = 0x3e514
(gdb) p elapsed
$3 = 18446744073709426615
(gdb) p/x elapsed
$4 = 0xfffffffffffe17b7
(gdb) p elapsed / period
$5 = 295147905179350
(gdb) p/x elapsed / period
$6 = 0x10c6f7a0b5ed6
(gdb) p 295147905179350 * period
$7 = 18446744073709375000
(gdb) p/x 295147905179350 * period
$8 = 0xfffffffffffd4e18
(gdb) n
97 h->hpet.comparator64[tn] = comparator;
(gdb) p comparator
$9 = 78636
(gdb) p/x comparator
$10 = 0x1332c
(gdb)
-Don Slutz
Quoted 2 lines
Jan
Re: [PATCH v2 06/10] hvm/hpet: comparator can only change when master clock is enabled.
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 15.04.14 at 17:53, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 14.04.14 at 21:50, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
As to the change - I'm not sure: The quoted description from the specification cal also be read to mean that interrupt generation is optional, but comparator increment will always happen. As long as this can't be clarified, I'd prefer to stay with the code as is.
I think the code needs to change to match the spec.
#define
timer_enabled(h, n)(timer_config(h, n)&HPET_TN_ENABLE)vs
#define
hpet_enabled(h)(h->hpet.config&HPET_CFG_ENABLE)Quoted 6 lines
Quoted 1 line
The change uses
hpet_enabled()(I.E. Overall Enable).Correct. But do we really need this? When the HPET is globally disabled,
hpet_read_maincounter()returns a fixed value, and hence - due to the comparators not changing either -hpet_get_comparator()will too even without the addition. So if at all, the change would be mostly for documentation purposes.
Quoted 3 lines
We do need this.
hpet_get_comparator()does not return a fixed value. Without this change it will always adjust tohpet_read_maincounter().
But as said, hpet_read_maincounter() returns a fixed value in that case too (or at least it is supposed to be).
And no, I'm not fully trusting the test program, so please explain things relative to the source code rather than by pointing at the test program showing something.
Jan
Re: [PATCH v2 06/10] hvm/hpet: comparator can only change when master clock is enabled.
Quoted 26 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 15.04.14 at 17:53, <[email protected]> wrote:
Quoted 16 lines · Jan Beulich
Quoted 16 lines
Quoted 1 line
Quoted 1 line · On 14.04.14 at 21:50, <[email protected]> wrote:
Quoted 4 lines · Jan Beulich
As to the change - I'm not sure: The quoted description from the specification cal also be read to mean that interrupt generation is optional, but comparator increment will always happen. As long as this can't be clarified, I'd prefer to stay with the code as is.
I think the code needs to change to match the spec.
#define
timer_enabled(h, n)(timer_config(h, n)&HPET_TN_ENABLE)vs
#define
hpet_enabled(h)(h->hpet.config&HPET_CFG_ENABLE)The change uses
hpet_enabled()(I.E. Overall Enable).Quoted 8 lines
Quoted 5 lines
Correct. But do we really need this? When the HPET is globally disabled,
hpet_read_maincounter()returns a fixed value, and hence - due to the comparators not changing either -hpet_get_comparator()will too even without the addition. So if at all, the change would be mostly for documentation purposes.We do need this.
hpet_get_comparator()does not return a fixed value. Without this change it will always adjust tohpet_read_maincounter().
Quoted 6 lines
But as said,
hpet_read_maincounter()returns a fixed value in that case too (or at least it is supposed to be).And no, I'm not fully trusting the test program, so please explain things relative to the source code rather than by pointing at the test program showing something.
Ok,
Since this is all about when master clock is not enabled, I will work with hpet_read_maincounter() returning a fix value. I will also only talk about timer 0 (tn==0).
Since master clock, comparator, and period can all be set by the guest, I am picking values:
master clock = 67752 (0x108a8)
comparator = 255252 (0x3e514)
period = 62500 (0xf424)
Using code as of:
commit d2b4c27c0718f27deba00a16317a8ba04c1a2cb7
xen/arm32: __cmpxchg_mb should be marked always_inline
86:static uint64_t hpet_get_comparator(HPETState *h, unsigned int tn) 87:{
88: uint64_t comparator;
89: uint64_t elapsed;
91: comparator = h->hpet.comparator64[tn];
92: if ( timer_is_periodic(h, tn) )
93: {
94: /* update comparator by number of periods elapsed since last update */
95: uint64_t period = h->hpet.period[tn];
96: if (period)
97: {98: elapsed = hpet_read_maincounter(h) + period - 1 - comparator;
99: comparator += (elapsed / period) * period;
100: h->hpet.comparator64[tn] = comparator;
101: }
102: } 104: /* truncate if timer is in 32 bit mode */ 105: if ( timer_is_32bit(h, tn) )
106: comparator = (uint32_t)comparator;
107: h->hpet.timers[tn].cmp = comparator;
108: return comparator;
109:}
so on line 98:
elapsed = 67752 + 62500 - 1 - 255252
bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc. This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
67752 + 62500 - 1 - 255252
-125001
Or in hex: 0xFFFFFFFFFFFE17B7
Next:
-125001/62500
-2
-2*62500
-125000
So on line 99 the comparator is changed by -125000.
I.E. the value written is not the value read.
-Don Slutz
Quoted 3 lines
Jan
Re: [PATCH v2 06/10] hvm/hpet: comparator can only change when master clock is enabled.
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 15.04.14 at 20:11, <[email protected]> wrote:
Since this is all about when master clock is not enabled, I will work with
hpet_read_maincounter()returning a fix value. I will also only talk about timer 0 (tn==0).Since master clock, comparator, and period can all be set by the guest, ...
Oh, okay, this is the piece I ignored so far - I assumed that the values would be unchanged from when last updated by the hypervisor. IOW I agree with the change then, but would ask for the description to point out why this is needed in a more explicit fashion.
Jan
PATCH v2 7/10 hvm/hpet: Call hpet_get_comparator during hpet_save.
In reply to Don SlutzThis changes save data to consistent/expected values. It is not technically required because hpet_get_comparator() will adjust from any value to the correct value.
--- xen/arch/x86/hvm/hpet.c | 7 +++++++ 1 file changed, 7 insertions(+)
xen/arch/x86/hvm/hpet.c +7 -0
@@ -500,6 +500,7 @@ static int hpet_save(struct domain *d, hvm_domain_context_t *h) {HPETState *hp =domain_vhpet (d);int rc; +uint64_t guest_time;spin_lock (&hp->lock);
@@ -529,6 +530,12 @@ static int hpet_save(struct domain *d, hvm_domain_context_t *h)C (period[1 ]);C (period[2 ]);#undef C +/* read the comparator to get it updated so hpet_save will +* return the expected value. */ + guest_time = hp->hpet.mc64 - hp->mc_offset; +hpet_get_comparator (hp,0 , guest_time); +hpet_get_comparator (hp,1 , guest_time); +hpet_get_comparator (hp,2 , guest_time);/* save the 64 bit comparator in the 64 bit timer[n].cmp field * regardless of whether or not the timer is in 32 bit mode. */ rec->timers[0 ].cmp = hp->hpet.comparator64[0 ];
Signature · 1 line
1.8.4
Re: [PATCH v2 07/10] hvm/hpet: Call hpet_get_comparator during hpet_save.
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 16:24, <[email protected]> wrote:
This changes save data to consistent/expected values. It is not technically required because
hpet_get_comparator()will adjust from any value to the correct value.
So am I getting it right that this is just to alter what's in the save image then? I'm somewhat confused by the wording above, which I first read mostly like "here is a change that we don't need".
Jan
Re: [PATCH v2 07/10] hvm/hpet: Call hpet_get_comparator during hpet_save.
Quoted 6 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 16:24, <[email protected]> wrote:
This changes save data to consistent/expected values. It is not technically required because
hpet_get_comparator()will adjust from any value to the correct value.So am I getting it right that this is just to alter what's in the save image then?
Yes.
Quoted 2 lines
I'm somewhat confused by the wording above, which I first read mostly like "here is a change that we don't need".
This is a change that is only "needed" with patch #10 "handle 1st period special".
However it does look strange to people that the output from xen-hvmctx for the comparator values do not change when the master clock does.
Since hpet_get_comparator() will always adjust the current value of comparator to the current value of the master clock, migration just "works".
-Don Slutz
Quoted 2 lines
Jan
Re: [PATCH v2 07/10] hvm/hpet: Call hpet_get_comparator during hpet_save.
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 15.04.14 at 02:21, <[email protected]> wrote:
Quoted 6 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 16:24, <[email protected]> wrote:
This changes save data to consistent/expected values. It is not technically required because
hpet_get_comparator()will adjust from any value to the correct value.So am I getting it right that this is just to alter what's in the save image then?
Yes.
Quoted 2 lines
I'm somewhat confused by the wording above, which I first read mostly like "here is a change that we don't need".
Quoted 6 lines
This is a change that is only "needed" with patch #10 "handle 1st period special".
However it does look strange to people that the output from xen-hvmctx for the comparator values do not change when the master clock does.
Maybe you should mention that aspect then in the commit message?
Jan
Re: [PATCH v2 07/10] hvm/hpet: Call hpet_get_comparator during hpet_save.
Quoted 9 lines · Jan Beulich
Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 15.04.14 at 02:21, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 08.04.14 at 16:24, <[email protected]> wrote:
I'm somewhat confused by the wording above, which I first read mostly like "here is a change that we don't need".
Quoted 7 lines
Quoted 6 lines
This is a change that is only "needed" with patch #10 "handle 1st period special".
However it does look strange to people that the output from xen-hvmctx for the comparator values do not change when the master clock does.
Maybe you should mention that aspect then in the commit message?
I will.
-Don Slutz
Quoted 2 lines
Jan
PATCH v2 8/10 hvm/hpet: Prevent master clock equal to comparator while enabled
In reply to Don SlutzBased on the software-developers-hpet-spec-1-0a.pdf, the comparator for a periodic timer will change to the new value when it matches the master clock. The current code here uses a very standard rounding formula of "((x + y - 1) / y) * y". This is wrong because in this case you need to go to the next comparator value when "x" equals "y". Not when "x + 1" equals "y". In this case "y" is the period and "x" is the master clock.
--- xen/arch/x86/hvm/hpet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/hvm/hpet.c +1 -1
@@ -97,7 +97,7 @@ static uint64_t hpet_get_comparator(HPETState *h, unsigned int tn,if (period) { elapsed =hpet_read_maincounter (h, guest_time) + - period -1 - comparator; + period - comparator; comparator += (elapsed / period) * period; h->hpet.comparator64[tn] = comparator; }
Signature · 1 line
1.8.4
PATCH v2 9/10 hvm/hpet: Correctly limit period to a maximum.
In reply to Don SlutzIn the code section after the comment:
/*
* Clamp period to reasonable min/max values:
* - minimum is 100us, same as timers controlled by vpt.c
* - maximum is to prevent overflow in time_after() calculations */
The current maximum limit actually allows "bad" values like 0 and 1. This is because it uses a mask not a maximum.
--- xen/arch/x86/hvm/hpet.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/hpet.c +5 -1
@@ -419,6 +419,9 @@ static int hpet_write( }else { +uint64_t max_period = + (timer_is_32bit (h, tn) ? ~0u : ~0ull ) >>1 ; +/* * Clamp period to reasonable min/max values: * - minimum is 100us, same as timers controlled by vpt.c
@@ -427,7 +430,8 @@ static int hpet_write(*/ if (hpet_tick_to_ns (h, new_val) <MICROSECS (100 ) ) new_val = (MICROSECS (100 ) <<10 ) / h->hpet_to_ns_scale; - new_val &= (timer_is_32bit (h, tn) ? ~0u : ~0ull ) >>1 ; +if ( new_val > max_period ) + new_val = max_period; h->hpet.period[tn] = new_val; } }
Signature · 1 line
1.8.4
PATCH v2 10/10 hvm/hpet: handle 1st period special
In reply to Don SlutzThe software-developers-hpet-spec-1-0a.pdf says that the 1st interrupt is based on the setting of comparator. After that it will be on each period. Add code that checks for this special case.
Add a callback routine when this special case is active that will disable the special case on the 1st interrupt.
--- xen/arch/x86/hvm/hpet.c | 56 +++++++++++++++++++++++++++++++++++++------ xen/include/asm-x86/hvm/vpt.h | 2 ++ 2 files changed, 51 insertions(+), 7 deletions(-)
xen/arch/x86/hvm/hpet.c +49 -7
@@ -94,10 +94,18 @@ static uint64_t hpet_get_comparator(HPETState *h, unsigned int tn, {/* update comparator by number of periods elapsed since last update */ uint64_t period = h->hpet.period[tn]; +uint64_t mc =hpet_read_maincounter (h, guest_time); + +if ( h->hpet.first_enabled[tn] ) + { +if ( mc >= h->hpet.first_mc64[tn] && mc < comparator ) + period =0 ;/* act like oneshot */ +else + h->hpet.first_enabled[tn] =0 ; + }if (period) { - elapsed =hpet_read_maincounter (h, guest_time) + - period - comparator; + elapsed = mc + period - comparator; comparator += (elapsed / period) * period; h->hpet.comparator64[tn] = comparator; }
@@ -203,6 +211,13 @@ static void hpet_stop_timer(HPETState *h, unsigned int tn)* 1/(2^10) second, namely, 0.9765625 milliseconds */ #define HPET_TINY_TIME_SPAN ((h->stime_freq >> 10) / STIME_PER_HPET_TICK) +static void hpet_time_fired (struct vcpu *v,void *priv) +{ +uint8_t *first_enabled_p = (uint8_t *)priv; + + *first_enabled_p =0 ; +} +static void hpet_set_timer (HPETState *h,unsigned int tn,int mc_starting) {uint64_t tn_cmp, cur_tick, diff;
@@ -223,8 +238,16 @@ static void hpet_set_timer(HPETState *h, unsigned int tn, int mc_starting)if ( !timer_enabled (h, tn) )return ; + oneshot = !timer_is_periodic (h, tn);if ( mc_starting ) + { guest_time = h->hpet.mc64 - h->mc_offset; +if ( !oneshot ) + { + h->hpet.first_mc64[tn] = h->hpet.mc64; + h->hpet.first_enabled[tn] =1 ; + } + }else guest_time =guest_time_hpet (h);
@@ -262,11 +285,27 @@ static void hpet_set_timer(HPETState *h, unsigned int tn, int mc_starting)* have elapsed between the time the comparator was written and the timer * being enabled (now). */ - oneshot = !timer_is_periodic (h, tn); -create_periodic_time (vhpet_vcpu (h), &h->pt[tn], -hpet_tick_to_ns (h, diff), - oneshot ?0 :hpet_tick_to_ns (h, h->hpet.period[tn]), - irq,NULL ,NULL ); +if ( oneshot ) +create_periodic_time (vhpet_vcpu (h), &h->pt[tn], +hpet_tick_to_ns (h, diff), +0 , irq,NULL ,NULL ); +else + { +if ( diff <= h->hpet.period[tn] ) + { + h->hpet.first_enabled[tn] =0 ; +create_periodic_time (vhpet_vcpu (h), &h->pt[tn], +hpet_tick_to_ns (h, diff), +hpet_tick_to_ns (h, h->hpet.period[tn]), + irq,NULL ,NULL ); + } +else +create_periodic_time (vhpet_vcpu (h), &h->pt[tn], +hpet_tick_to_ns (h, diff), +hpet_tick_to_ns (h, h->hpet.period[tn]), + irq, hpet_time_fired, + &h->hpet.first_enabled[tn]); + } } static inline uint64_t hpet_fixup_reg(
@@ -591,6 +630,9 @@ static int hpet_load(struct domain *d, hvm_domain_context_t *h)if (timer_is_32bit (hp, i) ) cmp = (uint32_t )cmp; hp->hpet.timers[i].cmp = cmp; +/* Init hidden regs also */ + hp->hpet.first_mc64[i] =0 ; + hp->hpet.first_enabled[i] =0 ; }#undef C
xen/include/asm-x86/hvm/vpt.h +2 -0
@@ -87,6 +87,8 @@ struct hpet_registers {/* Hidden register state */ uint64_t period[HPET_TIMER_NUM ];/* Last value written to comparator */ uint64_t comparator64[HPET_TIMER_NUM ];/* 64 bit running comparator */ +uint64_t first_mc64[HPET_TIMER_NUM ];/* 1st interval main counter */ +uint8_t first_enabled[HPET_TIMER_NUM ];/* In 1st interval */ }; typedef struct HPETState {
Signature · 1 line
1.8.4
Re: [PATCH v2 10/10] hvm/hpet: handle 1st period special
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 16:24, <[email protected]> wrote:
The software-developers-hpet-spec-1-0a.pdf says that the 1st interrupt is based on the setting of comparator. After that it will be on each period. Add code that checks for this special case.
The way hpet_set_timer() call create_periodic_time() to me seems to do exactly that. What am I missing?
Jan
Re: [PATCH v2 10/10] hvm/hpet: handle 1st period special
Quoted 6 lines · Jan Beulich
Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 08.04.14 at 16:24, <[email protected]> wrote:
The software-developers-hpet-spec-1-0a.pdf says that the 1st interrupt is based on the setting of comparator. After that it will be on each period. Add code that checks for this special case.
The way
hpet_set_timer()callcreate_periodic_time()to me seems to do exactly that. What am I missing?
Since hpet_get_comparator() will always adjust the current value of comparator to the current value of the master clock, the call to create_periodic_time() which uses diff which is:
tn_cmp = hpet_get_comparator(h, tn);
cur_tick = hpet_read_maincounter(h);
...
diff = tn_cmp - cur_tick;So using the manual test code and asking for 1 and 3 starting periods:
dcs-xen-54:~/xen/tools/tests/vhpet>./test_vhpet 0 1 0 3 3 >foo
hpet: T0 Error: Set 0x1fcbd(130,237) != 0x1e848(125,000)
...
Which is not the default mode, and the important arguments are:
hvm_clock_cost=0 hpet_mult=1 hpet_add=0
(I.E. the 1st 3)
create_periodic_time: pt=0 delta=916,208 period=1,000,000 - 1,000.00 Hz irq=0
and
dcs-xen-54:~/xen/tools/tests/vhpet>./test_vhpet 0 3 0 3 3 >foo
hpet: T0 Error: Set 0x3e505(255,237) != 0x1e848(125,000)
...
(hvm_clock_cost=0 hpet_mult=3 hpet_add=0)
create_periodic_time: pt=0 delta=916,208 period=1,000,000 - 1,000.00 Hz irq=0
Notice that the cmp jumps back to the same value. The master clock is not at the period (it is 0x10899(67,737)) and so cmp is adjusted "backwards" in this case.
This output is with no changes. It is not until patch #6:
hvm/hpet: comparator can only change when master clock is enabled.
That the unit test stops printing the error. However the hpet_save output still
shows the changed value.
It is not till after this patch that:
dcs-xen-54:~/xen/tools/tests/vhpet>./test_vhpet 0 1 0 3 0x13 >foo1 dcs-xen-54:~/xen/tools/tests/vhpet>./test_vhpet 0 3 0 3 0x13 >foo3 dcs-xen-54:~/xen>diff -suwp tools/tests/vhpet/foo1 tools/tests/vhpet/foo3 | head -30
tests/vhpet/foo3 2014-04-14 20:19:02.148251889 -0400 renamed from tests/vhpet/foo1 2014-04-14 20:17:51.923684610 -0400 +5 -5
@@ -1,5 +1,5 @@ test_vhpet 1.0 -hvm_clock_cost=0 hpet_mult=1 hpet_add=0 tick_count=3 debug=0x13 +hvm_clock_cost=0 hpet_mult=3 hpet_add=0 tick_count=3 debug=0x13 skip_load=1 HPET: capability 0xf424008086a201 config 0()
@@ -56,19 +56,19 @@ skip_load timer1 period 0(0) fsb 0 timer2 config 0xf0000000000030() cmp 0xffffffffffffffff(-1) timer2 period 0(0) fsb 0 -hpet_writel: HPET_TN_SETVAL cmp=0x1fccc(130,252) timer=0 +hpet_writel: HPET_TN_SETVAL cmp=0x3e514(255,252) timer=0 hpet_writel: period=0xf424(62,500) timer=0 create_periodic_time: mc64=0x108a8(67,752) mc_offset=0x108a7(67,751) - [0] cmp64=0x1fccc(130,252) cmp=0x1fccc(130,252) + [0] cmp64=0x3e514(255,252) cmp=0x3e514(255,252) [1] cmp64=0xffffffffffffffff(-1) cmp=0xffffffffffffffff(-1) [2] cmp64=0xffffffffffffffff(-1) cmp=0xffffffffffffffff(-1) -create_periodic_time: pt=0 delta=1,000,000 period=1,000,000 - 1,000.00 Hz irq=0 +create_periodic_time: pt=0 delta=3,000,000 period=1,000,000 - 1,000.00 Hz irq=0 hpet: hpet_set_mode(402): hpet: ID: 0x8086a201, PERIOD: 0xf42400 hpet: CFG: 0x1, STATUS: 0x0 hpet: COUNTER_l: 0x108a8, COUNTER_h: 0x0 hpet: T0: CFG_l: 0x13c, CFG_h: 0xf00000 -hpet: T0: CMP_l: 0x1fccc, CMP_h: 0x0 +hpet: T0: CMP_l: 0x3e514, CMP_h: 0x0
that the 1st delta is actually the request one in both cases.
-Don Slutz
Quoted 2 lines
Jan