New upstream version 18.02
[deb_dpdk.git] / examples / multi_process / l2fwd_fork / flib.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4
5 #ifndef __FLIB_H
6 #define __FLIB_H
7
8 /* callback function pointer when specific slave leaves */
9 typedef void (slave_exit_notify)(unsigned slaveid, int stat);
10
11 enum slave_stat{
12         ST_FREEZE = 1,
13         ST_IDLE,
14         ST_RUN,
15         ST_ZOMBIE,      /* Not implemented yet */
16 };
17
18 /**
19  * Initialize the fork lib.
20  *
21  * @return
22  *    - 0 : fork lib initialized successfully
23  *    - -1 : fork lib initialized failed
24  */
25 int flib_init(void);
26
27 /**
28  * Check that every SLAVE lcores are in WAIT state, then call
29  * flib_remote_launch() for all of them. If call_master is true
30  * (set to CALL_MASTER), also call the function on the master lcore.
31  *
32  * @param f:
33  *      function pointer need to run
34  * @param arg:
35  *      argument for f to carry
36  * @param call_master
37  *      - SKIP_MASTER : only launch function on slave lcores
38  *      - CALL_MASTER : launch function on master and slave lcores
39  * @return
40  *    - 0 : function  execute successfully
41  *    - -1 :  function  execute  failed
42  */
43 int flib_mp_remote_launch(lcore_function_t *f,
44                 void *arg, enum rte_rmt_call_master_t call_master);
45
46 /**
47  * Send a message to a slave lcore identified by slave_id to call a
48  * function f with argument arg.
49  *
50  * @param f:
51  *      function pointer need to run
52  * @param arg:
53  *      argument for f to carry
54  * @param slave_id
55  *      slave lcore id to run on
56  * @return
57  *    - 0 : function  execute successfully
58  *    - -1 :  function  execute  failed
59  */
60 int flib_remote_launch(lcore_function_t *f,
61                                         void *arg, unsigned slave_id);
62
63 /**
64  * Query the running stat for specific slave, wont' work in with master id
65  *
66  * @param slave_id:
67  *      lcore id which should not be master id
68  * @return
69  *    - ST_FREEZE : lcore is not in enabled core mask
70  *       - ST_IDLE     : lcore is idle
71  *    -  ST_RUN     : lcore is running something
72  */
73 enum slave_stat
74 flib_query_slave_status(unsigned slave_id);
75
76 /**
77  * Register a callback function to be notified in case specific slave exit.
78  *
79  * @param slave_id:
80  *      lcore id which should not be master id
81  * @param cb:
82  *      callback pointer to register
83  * @return
84  *    - 0            :  function  execute successfully
85  *    - -EFAULT  :  argument error
86  *    - -ENOENT :  slave_id not correct
87  */
88 int flib_register_slave_exit_notify(unsigned slave_id,
89         slave_exit_notify *cb);
90
91 /**
92  * Assign a lcore ID to non-slave thread.  Non-slave thread refers to thread that
93  * not created by function rte_eal_remote_launch or rte_eal_mp_remote_launch.
94  * These threads can either bind lcore or float among different lcores.
95  * This lcore ID will be unique in multi-thread or multi-process DPDK running
96  * environment, then it can benefit from using the cache mechanism provided in
97  * mempool library.
98  * After calling successfully, use rte_lcore_id() to get the assigned lcore ID, but
99  * other lcore funtions can't guarantee to work correctly.
100  *
101  * @return
102  *   -    -1  : can't assign a lcore id with 3 possibilities.
103  *                 - it's not non-slave thread.
104  *                 - it had assign a lcore id previously
105  *                 - the lcore id is running out.
106  *   -  > 0 :  the assigned lcore id.
107  */
108 int flib_assign_lcore_id(void);
109
110 /**
111  * Free the lcore_id that assigned in flib_assign_lcore_id().
112  * call it in case non-slave thread is leaving or left.
113  *
114  * @param lcore_id
115  * The identifier of the lcore, which MUST be between 1 and
116  *   RTE_MAX_LCORE-1.
117  */
118 void flib_free_lcore_id(unsigned lcore_id);
119
120 #endif /* __FLIB_H  */