-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace mtime counter with realtime timer
Replace 'mtime' counter by retrieving time of the specified clock ID. Additionally, a Real-Time counter (RTC) mechanism is implemented to prevent 'mtime' overflow. By changing 'mtime' to use the retrieved timer, real timestamps are visible in the booting log due to 'CONFIG_PRINTK_TIME' being enable by default. However, SEMU experiences a slowdown as the number of simulated harts increases. This is due to the increased number of timer interrupts and 'clock_gettime' system calls in this commit. Another issue addressed is RCU CPU stall warning[1], which occurs when the system waits more than a grace period (typically 21 seconds). [1]: https://docs.kernel.org/RCU/stallwarn.html
- Loading branch information
Showing
10 changed files
with
89 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#include <time.h> | ||
|
||
#include "utils.h" | ||
|
||
#if defined(__APPLE__) | ||
#define HAVE_MACH_TIMER | ||
#include <mach/mach_time.h> | ||
#elif !defined(_WIN32) && !defined(_WIN64) | ||
#define HAVE_POSIX_TIMER | ||
#ifdef CLOCK_MONOTONIC | ||
#define CLOCKID CLOCK_MONOTONIC | ||
#else | ||
#define CLOCKID CLOCK_REALTIME | ||
#endif | ||
#endif | ||
|
||
void semu_timer_init(semu_timer_t *timer, uint64_t freq) | ||
{ | ||
timer->freq = freq; | ||
semu_timer_rebase(timer, 0); | ||
} | ||
|
||
static uint64_t semu_timer_clocksource(uint64_t freq) | ||
{ | ||
#if defined(HAVE_POSIX_TIMER) | ||
struct timespec t; | ||
clock_gettime(CLOCKID, &t); | ||
return (t.tv_sec * freq) + (t.tv_nsec * freq / 1e9); | ||
#elif defined(HAVE_MACH_TIMER) | ||
static mach_timebase_info_data_t t; | ||
if (mach_clk.denom == 0) | ||
(void) mach_timebase_info(&t); | ||
return mach_absolute_time() * freq / t.denom * t.numer; | ||
#else | ||
return time(0) * freq; | ||
#endif | ||
} | ||
|
||
uint64_t semu_timer_gettime(semu_timer_t *timer) | ||
{ | ||
return semu_timer_clocksource(timer->freq) - timer->begin; | ||
} | ||
|
||
void semu_timer_rebase(semu_timer_t *timer, uint64_t time) | ||
{ | ||
timer->begin = semu_timer_clocksource(timer->freq) - time; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
|
||
/* TIMER */ | ||
typedef struct { | ||
uint64_t begin; | ||
uint64_t freq; | ||
} semu_timer_t; | ||
|
||
void semu_timer_init(semu_timer_t *timer, uint64_t freq); | ||
uint64_t semu_timer_gettime(semu_timer_t *timer); | ||
void semu_timer_rebase(semu_timer_t *timer, uint64_t time); |