Skip to content
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 a trait for Plugins and allow them to be dynamically loaded or statically linked #114

Merged
merged 19 commits into from
Jul 16, 2021
Merged

Conversation

p-avital
Copy link
Contributor

@p-avital p-avital commented Jul 7, 2021

Opening this PR as an RFC. When approved, I'll convert the existing plugins.

@p-avital p-avital marked this pull request as draft July 7, 2021 10:35
@p-avital
Copy link
Contributor Author

p-avital commented Jul 7, 2021

@JEnoch @OlivierHecart :)

@p-avital p-avital marked this pull request as ready for review July 7, 2021 10:40
@@ -2975,6 +2975,14 @@ dependencies = [
"zenoh_backend_traits",
]

[[package]]
name = "zenoh-plugin-trait"
version = "0.1.0-dev"
Copy link
Member

Choose a reason for hiding this comment

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

Version should be the same as zenoh (0.5.0-dev) since we will release all together.

#
[package]
name = "zenoh-plugin-trait"
version = "0.1.0-dev"
Copy link
Member

Choose a reason for hiding this comment

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

Version should be the same as zenoh (0.5.0-dev) since we will release all together.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, although I've removed zenoh when I realized it was causing a dependency cycle when I started working on integrating it into zenoh itself

"Julien Enoch <julien@enoch.fr>",
"Olivier Hécart <olivier.hecart@adlinktech.com>",
"Luca Cominardi <luca.cominardi@adlinktech.com>",
]
Copy link
Member

Choose a reason for hiding this comment

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

Feel free to add yourself! 😉

/// To signal that your plugin is incompatible with a previously instanciated plugin, return `Err`,
/// Otherwise, return `Ok(Self::compatibility())`.
///
/// By default, a plugin is non-reentrant to avoir reinstanciation if its dlib is accessible despite it already being statically linked.
Copy link
Member

Choose a reason for hiding this comment

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

"avoir" => "avoid"


/// For use with dynamically loaded plugins. Its size will not change accross versions, but its internal structure might.
///
/// To ensure compatibility, its size and alignment must allow `size_of::<Result<PluginVTable, PluginVTableVersion>>() == 64` (one cache line).
Copy link
Member

Choose a reason for hiding this comment

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

size_of::<Result<PluginVTable, PluginVTableVersion>> or size_of::<Result<PluginVTableInner, PluginVTableVersion>> ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PluginVTable, the goal is for the size of the outer type to be fixed even if we change the size of the inner one (by adding more functions to the vtable for example).

The constant should let us know that the pointers may not point to the same things, but I'm afraid of what would happen if the load_plugin function returns something bigger (or smaller) than what is expected by the caller.

__padding: [u8; PADDING_LENGTH],
}
const PADDING_LENGTH: usize =
64 - std::mem::size_of::<Result<PluginVTableInner, PluginVTableVersion>>();
Copy link
Member

Choose a reason for hiding this comment

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

Since the PluginVTablePadding is used along PluginVTableInner within PluginVTable, I don't understand why its length depends on Result<PluginVTableInner, PluginVTableVersion> rather than just PluginVTableInner. Can you explain ?

Copy link
Contributor Author

@p-avital p-avital Jul 8, 2021

Choose a reason for hiding this comment

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

It feels a bit less "magic" to set the padding length as "a cache line size minus the size of the type that actually interests us".

Result should use an 8 bytes marker due to align_of::<PluginVTable>() being 8 (and the same as align_of::<PluginVTableInner>()), but that might change (for example if it finds a niche to exploit or realizes that the first bytes are non-null for Ok and null of Err in a few compiler updates), so I'd rather use the Result type to ensure that type has consistent size.

Copy link
Member

Choose a reason for hiding this comment

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

There is a crate that does that: https://docs.rs/cache-padded/1.1.1/cache_padded/. I suggest to use this crate that is already widely used.

@JEnoch JEnoch changed the title WIP: Plugin trait Define a trait for Plugins and allow them to be dynamically loaded or statically linked Jul 16, 2021
@JEnoch JEnoch merged commit d7e60f2 into eclipse-zenoh:master Jul 16, 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.

3 participants