bf81a2faa83d9ff68ee994139d7354919e815174
[dpdk.git] / lib / librte_eal / common / include / rte_memory.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4
5 #ifndef _RTE_MEMORY_H_
6 #define _RTE_MEMORY_H_
7
8 /**
9  * @file
10  *
11  * Memory-related RTE API.
12  */
13
14 #include <stdint.h>
15 #include <stddef.h>
16 #include <stdio.h>
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 #include <rte_common.h>
23 #include <rte_compat.h>
24 #include <rte_config.h>
25 #include <rte_fbarray.h>
26
27 __extension__
28 enum rte_page_sizes {
29         RTE_PGSIZE_4K    = 1ULL << 12,
30         RTE_PGSIZE_64K   = 1ULL << 16,
31         RTE_PGSIZE_256K  = 1ULL << 18,
32         RTE_PGSIZE_2M    = 1ULL << 21,
33         RTE_PGSIZE_16M   = 1ULL << 24,
34         RTE_PGSIZE_256M  = 1ULL << 28,
35         RTE_PGSIZE_512M  = 1ULL << 29,
36         RTE_PGSIZE_1G    = 1ULL << 30,
37         RTE_PGSIZE_4G    = 1ULL << 32,
38         RTE_PGSIZE_16G   = 1ULL << 34,
39 };
40
41 #define SOCKET_ID_ANY -1                    /**< Any NUMA socket. */
42
43 /**
44  * Physical memory segment descriptor.
45  */
46 #define RTE_MEMSEG_FLAG_DO_NOT_FREE (1 << 0)
47 /**< Prevent this segment from being freed back to the OS. */
48 struct rte_memseg {
49         RTE_STD_C11
50         union {
51                 phys_addr_t phys_addr;  /**< deprecated - Start physical address. */
52                 rte_iova_t iova;        /**< Start IO address. */
53         };
54         RTE_STD_C11
55         union {
56                 void *addr;         /**< Start virtual address. */
57                 uint64_t addr_64;   /**< Makes sure addr is always 64 bits */
58         };
59         size_t len;               /**< Length of the segment. */
60         uint64_t hugepage_sz;       /**< The pagesize of underlying memory */
61         int32_t socket_id;          /**< NUMA socket ID. */
62         uint32_t nchannel;          /**< Number of channels. */
63         uint32_t nrank;             /**< Number of ranks. */
64         uint32_t flags;             /**< Memseg-specific flags */
65 } __rte_packed;
66
67 /**
68  * memseg list is a special case as we need to store a bunch of other data
69  * together with the array itself.
70  */
71 struct rte_memseg_list {
72         RTE_STD_C11
73         union {
74                 void *base_va;
75                 /**< Base virtual address for this memseg list. */
76                 uint64_t addr_64;
77                 /**< Makes sure addr is always 64-bits */
78         };
79         uint64_t page_sz; /**< Page size for all memsegs in this list. */
80         int socket_id; /**< Socket ID for all memsegs in this list. */
81         volatile uint32_t version; /**< version number for multiprocess sync. */
82         size_t len; /**< Length of memory area covered by this memseg list. */
83         unsigned int external; /**< 1 if this list points to external memory */
84         unsigned int heap; /**< 1 if this list points to a heap */
85         struct rte_fbarray memseg_arr;
86 };
87
88 /**
89  * Lock page in physical memory and prevent from swapping.
90  *
91  * @param virt
92  *   The virtual address.
93  * @return
94  *   0 on success, negative on error.
95  */
96 int rte_mem_lock_page(const void *virt);
97
98 /**
99  * Get physical address of any mapped virtual address in the current process.
100  * It is found by browsing the /proc/self/pagemap special file.
101  * The page must be locked.
102  *
103  * @param virt
104  *   The virtual address.
105  * @return
106  *   The physical address or RTE_BAD_IOVA on error.
107  */
108 phys_addr_t rte_mem_virt2phy(const void *virt);
109
110 /**
111  * Get IO virtual address of any mapped virtual address in the current process.
112  *
113  * @param virt
114  *   The virtual address.
115  * @return
116  *   The IO address or RTE_BAD_IOVA on error.
117  */
118 rte_iova_t rte_mem_virt2iova(const void *virt);
119
120 /**
121  * Get virtual memory address corresponding to iova address.
122  *
123  * @note This function read-locks the memory hotplug subsystem, and thus cannot
124  *       be used within memory-related callback functions.
125  *
126  * @param iova
127  *   The iova address.
128  * @return
129  *   Virtual address corresponding to iova address (or NULL if address does not
130  *   exist within DPDK memory map).
131  */
132 __rte_experimental
133 void *
134 rte_mem_iova2virt(rte_iova_t iova);
135
136 /**
137  * Get memseg to which a particular virtual address belongs.
138  *
139  * @param virt
140  *   The virtual address.
141  * @param msl
142  *   The memseg list in which to look up based on ``virt`` address
143  *   (can be NULL).
144  * @return
145  *   Memseg pointer on success, or NULL on error.
146  */
147 __rte_experimental
148 struct rte_memseg *
149 rte_mem_virt2memseg(const void *virt, const struct rte_memseg_list *msl);
150
151 /**
152  * Get memseg list corresponding to virtual memory address.
153  *
154  * @param virt
155  *   The virtual address.
156  * @return
157  *   Memseg list to which this virtual address belongs to.
158  */
159 __rte_experimental
160 struct rte_memseg_list *
161 rte_mem_virt2memseg_list(const void *virt);
162
163 /**
164  * Memseg walk function prototype.
165  *
166  * Returning 0 will continue walk
167  * Returning 1 will stop the walk
168  * Returning -1 will stop the walk and report error
169  */
170 typedef int (*rte_memseg_walk_t)(const struct rte_memseg_list *msl,
171                 const struct rte_memseg *ms, void *arg);
172
173 /**
174  * Memseg contig walk function prototype. This will trigger a callback on every
175  * VA-contiguous area starting at memseg ``ms``, so total valid VA space at each
176  * callback call will be [``ms->addr``, ``ms->addr + len``).
177  *
178  * Returning 0 will continue walk
179  * Returning 1 will stop the walk
180  * Returning -1 will stop the walk and report error
181  */
182 typedef int (*rte_memseg_contig_walk_t)(const struct rte_memseg_list *msl,
183                 const struct rte_memseg *ms, size_t len, void *arg);
184
185 /**
186  * Memseg list walk function prototype. This will trigger a callback on every
187  * allocated memseg list.
188  *
189  * Returning 0 will continue walk
190  * Returning 1 will stop the walk
191  * Returning -1 will stop the walk and report error
192  */
193 typedef int (*rte_memseg_list_walk_t)(const struct rte_memseg_list *msl,
194                 void *arg);
195
196 /**
197  * Walk list of all memsegs.
198  *
199  * @note This function read-locks the memory hotplug subsystem, and thus cannot
200  *       be used within memory-related callback functions.
201  *
202  * @note This function will also walk through externally allocated segments. It
203  *       is up to the user to decide whether to skip through these segments.
204  *
205  * @param func
206  *   Iterator function
207  * @param arg
208  *   Argument passed to iterator
209  * @return
210  *   0 if walked over the entire list
211  *   1 if stopped by the user
212  *   -1 if user function reported error
213  */
214 __rte_experimental
215 int
216 rte_memseg_walk(rte_memseg_walk_t func, void *arg);
217
218 /**
219  * Walk each VA-contiguous area.
220  *
221  * @note This function read-locks the memory hotplug subsystem, and thus cannot
222  *       be used within memory-related callback functions.
223  *
224  * @note This function will also walk through externally allocated segments. It
225  *       is up to the user to decide whether to skip through these segments.
226  *
227  * @param func
228  *   Iterator function
229  * @param arg
230  *   Argument passed to iterator
231  * @return
232  *   0 if walked over the entire list
233  *   1 if stopped by the user
234  *   -1 if user function reported error
235  */
236 __rte_experimental
237 int
238 rte_memseg_contig_walk(rte_memseg_contig_walk_t func, void *arg);
239
240 /**
241  * Walk each allocated memseg list.
242  *
243  * @note This function read-locks the memory hotplug subsystem, and thus cannot
244  *       be used within memory-related callback functions.
245  *
246  * @note This function will also walk through externally allocated segments. It
247  *       is up to the user to decide whether to skip through these segments.
248  *
249  * @param func
250  *   Iterator function
251  * @param arg
252  *   Argument passed to iterator
253  * @return
254  *   0 if walked over the entire list
255  *   1 if stopped by the user
256  *   -1 if user function reported error
257  */
258 __rte_experimental
259 int
260 rte_memseg_list_walk(rte_memseg_list_walk_t func, void *arg);
261
262 /**
263  * Walk list of all memsegs without performing any locking.
264  *
265  * @note This function does not perform any locking, and is only safe to call
266  *       from within memory-related callback functions.
267  *
268  * @param func
269  *   Iterator function
270  * @param arg
271  *   Argument passed to iterator
272  * @return
273  *   0 if walked over the entire list
274  *   1 if stopped by the user
275  *   -1 if user function reported error
276  */
277 __rte_experimental
278 int
279 rte_memseg_walk_thread_unsafe(rte_memseg_walk_t func, void *arg);
280
281 /**
282  * Walk each VA-contiguous area without performing any locking.
283  *
284  * @note This function does not perform any locking, and is only safe to call
285  *       from within memory-related callback functions.
286  *
287  * @param func
288  *   Iterator function
289  * @param arg
290  *   Argument passed to iterator
291  * @return
292  *   0 if walked over the entire list
293  *   1 if stopped by the user
294  *   -1 if user function reported error
295  */
296 __rte_experimental
297 int
298 rte_memseg_contig_walk_thread_unsafe(rte_memseg_contig_walk_t func, void *arg);
299
300 /**
301  * Walk each allocated memseg list without performing any locking.
302  *
303  * @note This function does not perform any locking, and is only safe to call
304  *       from within memory-related callback functions.
305  *
306  * @param func
307  *   Iterator function
308  * @param arg
309  *   Argument passed to iterator
310  * @return
311  *   0 if walked over the entire list
312  *   1 if stopped by the user
313  *   -1 if user function reported error
314  */
315 __rte_experimental
316 int
317 rte_memseg_list_walk_thread_unsafe(rte_memseg_list_walk_t func, void *arg);
318
319 /**
320  * Return file descriptor associated with a particular memseg (if available).
321  *
322  * @note This function read-locks the memory hotplug subsystem, and thus cannot
323  *       be used within memory-related callback functions.
324  *
325  * @note This returns an internal file descriptor. Performing any operations on
326  *       this file descriptor is inherently dangerous, so it should be treated
327  *       as read-only for all intents and purposes.
328  *
329  * @param ms
330  *   A pointer to memseg for which to get file descriptor.
331  *
332  * @return
333  *   Valid file descriptor in case of success.
334  *   -1 in case of error, with ``rte_errno`` set to the following values:
335  *     - EINVAL  - ``ms`` pointer was NULL or did not point to a valid memseg
336  *     - ENODEV  - ``ms`` fd is not available
337  *     - ENOENT  - ``ms`` is an unused segment
338  *     - ENOTSUP - segment fd's are not supported
339  */
340 __rte_experimental
341 int
342 rte_memseg_get_fd(const struct rte_memseg *ms);
343
344 /**
345  * Return file descriptor associated with a particular memseg (if available).
346  *
347  * @note This function does not perform any locking, and is only safe to call
348  *       from within memory-related callback functions.
349  *
350  * @note This returns an internal file descriptor. Performing any operations on
351  *       this file descriptor is inherently dangerous, so it should be treated
352  *       as read-only for all intents and purposes.
353  *
354  * @param ms
355  *   A pointer to memseg for which to get file descriptor.
356  *
357  * @return
358  *   Valid file descriptor in case of success.
359  *   -1 in case of error, with ``rte_errno`` set to the following values:
360  *     - EINVAL  - ``ms`` pointer was NULL or did not point to a valid memseg
361  *     - ENODEV  - ``ms`` fd is not available
362  *     - ENOENT  - ``ms`` is an unused segment
363  *     - ENOTSUP - segment fd's are not supported
364  */
365 __rte_experimental
366 int
367 rte_memseg_get_fd_thread_unsafe(const struct rte_memseg *ms);
368
369 /**
370  * Get offset into segment file descriptor associated with a particular memseg
371  * (if available).
372  *
373  * @note This function read-locks the memory hotplug subsystem, and thus cannot
374  *       be used within memory-related callback functions.
375  *
376  * @param ms
377  *   A pointer to memseg for which to get file descriptor.
378  * @param offset
379  *   A pointer to offset value where the result will be stored.
380  *
381  * @return
382  *   Valid file descriptor in case of success.
383  *   -1 in case of error, with ``rte_errno`` set to the following values:
384  *     - EINVAL  - ``ms`` pointer was NULL or did not point to a valid memseg
385  *     - EINVAL  - ``offset`` pointer was NULL
386  *     - ENODEV  - ``ms`` fd is not available
387  *     - ENOENT  - ``ms`` is an unused segment
388  *     - ENOTSUP - segment fd's are not supported
389  */
390 __rte_experimental
391 int
392 rte_memseg_get_fd_offset(const struct rte_memseg *ms, size_t *offset);
393
394 /**
395  * Get offset into segment file descriptor associated with a particular memseg
396  * (if available).
397  *
398  * @note This function does not perform any locking, and is only safe to call
399  *       from within memory-related callback functions.
400  *
401  * @param ms
402  *   A pointer to memseg for which to get file descriptor.
403  * @param offset
404  *   A pointer to offset value where the result will be stored.
405  *
406  * @return
407  *   Valid file descriptor in case of success.
408  *   -1 in case of error, with ``rte_errno`` set to the following values:
409  *     - EINVAL  - ``ms`` pointer was NULL or did not point to a valid memseg
410  *     - EINVAL  - ``offset`` pointer was NULL
411  *     - ENODEV  - ``ms`` fd is not available
412  *     - ENOENT  - ``ms`` is an unused segment
413  *     - ENOTSUP - segment fd's are not supported
414  */
415 __rte_experimental
416 int
417 rte_memseg_get_fd_offset_thread_unsafe(const struct rte_memseg *ms,
418                 size_t *offset);
419
420 /**
421  * @warning
422  * @b EXPERIMENTAL: this API may change without prior notice
423  *
424  * Register external memory chunk with DPDK.
425  *
426  * @note Using this API is mutually exclusive with ``rte_malloc`` family of
427  *   API's.
428  *
429  * @note This API will not perform any DMA mapping. It is expected that user
430  *   will do that themselves.
431  *
432  * @note Before accessing this memory in other processes, it needs to be
433  *   attached in each of those processes by calling ``rte_extmem_attach`` in
434  *   each other process.
435  *
436  * @param va_addr
437  *   Start of virtual area to register. Must be aligned by ``page_sz``.
438  * @param len
439  *   Length of virtual area to register. Must be aligned by ``page_sz``.
440  * @param iova_addrs
441  *   Array of page IOVA addresses corresponding to each page in this memory
442  *   area. Can be NULL, in which case page IOVA addresses will be set to
443  *   RTE_BAD_IOVA.
444  * @param n_pages
445  *   Number of elements in the iova_addrs array. Ignored if  ``iova_addrs``
446  *   is NULL.
447  * @param page_sz
448  *   Page size of the underlying memory
449  *
450  * @return
451  *   - 0 on success
452  *   - -1 in case of error, with rte_errno set to one of the following:
453  *     EINVAL - one of the parameters was invalid
454  *     EEXIST - memory chunk is already registered
455  *     ENOSPC - no more space in internal config to store a new memory chunk
456  */
457 __rte_experimental
458 int
459 rte_extmem_register(void *va_addr, size_t len, rte_iova_t iova_addrs[],
460                 unsigned int n_pages, size_t page_sz);
461
462 /**
463  * @warning
464  * @b EXPERIMENTAL: this API may change without prior notice
465  *
466  * Unregister external memory chunk with DPDK.
467  *
468  * @note Using this API is mutually exclusive with ``rte_malloc`` family of
469  *   API's.
470  *
471  * @note This API will not perform any DMA unmapping. It is expected that user
472  *   will do that themselves.
473  *
474  * @note Before calling this function, all other processes must call
475  *   ``rte_extmem_detach`` to detach from the memory area.
476  *
477  * @param va_addr
478  *   Start of virtual area to unregister
479  * @param len
480  *   Length of virtual area to unregister
481  *
482  * @return
483  *   - 0 on success
484  *   - -1 in case of error, with rte_errno set to one of the following:
485  *     EINVAL - one of the parameters was invalid
486  *     ENOENT - memory chunk was not found
487  */
488 __rte_experimental
489 int
490 rte_extmem_unregister(void *va_addr, size_t len);
491
492 /**
493  * @warning
494  * @b EXPERIMENTAL: this API may change without prior notice
495  *
496  * Attach to external memory chunk registered in another process.
497  *
498  * @note Using this API is mutually exclusive with ``rte_malloc`` family of
499  *   API's.
500  *
501  * @note This API will not perform any DMA mapping. It is expected that user
502  *   will do that themselves.
503  *
504  * @param va_addr
505  *   Start of virtual area to register
506  * @param len
507  *   Length of virtual area to register
508  *
509  * @return
510  *   - 0 on success
511  *   - -1 in case of error, with rte_errno set to one of the following:
512  *     EINVAL - one of the parameters was invalid
513  *     ENOENT - memory chunk was not found
514  */
515 __rte_experimental
516 int
517 rte_extmem_attach(void *va_addr, size_t len);
518
519 /**
520  * @warning
521  * @b EXPERIMENTAL: this API may change without prior notice
522  *
523  * Detach from external memory chunk registered in another process.
524  *
525  * @note Using this API is mutually exclusive with ``rte_malloc`` family of
526  *   API's.
527  *
528  * @note This API will not perform any DMA unmapping. It is expected that user
529  *   will do that themselves.
530  *
531  * @param va_addr
532  *   Start of virtual area to unregister
533  * @param len
534  *   Length of virtual area to unregister
535  *
536  * @return
537  *   - 0 on success
538  *   - -1 in case of error, with rte_errno set to one of the following:
539  *     EINVAL - one of the parameters was invalid
540  *     ENOENT - memory chunk was not found
541  */
542 __rte_experimental
543 int
544 rte_extmem_detach(void *va_addr, size_t len);
545
546 /**
547  * Dump the physical memory layout to a file.
548  *
549  * @note This function read-locks the memory hotplug subsystem, and thus cannot
550  *       be used within memory-related callback functions.
551  *
552  * @param f
553  *   A pointer to a file for output
554  */
555 void rte_dump_physmem_layout(FILE *f);
556
557 /**
558  * Get the total amount of available physical memory.
559  *
560  * @note This function read-locks the memory hotplug subsystem, and thus cannot
561  *       be used within memory-related callback functions.
562  *
563  * @return
564  *    The total amount of available physical memory in bytes.
565  */
566 uint64_t rte_eal_get_physmem_size(void);
567
568 /**
569  * Get the number of memory channels.
570  *
571  * @return
572  *   The number of memory channels on the system. The value is 0 if unknown
573  *   or not the same on all devices.
574  */
575 unsigned rte_memory_get_nchannel(void);
576
577 /**
578  * Get the number of memory ranks.
579  *
580  * @return
581  *   The number of memory ranks on the system. The value is 0 if unknown or
582  *   not the same on all devices.
583  */
584 unsigned rte_memory_get_nrank(void);
585
586 /**
587  * @warning
588  * @b EXPERIMENTAL: this API may change without prior notice
589  *
590  * Check if all currently allocated memory segments are compliant with
591  * supplied DMA address width.
592  *
593  *  @param maskbits
594  *    Address width to check against.
595  */
596 __rte_experimental
597 int rte_mem_check_dma_mask(uint8_t maskbits);
598
599 /**
600  * @warning
601  * @b EXPERIMENTAL: this API may change without prior notice
602  *
603  * Check if all currently allocated memory segments are compliant with
604  * supplied DMA address width. This function will use
605  * rte_memseg_walk_thread_unsafe instead of rte_memseg_walk implying
606  * memory_hotplug_lock will not be acquired avoiding deadlock during
607  * memory initialization.
608  *
609  * This function is just for EAL core memory internal use. Drivers should
610  * use the previous rte_mem_check_dma_mask.
611  *
612  *  @param maskbits
613  *    Address width to check against.
614  */
615 __rte_experimental
616 int rte_mem_check_dma_mask_thread_unsafe(uint8_t maskbits);
617
618 /**
619  * @warning
620  * @b EXPERIMENTAL: this API may change without prior notice
621  *
622  *  Set dma mask to use once memory initialization is done. Previous functions
623  *  rte_mem_check_dma_mask and rte_mem_check_dma_mask_thread_unsafe can not be
624  *  used safely until memory has been initialized.
625  */
626 __rte_experimental
627 void rte_mem_set_dma_mask(uint8_t maskbits);
628
629 /**
630  * Drivers based on uio will not load unless physical
631  * addresses are obtainable. It is only possible to get
632  * physical addresses when running as a privileged user.
633  *
634  * @return
635  *   1 if the system is able to obtain physical addresses.
636  *   0 if using DMA addresses through an IOMMU.
637  */
638 int rte_eal_using_phys_addrs(void);
639
640
641 /**
642  * Enum indicating which kind of memory event has happened. Used by callbacks to
643  * distinguish between memory allocations and deallocations.
644  */
645 enum rte_mem_event {
646         RTE_MEM_EVENT_ALLOC = 0, /**< Allocation event. */
647         RTE_MEM_EVENT_FREE,      /**< Deallocation event. */
648 };
649 #define RTE_MEM_EVENT_CALLBACK_NAME_LEN 64
650 /**< maximum length of callback name */
651
652 /**
653  * Function typedef used to register callbacks for memory events.
654  */
655 typedef void (*rte_mem_event_callback_t)(enum rte_mem_event event_type,
656                 const void *addr, size_t len, void *arg);
657
658 /**
659  * Function used to register callbacks for memory events.
660  *
661  * @note callbacks will happen while memory hotplug subsystem is write-locked,
662  *       therefore some functions (e.g. `rte_memseg_walk()`) will cause a
663  *       deadlock when called from within such callbacks.
664  *
665  * @note mem event callbacks not being supported is an expected error condition,
666  *       so user code needs to handle this situation. In these cases, return
667  *       value will be -1, and rte_errno will be set to ENOTSUP.
668  *
669  * @param name
670  *   Name associated with specified callback to be added to the list.
671  *
672  * @param clb
673  *   Callback function pointer.
674  *
675  * @param arg
676  *   Argument to pass to the callback.
677  *
678  * @return
679  *   0 on successful callback register
680  *   -1 on unsuccessful callback register, with rte_errno value indicating
681  *   reason for failure.
682  */
683 __rte_experimental
684 int
685 rte_mem_event_callback_register(const char *name, rte_mem_event_callback_t clb,
686                 void *arg);
687
688 /**
689  * Function used to unregister callbacks for memory events.
690  *
691  * @param name
692  *   Name associated with specified callback to be removed from the list.
693  *
694  * @param arg
695  *   Argument to look for among callbacks with specified callback name.
696  *
697  * @return
698  *   0 on successful callback unregister
699  *   -1 on unsuccessful callback unregister, with rte_errno value indicating
700  *   reason for failure.
701  */
702 __rte_experimental
703 int
704 rte_mem_event_callback_unregister(const char *name, void *arg);
705
706
707 #define RTE_MEM_ALLOC_VALIDATOR_NAME_LEN 64
708 /**< maximum length of alloc validator name */
709 /**
710  * Function typedef used to register memory allocation validation callbacks.
711  *
712  * Returning 0 will allow allocation attempt to continue. Returning -1 will
713  * prevent allocation from succeeding.
714  */
715 typedef int (*rte_mem_alloc_validator_t)(int socket_id,
716                 size_t cur_limit, size_t new_len);
717
718 /**
719  * @brief Register validator callback for memory allocations.
720  *
721  * Callbacks registered by this function will be called right before memory
722  * allocator is about to trigger allocation of more pages from the system if
723  * said allocation will bring total memory usage above specified limit on
724  * specified socket. User will be able to cancel pending allocation if callback
725  * returns -1.
726  *
727  * @note callbacks will happen while memory hotplug subsystem is write-locked,
728  *       therefore some functions (e.g. `rte_memseg_walk()`) will cause a
729  *       deadlock when called from within such callbacks.
730  *
731  * @note validator callbacks not being supported is an expected error condition,
732  *       so user code needs to handle this situation. In these cases, return
733  *       value will be -1, and rte_errno will be set to ENOTSUP.
734  *
735  * @param name
736  *   Name associated with specified callback to be added to the list.
737  *
738  * @param clb
739  *   Callback function pointer.
740  *
741  * @param socket_id
742  *   Socket ID on which to watch for allocations.
743  *
744  * @param limit
745  *   Limit above which to trigger callbacks.
746  *
747  * @return
748  *   0 on successful callback register
749  *   -1 on unsuccessful callback register, with rte_errno value indicating
750  *   reason for failure.
751  */
752 __rte_experimental
753 int
754 rte_mem_alloc_validator_register(const char *name,
755                 rte_mem_alloc_validator_t clb, int socket_id, size_t limit);
756
757 /**
758  * @brief Unregister validator callback for memory allocations.
759  *
760  * @param name
761  *   Name associated with specified callback to be removed from the list.
762  *
763  * @param socket_id
764  *   Socket ID on which to watch for allocations.
765  *
766  * @return
767  *   0 on successful callback unregister
768  *   -1 on unsuccessful callback unregister, with rte_errno value indicating
769  *   reason for failure.
770  */
771 __rte_experimental
772 int
773 rte_mem_alloc_validator_unregister(const char *name, int socket_id);
774
775 #ifdef __cplusplus
776 }
777 #endif
778
779 #endif /* _RTE_MEMORY_H_ */