Kernel: Remove get_unix_timestamp from SystemTimer

Kernel now uses the percise real_time() and time_since_boot()
This commit is contained in:
Bananymous 2023-08-09 08:57:50 +03:00
parent 008c777a9f
commit e74fdbc55b
6 changed files with 26 additions and 33 deletions

View File

@ -25,10 +25,9 @@ namespace Kernel
virtual uint64_t ms_since_boot() const override; virtual uint64_t ms_since_boot() const override;
virtual timespec time_since_boot() const override; virtual timespec time_since_boot() const override;
void sleep(uint64_t) const; void sleep(uint64_t ms) const;
uint64_t get_unix_timestamp() const; timespec real_time() const;
timespec get_real_time() const;
private: private:
SystemTimer() = default; SystemTimer() = default;

View File

@ -384,16 +384,16 @@ namespace Kernel
if (error_or.error().get_error_code() != ENOENT) if (error_or.error().get_error_code() != ENOENT)
return error_or.error(); return error_or.error();
uint64_t current_time = SystemTimer::get().get_unix_timestamp(); timespec current_time = SystemTimer::get().real_time();
Ext2::Inode ext2_inode; Ext2::Inode ext2_inode;
ext2_inode.mode = mode; ext2_inode.mode = mode;
ext2_inode.uid = uid; ext2_inode.uid = uid;
ext2_inode.size = 0; ext2_inode.size = 0;
ext2_inode.atime = current_time; ext2_inode.atime = current_time.tv_sec;
ext2_inode.ctime = current_time; ext2_inode.ctime = current_time.tv_sec;
ext2_inode.mtime = current_time; ext2_inode.mtime = current_time.tv_sec;
ext2_inode.dtime = current_time; ext2_inode.dtime = current_time.tv_sec;
ext2_inode.gid = gid; ext2_inode.gid = gid;
ext2_inode.links_count = 1; ext2_inode.links_count = 1;
ext2_inode.blocks = 0; ext2_inode.blocks = 0;

View File

@ -17,10 +17,10 @@ namespace Kernel
: m_uid(credentials.euid()) : m_uid(credentials.euid())
, m_gid(credentials.egid()) , m_gid(credentials.egid())
{ {
uint64_t current_time = SystemTimer::get().get_unix_timestamp(); timespec current_time = SystemTimer::get().real_time();
m_atime = { .tv_sec = current_time, .tv_nsec = 0 }; m_atime = current_time;
m_mtime = { .tv_sec = current_time, .tv_nsec = 0 }; m_mtime = current_time;
m_ctime = { .tv_sec = current_time, .tv_nsec = 0 }; m_ctime = current_time;
} }
void Pipe::clone_writing() void Pipe::clone_writing()
@ -57,8 +57,7 @@ namespace Kernel
memmove(m_buffer.data(), m_buffer.data() + to_copy, m_buffer.size() - to_copy); memmove(m_buffer.data(), m_buffer.data() + to_copy, m_buffer.size() - to_copy);
MUST(m_buffer.resize(m_buffer.size() - to_copy)); MUST(m_buffer.resize(m_buffer.size() - to_copy));
uint64_t current_time = SystemTimer::get().get_unix_timestamp(); m_atime = SystemTimer::get().real_time();
m_atime = { .tv_sec = current_time, .tv_nsec = 0 };
m_semaphore.unblock(); m_semaphore.unblock();
@ -76,9 +75,9 @@ namespace Kernel
TRY(m_buffer.resize(old_size + count)); TRY(m_buffer.resize(old_size + count));
memcpy(m_buffer.data() + old_size, buffer, count); memcpy(m_buffer.data() + old_size, buffer, count);
uint64_t current_time = SystemTimer::get().get_unix_timestamp(); timespec current_time = SystemTimer::get().real_time();
m_mtime = { .tv_sec = current_time, .tv_nsec = 0 }; m_mtime = current_time;
m_ctime = { .tv_sec = current_time, .tv_nsec = 0 }; m_ctime = current_time;
m_semaphore.unblock(); m_semaphore.unblock();

View File

@ -23,10 +23,7 @@ namespace Kernel
RamInode::RamInode(RamFileSystem& fs, mode_t mode, uid_t uid, gid_t gid) RamInode::RamInode(RamFileSystem& fs, mode_t mode, uid_t uid, gid_t gid)
: m_fs(fs) : m_fs(fs)
{ {
uint64_t current_unix_time = SystemTimer::get().get_unix_timestamp(); timespec current_time = SystemTimer::get().real_time();
timespec current_timespec;
current_timespec.tv_sec = current_unix_time;
current_timespec.tv_nsec = 0;
m_inode_info.ino = fs.next_ino(); m_inode_info.ino = fs.next_ino();
m_inode_info.mode = mode; m_inode_info.mode = mode;
@ -34,9 +31,9 @@ namespace Kernel
m_inode_info.uid = uid; m_inode_info.uid = uid;
m_inode_info.gid = gid; m_inode_info.gid = gid;
m_inode_info.size = 0; m_inode_info.size = 0;
m_inode_info.atime = current_timespec; m_inode_info.atime = current_time;
m_inode_info.mtime = current_timespec; m_inode_info.mtime = current_time;
m_inode_info.ctime = current_timespec; m_inode_info.ctime = current_time;
m_inode_info.blksize = fs.blksize(); m_inode_info.blksize = fs.blksize();
m_inode_info.blocks = 0; m_inode_info.blocks = 0;
m_inode_info.dev = 0; m_inode_info.dev = 0;

View File

@ -811,9 +811,12 @@ namespace Kernel
{ {
case CLOCK_MONOTONIC: case CLOCK_MONOTONIC:
{ {
uint64_t time_ms = SystemTimer::get().ms_since_boot(); *tp = SystemTimer::get().time_since_boot();
tp->tv_sec = time_ms / 1000; break;
tp->tv_nsec = (time_ms % 1000) * 1000000; }
case CLOCK_REALTIME:
{
*tp = SystemTimer::get().real_time();
break; break;
} }
default: default:

View File

@ -74,12 +74,7 @@ namespace Kernel
dwarnln("sleep woke {} ms too soon", wake_time - ms_since_boot()); dwarnln("sleep woke {} ms too soon", wake_time - ms_since_boot());
} }
uint64_t SystemTimer::get_unix_timestamp() const timespec SystemTimer::real_time() const
{
return m_boot_time + ms_since_boot() / 1000;
}
timespec SystemTimer::get_real_time() const
{ {
auto result = time_since_boot(); auto result = time_since_boot();
result.tv_sec += m_boot_time; result.tv_sec += m_boot_time;