From: Wei Liu <wei.liu2@citrix.com>
To: Roger Pau Monne <roger.pau@citrix.com>
Cc: xen-devel@lists.xenproject.org, Wei Liu <wei.liu2@citrix.com>,
Andrew Cooper <andrew.cooper3@citrix.com>
Subject: Re: [PATCH RFC 3/3] xtf: add minimal HPET functionality test
Date: Fri, 23 Feb 2018 19:07:18 +0000 [thread overview]
Message-ID: <20180223190718.pfbszon36aamqelb@citrix.com> (raw)
In-Reply-To: <20180223132743.59804-4-roger.pau@citrix.com>
On Fri, Feb 23, 2018 at 01:27:43PM +0000, Roger Pau Monne wrote:
> Add a basic HPET functionality test, note that this test requires the
> HPET to support level triggered interrupts.
>
> Further improvements should add support for interrupt delivery, and
> testing all the available timers.
>
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> ---
> Cc: Andrew Cooper <andrew.cooper3@citrix.com>
> ---
> arch/x86/include/arch/lib.h | 14 ++++
> docs/all-tests.dox | 2 +
> tests/hpet/Makefile | 9 +++
> tests/hpet/main.c | 187 ++++++++++++++++++++++++++++++++++++++++++++
> 4 files changed, 212 insertions(+)
> create mode 100644 tests/hpet/Makefile
> create mode 100644 tests/hpet/main.c
>
> diff --git a/arch/x86/include/arch/lib.h b/arch/x86/include/arch/lib.h
> index 6714bdc..3400890 100644
> --- a/arch/x86/include/arch/lib.h
> +++ b/arch/x86/include/arch/lib.h
> @@ -392,6 +392,20 @@ static inline void write_xcr0(uint64_t xcr0)
> xsetbv(0, xcr0);
> }
>
> +static inline uint64_t rdtsc(void)
> +{
> + uint32_t low, high;
> +
> + asm volatile ("rdtsc" : "=a" (low), "=d" (high));
> +
You probably need to add lfence or mfence. See rdtsc_ordered in Xen.
> + return ((uint64_t)high << 32) | low;
> +}
> +
[...]
> +static void set_freq(void)
> +{
> + uint32_t eax, ebx, ecx, edx, base;
> + bool found = false;
> +
> + /* Get tsc frequency from cpuid. */
> + for ( base = XEN_CPUID_FIRST_LEAF;
> + base < XEN_CPUID_FIRST_LEAF + 0x10000; base += 0x100 )
> + {
> + cpuid(base, &eax, &ebx, &ecx, &edx);
> +
> + if ( (ebx == XEN_CPUID_SIGNATURE_EBX) &&
> + (ecx == XEN_CPUID_SIGNATURE_ECX) &&
> + (edx == XEN_CPUID_SIGNATURE_EDX) &&
> + ((eax - base) >= 2) )
> + {
> + found = true;
> + break;
> + }
> + }
> +
> + if ( !found )
> + panic("Unable to locate Xen CPUID leaves\n");
> +
Finding Xen leaves should live in its own function and move to common
code if possible.
> + cpuid_count(base + 3, 0, &eax, &ebx, &freq, &edx);
> + printk("TSC frequency %ukHz\n", freq);
> +}
> +
> +/* Busy-wait implementation based on tsc value. */
> +static void wait(unsigned int ms)
> +{
> + uint64_t end = rdtsc() + (uint64_t)ms * (uint64_t)freq;
> +
> + while ( rdtsc() < end )
> + pause();
> +}
Rename to mdelay and move to a helper file?
> +
> +void test_main(void)
> +{
[...]
> + HPET_REG(HPET_Tn_CFG(nr)) &= ~HPET_TN_LEVEL;
> + HPET_REG(HPET_STATUS) = 1 << nr;
> + wait(200);
> + if ( ((HPET_REG(HPET_STATUS) >> nr) & 1) )
> + return xtf_failure("Fail: Status bit set for edge interrupt in periodic mode\n");
> +
Is it possible to use shorter time in the test? This test as-is will run
for 1 or 2 seconds which is a bit long as micro-kernel testing.
Wei.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
next prev parent reply other threads:[~2018-02-23 19:07 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-23 13:27 [PATCH RFC 0/3] hpet: add support for level triggered interrupts Roger Pau Monne
2018-02-23 13:27 ` [PATCH RFC 1/3] x86/vpt: execute callbacks for masked interrupts Roger Pau Monne
2018-02-26 12:35 ` Wei Liu
2018-02-26 12:48 ` Roger Pau Monné
2018-02-26 13:04 ` Jan Beulich
2018-02-26 14:12 ` Roger Pau Monné
2018-02-23 13:27 ` [PATCH RFC 2/3] vhpet: add support for level triggered interrupts Roger Pau Monne
2018-02-23 13:27 ` [PATCH RFC 3/3] xtf: add minimal HPET functionality test Roger Pau Monne
2018-02-23 19:07 ` Wei Liu [this message]
2018-02-28 15:37 ` Roger Pau Monné
2018-02-28 16:24 ` Jan Beulich
2018-03-01 9:55 ` Roger Pau Monné
2018-03-01 10:04 ` Jan Beulich
2018-03-01 10:14 ` Roger Pau Monné
2018-03-01 10:22 ` Jan Beulich
2018-03-01 11:46 ` Andrew Cooper
2018-03-01 12:57 ` Jan Beulich
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180223190718.pfbszon36aamqelb@citrix.com \
--to=wei.liu2@citrix.com \
--cc=andrew.cooper3@citrix.com \
--cc=roger.pau@citrix.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).