Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix CPU frequency estimation on riscv #1549

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

Merged
merged 6 commits into from
Feb 21, 2023
Merged

Conversation

dtcxzyw
Copy link
Contributor

@dtcxzyw dtcxzyw commented Feb 19, 2023

I used to run llvm-test-suite on the riscv64 platform, but I found that the CPU frequency given by the benchmark framework was incorrect. Unfortunately, neither the cpufreq interface nor BogoMIPS is implemented on the linux-riscv64 platform, it just uses
rdcycle and nanosleep to estimate CPU frequency.

However, cycle counters are per-core on RISC-V, and what “sleep” means is also not standardized by the RISC-V specifications.
On my machine, calling nanosleep doesn't work because the cycle counter doesn't increase during sleeping. Furthermore, it does not prevent thread migration during timing.

Please also refer to riscv/riscv-isa-manual#140 and the RISC-V Instruction Set Manual.

I use the pseudo-random number generator given by <random> instead of calling SleepForMilliseconds as the load and temporarily pin the current thread to a core during timing. This patch works fine on my machine.

It has been tested on the following platforms:

  • Linux 5.19.0-1012-generic 13~22.04.1-Ubuntu SMP Thu Jan 12 15:34:31 UTC 2023 riscv64 + gcc 11.3.0 riscv64-linux-gnu + SiFive u74-mc
  • Linux 5.15.0-57-generic 63-Ubuntu SMP Thu Nov 24 13:43:17 UTC 2022 x86_64 + gcc 11.3.0 x86_64-linux-gnu/clang 14.0.0
  • Windows 10 22H2 19045.2604 + MSVC 19.29.30147.0

If it is OK, I can also drop bogoMIPS and just use the estimation to close #312.
Since SleepForMilliseconds is no longer used, sleep.h and sleep.cc can be removed from the framework.

@google-cla
Copy link

google-cla bot commented Feb 19, 2023

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@dmah42
Copy link
Member

dmah42 commented Feb 20, 2023

https://github.com/google/benchmark/actions/runs/4217605263/jobs/7332317281#step:6:24 .. looks like a bit cleverer #defines are needed to avoid the lambda capture that's unnecessary.

@dtcxzyw
Copy link
Contributor Author

dtcxzyw commented Feb 20, 2023

https://github.com/google/benchmark/actions/runs/4217605263/jobs/7332317281#step:6:24 .. looks like a bit cleverer #defines are needed to avoid the lambda capture that's unnecessary.

It has been resolved. It looks like only clang++ complains about this. By the way, I think clang is actually used for the workflow macos-latest.**.**.g++ because g++ doesn't recognize the option -Wunused-lambda-capture at all.

@dmah42
Copy link
Member

dmah42 commented Feb 21, 2023

looks good.. just that one thing i'd like you to move back please, then check CI, then i can merge it :)

@dtcxzyw
Copy link
Contributor Author

dtcxzyw commented Feb 21, 2023

looks good.. just that one thing i'd like you to move back please, then check CI, then i can merge it :)

I think sleep.h and sleep.cc should be removed before merging since the function SleepForMilliseconds is no longer used.

@dmah42
Copy link
Member

dmah42 commented Feb 21, 2023

looks good.. just that one thing i'd like you to move back please, then check CI, then i can merge it :)

I think sleep.h and sleep.cc should be removed before merging since the function SleepForMilliseconds is no longer used.

sure. if they're unused let's do that. i'll wait :)

@dmah42 dmah42 merged commit 3b19d72 into google:main Feb 21, 2023
@dmah42
Copy link
Member

dmah42 commented Feb 21, 2023

thank you!

pull bot pushed a commit to jamlee-t/v8 that referenced this pull request Apr 19, 2023
--- Manual changes: ---

1) Updated version of google_benchmark to fix windows compile error.
  New range: https://chromium.googlesource.com/external/github.com/google/benchmark/+log/e8baf26..b177433
2) Remove unused sleep.[cc|h] from BUILD.gn. (Removed here: google/benchmark#1549)
3) Fix deprecation warnings (treated as errors) in allocation_perf.cc.
  benchmark::DoNotOptimize has deprecated overloads due to google/benchmark#1493.

Bug: 1425054

--- Original message generated by autoroll: ---

Rolling v8/third_party/google_benchmark/src: https://chromium.googlesource.com/external/github.com/google/benchmark/+log/e8baf26..efc89f0

link to benchmark directly for tests that aren't link_main_test (#1576) (dominic)
https://chromium.googlesource.com/external/github.com/google/benchmark/+/efc89f0

Convert uses of `const char*` to `std::string` (#1567) (dominic)
https://chromium.googlesource.com/external/github.com/google/benchmark/+/46d3c84

add '@' to correctly reference build file for libpfm (#1575) (dominic)
https://chromium.googlesource.com/external/github.com/google/benchmark/+/68aa190

Address warnings on NVIDIA nvc++ (#1573) (Henrique Bucher)
https://chromium.googlesource.com/external/github.com/google/benchmark/+/9f7dc38

simplify setting C++ standard (Dominic Hamon)
https://chromium.googlesource.com/external/github.com/google/benchmark/+/1b507cb

[FR] Provide public accessors to benchmark name and arguments #1551 (#1563) (Mike Apodaca)
https://chromium.googlesource.com/external/github.com/google/benchmark/+/f32748c

use std::string for skip messages (#1571) (dominic)
https://chromium.googlesource.com/external/github.com/google/benchmark/+/060d762

[FR] state.SkipWithMessage #963 (#1564) (Mike Apodaca)
https://chromium.googlesource.com/external/github.com/google/benchmark/+/adb0d3d

...

Change-Id: I69218b84b88fb1da25e740d7fb623528d526b85b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4429376
Reviewed-by: Toon Verwaest <[email protected]>
Commit-Queue: Matthias Liedtke <[email protected]>
Cr-Commit-Position: refs/heads/main@{#87139}
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.

BogoMIPS usage is incorrect
2 participants