summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrcitach <[email protected]>2026-04-21 10:11:50 +0000
committerBernard Xiong <[email protected]>2026-04-30 06:19:58 +0800
commit3b5d4342c0cb8c66dc9fc5af398ba596d3d4902c (patch)
tree9fcc0c9239907674e37387a9d4d89695593b174e
parentc92480894c97378cecb492086404b2a0c2bebc07 (diff)
解决 base_time 和 counter_last 采样不同步产生固定偏差
-rw-r--r--components/lwp/arch/common/vdso_kernel.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/components/lwp/arch/common/vdso_kernel.c b/components/lwp/arch/common/vdso_kernel.c
index 61a20fc4c9..c831c94d8d 100644
--- a/components/lwp/arch/common/vdso_kernel.c
+++ b/components/lwp/arch/common/vdso_kernel.c
@@ -90,6 +90,16 @@ static void rt_vdso_normalize_timespec(struct timespec *ts)
}
}
+static void rt_vdso_counter_to_timespec(rt_uint64_t counter_value,
+ struct timespec *ts)
+{
+ rt_uint64_t monotonic_ns;
+
+ monotonic_ns = rt_clock_time_counter_to_ns(counter_value);
+ ts->tv_sec = monotonic_ns / RT_VDSO_NSEC_PER_SEC;
+ ts->tv_nsec = monotonic_ns % RT_VDSO_NSEC_PER_SEC;
+}
+
static struct timespec rt_vdso_add_timespec(const struct timespec *lhs,
const struct timespec *rhs)
{
@@ -106,13 +116,14 @@ static int rt_vdso_read_monotonic_snapshot(struct timespec *monotonic_time,
rt_uint64_t *counter_value,
rt_uint64_t *counter_freq)
{
- if (rt_clock_boottime_get_ns(monotonic_time) != RT_EOK)
+ *counter_value = rt_clock_time_get_counter();
+ *counter_freq = rt_clock_time_get_freq();
+ if (*counter_freq == 0)
{
return -RT_ERROR;
}
- *counter_value = rt_clock_time_get_counter();
- *counter_freq = rt_clock_time_get_freq();
+ rt_vdso_counter_to_timespec(*counter_value, monotonic_time);
return RT_EOK;
}