[kvm-unit-tests PATCH v1 3/5] s390x: smp: avoid hardcoded CPU addresses

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use the recently introduced functions to work with CPU indexes, instead of
using hardcoded values. This makes the test more portable.

Signed-off-by: Claudio Imbrenda <imbrenda@xxxxxxxxxxxxx>
---
 s390x/smp.c | 83 ++++++++++++++++++++++++++++-------------------------
 1 file changed, 44 insertions(+), 39 deletions(-)

diff --git a/s390x/smp.c b/s390x/smp.c
index 1bbe4c31..da668ca6 100644
--- a/s390x/smp.c
+++ b/s390x/smp.c
@@ -18,6 +18,7 @@
 #include <smp.h>
 #include <alloc_page.h>
 
+static uint16_t cpu0, cpu1;
 static int testflag = 0;
 
 static void wait_for_flag(void)
@@ -45,7 +46,7 @@ static void test_start(void)
 	psw.addr = (unsigned long)test_func;
 
 	set_flag(0);
-	smp_cpu_start(1, psw);
+	smp_cpu_start(cpu1, psw);
 	wait_for_flag();
 	report_pass("start");
 }
@@ -56,16 +57,16 @@ static void test_start(void)
  */
 static void test_restart(void)
 {
-	struct cpu *cpu = smp_cpu_from_addr(1);
+	struct cpu *cpu = smp_cpu_from_idx(1);
 	struct lowcore *lc = cpu->lowcore;
 
 	lc->restart_new_psw.mask = extract_psw_mask();
 	lc->restart_new_psw.addr = (unsigned long)test_func;
 
 	/* Make sure cpu is running */
-	smp_cpu_stop(0);
+	smp_cpu_stop(cpu0);
 	set_flag(0);
-	smp_cpu_restart(1);
+	smp_cpu_restart(cpu1);
 	wait_for_flag();
 
 	/*
@@ -73,44 +74,44 @@ static void test_restart(void)
 	 * restart function.
 	 */
 	set_flag(0);
-	smp_cpu_restart(1);
+	smp_cpu_restart(cpu1);
 	wait_for_flag();
 	report_pass("restart while running");
 }
 
 static void test_stop(void)
 {
-	smp_cpu_stop(1);
+	smp_cpu_stop(cpu1);
 	/*
 	 * The smp library waits for the CPU to shut down, but let's
 	 * also do it here, so we don't rely on the library
 	 * implementation
 	 */
-	while (!smp_cpu_stopped(1)) {}
+	while (!smp_cpu_stopped(cpu1)) {}
 	report_pass("stop");
 }
 
 static void test_stop_store_status(void)
 {
-	struct cpu *cpu = smp_cpu_from_addr(1);
+	struct cpu *cpu = smp_cpu_from_idx(1);
 	struct lowcore *lc = (void *)0x0;
 
 	report_prefix_push("stop store status");
 	report_prefix_push("running");
-	smp_cpu_restart(1);
+	smp_cpu_restart(cpu1);
 	lc->prefix_sa = 0;
 	lc->grs_sa[15] = 0;
-	smp_cpu_stop_store_status(1);
+	smp_cpu_stop_store_status(cpu1);
 	mb();
 	report(lc->prefix_sa == (uint32_t)(uintptr_t)cpu->lowcore, "prefix");
 	report(lc->grs_sa[15], "stack");
-	report(smp_cpu_stopped(1), "cpu stopped");
+	report(smp_cpu_stopped(cpu1), "cpu stopped");
 	report_prefix_pop();
 
 	report_prefix_push("stopped");
 	lc->prefix_sa = 0;
 	lc->grs_sa[15] = 0;
-	smp_cpu_stop_store_status(1);
+	smp_cpu_stop_store_status(cpu1);
 	mb();
 	report(lc->prefix_sa == (uint32_t)(uintptr_t)cpu->lowcore, "prefix");
 	report(lc->grs_sa[15], "stack");
@@ -128,8 +129,8 @@ static void test_store_status(void)
 	memset(status, 0, PAGE_SIZE * 2);
 
 	report_prefix_push("running");
-	smp_cpu_restart(1);
-	sigp(1, SIGP_STORE_STATUS_AT_ADDRESS, (uintptr_t)status, &r);
+	smp_cpu_restart(cpu1);
+	sigp(cpu1, SIGP_STORE_STATUS_AT_ADDRESS, (uintptr_t)status, &r);
 	report(r == SIGP_STATUS_INCORRECT_STATE, "incorrect state");
 	report(!memcmp(status, (void *)status + PAGE_SIZE, PAGE_SIZE),
 	       "status not written");
@@ -137,13 +138,13 @@ static void test_store_status(void)
 
 	memset(status, 0, PAGE_SIZE);
 	report_prefix_push("stopped");
-	smp_cpu_stop(1);
-	sigp(1, SIGP_STORE_STATUS_AT_ADDRESS, (uintptr_t)status, NULL);
+	smp_cpu_stop(cpu1);
+	sigp(cpu1, SIGP_STORE_STATUS_AT_ADDRESS, (uintptr_t)status, NULL);
 	while (!status->prefix) { mb(); }
 	report_pass("status written");
 	free_pages(status);
 	report_prefix_pop();
-	smp_cpu_stop(1);
+	smp_cpu_stop(cpu1);
 
 	report_prefix_pop();
 }
