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

Read public GC options if available #86068

Merged
merged 6 commits into from
May 30, 2023

Conversation

kant2002
Copy link
Contributor

Also pass RuntimeHostConfigurationOption into --runtimeopt ILC parameter Fixes : #85961

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label May 10, 2023
@ghost
Copy link

ghost commented May 10, 2023

Tagging subscribers to this area: @agocke, @MichalStrehovsky, @jkotas
See info in area-owners.md if you want to be subscribed.

Issue Details

Also pass RuntimeHostConfigurationOption into --runtimeopt ILC parameter Fixes : #85961

Author: kant2002
Assignees: -
Labels:

area-NativeAOT-coreclr

Milestone: -

@kant2002 kant2002 force-pushed the kant/read-public-gc-options branch from 0edad47 to b4a4f08 Compare May 10, 2023 19:50
@MichalStrehovsky
Copy link
Member

These configuration names come from different "namespaces". Like I wrote in #85961 (comment) "We need to either add another blob with the new values, or come up with some sort of mangling so that we can store both key/value pairs in the same blob. I don't have an opinion. Whichever looks better."

The approach in this PR will run into issues as soon as there's a conflict between a "Config" name and "Knob" name. Here's how CoreCLR implements this:

if (CLRConfig::IsConfigOptionSpecified(configKey))
{
CLRConfig::ConfigDWORDInfo info { configKey , 0, CLRConfig::LookupOptions::Default };
*value = CLRConfig::GetConfigValue(info) != 0;
return true;
}
else if (publicKey != NULL)
{
if (MultiByteToWideChar(CP_ACP, 0, publicKey, -1 /* key is null-terminated */, configKey, MaxConfigKeyLength) == 0)
{
// whatever this is... it's not something we care about. (It was too long, wasn't unicode, etc.)
return false;
}
if (Configuration::GetKnobStringValue(configKey) != NULL)
{
*value = Configuration::GetKnobBooleanValue(configKey, false);
return true;
}
}

CLRConfig::GetConfigValue is the moral equivalent of RhConfig. It will try reading the value from embedded config or from a DOTNET_ prefixed environment variable with that name. Configuration::GetKnobStringValue reads the value from the JSON on the other hand. We miss the other thing. I don't think making CLRConfig::GetConfigValue do the other thing is the right approach.

Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

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

Thanks for taking up the challenge!

@@ -82,6 +82,55 @@ bool RhConfig::ReadConfigValue(_In_z_ const TCHAR *wszName, uint64_t* pValue, bo
}

#ifdef FEATURE_EMBEDDED_CONFIG

bool RhConfig::ReadKnobValue(_In_z_ const TCHAR *wszName, uint64_t* pValue, bool decimal)
Copy link
Member

Choose a reason for hiding this comment

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

We just switched ReadConfigValue from TCHAR to char*. Could you rebase against latest main and apply similar changes as in #86393? Cc @elinor-fung

#endif // FEATURE_EMBEDDED_CONFIG

public:

bool ReadConfigValue(_In_z_ const TCHAR* wszName, uint64_t* pValue, bool decimal = false);
#ifdef FEATURE_EMBEDDED_CONFIG
bool ReadKnobValue(_In_z_ const TCHAR* wszName, uint64_t* pValue, bool decimal = false);
Copy link
Member

Choose a reason for hiding this comment

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

decimal = false doesn't look right - we don't pass this as true for GC settings but the GC settings in runtimeconfig.json are documented to be decimal (as opposed to the GC settings set through environment variables that are hex).

In fact, do we need the hex support in knobs?


foreach (string option in _runtimeKnobs)
{
byte[] optionBytes = System.Text.Encoding.ASCII.GetBytes(option);
Copy link
Member

Choose a reason for hiding this comment

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

We should use UTF-8 - users can dump anything they want into RuntimeHostConfigurationOption ItemGroup.

Suggested change
byte[] optionBytes = System.Text.Encoding.ASCII.GetBytes(option);
byte[] optionBytes = System.Text.Encoding.UTF8.GetBytes(option);

@kant2002
Copy link
Contributor Author

What about honoring COMPlus_XXX environment variables while I'm in this location?

image

@MichalStrehovsky
Copy link
Member

We should be already honoring the DOTNET_ prefixed ones. Reading from environment variables is the major difference between "knobs" and "switches".

@kant2002
Copy link
Contributor Author

Yes DOTNET_ is honored, but in the docs still exists old one COMPLUS_, and I thinking about adding that support for switches and not knobs. Just I see it is as supported (not sure for how long) and I suspect that after some time would be customer request for that.

@jkotas
Copy link
Member

jkotas commented May 23, 2023

COMPlus_ prefix for env settings is deprecated. We do not need to give it a new life in native AOT. We can add stronger wording in the docs to use DOTNET_.

@kant2002 kant2002 force-pushed the kant/read-public-gc-options branch from e4c84c5 to a0a1a65 Compare May 23, 2023 13:35

const ConfigPair* configPairs = (const ConfigPair*)g_embeddedKnobs;

// Find the first name which matches (case insensitive to be compat with environment variable counterpart)
Copy link
Member

Choose a reason for hiding this comment

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

TODO: compare with coreclr - is this case insensitive?

Copy link
Member

Choose a reason for hiding this comment

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

Whoops, that TODO was for me, but might as well dump it on you :). Can you compare how this is done in CoreCLR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

casesensetive comparison always. for knobs and configs.

const ConfigPair* configPairs = (const ConfigPair*)g_embeddedKnobs;

// Find the first name which matches (case insensitive to be compat with environment variable counterpart)
for (int iSettings = 0; iSettings < RCV_Count; iSettings++)
Copy link
Member

Choose a reason for hiding this comment

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

RCV_Count only make sense if we know the upper bound because this is not something that is user-configurable. RuntimeHostConfigurationOption is unbounded. We need to keep track of the real count. (Same comment applies to other uses of RCV_Count in this file)

@@ -179,6 +191,103 @@ void RhConfig::ReadEmbeddedSettings()
return;
}

bool RhConfig::GetEmbeddedKnob(_In_z_ const char* configName, _Out_ const char** configValue)
Copy link
Member

Choose a reason for hiding this comment

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

The new methods look very similar to the existing ones. Can we share them?

Copy link
Member

Choose a reason for hiding this comment

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

If we share, we'd delete the concept of RCV_Count.

Copy link
Member

Choose a reason for hiding this comment

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

Note that there's another PR in flight making changes here so we might want to pause for a moment to avoid conflicts. #86656 cc @elinor-fung

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not sure if sharing make things better, but please take a look.

Comment on lines 1378 to 1381
if (g_pRhConfig->ReadKnobValue(publicKey, &uiValue))
{
*value = uiValue != 0;
return true;
}
Copy link
Member

Choose a reason for hiding this comment

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

This won't work for settings that specify true/false. Could you mirror how this is handled in CoreCLR?

Copy link
Member

@MichalStrehovsky MichalStrehovsky left a comment

Choose a reason for hiding this comment

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

Thank you!

src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs Outdated Show resolved Hide resolved
src/coreclr/nativeaot/Runtime/RhConfig.cpp Outdated Show resolved Hide resolved
src/coreclr/nativeaot/Runtime/RhConfig.cpp Outdated Show resolved Hide resolved
src/coreclr/nativeaot/Runtime/RhConfig.cpp Outdated Show resolved Hide resolved
src/coreclr/nativeaot/Runtime/RhConfig.cpp Outdated Show resolved Hide resolved
src/coreclr/nativeaot/Runtime/RhConfig.cpp Outdated Show resolved Hide resolved
src/coreclr/nativeaot/Runtime/RhConfig.cpp Outdated Show resolved Hide resolved
src/coreclr/nativeaot/Runtime/RhConfig.h Outdated Show resolved Hide resolved
@kant2002
Copy link
Contributor Author

Looks like you are tired to babysit me 😄 thank you!

@MichalStrehovsky MichalStrehovsky merged commit 15f5f79 into dotnet:main May 30, 2023
@MichalStrehovsky
Copy link
Member

Looks like you are tired to babysit me 😄 thank you!

It was already close enough that we could avoid another round :). Thanks!

@kant2002 kant2002 deleted the kant/read-public-gc-options branch May 30, 2023 04:22
MichalStrehovsky added a commit to MichalStrehovsky/runtime that referenced this pull request May 30, 2023
Previously AppContext switches were set by injecting a method that calls `AppContext.SetSwitch` at startup. Use the configuration blob added in dotnet#86068 instead. This makes startup a tiny bit faster and the outputs a tiny bit smaller.

Fixes dotnet#77054.
MichalStrehovsky added a commit that referenced this pull request May 31, 2023
Previously AppContext switches were set by injecting a method that calls `AppContext.SetSwitch` at startup. Use the configuration blob added in #86068 instead. This makes startup a tiny bit faster and the outputs a tiny bit smaller.

Fixes #77054.
@ghost ghost locked as resolved and limited conversation to collaborators Jun 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-NativeAOT-coreclr community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RuntimeHostConfigurationOption for GC configuration ignored in NativeAOT
3 participants