Repository: dotnet/runtime
File: src/native/minipal/time.c (C)

Code before:
#elif defined(HOST_LOONGARCH64)
    __asm__ volatile( "dbar 0;  \n");
#elif defined(HOST_RISCV64)
    // TODO-RISCV64-CQ: When Zihintpause is supported, replace with `pause` instruction.
    __asm__ __volatile__(".word 0x0100000f");
#else
    return;
#endif
}

#define tccSecondsToNanoSeconds 1000000000      // 10^9
#define tccSecondsToMilliSeconds 1000           // 10^3
#define tccMilliSecondsToNanoSeconds 1000000    // 10^6
#define tccSecondsTo100NS 10000000              // 10^7
int64_t minipal_hires_tick_frequency(void)
{
    return tccSecondsToNanoSeconds;
}

int64_t minipal_hires_ticks(void)
{
#if HAVE_CLOCK_GETTIME_NSEC_NP
    return (int64_t)clock_gettime_nsec_np(CLOCK_UPTIME_RAW);
#else
    struct timespec ts;
    int result = clock_gettime(CLOCK_MONOTONIC, &ts);
    assert(result == 0 && "clock_gettime(CLOCK_MONOTONIC) failed");

    return ((int64_t)(ts.tv_sec) * (int64_t)(tccSecondsToNanoSeconds)) + (int64_t)(ts.tv_nsec);
#endif
}

int64_t minipal_lowres_ticks(void)
{
#if HAVE_CLOCK_GETTIME_NSEC_NP
    return  (int64_t)clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / (int64_t)(tccMilliSecondsToNanoSeconds);
#else
    struct timespec ts;

    // emscripten exposes CLOCK_MONOTONIC_COARSE but doesn't implement it
#if HAVE_CLOCK_MONOTONIC_COARSE && !defined(__EMSCRIPTEN__)
    // CLOCK_MONOTONIC_COARSE has enough precision for GetTickCount but
    // doesn't have the same overhead as CLOCK_MONOTONIC. This allows
    // overall higher throughput. See dotnet/coreclr#2257 for more details.

    const clockid_t clockType = CLOCK_MONOTONIC_COARSE;
#else
    const clockid_t clockType = CLOCK_MONOTONIC;
#endif

    int result = clock_gettime(clockType, &ts);

Review comment (suggestion):
```suggestion
    int result;
    result = clock_gettime(CLOCK_MONOTONIC, &ts);
```

Code after:
#elif defined(HOST_LOONGARCH64)
    __asm__ volatile( "dbar 0;  \n");
#elif defined(HOST_RISCV64)
    // TODO-RISCV64-CQ: When Zihintpause is supported, replace with `pause` instruction.
    __asm__ __volatile__(".word 0x0100000f");
#else
    return;
#endif
}

#define tccSecondsToNanoSeconds 1000000000      // 10^9
#define tccSecondsToMilliSeconds 1000           // 10^3
#define tccMilliSecondsToNanoSeconds 1000000    // 10^6
#define tccSecondsTo100NS 10000000              // 10^7
int64_t minipal_hires_tick_frequency(void)
{
    return tccSecondsToNanoSeconds;
}

int64_t minipal_hires_ticks(void)
{
#if HAVE_CLOCK_GETTIME_NSEC_NP
    return (int64_t)clock_gettime_nsec_np(CLOCK_UPTIME_RAW);
#else
    struct timespec ts;
    int result;
    result = clock_gettime(CLOCK_MONOTONIC, &ts);
    assert(result == 0 && "clock_gettime(CLOCK_MONOTONIC) failed");

    return ((int64_t)(ts.tv_sec) * (int64_t)(tccSecondsToNanoSeconds)) + (int64_t)(ts.tv_nsec);
#endif
}

int64_t minipal_lowres_ticks(void)
{
#if HAVE_CLOCK_GETTIME_NSEC_NP
    return  (int64_t)clock_gettime_nsec_np(CLOCK_UPTIME_RAW) / (int64_t)(tccMilliSecondsToNanoSeconds);
#else
    struct timespec ts;

    // emscripten exposes CLOCK_MONOTONIC_COARSE but doesn't implement it
#if HAVE_CLOCK_MONOTONIC_COARSE && !defined(__EMSCRIPTEN__)
    // CLOCK_MONOTONIC_COARSE has enough precision for GetTickCount but
    // doesn't have the same overhead as CLOCK_MONOTONIC. This allows
    // overall higher throughput. See dotnet/coreclr#2257 for more details.

    const clockid_t clockType = CLOCK_MONOTONIC_COARSE;
#else
    const clockid_t clockType = CLOCK_MONOTONIC;
#endif