26 #include <arpa/inet.h>
31 #include <sys/epoll.h>
32 #include <sys/signalfd.h>
51 #define MAX_MSG_SIZE 65535
52 #define SLEEP_IN_NANOS (10 * 1000)
53 #define MAX_FASTPATH_TASKS 1024
54 #define CACHE_ALIGN 64
56 #define NS_PER_SEC 1E9
57 #define NS_PER_MSEC 1E6
58 #ifdef CLOCK_MONOTONIC_RAW
59 #define CLOCK_TYPE_ID CLOCK_MONOTONIC_RAW
61 #define CLOCK_TYPE_ID CLOCK_MONOTONIC
70 struct doca_buf_inventory *
inv;
84 int nb_send_msg = *(
int *)param;
86 if (nb_send_msg < 1) {
87 DOCA_LOG_ERR(
"Amount of messages to be sent by the client is less than 1");
91 app_cfg->send_msg_nb = nb_send_msg;
108 if (send_msg_size < 1 || send_msg_size >
MAX_MSG_SIZE) {
127 const char *dev_pci_addr = (
char *)param;
130 DOCA_LOG_ERR(
"Entered device PCI address exceeding the maximum size of %d",
150 const char *rep_pci_addr = (
char *)param;
154 DOCA_LOG_ERR(
"Entered device representor PCI address exceeding the maximum size of %d",
166 struct doca_comch_connection *comch_connection,
173 cfg->consumer_id = id;
188 uint8_t *recv_buffer,
199 DOCA_LOG_ERR(
"Invalid message length detected: %u", msg_len);
201 cfg->expected_msgs = -1;
209 cfg->expected_msgs = 0;
241 const char *pci_addr,
244 uint32_t permissions)
246 size_t data_length = buf_len * num_bufs;
262 DOCA_LOG_ERR(
"Failed allocate buffer memory of length: %lu", data_length);
337 (
void)task_user_data;
381 (void)task_user_data;
387 DOCA_LOG_ERR(
"Received a producer send task completion error");
403 struct doca_comch_producer *producer;
405 struct doca_pe *producer_pe;
406 struct doca_buf *doca_buf;
409 uint32_t total_tasks;
414 struct timespec ts = {
419 total_msgs =
ctx->cfg->send_msg_nb;
420 msg_len =
ctx->cfg->send_msg_size;
439 goto destroy_local_mem;
442 if (max_cap < msg_len) {
443 DOCA_LOG_ERR(
"Producer does not support message size. Requested: %u, max: %u", msg_len, max_cap);
445 goto destroy_local_mem;
451 goto destroy_local_mem;
463 goto destroy_producer;
476 ctx_user_data.
ptr = &producer_ctx;
504 while (
ctx->consumer_id == 0) {
514 for (i = 0; i < total_tasks; i++) {
554 for (i = 0; i < total_tasks; i++)
564 goto destroy_producer;
589 ctx->send_result->end_time = producer_ctx.
end_time;
609 struct doca_buf *buf;
612 (
void)task_user_data;
657 (void)task_user_data;
663 DOCA_LOG_ERR(
"Received a consumer post recv completion error");
678 struct doca_comch_consumer *consumer;
682 struct doca_pe *consumer_pe;
685 uint32_t total_tasks;
690 struct timespec ts = {
695 total_msgs =
ctx->expected_msgs;
696 msg_len =
ctx->expected_msg_size;
705 ctx->cfg->cc_dev_pci_addr,
718 goto destroy_local_mem;
721 if (max_cap < msg_len) {
722 DOCA_LOG_ERR(
"Consumer does not support message size. Requested: %u, max: %u", msg_len, max_cap);
724 goto destroy_local_mem;
730 goto destroy_local_mem;
742 goto destroy_consumer;
755 ctx_user_data.
ptr = &consumer_ctx;
779 for (i = 0; i < total_tasks; i++) {
787 goto free_task_and_bufs;
793 goto free_task_and_bufs;
799 goto free_task_and_bufs;
818 for (i = 0; i < total_tasks; i++) {
819 if (doca_buf[i] !=
NULL)
828 goto destroy_consumer;
855 ctx->recv_result->end_time = consumer_ctx.
end_time;
884 if (pthread_detach(*
ctx->sendto_t) != 0) {
894 if (pthread_detach(*
ctx->recvfrom_t) != 0) {
903 while (running_threads > 0) {
926 diff = (end->tv_sec - start->tv_sec) *
NS_PER_SEC;
927 diff += end->tv_nsec;
928 diff -= start->tv_nsec;
937 pthread_t sendto_thread, recvfrom_thread;
955 while (
ctx->expected_msgs == 0) {
963 if (
ctx->expected_msgs < 0) {
968 ctx->sendto_t = &sendto_thread;
969 ctx->recvfrom_t = &recvfrom_thread;
1003 while (
ctx->expected_msgs != 0) {
1012 DOCA_LOG_INFO(
"Producer sent %u messages in approximately %0.4f milliseconds",
1013 ctx->send_result->processed_msgs,
1015 DOCA_LOG_INFO(
"Consumer received %u messages in approximately %0.4f milliseconds",
1016 ctx->recv_result->processed_msgs,
1026 struct doca_argp_param *message_size_param, *messages_number_param, *pci_addr_param, *rep_pci_addr_param;
1091 "DOCA Comch device representor PCI address (needed only on DPU)");
void * comch_utils_get_user_data(struct doca_comch_connection *connection)
doca_error_t comch_utils_progress_connection(struct doca_comch_connection *connection)
struct doca_comch_connection * comch_util_get_connection(struct comch_cfg *comch_cfg)
doca_error_t comch_utils_send(struct doca_comch_connection *connection, const void *msg, uint32_t len)
static doca_error_t open_doca_device_with_pci(const char *pcie_value, struct doca_dev **retval)
static struct app_gpu_cfg app_cfg
DOCA_EXPERIMENTAL void doca_argp_param_set_description(struct doca_argp_param *param, const char *description)
Set the description of the program param, used during program usage.
DOCA_EXPERIMENTAL void doca_argp_param_set_long_name(struct doca_argp_param *param, const char *name)
Set the long name of the program param.
DOCA_EXPERIMENTAL void doca_argp_param_set_callback(struct doca_argp_param *param, doca_argp_param_cb_t callback)
Set the callback function of the program param.
DOCA_EXPERIMENTAL void doca_argp_param_set_mandatory(struct doca_argp_param *param)
Mark the program param as mandatory.
DOCA_EXPERIMENTAL doca_error_t doca_argp_param_create(struct doca_argp_param **param)
Create new program param.
DOCA_EXPERIMENTAL void doca_argp_param_set_type(struct doca_argp_param *param, enum doca_argp_type type)
Set the type of the param arguments.
DOCA_EXPERIMENTAL doca_error_t doca_argp_register_version_callback(doca_argp_param_cb_t callback)
Register an alternative version callback.
DOCA_EXPERIMENTAL void doca_argp_param_set_short_name(struct doca_argp_param *param, const char *name)
Set the short name of the program param.
DOCA_EXPERIMENTAL doca_error_t doca_argp_register_param(struct doca_argp_param *input_param)
Register a program flag.
DOCA_STABLE doca_error_t doca_buf_inventory_destroy(struct doca_buf_inventory *inventory)
Destroy buffer inventory structure.
static doca_error_t doca_buf_inventory_buf_get_by_addr(struct doca_buf_inventory *inventory, struct doca_mmap *mmap, void *addr, size_t len, struct doca_buf **buf)
Allocate single element from buffer inventory and point it to the buffer defined by addr & len argume...
static doca_error_t doca_buf_inventory_buf_get_by_data(struct doca_buf_inventory *inventory, struct doca_mmap *mmap, void *data, size_t data_len, struct doca_buf **buf)
Allocate single element from buffer inventory and point it to the buffer defined by data & data_len a...
DOCA_STABLE doca_error_t doca_buf_inventory_start(struct doca_buf_inventory *inventory)
Start element retrieval from inventory.
DOCA_STABLE doca_error_t doca_buf_inventory_create(size_t num_elements, struct doca_buf_inventory **inventory)
Allocates buffer inventory with default/unset attributes.
DOCA_STABLE doca_error_t doca_buf_dec_refcount(struct doca_buf *buf, uint16_t *refcount)
Decrease the object reference count by 1, if 0 reached, return the element back to the inventory.
DOCA_STABLE doca_error_t doca_buf_reset_data_len(struct doca_buf *buf)
DOCA_STABLE struct doca_buf * doca_comch_consumer_task_post_recv_get_buf(const struct doca_comch_consumer_task_post_recv *task)
DOCA_STABLE doca_error_t doca_comch_consumer_create(struct doca_comch_connection *comch_connection, struct doca_mmap *buf_mmap, struct doca_comch_consumer **consumer)
DOCA_STABLE doca_error_t doca_comch_consumer_destroy(struct doca_comch_consumer *consumer)
DOCA_STABLE doca_error_t doca_comch_consumer_task_post_recv_set_conf(struct doca_comch_consumer *consumer, doca_comch_consumer_task_post_recv_completion_cb_t task_completion_cb, doca_comch_consumer_task_post_recv_completion_cb_t task_error_cb, uint32_t num_post_recv_tasks)
DOCA_STABLE doca_error_t doca_comch_consumer_task_post_recv_alloc_init(struct doca_comch_consumer *consumer, struct doca_buf *buf, struct doca_comch_consumer_task_post_recv **task)
Allocate and initialize a doca_consumer post receive task.
DOCA_STABLE struct doca_ctx * doca_comch_consumer_as_ctx(struct doca_comch_consumer *consumer)
DOCA_STABLE struct doca_task * doca_comch_consumer_task_post_recv_as_task(struct doca_comch_consumer_task_post_recv *task)
DOCA_STABLE doca_error_t doca_comch_consumer_cap_get_max_buf_size(const struct doca_devinfo *devinfo, uint32_t *max_buf_size)
DOCA_STABLE doca_error_t doca_comch_producer_create(struct doca_comch_connection *comch_connection, struct doca_comch_producer **producer)
DOCA_STABLE struct doca_task * doca_comch_producer_task_send_as_task(struct doca_comch_producer_task_send *task)
DOCA_STABLE doca_error_t doca_comch_producer_task_send_set_conf(struct doca_comch_producer *producer, doca_comch_producer_task_send_completion_cb_t task_completion_cb, doca_comch_producer_task_send_completion_cb_t task_error_cb, uint32_t num_send_tasks)
DOCA_STABLE doca_error_t doca_comch_producer_destroy(struct doca_comch_producer *producer)
DOCA_STABLE doca_error_t doca_comch_producer_cap_get_max_buf_size(const struct doca_devinfo *devinfo, uint32_t *max_buf_size)
DOCA_STABLE struct doca_ctx * doca_comch_producer_as_ctx(struct doca_comch_producer *producer)
DOCA_STABLE doca_error_t doca_comch_producer_task_send_alloc_init(struct doca_comch_producer *producer, const struct doca_buf *buf, uint8_t *imm_data, uint32_t imm_data_len, uint32_t consumer_id, struct doca_comch_producer_task_send **task)
DOCA_STABLE doca_error_t doca_ctx_start(struct doca_ctx *ctx)
Finalizes all configurations, and starts the DOCA CTX.
DOCA_STABLE doca_error_t doca_ctx_get_state(const struct doca_ctx *ctx, enum doca_ctx_states *state)
Get context state.
DOCA_STABLE doca_error_t doca_ctx_set_user_data(struct doca_ctx *ctx, union doca_data user_data)
set user data to context
DOCA_STABLE doca_error_t doca_ctx_stop(struct doca_ctx *ctx)
Stops the context allowing reconfiguration.
doca_ctx_states
This enum defines the states of a context.
#define DOCA_DEVINFO_REP_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
#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.
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
#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_pe_destroy(struct doca_pe *pe)
Destroy doca progress engine.
DOCA_STABLE doca_error_t doca_pe_connect_ctx(struct doca_pe *pe, struct doca_ctx *ctx)
This method connects a context to a progress engine.
DOCA_STABLE doca_error_t doca_task_submit(struct doca_task *task)
Submit a task to a progress engine.
DOCA_STABLE uint8_t doca_pe_progress(struct doca_pe *pe)
Run the progress engine.
DOCA_STABLE doca_error_t doca_pe_create(struct doca_pe **pe)
Creates DOCA progress engine.
DOCA_STABLE void doca_task_free(struct doca_task *task)
Free a task back to where it was allocated from.
@ DOCA_ACCESS_FLAG_PCI_READ_WRITE
@ DOCA_ACCESS_FLAG_PCI_READ_ONLY
const struct ip_frag_config * cfg
void * aligned_alloc(size_t alignment, size_t size)
static doca_error_t messages_number_callback(void *param, void *config)
void comch_recv_event_cb(struct doca_comch_event_msg_recv *event, uint8_t *recv_buffer, uint32_t msg_len, struct doca_comch_connection *comch_connection)
static void send_task_fail_callback(struct doca_comch_producer_task_send *task, union doca_data task_user_data, union doca_data ctx_user_data)
static doca_error_t start_threads(struct cc_ctx *ctx, struct comch_cfg *comch_cfg)
void expired_consumer_callback(struct doca_comch_event_consumer *event, struct doca_comch_connection *comch_connection, uint32_t id)
doca_error_t sc_start(struct comch_cfg *comch_cfg, struct sc_config *cfg, struct cc_ctx *ctx)
DOCA_LOG_REGISTER(SECURE_CHANNEL::Core)
static doca_error_t rep_pci_addr_callback(void *param, void *config)
static void * run_consumer(void *context)
static double calculate_timediff_ms(struct timespec *end, struct timespec *start)
static void * run_producer(void *context)
#define MAX_FASTPATH_TASKS
static void recv_task_fail_callback(struct doca_comch_consumer_task_post_recv *task, union doca_data task_user_data, union doca_data ctx_user_data)
static void send_task_completed_callback(struct doca_comch_producer_task_send *task, union doca_data task_user_data, union doca_data ctx_user_data)
static void destroy_local_memory(struct local_memory_bufs *local_mem)
static void recv_task_completed_callback(struct doca_comch_consumer_task_post_recv *task, union doca_data task_user_data, union doca_data ctx_user_data)
void new_consumer_callback(struct doca_comch_event_consumer *event, struct doca_comch_connection *comch_connection, uint32_t id)
doca_error_t register_secure_channel_params(void)
static doca_error_t dev_pci_addr_callback(void *param, void *config)
static doca_error_t message_size_callback(void *param, void *config)
static doca_error_t prepare_local_memory(struct local_memory_bufs *local_mem, const char *pci_addr, size_t buf_len, uint32_t num_bufs, uint32_t permissions)
#define atomic_fetch_sub(object, operand)
#define atomic_load(object)
struct doca_comch_connection * comch_connection
struct timespec start_time
enum transfer_state state
struct doca_buf_inventory * inv
Convenience type for representing opaque data.
struct upf_accel_ctx * ctx
size_t strlcpy(char *dst, const char *src, size_t size)
noreturn doca_error_t sdk_version_callback(void *param, void *doca_config)