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

oak_runtime: Track Nodes with u64 NodeRefs #690

Merged
merged 4 commits into from
Mar 10, 2020

Conversation

blaxill
Copy link
Contributor

@blaxill blaxill commented Mar 9, 2020

Checklist

  • Pull request affects core Oak functionality (e.g. runtime, SDK, ABI)
    • I have written tests that cover the code changes.
    • I have checked that these tests are run by Cloudbuild
    • I have updated documentation accordingly.
    • I have raised an issue to
      cover any TODOs and/or unfinished work.
  • Pull request includes prototype/experimental work that is under
    construction.

@blaxill blaxill requested a review from tiziano88 March 9, 2020 22:31
Copy link
Collaborator

@tiziano88 tiziano88 left a comment

Choose a reason for hiding this comment

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

Thanks, looking good!

#[derive(Debug)]
struct Node {
reference: NodeRef,
join_handle: Option<JoinHandle>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess this may become HashSet<JoinHandle> in the future, if / when we support multiple threads per node?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this can be expanded

let mut node_threads = self.node_threads.lock().unwrap();
{
let nodes = self.nodes.lock().unwrap();
debug!("nodes: {:?}", nodes);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this intended? Why not just move this after line 99?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed: left over from checking things were working as intended :)

@@ -73,6 +72,7 @@ impl Configuration {
&self,
config_name: &str, // Used for pretty debugging
runtime: RuntimeRef,
_noderef: NodeRef,
Copy link
Collaborator

Choose a reason for hiding this comment

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

What is this used for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When a Node is created and the runtime generates a new reference/id, i pass it here into the newly created threads so it knows its own reference. Currently unused as the runtime/channel methods don't use the references.

fn new_node_handle(&self) -> NodeRef {
let mut handle;

loop {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel it would be sufficient / simpler to just use an incrementing (atomic) counter, similar to how Process IDs work in OSs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. Argh, I had randomized it as I think thats the direct you want to go with Channels.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think channels will also not be randomized, but channel handles (read or write) will be, since they are the ones used as capabilities.

@blaxill blaxill requested a review from tiziano88 March 10, 2020 11:36
@@ -47,7 +56,8 @@ pub struct Runtime {
configurations: HashMap<String, node::Configuration>,
terminating: AtomicBool,
channels: Mutex<Channels>,
node_threads: Mutex<Vec<JoinHandle>>,
nodes: Mutex<HashMap<NodeRef, Node>>,
next_node: AtomicU64,
Copy link
Collaborator

Choose a reason for hiding this comment

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

(optional)

Suggested change
next_node: AtomicU64,
next_node_reference: AtomicU64,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -312,20 +323,36 @@ impl RuntimeRef {
return Err(OakStatus::ErrTerminated);
}

let mut node_threads = self.node_threads.lock().unwrap();
let reference = NodeRef(self.next_node.fetch_add(1, SeqCst));
Copy link
Collaborator

Choose a reason for hiding this comment

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

(optional) Could have a method next_node_reference or similar on self.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done new_node_reference

Ok(join_handle) => {
nodes.insert(
reference,
Node {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe Configuration::new_instance should return a Node struct directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently the implementation of Node is private to the runtime, and would require being visible to the crate for this. I think the encapsulation to only the runtime is preferable, but we can change it in future PRs as necessary.

fn new_node_handle(&self) -> NodeRef {
let mut handle;

loop {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think channels will also not be randomized, but channel handles (read or write) will be, since they are the ones used as capabilities.

@blaxill blaxill merged commit 3da7825 into project-oak:master Mar 10, 2020
@blaxill blaxill mentioned this pull request Mar 23, 2020
19 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants