Skip to content

Commit ee4e778

Browse files
atishp04avpatel
authored andcommitted
KVM: riscv: selftests: Allow number of interrupts to be configurable
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> Reviewed-by: Andrew Jones <ajones@ventanamicro.com> Link: https://lore.kernel.org/r/20250303-kvm_pmu_improve-v2-4-41d177e45929@rivosinc.com Signed-off-by: Anup Patel <anup@brainfault.org>
1 parent 4b506ad commit ee4e778

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

tools/testing/selftests/kvm/riscv/sbi_pmu_test.c

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ static bool illegal_handler_invoked;
3939
#define SBI_PMU_TEST_SNAPSHOT BIT(2)
4040
#define SBI_PMU_TEST_OVERFLOW BIT(3)
4141

42+
#define SBI_PMU_OVERFLOW_IRQNUM_DEFAULT 5
4243
struct test_args {
4344
int disabled_tests;
45+
int overflow_irqnum;
4446
};
4547

4648
static struct test_args targs;
@@ -478,7 +480,7 @@ static void test_pmu_events_snaphost(void)
478480

479481
static void test_pmu_events_overflow(void)
480482
{
481-
int num_counters = 0;
483+
int num_counters = 0, i = 0;
482484

483485
/* Verify presence of SBI PMU and minimum requrired SBI version */
484486
verify_sbi_requirement_assert();
@@ -495,11 +497,15 @@ static void test_pmu_events_overflow(void)
495497
* Qemu supports overflow for cycle/instruction.
496498
* This test may fail on any platform that do not support overflow for these two events.
497499
*/
498-
test_pmu_event_overflow(SBI_PMU_HW_CPU_CYCLES);
499-
GUEST_ASSERT_EQ(vcpu_shared_irq_count, 1);
500+
for (i = 0; i < targs.overflow_irqnum; i++)
501+
test_pmu_event_overflow(SBI_PMU_HW_CPU_CYCLES);
502+
GUEST_ASSERT_EQ(vcpu_shared_irq_count, targs.overflow_irqnum);
503+
504+
vcpu_shared_irq_count = 0;
500505

501-
test_pmu_event_overflow(SBI_PMU_HW_INSTRUCTIONS);
502-
GUEST_ASSERT_EQ(vcpu_shared_irq_count, 2);
506+
for (i = 0; i < targs.overflow_irqnum; i++)
507+
test_pmu_event_overflow(SBI_PMU_HW_INSTRUCTIONS);
508+
GUEST_ASSERT_EQ(vcpu_shared_irq_count, targs.overflow_irqnum);
503509

504510
GUEST_DONE();
505511
}
@@ -621,8 +627,11 @@ static void test_vm_events_overflow(void *guest_code)
621627

622628
static void test_print_help(char *name)
623629
{
624-
pr_info("Usage: %s [-h] [-t <test name>]\n", name);
630+
pr_info("Usage: %s [-h] [-t <test name>] [-n <number of LCOFI interrupt for overflow test>]\n",
631+
name);
625632
pr_info("\t-t: Test to run (default all). Available tests are 'basic', 'events', 'snapshot', 'overflow'\n");
633+
pr_info("\t-n: Number of LCOFI interrupt to trigger for each event in overflow test (default: %d)\n",
634+
SBI_PMU_OVERFLOW_IRQNUM_DEFAULT);
626635
pr_info("\t-h: print this help screen\n");
627636
}
628637

@@ -631,7 +640,9 @@ static bool parse_args(int argc, char *argv[])
631640
int opt;
632641
int temp_disabled_tests = SBI_PMU_TEST_BASIC | SBI_PMU_TEST_EVENTS | SBI_PMU_TEST_SNAPSHOT |
633642
SBI_PMU_TEST_OVERFLOW;
634-
while ((opt = getopt(argc, argv, "ht:")) != -1) {
643+
int overflow_interrupts = 0;
644+
645+
while ((opt = getopt(argc, argv, "ht:n:")) != -1) {
635646
switch (opt) {
636647
case 't':
637648
if (!strncmp("basic", optarg, 5))
@@ -646,12 +657,24 @@ static bool parse_args(int argc, char *argv[])
646657
goto done;
647658
targs.disabled_tests = temp_disabled_tests;
648659
break;
660+
case 'n':
661+
overflow_interrupts = atoi_positive("Number of LCOFI", optarg);
662+
break;
649663
case 'h':
650664
default:
651665
goto done;
652666
}
653667
}
654668

669+
if (overflow_interrupts > 0) {
670+
if (targs.disabled_tests & SBI_PMU_TEST_OVERFLOW) {
671+
pr_info("-n option is only available for overflow test\n");
672+
goto done;
673+
} else {
674+
targs.overflow_irqnum = overflow_interrupts;
675+
}
676+
}
677+
655678
return true;
656679
done:
657680
test_print_help(argv[0]);
@@ -661,6 +684,7 @@ static bool parse_args(int argc, char *argv[])
661684
int main(int argc, char *argv[])
662685
{
663686
targs.disabled_tests = 0;
687+
targs.overflow_irqnum = SBI_PMU_OVERFLOW_IRQNUM_DEFAULT;
664688

665689
if (!parse_args(argc, argv))
666690
exit(KSFT_SKIP);

0 commit comments

Comments
 (0)