Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause 2 : : * Copyright(c) 2010-2014 Intel Corporation 3 : : */ 4 : : 5 : : #include <stdio.h> 6 : : #include <stdint.h> 7 : : #include <sys/queue.h> 8 : : 9 : : #include <rte_common.h> 10 : : #include <rte_memory.h> 11 : : #include <rte_per_lcore.h> 12 : : #include <rte_launch.h> 13 : : #include <rte_eal.h> 14 : : #include <rte_lcore.h> 15 : : #include <rte_cycles.h> 16 : : 17 : : #include "test.h" 18 : : 19 : : /* 20 : : * Per-lcore variables and lcore launch 21 : : * ==================================== 22 : : * 23 : : * - Use ``rte_eal_mp_remote_launch()`` to call ``assign_vars()`` on 24 : : * every available lcore. In this function, a per-lcore variable is 25 : : * assigned to the lcore_id. 26 : : * 27 : : * - Use ``rte_eal_mp_remote_launch()`` to call ``display_vars()`` on 28 : : * every available lcore. The function checks that the variable is 29 : : * correctly set, or returns -1. 30 : : * 31 : : * - If at least one per-core variable was not correct, the test function 32 : : * returns -1. 33 : : */ 34 : : 35 : : static RTE_DEFINE_PER_LCORE(unsigned, test) = 0x12345678; 36 : : 37 : : static int 38 : 1 : assign_vars(__rte_unused void *arg) 39 : : { 40 [ + - ]: 1 : if (RTE_PER_LCORE(test) != 0x12345678) 41 : : return -1; 42 : 1 : RTE_PER_LCORE(test) = rte_lcore_id(); 43 : 1 : return 0; 44 : : } 45 : : 46 : : static int 47 : 1 : display_vars(__rte_unused void *arg) 48 : : { 49 : : unsigned lcore_id = rte_lcore_id(); 50 : 1 : unsigned var = RTE_PER_LCORE(test); 51 : 1 : unsigned socket_id = rte_lcore_to_socket_id(lcore_id); 52 : : 53 : : printf("on socket %u, on core %u, variable is %u\n", socket_id, lcore_id, var); 54 [ + - ]: 1 : if (lcore_id != var) 55 : : return -1; 56 : : 57 : 1 : RTE_PER_LCORE(test) = 0x12345678; 58 : 1 : return 0; 59 : : } 60 : : 61 : : static int 62 : 1 : test_per_lcore_delay(__rte_unused void *arg) 63 : : { 64 : : rte_delay_ms(100); 65 : : printf("wait 100ms on lcore %u\n", rte_lcore_id()); 66 : : 67 : 1 : return 0; 68 : : } 69 : : 70 : : static int 71 : 1 : test_per_lcore(void) 72 : : { 73 : : unsigned lcore_id; 74 : : int ret; 75 : : 76 : 1 : rte_eal_mp_remote_launch(assign_vars, NULL, SKIP_MAIN); 77 [ + + ]: 2 : RTE_LCORE_FOREACH_WORKER(lcore_id) { 78 [ + - ]: 1 : if (rte_eal_wait_lcore(lcore_id) < 0) 79 : : return -1; 80 : : } 81 : : 82 : 1 : rte_eal_mp_remote_launch(display_vars, NULL, SKIP_MAIN); 83 [ + + ]: 2 : RTE_LCORE_FOREACH_WORKER(lcore_id) { 84 [ + - ]: 1 : if (rte_eal_wait_lcore(lcore_id) < 0) 85 : : return -1; 86 : : } 87 : : 88 : : /* test if it could do remote launch twice at the same time or not */ 89 : 1 : ret = rte_eal_mp_remote_launch(test_per_lcore_delay, NULL, SKIP_MAIN); 90 [ - + ]: 1 : if (ret < 0) { 91 : : printf("It fails to do remote launch but it should able to do\n"); 92 : 0 : return -1; 93 : : } 94 : : /* it should not be able to launch a lcore which is running */ 95 : 1 : ret = rte_eal_mp_remote_launch(test_per_lcore_delay, NULL, SKIP_MAIN); 96 [ - + ]: 1 : if (ret == 0) { 97 : : printf("It does remote launch successfully but it should not at this time\n"); 98 : 0 : return -1; 99 : : } 100 [ + + ]: 2 : RTE_LCORE_FOREACH_WORKER(lcore_id) { 101 [ + - ]: 1 : if (rte_eal_wait_lcore(lcore_id) < 0) 102 : : return -1; 103 : : } 104 : : 105 : : return 0; 106 : : } 107 : : 108 : 238 : REGISTER_FAST_TEST(per_lcore_autotest, true, true, test_per_lcore);