public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Jones <andrew.jones@linux.dev>
To: kvm@vger.kernel.org, kvm-riscv@lists.infradead.org
Cc: cade.richard@gmail.com, atishp@rivosinc.com, jamestiotio@gmail.com
Subject: [kvm-unit-tests PATCH v2 3/3] riscv: sbi: Add two in hart_mask IPI test
Date: Wed,  6 Nov 2024 12:38:18 +0100	[thread overview]
Message-ID: <20241106113814.42992-8-andrew.jones@linux.dev> (raw)
In-Reply-To: <20241106113814.42992-5-andrew.jones@linux.dev>

We should ensure that when hart_mask has more than one hartid
that both harts get IPIs with a single call of the IPI function.

Signed-off-by: Andrew Jones <andrew.jones@linux.dev>
---
 riscv/sbi.c | 39 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 38 insertions(+), 1 deletion(-)

diff --git a/riscv/sbi.c b/riscv/sbi.c
index cdf8d13cc9cf..8ccdf42f902a 100644
--- a/riscv/sbi.c
+++ b/riscv/sbi.c
@@ -364,10 +364,11 @@ static void check_ipi(void)
 	int nr_cpus_present = cpumask_weight(&cpu_present_mask);
 	int me = smp_processor_id();
 	unsigned long max_hartid = 0;
+	unsigned long hartid1, hartid2;
 	cpumask_t ipi_receivers;
 	static prng_state ps;
 	struct sbiret ret;
-	int cpu;
+	int cpu, cpu2;
 
 	ps = prng_init(0xDEADBEEF);
 
@@ -398,6 +399,42 @@ static void check_ipi(void)
 	ipi_hart_check(&ipi_receivers);
 	report_prefix_pop();
 
+	report_prefix_push("two in hart_mask");
+
+	if (nr_cpus_present < 3) {
+		report_skip("3 cpus required");
+		goto end_two;
+	}
+
+	cpu = rand_online_cpu(&ps);
+	hartid1 = cpus[cpu].hartid;
+	hartid2 = 0;
+	for_each_present_cpu(cpu2) {
+		if (cpu2 == cpu || cpu2 == me)
+			continue;
+		hartid2 = cpus[cpu2].hartid;
+		if (__builtin_labs(hartid2 - hartid1) < BITS_PER_LONG)
+			break;
+	}
+	if (cpu2 == nr_cpus) {
+		report_skip("hartids are too sparse");
+		goto end_two;
+	}
+
+	cpumask_clear(&ipi_done);
+	cpumask_clear(&ipi_receivers);
+	cpumask_set_cpu(cpu, &ipi_receivers);
+	cpumask_set_cpu(cpu2, &ipi_receivers);
+	on_cpu_async(cpu, ipi_hart_wait, (void *)d);
+	on_cpu_async(cpu2, ipi_hart_wait, (void *)d);
+	ret = sbi_send_ipi((1UL << __builtin_labs(hartid2 - hartid1)) | 1UL, hartid1 < hartid2 ? hartid1 : hartid2);
+	report(ret.error == SBI_SUCCESS, "ipi returned success");
+	while (!cpumask_equal(&ipi_done, &ipi_receivers))
+		cpu_relax();
+	ipi_hart_check(&ipi_receivers);
+end_two:
+	report_prefix_pop();
+
 	report_prefix_push("broadcast");
 	cpumask_clear(&ipi_done);
 	cpumask_copy(&ipi_receivers, &cpu_present_mask);
-- 
2.47.0


  parent reply	other threads:[~2024-11-06 11:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-06 11:38 [kvm-unit-tests PATCH v2 0/3] riscv: sbi: Add IPI tests Andrew Jones
2024-11-06 11:38 ` [kvm-unit-tests PATCH v2 1/3] riscv: Add sbi_send_ipi_broadcast Andrew Jones
2024-11-06 11:38 ` [kvm-unit-tests PATCH v2 2/3] riscv: sbi: Add IPI extension tests Andrew Jones
2024-11-06 11:38 ` Andrew Jones [this message]
2024-11-06 12:22   ` [kvm-unit-tests PATCH v2 3/3] riscv: sbi: Add two in hart_mask IPI test Andrew Jones
2024-11-11 15:07 ` [kvm-unit-tests PATCH v2 0/3] riscv: sbi: Add IPI tests Andrew Jones

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=20241106113814.42992-8-andrew.jones@linux.dev \
    --to=andrew.jones@linux.dev \
    --cc=atishp@rivosinc.com \
    --cc=cade.richard@gmail.com \
    --cc=jamestiotio@gmail.com \
    --cc=kvm-riscv@lists.infradead.org \
    --cc=kvm@vger.kernel.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