Re: [Qemu-devel] [kvm-unit-tests PATCH v11 1/3] arm: Add PMU test
On 11/25/2016 08:26 AM, Andrew Jones wrote: > On Fri, Nov 25, 2016 at 12:32:24PM +, Andre Przywara wrote: >> Hi Drew, >> >> >> >> On 23/11/16 17:15, Andrew Jones wrote: > + > +#if defined(__arm__) I guess you should use the arch specific header files we have in place for that (lib/arm{.64}/asm/processor.h). Also there are sysreg read wrappers (at least for arm64) in there already, can't we base this function on them: DEFINE_GET_SYSREG32(pmcr, el0)? (Requires a small change to get rid of the forced "_el1" suffix) We should wait for the GIC series to be merged, as this contains some changes in this area. >>> >>> As this unit test is the only consumer of PMC registers so far, then >>> I'd prefer the defines and accessors stay here for now. Once we see >>> a use in other unit tests then we can move some of it out. >> >> Well, I was more thinking of something like below. >> I am fine with keeping the PMU sysregs private to pmu.c, but we can still >> use the sysreg wrappers, can't we? >> This is on top of Wei's series, so doesn't have your SYSREG32/64 >> unification, but I leave this as an exercise to the reader. >> There is some churn in pmu.c below due to the change of _write to >> set_, but the rest looks like simplification to me. >> >> Does that make sense? > > Ah, now I see what you mean, and I think I like that. The question is > whether or not I like my SYSREG macros :-) I see value in having the > asm's easy to read (open-coded), as well as value in making sure we > only have to review sysreg functions once. Let's ask for Wei's and > Cov's votes. If they like the SYSREG direction, then they can vote > with another version of this series :-) Let us use SYSREG macros then, because it makes coding easier. V13 has been sent. I think this PMU patcheset is a bit bloated now. So hopefully this is the last version. After it is accepted, we can always come back to re-factor SYSREG r/w further (if need). Thanks, -Wei > > Thanks, > drew > >> >> Cheers, >> Andre. >> >> --- >> arm/pmu.c | 159 >> +- >> lib/arm/asm/processor.h | 34 -- >> lib/arm64/asm/processor.h | 23 ++- >> 3 files changed, 92 insertions(+), 124 deletions(-) >> >> diff --git a/arm/pmu.c b/arm/pmu.c >> index f667676..f0ad02a 100644 >> --- a/arm/pmu.c >> +++ b/arm/pmu.c >> @@ -14,6 +14,7 @@ >> */ >> #include "libcflat.h" >> #include "asm/barrier.h" >> +#include "asm/processor.h" >> >> #define PMU_PMCR_E (1 << 0) >> #define PMU_PMCR_C (1 << 2) >> @@ -33,78 +34,42 @@ >> #define NR_SAMPLES 10 >> >> static unsigned int pmu_version; >> -#if defined(__arm__) >> -static inline uint32_t pmcr_read(void) >> -{ >> -uint32_t ret; >> - >> -asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r" (ret)); >> -return ret; >> -} >> - >> -static inline void pmcr_write(uint32_t value) >> -{ >> -asm volatile("mcr p15, 0, %0, c9, c12, 0" : : "r" (value)); >> -isb(); >> -} >> >> -static inline void pmselr_write(uint32_t value) >> -{ >> -asm volatile("mcr p15, 0, %0, c9, c12, 5" : : "r" (value)); >> -isb(); >> -} >> - >> -static inline void pmxevtyper_write(uint32_t value) >> -{ >> -asm volatile("mcr p15, 0, %0, c9, c13, 1" : : "r" (value)); >> -} >> - >> -static inline uint64_t pmccntr_read(void) >> +#if defined(__arm__) >> +DEFINE_GET_SYSREG32(pmcr, 0, c9, c12, 0) >> +DEFINE_SET_SYSREG32(pmcr, 0, c9, c12, 0) >> +DEFINE_GET_SYSREG32(id_dfr0, 0, c0, c1, 2) >> +DEFINE_SET_SYSREG32(pmselr, 0, c9, c12, 5) >> +DEFINE_SET_SYSREG32(pmxevtyper, 0, c9, c13, 1) >> +DEFINE_GET_SYSREG32(pmccntr32, 0, c9, c13, 0) >> +DEFINE_SET_SYSREG32(pmccntr32, 0, c9, c13, 0) >> +DEFINE_GET_SYSREG64(pmccntr64, 0, c9) >> +DEFINE_SET_SYSREG64(pmccntr64, 0, c9) >> +DEFINE_SET_SYSREG32(pmcntenset, 0, c9, c12, 1) >> + >> +static inline uint64_t get_pmccntr(void) >> { >> -uint32_t lo, hi = 0; >> - >> if (pmu_version == 0x3) >> -asm volatile("mrrc p15, 0, %0, %1, c9" : "=r" (lo), "=r" (hi)); >> +return get_pmccntr32(); >> else >> -asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (lo)); >> - >> -return ((uint64_t)hi << 32) | lo; >> +return get_pmccntr64(); >> } >> >> -static inline void pmccntr_write(uint64_t value) >> +static inline void set_pmccntr(uint64_t value) >> { >> -uint32_t lo, hi; >> - >> -lo = value & 0x; >> -hi = (value >> 32) & 0x; >> - >> if (pmu_version == 0x3) >> -asm volatile("mcrr p15, 0, %0, %1, c9" : : "r" (lo), "r" (hi)); >> +set_pmccntr64(value); >> else >> -asm volatile("mcr p15, 0, %0, c9, c13, 0" : : "r" (lo)); >> +set_pmccntr64(value & 0x); >> } >> - >> -static inline void pmcntenset_write(uint32_t value) >> -{ >> -asm volatile("mcr p15, 0, %0, c9, c12, 1" : : "r" (value)); >> -} >> - >> /* PMCCFILTR is an
Re: [Qemu-devel] [kvm-unit-tests PATCH v11 1/3] arm: Add PMU test
Hi, On 25/11/16 14:26, Andrew Jones wrote: > On Fri, Nov 25, 2016 at 12:32:24PM +, Andre Przywara wrote: >> Hi Drew, >> >> >> >> On 23/11/16 17:15, Andrew Jones wrote: > + > +#if defined(__arm__) I guess you should use the arch specific header files we have in place for that (lib/arm{.64}/asm/processor.h). Also there are sysreg read wrappers (at least for arm64) in there already, can't we base this function on them: DEFINE_GET_SYSREG32(pmcr, el0)? (Requires a small change to get rid of the forced "_el1" suffix) We should wait for the GIC series to be merged, as this contains some changes in this area. >>> >>> As this unit test is the only consumer of PMC registers so far, then >>> I'd prefer the defines and accessors stay here for now. Once we see >>> a use in other unit tests then we can move some of it out. >> >> Well, I was more thinking of something like below. >> I am fine with keeping the PMU sysregs private to pmu.c, but we can still >> use the sysreg wrappers, can't we? >> This is on top of Wei's series, so doesn't have your SYSREG32/64 >> unification, but I leave this as an exercise to the reader. >> There is some churn in pmu.c below due to the change of _write to >> set_, but the rest looks like simplification to me. >> >> Does that make sense? > > Ah, now I see what you mean, and I think I like that. The question is > whether or not I like my SYSREG macros :-) I see value in having the > asm's easy to read (open-coded), Mmh, where is this easy to read? Especially the v7 syntax is really error prone and hard to grasp with all these c9s, c12s and friends, in addition to the weird ordering and mixing in of register names in the (inline) assembly syntax. Blame the company that came up with this architecture ;-) Compare: mrc p15, 0, %0, c9, c12, 0 with: DEFINE_GET_SYSREG32(pmcr, 0, c9, c12, 0) The "0, %0" in there always kills me when reading this. On top of this a list of one-line-per-sysreg declarations is much easier to compare with the manual than the open coded versions. Another benefit is that we don't need to encode versions for both bitnesses in each test. For shared sysregs we could put the definitions in processor.h, the code then just uses one architecture agnostic version. But I leave it up to you guys to decide on this, you don't break my heart if you stick with inline assembly ;-) Cheers, Andre. as well as value in making sure we > only have to review sysreg functions once. Let's ask for Wei's and > Cov's votes. If they like the SYSREG direction, then they can vote > with another version of this series :-) > > Thanks, > drew > >> >> Cheers, >> Andre. >> >> --- >> arm/pmu.c | 159 >> +- >> lib/arm/asm/processor.h | 34 -- >> lib/arm64/asm/processor.h | 23 ++- >> 3 files changed, 92 insertions(+), 124 deletions(-) >> >> diff --git a/arm/pmu.c b/arm/pmu.c >> index f667676..f0ad02a 100644 >> --- a/arm/pmu.c >> +++ b/arm/pmu.c >> @@ -14,6 +14,7 @@ >> */ >> #include "libcflat.h" >> #include "asm/barrier.h" >> +#include "asm/processor.h" >> >> #define PMU_PMCR_E (1 << 0) >> #define PMU_PMCR_C (1 << 2) >> @@ -33,78 +34,42 @@ >> #define NR_SAMPLES 10 >> >> static unsigned int pmu_version; >> -#if defined(__arm__) >> -static inline uint32_t pmcr_read(void) >> -{ >> -uint32_t ret; >> - >> -asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r" (ret)); >> -return ret; >> -} >> - >> -static inline void pmcr_write(uint32_t value) >> -{ >> -asm volatile("mcr p15, 0, %0, c9, c12, 0" : : "r" (value)); >> -isb(); >> -} >> >> -static inline void pmselr_write(uint32_t value) >> -{ >> -asm volatile("mcr p15, 0, %0, c9, c12, 5" : : "r" (value)); >> -isb(); >> -} >> - >> -static inline void pmxevtyper_write(uint32_t value) >> -{ >> -asm volatile("mcr p15, 0, %0, c9, c13, 1" : : "r" (value)); >> -} >> - >> -static inline uint64_t pmccntr_read(void) >> +#if defined(__arm__) >> +DEFINE_GET_SYSREG32(pmcr, 0, c9, c12, 0) >> +DEFINE_SET_SYSREG32(pmcr, 0, c9, c12, 0) >> +DEFINE_GET_SYSREG32(id_dfr0, 0, c0, c1, 2) >> +DEFINE_SET_SYSREG32(pmselr, 0, c9, c12, 5) >> +DEFINE_SET_SYSREG32(pmxevtyper, 0, c9, c13, 1) >> +DEFINE_GET_SYSREG32(pmccntr32, 0, c9, c13, 0) >> +DEFINE_SET_SYSREG32(pmccntr32, 0, c9, c13, 0) >> +DEFINE_GET_SYSREG64(pmccntr64, 0, c9) >> +DEFINE_SET_SYSREG64(pmccntr64, 0, c9) >> +DEFINE_SET_SYSREG32(pmcntenset, 0, c9, c12, 1) >> + >> +static inline uint64_t get_pmccntr(void) >> { >> -uint32_t lo, hi = 0; >> - >> if (pmu_version == 0x3) >> -asm volatile("mrrc p15, 0, %0, %1, c9" : "=r" (lo), "=r" (hi)); >> +return get_pmccntr32(); >> else >> -asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (lo)); >> - >> -return ((uint64_t)hi << 32) | lo; >> +return get_pmccntr64(); >> } >> >> -static inline void pmccntr_write(uint64_t value)
Re: [Qemu-devel] [kvm-unit-tests PATCH v11 1/3] arm: Add PMU test
On Fri, Nov 25, 2016 at 12:32:24PM +, Andre Przywara wrote: > Hi Drew, > > > > On 23/11/16 17:15, Andrew Jones wrote: > >>> + > >>> +#if defined(__arm__) > >> > >> I guess you should use the arch specific header files we have in place > >> for that (lib/arm{.64}/asm/processor.h). Also there are sysreg read > >> wrappers (at least for arm64) in there already, can't we base this > >> function on them: DEFINE_GET_SYSREG32(pmcr, el0)? > >> (Requires a small change to get rid of the forced "_el1" suffix) > >> > >> We should wait for the GIC series to be merged, as this contains some > >> changes in this area. > > > > As this unit test is the only consumer of PMC registers so far, then > > I'd prefer the defines and accessors stay here for now. Once we see > > a use in other unit tests then we can move some of it out. > > Well, I was more thinking of something like below. > I am fine with keeping the PMU sysregs private to pmu.c, but we can still > use the sysreg wrappers, can't we? > This is on top of Wei's series, so doesn't have your SYSREG32/64 > unification, but I leave this as an exercise to the reader. > There is some churn in pmu.c below due to the change of _write to > set_, but the rest looks like simplification to me. > > Does that make sense? Ah, now I see what you mean, and I think I like that. The question is whether or not I like my SYSREG macros :-) I see value in having the asm's easy to read (open-coded), as well as value in making sure we only have to review sysreg functions once. Let's ask for Wei's and Cov's votes. If they like the SYSREG direction, then they can vote with another version of this series :-) Thanks, drew > > Cheers, > Andre. > > --- > arm/pmu.c | 159 > +- > lib/arm/asm/processor.h | 34 -- > lib/arm64/asm/processor.h | 23 ++- > 3 files changed, 92 insertions(+), 124 deletions(-) > > diff --git a/arm/pmu.c b/arm/pmu.c > index f667676..f0ad02a 100644 > --- a/arm/pmu.c > +++ b/arm/pmu.c > @@ -14,6 +14,7 @@ > */ > #include "libcflat.h" > #include "asm/barrier.h" > +#include "asm/processor.h" > > #define PMU_PMCR_E (1 << 0) > #define PMU_PMCR_C (1 << 2) > @@ -33,78 +34,42 @@ > #define NR_SAMPLES 10 > > static unsigned int pmu_version; > -#if defined(__arm__) > -static inline uint32_t pmcr_read(void) > -{ > - uint32_t ret; > - > - asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r" (ret)); > - return ret; > -} > - > -static inline void pmcr_write(uint32_t value) > -{ > - asm volatile("mcr p15, 0, %0, c9, c12, 0" : : "r" (value)); > - isb(); > -} > > -static inline void pmselr_write(uint32_t value) > -{ > - asm volatile("mcr p15, 0, %0, c9, c12, 5" : : "r" (value)); > - isb(); > -} > - > -static inline void pmxevtyper_write(uint32_t value) > -{ > - asm volatile("mcr p15, 0, %0, c9, c13, 1" : : "r" (value)); > -} > - > -static inline uint64_t pmccntr_read(void) > +#if defined(__arm__) > +DEFINE_GET_SYSREG32(pmcr, 0, c9, c12, 0) > +DEFINE_SET_SYSREG32(pmcr, 0, c9, c12, 0) > +DEFINE_GET_SYSREG32(id_dfr0, 0, c0, c1, 2) > +DEFINE_SET_SYSREG32(pmselr, 0, c9, c12, 5) > +DEFINE_SET_SYSREG32(pmxevtyper, 0, c9, c13, 1) > +DEFINE_GET_SYSREG32(pmccntr32, 0, c9, c13, 0) > +DEFINE_SET_SYSREG32(pmccntr32, 0, c9, c13, 0) > +DEFINE_GET_SYSREG64(pmccntr64, 0, c9) > +DEFINE_SET_SYSREG64(pmccntr64, 0, c9) > +DEFINE_SET_SYSREG32(pmcntenset, 0, c9, c12, 1) > + > +static inline uint64_t get_pmccntr(void) > { > - uint32_t lo, hi = 0; > - > if (pmu_version == 0x3) > - asm volatile("mrrc p15, 0, %0, %1, c9" : "=r" (lo), "=r" (hi)); > + return get_pmccntr32(); > else > - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (lo)); > - > - return ((uint64_t)hi << 32) | lo; > + return get_pmccntr64(); > } > > -static inline void pmccntr_write(uint64_t value) > +static inline void set_pmccntr(uint64_t value) > { > - uint32_t lo, hi; > - > - lo = value & 0x; > - hi = (value >> 32) & 0x; > - > if (pmu_version == 0x3) > - asm volatile("mcrr p15, 0, %0, %1, c9" : : "r" (lo), "r" (hi)); > + set_pmccntr64(value); > else > - asm volatile("mcr p15, 0, %0, c9, c13, 0" : : "r" (lo)); > + set_pmccntr64(value & 0x); > } > - > -static inline void pmcntenset_write(uint32_t value) > -{ > - asm volatile("mcr p15, 0, %0, c9, c12, 1" : : "r" (value)); > -} > - > /* PMCCFILTR is an obsolete name for PMXEVTYPER31 in ARMv7 */ > -static inline void pmccfiltr_write(uint32_t value) > +static inline void set_pmccfiltr(uint32_t value) > { > - pmselr_write(PMU_CYCLE_IDX); > - pmxevtyper_write(value); > + set_pmselr(PMU_CYCLE_IDX); > + set_pmxevtyper(value); > isb(); > } > > -static inline uint32_t id_dfr0_read(void) > -{ > - uint32_t val; > - > - asm volatile("mrc p15, 0, %0, c0,
Re: [Qemu-devel] [kvm-unit-tests PATCH v11 1/3] arm: Add PMU test
Hi Drew, On 23/11/16 17:15, Andrew Jones wrote: >>> + >>> +#if defined(__arm__) >> >> I guess you should use the arch specific header files we have in place >> for that (lib/arm{.64}/asm/processor.h). Also there are sysreg read >> wrappers (at least for arm64) in there already, can't we base this >> function on them: DEFINE_GET_SYSREG32(pmcr, el0)? >> (Requires a small change to get rid of the forced "_el1" suffix) >> >> We should wait for the GIC series to be merged, as this contains some >> changes in this area. > > As this unit test is the only consumer of PMC registers so far, then > I'd prefer the defines and accessors stay here for now. Once we see > a use in other unit tests then we can move some of it out. Well, I was more thinking of something like below. I am fine with keeping the PMU sysregs private to pmu.c, but we can still use the sysreg wrappers, can't we? This is on top of Wei's series, so doesn't have your SYSREG32/64 unification, but I leave this as an exercise to the reader. There is some churn in pmu.c below due to the change of _write to set_, but the rest looks like simplification to me. Does that make sense? Cheers, Andre. --- arm/pmu.c | 159 +- lib/arm/asm/processor.h | 34 -- lib/arm64/asm/processor.h | 23 ++- 3 files changed, 92 insertions(+), 124 deletions(-) diff --git a/arm/pmu.c b/arm/pmu.c index f667676..f0ad02a 100644 --- a/arm/pmu.c +++ b/arm/pmu.c @@ -14,6 +14,7 @@ */ #include "libcflat.h" #include "asm/barrier.h" +#include "asm/processor.h" #define PMU_PMCR_E (1 << 0) #define PMU_PMCR_C (1 << 2) @@ -33,78 +34,42 @@ #define NR_SAMPLES 10 static unsigned int pmu_version; -#if defined(__arm__) -static inline uint32_t pmcr_read(void) -{ - uint32_t ret; - - asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r" (ret)); - return ret; -} - -static inline void pmcr_write(uint32_t value) -{ - asm volatile("mcr p15, 0, %0, c9, c12, 0" : : "r" (value)); - isb(); -} -static inline void pmselr_write(uint32_t value) -{ - asm volatile("mcr p15, 0, %0, c9, c12, 5" : : "r" (value)); - isb(); -} - -static inline void pmxevtyper_write(uint32_t value) -{ - asm volatile("mcr p15, 0, %0, c9, c13, 1" : : "r" (value)); -} - -static inline uint64_t pmccntr_read(void) +#if defined(__arm__) +DEFINE_GET_SYSREG32(pmcr, 0, c9, c12, 0) +DEFINE_SET_SYSREG32(pmcr, 0, c9, c12, 0) +DEFINE_GET_SYSREG32(id_dfr0, 0, c0, c1, 2) +DEFINE_SET_SYSREG32(pmselr, 0, c9, c12, 5) +DEFINE_SET_SYSREG32(pmxevtyper, 0, c9, c13, 1) +DEFINE_GET_SYSREG32(pmccntr32, 0, c9, c13, 0) +DEFINE_SET_SYSREG32(pmccntr32, 0, c9, c13, 0) +DEFINE_GET_SYSREG64(pmccntr64, 0, c9) +DEFINE_SET_SYSREG64(pmccntr64, 0, c9) +DEFINE_SET_SYSREG32(pmcntenset, 0, c9, c12, 1) + +static inline uint64_t get_pmccntr(void) { - uint32_t lo, hi = 0; - if (pmu_version == 0x3) - asm volatile("mrrc p15, 0, %0, %1, c9" : "=r" (lo), "=r" (hi)); + return get_pmccntr32(); else - asm volatile("mrc p15, 0, %0, c9, c13, 0" : "=r" (lo)); - - return ((uint64_t)hi << 32) | lo; + return get_pmccntr64(); } -static inline void pmccntr_write(uint64_t value) +static inline void set_pmccntr(uint64_t value) { - uint32_t lo, hi; - - lo = value & 0x; - hi = (value >> 32) & 0x; - if (pmu_version == 0x3) - asm volatile("mcrr p15, 0, %0, %1, c9" : : "r" (lo), "r" (hi)); + set_pmccntr64(value); else - asm volatile("mcr p15, 0, %0, c9, c13, 0" : : "r" (lo)); + set_pmccntr64(value & 0x); } - -static inline void pmcntenset_write(uint32_t value) -{ - asm volatile("mcr p15, 0, %0, c9, c12, 1" : : "r" (value)); -} - /* PMCCFILTR is an obsolete name for PMXEVTYPER31 in ARMv7 */ -static inline void pmccfiltr_write(uint32_t value) +static inline void set_pmccfiltr(uint32_t value) { - pmselr_write(PMU_CYCLE_IDX); - pmxevtyper_write(value); + set_pmselr(PMU_CYCLE_IDX); + set_pmxevtyper(value); isb(); } -static inline uint32_t id_dfr0_read(void) -{ - uint32_t val; - - asm volatile("mrc p15, 0, %0, c0, c1, 2" : "=r" (val)); - return val; -} - /* * Extra instructions inserted by the compiler would be difficult to compensate * for, so hand assemble everything between, and including, the PMCR accesses @@ -126,51 +91,13 @@ static inline void precise_instrs_loop(int loop, uint32_t pmcr) : "cc"); } #elif defined(__aarch64__) -static inline uint32_t pmcr_read(void) -{ - uint32_t ret; - - asm volatile("mrs %0, pmcr_el0" : "=r" (ret)); - return ret; -} - -static inline void pmcr_write(uint32_t value) -{ - asm volatile("msr pmcr_el0, %0" : : "r" (value)); - isb(); -} - -static inline uint64_t pmccntr_read(void) -{ - uint64_t cycles; -
Re: [Qemu-devel] [kvm-unit-tests PATCH v11 1/3] arm: Add PMU test
On 11/23/2016 11:15 AM, Andrew Jones wrote: > On Wed, Nov 23, 2016 at 01:16:08PM +, Andre Przywara wrote: >> Hi, >> >> On 22/11/16 18:29, Wei Huang wrote: >>> From: Christopher Covington>>> >>> Beginning with a simple sanity check of the control register, add >>> a unit test for the ARM Performance Monitors Unit (PMU). >> >> Mmh, the output of this is a bit confusing. How about to join some >> information? I changed it to give me: >> INFO: pmu: PMU implementer/ID code: "A"(0x41)/0x0 >> INFO: pmu: Event counters: 0 >> PASS: pmu: Control register >> >> ... by using the newly introduced report_info() to make it look nicer. > > Agreed. That would look nicer and make good use of report_info. Let's > do that. I have adjusted v12 using report_info(), with all PMU PMCR fields printed in the same line. Implementer info was printed with Hex first, then ASCII representation, to match MIDR table in ARM manual: INFO: pmu: PMU implementer/ID code/counters: 0x41("A")/0x1/6 > >> >>> >>> Signed-off-by: Christopher Covington >>> Signed-off-by: Wei Huang >>> Reviewed-by: Andrew Jones >>> --- >>> arm/Makefile.common | 3 ++- >>> arm/pmu.c | 74 >>> + >>> arm/unittests.cfg | 5 >>> 3 files changed, 81 insertions(+), 1 deletion(-) >>> create mode 100644 arm/pmu.c >>> >>> diff --git a/arm/Makefile.common b/arm/Makefile.common >>> index f37b5c2..5da2fdd 100644 >>> --- a/arm/Makefile.common >>> +++ b/arm/Makefile.common >>> @@ -12,7 +12,8 @@ endif >>> tests-common = \ >>> $(TEST_DIR)/selftest.flat \ >>> $(TEST_DIR)/spinlock-test.flat \ >>> - $(TEST_DIR)/pci-test.flat >>> + $(TEST_DIR)/pci-test.flat \ >>> + $(TEST_DIR)/pmu.flat >>> >>> all: test_cases >>> >>> diff --git a/arm/pmu.c b/arm/pmu.c >>> new file mode 100644 >>> index 000..9d9c53b >>> --- /dev/null >>> +++ b/arm/pmu.c >>> @@ -0,0 +1,74 @@ >>> +/* >>> + * Test the ARM Performance Monitors Unit (PMU). >>> + * >>> + * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. >>> + * >>> + * This program is free software; you can redistribute it and/or modify it >>> + * under the terms of the GNU Lesser General Public License version 2.1 and >>> + * only version 2.1 as published by the Free Software Foundation. >>> + * >>> + * This program is distributed in the hope that it will be useful, but >>> WITHOUT >>> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or >>> + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public >>> License >>> + * for more details. >>> + */ >>> +#include "libcflat.h" >>> +#include "asm/barrier.h" >>> + >>> +#define PMU_PMCR_N_SHIFT 11 >>> +#define PMU_PMCR_N_MASK0x1f >>> +#define PMU_PMCR_ID_SHIFT 16 >>> +#define PMU_PMCR_ID_MASK 0xff >>> +#define PMU_PMCR_IMP_SHIFT 24 >>> +#define PMU_PMCR_IMP_MASK 0xff >>> + >>> +#if defined(__arm__) >> >> I guess you should use the arch specific header files we have in place >> for that (lib/arm{.64}/asm/processor.h). Also there are sysreg read >> wrappers (at least for arm64) in there already, can't we base this >> function on them: DEFINE_GET_SYSREG32(pmcr, el0)? >> (Requires a small change to get rid of the forced "_el1" suffix) >> >> We should wait for the GIC series to be merged, as this contains some >> changes in this area. > > As this unit test is the only consumer of PMC registers so far, then > I'd prefer the defines and accessors stay here for now. Once we see > a use in other unit tests then we can move some of it out. I left accessors in-place. We can always come back to refactor them later. > >> >>> +static inline uint32_t pmcr_read(void) >>> +{ >>> + uint32_t ret; >>> + >>> + asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r" (ret)); >>> + return ret; >>> +} >>> +#elif defined(__aarch64__) >>> +static inline uint32_t pmcr_read(void) >>> +{ >>> + uint32_t ret; >>> + >>> + asm volatile("mrs %0, pmcr_el0" : "=r" (ret)); >>> + return ret; >>> +} >>> +#endif >>> + >>> +/* >>> + * As a simple sanity check on the PMCR_EL0, ensure the implementer field >>> isn't >>> + * null. Also print out a couple other interesting fields for diagnostic >>> + * purposes. For example, as of fall 2016, QEMU TCG mode doesn't implement >>> + * event counters and therefore reports zero event counters, but hopefully >>> + * support for at least the instructions event will be added in the future >>> and >>> + * the reported number of event counters will become nonzero. >>> + */ >>> +static bool check_pmcr(void) >>> +{ >>> + uint32_t pmcr; >>> + >>> + pmcr = pmcr_read(); >>> + >>> + printf("PMU implementer: %c\n", >>> + (pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK); >> >> If this register reads as zero, the output is mangled (since it cuts off >> the string before the newline): >> = >> PMU implementer: Identification code:
Re: [Qemu-devel] [kvm-unit-tests PATCH v11 1/3] arm: Add PMU test
On Wed, Nov 23, 2016 at 01:16:08PM +, Andre Przywara wrote: > Hi, > > On 22/11/16 18:29, Wei Huang wrote: > > From: Christopher Covington> > > > Beginning with a simple sanity check of the control register, add > > a unit test for the ARM Performance Monitors Unit (PMU). > > Mmh, the output of this is a bit confusing. How about to join some > information? I changed it to give me: > INFO: pmu: PMU implementer/ID code: "A"(0x41)/0x0 > INFO: pmu: Event counters: 0 > PASS: pmu: Control register > > ... by using the newly introduced report_info() to make it look nicer. Agreed. That would look nicer and make good use of report_info. Let's do that. > > > > > Signed-off-by: Christopher Covington > > Signed-off-by: Wei Huang > > Reviewed-by: Andrew Jones > > --- > > arm/Makefile.common | 3 ++- > > arm/pmu.c | 74 > > + > > arm/unittests.cfg | 5 > > 3 files changed, 81 insertions(+), 1 deletion(-) > > create mode 100644 arm/pmu.c > > > > diff --git a/arm/Makefile.common b/arm/Makefile.common > > index f37b5c2..5da2fdd 100644 > > --- a/arm/Makefile.common > > +++ b/arm/Makefile.common > > @@ -12,7 +12,8 @@ endif > > tests-common = \ > > $(TEST_DIR)/selftest.flat \ > > $(TEST_DIR)/spinlock-test.flat \ > > - $(TEST_DIR)/pci-test.flat > > + $(TEST_DIR)/pci-test.flat \ > > + $(TEST_DIR)/pmu.flat > > > > all: test_cases > > > > diff --git a/arm/pmu.c b/arm/pmu.c > > new file mode 100644 > > index 000..9d9c53b > > --- /dev/null > > +++ b/arm/pmu.c > > @@ -0,0 +1,74 @@ > > +/* > > + * Test the ARM Performance Monitors Unit (PMU). > > + * > > + * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. > > + * > > + * This program is free software; you can redistribute it and/or modify it > > + * under the terms of the GNU Lesser General Public License version 2.1 and > > + * only version 2.1 as published by the Free Software Foundation. > > + * > > + * This program is distributed in the hope that it will be useful, but > > WITHOUT > > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > > + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public > > License > > + * for more details. > > + */ > > +#include "libcflat.h" > > +#include "asm/barrier.h" > > + > > +#define PMU_PMCR_N_SHIFT 11 > > +#define PMU_PMCR_N_MASK0x1f > > +#define PMU_PMCR_ID_SHIFT 16 > > +#define PMU_PMCR_ID_MASK 0xff > > +#define PMU_PMCR_IMP_SHIFT 24 > > +#define PMU_PMCR_IMP_MASK 0xff > > + > > +#if defined(__arm__) > > I guess you should use the arch specific header files we have in place > for that (lib/arm{.64}/asm/processor.h). Also there are sysreg read > wrappers (at least for arm64) in there already, can't we base this > function on them: DEFINE_GET_SYSREG32(pmcr, el0)? > (Requires a small change to get rid of the forced "_el1" suffix) > > We should wait for the GIC series to be merged, as this contains some > changes in this area. As this unit test is the only consumer of PMC registers so far, then I'd prefer the defines and accessors stay here for now. Once we see a use in other unit tests then we can move some of it out. > > > +static inline uint32_t pmcr_read(void) > > +{ > > + uint32_t ret; > > + > > + asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r" (ret)); > > + return ret; > > +} > > +#elif defined(__aarch64__) > > +static inline uint32_t pmcr_read(void) > > +{ > > + uint32_t ret; > > + > > + asm volatile("mrs %0, pmcr_el0" : "=r" (ret)); > > + return ret; > > +} > > +#endif > > + > > +/* > > + * As a simple sanity check on the PMCR_EL0, ensure the implementer field > > isn't > > + * null. Also print out a couple other interesting fields for diagnostic > > + * purposes. For example, as of fall 2016, QEMU TCG mode doesn't implement > > + * event counters and therefore reports zero event counters, but hopefully > > + * support for at least the instructions event will be added in the future > > and > > + * the reported number of event counters will become nonzero. > > + */ > > +static bool check_pmcr(void) > > +{ > > + uint32_t pmcr; > > + > > + pmcr = pmcr_read(); > > + > > + printf("PMU implementer: %c\n", > > + (pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK); > > If this register reads as zero, the output is mangled (since it cuts off > the string before the newline): > = > PMU implementer: Identification code: 0x0 > = > > I guess you need something like: > (pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK ?: ' ' Good idea. > > > + printf("Identification code: 0x%x\n", > > + (pmcr >> PMU_PMCR_ID_SHIFT) & PMU_PMCR_ID_MASK); > > As mentioned above this should use report_info() now, also it would be > nice to merge this with the message above into one line of output. Agreed. Thanks, drew > > Cheers, > Andre >
Re: [kvm-unit-tests PATCH v11 1/3] arm: Add PMU test
On 11/23/2016 07:16 AM, Andre Przywara wrote: > Hi, > > On 22/11/16 18:29, Wei Huang wrote: >> From: Christopher Covington>> >> Beginning with a simple sanity check of the control register, add >> a unit test for the ARM Performance Monitors Unit (PMU). > > Mmh, the output of this is a bit confusing. How about to join some > information? I changed it to give me: > INFO: pmu: PMU implementer/ID code: "A"(0x41)/0x0 > INFO: pmu: Event counters: 0 > PASS: pmu: Control register > > ... by using the newly introduced report_info() to make it look nicer. > >> >> Signed-off-by: Christopher Covington >> Signed-off-by: Wei Huang >> Reviewed-by: Andrew Jones >> --- >> arm/Makefile.common | 3 ++- >> arm/pmu.c | 74 >> + >> arm/unittests.cfg | 5 >> 3 files changed, 81 insertions(+), 1 deletion(-) >> create mode 100644 arm/pmu.c >> >> diff --git a/arm/Makefile.common b/arm/Makefile.common >> index f37b5c2..5da2fdd 100644 >> --- a/arm/Makefile.common >> +++ b/arm/Makefile.common >> @@ -12,7 +12,8 @@ endif >> tests-common = \ >> $(TEST_DIR)/selftest.flat \ >> $(TEST_DIR)/spinlock-test.flat \ >> -$(TEST_DIR)/pci-test.flat >> +$(TEST_DIR)/pci-test.flat \ >> +$(TEST_DIR)/pmu.flat >> >> all: test_cases >> >> diff --git a/arm/pmu.c b/arm/pmu.c >> new file mode 100644 >> index 000..9d9c53b >> --- /dev/null >> +++ b/arm/pmu.c >> @@ -0,0 +1,74 @@ >> +/* >> + * Test the ARM Performance Monitors Unit (PMU). >> + * >> + * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. >> + * >> + * This program is free software; you can redistribute it and/or modify it >> + * under the terms of the GNU Lesser General Public License version 2.1 and >> + * only version 2.1 as published by the Free Software Foundation. >> + * >> + * This program is distributed in the hope that it will be useful, but >> WITHOUT >> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or >> + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public >> License >> + * for more details. >> + */ >> +#include "libcflat.h" >> +#include "asm/barrier.h" >> + >> +#define PMU_PMCR_N_SHIFT 11 >> +#define PMU_PMCR_N_MASK0x1f >> +#define PMU_PMCR_ID_SHIFT 16 >> +#define PMU_PMCR_ID_MASK 0xff >> +#define PMU_PMCR_IMP_SHIFT 24 >> +#define PMU_PMCR_IMP_MASK 0xff >> + >> +#if defined(__arm__) > > I guess you should use the arch specific header files we have in place > for that (lib/arm{.64}/asm/processor.h). Also there are sysreg read > wrappers (at least for arm64) in there already, can't we base this > function on them: DEFINE_GET_SYSREG32(pmcr, el0)? > (Requires a small change to get rid of the forced "_el1" suffix) > > We should wait for the GIC series to be merged, as this contains some > changes in this area. We planned to add it after this series is merged. However if GIC series has a similar support, we can piggy-back on it. > >> +static inline uint32_t pmcr_read(void) >> +{ >> +uint32_t ret; >> + >> +asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r" (ret)); >> +return ret; >> +} >> +#elif defined(__aarch64__) >> +static inline uint32_t pmcr_read(void) >> +{ >> +uint32_t ret; >> + >> +asm volatile("mrs %0, pmcr_el0" : "=r" (ret)); >> +return ret; >> +} >> +#endif >> + >> +/* >> + * As a simple sanity check on the PMCR_EL0, ensure the implementer field >> isn't >> + * null. Also print out a couple other interesting fields for diagnostic >> + * purposes. For example, as of fall 2016, QEMU TCG mode doesn't implement >> + * event counters and therefore reports zero event counters, but hopefully >> + * support for at least the instructions event will be added in the future >> and >> + * the reported number of event counters will become nonzero. >> + */ >> +static bool check_pmcr(void) >> +{ >> +uint32_t pmcr; >> + >> +pmcr = pmcr_read(); >> + >> +printf("PMU implementer: %c\n", >> + (pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK); > > If this register reads as zero, the output is mangled (since it cuts off > the string before the newline): > = > PMU implementer: Identification code: 0x0 > = > > I guess you need something like: > (pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK ?: ' ' > >> +printf("Identification code: 0x%x\n", >> + (pmcr >> PMU_PMCR_ID_SHIFT) & PMU_PMCR_ID_MASK); > > As mentioned above this should use report_info() now, also it would be > nice to merge this with the message above into one line of output. I will take them into consideration. Thanks. > > Cheers, > Andre > >> +printf("Event counters: %d\n", >> + (pmcr >> PMU_PMCR_N_SHIFT) & PMU_PMCR_N_MASK); >> + >> +return ((pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK) != 0; >> +} >> + >> +int main(void) >> +{ >> +
Re: [kvm-unit-tests PATCH v11 1/3] arm: Add PMU test
Hi, On 22/11/16 18:29, Wei Huang wrote: > From: Christopher Covington> > Beginning with a simple sanity check of the control register, add > a unit test for the ARM Performance Monitors Unit (PMU). Mmh, the output of this is a bit confusing. How about to join some information? I changed it to give me: INFO: pmu: PMU implementer/ID code: "A"(0x41)/0x0 INFO: pmu: Event counters: 0 PASS: pmu: Control register ... by using the newly introduced report_info() to make it look nicer. > > Signed-off-by: Christopher Covington > Signed-off-by: Wei Huang > Reviewed-by: Andrew Jones > --- > arm/Makefile.common | 3 ++- > arm/pmu.c | 74 > + > arm/unittests.cfg | 5 > 3 files changed, 81 insertions(+), 1 deletion(-) > create mode 100644 arm/pmu.c > > diff --git a/arm/Makefile.common b/arm/Makefile.common > index f37b5c2..5da2fdd 100644 > --- a/arm/Makefile.common > +++ b/arm/Makefile.common > @@ -12,7 +12,8 @@ endif > tests-common = \ > $(TEST_DIR)/selftest.flat \ > $(TEST_DIR)/spinlock-test.flat \ > - $(TEST_DIR)/pci-test.flat > + $(TEST_DIR)/pci-test.flat \ > + $(TEST_DIR)/pmu.flat > > all: test_cases > > diff --git a/arm/pmu.c b/arm/pmu.c > new file mode 100644 > index 000..9d9c53b > --- /dev/null > +++ b/arm/pmu.c > @@ -0,0 +1,74 @@ > +/* > + * Test the ARM Performance Monitors Unit (PMU). > + * > + * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. > + * > + * This program is free software; you can redistribute it and/or modify it > + * under the terms of the GNU Lesser General Public License version 2.1 and > + * only version 2.1 as published by the Free Software Foundation. > + * > + * This program is distributed in the hope that it will be useful, but > WITHOUT > + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or > + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public > License > + * for more details. > + */ > +#include "libcflat.h" > +#include "asm/barrier.h" > + > +#define PMU_PMCR_N_SHIFT 11 > +#define PMU_PMCR_N_MASK0x1f > +#define PMU_PMCR_ID_SHIFT 16 > +#define PMU_PMCR_ID_MASK 0xff > +#define PMU_PMCR_IMP_SHIFT 24 > +#define PMU_PMCR_IMP_MASK 0xff > + > +#if defined(__arm__) I guess you should use the arch specific header files we have in place for that (lib/arm{.64}/asm/processor.h). Also there are sysreg read wrappers (at least for arm64) in there already, can't we base this function on them: DEFINE_GET_SYSREG32(pmcr, el0)? (Requires a small change to get rid of the forced "_el1" suffix) We should wait for the GIC series to be merged, as this contains some changes in this area. > +static inline uint32_t pmcr_read(void) > +{ > + uint32_t ret; > + > + asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r" (ret)); > + return ret; > +} > +#elif defined(__aarch64__) > +static inline uint32_t pmcr_read(void) > +{ > + uint32_t ret; > + > + asm volatile("mrs %0, pmcr_el0" : "=r" (ret)); > + return ret; > +} > +#endif > + > +/* > + * As a simple sanity check on the PMCR_EL0, ensure the implementer field > isn't > + * null. Also print out a couple other interesting fields for diagnostic > + * purposes. For example, as of fall 2016, QEMU TCG mode doesn't implement > + * event counters and therefore reports zero event counters, but hopefully > + * support for at least the instructions event will be added in the future > and > + * the reported number of event counters will become nonzero. > + */ > +static bool check_pmcr(void) > +{ > + uint32_t pmcr; > + > + pmcr = pmcr_read(); > + > + printf("PMU implementer: %c\n", > +(pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK); If this register reads as zero, the output is mangled (since it cuts off the string before the newline): = PMU implementer: Identification code: 0x0 = I guess you need something like: (pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK ?: ' ' > + printf("Identification code: 0x%x\n", > +(pmcr >> PMU_PMCR_ID_SHIFT) & PMU_PMCR_ID_MASK); As mentioned above this should use report_info() now, also it would be nice to merge this with the message above into one line of output. Cheers, Andre > + printf("Event counters: %d\n", > +(pmcr >> PMU_PMCR_N_SHIFT) & PMU_PMCR_N_MASK); > + > + return ((pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK) != 0; > +} > + > +int main(void) > +{ > + report_prefix_push("pmu"); > + > + report("Control register", check_pmcr()); > + > + return report_summary(); > +} > diff --git a/arm/unittests.cfg b/arm/unittests.cfg > index ae32a42..816f494 100644 > --- a/arm/unittests.cfg > +++ b/arm/unittests.cfg > @@ -58,3 +58,8 @@ groups = selftest > [pci-test] > file = pci-test.flat > groups = pci > + > +# Test PMU support > +[pmu] > +file =
[kvm-unit-tests PATCH v11 1/3] arm: Add PMU test
From: Christopher CovingtonBeginning with a simple sanity check of the control register, add a unit test for the ARM Performance Monitors Unit (PMU). Signed-off-by: Christopher Covington Signed-off-by: Wei Huang Reviewed-by: Andrew Jones --- arm/Makefile.common | 3 ++- arm/pmu.c | 74 + arm/unittests.cfg | 5 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 arm/pmu.c diff --git a/arm/Makefile.common b/arm/Makefile.common index f37b5c2..5da2fdd 100644 --- a/arm/Makefile.common +++ b/arm/Makefile.common @@ -12,7 +12,8 @@ endif tests-common = \ $(TEST_DIR)/selftest.flat \ $(TEST_DIR)/spinlock-test.flat \ - $(TEST_DIR)/pci-test.flat + $(TEST_DIR)/pci-test.flat \ + $(TEST_DIR)/pmu.flat all: test_cases diff --git a/arm/pmu.c b/arm/pmu.c new file mode 100644 index 000..9d9c53b --- /dev/null +++ b/arm/pmu.c @@ -0,0 +1,74 @@ +/* + * Test the ARM Performance Monitors Unit (PMU). + * + * Copyright (c) 2015-2016, The Linux Foundation. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 2.1 and + * only version 2.1 as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + */ +#include "libcflat.h" +#include "asm/barrier.h" + +#define PMU_PMCR_N_SHIFT 11 +#define PMU_PMCR_N_MASK0x1f +#define PMU_PMCR_ID_SHIFT 16 +#define PMU_PMCR_ID_MASK 0xff +#define PMU_PMCR_IMP_SHIFT 24 +#define PMU_PMCR_IMP_MASK 0xff + +#if defined(__arm__) +static inline uint32_t pmcr_read(void) +{ + uint32_t ret; + + asm volatile("mrc p15, 0, %0, c9, c12, 0" : "=r" (ret)); + return ret; +} +#elif defined(__aarch64__) +static inline uint32_t pmcr_read(void) +{ + uint32_t ret; + + asm volatile("mrs %0, pmcr_el0" : "=r" (ret)); + return ret; +} +#endif + +/* + * As a simple sanity check on the PMCR_EL0, ensure the implementer field isn't + * null. Also print out a couple other interesting fields for diagnostic + * purposes. For example, as of fall 2016, QEMU TCG mode doesn't implement + * event counters and therefore reports zero event counters, but hopefully + * support for at least the instructions event will be added in the future and + * the reported number of event counters will become nonzero. + */ +static bool check_pmcr(void) +{ + uint32_t pmcr; + + pmcr = pmcr_read(); + + printf("PMU implementer: %c\n", + (pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK); + printf("Identification code: 0x%x\n", + (pmcr >> PMU_PMCR_ID_SHIFT) & PMU_PMCR_ID_MASK); + printf("Event counters: %d\n", + (pmcr >> PMU_PMCR_N_SHIFT) & PMU_PMCR_N_MASK); + + return ((pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK) != 0; +} + +int main(void) +{ + report_prefix_push("pmu"); + + report("Control register", check_pmcr()); + + return report_summary(); +} diff --git a/arm/unittests.cfg b/arm/unittests.cfg index ae32a42..816f494 100644 --- a/arm/unittests.cfg +++ b/arm/unittests.cfg @@ -58,3 +58,8 @@ groups = selftest [pci-test] file = pci-test.flat groups = pci + +# Test PMU support +[pmu] +file = pmu.flat +groups = pmu -- 1.8.3.1 ___ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm