Skip to content

Commit 30ae787

Browse files
committed
解决 base_time 和 counter_last 采样不同步产生固定偏差
1 parent 7b02345 commit 30ae787

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

components/lwp/arch/common/vdso_kernel.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ static void rt_vdso_normalize_timespec(struct timespec *ts)
9090
}
9191
}
9292

93+
static void rt_vdso_counter_to_timespec(rt_uint64_t counter_value,
94+
struct timespec *ts)
95+
{
96+
rt_uint64_t monotonic_ns;
97+
98+
monotonic_ns = rt_clock_time_counter_to_ns(counter_value);
99+
ts->tv_sec = monotonic_ns / RT_VDSO_NSEC_PER_SEC;
100+
ts->tv_nsec = monotonic_ns % RT_VDSO_NSEC_PER_SEC;
101+
}
102+
93103
static struct timespec rt_vdso_add_timespec(const struct timespec *lhs,
94104
const struct timespec *rhs)
95105
{
@@ -106,13 +116,14 @@ static int rt_vdso_read_monotonic_snapshot(struct timespec *monotonic_time,
106116
rt_uint64_t *counter_value,
107117
rt_uint64_t *counter_freq)
108118
{
109-
if (rt_clock_boottime_get_ns(monotonic_time) != RT_EOK)
119+
*counter_value = rt_clock_time_get_counter();
120+
*counter_freq = rt_clock_time_get_freq();
121+
if (*counter_freq == 0)
110122
{
111123
return -RT_ERROR;
112124
}
113125

114-
*counter_value = rt_clock_time_get_counter();
115-
*counter_freq = rt_clock_time_get_freq();
126+
rt_vdso_counter_to_timespec(*counter_value, monotonic_time);
116127

117128
return RT_EOK;
118129
}

0 commit comments

Comments
 (0)