-
Notifications
You must be signed in to change notification settings - Fork 70
Cache context offline device setting specified by environment variables (2nd stage) #234
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
base: main
Are you sure you want to change the base?
Conversation
be2576f
to
d32aac4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @sophimao for addressing this performance issue. The change is headed in the right direction, but post feature complete I would suggest specifically addressing the regression from #214 and postponing more extensive refactoring to the next release.
What do you think about breaking this up into two PRs?
-
Open a second PR for the regression fix with three commits:
a. declare and initialize
acl_platform.offline_mode
, usingint
as before,b. replace calls of
(void) acl_get_offline_device_user_setting(...)
withacl_platform.offline_mode
; in the commit message explain why the caching is needed,c. introduce and declare
acl_platform.offline_mode
as an enum. -
Mark this PR as a draft for the next release, to be rebased on the other PR once merged.
In particular, for the regression fix I would suggest leaving the current signature of acl_get_offline_device_user_setting()
intact, apart from switching to an enum
which has no further implications.
Regarding the offline_device
string, however, I am wondering whether the post-release refactoring PR could replace this with a non-string representation of the possible states, e.g., replacing the +
prefixing with a combination of enums or something to that effect.
Series of small commits are much easier to review without the context you gained from implementing the change, and they allow individual backporting or reversal as needed.
Thinking about it some more, you might even want to postpone this change to later. It does not do any harm, but you generally want to avoid introducing a change that will likely require further refactoring anyway, e.g., to replace the |
Thanks Peter for the review! I actually have a separate change just targeting the QoR regression introduced in #214, just that I didn't include the enum change in there. I will modify that a bit more to replace all the |
d32aac4
to
169df38
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @sophimao for resuming this. I suggest to focus on acl_get_offline_device_user_setting()
first. That function is hard to follow due to the deep nesting. Would it be feasible to simplify the control flow such that each possible mode is handled in a single block and within each block the function immediately returns the mode and device name?
typedef enum { | ||
ACL_CONTEXT_OFFLINE_AND_AUTODISCOVERY, | ||
ACL_CONTEXT_OFFLINE_ONLY, | ||
ACL_CONTEXT_MSIM, | ||
ACL_CONTEXT_MPSIM | ||
} acl_context_offline_mode_t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can introduce a scoped enum to group the constants:
typedef enum { | |
ACL_CONTEXT_OFFLINE_AND_AUTODISCOVERY, | |
ACL_CONTEXT_OFFLINE_ONLY, | |
ACL_CONTEXT_MSIM, | |
ACL_CONTEXT_MPSIM | |
} acl_context_offline_mode_t; | |
enum class acl_context_offline_mode { | |
offline_and_autodiscovery, | |
offline_only, | |
msim, | |
mpsim | |
}; |
Lowercase is easier to discern for the human reader. (Other projects use SnakeCase for similar reasons.)
acl_context_offline_mode_t | ||
acl_get_offline_device_user_setting(std::string *offline_device) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about combining these into a struct to avoid the null pointer?
struct acl_context_offline_device {
std::string name;
acl_context_offline_mode mode;
}
if (offline_device) { | ||
if (use_offline_only == ACL_CONTEXT_MPSIM) { | ||
*offline_device = ACL_MPSIM_DEVICE_NAME; | ||
} else if (result) { | ||
*offline_device = result; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this function is indeed the right place for this code. However, could you replace the earlier setting = "1"
(which is confusing since that does not appear to be an actually used device name) in favour of directly setting the device name to ACL_MPSIM_DEVICE_NAME
?
What is the content of CL_CONTEXT_MSIM_DEVICE_INTELFPGA
? Is that a boolean or an actual device name? I could not find an equivalent ACL_MSIM_DEVICE_NAME
. Is the code for the old simulator still needed at all?
// Looks at environment variable CL_CONTEXT_OFFLINE_DEVICE_INTELFPGA. | ||
// If it exists and is prefixed by "+" then: | ||
// Return a pointer to the device name (without the "+" prefix). | ||
// Set *use_offline_ret_only = 1 | ||
// If it exists and is not prefixed by "+" then | ||
// Return a pointer to the device name. | ||
// Set *use_offline_ret_only = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not document the possible modes, but the offline device name passed to acl_get_offline_device_user_setting()
. Could you move this comment to the function body and replace the existing, duplicate comment? (There are two possible places for the comment; I prefer the function definition since that avoids having to jump between the comment and the implementation.)
The context offline mode is set through environment variables and remains constant throughout the host program lifetime. This change caches the context offline device setting in the platform which saves the overhead of calling the environment variable querying function.