26 #include <arpa/inet.h>
30 #include "gpunetio_common.h"
34 #define FLOW_NB_COUNTERS 524228
36 #define MBUF_SIZE 2048
37 #define CPU_TO_BE16(val) __builtin_bswap16(val)
51 if (signum == SIGINT || signum == SIGTERM) {
52 DOCA_LOG_INFO(
"Signal %d received, preparing to exit!", signum);
76 DOCA_LOG_ERR(
"Failed to open NIC device based on PCI address");
90 struct doca_flow_cfg *queue_flow_cfg;
140 struct doca_flow_port_cfg *port_cfg;
185 DOCA_LOG_ERR(
"Can't destroy UDP queues, invalid input");
250 struct doca_dev *
ddev,
255 cudaError_t res_cuda;
257 uint32_t buffer_size = 0;
258 uint8_t *cpu_pkt_addr;
347 cpu_pkt_addr = (uint8_t *)calloc(txq->
cuda_threads * pkt_size,
sizeof(uint8_t));
348 if (cpu_pkt_addr ==
NULL) {
349 DOCA_LOG_ERR(
"Error in tx buf preparation, failed to allocate memory");
355 for (uint32_t idx = 0; idx < txq->
cuda_threads; idx++) {
356 eth = (
struct ether_hdr *)(cpu_pkt_addr + (idx * pkt_size));
357 eth->d_addr_bytes[0] = 0x10;
358 eth->d_addr_bytes[1] = 0x11;
359 eth->d_addr_bytes[2] = 0x12;
360 eth->d_addr_bytes[3] = 0x13;
361 eth->d_addr_bytes[4] = 0x14;
362 eth->d_addr_bytes[5] = 0x15;
364 eth->s_addr_bytes[0] = 0x20;
365 eth->s_addr_bytes[1] = 0x21;
366 eth->s_addr_bytes[2] = 0x22;
367 eth->s_addr_bytes[3] = 0x23;
368 eth->s_addr_bytes[4] = 0x24;
369 eth->s_addr_bytes[5] = 0x25;
374 res_cuda = cudaMemcpy(txq->
gpu_pkt_addr, cpu_pkt_addr, buffer_size, cudaMemcpyDefault);
376 if (res_cuda != cudaSuccess) {
377 DOCA_LOG_ERR(
"Function CUDA Memcpy cqe_addr failed with %s", cudaGetErrorString(res_cuda));
384 DOCA_LOG_INFO(
"Mapping receive queue buffer (0x%p size %dB) with nvidia-peermem mode",
395 DOCA_LOG_INFO(
"Mapping receive queue buffer (0x%p size %dB dmabuf fd %d) with dmabuf mode",
425 DOCA_LOG_ERR(
"Unable to start buf: doca buf_arr internal error");
431 DOCA_LOG_ERR(
"Unable to start buf: doca buf_arr internal error");
437 DOCA_LOG_ERR(
"Unable to start buf: doca buf_arr internal error");
443 DOCA_LOG_ERR(
"Unable to start buf: doca buf_arr internal error");
473 cudaError_t res_rt = cudaSuccess;
474 uint32_t *cpu_exit_condition;
475 uint32_t *gpu_exit_condition;
512 res_rt = cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking);
513 if (res_rt != cudaSuccess) {
514 DOCA_LOG_ERR(
"Function cudaStreamCreateWithFlags error %d", res_rt);
522 (
void **)&gpu_exit_condition,
523 (
void **)&cpu_exit_condition);
528 cpu_exit_condition[0] = 0;
536 while (DOCA_GPUNETIO_VOLATILE(
force_quit) ==
false)
538 DOCA_GPUNETIO_VOLATILE(*cpu_exit_condition) = 1;
542 cudaStreamSynchronize(stream);
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
doca_error_t kernel_send_packets(cudaStream_t stream, struct txq_queue *txq, uint32_t *gpu_exit_condition)
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)
DOCA_LOG_REGISTER(SIMPLE_SEND :SAMPLE)
struct doca_flow_port * df_port
static doca_error_t start_doca_flow(struct doca_dev *dev)
static doca_error_t create_txq(struct txq_queue *txq, struct doca_gpu *gpu_dev, struct doca_dev *ddev, uint32_t pkt_size, uint32_t pkt_num)
doca_error_t gpunetio_simple_send(struct sample_simple_send_cfg *sample_cfg)
static void signal_handler(int signum)
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_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.
#define DOCA_DEVINFO_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
DOCA_STABLE doca_error_t doca_dev_close(struct doca_dev *dev)
Destroy allocated local device instance.
enum doca_error doca_error_t
DOCA API return codes.
DOCA_STABLE const char * doca_error_get_name(doca_error_t error)
Returns the string representation of an error code name.
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 doca_error_t doca_eth_txq_gpu_set_completion_on_gpu(struct doca_eth_txq *eth_txq)
By default, the Eth Txq completion can be checked on th CPU. With this method set the Eth Txq complet...
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_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_set_l3_chksum_offload(struct doca_eth_txq *eth_txq, uint8_t enable_l3_chksum)
Set offload for the calculation of IPv4 checksum (L3) on transmitted packets. If the users enables L3...
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_set_l4_chksum_offload(struct doca_eth_txq *eth_txq, uint8_t enable_l4_chksum)
Set offload for the calculation of TCP/UDP checksum (L4) on transmitted packets. If the users enables...
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_cfg_set_nr_counters(struct doca_flow_cfg *cfg, uint32_t nr_counters)
Set number of counters to configure.
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_GPU_MEM_TYPE_GPU_CPU
@ DOCA_ACCESS_FLAG_LOCAL_READ_WRITE
char nic_pcie_addr[MAX_PCI_ADDRESS_LEN]
char gpu_pcie_addr[MAX_PCI_ADDRESS_LEN]
struct doca_buf_arr * buf_arr
struct doca_gpu_eth_txq * eth_txq_gpu
struct doca_flow_port * port
struct doca_mmap * pkt_buff_mmap
struct doca_ctx * eth_txq_ctx
struct doca_gpu_buf_arr * buf_arr_gpu
struct doca_eth_txq * eth_txq_cpu
struct doca_gpu * gpu_dev