33 #include "../gpunetio_common.h"
35 #define MAC_ADDR_BYTE_SZ 6
36 #define MAX_PORT_STR_LEN 128
60 DOCA_LOG_ERR(
"Failed to open NIC device based on PCI address");
74 struct doca_flow_cfg *queue_flow_cfg;
117 struct doca_flow_port_cfg *port_cfg;
161 ret = clock_gettime(CLOCK_REALTIME, &t);
165 return (uint64_t)t.tv_nsec + (uint64_t)t.tv_sec * 1000 * 1000 * 1000;
193 DOCA_LOG_ERR(
"Unable to create doca_buf: failed to create mmap");
199 DOCA_LOG_ERR(
"Unable to add dev to buf: doca mmap internal error");
203 status = doca_gpu_mem_alloc(buf->
gpu_dev,
210 DOCA_LOG_ERR(
"Unable to alloc txbuf: failed to allocate gpu memory");
215 status = doca_gpu_dmabuf_fd(buf->
gpu_dev,
220 DOCA_LOG_INFO(
"Mapping send queue buffer (0x%p size %dB) with legacy nvidia-peermem mode",
227 DOCA_LOG_ERR(
"Unable to start buf: doca mmap internal error");
231 DOCA_LOG_INFO(
"Mapping send queue buffer (0x%p size %dB dmabuf fd %d) with dmabuf mode",
249 DOCA_LOG_ERR(
"Unable to start buf: doca mmap internal error");
255 DOCA_LOG_ERR(
"Unable to start buf: doca mmap internal error");
261 DOCA_LOG_ERR(
"Unable to start buf: doca buf_arr internal error");
267 DOCA_LOG_ERR(
"Unable to start buf: doca buf_arr internal error");
273 DOCA_LOG_ERR(
"Unable to start buf: doca buf_arr internal error");
279 DOCA_LOG_ERR(
"Unable to start buf: doca buf_arr internal error");
300 uint8_t *cpu_pkt_addr;
303 cudaError_t res_cuda;
308 const char *payload =
"Sent from DOCA GPUNetIO";
325 if (cpu_pkt_addr ==
NULL) {
326 DOCA_LOG_ERR(
"Error in txbuf preparation, failed to allocate memory");
335 hdr->s_addr_bytes[1] = mac_addr[1];
336 hdr->s_addr_bytes[2] = mac_addr[2];
337 hdr->s_addr_bytes[3] = mac_addr[3];
338 hdr->s_addr_bytes[4] = mac_addr[4];
339 hdr->s_addr_bytes[5] = mac_addr[5];
341 hdr->d_addr_bytes[0] = 0x10;
342 hdr->d_addr_bytes[1] = 0x11;
343 hdr->d_addr_bytes[2] = 0x12;
344 hdr->d_addr_bytes[3] = 0x13;
345 hdr->d_addr_bytes[4] = 0x14;
346 hdr->d_addr_bytes[5] = 0x15;
359 if (res_cuda != cudaSuccess) {
360 DOCA_LOG_ERR(
"Function CUDA Memcpy cqe_addr failed with %s", cudaGetErrorString(res_cuda));
392 DOCA_LOG_ERR(
"Unable to destroy doca_buf: failed to destroy mmap");
400 DOCA_LOG_ERR(
"Unable to stop buf: failed to free gpu memory");
408 DOCA_LOG_ERR(
"Unable to stop buf: failed to destroy doca_buf_arr");
414 DOCA_LOG_ERR(
"Unable to stop buf: failed to destroy doca_buf_arr");
473 DOCA_LOG_ERR(
"Can't create DOCA Eth Tx queue, invalid input");
534 uint64_t *intervals_cpu =
NULL;
535 uint64_t *intervals_gpu =
NULL;
542 cudaError_t res_rt = cudaSuccess;
607 res_rt = cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking);
608 if (res_rt != cudaSuccess) {
609 DOCA_LOG_ERR(
"Function cudaStreamCreateWithFlags error %d", res_rt);
617 (
void **)&intervals_gpu,
618 (
void **)&intervals_cpu);
628 &intervals_cpu[idx]);
630 DOCA_LOG_ERR(
"Failed to get wait on time value for timestamp %ld, error %s",
639 cudaStreamSynchronize(stream);
649 doca_gpu_mem_free(
gpu_dev, intervals_gpu);
static doca_error_t open_doca_device_with_pci(const char *pcie_value, struct doca_dev **retval)
static struct doca_gpu * gpu_dev
static struct doca_dev * ddev
#define NUM_PACKETS_X_BURST
doca_error_t kernel_send_wait_on_time(cudaStream_t stream, struct txq_queue *txq, uint64_t *intervals_gpu)
static doca_error_t destroy_txq(struct txq_queue *txq)
static doca_error_t init_doca_flow(void)
static doca_error_t init_doca_device(char *nic_pcie_addr, struct doca_dev **ddev)
struct doca_flow_port * df_port
static doca_error_t destroy_tx_buf(struct txq_queue *txq)
doca_error_t gpunetio_send_wait_time(struct sample_send_wait_cfg *sample_cfg)
static doca_error_t start_doca_flow(struct doca_dev *dev)
static doca_error_t create_tx_buf(struct txq_queue *txq, uint32_t num_packets, uint32_t max_pkt_sz)
static doca_error_t prepare_tx_buf(struct txq_queue *txq, struct doca_dev *ddev)
static doca_error_t create_txq(struct txq_queue *txq, struct doca_gpu *gpu_dev, struct doca_dev *ddev)
DOCA_LOG_REGISTER(GPU_SEND_WAIT_TIME :SAMPLE)
DOCA_EXPERIMENTAL doca_error_t doca_buf_arr_destroy(struct doca_buf_arr *buf_arr)
Destroys a doca buf array instance.
DOCA_EXPERIMENTAL doca_error_t doca_buf_arr_set_params(struct doca_buf_arr *buf_arr, struct doca_mmap *mmap, size_t elem_size, uint64_t start_offset)
Sets the buf array params.
DOCA_EXPERIMENTAL doca_error_t doca_buf_arr_stop(struct doca_buf_arr *buf_arr)
Stops a started doca buf array.
DOCA_EXPERIMENTAL doca_error_t doca_buf_arr_set_target_gpu(struct doca_buf_arr *buf_arr, struct doca_gpu *gpu_handler)
Configures the buf array to be created on the gpu device.
DOCA_EXPERIMENTAL doca_error_t doca_buf_arr_get_gpu_handle(const struct doca_buf_arr *buf_arr, struct doca_gpu_buf_arr **gpu_buf_arr)
Retrieves the handle in the gpu memory space of a doca_buf_arr.
DOCA_EXPERIMENTAL doca_error_t doca_buf_arr_create(size_t num_elem, struct doca_buf_arr **buf_arr)
Allocates a doca_buf_arr.
DOCA_EXPERIMENTAL doca_error_t doca_buf_arr_start(struct doca_buf_arr *buf_arr)
This method enables the allocation of doca_bufs.
DOCA_STABLE doca_error_t doca_ctx_start(struct doca_ctx *ctx)
Finalizes all configurations, and starts the DOCA CTX.
DOCA_EXPERIMENTAL doca_error_t doca_ctx_set_datapath_on_gpu(struct doca_ctx *ctx, struct doca_gpu *gpu_dev)
This function binds the DOCA context to a gpu device.
DOCA_STABLE doca_error_t doca_ctx_stop(struct doca_ctx *ctx)
Stops the context allowing reconfiguration.
DOCA_STABLE doca_error_t doca_devinfo_get_mac_addr(const struct doca_devinfo *devinfo, uint8_t *mac_addr, uint32_t size)
Get the MAC address of a DOCA devinfo.
#define DOCA_DEVINFO_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
DOCA_STABLE struct doca_devinfo * doca_dev_as_devinfo(const struct doca_dev *dev)
Get local device info from device. This should be useful when wanting to query information about devi...
DOCA_STABLE doca_error_t doca_dev_close(struct doca_dev *dev)
Destroy allocated local device instance.
DOCA_EXPERIMENTAL doca_error_t doca_dpdk_port_probe(struct doca_dev *dev, const char *devargs)
Attach a DPDK port specified by DOCA device.
enum doca_error doca_error_t
DOCA API return codes.
DOCA_STABLE const char * doca_error_get_descr(doca_error_t error)
Returns the description string of an error code.
@ DOCA_ERROR_INVALID_VALUE
DOCA_EXPERIMENTAL struct doca_ctx * doca_eth_txq_as_doca_ctx(struct doca_eth_txq *eth_txq)
Convert doca_eth_txq instance into a generalized context for use with doca core objects.
DOCA_EXPERIMENTAL doca_error_t doca_eth_txq_get_gpu_handle(const struct doca_eth_txq *eth_txq, struct doca_gpu_eth_txq **eth_txq_ext)
Get a gpu handle of a doca_eth_txq.
DOCA_EXPERIMENTAL doca_error_t doca_eth_txq_set_wait_on_time_offload(struct doca_eth_txq *eth_txq)
Set offload to enable wait on time feature on the queue. can only be called before calling doca_ctx_s...
DOCA_EXPERIMENTAL doca_error_t doca_eth_txq_create(struct doca_dev *dev, uint32_t max_burst_size, struct doca_eth_txq **eth_txq)
Create a DOCA ETH TXQ instance.
DOCA_EXPERIMENTAL doca_error_t doca_eth_txq_destroy(struct doca_eth_txq *eth_txq)
Destroy a DOCA ETH TXQ instance.
DOCA_EXPERIMENTAL doca_error_t doca_eth_txq_cap_get_wait_on_time_offload_supported(const struct doca_devinfo *devinfo, enum doca_eth_wait_on_time_type *wait_on_time_mode)
Check if wait on time offload is supported by the network device.
DOCA_EXPERIMENTAL doca_error_t doca_eth_txq_calculate_timestamp(struct doca_eth_txq *eth_txq, uint64_t timestamp_ns, uint64_t *wait_on_time_value)
Calculate timestamp to use when setting the wait on time on the Tx queue.
#define DOCA_FLOW_ETHER_TYPE_IPV4
DOCA_STABLE doca_error_t doca_flow_cfg_set_mode_args(struct doca_flow_cfg *cfg, const char *mode_args)
Set DOCA mode args.
DOCA_EXPERIMENTAL doca_error_t doca_flow_port_start(const struct doca_flow_port_cfg *cfg, struct doca_flow_port **port)
Start a doca port.
DOCA_STABLE doca_error_t doca_flow_cfg_create(struct doca_flow_cfg **cfg)
Create DOCA Flow configuration struct.
DOCA_EXPERIMENTAL doca_error_t doca_flow_init(struct doca_flow_cfg *cfg)
Initialize the doca flow.
DOCA_EXPERIMENTAL doca_error_t doca_flow_port_cfg_set_dev(struct doca_flow_port_cfg *cfg, struct doca_dev *dev)
Set port's device.
DOCA_STABLE doca_error_t doca_flow_port_stop(struct doca_flow_port *port)
Stop a doca port.
DOCA_EXPERIMENTAL doca_error_t doca_flow_port_cfg_set_port_id(struct doca_flow_port_cfg *cfg, uint16_t port_id)
Set the logical port ID.
DOCA_STABLE doca_error_t doca_flow_port_cfg_create(struct doca_flow_port_cfg **cfg)
Create DOCA Flow port configuration struct.
DOCA_STABLE doca_error_t doca_flow_port_cfg_destroy(struct doca_flow_port_cfg *cfg)
Destroy DOCA Flow port configuration struct.
DOCA_STABLE doca_error_t doca_flow_cfg_set_pipe_queues(struct doca_flow_cfg *cfg, uint16_t pipe_queues)
Set pipe queues.
DOCA_STABLE doca_error_t doca_flow_cfg_destroy(struct doca_flow_cfg *cfg)
Destroy DOCA Flow configuration struct.
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
DOCA_STABLE doca_error_t doca_mmap_set_memrange(struct doca_mmap *mmap, void *addr, size_t len)
Set the memory range of DOCA memory map.
DOCA_STABLE doca_error_t doca_mmap_destroy(struct doca_mmap *mmap)
Destroy DOCA Memory Map structure.
DOCA_STABLE doca_error_t doca_mmap_create(struct doca_mmap **mmap)
Allocates zero size memory map object with default/unset attributes.
DOCA_STABLE doca_error_t doca_mmap_set_permissions(struct doca_mmap *mmap, uint32_t access_mask)
Set access flags of the registered memory.
DOCA_STABLE doca_error_t doca_mmap_start(struct doca_mmap *mmap)
Start DOCA Memory Map.
DOCA_STABLE doca_error_t doca_mmap_add_dev(struct doca_mmap *mmap, struct doca_dev *dev)
Register DOCA memory map on a given device.
DOCA_STABLE doca_error_t doca_mmap_set_dmabuf_memrange(struct doca_mmap *mmap, int dmabuf_fd, void *addr, size_t dmabuf_offset, size_t len)
Set the memory range of DOCA memory map using dmabuf.
doca_eth_wait_on_time_type
Type of wait on time the network card can support.
@ DOCA_GPU_MEM_TYPE_GPU_CPU
@ DOCA_ACCESS_FLAG_LOCAL_READ_WRITE
@ DOCA_ETH_WAIT_ON_TIME_TYPE_DPDK
uint8_t s_addr_bytes[ETHER_ADDR_LEN]
uint32_t time_interval_ns
char gpu_pcie_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]
char nic_pcie_addr[DOCA_DEVINFO_PCI_ADDR_SIZE]
struct doca_buf_arr * buf_arr
struct doca_gpu_buf_arr * buf_arr_gpu
struct doca_gpu * gpu_dev
struct doca_gpu_eth_txq * eth_txq_gpu
struct doca_ctx * eth_txq_ctx
struct doca_eth_txq * eth_txq_cpu
struct doca_gpu * gpu_dev