gpt4 book ai didi

c - Linux 内核 v5 中的 current_kernel_time 相当于什么?

转载 作者:行者123 更新时间:2023-12-02 22:28:15 27 4
gpt4 key购买 nike

我尝试在内核版本为 5.0.0-38-generic 的 Linux Ubuntu 19.04 机器上从 Pleora eBUS SDK 编译一些内核模块,但出现编译错误:

error: implicit declaration of function ‘current_kernel_time’; did you mean ‘core_kernel_text’? [-Werror=implicit-function-declaration]
lTime = current_kernel_time();

还有一个函数do_gettimeofday(同样的问题)。

我注意到 current_kernel_timecurrent_kernel_time64 在内核 v4.15 中仍然可用(例如我的另一台装有 Ubuntu 18.04 的机器使用的),最后一次出现在 linux v4.19.97 中。 。在 time.h我的内核版本的 header 有一个函数 get_timespec64 ,它似乎做了类似的事情,但是它接受 2 个参数,对我来说似乎不正确(因为在源代码中我看到有一个 copy_from_user 调用)以传递一些未初始化的 const struct __kernel_timespec __user *uts 作为第二个参数。有人可以给我一些提示,如何在我的新内核版本中替换对 current_kernel_time 的调用吗?

需要修改的示例代码:

OS_UINT64 OS_TimeGetUS( OS_VOID )
{
struct timespec64 lTime;
lTime = current_kernel_time();
return ( lTime.tv_sec * 1000000 + OS_DIV64( lTime.tv_nsec, 1000 ) );
}

最佳答案

current_kernel_time() 函数已被弃用并移至 timekeeping32.h在 v4.15 ( commit ) 中,然后在 v4.20 ( commit ) 中完全删除。 v4.18 ( commit ) 中引入了更新的计时功能。

新的导出函数为 ( source ):

extern void ktime_get_raw_ts64(struct timespec64 *ts);
extern void ktime_get_ts64(struct timespec64 *ts);
extern void ktime_get_real_ts64(struct timespec64 *tv);
extern void ktime_get_coarse_ts64(struct timespec64 *ts);
extern void ktime_get_coarse_real_ts64(struct timespec64 *ts);

另请参阅the relevant kernel documentation page ,其中指出:

Deprecated time interfaces

[...]

struct timespec current_kernel_time(void)
struct timespec64 current_kernel_time64(void)
struct timespec get_monotonic_coarse(void)
struct timespec64 get_monotonic_coarse64(void)

These are replaced by ktime_get_coarse_real_ts64() and ktime_get_coarse_ts64(). However, A lot of code that wants coarse-grained times can use the simple ‘jiffies’ instead, while some drivers may actually want the higher resolution accessors these days.

<小时/>

您可以将代码重写为:

OS_UINT64 OS_TimeGetUS( OS_VOID )
{
struct timespec64 lTime;
ktime_get_coarse_real_ts64(&lTime);
return (lTime.tv_sec * 1000000 + OS_DIV64( lTime.tv_nsec, 1000 ) );
}

但是我看到您返回的时间以微秒为单位。在这种情况下,您可能想直接使用 ktime_t ktime_get(void)或同等的 u64 ktime_get_ns(void) 。您提供的代码片段可以重写为:

OS_UINT64 OS_TimeGetUS( OS_VOID )
{
return OS_DIV64(ktime_get_ns(), 1000);
}

关于c - Linux 内核 v5 中的 current_kernel_time 相当于什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59828144/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com