tools/testing/selftests/arm64/fp/vec-syscfg.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/arm64/fp/vec-syscfg.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/arm64/fp/vec-syscfg.c
Extension
.c
Size
18636 bytes
Lines
797
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source 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

struct vec_data {
	const char *name;
	unsigned long hwcap_type;
	unsigned long hwcap;
	const char *rdvl_binary;
	int (*rdvl)(void);

	int prctl_get;
	int prctl_set;
	const char *default_vl_file;

	int default_vl;
	int min_vl;
	int max_vl;
};

#define VEC_SVE 0
#define VEC_SME 1

static struct vec_data vec_data[] = {
	[VEC_SVE] = {
		.name = "SVE",
		.hwcap_type = AT_HWCAP,
		.hwcap = HWCAP_SVE,
		.rdvl = rdvl_sve,
		.rdvl_binary = "./rdvl-sve",
		.prctl_get = PR_SVE_GET_VL,
		.prctl_set = PR_SVE_SET_VL,
		.default_vl_file = "/proc/sys/abi/sve_default_vector_length",
	},
	[VEC_SME] = {
		.name = "SME",
		.hwcap_type = AT_HWCAP2,
		.hwcap = HWCAP2_SME,
		.rdvl = rdvl_sme,
		.rdvl_binary = "./rdvl-sme",
		.prctl_get = PR_SME_GET_VL,
		.prctl_set = PR_SME_SET_VL,
		.default_vl_file = "/proc/sys/abi/sme_default_vector_length",
	},
};

static bool vec_type_supported(struct vec_data *data)
{
	return getauxval(data->hwcap_type) & data->hwcap;
}

static int stdio_read_integer(FILE *f, const char *what, int *val)
{
	int n = 0;
	int ret;

	ret = fscanf(f, "%d%*1[\n]%n", val, &n);
	if (ret < 1 || n < 1) {
		ksft_print_msg("failed to parse integer from %s\n", what);
		return -1;
	}

	return 0;
}

/* Start a new process and return the vector length it sees */
static int get_child_rdvl(struct vec_data *data)
{
	FILE *out;
	int pipefd[2];
	pid_t pid, child;
	int read_vl, ret;

	ret = pipe(pipefd);
	if (ret == -1) {
		ksft_print_msg("pipe() failed: %d (%s)\n",
			       errno, strerror(errno));
		return -1;
	}

	fflush(stdout);

	child = fork();
	if (child == -1) {
		ksft_print_msg("fork() failed: %d (%s)\n",
			       errno, strerror(errno));
		close(pipefd[0]);
		close(pipefd[1]);
		return -1;
	}

	/* Child: put vector length on the pipe */
	if (child == 0) {
		/*

Annotation

Implementation Notes