]> git.proxmox.com Git - ceph.git/blob - ceph/src/dpdk/examples/multi_process/l2fwd_fork/flib.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / dpdk / examples / multi_process / l2fwd_fork / flib.h
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 #ifndef __FLIB_H
35 #define __FLIB_H
36
37 /* callback function pointer when specific slave leaves */
38 typedef void (slave_exit_notify)(unsigned slaveid, int stat);
39
40 enum slave_stat{
41 ST_FREEZE = 1,
42 ST_IDLE,
43 ST_RUN,
44 ST_ZOMBIE, /* Not implemented yet */
45 };
46
47 /**
48 * Initialize the fork lib.
49 *
50 * @return
51 * - 0 : fork lib initialized successfully
52 * - -1 : fork lib initialized failed
53 */
54 int flib_init(void);
55
56 /**
57 * Check that every SLAVE lcores are in WAIT state, then call
58 * flib_remote_launch() for all of them. If call_master is true
59 * (set to CALL_MASTER), also call the function on the master lcore.
60 *
61 * @param f:
62 * function pointer need to run
63 * @param arg:
64 * argument for f to carry
65 * @param call_master
66 * - SKIP_MASTER : only launch function on slave lcores
67 * - CALL_MASTER : launch function on master and slave lcores
68 * @return
69 * - 0 : function execute successfully
70 * - -1 : function execute failed
71 */
72 int flib_mp_remote_launch(lcore_function_t *f,
73 void *arg, enum rte_rmt_call_master_t call_master);
74
75 /**
76 * Send a message to a slave lcore identified by slave_id to call a
77 * function f with argument arg.
78 *
79 * @param f:
80 * function pointer need to run
81 * @param arg:
82 * argument for f to carry
83 * @param slave_id
84 * slave lcore id to run on
85 * @return
86 * - 0 : function execute successfully
87 * - -1 : function execute failed
88 */
89 int flib_remote_launch(lcore_function_t *f,
90 void *arg, unsigned slave_id);
91
92 /**
93 * Query the running stat for specific slave, wont' work in with master id
94 *
95 * @param slave_id:
96 * lcore id which should not be master id
97 * @return
98 * - ST_FREEZE : lcore is not in enabled core mask
99 * - ST_IDLE : lcore is idle
100 * - ST_RUN : lcore is running something
101 */
102 enum slave_stat
103 flib_query_slave_status(unsigned slave_id);
104
105 /**
106 * Register a callback function to be notified in case specific slave exit.
107 *
108 * @param slave_id:
109 * lcore id which should not be master id
110 * @param cb:
111 * callback pointer to register
112 * @return
113 * - 0 : function execute successfully
114 * - -EFAULT : argument error
115 * - -ENOENT : slave_id not correct
116 */
117 int flib_register_slave_exit_notify(unsigned slave_id,
118 slave_exit_notify *cb);
119
120 /**
121 * Assign a lcore ID to non-slave thread. Non-slave thread refers to thread that
122 * not created by function rte_eal_remote_launch or rte_eal_mp_remote_launch.
123 * These threads can either bind lcore or float among differnt lcores.
124 * This lcore ID will be unique in multi-thread or multi-process DPDK running
125 * environment, then it can benefit from using the cache mechanism provided in
126 * mempool library.
127 * After calling successfully, use rte_lcore_id() to get the assigned lcore ID, but
128 * other lcore funtions can't guarantee to work correctly.
129 *
130 * @return
131 * - -1 : can't assign a lcore id with 3 possibilities.
132 * - it's not non-slave thread.
133 * - it had assign a lcore id previously
134 * - the lcore id is running out.
135 * - > 0 : the assigned lcore id.
136 */
137 int flib_assign_lcore_id(void);
138
139 /**
140 * Free the lcore_id that assigned in flib_assign_lcore_id().
141 * call it in case non-slave thread is leaving or left.
142 *
143 * @param lcore_id
144 * The identifier of the lcore, which MUST be between 1 and
145 * RTE_MAX_LCORE-1.
146 */
147 void flib_free_lcore_id(unsigned lcore_id);
148
149 #endif /* __FLIB_H */