1 /*- 2 * BSD LICENSE 3 * 4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 11 * * Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * * Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in 15 * the documentation and/or other materials provided with the 16 * distribution. 17 * * Neither the name of Intel Corporation nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #include <stdio.h> 35 36 #include <cmdline_parse.h> 37 #include <errno.h> 38 #include <stdint.h> 39 #include <rte_cpuflags.h> 40 #include <rte_debug.h> 41 42 #include "test.h" 43 44 45 /* convenience define */ 46 #define CHECK_FOR_FLAG(x) \ 47 result = rte_cpu_get_flag_enabled(x); \ 48 printf("%s\n", cpu_flag_result(result)); \ 49 if (result == -ENOENT) \ 50 return -1; 51 52 /* 53 * Helper function to display result 54 */ 55 static inline const char * 56 cpu_flag_result(int result) 57 { 58 switch (result) { 59 case 0: 60 return "NOT PRESENT"; 61 case 1: 62 return "OK"; 63 default: 64 return "ERROR"; 65 } 66 } 67 68 69 70 /* 71 * CPUID test 72 * =========== 73 * 74 * - Check flags from different registers with rte_cpu_get_flag_enabled() 75 * - Check if register and CPUID functions fail properly 76 */ 77 78 int 79 test_cpuflags(void) 80 { 81 int result; 82 printf("\nChecking for flags from different registers...\n"); 83 84 printf("Check for SSE:\t\t"); 85 CHECK_FOR_FLAG(RTE_CPUFLAG_SSE); 86 87 printf("Check for SSE2:\t\t"); 88 CHECK_FOR_FLAG(RTE_CPUFLAG_SSE2); 89 90 printf("Check for SSE3:\t\t"); 91 CHECK_FOR_FLAG(RTE_CPUFLAG_SSE3); 92 93 printf("Check for SSE4.1:\t"); 94 CHECK_FOR_FLAG(RTE_CPUFLAG_SSE4_1); 95 96 printf("Check for SSE4.2:\t"); 97 CHECK_FOR_FLAG(RTE_CPUFLAG_SSE4_2); 98 99 printf("Check for AVX:\t\t"); 100 CHECK_FOR_FLAG(RTE_CPUFLAG_AVX); 101 102 printf("Check for AVX2:\t\t"); 103 CHECK_FOR_FLAG(RTE_CPUFLAG_AVX2); 104 105 printf("Check for TRBOBST:\t"); 106 CHECK_FOR_FLAG(RTE_CPUFLAG_TRBOBST); 107 108 printf("Check for ENERGY_EFF:\t"); 109 CHECK_FOR_FLAG(RTE_CPUFLAG_ENERGY_EFF); 110 111 printf("Check for LAHF_SAHF:\t"); 112 CHECK_FOR_FLAG(RTE_CPUFLAG_LAHF_SAHF); 113 114 printf("Check for 1GB_PG:\t"); 115 CHECK_FOR_FLAG(RTE_CPUFLAG_1GB_PG); 116 117 printf("Check for INVTSC:\t"); 118 CHECK_FOR_FLAG(RTE_CPUFLAG_INVTSC); 119 120 121 122 /* 123 * Check if invalid data is handled properly 124 */ 125 printf("\nCheck for invalid flag:\t"); 126 result = rte_cpu_get_flag_enabled(RTE_CPUFLAG_NUMFLAGS); 127 printf("%s\n", cpu_flag_result(result)); 128 if (result != -ENOENT) 129 return -1; 130 131 return 0; 132 } 133