aboutsummaryrefslogtreecommitdiff
path: root/kern/timer.c
diff options
context:
space:
mode:
authorFlavio Cruz <flaviocruz@gmail.com>2023-03-13 01:42:12 -0400
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2023-03-13 20:42:03 +0100
commit5ff6ff2707b7b482efc9e172c87bd5c4106d9ed4 (patch)
tree68abe2ad4b92c47deebb23bdcd54eb359d9921a9 /kern/timer.c
parentf72cc8c81afe03667cc1ee70169ed343a40f4578 (diff)
downloadgnumach-5ff6ff2707b7b482efc9e172c87bd5c4106d9ed4.tar.gz
gnumach-5ff6ff2707b7b482efc9e172c87bd5c4106d9ed4.tar.bz2
gnumach-5ff6ff2707b7b482efc9e172c87bd5c4106d9ed4.zip
Track task and thread time using time_value64_t.
Changed kern/timer.c to use the higher precision time_value64_t. Of course, this won't suffer from the 2038 overflow but it does provide nanosecond precision (if gnumach ever uses a better timer) and moves us closer to only having time_value64_t. Message-Id: <ZA63tGcv3bETUJFJ@jupiter.tail36e24.ts.net>
Diffstat (limited to 'kern/timer.c')
-rw-r--r--kern/timer.c82
1 files changed, 33 insertions, 49 deletions
diff --git a/kern/timer.c b/kern/timer.c
index 3b81ab79..7d029b7c 100644
--- a/kern/timer.c
+++ b/kern/timer.c
@@ -378,8 +378,13 @@ static void timer_grab(
} while ( (save)->high != (timer)->high_bits_check);
}
+#define TIMER_TO_TIME_VALUE64(tv, timer) do { \
+ (tv)->seconds = (timer)->high + (timer)->low / 1000000; \
+ (tv)->nanoseconds = (timer)->low % 1000000 * 1000; \
+} while(0);
+
/*
- * timer_read reads the value of a timer into a time_value_t. If the
+ * timer_read reads the value of a timer into a time_value64_t. If the
* timer was modified during the read, retry. The value returned
* is accurate to the last update; time accumulated by a running
* timer since its last timestamp is not included.
@@ -388,7 +393,7 @@ static void timer_grab(
void
timer_read(
timer_t timer,
- time_value_t *tv)
+ time_value64_t *tv)
{
timer_save_data_t temp;
@@ -399,9 +404,7 @@ timer_read(
#ifdef TIMER_ADJUST
TIMER_ADJUST(&temp);
#endif /* TIMER_ADJUST */
- tv->seconds = temp.high + temp.low/1000000;
- tv->microseconds = temp.low%1000000;
-
+ TIMER_TO_TIME_VALUE64(tv, &temp);
}
/*
@@ -414,29 +417,11 @@ timer_read(
*/
void thread_read_times(
thread_t thread,
- time_value_t *user_time_p,
- time_value_t *system_time_p)
+ time_value64_t *user_time_p,
+ time_value64_t *system_time_p)
{
- timer_save_data_t temp;
- timer_t timer;
-
- timer = &thread->user_timer;
- timer_grab(timer, &temp);
-
-#ifdef TIMER_ADJUST
- TIMER_ADJUST(&temp);
-#endif /* TIMER_ADJUST */
- user_time_p->seconds = temp.high + temp.low/1000000;
- user_time_p->microseconds = temp.low % 1000000;
-
- timer = &thread->system_timer;
- timer_grab(timer, &temp);
-
-#ifdef TIMER_ADJUST
- TIMER_ADJUST(&temp);
-#endif /* TIMER_ADJUST */
- system_time_p->seconds = temp.high + temp.low/1000000;
- system_time_p->microseconds = temp.low % 1000000;
+ timer_read(&thread->user_timer, user_time_p);
+ timer_read(&thread->system_timer, system_time_p);
}
#if MACH_DEBUG
@@ -458,6 +443,23 @@ static void db_timer_grab(
(save)->low = (timer)->low_bits;
}
+static void
+nonblocking_timer_read(
+ timer_t timer,
+ time_value64_t *tv)
+{
+ timer_save_data_t temp;
+
+ db_timer_grab(timer, &temp);
+ /*
+ * Normalize the result
+ */
+#ifdef TIMER_ADJUST
+ TIMER_ADJUST(&temp);
+#endif /* TIMER_ADJUST */
+ TIMER_TO_TIME_VALUE64(tv, &temp);
+}
+
/*
* Db_thread_read_times: A version of thread_read_times that
* can be called by the debugger. This version does not call
@@ -467,29 +469,11 @@ static void db_timer_grab(
*/
void db_thread_read_times(
thread_t thread,
- time_value_t *user_time_p,
- time_value_t *system_time_p)
+ time_value64_t *user_time_p,
+ time_value64_t *system_time_p)
{
- timer_save_data_t temp;
- timer_t timer;
-
- timer = &thread->user_timer;
- db_timer_grab(timer, &temp);
-
-#ifdef TIMER_ADJUST
- TIMER_ADJUST(&temp);
-#endif /* TIMER_ADJUST */
- user_time_p->seconds = temp.high + temp.low/1000000;
- user_time_p->microseconds = temp.low % 1000000;
-
- timer = &thread->system_timer;
- timer_grab(timer, &temp);
-
-#ifdef TIMER_ADJUST
- TIMER_ADJUST(&temp);
-#endif /* TIMER_ADJUST */
- system_time_p->seconds = temp.high + temp.low/1000000;
- system_time_p->microseconds = temp.low % 1000000;
+ nonblocking_timer_read(&thread->user_timer, user_time_p);
+ nonblocking_timer_read(&thread->system_timer, system_time_p);
}
#endif /* MACH_DEBUG */