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

[ESI][Runtime] MMIO service support #6034

Merged
merged 4 commits into from
Sep 6, 2023
Merged

Conversation

teqdruid
Copy link
Contributor

@teqdruid teqdruid commented Sep 1, 2023

Service C++ interface, Python wrapping, and cosim support for MMIO. Also adds the basic service framework.

Service C++ interface, Python wrapping, and cosim support. Also adds the
basic service framework.
@teqdruid teqdruid added the ESI label Sep 1, 2023
@teqdruid teqdruid marked this pull request as ready for review September 1, 2023 23:40
Comment on lines 23 to 28
std::unique_ptr<Service> &cacheEntry = serviceCache[&svcType];
if (cacheEntry != nullptr)
return cacheEntry.get();
cacheEntry = std::unique_ptr<Service>(createService(svcType));
return cacheEntry.get();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

use std::map::emplace instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Getting a reference to the storage slot saves a little code (which I fucked up) and a search for the insertion.

virtual std::string rawJsonManifest() const = 0;
protected:
using Service = services::Service;
virtual Service *createService(Service::Type service) = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use smart pointers here or write a comment to be very explicit about the ownership of the returned pointer (i see a mix of unique_ptrs being placed into caches and raw-pointers being allocated and return to the former).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a protected method because it is not intended to be called directly by clients. It is called by getServiceImpl, which immediately wraps it in a unique pointer and adds it to the cache. I structured it that way to avoid subclasses from having to reason about the way that the cache is implemented. I will add some documentation to that effect.

Comment on lines +108 to +113
Service *CosimAccelerator::createService(Service::Type svcType) {
if (svcType == typeid(MMIO))
return new CosimMMIO(impl->lowLevel, impl->waitScope);
else if (svcType == typeid(SysInfo))
return new MMIOSysInfo(getService<MMIO>());
return nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

To be frank, i don't think there is any merit in this kind of code returning a raw pointer. If you really want the raw pointer semantics, then there should be a Service* getService method that dispatches to a std::unique_ptr<Service> createService function in case the service was not found in the cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I do, but I wrap the pointer in another method.

@teqdruid teqdruid merged commit 28bd7f1 into main Sep 6, 2023
5 checks passed
@teqdruid teqdruid deleted the dev/teqdruid/esi/mmio-cosim branch September 6, 2023 20:11
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.

None yet

2 participants