NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
rdma_sync_event_requester_sample.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #include <doca_error.h>
27 #include <doca_log.h>
28 #include <doca_buf_inventory.h>
29 #include <doca_buf.h>
30 #include <doca_ctx.h>
31 
32 #include "rdma_common.h"
33 
34 DOCA_LOG_REGISTER(RDMA_SYNC_EVENT_REQUESTER::SAMPLE);
35 
36 #define EXAMPLE_SET_VALUE (0xD0CA) /* Example value to use for setting sync event */
37 
38 /*
39  * DOCA device with rdma remote sync event tasks capability filter callback
40  *
41  * @devinfo [in]: doca_devinfo
42  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
43  */
44 static doca_error_t sync_event_tasks_supported(const struct doca_devinfo *devinfo)
45 {
47 
49  if (status != DOCA_SUCCESS)
50  return status;
51 
53 }
54 
55 /*
56  * Write the connection details for the responder to read,
57  * and read the connection details and the remote sync event details of the responder
58  * In DC transport mode it is only needed to read the remote connection details
59  *
60  * @cfg [in]: Configuration parameters
61  * @resources [in/out]: DOCA RDMA resources
62  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
63  */
65 {
67 
68  if (cfg->transport_type == DOCA_RDMA_TRANSPORT_TYPE_RC) {
69  /* Write the RDMA connection details */
70  result = write_file(cfg->local_connection_desc_path,
73  if (result != DOCA_SUCCESS) {
74  DOCA_LOG_ERR("Failed to write the RDMA connection details: %s", doca_error_get_descr(result));
75  return result;
76  }
77 
78  DOCA_LOG_INFO("You can now copy %s to the responder", cfg->local_connection_desc_path);
79  }
80 
82  "Please copy %s and %s from the responder and then press enter after pressing enter in the responder side",
83  cfg->remote_connection_desc_path,
84  cfg->remote_resource_desc_path);
85 
86  /* Wait for enter */
88 
89  /* Read the remote RDMA connection details */
90  result = read_file(cfg->remote_connection_desc_path,
93  if (result != DOCA_SUCCESS) {
94  DOCA_LOG_ERR("Failed to read the remote RDMA connection details: %s", doca_error_get_descr(result));
95  return result;
96  }
97 
98  /* Read the remote sync event connection details */
99  result = read_file(cfg->remote_resource_desc_path,
100  (char **)&resources->sync_event_descriptor,
102  if (result != DOCA_SUCCESS) {
103  DOCA_LOG_ERR("Failed to read the sync event export blob: %s", doca_error_get_descr(result));
104  return result;
105  }
106 
107  return result;
108 }
109 
110 /*
111  * Free RDMA remote net sync event notify set task resources and task
112  *
113  * @se_set_task [in]: the task that should be freed along with it's resources
114  * @ctx_user_data [in]: doca_data from the context (used to free relevant resources)
115  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
116  */
118  struct doca_rdma_task_remote_net_sync_event_notify_set *se_set_task,
119  union doca_data ctx_user_data)
120 {
121  doca_error_t result, return_value = DOCA_SUCCESS;
122  struct doca_task *task = doca_rdma_task_remote_net_sync_event_notify_set_as_task(se_set_task);
123  struct rdma_resources *resources = (struct rdma_resources *)ctx_user_data.ptr;
124  char *successful_task_message = (char *)(doca_task_get_user_data(task).ptr);
125 
126  /* Release task resources and stop the ctx */
128  if (result != DOCA_SUCCESS) {
129  DOCA_LOG_ERR("Failed to decrease buffer's refcount: %s", doca_error_get_descr(result));
130  DOCA_ERROR_PROPAGATE(return_value, result);
131  }
132 
133  free(successful_task_message);
134 
135  doca_task_free(task);
136 
137  return return_value;
138 }
139 
140 /*
141  * RDMA remote net sync event notify set task completed callback
142  *
143  * @se_set_task [in]: Completed task
144  * @task_user_data [in]: doca_data from the task
145  * @ctx_user_data [in]: doca_data from the context
146  */
148  struct doca_rdma_task_remote_net_sync_event_notify_set *se_set_task,
149  union doca_data task_user_data,
150  union doca_data ctx_user_data)
151 {
153  struct rdma_resources *resources = (struct rdma_resources *)ctx_user_data.ptr;
154  char *successful_task_message = (char *)task_user_data.ptr;
155 
156  DOCA_LOG_INFO("RDMA remote net sync event notify set was done successfully");
157  DOCA_LOG_INFO("%s", successful_task_message);
158 
159  /* Decrement number of remaining tasks */
161 
162  if (resources->num_remaining_tasks == 0) {
163  /* Release task resources and stop the ctx */
165  if (result != DOCA_SUCCESS) {
166  DOCA_LOG_ERR("Failed to release task resources: %s", doca_error_get_descr(result));
168  }
169 
170  if (resources->cfg->use_rdma_cm == true)
172 
173  /* Stop in callback context is expected to return DOCA_ERROR_IN_PROGRESS */
176  DOCA_LOG_ERR("Failed to stop DOCA RDMA context: %s", doca_error_get_descr(result));
178  }
179  }
180 }
181 
182 /*
183  * RDMA remote net sync event notify set task error callback
184  *
185  * @se_set_task [in]: failed task
186  * @task_user_data [in]: doca_data from the task
187  * @ctx_user_data [in]: doca_data from the context
188  */
190  struct doca_rdma_task_remote_net_sync_event_notify_set *se_set_task,
191  union doca_data task_user_data,
192  union doca_data ctx_user_data)
193 {
195  struct rdma_resources *resources = (struct rdma_resources *)ctx_user_data.ptr;
196  struct doca_task *task = doca_rdma_task_remote_net_sync_event_notify_set_as_task(se_set_task);
197 
198  (void)task_user_data.ptr;
199 
200  /* Decrement number of remaining tasks */
202 
203  /* Update that an error was encountered */
206  DOCA_LOG_ERR("RDMA remote net sync event notify set task failed: %s", doca_error_get_descr(result));
207 
208  /* Release task resources only if there are no remaining tasks */
209  if (resources->num_remaining_tasks == 0) {
211  if (result != DOCA_SUCCESS)
212  DOCA_LOG_ERR("Failed to release task resources: %s", doca_error_get_descr(result));
213  }
214 
215  if (resources->cfg->use_rdma_cm == true)
217 
218  /* Stop in callback context is expected to return DOCA_ERROR_IN_PROGRESS */
221  DOCA_LOG_ERR("Failed to stop DOCA RDMA context: %s", doca_error_get_descr(result));
222 }
223 
224 /*
225  * RDMA remote net sync event get task completed callback
226  *
227  * @se_get_task [in]: Completed task
228  * @task_user_data [in]: doca_data from the task
229  * @ctx_user_data [in]: doca_data from the context
230  */
232  struct doca_rdma_task_remote_net_sync_event_get *se_get_task,
233  union doca_data task_user_data,
234  union doca_data ctx_user_data)
235 {
237  struct rdma_resources *resources = (struct rdma_resources *)ctx_user_data.ptr;
238  struct doca_rdma_task_remote_net_sync_event_notify_set *se_set_task =
239  (struct doca_rdma_task_remote_net_sync_event_notify_set *)task_user_data.ptr;
240  union doca_data set_task_user_data;
241  struct doca_task *task, *set_task;
242  struct doca_buf *get_buf;
243  char *successful_task_message;
244  void *buf_data;
245 
246  DOCA_LOG_INFO("RDMA remote net sync event get was done successfully");
247 
249 
251 
252  result = doca_buf_get_data(get_buf, &buf_data);
253  if (result != DOCA_SUCCESS) {
254  DOCA_LOG_ERR("Failed to get buffer data for get task: %s", doca_error_get_descr(result));
255  goto propagate_error;
256  } else
257  DOCA_LOG_INFO("Received sync event value 0x%X", *(int *)buf_data);
258 
259  if (*(int *)buf_data <= EXAMPLE_SET_VALUE) {
260  /* Resubmit the task, as long as the data is different from expected */
261  result = doca_buf_reset_data_len(get_buf);
262  if (result != DOCA_SUCCESS) {
263  DOCA_LOG_ERR("Failed to reset buffer's data length: %s", doca_error_get_descr(result));
264  goto propagate_error;
265  }
266 
267  result = doca_task_submit(task);
268  if (result != DOCA_SUCCESS) {
269  DOCA_LOG_ERR("Failed to submit RDMA sync event get task: %s", doca_error_get_descr(result));
270  goto propagate_error;
271  }
272 
273  return;
274  }
275 
276  /* Submit RDMA sync event set task to notify that the sync event is complete */
278  set_task_user_data = doca_task_get_user_data(set_task);
279 
280  result = doca_buf_get_data(resources->src_buf, &buf_data);
281  if (result != DOCA_SUCCESS) {
282  DOCA_LOG_ERR("Failed to get buffer data for set task: %s", doca_error_get_descr(result));
283  goto propagate_error;
284  }
285  *(uint64_t *)buf_data = UINT64_MAX;
286 
287  DOCA_LOG_INFO("Notifying remote sync event for completion");
288  successful_task_message = (char *)set_task_user_data.ptr;
289  memset(successful_task_message, 0, MAX_ARG_SIZE);
290  strncpy(successful_task_message,
291  "Remote sync event has been notified for completion successfully",
292  MAX_ARG_SIZE - 1);
293 
294  result = doca_task_submit(set_task);
295  if (result != DOCA_SUCCESS) {
296  DOCA_LOG_ERR("Failed to submit RDMA remote sync event set task: %s", doca_error_get_descr(result));
297  goto propagate_error;
298  }
300 
301 propagate_error:
303 
305 
306  /* Release task resources and stop the ctx */
307  result = doca_buf_dec_refcount(get_buf, NULL);
308  if (result != DOCA_SUCCESS) {
309  DOCA_LOG_ERR("Failed to decrease buffer's refcount: %s", doca_error_get_descr(result));
311  }
312 
313  doca_task_free(task);
314 
315  /* if num_remaining_tasks is 0, the set task wasn't successfully submitted */
316  if (resources->num_remaining_tasks == 0) {
318  if (result != DOCA_SUCCESS)
319  DOCA_LOG_ERR("Failed to free remote_net_sync_event_notify_set task's resources: %s",
321 
322  if (resources->cfg->use_rdma_cm == true)
324 
325  /* Stop in callback context is expected to return DOCA_ERROR_IN_PROGRESS */
328  DOCA_LOG_ERR("Failed to stop DOCA RDMA context: %s", doca_error_get_descr(result));
329  }
330 }
331 
332 /*
333  * RDMA remote net sync event get task error callback
334  *
335  * @se_get_task [in]: failed task
336  * @task_user_data [in]: doca_data from the task
337  * @ctx_user_data [in]: doca_data from the context
338  */
339 static void rdma_remote_net_sync_event_get_error_callback(struct doca_rdma_task_remote_net_sync_event_get *se_get_task,
340  union doca_data task_user_data,
341  union doca_data ctx_user_data)
342 {
344  struct rdma_resources *resources = (struct rdma_resources *)ctx_user_data.ptr;
345  struct doca_rdma_task_remote_net_sync_event_notify_set *se_set_task =
346  (struct doca_rdma_task_remote_net_sync_event_notify_set *)task_user_data.ptr;
347  struct doca_task *task = doca_rdma_task_remote_net_sync_event_get_as_task(se_get_task);
348 
349  /* Decrement number of remaining tasks */
351 
352  /* Update that an error was encountered */
355  DOCA_LOG_ERR("RDMA remote net sync event get task failed: %s", doca_error_get_descr(result));
356 
357  /* Release task resources and stop the ctx */
359  if (result != DOCA_SUCCESS)
360  DOCA_LOG_ERR("Failed to free remote_net_sync_event_notify_set task's resources: %s",
362 
364  if (result != DOCA_SUCCESS)
365  DOCA_LOG_ERR("Failed to decrease buffer's refcount: %s", doca_error_get_descr(result));
366 
367  doca_task_free(task);
368 
369  if (resources->cfg->use_rdma_cm == true)
371 
372  /* Stop in callback context is expected to return DOCA_ERROR_IN_PROGRESS */
375  DOCA_LOG_ERR("Failed to stop DOCA RDMA context: %s", doca_error_get_descr(result));
376 }
377 
378 /*
379  * Prepare and submit RDMA sync event tasks
380  *
381  * @resources [in]: RDMA resources
382  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
383  */
385 {
386  doca_error_t result, tmp_result;
387  struct doca_task *task = NULL;
388  struct doca_rdma_task_remote_net_sync_event_notify_set *se_set_task;
389  struct doca_rdma_task_remote_net_sync_event_get *se_get_task;
390  union doca_data task_user_data = {0};
391  void *set_buf_data;
392  void *get_buf_data;
393  char *successful_task_message;
394 
395  if (resources->cfg->use_rdma_cm == true) {
396  /* Create remote net sync event */
400  &(resources->remote_se));
401  if (result != DOCA_SUCCESS) {
402  DOCA_LOG_ERR("Failed to create remote sync event from export: %s",
404  return result;
405  }
406  }
407 
408  successful_task_message = calloc(1, MAX_ARG_SIZE);
409  if (successful_task_message == NULL) {
410  DOCA_LOG_ERR("Failed to allocate memory for string");
411  return DOCA_ERROR_NO_MEMORY;
412  }
413 
414  /* Retrieve buffers from DOCA buffer inventory */
416  resources->mmap,
418  sizeof(uint64_t),
419  &resources->src_buf);
420  if (result != DOCA_SUCCESS) {
421  DOCA_LOG_ERR("Failed to allocate DOCA buffer to DOCA buffer inventory: %s",
423  goto free_successful_task_message;
424  }
425 
426  result = doca_buf_get_data(resources->src_buf, &set_buf_data);
427  if (result != DOCA_SUCCESS) {
428  DOCA_LOG_ERR("Failed to get buffer data for set task: %s", doca_error_get_descr(result));
429  goto destroy_set_buf;
430  }
431  *(uint64_t *)set_buf_data = EXAMPLE_SET_VALUE;
432 
433  /* Include a message for successful sync_event_notify_set tasks, to be used in the callbacks */
434  task_user_data.ptr = (void *)successful_task_message;
435 
436  /* Allocate and construct RDMA sync event set task */
441  task_user_data,
442  &se_set_task);
443  if (result != DOCA_SUCCESS) {
444  DOCA_LOG_ERR("Failed to allocate RDMA sync event set task: %s", doca_error_get_descr(result));
445  goto destroy_set_buf;
446  }
447 
448  task_user_data.ptr = (void *)se_set_task;
449 
450  /* Submit RDMA sync event set task */
452 
453  DOCA_LOG_INFO("Signaling remote sync event");
454  strncpy(successful_task_message,
455  "Remote sync event has been signaled successfully, now waiting for remote sync event to be signaled",
456  MAX_ARG_SIZE - 1);
457  result = doca_task_submit(task);
458  if (result != DOCA_SUCCESS) {
459  DOCA_LOG_ERR("Failed to submit RDMA remote sync event set task: %s", doca_error_get_descr(result));
460  goto free_set_task;
461  }
463 
465  resources->mmap,
467  sizeof(uint64_t),
468  &resources->dst_buf);
469  if (result != DOCA_SUCCESS) {
470  DOCA_LOG_ERR("Failed to allocate DOCA buffer to DOCA buffer inventory: %s",
472  /* Set task was submitted, resources will be freed in error completion callback */
473  return result;
474  }
475 
476  result = doca_buf_get_data(resources->dst_buf, &get_buf_data);
477  if (result != DOCA_SUCCESS) {
478  DOCA_LOG_ERR("Failed to get buffer data for get task: %s", doca_error_get_descr(result));
479  goto destroy_get_buf;
480  }
481 
482  /* Allocate and construct RDMA sync event get task */
487  task_user_data,
488  &se_get_task);
489  if (result != DOCA_SUCCESS) {
490  DOCA_LOG_ERR("Failed to allocate RDMA sync event get task: %s", doca_error_get_descr(result));
491  goto destroy_get_buf;
492  }
493 
494  /* Submit RDMA sync event get task */
496 
497  result = doca_task_submit(task);
498  if (result != DOCA_SUCCESS) {
499  DOCA_LOG_ERR("Failed to submit RDMA remote sync event get task: %s", doca_error_get_descr(result));
500  doca_task_free(task);
501  goto destroy_get_buf;
502  }
504 
505  return DOCA_SUCCESS;
506 
507 destroy_get_buf:
509  if (tmp_result != DOCA_SUCCESS)
510  DOCA_LOG_ERR("Failed to decrease buffer's refcount: %s", doca_error_get_descr(tmp_result));
511 
512  /* After set task is submitted, resources will be freed in error completion callback */
513  return result;
514 
515 free_set_task:
517 
518 destroy_set_buf:
520  if (tmp_result != DOCA_SUCCESS)
521  DOCA_LOG_ERR("Failed to decrease buffer's refcount: %s", doca_error_get_descr(tmp_result));
522 
523 free_successful_task_message:
524  free(successful_task_message);
525 
526  return result;
527 }
528 
529 /*
530  * Export/connect RDMA and connection and sync event details, connect to the remote RDMA and create remote sync event
531  *
532  * @resources [in]: RDMA resources
533  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
534  */
536 {
538 
539  if (resources->cfg->use_rdma_cm == true)
540  return rdma_cm_connect(resources);
541 
542  /* Export DOCA RDMA */
546  &(resources->connections[0]));
547  if (result != DOCA_SUCCESS) {
548  DOCA_LOG_ERR("Failed to export DOCA RDMA: %s", doca_error_get_descr(result));
549  return result;
550  }
551 
552  /* Write and read connection details from the responder */
554  if (result != DOCA_SUCCESS) {
555  DOCA_LOG_ERR("Failed to write and read connection details from the responder: %s",
557  return result;
558  }
559 
560  /* Connect RDMA */
564  resources->connections[0]);
565  if (result != DOCA_SUCCESS) {
566  DOCA_LOG_ERR("Failed to connect the requester's DOCA RDMA to the responder's DOCA RDMA: %s",
568  return result;
569  }
570 
571  /* Create remote net sync event */
575  &(resources->remote_se));
576  if (result != DOCA_SUCCESS) {
577  DOCA_LOG_ERR("Failed to create remote sync event from export: %s", doca_error_get_descr(result));
578  return result;
579  }
580 
581  return DOCA_SUCCESS;
582 }
583 
584 /*
585  * destroy remote sync event if exists
586  *
587  * @resources [in]: RDMA resources
588  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
589  */
591 {
593 
594  /* Destroy remote sync event if exists */
595  if (resources->remote_se != NULL) {
597  if (result != DOCA_SUCCESS) {
598  DOCA_LOG_ERR("Failed to destroy DOCA remote sync event: %s", doca_error_get_descr(result));
599  return result;
600  }
601 
603  }
604 
605  return DOCA_SUCCESS;
606 }
607 
608 /*
609  * RDMA sync event requestor state change callback
610  * This function represents the state machine for this RDMA program
611  *
612  * @user_data [in]: doca_data from the context
613  * @ctx [in]: DOCA context
614  * @prev_state [in]: Previous DOCA context state
615  * @next_state [in]: Next DOCA context state
616  */
618  struct doca_ctx *ctx,
619  enum doca_ctx_states prev_state,
620  enum doca_ctx_states next_state)
621 {
622  struct rdma_resources *resources = (struct rdma_resources *)user_data.ptr;
624  (void)prev_state;
625  (void)ctx;
626 
627  switch (next_state) {
629  DOCA_LOG_INFO("RDMA context entered starting state");
630  break;
632  DOCA_LOG_INFO("RDMA context is running");
633 
635  if (result != DOCA_SUCCESS) {
636  DOCA_LOG_ERR("rdma_sync_event_requestor_export_and_connect() failed: %s",
638  break;
639  } else
640  DOCA_LOG_INFO("RDMA context finished initialization");
641 
642  if (resources->cfg->use_rdma_cm == true)
643  break;
644 
646  if (result != DOCA_SUCCESS)
647  DOCA_LOG_ERR("rdma_sync_event_requestor_prepare_and_submit_tasks() failed: %s",
649  break;
658  DOCA_LOG_INFO("RDMA context entered into stopping state. Any inflight tasks will be flushed");
659  break;
660  case DOCA_CTX_STATE_IDLE:
661  DOCA_LOG_INFO("RDMA context has been stopped");
662 
664  if (result != DOCA_SUCCESS) {
665  DOCA_LOG_ERR("Failed to destroy remote sync event: %s", doca_error_get_descr(result));
667  }
668 
669  /* We can stop the progressing the PE */
670  resources->run_pe_progress = false;
671  break;
672  default:
673  break;
674  }
675 
676  /* If something failed - update that an error was encountered and stop the ctx */
677  if (result != DOCA_SUCCESS) {
679  (void)doca_ctx_stop(ctx);
680  }
681 }
682 
683 /*
684  * Requester side of the RDMA sync event
685  *
686  * @cfg [in]: Configuration parameters
687  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
688  */
690 {
691  struct rdma_resources resources = {0};
692  union doca_data ctx_user_data = {0};
693  const uint32_t mmap_permissions = DOCA_ACCESS_FLAG_LOCAL_READ_WRITE;
694  const uint32_t rdma_permissions = DOCA_ACCESS_FLAG_LOCAL_READ_WRITE;
695  struct timespec ts = {
696  .tv_sec = 0,
697  .tv_nsec = SLEEP_IN_NANOS,
698  };
699  doca_error_t result, tmp_result;
700 
701  /* Allocating resources */
702  result =
703  allocate_rdma_resources(cfg, mmap_permissions, rdma_permissions, sync_event_tasks_supported, &resources);
704  if (result != DOCA_SUCCESS) {
705  DOCA_LOG_ERR("Failed to allocate RDMA Resources: %s", doca_error_get_descr(result));
706  return result;
707  }
708 
710  resources.rdma,
714  if (result != DOCA_SUCCESS) {
715  DOCA_LOG_ERR("Unable to set configurations for RDMA sync event set task: %s",
717  goto destroy_resources;
718  }
719 
724  if (result != DOCA_SUCCESS) {
725  DOCA_LOG_ERR("Unable to set configurations for RDMA sync event get task: %s",
727  goto destroy_resources;
728  }
729 
731  if (result != DOCA_SUCCESS) {
732  DOCA_LOG_ERR("Unable to set state change callback for RDMA context: %s", doca_error_get_descr(result));
733  goto destroy_resources;
734  }
735 
736  /* Create DOCA buffer inventory */
738  if (result != DOCA_SUCCESS) {
739  DOCA_LOG_ERR("Failed to create DOCA buffer inventory: %s", doca_error_get_descr(result));
740  goto destroy_resources;
741  }
742 
743  /* Start DOCA buffer inventory */
745  if (result != DOCA_SUCCESS) {
746  DOCA_LOG_ERR("Failed to start DOCA buffer inventory: %s", doca_error_get_descr(result));
747  goto destroy_buf_inventory;
748  }
749 
750  /* Include the program's resources in user data of context to be used in callbacks */
751  ctx_user_data.ptr = &(resources);
753  if (result != DOCA_SUCCESS) {
754  DOCA_LOG_ERR("Failed to set context user data: %s", doca_error_get_descr(result));
755  goto stop_buf_inventory;
756  }
757 
758  if (cfg->use_rdma_cm == true) {
760  resources.is_requester = true;
764  /* need_send_mmap_info */ false,
765  /* need_recv_mmap_info */ true);
766  if (result != DOCA_SUCCESS) {
767  DOCA_LOG_ERR("Failed to config RDMA CM callbacks and negotiation functions: %s",
769  goto destroy_buf_inventory;
770  }
771  }
772 
773  /* Start RDMA context */
775  if (result != DOCA_SUCCESS) {
776  DOCA_LOG_ERR("Failed to start RDMA context: %s", doca_error_get_descr(result));
777  goto stop_buf_inventory;
778  }
779 
780  /*
781  * Run the progress engine which will run the state machine defined in
782  * rdma_sync_event_requestor_state_change_callback().
783  * When signaled, stop running the progress engine and continue.
784  */
785  while (resources.run_pe_progress) {
786  if (doca_pe_progress(resources.pe) == 0)
787  nanosleep(&ts, &ts);
788  }
789 
790  /* Check the first_encountered_error we update in the callbacks */
792 
793 stop_buf_inventory:
795  if (tmp_result != DOCA_SUCCESS) {
796  DOCA_LOG_ERR("Failed to stop DOCA buffer inventory: %s", doca_error_get_descr(tmp_result));
797  DOCA_ERROR_PROPAGATE(result, tmp_result);
798  }
799 destroy_buf_inventory:
801  if (tmp_result != DOCA_SUCCESS) {
802  DOCA_LOG_ERR("Failed to destroy DOCA buffer inventory: %s", doca_error_get_descr(tmp_result));
803  DOCA_ERROR_PROPAGATE(result, tmp_result);
804  }
805 destroy_resources:
806  tmp_result = destroy_rdma_resources(&resources, cfg);
807  if (tmp_result != DOCA_SUCCESS) {
808  DOCA_LOG_ERR("Failed to destroy DOCA RDMA resources: %s", doca_error_get_descr(tmp_result));
809  DOCA_ERROR_PROPAGATE(result, tmp_result);
810  }
811  return result;
812 }
#define NULL
Definition: __stddef_null.h:26
int32_t result
#define SLEEP_IN_NANOS
Definition: comch_utils.c:40
#define MAX_ARG_SIZE
Definition: dma_copy_core.h:39
doca_error_t destroy_rdma_resources(struct rdma_resources *resources)
Definition: rdma_common.c:470
void wait_for_enter(void)
Definition: rdma_common.c:1771
doca_error_t write_file(const char *file_path, const char *string, size_t string_len)
Definition: rdma_common.c:1087
doca_error_t rdma_cm_connect(struct rdma_resources *resources)
Definition: rdma_common.c:1172
doca_error_t allocate_rdma_resources(struct rdma_config *cfg, const uint32_t mmap_permissions, const uint32_t rdma_permissions, task_check func, struct rdma_resources *resources)
Definition: rdma_common.c:758
doca_error_t config_rdma_cm_callback_and_negotiation_task(struct rdma_resources *resources, bool need_send_task, bool need_recv_task)
Definition: rdma_common.c:1720
doca_error_t rdma_cm_disconnect(struct rdma_resources *resources)
Definition: rdma_common.c:1244
#define INVENTORY_NUM_INITIAL_ELEMENTS
Definition: rdma_common.h:47
#define NUM_RDMA_TASKS
Definition: rdma_common.h:57
struct rdma_resources resources
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_inventory_stop(struct doca_buf_inventory *inventory)
Stop element retrieval from inventory.
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_get_data(const struct doca_buf *buf, void **data)
Get the buffer's data.
DOCA_STABLE doca_error_t doca_buf_reset_data_len(struct doca_buf *buf)
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_set_state_changed_cb(struct doca_ctx *ctx, doca_ctx_state_changed_callback_t cb)
Set state changed callback.
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.
Definition: doca_ctx.h:83
@ DOCA_CTX_STATE_STARTING
Definition: doca_ctx.h:93
@ DOCA_CTX_STATE_STOPPING
Definition: doca_ctx.h:106
@ DOCA_CTX_STATE_IDLE
Definition: doca_ctx.h:88
@ DOCA_CTX_STATE_RUNNING
Definition: doca_ctx.h:98
#define DOCA_ERROR_PROPAGATE(r, t)
Save the first encountered doca_error_t.
Definition: doca_error.h:83
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_UNKNOWN
Definition: doca_error.h:39
@ DOCA_SUCCESS
Definition: doca_error.h:38
@ DOCA_ERROR_NO_MEMORY
Definition: doca_error.h:45
@ DOCA_ERROR_IN_PROGRESS
Definition: doca_error.h:64
#define DOCA_LOG_ERR(format,...)
Generates an ERROR application log message.
Definition: doca_log.h:466
#define DOCA_LOG_INFO(format,...)
Generates an INFO application log message.
Definition: doca_log.h:486
DOCA_STABLE doca_error_t doca_task_get_status(const struct doca_task *task)
Get task status.
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 union doca_data doca_task_get_user_data(const struct doca_task *task)
Get user data from a task.
DOCA_STABLE void doca_task_free(struct doca_task *task)
Free a task back to where it was allocated from.
DOCA_EXPERIMENTAL struct doca_task * doca_rdma_task_remote_net_sync_event_notify_set_as_task(struct doca_rdma_task_remote_net_sync_event_notify_set *task)
This method converts a remote_net_sync_event_notify_set task to a doca_task.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_task_remote_net_sync_event_get_set_conf(struct doca_rdma *rdma, doca_rdma_task_remote_net_sync_event_get_completion_cb_t successful_task_completion_cb, doca_rdma_task_remote_net_sync_event_get_completion_cb_t error_task_completion_cb, uint32_t num_tasks)
This method sets the remote_net_sync_event_get tasks configuration.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_cap_task_remote_net_sync_event_notify_set_is_supported(const struct doca_devinfo *devinfo)
DOCA_EXPERIMENTAL struct doca_task * doca_rdma_task_remote_net_sync_event_get_as_task(struct doca_rdma_task_remote_net_sync_event_get *task)
This method converts a remote_net_sync_event_get task to a doca_task.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_task_remote_net_sync_event_notify_set_set_conf(struct doca_rdma *rdma, doca_rdma_task_remote_net_sync_event_notify_set_completion_cb_t successful_task_completion_cb, doca_rdma_task_remote_net_sync_event_notify_set_completion_cb_t error_task_completion_cb, uint32_t num_tasks)
This method sets the remote_net_sync_event_notify_set tasks configuration.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_cap_task_remote_net_sync_event_get_is_supported(const struct doca_devinfo *devinfo)
DOCA_EXPERIMENTAL doca_error_t doca_rdma_export(struct doca_rdma *rdma, const void **local_rdma_conn_details, size_t *local_rdma_conn_details_size, struct doca_rdma_connection **rdma_connection)
Export doca_rdma connection details object The doca_rdma_conn_details are used in doca_rdma_connect()...
DOCA_EXPERIMENTAL doca_error_t doca_rdma_task_remote_net_sync_event_notify_set_allocate_init(struct doca_rdma *rdma, struct doca_rdma_connection *rdma_connection, struct doca_sync_event_remote_net *event, const struct doca_buf *src_buf, union doca_data user_data, struct doca_rdma_task_remote_net_sync_event_notify_set **task)
This method allocates and initializes a remote_net_sync_event_notify_set task.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_connect(struct doca_rdma *rdma, const void *remote_rdma_conn_details, size_t remote_rdma_conn_details_size, struct doca_rdma_connection *rdma_connection)
Connect to remote doca_rdma peer. Can only be called when the ctx is in DOCA_CTX_STATE_STARTING state...
DOCA_EXPERIMENTAL struct doca_buf * doca_rdma_task_remote_net_sync_event_get_get_dst_buf(const struct doca_rdma_task_remote_net_sync_event_get *task)
This method gets the destination buffer of a remote_net_sync_event_get task.
DOCA_EXPERIMENTAL doca_error_t doca_rdma_task_remote_net_sync_event_get_allocate_init(struct doca_rdma *rdma, struct doca_rdma_connection *rdma_connection, const struct doca_sync_event_remote_net *event, struct doca_buf *dst_buf, union doca_data user_data, struct doca_rdma_task_remote_net_sync_event_get **task)
This method allocates and initializes a remote_net_sync_event_get task.
@ DOCA_RDMA_TRANSPORT_TYPE_RC
Definition: doca_rdma.h:46
DOCA_EXPERIMENTAL doca_error_t doca_sync_event_remote_net_create_from_export(struct doca_dev *dev, const uint8_t *data, size_t sz, struct doca_sync_event_remote_net **event)
Create a remote Sync Event handle from an export.
DOCA_EXPERIMENTAL doca_error_t doca_sync_event_remote_net_destroy(struct doca_sync_event_remote_net *event)
Destroy a Sync Event instance.
@ DOCA_ACCESS_FLAG_LOCAL_READ_WRITE
Definition: doca_types.h:83
const struct ip_frag_config * cfg
Definition: ip_frag_dp.c:0
static void rdma_sync_event_requestor_state_change_callback(const union doca_data user_data, struct doca_ctx *ctx, enum doca_ctx_states prev_state, enum doca_ctx_states next_state)
static doca_error_t rdma_sync_event_requestor_destroy_remote_sync_event(struct rdma_resources *resources)
static doca_error_t rdma_sync_event_requestor_export_and_connect(struct rdma_resources *resources)
static void rdma_remote_net_sync_event_get_completed_callback(struct doca_rdma_task_remote_net_sync_event_get *se_get_task, union doca_data task_user_data, union doca_data ctx_user_data)
static doca_error_t rdma_remote_net_sync_event_notify_set_free_task_resources(struct doca_rdma_task_remote_net_sync_event_notify_set *se_set_task, union doca_data ctx_user_data)
static void rdma_remote_net_sync_event_notify_set_error_callback(struct doca_rdma_task_remote_net_sync_event_notify_set *se_set_task, union doca_data task_user_data, union doca_data ctx_user_data)
static doca_error_t write_read_connection(struct rdma_config *cfg, struct rdma_resources *resources)
DOCA_LOG_REGISTER(RDMA_SYNC_EVENT_REQUESTER::SAMPLE)
static void rdma_remote_net_sync_event_notify_set_completed_callback(struct doca_rdma_task_remote_net_sync_event_notify_set *se_set_task, union doca_data task_user_data, union doca_data ctx_user_data)
static void rdma_remote_net_sync_event_get_error_callback(struct doca_rdma_task_remote_net_sync_event_get *se_get_task, union doca_data task_user_data, union doca_data ctx_user_data)
static doca_error_t rdma_sync_event_requestor_prepare_and_submit_tasks(struct rdma_resources *resources)
#define EXAMPLE_SET_VALUE
doca_error_t rdma_sync_event_requester(struct rdma_config *cfg)
static doca_error_t sync_event_tasks_supported(const struct doca_devinfo *devinfo)
bool use_rdma_cm
Definition: rdma_common.h:71
size_t remote_rdma_conn_descriptor_size
Definition: rdma_common.h:127
doca_error_t first_encountered_error
Definition: rdma_common.h:132
bool require_remote_mmap
Definition: rdma_common.h:152
struct doca_ctx * rdma_ctx
Definition: rdma_common.h:85
size_t sync_event_descriptor_size
Definition: rdma_common.h:131
size_t num_remaining_tasks
Definition: rdma_common.h:134
prepare_and_submit_task_fn task_fn
Definition: rdma_common.h:150
const void * rdma_conn_descriptor
Definition: rdma_common.h:124
bool recv_sync_event_desc
Definition: rdma_common.h:145
struct doca_sync_event_remote_net * remote_se
Definition: rdma_common.h:115
void * remote_rdma_conn_descriptor
Definition: rdma_common.h:126
struct doca_rdma_connection * connections[MAX_NUM_CONNECTIONS]
Definition: rdma_common.h:138
struct doca_buf * dst_buf
Definition: rdma_common.h:123
struct rdma_config * cfg
Definition: rdma_common.h:80
struct doca_rdma * rdma
Definition: rdma_common.h:83
struct doca_pe * pe
Definition: rdma_common.h:86
struct doca_mmap * mmap
Definition: rdma_common.h:112
bool run_pe_progress
Definition: rdma_common.h:133
struct doca_dev * doca_device
Definition: rdma_common.h:81
struct doca_buf * src_buf
Definition: rdma_common.h:122
struct doca_buf_inventory * buf_inventory
Definition: rdma_common.h:117
size_t rdma_conn_descriptor_size
Definition: rdma_common.h:125
void * sync_event_descriptor
Definition: rdma_common.h:130
char * mmap_memrange
Definition: rdma_common.h:116
Convenience type for representing opaque data.
Definition: doca_types.h:56
void * ptr
Definition: doca_types.h:57
struct upf_accel_ctx * ctx
doca_error_t read_file(char const *path, char **out_bytes, size_t *out_bytes_len)
Definition: utils.c:56