It is helpful to vary the number of the LCOFI interrupts generated
by the overflow test. Allow additional argument for overflow test
to accommodate that. It can be easily cross-validated with
/proc/interrupts output in the host.
Signed-off-by: Atish Patra <atishp@rivosinc.com>
---
tools/testing/selftests/kvm/riscv/sbi_pmu_test.c | 36 ++++++++++++++++++++----
1 file changed, 30 insertions(+), 6 deletions(-)
diff --git a/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c b/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c
index 533b76d0de82..7c273a1adb17 100644
--- a/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c
+++ b/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c
@@ -39,8 +39,10 @@ static bool illegal_handler_invoked;
#define SBI_PMU_TEST_SNAPSHOT BIT(2)
#define SBI_PMU_TEST_OVERFLOW BIT(3)
+#define SBI_PMU_OVERFLOW_IRQNUM_DEFAULT 5
struct test_args {
int disabled_tests;
+ int overflow_irqnum;
};
static struct test_args targs;
@@ -478,7 +480,7 @@ static void test_pmu_events_snaphost(void)
static void test_pmu_events_overflow(void)
{
- int num_counters = 0;
+ int num_counters = 0, i = 0;
/* Verify presence of SBI PMU and minimum requrired SBI version */
verify_sbi_requirement_assert();
@@ -495,11 +497,15 @@ static void test_pmu_events_overflow(void)
* Qemu supports overflow for cycle/instruction.
* This test may fail on any platform that do not support overflow for these two events.
*/
- test_pmu_event_overflow(SBI_PMU_HW_CPU_CYCLES);
- GUEST_ASSERT_EQ(vcpu_shared_irq_count, 1);
+ for (i = 0; i < targs.overflow_irqnum; i++)
+ test_pmu_event_overflow(SBI_PMU_HW_CPU_CYCLES);
+ GUEST_ASSERT_EQ(vcpu_shared_irq_count, targs.overflow_irqnum);
+
+ vcpu_shared_irq_count = 0;
- test_pmu_event_overflow(SBI_PMU_HW_INSTRUCTIONS);
- GUEST_ASSERT_EQ(vcpu_shared_irq_count, 2);
+ for (i = 0; i < targs.overflow_irqnum; i++)
+ test_pmu_event_overflow(SBI_PMU_HW_INSTRUCTIONS);
+ GUEST_ASSERT_EQ(vcpu_shared_irq_count, targs.overflow_irqnum);
GUEST_DONE();
}
@@ -621,8 +627,11 @@ static void test_vm_events_overflow(void *guest_code)
static void test_print_help(char *name)
{
- pr_info("Usage: %s [-h] [-t <test name>]\n", name);
+ pr_info("Usage: %s [-h] [-t <test name>] [-n <number of LCOFI interrupt for overflow test>]\n",
+ name);
pr_info("\t-t: Test to run (default all). Available tests are 'basic', 'events', 'snapshot', 'overflow'\n");
+ pr_info("\t-n: Number of LCOFI interrupt to trigger for each event in overflow test (default: %d)\n",
+ SBI_PMU_OVERFLOW_IRQNUM_DEFAULT);
pr_info("\t-h: print this help screen\n");
}
@@ -631,6 +640,8 @@ static bool parse_args(int argc, char *argv[])
int opt;
int temp_disabled_tests = SBI_PMU_TEST_BASIC | SBI_PMU_TEST_EVENTS | SBI_PMU_TEST_SNAPSHOT |
SBI_PMU_TEST_OVERFLOW;
+ int overflow_interrupts = -1;
+
while ((opt = getopt(argc, argv, "h:t:n:")) != -1) {
switch (opt) {
case 't':
@@ -646,12 +657,24 @@ static bool parse_args(int argc, char *argv[])
goto done;
targs.disabled_tests = temp_disabled_tests;
break;
+ case 'n':
+ overflow_interrupts = atoi_positive("Number of LCOFI", optarg);
+ break;
case 'h':
default:
goto done;
}
}
+ if (overflow_interrupts > 0) {
+ if (targs.disabled_tests & SBI_PMU_TEST_OVERFLOW) {
+ pr_info("-n option is only available for overflow test\n");
+ goto done;
+ } else {
+ targs.overflow_irqnum = overflow_interrupts;
+ }
+ }
+
return true;
done:
test_print_help(argv[0]);
@@ -661,6 +684,7 @@ static bool parse_args(int argc, char *argv[])
int main(int argc, char *argv[])
{
targs.disabled_tests = 0;
+ targs.overflow_irqnum = SBI_PMU_OVERFLOW_IRQNUM_DEFAULT;
if (!parse_args(argc, argv))
exit(KSFT_SKIP);
--
2.43.0
On Wed, Feb 26, 2025 at 12:25:06PM -0800, Atish Patra wrote:
> It is helpful to vary the number of the LCOFI interrupts generated
> by the overflow test. Allow additional argument for overflow test
> to accommodate that. It can be easily cross-validated with
> /proc/interrupts output in the host.
>
> Signed-off-by: Atish Patra <atishp@rivosinc.com>
> ---
> tools/testing/selftests/kvm/riscv/sbi_pmu_test.c | 36 ++++++++++++++++++++----
> 1 file changed, 30 insertions(+), 6 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c b/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c
> index 533b76d0de82..7c273a1adb17 100644
> --- a/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c
> +++ b/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c
> @@ -39,8 +39,10 @@ static bool illegal_handler_invoked;
> #define SBI_PMU_TEST_SNAPSHOT BIT(2)
> #define SBI_PMU_TEST_OVERFLOW BIT(3)
>
> +#define SBI_PMU_OVERFLOW_IRQNUM_DEFAULT 5
> struct test_args {
> int disabled_tests;
> + int overflow_irqnum;
> };
>
> static struct test_args targs;
> @@ -478,7 +480,7 @@ static void test_pmu_events_snaphost(void)
>
> static void test_pmu_events_overflow(void)
> {
> - int num_counters = 0;
> + int num_counters = 0, i = 0;
>
> /* Verify presence of SBI PMU and minimum requrired SBI version */
> verify_sbi_requirement_assert();
> @@ -495,11 +497,15 @@ static void test_pmu_events_overflow(void)
> * Qemu supports overflow for cycle/instruction.
> * This test may fail on any platform that do not support overflow for these two events.
> */
> - test_pmu_event_overflow(SBI_PMU_HW_CPU_CYCLES);
> - GUEST_ASSERT_EQ(vcpu_shared_irq_count, 1);
> + for (i = 0; i < targs.overflow_irqnum; i++)
> + test_pmu_event_overflow(SBI_PMU_HW_CPU_CYCLES);
> + GUEST_ASSERT_EQ(vcpu_shared_irq_count, targs.overflow_irqnum);
> +
> + vcpu_shared_irq_count = 0;
>
> - test_pmu_event_overflow(SBI_PMU_HW_INSTRUCTIONS);
> - GUEST_ASSERT_EQ(vcpu_shared_irq_count, 2);
> + for (i = 0; i < targs.overflow_irqnum; i++)
> + test_pmu_event_overflow(SBI_PMU_HW_INSTRUCTIONS);
> + GUEST_ASSERT_EQ(vcpu_shared_irq_count, targs.overflow_irqnum);
>
> GUEST_DONE();
> }
> @@ -621,8 +627,11 @@ static void test_vm_events_overflow(void *guest_code)
>
> static void test_print_help(char *name)
> {
> - pr_info("Usage: %s [-h] [-t <test name>]\n", name);
> + pr_info("Usage: %s [-h] [-t <test name>] [-n <number of LCOFI interrupt for overflow test>]\n",
> + name);
> pr_info("\t-t: Test to run (default all). Available tests are 'basic', 'events', 'snapshot', 'overflow'\n");
> + pr_info("\t-n: Number of LCOFI interrupt to trigger for each event in overflow test (default: %d)\n",
> + SBI_PMU_OVERFLOW_IRQNUM_DEFAULT);
> pr_info("\t-h: print this help screen\n");
> }
>
> @@ -631,6 +640,8 @@ static bool parse_args(int argc, char *argv[])
> int opt;
> int temp_disabled_tests = SBI_PMU_TEST_BASIC | SBI_PMU_TEST_EVENTS | SBI_PMU_TEST_SNAPSHOT |
> SBI_PMU_TEST_OVERFLOW;
> + int overflow_interrupts = -1;
Initializing to -1 made me think that '-n 0' would be valid and a way to
disable the overflow test, but...
> +
> while ((opt = getopt(argc, argv, "h:t:n:")) != -1) {
> switch (opt) {
> case 't':
> @@ -646,12 +657,24 @@ static bool parse_args(int argc, char *argv[])
> goto done;
> targs.disabled_tests = temp_disabled_tests;
> break;
> + case 'n':
> + overflow_interrupts = atoi_positive("Number of LCOFI", optarg);
...here we use atoi_positive() and...
> + break;
> case 'h':
> default:
> goto done;
> }
> }
>
> + if (overflow_interrupts > 0) {
...here we only change from the default of 5 for nonzero.
Should we allow '-n 0'? Otherwise overflow_interrupts can be initialized
to zero (not that it matters).
> + if (targs.disabled_tests & SBI_PMU_TEST_OVERFLOW) {
> + pr_info("-n option is only available for overflow test\n");
> + goto done;
> + } else {
> + targs.overflow_irqnum = overflow_interrupts;
> + }
> + }
> +
> return true;
> done:
> test_print_help(argv[0]);
> @@ -661,6 +684,7 @@ static bool parse_args(int argc, char *argv[])
> int main(int argc, char *argv[])
> {
> targs.disabled_tests = 0;
> + targs.overflow_irqnum = SBI_PMU_OVERFLOW_IRQNUM_DEFAULT;
>
> if (!parse_args(argc, argv))
> exit(KSFT_SKIP);
>
> --
> 2.43.0
>
Thanks,
drew
On Thu, Feb 27, 2025 at 12:16 AM Andrew Jones <ajones@ventanamicro.com> wrote:
>
> On Wed, Feb 26, 2025 at 12:25:06PM -0800, Atish Patra wrote:
> > It is helpful to vary the number of the LCOFI interrupts generated
> > by the overflow test. Allow additional argument for overflow test
> > to accommodate that. It can be easily cross-validated with
> > /proc/interrupts output in the host.
> >
> > Signed-off-by: Atish Patra <atishp@rivosinc.com>
> > ---
> > tools/testing/selftests/kvm/riscv/sbi_pmu_test.c | 36 ++++++++++++++++++++----
> > 1 file changed, 30 insertions(+), 6 deletions(-)
> >
> > diff --git a/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c b/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c
> > index 533b76d0de82..7c273a1adb17 100644
> > --- a/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c
> > +++ b/tools/testing/selftests/kvm/riscv/sbi_pmu_test.c
> > @@ -39,8 +39,10 @@ static bool illegal_handler_invoked;
> > #define SBI_PMU_TEST_SNAPSHOT BIT(2)
> > #define SBI_PMU_TEST_OVERFLOW BIT(3)
> >
> > +#define SBI_PMU_OVERFLOW_IRQNUM_DEFAULT 5
> > struct test_args {
> > int disabled_tests;
> > + int overflow_irqnum;
> > };
> >
> > static struct test_args targs;
> > @@ -478,7 +480,7 @@ static void test_pmu_events_snaphost(void)
> >
> > static void test_pmu_events_overflow(void)
> > {
> > - int num_counters = 0;
> > + int num_counters = 0, i = 0;
> >
> > /* Verify presence of SBI PMU and minimum requrired SBI version */
> > verify_sbi_requirement_assert();
> > @@ -495,11 +497,15 @@ static void test_pmu_events_overflow(void)
> > * Qemu supports overflow for cycle/instruction.
> > * This test may fail on any platform that do not support overflow for these two events.
> > */
> > - test_pmu_event_overflow(SBI_PMU_HW_CPU_CYCLES);
> > - GUEST_ASSERT_EQ(vcpu_shared_irq_count, 1);
> > + for (i = 0; i < targs.overflow_irqnum; i++)
> > + test_pmu_event_overflow(SBI_PMU_HW_CPU_CYCLES);
> > + GUEST_ASSERT_EQ(vcpu_shared_irq_count, targs.overflow_irqnum);
> > +
> > + vcpu_shared_irq_count = 0;
> >
> > - test_pmu_event_overflow(SBI_PMU_HW_INSTRUCTIONS);
> > - GUEST_ASSERT_EQ(vcpu_shared_irq_count, 2);
> > + for (i = 0; i < targs.overflow_irqnum; i++)
> > + test_pmu_event_overflow(SBI_PMU_HW_INSTRUCTIONS);
> > + GUEST_ASSERT_EQ(vcpu_shared_irq_count, targs.overflow_irqnum);
> >
> > GUEST_DONE();
> > }
> > @@ -621,8 +627,11 @@ static void test_vm_events_overflow(void *guest_code)
> >
> > static void test_print_help(char *name)
> > {
> > - pr_info("Usage: %s [-h] [-t <test name>]\n", name);
> > + pr_info("Usage: %s [-h] [-t <test name>] [-n <number of LCOFI interrupt for overflow test>]\n",
> > + name);
> > pr_info("\t-t: Test to run (default all). Available tests are 'basic', 'events', 'snapshot', 'overflow'\n");
> > + pr_info("\t-n: Number of LCOFI interrupt to trigger for each event in overflow test (default: %d)\n",
> > + SBI_PMU_OVERFLOW_IRQNUM_DEFAULT);
> > pr_info("\t-h: print this help screen\n");
> > }
> >
> > @@ -631,6 +640,8 @@ static bool parse_args(int argc, char *argv[])
> > int opt;
> > int temp_disabled_tests = SBI_PMU_TEST_BASIC | SBI_PMU_TEST_EVENTS | SBI_PMU_TEST_SNAPSHOT |
> > SBI_PMU_TEST_OVERFLOW;
> > + int overflow_interrupts = -1;
>
> Initializing to -1 made me think that '-n 0' would be valid and a way to
> disable the overflow test, but...
>
Is there any benefit ? I found it much more convenient to select a
single test and run instead of disabling
a single test.
Once you single or a set of tests, all other tests are disabled anyways.
> > +
> > while ((opt = getopt(argc, argv, "h:t:n:")) != -1) {
> > switch (opt) {
> > case 't':
> > @@ -646,12 +657,24 @@ static bool parse_args(int argc, char *argv[])
> > goto done;
> > targs.disabled_tests = temp_disabled_tests;
> > break;
> > + case 'n':
> > + overflow_interrupts = atoi_positive("Number of LCOFI", optarg);
>
> ...here we use atoi_positive() and...
>
> > + break;
> > case 'h':
> > default:
> > goto done;
> > }
> > }
> >
> > + if (overflow_interrupts > 0) {
>
> ...here we only change from the default of 5 for nonzero.
>
> Should we allow '-n 0'? Otherwise overflow_interrupts can be initialized
> to zero (not that it matters).
>
I will change the default value to 0 to avoid ambiguity for now.
Please let me know if you strongly think we should support -n 0.
We can always support it. I just don't see the point of specifying the
test with options to disable it anymore.
> > + if (targs.disabled_tests & SBI_PMU_TEST_OVERFLOW) {
> > + pr_info("-n option is only available for overflow test\n");
> > + goto done;
> > + } else {
> > + targs.overflow_irqnum = overflow_interrupts;
> > + }
> > + }
> > +
> > return true;
> > done:
> > test_print_help(argv[0]);
> > @@ -661,6 +684,7 @@ static bool parse_args(int argc, char *argv[])
> > int main(int argc, char *argv[])
> > {
> > targs.disabled_tests = 0;
> > + targs.overflow_irqnum = SBI_PMU_OVERFLOW_IRQNUM_DEFAULT;
> >
> > if (!parse_args(argc, argv))
> > exit(KSFT_SKIP);
> >
> > --
> > 2.43.0
> >
>
> Thanks,
> drew
On Mon, Mar 03, 2025 at 01:27:47PM -0800, Atish Kumar Patra wrote: > On Thu, Feb 27, 2025 at 12:16 AM Andrew Jones <ajones@ventanamicro.com> wrote: > > > > On Wed, Feb 26, 2025 at 12:25:06PM -0800, Atish Patra wrote: ... > I will change the default value to 0 to avoid ambiguity for now. > Please let me know if you strongly think we should support -n 0. > We can always support it. I just don't see the point of specifying the > test with options to disable it anymore. > I don't mind not supporting '-n 0'. Thanks, drew
© 2016 - 2026 Red Hat, Inc.