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

Issue with std::chrono with libc++ in armv7 #618

Closed
koying opened this issue Jan 17, 2018 · 3 comments
Closed

Issue with std::chrono with libc++ in armv7 #618

koying opened this issue Jan 17, 2018 · 3 comments
Assignees

Comments

@koying
Copy link

koying commented Jan 17, 2018

I know this is not a proper bug report but I wanted to report that we found an issue with the following configuration:

NDK: 16b
Arch: armv7
STL: libc++
Code: std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now().time_since_epoch()).count()

This used to work, and basically gave the same information as

  struct timespec now;
  clock_gettime(CLOCK_MONOTONIC, &now);
  return( ((int64_t)now.tv_sec * 1000000000L) + now.tv_nsec );

Since moving to libc++, it doesn't work as expected anymore.
Replacing the "std::" code with the "clock_gettime" solves the issue.

It's still working fine in aarch64.

Sorry, I didn't actually digged deeper to get to the bottom of it, as I personally wanted to get rid of the std::chrono construct anyways ;)

@alexcohn
Copy link

alexcohn commented Jan 18, 2018

This could be related to #423 (comment). Check if the value is correct for armv7 with target API 21.

@rprichard
Copy link
Collaborator

it doesn't work as expected anymore.

How does it fail?

I can't reproduce a problem here. AFAICT, std::chrono::steady_clock is a C++ interface to clock_gettime(CLOCK_MONOTONIC, ...) on Android (android-ndk-r16b/sources/cxx-stl/llvm-libc++/src/chrono.cpp):

steady_clock::time_point
steady_clock::now() _NOEXCEPT
{
    struct timespec tp;
    if (0 != clock_gettime(CLOCK_MONOTONIC, &tp))
        __throw_system_error(errno, "clock_gettime(CLOCK_MONOTONIC) failed");
    return time_point(seconds(tp.tv_sec) + nanoseconds(tp.tv_nsec));
}

This code works fine:

#include <chrono>

#include <stdint.h>
#include <stdio.h>

unsigned long long time_posix() {
  struct timespec now;
  clock_gettime(CLOCK_MONOTONIC, &now);
  return( ((int64_t)now.tv_sec * 1000000000L) + now.tv_nsec );  
}

unsigned long long time_cxx() {
  return std::chrono::duration_cast<std::chrono::nanoseconds>(
    std::chrono::steady_clock::now().time_since_epoch()).count();
}

int main() {
  printf("%llu\n", time_posix());
  printf("%llu\n", time_cxx());
}

time_posix and time_cxx output roughly the same value.

NDK Version: r16b
Build system: ndk-build
Host OS: Linux
Compiler: Clang (w/ APP_CPPFLAGS := -std=c++11)
ABI: armeabi-v7a
STL: c++_static
NDK API level: 21
Device API level: 26

@DanAlbert
Copy link
Member

Closing since we couldn't repro. Will reopen if we get a failing test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants