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

feature: Fine-grained control of the CPU. #115

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

Super-long
Copy link
Contributor

@Super-long Super-long commented May 23, 2022

Signed-off-by: Super-long [email protected]

Describe what this PR does / why we need it

This PR attempts to improve the existing CPU burn implementation by modifying the coarse-grained loop to a finer one and introducing more algorithms to enrich the CPU burn.

Describe how you did it

The existing CPU fullload maintains the CPU load specified by the cpu-percent and gets q and ds based on the quota channel, then executes the CPU burn logic based on q and ds, I modified the implementation of the existing loop to introduce a richer and more diverse cpu burn algorithm, the algorithm ideas refer to the implementation of stress-ng --cpu-load.

Notes

The reason I greatly complicated burn's default judgment compared to previous implementations is that in extreme cases burn may get two consecutive values from quota, which can cause a sudden increase in CPU burn load. I encountered the following situation in the 910dab71b62ff91bbc715ccde4fc5faf59d274c1 commit:

截屏2022-05-24 下午7 34 26

TODO List

New features are still being implemented, I hope you have more comments.

  1. More diverse CPU burn algorithms can be implemented in cpu_methods.
  2. Do existing loop-based CPU burn implementations really need to be replaced? There is already a simple test for implementing CPU burn based on loop you can refer to the Specify the CPU percentage section in https://blog.csdn.net/weixin_43705457/article/details/124904793

Test

  1. First execute taskset -c 0 . /chaos_os create cpu fullload --uid=d32d49a509d73856 --cpu-count=1 --cpu-percent=70 --cpu-index 0 Observe that the current CPU0 load is about 70%.
  2. Then execute taskset -c 0 . /stress-ng --cpu 1 --cpu-load 40 --timeout 20h and observe that the CPU usage of the stress-ng process is 40% and the CPU usage of the chaos_os process is 30%.
  3. Shut down the last stress-ng process, execute taskset -c 0 . /stress-ng --cpu 1 --cpu-load 80 --timeout 20h and observe that the CPU usage of the stress-ng process is 80% and chaos_os is nearly zero.
  4. Shut down the last stress-ng process and observe that the current CPU0 load is about 70%.

CPU burn

The current individual CPU burn algorithm's average consumption time, The test code is available here: https://github.com/Super-long/tproxy-http_hijacking/blob/main/stress_cpu.go

  • fft 180.146µs
  • pi 1.596478ms
  • fibonacci 193ns
  • ackermann 4.687225ms
  • bitops 337.691µs
  • collatz 4.216µs
  • crc16 108.159µs
  • factorial 61.788µs

@Super-long Super-long force-pushed the Refinement_of_CPU_control branch from 3285694 to bb0d1ea Compare May 24, 2022 02:58
@tiny-x tiny-x added the type/enhancement New feature or request label May 24, 2022
@Super-long Super-long force-pushed the Refinement_of_CPU_control branch 2 times, most recently from df4bf7f to a3a673a Compare May 24, 2022 09:00
@Super-long Super-long force-pushed the Refinement_of_CPU_control branch from a3a673a to 910dab7 Compare May 24, 2022 12:31
@Super-long Super-long force-pushed the Refinement_of_CPU_control branch from f2afb5b to aecf663 Compare May 25, 2022 02:06
@tiny-x tiny-x self-requested a review June 21, 2022 08:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants