#ifndef UCS_REG_CACHE_H_
#define UCS_REG_CACHE_H_
#include <ucs/datastruct/pgtable.h>
#include <ucs/datastruct/list.h>
#include <ucs/datastruct/queue_types.h>
#include <ucs/datastruct/mpool.h>
#include <ucs/stats/stats_fwd.h>
#include <sys/mman.h>
#define UCS_RCACHE_PROT_FMT "%c%c"
#define UCS_RCACHE_PROT_ARG(_prot) \
((_prot) & PROT_READ) ? 'r' : '-', \
((_prot) & PROT_WRITE) ? 'w' : '-'
typedef struct ucs_rcache ucs_rcache_t;
typedef struct ucs_rcache_ops ucs_rcache_ops_t;
typedef struct ucs_rcache_params ucs_rcache_params_t;
typedef struct ucs_rcache_region ucs_rcache_region_t;
enum {
UCS_RCACHE_REGION_FLAG_REGISTERED = UCS_BIT(0),
UCS_RCACHE_REGION_FLAG_PGTABLE = UCS_BIT(1),
};
enum {
UCS_RCACHE_MEM_REG_HIDE_ERRORS = UCS_BIT(0)
};
enum {
UCS_RCACHE_FLAG_NO_PFN_CHECK = UCS_BIT(0),
UCS_RCACHE_FLAG_PURGE_ON_FORK = UCS_BIT(1),
};
enum {
UCS_RCACHE_LRU_FLAG_IN_LRU = UCS_BIT(0)
};
typedef void (*ucs_rcache_invalidate_comp_func_t)(void *arg);
struct ucs_rcache_ops {
ucs_status_t (*mem_reg)(void *context, ucs_rcache_t *rcache,
void *arg, ucs_rcache_region_t *region,
uint16_t flags);
void (*mem_dereg)(void *context, ucs_rcache_t *rcache,
ucs_rcache_region_t *region);
void (*dump_region)(void *context, ucs_rcache_t *rcache,
ucs_rcache_region_t *region,
char *buf, size_t max);
};
struct ucs_rcache_params {
size_t region_struct_size;
size_t alignment;
size_t max_alignment;
int ucm_events;
int ucm_event_priority;
const ucs_rcache_ops_t *ops;
void *context;
int flags;
unsigned long max_regions;
size_t max_size;
size_t max_unreleased;
};
struct ucs_rcache_region {
ucs_pgt_region_t super;
ucs_list_link_t lru_list;
ucs_list_link_t tmp_list;
ucs_list_link_t comp_list;
volatile uint32_t refcount;
ucs_status_t status;
uint8_t prot;
uint8_t flags;
uint8_t lru_flags;
union {
uint64_t priv;
unsigned long *pfn;
};
};
ucs_status_t ucs_rcache_create(const ucs_rcache_params_t *params, const char *name,
ucs_stats_node_t *stats_parent, ucs_rcache_t **rcache_p);
void ucs_rcache_destroy(ucs_rcache_t *rcache);
ucs_status_t ucs_rcache_get(ucs_rcache_t *rcache, void *address, size_t length,
int prot, void *arg, ucs_rcache_region_t **region_p);
void ucs_rcache_region_hold(ucs_rcache_t *rcache, ucs_rcache_region_t *region);
void ucs_rcache_region_put(ucs_rcache_t *rcache, ucs_rcache_region_t *region);
void ucs_rcache_region_invalidate(ucs_rcache_t *rcache,
ucs_rcache_region_t *region,
ucs_rcache_invalidate_comp_func_t cb,
void *arg);
#endif