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

Cache context offline device setting specified by environment variables #235

Merged
merged 1 commit into from
Jan 6, 2023

Conversation

sophimao
Copy link
Contributor

@sophimao sophimao commented Jan 5, 2023

Currently runtime queries context offline device setting from environment variables whenever this setting is needed, therefore introduces performance overhead. The caching is done to avoid this performance overhead.

@sophimao sophimao requested review from pcolberg and zibaiwan January 5, 2023 14:50
@sophimao
Copy link
Contributor Author

sophimao commented Jan 5, 2023

This is the first stage change to refactor the context offline mode setting, full change will come later in #234.
Verified that this resolves the regression introduced in #214

@sophimao sophimao self-assigned this Jan 5, 2023
@sophimao sophimao added this to the 2023.1 milestone Jan 5, 2023
zibaiwan
zibaiwan previously approved these changes Jan 5, 2023
Copy link
Contributor

@zibaiwan zibaiwan left a comment

Choose a reason for hiding this comment

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

Thanks @sophimao ! Looks good to me!

Copy link
Contributor

@pcolberg pcolberg left a comment

Choose a reason for hiding this comment

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

Thanks @sophimao, looks good. Please see two minor nitpicks below.

There remain two further calls of acl_get_offline_device_user_setting() as detailed below. Why are these still needed, i.e., why can't they use the cached setting? This might be worthwhile commenting on in the commit message.

// Initialize the HAL and load the builtin system definition.
//
// It will handle setting up an offline device, either exclusively (by
// default), or in addition to devices found via HAL probing.
//
// This function returns CL_TRUE if a hal is initialized and CL_FALSE
// if it is not.
cl_bool acl_init_from_hal_discovery(void) {
int use_offline_only = 0;
const acl_hal_t *board_hal;
acl_assert_locked();
(void)acl_get_offline_device_user_setting(&use_offline_only);

// Dynamically load board mmd & symbols
(void)acl_get_offline_device_user_setting(&use_offline_only);

@sophimao
Copy link
Contributor Author

sophimao commented Jan 5, 2023

There remain two further calls of acl_get_offline_device_user_setting() as detailed below. Why are these still needed, i.e., why can't they use the cached setting?

These are called before the variable is cached. The reason why I cached the variable in acl_init_platform is because it is the function that both acl_init and acl_init_from_hal_discovery calls. Another option is to add a acl_get_offline_device_user_setting call to acl_init and do the caching in acl_init/acl_init_from_hal_discovery.

I personally think it is cleaner to cache the variable in the acl_init_platform function, as the cache is a member of acl_platform, and the two remaining calls shouldn't add too much overhead, but I'm open to the other option if you have a reason for going with it. If you don't strongly prefer the other option then I can add this explanation to the commit message :)

@pcolberg
Copy link
Contributor

pcolberg commented Jan 5, 2023

There remain two further calls of acl_get_offline_device_user_setting() as detailed below. Why are these still needed, i.e., why can't they use the cached setting?

These are called before the variable is cached. The reason why I cached the variable in acl_init_platform is because it is the function that both acl_init and acl_init_from_hal_discovery calls. Another option is to add a acl_get_offline_device_user_setting call to acl_init and do the caching in acl_init/acl_init_from_hal_discovery.

I see. The call graph here is

acl_init_from_hal_discovery()
├── acl_mmd_get_system_definition()
└── acl_init_platform()

so to avoid multiple calls, acl_get_offline_device_user_setting() would need to be called in acl_init_from_hal_discovery(), correct? The setting could then be passed to acl_mmd_get_system_definition() and acl_init_platform() as an argument, for instance.

I personally think it is cleaner to cache the variable in the acl_init_platform function, as the cache is a member of acl_platform, and the two remaining calls shouldn't add too much overhead, but I'm open to the other option if you have a reason for going with it. If you don't strongly prefer the other option then I can add this explanation to the commit message :)

Yes, this is about design only, and now I think your commit is fine without further comment. Let's keep this commit as is for 2023.1 and work out the full design in #234.

@sophimao
Copy link
Contributor Author

sophimao commented Jan 6, 2023

so to avoid multiple calls, acl_get_offline_device_user_setting() would need to be called in acl_init_from_hal_discovery(), correct?

Yes, for the regular flow that is correct. However, for unit test, there is another call graph:

acl_init()
└── acl_init_platform()

So we would also need to add a call to acl_get_offline_device_user_setting in acl_init to pass the value around.

I will keep the design this way for now, and address this in #234.

Currently runtime queries context offline device setting from environment
variables whenever this setting is needed, therefore introduces performance
overhead. The caching is done to avoid this performance overhead.
@pcolberg pcolberg merged commit b645bbe into intel:main Jan 6, 2023
@pcolberg
Copy link
Contributor

pcolberg commented Jan 6, 2023

so to avoid multiple calls, acl_get_offline_device_user_setting() would need to be called in acl_init_from_hal_discovery(), correct?

Yes, for the regular flow that is correct. However, for unit test, there is another call graph:

acl_init()
└── acl_init_platform()

Of course, I missed that despite being right above the other entry point 🤦

So we would also need to add a call to acl_get_offline_device_user_setting in acl_init to pass the value around.

I will keep the design this way for now, and address this in #234.

The separate entry points for testing and production are unfortunate, but that topic should probably be handled separately from the revision in #234. I suggest you rebase that PR onto the main branch and narrow the focus on refactoring acl_get_offline_device_user_setting() to remove the free-form string return value (if that makes sense).

@sophimao sophimao deleted the cache-first-stage branch January 6, 2023 20:52
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