1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
9 #include <rte_common.h>
10 #include <rte_memory.h>
11 #include <rte_per_lcore.h>
12 #include <rte_launch.h>
14 #include <rte_lcore.h>
15 #include <rte_cycles.h>
20 * Per-lcore variables and lcore launch
21 * ====================================
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.
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.
31 * - If at least one per-core variable was not correct, the test function
35 static RTE_DEFINE_PER_LCORE(unsigned, test) = 0x12345678;
38 assign_vars(__attribute__((unused)) void *arg)
40 if (RTE_PER_LCORE(test) != 0x12345678)
42 RTE_PER_LCORE(test) = rte_lcore_id();
47 display_vars(__attribute__((unused)) void *arg)
49 unsigned lcore_id = rte_lcore_id();
50 unsigned var = RTE_PER_LCORE(test);
51 unsigned socket_id = rte_lcore_to_socket_id(lcore_id);
53 printf("on socket %u, on core %u, variable is %u\n", socket_id, lcore_id, var);
57 RTE_PER_LCORE(test) = 0x12345678;
62 test_per_lcore_delay(__attribute__((unused)) void *arg)
65 printf("wait 100ms on lcore %u\n", rte_lcore_id());
76 rte_eal_mp_remote_launch(assign_vars, NULL, SKIP_MASTER);
77 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
78 if (rte_eal_wait_lcore(lcore_id) < 0)
82 rte_eal_mp_remote_launch(display_vars, NULL, SKIP_MASTER);
83 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
84 if (rte_eal_wait_lcore(lcore_id) < 0)
88 /* test if it could do remote launch twice at the same time or not */
89 ret = rte_eal_mp_remote_launch(test_per_lcore_delay, NULL, SKIP_MASTER);
91 printf("It fails to do remote launch but it should able to do\n");
94 /* it should not be able to launch a lcore which is running */
95 ret = rte_eal_mp_remote_launch(test_per_lcore_delay, NULL, SKIP_MASTER);
97 printf("It does remote launch successfully but it should not at this time\n");
100 RTE_LCORE_FOREACH_SLAVE(lcore_id) {
101 if (rte_eal_wait_lcore(lcore_id) < 0)
108 REGISTER_TEST_COMMAND(per_lcore_autotest, test_per_lcore);