-
Notifications
You must be signed in to change notification settings - Fork 395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define monitor unsubscribe_on_delete #10687
Open
iziemba
wants to merge
3
commits into
ofiwg:main
Choose a base branch
from
iziemba:mem_monitor_updates
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+723
−578
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,195 @@ | ||
/* | ||
* Copyright (c) 2017 Cray Inc. All rights reserved. | ||
* Copyright (c) 2017-2021 Intel Inc. All rights reserved. | ||
* Copyright (c) 2019-2021 Amazon.com, Inc. or its affiliates. | ||
* All rights reserved. | ||
* (C) Copyright 2020,2024 Hewlett Packard Enterprise Development LP | ||
* Copyright (C) 2024 Cornelis Networks. All rights reserved. | ||
* | ||
* This software is available to you under a choice of one of two | ||
* licenses. You may choose to be licensed under the terms of the GNU | ||
* General Public License (GPL) Version 2, available from the file | ||
* COPYING in the main directory of this source tree, or the | ||
* BSD license below: | ||
* | ||
* Redistribution and use in source and binary forms, with or | ||
* without modification, are permitted provided that the following | ||
* conditions are met: | ||
* | ||
* - Redistributions of source code must retain the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer. | ||
* | ||
* - Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials | ||
* provided with the distribution. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS | ||
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN | ||
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
|
||
#include <unistd.h> | ||
|
||
#include <ofi_mr.h> | ||
#include <ofi_enosys.h> | ||
#include <rdma/fi_ext.h> | ||
|
||
static void ofi_import_monitor_init(struct ofi_mem_monitor *monitor); | ||
static void ofi_import_monitor_cleanup(struct ofi_mem_monitor *monitor); | ||
static int ofi_import_monitor_start(struct ofi_mem_monitor *monitor); | ||
static void ofi_import_monitor_stop(struct ofi_mem_monitor *monitor); | ||
static int ofi_import_monitor_subscribe(struct ofi_mem_monitor *notifier, | ||
const void *addr, size_t len, | ||
union ofi_mr_hmem_info *hmem_info); | ||
static void ofi_import_monitor_unsubscribe(struct ofi_mem_monitor *notifier, | ||
const void *addr, size_t len, | ||
union ofi_mr_hmem_info *hmem_info); | ||
static bool ofi_import_monitor_valid(struct ofi_mem_monitor *notifier, | ||
const struct ofi_mr_info *info, | ||
struct ofi_mr_entry *entry); | ||
|
||
struct ofi_import_monitor { | ||
struct ofi_mem_monitor monitor; | ||
struct fid_mem_monitor *impfid; | ||
}; | ||
|
||
static struct ofi_import_monitor impmon = { | ||
.monitor.iface = FI_HMEM_SYSTEM, | ||
.monitor.init = ofi_import_monitor_init, | ||
.monitor.cleanup = ofi_import_monitor_cleanup, | ||
.monitor.start = ofi_import_monitor_start, | ||
.monitor.stop = ofi_import_monitor_stop, | ||
.monitor.subscribe = ofi_import_monitor_subscribe, | ||
.monitor.unsubscribe = ofi_import_monitor_unsubscribe, | ||
.monitor.valid = ofi_import_monitor_valid, | ||
.monitor.name = "import", | ||
}; | ||
|
||
struct ofi_mem_monitor *import_monitor = &impmon.monitor; | ||
|
||
static void ofi_import_monitor_init(struct ofi_mem_monitor *monitor) | ||
{ | ||
ofi_monitor_init(monitor); | ||
} | ||
|
||
static void ofi_import_monitor_cleanup(struct ofi_mem_monitor *monitor) | ||
{ | ||
assert(!impmon.impfid); | ||
ofi_monitor_cleanup(monitor); | ||
} | ||
|
||
static int ofi_import_monitor_start(struct ofi_mem_monitor *monitor) | ||
{ | ||
if (!impmon.impfid) | ||
return -FI_ENOSYS; | ||
|
||
return impmon.impfid->export_ops->start(impmon.impfid); | ||
} | ||
|
||
static void ofi_import_monitor_stop(struct ofi_mem_monitor *monitor) | ||
{ | ||
assert(impmon.impfid); | ||
impmon.impfid->export_ops->stop(impmon.impfid); | ||
} | ||
|
||
static int ofi_import_monitor_subscribe(struct ofi_mem_monitor *notifier, | ||
const void *addr, size_t len, | ||
union ofi_mr_hmem_info *hmem_info) | ||
{ | ||
assert(impmon.impfid); | ||
return impmon.impfid->export_ops->subscribe(impmon.impfid, addr, len); | ||
} | ||
|
||
static void ofi_import_monitor_unsubscribe(struct ofi_mem_monitor *notifier, | ||
const void *addr, size_t len, | ||
union ofi_mr_hmem_info *hmem_info) | ||
{ | ||
assert(impmon.impfid); | ||
impmon.impfid->export_ops->unsubscribe(impmon.impfid, addr, len); | ||
} | ||
|
||
static bool ofi_import_monitor_valid(struct ofi_mem_monitor *notifier, | ||
const struct ofi_mr_info *info, | ||
struct ofi_mr_entry *entry) | ||
{ | ||
assert(impmon.impfid); | ||
return impmon.impfid->export_ops->valid(impmon.impfid, | ||
entry->info.iov.iov_base, | ||
entry->info.iov.iov_len); | ||
} | ||
|
||
static void ofi_import_monitor_notify(struct fid_mem_monitor *monitor, | ||
const void *addr, size_t len) | ||
{ | ||
assert(monitor->fid.context == &impmon); | ||
pthread_rwlock_rdlock(&mm_list_rwlock); | ||
pthread_mutex_lock(&mm_lock); | ||
ofi_monitor_notify(&impmon.monitor, addr, len); | ||
pthread_mutex_unlock(&mm_lock); | ||
pthread_rwlock_unlock(&mm_list_rwlock); | ||
} | ||
|
||
static int ofi_close_import(struct fid *fid) | ||
{ | ||
pthread_mutex_lock(&mm_state_lock); | ||
impmon.monitor.state = FI_MM_STATE_IDLE; | ||
pthread_mutex_unlock(&mm_state_lock); | ||
impmon.impfid = NULL; | ||
return 0; | ||
} | ||
|
||
static struct fi_ops_mem_notify import_ops = { | ||
.size = sizeof(struct fi_ops_mem_notify), | ||
.notify = ofi_import_monitor_notify, | ||
}; | ||
|
||
static struct fi_ops impfid_ops = { | ||
.size = sizeof(struct fi_ops), | ||
.close = ofi_close_import, | ||
.bind = fi_no_bind, | ||
.control = fi_no_control, | ||
.ops_open = fi_no_ops_open, | ||
.tostr = fi_no_tostr, | ||
.ops_set = fi_no_ops_set, | ||
}; | ||
|
||
int ofi_monitor_import(struct fid *fid) | ||
{ | ||
struct fid_mem_monitor *impfid; | ||
|
||
if (fid->fclass != FI_CLASS_MEM_MONITOR) | ||
return -FI_ENOSYS; | ||
|
||
if (impmon.impfid) { | ||
FI_WARN(&core_prov, FI_LOG_MR, | ||
"imported monitor already exists\n"); | ||
return -FI_EBUSY; | ||
} | ||
|
||
if (default_monitor && !dlist_empty(&default_monitor->list)) { | ||
FI_WARN(&core_prov, FI_LOG_MR, | ||
"cannot replace active monitor\n"); | ||
return -FI_EBUSY; | ||
} | ||
|
||
impfid = container_of(fid, struct fid_mem_monitor, fid); | ||
if (impfid->export_ops->size < sizeof(struct fi_ops_mem_monitor)) | ||
return -FI_EINVAL; | ||
|
||
impmon.impfid = impfid; | ||
impfid->fid.context = &impmon; | ||
impfid->fid.ops = &impfid_ops; | ||
impfid->import_ops = &import_ops; | ||
|
||
FI_INFO(&core_prov, FI_LOG_MR, | ||
"setting imported memory monitor as default\n"); | ||
default_monitor = &impmon.monitor; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: we can use ofi_monitor_unsubscribe_no_op() as the monitor callback and leave rocr_mm_unsubscribe() named as-is.