Skip to content

Conversation

@wckzhang
Copy link
Contributor

Signed-off-by: William Zhang [email protected]

@wckzhang
Copy link
Contributor Author

Adding some comments to make the code more understandable.


/*
* These no-op functions are necessary since libfabric does not allow null
* function pointers here or else it will segfault.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drop the "or else it will segfault". The fact that it doesn't allow NULL pointers is sufficient.

#endif /* OPAL_OFI_IMPORT_MONITOR_SUPPORT */

OPAL_DECLSPEC int opal_common_ofi_init(void)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All functions that do interesting work should have a doxygen style header.

You should call out things like what this function is doing and why. At some point, you should explicitly say that you're injecting a monitor into Libfabric so that Libfabric can use Open MPI's memory hooks as its memory monitor, rather than trying to use its own.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a comment in the header file for the function, but it isn't doxygen style, I'll update it and give it more information

int ret;

/*
* Global refcnt and boolean are used to ensure we only initialize once
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern is well established and doesn't need a comment about why its here. However, you do need to explain how this fits in with the thread safety requirements of this function (and document those requirements in the function header).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think to make it easier for users to call this function, I'll add a new opal_mutex_t lock and lock around the whole function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is that the right thing to do? That has its own risks, especially around initialization of the mutex in the initialization function you're currently writing. Just get the definition right.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already a common mutex lock that is being used, I think it's fine to re-use that

}

/*
* This cache object doesn't do much, but is necessary for the API to work.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this doesn't really help the reader. Bigger questions would be "Why 1.13" and "why "mr_cache"". Those are the things you should comment on.

OPAL_DECLSPEC int opal_common_ofi_fini(void)
{
/*
* Global refcnt and boolean are used to ensure we only finalize once
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't need to do this comment.

For thread safety, we have the init/fini functions locked under the
common ofi lock.

Signed-off-by: William Zhang <[email protected]>
@wckzhang
Copy link
Contributor Author

Updated comments, added locking to the init/fini function since I don't think it was actually thread safe previously. Reused the common ofi mutex lock for this.

@bwbarrett
Copy link
Member

Replaced by #9441

@bwbarrett bwbarrett closed this Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants