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

Avoid unnecessary inter-processor interrupts by checking that writes are necessary #622

Merged
merged 5 commits into from
May 30, 2024

Conversation

zacikpa
Copy link
Contributor

@zacikpa zacikpa commented Apr 10, 2024

This PR adds a new option check_diff to the function commands.write_to_file. When set to True, the function checks whether the current value is equal to the one being written - if it is, the write is skipped.

The new option is disabled by default, but I enable it for plugin options where the write may cause an inter-processor interrupt even when the value does not change.

Print the name of the file being read instead
of its descriptor.
We can use `read_file` and `write_to_file` to handle all manipulation
of sysctl parameters. This does not change the behavior of _read_sysctl
and _write_sysctl, but it alters some of their debug/error messages.
@zacikpa zacikpa force-pushed the reduce-ipi branch 2 times, most recently from 4cf17a0 to 36e1f0b Compare April 11, 2024 08:11
@zacikpa zacikpa marked this pull request as ready for review April 11, 2024 09:36
@zacikpa zacikpa requested review from jmencak and yarda April 11, 2024 09:36
Copy link
Contributor

@jmencak jmencak 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 for the PR. I'm wondering why do we need a new option for this and why this is not a default? cc @MarSik

Edit: Sorry, my bad. Looking at the code this seems fine. I thought we're adding a new option to tuned-main.conf

@jmencak
Copy link
Contributor

jmencak commented May 10, 2024

Thank you for the PR, @zacikpa . Testing this right now. So far, I've noticed the following issues. When the same value is in the governor, we still write the same value. The check_diff seems to be False. Another issue I've noticed is that we'll need to change the TuneD configs. There are some aliases like "performance" when written to /sys/devices/system/cpu/cpuX/power/energy_perf_bias will be translated to 0. So our configuration, such as

energy_perf_bias=performance

will have to be changed to

energy_perf_bias=0

so that we take advantage of this new functionality.

Anyways, could you please look into the scaling_governor issue? Thank you.

@jmencak
Copy link
Contributor

jmencak commented May 10, 2024

Also, running

x86_energy_perf_policy -r

causes quite a few IPIs. This is pretty "expensive" if we're just checking that x86_energy_perf_policy is supported by TuneD and then we never use it anyway. I wonder if we could just check for the presence of the file and whether it is executable?

@jmencak
Copy link
Contributor

jmencak commented May 10, 2024

I've finished testing the code. In summary, I see these issues that I'd like to see fixed before merging:

  • setting the same scaling_governor still triggers IPIs
  • let's remove x86_energy_perf_policy -r check, which causes unnecessary IPIs

Issues that I do not expected fixed by this PR:

  • [rtentsk] plug-in
  • even reading EPB/EPP causes IPIs

As even reading

/sys/devices/system/cpu/cpu*/power/energy_perf_bias
/sys/devices/system/cpu/cpufreq/policy*/energy_performance_preference

can cause IPIs, this change could essentially make things worse IPI-wise when writing a different value of EPB/EPP. The first IPI would happen during the read, the second during the write. I wonder if it would make sense to exclude the diff_check (set it False) for these two knobs.

FWIW, reads/writes to EPP seem to be "expensive" in mostly the same way, whereas reads of EPB are less expensive than writes to EPB.

@zacikpa
Copy link
Contributor Author

zacikpa commented May 21, 2024

Hello @jmencak. I updated the PR so that:

  • check_diff is True also for the scaling_governor,
  • x86_energy_perf_policy is only checked for if we may actually need it, i.e., if we cannot set EPB via sysfs.

Regarding the reads: if reading EPP is as expensive as writing, then I'd say it doesn't make sense to check the value first.

@zacikpa
Copy link
Contributor Author

zacikpa commented May 21, 2024

@jmencak Regarding the aliases for EPB: can you please open a separate upstream or Jira issue for that?

@jmencak
Copy link
Contributor

jmencak commented May 21, 2024

Thank you for the changes, Pavol. Great work! The code now does what I expect it to do. After testing, I can only see IPIs caused by the following options:

[rtentsk]
[cpu]
energy_perf_bias=<value>
energy_performance_preference=<value>

At this point this is expected and hard to avoid/work around.

The code changes look sane to me, but deferring to other reviewers for comment.

Copy link
Contributor

@yarda yarda left a comment

Choose a reason for hiding this comment

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

Thanks, the code LGTM. I have two minor comments that aren't blockers and could be handled later. I think this PR needs to be merged into FDP and we have still some time to fine tune it, so I will keep it open for now.

tuned/utils/commands.py Outdated Show resolved Hide resolved
tuned/plugins/plugin_cpu.py Outdated Show resolved Hide resolved
In some situations it may be desirable to check if a file write is
necessary by comparing the new file content with the existing one
(e.g., when the write always causes an inter-processor interrupt).
This commit adds an option to perform such a check in `write_to_file`.
If it succeeds, the write is skipped.
If the CPU supports hwp_epp, we should always be able to access
EPB via its sysfs knob, so we don't have to check if we have
x86_energy_perf_policy because we don't need it to manipulate EPB.
@jmencak
Copy link
Contributor

jmencak commented May 28, 2024

I've retested with the latest code, still looks good.

@yarda yarda merged commit 6de25e2 into redhat-performance:master May 30, 2024
14 checks passed
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.

None yet

3 participants