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

Add support for s390x cpu frequency #728

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions absl/base/internal/unscaledcycleclock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ double UnscaledCycleClock::Frequency() {
#endif
}

#elif defined(__s390x__)

int64_t UnscaledCycleClock::Now() {
int64_t tsc;
asm("stck %0" : "=Q" (tsc) : : "cc");
return tsc;
}

double UnscaledCycleClock::Frequency() {
return base_internal::NominalCPUFrequency();
}

#elif defined(__aarch64__)

// System timer of ARMv8 runs at a different frequency than the CPU's.
Expand Down
4 changes: 2 additions & 2 deletions absl/base/internal/unscaledcycleclock.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
// The following platforms have an implementation of a hardware counter.
#if defined(__i386__) || defined(__x86_64__) || defined(__aarch64__) || \
defined(__powerpc__) || defined(__ppc__) || \
defined(_M_IX86) || defined(_M_X64)
defined(_M_IX86) || defined(_M_X64) || defined(__s390x__)
#define ABSL_HAVE_UNSCALED_CYCLECLOCK_IMPLEMENTATION 1
#else
#define ABSL_HAVE_UNSCALED_CYCLECLOCK_IMPLEMENTATION 0
Expand Down Expand Up @@ -81,7 +81,7 @@
// This macro can be used to test if UnscaledCycleClock::Frequency()
// is NominalCPUFrequency() on a particular platform.
#if (defined(__i386__) || defined(__x86_64__) || \
defined(_M_IX86) || defined(_M_X64))
defined(_M_IX86) || defined(_M_X64)) || defined(__s390x__)
Copy link
Member

Choose a reason for hiding this comment

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

https://groups.google.com/forum/#!topic/bit.listserv.ibm-main/mYYcbXg0lGY makes me think that the counter retreived by the stck instruction is a clock, but not one that runs at the CPU frequency, since it seems constant across chips. Can you point me to documentation that shows otherwise?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the notes. Honestly speaking, I'm not very familiar with instruction set or cpu counter, so I guess what you are suggesting is that stck does not return the correct cpu time so the frequency calculated based on this will not be accurate, am I understanding it correctly? If this is the case, could you please give me a hint of what counter do we need to retrieve here so that I could look into it further? Thank you.

#define ABSL_INTERNAL_UNSCALED_CYCLECLOCK_FREQUENCY_IS_CPU_FREQUENCY
#endif

Expand Down