summaryrefslogtreecommitdiff
path: root/libhw/host_bootclock.c
blob: ca9565c9efa75498ff34a16ec750ca84cc65f17a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* libhw/host_bootclock.c - <libhw/generic/bootclock.h> implementation for POSIX hosts
 *
 * Copyright (C) 2024  Luke T. Shumaker <lukeshu@lukeshu.com>
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */

#include <assert.h>
#include <time.h> /* for clock_gettime(), CLOCK_MONOTONIC, struct timespec */

#include <libhw/generic/bootclock.h>

uint64_t bootclock_get_ns(void) {
	struct timespec ts;
	int r;

	r = clock_gettime(CLOCK_MONOTONIC, &ts);
	assert(r == 0);

	return (((uint64_t)ts.tv_sec) * NS_PER_S) + (uint64_t)ts.tv_nsec;
}