2024-01-04 19:52:08 +08:00
|
|
|
/* Copyright (C) 2021-2024 Free Software Foundation, Inc.
|
2022-03-11 16:58:31 +08:00
|
|
|
Contributed by Oracle.
|
|
|
|
|
|
|
|
This file is part of GNU Binutils.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, 51 Franklin Street - Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA. */
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include <time.h>
|
|
|
|
#include "gp-time.h"
|
|
|
|
|
2022-03-15 23:21:56 +08:00
|
|
|
/* CLOCK_MONOTONIC
|
|
|
|
Clock that cannot be set and represents monotonic time since some
|
|
|
|
unspecified starting point. */
|
|
|
|
|
2022-03-11 16:58:31 +08:00
|
|
|
static hrtime_t
|
2022-03-15 23:21:56 +08:00
|
|
|
linux_gethrtime (void)
|
2022-03-11 16:58:31 +08:00
|
|
|
{
|
|
|
|
struct timespec tp;
|
|
|
|
hrtime_t rc = 0;
|
2022-03-15 23:21:56 +08:00
|
|
|
|
|
|
|
#ifdef CLOCK_MONOTONIC_RAW
|
2022-03-11 16:58:31 +08:00
|
|
|
int r = clock_gettime (CLOCK_MONOTONIC_RAW, &tp);
|
2022-03-15 23:21:56 +08:00
|
|
|
#else
|
|
|
|
int r = clock_gettime (CLOCK_MONOTONIC, &tp);
|
|
|
|
#endif
|
|
|
|
|
2022-03-11 16:58:31 +08:00
|
|
|
if (r == 0)
|
|
|
|
rc = ((hrtime_t) tp.tv_sec)*1000000000 + (hrtime_t) tp.tv_nsec;
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
hrtime_t (*__collector_gethrtime)() = linux_gethrtime;
|