xref: /dpdk/lib/eal/common/eal_common_cpuflags.c (revision 99a2dd955fba6e4cc23b77d590a033650ced9c45)
1*99a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2*99a2dd95SBruce Richardson  * Copyright(c) 2010-2014 Intel Corporation
3*99a2dd95SBruce Richardson  */
4*99a2dd95SBruce Richardson 
5*99a2dd95SBruce Richardson #include <stdio.h>
6*99a2dd95SBruce Richardson 
7*99a2dd95SBruce Richardson #include <rte_common.h>
8*99a2dd95SBruce Richardson #include <rte_cpuflags.h>
9*99a2dd95SBruce Richardson 
10*99a2dd95SBruce Richardson int
rte_cpu_is_supported(void)11*99a2dd95SBruce Richardson rte_cpu_is_supported(void)
12*99a2dd95SBruce Richardson {
13*99a2dd95SBruce Richardson 	/* This is generated at compile-time by the build system */
14*99a2dd95SBruce Richardson 	static const enum rte_cpu_flag_t compile_time_flags[] = {
15*99a2dd95SBruce Richardson 			RTE_COMPILE_TIME_CPUFLAGS
16*99a2dd95SBruce Richardson 	};
17*99a2dd95SBruce Richardson 	unsigned count = RTE_DIM(compile_time_flags), i;
18*99a2dd95SBruce Richardson 	int ret;
19*99a2dd95SBruce Richardson 
20*99a2dd95SBruce Richardson 	for (i = 0; i < count; i++) {
21*99a2dd95SBruce Richardson 		ret = rte_cpu_get_flag_enabled(compile_time_flags[i]);
22*99a2dd95SBruce Richardson 
23*99a2dd95SBruce Richardson 		if (ret < 0) {
24*99a2dd95SBruce Richardson 			fprintf(stderr,
25*99a2dd95SBruce Richardson 				"ERROR: CPU feature flag lookup failed with error %d\n",
26*99a2dd95SBruce Richardson 				ret);
27*99a2dd95SBruce Richardson 			return 0;
28*99a2dd95SBruce Richardson 		}
29*99a2dd95SBruce Richardson 		if (!ret) {
30*99a2dd95SBruce Richardson 			fprintf(stderr,
31*99a2dd95SBruce Richardson 			        "ERROR: This system does not support \"%s\".\n"
32*99a2dd95SBruce Richardson 			        "Please check that RTE_MACHINE is set correctly.\n",
33*99a2dd95SBruce Richardson 			        rte_cpu_get_flag_name(compile_time_flags[i]));
34*99a2dd95SBruce Richardson 			return 0;
35*99a2dd95SBruce Richardson 		}
36*99a2dd95SBruce Richardson 	}
37*99a2dd95SBruce Richardson 
38*99a2dd95SBruce Richardson 	return 1;
39*99a2dd95SBruce Richardson }
40