tools/testing/selftests/powerpc/tm/tm-syscall.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/powerpc/tm/tm-syscall.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/powerpc/tm/tm-syscall.c
Extension
.c
Size
3125 bytes
Lines
129
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: syscall or user/kernel boundary
Status
core implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (suspend) {
			if (scv)
				pid = getppid_scv_tm_suspended();
			else
				pid = getppid_tm_suspended();
		} else {
			if (scv)
				pid = getppid_scv_tm_active();
			else
				pid = getppid_tm_active();
		}

		if (pid >= 0)
			return pid;

		if (failure_is_persistent()) {
			if (failure_is_syscall())
				return -1;

			printf("Unexpected persistent transaction failure.\n");
			printf("TEXASR 0x%016lx, TFIAR 0x%016lx.\n",
			       __builtin_get_texasr(), __builtin_get_tfiar());
			exit(-1);
		}

		retries++;
	}

	printf("Exceeded limit of %d temporary transaction failures.\n", TM_RETRIES);
	printf("TEXASR 0x%016lx, TFIAR 0x%016lx.\n",
	       __builtin_get_texasr(), __builtin_get_tfiar());

	exit(-1);
}

int tm_syscall(void)
{
	unsigned count = 0;
	struct timeval end, now;

	SKIP_IF(!have_htm_nosc());
	SKIP_IF(htm_is_synthetic());

	setbuf(stdout, NULL);

	printf("Testing transactional syscalls for %d seconds...\n", TEST_DURATION);

	gettimeofday(&end, NULL);
	now.tv_sec = TEST_DURATION;
	now.tv_usec = 0;
	timeradd(&end, &now, &end);

	for (count = 0; timercmp(&now, &end, <); count++) {
		/*
		 * Test a syscall within a suspended transaction and verify
		 * that it succeeds.
		 */
		FAIL_IF(getppid_tm(false, true) == -1); /* Should succeed. */

		/*
		 * Test a syscall within an active transaction and verify that
		 * it fails with the correct failure code.
		 */
		FAIL_IF(getppid_tm(false, false) != -1);  /* Should fail... */
		FAIL_IF(!failure_is_persistent()); /* ...persistently... */
		FAIL_IF(!failure_is_syscall());    /* ...with code syscall. */

		/* Now do it all again with scv if it is available. */
		if (have_hwcap2(PPC_FEATURE2_SCV)) {
			FAIL_IF(getppid_tm(true, true) == -1); /* Should succeed. */
			FAIL_IF(getppid_tm(true, false) != -1);  /* Should fail... */
			FAIL_IF(!failure_is_persistent()); /* ...persistently... */
			FAIL_IF(!failure_is_syscall());    /* ...with code syscall. */
		}

		gettimeofday(&now, 0);
	}

	printf("%d active and suspended transactions behaved correctly.\n", count);
	printf("(There were %d transaction retries.)\n", retries);

	return 0;
}

int main(void)
{
	return test_harness(tm_syscall, "tm_syscall");
}

Annotation

Implementation Notes