mirror of
https://github.com/RGBCube/serenity
synced 2025-05-21 15:25:07 +00:00

This patch adds a vDSO-like mechanism for exposing the current time as an array of per-clock-source timestamps. LibC's clock_gettime() calls sys$map_time_page() to map the kernel's "time page" into the process address space (at a random address, ofc.) This is only done on first call, and from then on the timestamps are fetched from the time page. This first patch only adds support for CLOCK_REALTIME, but eventually we should be able to support all clock sources this way and get rid of sys$clock_gettime() in the kernel entirely. :^) Accesses are synchronized using two atomic integers that are incremented at the start and finish of the kernel's time page update cycle.
30 lines
468 B
C++
30 lines
468 B
C++
/*
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Types.h>
|
|
|
|
#ifdef KERNEL
|
|
# include <Kernel/UnixTypes.h>
|
|
#else
|
|
# include <time.h>
|
|
#endif
|
|
|
|
namespace Kernel {
|
|
|
|
inline bool time_page_supports(clockid_t clock_id)
|
|
{
|
|
return clock_id == CLOCK_REALTIME;
|
|
}
|
|
|
|
struct TimePage {
|
|
volatile u32 update1;
|
|
struct timespec clocks[CLOCK_ID_COUNT];
|
|
volatile u32 update2;
|
|
};
|
|
|
|
}
|