@@ -173,12 +174,12 @@ static void test_ecall(void)
 	report_prefix_push("ecall");
 	set_flag(0);
 
-	smp_cpu_start(1, psw);
+	smp_cpu_start(cpu1, psw);
 	wait_for_flag();
 	set_flag(0);
-	sigp(1, SIGP_EXTERNAL_CALL, 0, NULL);
+	sigp(cpu1, SIGP_EXTERNAL_CALL, 0, NULL);
 	wait_for_flag();
-	smp_cpu_stop(1);
+	smp_cpu_stop(cpu1);
 	report_prefix_pop();
 }
 
@@ -207,12 +208,12 @@ static void test_emcall(void)
 	report_prefix_push("emcall");
 	set_flag(0);
 
-	smp_cpu_start(1, psw);
+	smp_cpu_start(cpu1, psw);
 	wait_for_flag();
 	set_flag(0);
-	sigp(1, SIGP_EMERGENCY_SIGNAL, 0, NULL);
+	sigp(cpu1, SIGP_EMERGENCY_SIGNAL, 0, NULL);
 	wait_for_flag();
-	smp_cpu_stop(1);
+	smp_cpu_stop(cpu1);
 	report_prefix_pop();
 }
 
@@ -220,11 +221,11 @@ static void test_sense_running(void)
 {
 	report_prefix_push("sense_running");
 	/* we (CPU0) are running */
-	report(smp_sense_running_status(0), "CPU0 sense claims running");
+	report(smp_sense_running_status(cpu0), "CPU0 sense claims running");
 	/* stop the target CPU (CPU1) to speed up the not running case */
-	smp_cpu_stop(1);
+	smp_cpu_stop(cpu1);
 	/* Make sure to have at least one time with a not running indication */
-	while(smp_sense_running_status(1));
+	while(smp_sense_running_status(cpu1));
 	report_pass("CPU1 sense claims not running");
 	report_prefix_pop();
 }
@@ -250,11 +251,11 @@ static void test_reset_initial(void)
 
 	report_prefix_push("reset initial");
 	set_flag(0);
-	smp_cpu_start(1, psw);
+	smp_cpu_start(cpu1, psw);
 	wait_for_flag();
 
-	sigp_retry(1, SIGP_INITIAL_CPU_RESET, 0, NULL);
-	sigp(1, SIGP_STORE_STATUS_AT_ADDRESS, (uintptr_t)status, NULL);
+	sigp_retry(cpu1, SIGP_INITIAL_CPU_RESET, 0, NULL);
+	sigp(cpu1, SIGP_STORE_STATUS_AT_ADDRESS, (uintptr_t)status, NULL);
 
 	report_prefix_push("clear");
 	report(!status->psw.mask && !status->psw.addr, "psw");
@@ -273,7 +274,7 @@ static void test_reset_initial(void)
 	report(status->crs[14] == 0xC2000000UL, "cr14 == 0xC2000000");
 	report_prefix_pop();
 
-	report(smp_cpu_stopped(1), "cpu stopped");
+	report(smp_cpu_stopped(cpu1), "cpu stopped");
 	free_pages(status);
 	report_prefix_pop();
 }
@@ -299,16 +300,16 @@ static void test_reset(void)
 	psw.addr = (unsigned long)test_func;
 
 	report_prefix_push("cpu reset");
-	sigp(1, SIGP_EMERGENCY_SIGNAL, 0, NULL);
-	sigp(1, SIGP_EXTERNAL_CALL, 0, NULL);
-	smp_cpu_start(1, psw);
+	sigp(cpu1, SIGP_EMERGENCY_SIGNAL, 0, NULL);
+	sigp(cpu1, SIGP_EXTERNAL_CALL, 0, NULL);
+	smp_cpu_start(cpu1, psw);
 
-	sigp_retry(1, SIGP_CPU_RESET, 0, NULL);
-	report(smp_cpu_stopped(1), "cpu stopped");
+	sigp_retry(cpu1, SIGP_CPU_RESET, 0, NULL);
+	report(smp_cpu_stopped(cpu1), "cpu stopped");
 
 	set_flag(0);
 	psw.addr = (unsigned long)test_local_ints;
-	smp_cpu_start(1, psw);
+	smp_cpu_start(cpu1, psw);
 	wait_for_flag();
 	report_pass("local interrupts cleared");
 	report_prefix_pop();
@@ -324,11 +325,15 @@ int main(void)
 		goto done;
 	}
 
+	/* the boot CPU is guaranteed to have index 0 */
+	cpu0 = stap();
+	cpu1 = smp_cpu_addr_from_idx(1);
+
 	/* Setting up the cpu to give it a stack and lowcore */
 	psw.mask = extract_psw_mask();
 	psw.addr = (unsigned long)test_func;
-	smp_cpu_setup(1, psw);
-	smp_cpu_stop(1);
+	smp_cpu_setup(cpu1, psw);
+	smp_cpu_stop(cpu1);
 
 	test_start();
 	test_restart();
@@ -340,7 +345,7 @@ int main(void)
 	test_sense_running();
 	test_reset();
 	test_reset_initial();
-	smp_cpu_destroy(1);
+	smp_cpu_destroy(cpu1);
 
 done:
 	report_prefix_pop();
-- 
2.34.1




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux