X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvcl%2Fvcl_private.h;h=5918a019eaa2717c43d09d1f10f2e30b99ee55d3;hb=070453d872b22b75182381c44817c9486d280ec4;hp=aba4839f12993a63a8551b2141b6eb0597bea388;hpb=3c2fed5145d9e40a9ecd178c2866c813eddc6203;p=vpp.git diff --git a/src/vcl/vcl_private.h b/src/vcl/vcl_private.h index aba4839f129..5918a019eaa 100644 --- a/src/vcl/vcl_private.h +++ b/src/vcl/vcl_private.h @@ -58,6 +58,7 @@ typedef enum #define SERVER_STATE_OPEN (STATE_ACCEPT|STATE_CLOSE_ON_EMPTY) #define CLIENT_STATE_OPEN (STATE_CONNECT|STATE_CLOSE_ON_EMPTY) +#define STATE_OPEN (SERVER_STATE_OPEN | CLIENT_STATE_OPEN) typedef struct epoll_event vppcom_epoll_event_t; @@ -78,6 +79,15 @@ typedef struct ip46_address_t ip46; } vppcom_ip46_t; +typedef struct vcl_session_msg +{ + u32 next; + union + { + session_accepted_msg_t accepted_msg; + }; +} vcl_session_msg_t; + enum { VCL_SESS_ATTR_SERVER, @@ -130,9 +140,10 @@ typedef struct u32 wait_cont_idx; vppcom_epoll_t vep; int libc_epfd; - u64 client_queue_address; + svm_msg_q_t *our_evt_q; u64 options[16]; vce_event_handler_reg_t *poll_reg; + vcl_session_msg_t *accept_evts_fifo; #if VCL_ELOG elog_track_t elog_track; #endif @@ -156,35 +167,56 @@ typedef struct vppcom_cfg_t_ u8 app_scope_global; u8 *namespace_id; u64 namespace_secret; + u8 use_mq_eventfd; f64 app_timeout; f64 session_timeout; f64 accept_timeout; u32 event_ring_size; char *event_log_path; u8 *vpp_api_filename; + u8 *vpp_api_socket_name; } vppcom_cfg_t; void vppcom_cfg (vppcom_cfg_t * vcl_cfg); +typedef struct vcl_cut_through_registration_ +{ + svm_msg_q_t *mq; + svm_msg_q_t *peer_mq; + u32 sid; + u32 epoll_evt_conn_index; /*< mq evt connection index part of + the mqs evtfd epoll (if used) */ +} vcl_cut_through_registration_t; + +typedef struct vcl_mq_evt_conn_ +{ + svm_msg_q_t *mq; + int mq_fd; +} vcl_mq_evt_conn_t; + typedef struct vppcom_main_t_ { u8 init; u32 debug; int main_cpu; - /* FIFO for accepted connections - used in epoll/select */ - clib_spinlock_t session_fifo_lockp; - u32 *client_session_index_fifo; - /* vpp input queue */ svm_queue_t *vl_input_queue; /* API client handle */ u32 my_client_index; /* Session pool */ - clib_spinlock_t sessions_lockp; vcl_session_t *sessions; + /** Message queues epoll fd. Initialized only if using mqs with eventfds */ + int mqs_epfd; + + /** Pool of event message queue event connections */ + vcl_mq_evt_conn_t *mq_evt_conns; + + /** Per worker buffer for receiving mq epoll events */ + struct epoll_event *mq_events; + /* Hash table for disconnect processing */ uword *session_index_by_vpp_handles; @@ -196,6 +228,8 @@ typedef struct vppcom_main_t_ /* Our event queue */ svm_msg_q_t *app_event_queue; + svm_msg_q_t **vpp_event_queues; + /* unique segment name counter */ u32 unique_segment_index; @@ -213,6 +247,23 @@ typedef struct vppcom_main_t_ /* IO thread */ vppcom_session_io_thread_t session_io_thread; + /* pool of ctrl msgs */ + vcl_session_msg_t *ctrl_evt_pool; + + /** Pool of cut through registrations */ + vcl_cut_through_registration_t *cut_through_registrations; + + /** Lock for accessing ct registration pool */ + clib_spinlock_t ct_registration_lock; + + /** Cut-through registration by mq address hash table */ + uword *ct_registration_by_mq; + + svm_msg_q_msg_t *mq_msg_vector; + + /** Flag indicating that a new segment is being mounted */ + volatile u32 mounting_segment; + #ifdef VCL_ELOG /* VPP Event-logger */ elog_main_t elog_main; @@ -225,49 +276,59 @@ typedef struct vppcom_main_t_ extern vppcom_main_t *vcm; -#define VCL_SESSION_LOCK_AND_GET(I, S) \ -do { \ - clib_spinlock_lock (&vcm->sessions_lockp); \ - rv = vppcom_session_at_index (I, S); \ - if (PREDICT_FALSE (rv)) \ - { \ - clib_spinlock_unlock (&vcm->sessions_lockp); \ - clib_warning ("VCL<%d>: ERROR: Invalid ##I (%u)!", \ - getpid (), I); \ - goto done; \ - } \ -} while (0) - -#define VCL_SESSION_LOCK() clib_spinlock_lock (&(vcm->sessions_lockp)) -#define VCL_SESSION_UNLOCK() clib_spinlock_unlock (&(vcm->sessions_lockp)) - -#define VCL_IO_SESSIONS_LOCK() \ - clib_spinlock_lock (&(vcm->session_io_thread.io_sessions_lockp)) -#define VCL_IO_SESSIONS_UNLOCK() \ - clib_spinlock_unlock (&(vcm->session_io_thread.io_sessions_lockp)) - -#define VCL_ACCEPT_FIFO_LOCK() clib_spinlock_lock (&(vcm->session_fifo_lockp)) -#define VCL_ACCEPT_FIFO_UNLOCK() \ - clib_spinlock_unlock (&(vcm->session_fifo_lockp)) - -#define VCL_EVENTS_LOCK() \ - clib_spinlock_lock (&(vcm->event_thread.events_lockp)) -#define VCL_EVENTS_UNLOCK() \ - clib_spinlock_unlock (&(vcm->event_thread.events_lockp)) - -static inline int -vppcom_session_at_index (u32 session_index, vcl_session_t * volatile *sess) +#define VCL_INVALID_SESSION_INDEX ((u32)~0) + +static inline vcl_session_t * +vcl_session_alloc (void) { - /* Assumes that caller has acquired spinlock: vcm->sessions_lockp */ - if (PREDICT_FALSE ((session_index == ~0) || - pool_is_free_index (vcm->sessions, session_index))) - { - clib_warning ("VCL<%d>: invalid session, sid (%u) has been closed!", - getpid (), session_index); - return VPPCOM_EBADFD; - } - *sess = pool_elt_at_index (vcm->sessions, session_index); - return VPPCOM_OK; + vcl_session_t *s; + pool_get (vcm->sessions, s); + memset (s, 0, sizeof (*s)); + return s; +} + +static inline void +vcl_session_free (vcl_session_t * s) +{ + pool_put (vcm->sessions, s); +} + +static inline vcl_session_t * +vcl_session_get (u32 session_index) +{ + if (pool_is_free_index (vcm->sessions, session_index)) + return 0; + return pool_elt_at_index (vcm->sessions, session_index); +} + +static inline u32 +vcl_session_index (vcl_session_t * s) +{ + return (s - vcm->sessions); +} + +static inline vcl_session_t * +vcl_session_get_w_handle (u64 handle) +{ + uword *p; + if ((p = hash_get (vcm->session_index_by_vpp_handles, handle))) + return vcl_session_get ((u32) p[0]); + return 0; +} + +static inline u32 +vcl_session_get_index_from_handle (u64 handle) +{ + uword *p; + if ((p = hash_get (vcm->session_index_by_vpp_handles, handle))) + return p[0]; + return VCL_INVALID_SESSION_INDEX; +} + +static inline u8 +vcl_session_is_ct (vcl_session_t * s) +{ + return (s->our_evt_q != 0); } static inline void @@ -307,6 +368,23 @@ vppcom_session_table_lookup_listener (u64 listener_handle) const char *vppcom_session_state_str (session_state_t state); +/* + * Helpers + */ +vcl_cut_through_registration_t *vcl_ct_registration_lock_and_alloc (void); +void vcl_ct_registration_del (vcl_cut_through_registration_t * ctr); +u32 vcl_ct_registration_index (vcl_cut_through_registration_t * ctr); +void vcl_ct_registration_unlock (void); +vcl_cut_through_registration_t *vcl_ct_registration_get (u32 ctr_index); +vcl_cut_through_registration_t *vcl_ct_registration_lock_and_lookup (uword); +void vcl_ct_registration_lookup_add (uword mq_addr, u32 ctr_index); +void vcl_ct_registration_lookup_del (uword mq_addr); +vcl_mq_evt_conn_t *vcl_mq_evt_conn_alloc (void); +u32 vcl_mq_evt_conn_index (vcl_mq_evt_conn_t * mqc); +vcl_mq_evt_conn_t *vcl_mq_evt_conn_get (u32 mq_conn_idx); +int vcl_mq_epoll_add_evfd (svm_msg_q_t * mq); +int vcl_mq_epoll_del_evfd (u32 mqc_index); + /* * VCL Binary API */ @@ -326,6 +404,8 @@ void vppcom_send_accept_session_reply (u64 handle, u32 context, int retval); u32 vcl_max_nsid_len (void); +u8 *format_api_error (u8 * s, va_list * args); + #endif /* SRC_VCL_VCL_PRIVATE_H_ */ /*