Skip to content

Commit

Permalink
util/mem_monitor, prov/verbs: Write free/realloc events from hooks to…
Browse files Browse the repository at this point in the history
… NQ event list

The current implementation works as follows:
Events from free/realloc hooks (if an user subscribes on this memory address)
are written to its own intermediate event list and then they are written to
a NQ's event list.

The commint improves current implementation by removing intermediate event list
of notifier. The notifier (verbs global notifier) inserts events directly
into the NQ's event list.

Signed-off-by: Dmitry Gladkov <dmitry.gladkov@intel.com>
  • Loading branch information
dmitrygx committed Sep 12, 2018
1 parent 6d310e6 commit a6e33da
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 69 deletions.
15 changes: 13 additions & 2 deletions include/ofi_mr.h
Expand Up @@ -105,7 +105,6 @@ struct ofi_mem_monitor {
size_t len, struct ofi_subscription *subscription);
void (*unsubscribe)(struct ofi_mem_monitor *notifier, void *addr,
size_t len, struct ofi_subscription *subscription);
struct ofi_subscription *(*get_event)(struct ofi_mem_monitor *notifier);
};

struct ofi_notification_queue {
Expand Down Expand Up @@ -133,7 +132,19 @@ int ofi_monitor_subscribe(struct ofi_notification_queue *nq,
struct ofi_subscription *subscription);
void ofi_monitor_unsubscribe(struct ofi_subscription *subscription);
struct ofi_subscription *ofi_monitor_get_event(struct ofi_notification_queue *nq);

static inline void
ofi_monitor_add_event_to_nq(struct ofi_subscription *subscription)
{
FI_DBG(&core_prov, FI_LOG_MR,
"Add event to NQ, context=%p, addr=%p, len=%"PRIu64" nq=%p\n",
subscription, subscription->addr,
subscription->len, subscription->nq);
fastlock_acquire(&subscription->nq->lock);
if (dlist_empty(&subscription->entry))
dlist_insert_tail(&subscription->entry,
&subscription->nq->list);
fastlock_release(&subscription->nq->lock);
}

/*
* MR map
Expand Down
27 changes: 0 additions & 27 deletions prov/util/src/util_mem_monitor.c
Expand Up @@ -112,37 +112,10 @@ void ofi_monitor_unsubscribe(struct ofi_subscription *subscription)
fastlock_release(&subscription->nq->lock);
}

static void util_monitor_read_events(struct ofi_mem_monitor *monitor)
{
struct ofi_subscription *subscription;

do {
subscription = monitor->get_event(monitor);
if (!subscription) {
FI_DBG(&core_prov, FI_LOG_MR,
"no more events to be read\n");
break;
}

FI_DBG(&core_prov, FI_LOG_MR,
"found event, context=%p, addr=%p, len=%"PRIu64" nq=%p\n",
subscription, subscription->addr,
subscription->len, subscription->nq);

fastlock_acquire(&subscription->nq->lock);
if (dlist_empty(&subscription->entry))
dlist_insert_tail(&subscription->entry,
&subscription->nq->list);
fastlock_release(&subscription->nq->lock);
} while (1);
}

struct ofi_subscription *ofi_monitor_get_event(struct ofi_notification_queue *nq)
{
struct ofi_subscription *subscription;

util_monitor_read_events(nq->monitor);

fastlock_acquire(&nq->lock);
if (!dlist_empty(&nq->list)) {
dlist_pop_front(&nq->list, struct ofi_subscription,
Expand Down
1 change: 0 additions & 1 deletion prov/verbs/src/fi_verbs.h
Expand Up @@ -430,7 +430,6 @@ struct fi_ibv_mem_ptr_entry {
struct fi_ibv_mem_notifier {
struct fi_ibv_mem_ptr_entry *mem_ptrs_hash;
struct util_buf_pool *mem_ptrs_ent_pool;
struct dlist_entry event_list;
ofi_mem_free_hook prev_free_hook;
ofi_mem_realloc_hook prev_realloc_hook;
int ref_cnt;
Expand Down
15 changes: 2 additions & 13 deletions prov/verbs/src/verbs_domain.c
Expand Up @@ -124,11 +124,7 @@ void fi_ibv_mem_notifier_free_hook(void *ptr, const void *caller)
if (!entry)
goto out;
VERBS_DBG(FI_LOG_MR, "Catch free hook for %p, entry - %p\n", ptr, entry);

if (!dlist_empty(&entry->entry))
dlist_remove_init(&entry->entry);
dlist_insert_tail(&entry->entry,
&fi_ibv_mem_notifier->event_list);
ofi_monitor_add_event_to_nq(entry->subscription);
out:
FI_IBV_MEMORY_HOOK_END(fi_ibv_mem_notifier)
}
Expand All @@ -150,11 +146,7 @@ void *fi_ibv_mem_notifier_realloc_hook(void *ptr, size_t size, const void *calle
if (!entry)
goto out;
VERBS_DBG(FI_LOG_MR, "Catch realloc hook for %p, entry - %p\n", ptr, entry);

if (!dlist_empty(&entry->entry))
dlist_remove_init(&entry->entry);
dlist_insert_tail(&entry->entry,
&fi_ibv_mem_notifier->event_list);
ofi_monitor_add_event_to_nq(entry->subscription);
out:
FI_IBV_MEMORY_HOOK_END(fi_ibv_mem_notifier)
return ret_ptr;
Expand Down Expand Up @@ -209,8 +201,6 @@ static struct fi_ibv_mem_notifier *fi_ibv_mem_notifier_init(void)
goto err2;
pthread_mutexattr_destroy(&mutex_attr);

dlist_init(&fi_ibv_mem_notifier->event_list);

pthread_mutex_lock(&fi_ibv_mem_notifier->lock);
fi_ibv_mem_notifier->prev_free_hook = ofi_get_mem_free_hook();
fi_ibv_mem_notifier->prev_realloc_hook = ofi_get_mem_realloc_hook();
Expand Down Expand Up @@ -469,7 +459,6 @@ fi_ibv_domain(struct fid_fabric *fabric, struct fi_info *info,
_domain->notifier = fi_ibv_mem_notifier_init();
_domain->monitor.subscribe = fi_ibv_monitor_subscribe;
_domain->monitor.unsubscribe = fi_ibv_monitor_unsubscribe;
_domain->monitor.get_event = fi_ibv_monitor_get_event;
ofi_monitor_init(&_domain->monitor);

_domain->cache.max_cached_cnt = fi_ibv_gl_data.mr_max_cached_cnt;
Expand Down
26 changes: 0 additions & 26 deletions prov/verbs/src/verbs_mr.c
Expand Up @@ -432,32 +432,6 @@ void fi_ibv_monitor_unsubscribe(struct ofi_mem_monitor *notifier, void *addr,
pthread_mutex_unlock(&domain->notifier->lock);
}

struct ofi_subscription *
fi_ibv_monitor_get_event(struct ofi_mem_monitor *notifier)
{
struct fi_ibv_domain *domain =
container_of(notifier, struct fi_ibv_domain, monitor);
struct fi_ibv_mem_ptr_entry *entry;

pthread_mutex_lock(&domain->notifier->lock);
if (!dlist_empty(&domain->notifier->event_list)) {
dlist_pop_front(&domain->notifier->event_list,
struct fi_ibv_mem_ptr_entry,
entry, entry);
VERBS_DBG(FI_LOG_MR,
"Retrieve %p (entry %p) from event list\n",
entry->addr, entry);
/* needed to protect against double insertions */
dlist_init(&entry->entry);

pthread_mutex_unlock(&domain->notifier->lock);
return entry->subscription;
} else {
pthread_mutex_unlock(&domain->notifier->lock);
return NULL;
}
}

int fi_ibv_mr_cache_entry_reg(struct ofi_mr_cache *cache,
struct ofi_mr_entry *entry)
{
Expand Down

0 comments on commit a6e33da

Please sign in to comment.