xref: /dpdk/lib/eal/include/rte_epoll.h (revision 2a7a42a5918af42dbf229d30dbba13697e68320f)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell International Ltd.
3  */
4 
5 #ifndef __RTE_EPOLL_H__
6 #define __RTE_EPOLL_H__
7 
8 /**
9  * @file
10  * The rte_epoll provides interfaces functions to add delete events,
11  * wait poll for an event.
12  */
13 
14 #include <stdint.h>
15 
16 #include <rte_stdatomic.h>
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #define RTE_INTR_EVENT_ADD            1UL
23 #define RTE_INTR_EVENT_DEL            2UL
24 
25 typedef void (*rte_intr_event_cb_t)(int fd, void *arg);
26 
27 struct rte_epoll_data {
28 	uint32_t event;               /**< event type */
29 	void *data;                   /**< User data */
30 	rte_intr_event_cb_t cb_fun;   /**< IN: callback fun */
31 	void *cb_arg;	              /**< IN: callback arg */
32 };
33 
34 enum {
35 	RTE_EPOLL_INVALID = 0,
36 	RTE_EPOLL_VALID,
37 	RTE_EPOLL_EXEC,
38 };
39 
40 /** interrupt epoll event obj, taken by epoll_event.ptr */
41 struct rte_epoll_event {
42 	RTE_ATOMIC(uint32_t) status;           /**< OUT: event status */
43 	int fd;                    /**< OUT: event fd */
44 	int epfd;       /**< OUT: epoll instance the ev associated with */
45 	struct rte_epoll_data epdata;
46 };
47 
48 #define RTE_EPOLL_PER_THREAD        -1  /**< to hint using per thread epfd */
49 
50 /**
51  * It waits for events on the epoll instance.
52  * Retries if signal received.
53  *
54  * @param epfd
55  *   Epoll instance fd on which the caller wait for events.
56  * @param events
57  *   Memory area contains the events that will be available for the caller.
58  * @param maxevents
59  *   Up to maxevents are returned, must greater than zero.
60  * @param timeout
61  *   Specifying a timeout of -1 causes a block indefinitely.
62  *   Specifying a timeout equal to zero cause to return immediately.
63  * @return
64  *   - On success, returns the number of available event.
65  *   - On failure, a negative value.
66  */
67 int
68 rte_epoll_wait(int epfd, struct rte_epoll_event *events,
69 	       int maxevents, int timeout);
70 
71 /**
72  * It waits for events on the epoll instance.
73  * Does not retry if signal received.
74  *
75  * @param epfd
76  *   Epoll instance fd on which the caller wait for events.
77  * @param events
78  *   Memory area contains the events that will be available for the caller.
79  * @param maxevents
80  *   Up to maxevents are returned, must greater than zero.
81  * @param timeout
82  *   Specifying a timeout of -1 causes a block indefinitely.
83  *   Specifying a timeout equal to zero cause to return immediately.
84  * @return
85  *   - On success, returns the number of available event.
86  *   - On failure, a negative value.
87  */
88 int
89 rte_epoll_wait_interruptible(int epfd, struct rte_epoll_event *events,
90 	       int maxevents, int timeout);
91 
92 /**
93  * It performs control operations on epoll instance referred by the epfd.
94  * It requests that the operation op be performed for the target fd.
95  *
96  * @param epfd
97  *   Epoll instance fd on which the caller perform control operations.
98  * @param op
99  *   The operation be performed for the target fd.
100  * @param fd
101  *   The target fd on which the control ops perform.
102  * @param event
103  *   Describes the object linked to the fd.
104  *   Note: The caller must take care the object deletion after CTL_DEL.
105  * @return
106  *   - On success, zero.
107  *   - On failure, a negative value.
108  */
109 int
110 rte_epoll_ctl(int epfd, int op, int fd,
111 	      struct rte_epoll_event *event);
112 
113 #ifdef __cplusplus
114 }
115 #endif
116 
117 #endif /* __RTE_EPOLL_H__ */
118