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

Reduce rtp port name search complexity #4272

Merged
merged 2 commits into from
Oct 21, 2020
Merged

Reduce rtp port name search complexity #4272

merged 2 commits into from
Oct 21, 2020

Conversation

larry9523
Copy link
Collaborator

This PR addressed the following issues
1.
We are currently using vector to store RTP port and when a port is updated, we use
auto rtp = std::find_if(rtps.begin(), rtps.end(), auto it = rtps.find(port);
[port](rtp_type it) { return it.name.compare(port) == 0; });
to match a given port name.

This is time consuming when there are as much as 400 rtp ports used. In this PR, we changed vector to unordered_map to store rtp ports so that we can theoretically reduce the search complexity to O(1)

For interface xrtGraphWait and xrtGraphWaitDone, we return successfully if the graph is already in suspend state or stop state.

@larry9523 larry9523 requested a review from stsoe October 19, 2020 22:14
@gbuildx
Copy link
Collaborator

gbuildx commented Oct 19, 2020

Build Passed!

@@ -79,7 +79,7 @@ graph_type(std::shared_ptr<xrt_core::device> dev, const uuid_t, const std::strin
rtp.selector_row += 1;
rtp.ping_row += 1;
rtp.pong_row += 1;
rtps.emplace_back(std::move(rtp));
rtps.insert(std::make_pair(rtp.name, std::move(rtp)));
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
rtps.insert(std::make_pair(rtp.name, std::move(rtp)));
rtps.emplace(rtp.name, std::move(rtp));

Copy link
Collaborator

@stsoe stsoe Oct 20, 2020

Choose a reason for hiding this comment

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

Same code fewer key strokes. But btw is either construct really safe? Is there any chance rtp.name could have been moved before it is copied, for sure order of evaluation is not defined here. There is enough doubt in my mind that I think a copy of the string should have been done outside insert or emplace, then another std::move on the copied string.

Better, a std::set should have been used with proper compare defined.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

Copy link
Member

Choose a reason for hiding this comment

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

Same code fewer key strokes. But btw is either construct really safe? Is there any chance rtp.name could have been moved before it is copied, for sure order of evaluation is not defined here. There is enough doubt in my mind that I think a copy of the string should have been done outside insert or emplace, then another std::move on the copied string.

Ouch, you are right!

Better, a std::set should have been used with proper compare defined.

Brilliant.

throw xrt_core::error(-EINVAL, "Can't update graph '" + name + "': RTP port '" + port + "' not found");
auto& rtp = it->second;
Copy link
Member

Choose a reason for hiding this comment

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

I love this laziness! :-)

@@ -25,6 +25,7 @@
#include "core/common/device.h"
#include <string>
#include <vector>
#include <unordered_map>
Copy link
Member

Choose a reason for hiding this comment

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

Are you using an unordered_sort on the headers here? ;-)

Copy link
Member

Choose a reason for hiding this comment

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

It would have been nicer with #include <unordered_map> before #include <vector>

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Point taken. Will sort it in my next PR.

Copy link
Collaborator

@stsoe stsoe Oct 21, 2020

Choose a reason for hiding this comment

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

Never thought about sorting #includes but actually that's a good idea. I will follow that.
Do make sure all XRT local includes are grouped before system includes though.
@keryell Took your second comment before I understood your first :-)

Copy link
Member

Choose a reason for hiding this comment

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

Sorry for using too much convoluted humor too often...
Sorting headers is common in a lot of projects and coding styles to have a quicker idea about what are the headers in use.

Copy link
Collaborator

@stsoe stsoe left a comment

Choose a reason for hiding this comment

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

See comment on insert/emplace.

@larry9523 larry9523 requested a review from stsoe October 20, 2020 22:25
@gbuildx
Copy link
Collaborator

gbuildx commented Oct 21, 2020

Build Passed!

@stsoe stsoe merged commit a643023 into Xilinx:master Oct 21, 2020
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.

4 participants