Blame src/vma/iomux/epfd_info.h

Packit Service aa3af4
/*
Packit Service aa3af4
 * Copyright (c) 2001-2020 Mellanox Technologies, Ltd. All rights reserved.
Packit Service aa3af4
 *
Packit Service aa3af4
 * This software is available to you under a choice of one of two
Packit Service aa3af4
 * licenses.  You may choose to be licensed under the terms of the GNU
Packit Service aa3af4
 * General Public License (GPL) Version 2, available from the file
Packit Service aa3af4
 * COPYING in the main directory of this source tree, or the
Packit Service aa3af4
 * BSD license below:
Packit Service aa3af4
 *
Packit Service aa3af4
 *     Redistribution and use in source and binary forms, with or
Packit Service aa3af4
 *     without modification, are permitted provided that the following
Packit Service aa3af4
 *     conditions are met:
Packit Service aa3af4
 *
Packit Service aa3af4
 *      - Redistributions of source code must retain the above
Packit Service aa3af4
 *        copyright notice, this list of conditions and the following
Packit Service aa3af4
 *        disclaimer.
Packit Service aa3af4
 *
Packit Service aa3af4
 *      - Redistributions in binary form must reproduce the above
Packit Service aa3af4
 *        copyright notice, this list of conditions and the following
Packit Service aa3af4
 *        disclaimer in the documentation and/or other materials
Packit Service aa3af4
 *        provided with the distribution.
Packit Service aa3af4
 *
Packit Service aa3af4
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
Packit Service aa3af4
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit Service aa3af4
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
Packit Service aa3af4
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
Packit Service aa3af4
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
Packit Service aa3af4
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
Packit Service aa3af4
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
Packit Service aa3af4
 * SOFTWARE.
Packit Service aa3af4
 */
Packit Service aa3af4
Packit Service aa3af4
Packit Service aa3af4
#ifndef VMA_EPOLL_H
Packit Service aa3af4
#define VMA_EPOLL_H
Packit Service aa3af4
Packit Service aa3af4
#include <vma/util/wakeup_pipe.h>
Packit Service aa3af4
#include <vma/sock/cleanable_obj.h>
Packit Service aa3af4
#include <vma/sock/sockinfo.h>
Packit Service aa3af4
Packit Service aa3af4
typedef vma_list_t<socket_fd_api, socket_fd_api::ep_ready_fd_node_offset>   ep_ready_fd_list_t;
Packit Service aa3af4
typedef vma_list_t<socket_fd_api, socket_fd_api::ep_info_fd_node_offset>    fd_info_list_t;
Packit Service aa3af4
typedef std::tr1::unordered_map<int, epoll_fd_rec>                          fd_info_map_t;
Packit Service aa3af4
typedef std::tr1::unordered_map<ring*, int /*ref count*/>                   ring_map_t;
Packit Service aa3af4
typedef std::deque<int>                                                     ready_cq_fd_q_t;
Packit Service aa3af4
Packit Service aa3af4
class epfd_info : public lock_mutex_recursive, public cleanable_obj, public wakeup_pipe
Packit Service aa3af4
{
Packit Service aa3af4
public:
Packit Service aa3af4
	epfd_info(int epfd, int size);
Packit Service aa3af4
	~epfd_info();
Packit Service aa3af4
Packit Service aa3af4
	/**
Packit Service aa3af4
	 * Lock and perform epoll_ctl.
Packit Service aa3af4
	 * Arguments the same as for epoll_ctl()
Packit Service aa3af4
	 */
Packit Service aa3af4
	int ctl(int op, int fd, epoll_event *event);
Packit Service aa3af4
Packit Service aa3af4
	/**
Packit Service aa3af4
	 * Get the offloaded fds array and its length.
Packit Service aa3af4
	 * @param adress of the pointer to number of offloaded fds.
Packit Service aa3af4
	 * @param adress of the offloaded fds array.
Packit Service aa3af4
	 */
Packit Service aa3af4
	void get_offloaded_fds_arr_and_size(int **p_p_num_offloaded_fds,
Packit Service aa3af4
				            int **p_p_offloadded_fds);
Packit Service aa3af4
Packit Service aa3af4
	/**
Packit Service aa3af4
	 * check if fd is cq fd according to the data.
Packit Service aa3af4
	 * if it is, save the fd in ready cq fds queue.
Packit Service aa3af4
	 * @param data field from event data
Packit Service aa3af4
	 * @return true if fd is cq fd
Packit Service aa3af4
	 */
Packit Service aa3af4
	bool is_cq_fd(uint64_t data);
Packit Service aa3af4
Packit Service aa3af4
	/**
Packit Service aa3af4
	 * Get the original user data posted with this fd.
Packit Service aa3af4
	 * @param fd File descriptor.
Packit Service aa3af4
	 * @return Pointer to user data if the data for this fd was found.
Packit Service aa3af4
	 */
Packit Service aa3af4
	epoll_fd_rec* get_fd_rec(int fd);
Packit Service aa3af4
Packit Service aa3af4
	/**
Packit Service aa3af4
	 * Called when fd is closed, to remove it from this set.
Packit Service aa3af4
	 * @param fd Closed file descriptor.
Packit Service aa3af4
	 */
Packit Service aa3af4
	void fd_closed(int fd, bool passthrough = false);
Packit Service aa3af4
Packit Service aa3af4
	ep_ready_fd_list_t              m_ready_fds;
Packit Service aa3af4
Packit Service aa3af4
	/**
Packit Service aa3af4
	 * @return Pointer to statistics block for this group
Packit Service aa3af4
	 */
Packit Service aa3af4
	epoll_stats_t  *stats();
Packit Service aa3af4
Packit Service aa3af4
	int ring_poll_and_process_element(uint64_t *p_poll_sn, void* pv_fd_ready_array = NULL);
Packit Service aa3af4
Packit Service aa3af4
	int ring_request_notification(uint64_t poll_sn);
Packit Service aa3af4
Packit Service aa3af4
	int ring_wait_for_notification_and_process_element(uint64_t *p_poll_sn, void* pv_fd_ready_array = NULL);
Packit Service aa3af4
Packit Service aa3af4
	virtual void clean_obj();
Packit Service aa3af4
Packit Service aa3af4
	void statistics_print(vlog_levels_t log_level = VLOG_DEBUG);
Packit Service aa3af4
Packit Service aa3af4
	// Called from the internal thread to mark that non offloaded data is available.
Packit Service aa3af4
	void set_os_data_available();
Packit Service aa3af4
Packit Service aa3af4
	// Register this epfd to the internal thread, Called after non offloaded data has been received.
Packit Service aa3af4
	void register_to_internal_thread();
Packit Service aa3af4
Packit Service aa3af4
	// Thread safe function which returns true if non offloaded data is available.
Packit Service aa3af4
	// Will also set m_b_os_data_available to false.
Packit Service aa3af4
	bool get_and_unset_os_data_available();
Packit Service aa3af4
Packit Service aa3af4
	// Returns true if non offloaded data is available.
Packit Service aa3af4
	inline bool get_os_data_available() {return m_b_os_data_available;}
Packit Service aa3af4
Packit Service aa3af4
	static inline size_t epfd_info_node_offset(void) {return NODE_OFFSET(epfd_info, epfd_info_node);}
Packit Service aa3af4
	list_node<epfd_info, epfd_info::epfd_info_node_offset>	epfd_info_node;
Packit Service aa3af4
Packit Service aa3af4
private:
Packit Service aa3af4
Packit Service aa3af4
	const int              m_epfd;
Packit Service aa3af4
	int                    m_size;
Packit Service aa3af4
	int                    *m_p_offloaded_fds;
Packit Service aa3af4
	int                    m_n_offloaded_fds;
Packit Service aa3af4
	fd_info_map_t          m_fd_non_offloaded_map;
Packit Service aa3af4
	fd_info_list_t         m_fd_offloaded_list;
Packit Service aa3af4
	ring_map_t             m_ring_map;
Packit Service aa3af4
	lock_mutex_recursive   m_ring_map_lock;
Packit Service aa3af4
	lock_spin              m_lock_poll_os;
Packit Service aa3af4
	const thread_mode_t    m_sysvar_thread_mode;
Packit Service aa3af4
	ready_cq_fd_q_t        m_ready_cq_fd_q;
Packit Service aa3af4
	epoll_stats_t          m_local_stats;
Packit Service aa3af4
	epoll_stats_t          *m_stats;
Packit Service aa3af4
	int                    m_log_invalid_events;
Packit Service aa3af4
	bool                   m_b_os_data_available; // true when non offloaded data is available
Packit Service aa3af4
Packit Service aa3af4
	int add_fd(int fd, epoll_event *event);
Packit Service aa3af4
	int del_fd(int fd, bool passthrough = false);
Packit Service aa3af4
	int mod_fd(int fd, epoll_event *event);
Packit Service aa3af4
Packit Service aa3af4
public:
Packit Service aa3af4
	int get_epoll_fd() {return m_epfd;};
Packit Service aa3af4
	int remove_fd_from_epoll_os(int fd);
Packit Service aa3af4
	inline size_t get_fd_non_offloaded_size() {return  m_fd_non_offloaded_map.size();}
Packit Service aa3af4
	inline size_t get_fd_offloaded_size() {return  m_fd_offloaded_list.size();}
Packit Service aa3af4
	void insert_epoll_event_cb(socket_fd_api* sock_fd, uint32_t event_flags);
Packit Service aa3af4
	void insert_epoll_event(socket_fd_api *sock_fd, uint32_t event_flags);
Packit Service aa3af4
	void remove_epoll_event(socket_fd_api *sock_fd, uint32_t event_flags);
Packit Service aa3af4
	void increase_ring_ref_count(ring* ring);
Packit Service aa3af4
	void decrease_ring_ref_count(ring* ring);
Packit Service aa3af4
};
Packit Service aa3af4
Packit Service aa3af4
#endif
Packit Service aa3af4