Linux“jiffies”的物理地址多变的
我想获取Linux“jiffies”变量的物理地址,以便我可以通过读取该内存地址的内容来读取它。
I would like to get the physical address of Linux "jiffies" variable so that I can read it by just reading the contents of this memory address.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在内核模式代码(例如可加载内核模块)中,您需要包含
头文件。它包含jiffies
变量的定义:但是,它还包含此警告:
即您不应直接访问此变量。它是一个 64 位变量,在 32 位系统上对其的访问不是原子的,因此来自同一头文件的
get_jiffies_64()
函数。在 64 位系统上,该函数是一个非常简单的内联函数,它返回 jiffies 变量的值。另一方面,从用户空间代码中,您根本无法访问内核内存。
From kernel-mode code (e.g. a loadable kernel module) you need to include the
<linux/jiffies.h>
header file. It contains the definition of thejiffies
variable:However, it also contains this warning:
I.e. you should not access this variable directly. It's a 64-bit variable and accesses to it are not atomic on 32-bit systems, hence the
get_jiffies_64()
function from the same header file. On 64-bit systems that function is a very simple inline function that returns the value of thejiffies
variable.From userspace code, on the other hand, you cannot access kernel memory at all.
对于内核代码,请使用
include/linux/jiffies.h
中定义的函数。 (例如get_jiffies_64
)。使用 Linux 系统调用的内核命令 说明了 Linux 中的系统调用处理使用读取 jiffies 的用户空间系统调用。可能就是你所追求的。
Linux 获取当前的 jiffies 自重启以来 在超级用户上也有一些信息您可能会感兴趣。
将 jiffies 转换为毫秒 也需要记住。
For kernel code, use the functions defined in
include/linux/jiffies.h
. (get_jiffies_64
for example).Kernel command using Linux system calls illustrates syscall handling in Linux with a userspace syscall that reads jiffies. Could be what you're after.
Linux obtain current of jiffies since reboot over at superuser also has some information you could be interested in.
Converting jiffies to milli seconds is also something to keep in mind.
这与您的问题没有直接关系,但可能仍然相关。
我在这里维护一个小项目(devmem-rw):
http://code.google.com/p/device-memory-readwrite/
对于驱动/内核开发/测试人员来说非常有用;它允许一个设置能够读取/写入任何有效内存位置 - 这可能是 RAM(用户/内核空间)、内存映射寄存器位置、共享内存区域等。
请参阅 wiki项目区域(具体来说,http://code.google.com/ p/device-memory-readwrite/wiki/UsageWithExamples)。
与您的问题更相关,我使用这个项目来演示一些用例,其中之一是重复读取“jiffies”值。看到它的变化证明了这一点。
来自 http://code.google .com/p/device-memory-readwrite/wiki/UsageWithExamples:
“...
例如。 2:在x86 PC上读取'jiffies'的值
前面提到的“vm_img”内核模块还向我们显示了“jiffies_64”内核全局变量(保存当前 jiffies 值)的位置;在上面的运行中,它的内核位置是0xc07c7a40。所以:
我们可以看到它是如何更新的...(事实上,该系统上的 CONFIG_HZ=250,并且还需要一些 + 因子...)。
...
“
请参阅项目页面了解详细信息。
人们发现它对于驱动程序开发人员非常有用 - 例如他们可以在不编写代码的情况下探测/更改寄存器值:)
一定要试一试!
This is not directly related to your question but might still be relevant.
I maintain a small project (devmem-rw) here:
http://code.google.com/p/device-memory-readwrite/
It's quite useful to driver/kernel developers/testers; it lets one setup to be able to read/write any valid memory location- this could be RAM (user/kernel space), memory-mapped register locations, shared memory regions, etc.
Pl see the wiki area of the project (specifically, http://code.google.com/p/device-memory-readwrite/wiki/UsageWithExamples).
More relevant to your question, I use this project to demo a few use cases, one of them being repeated reads on the 'jiffies' value. Seeing that it changes proves the point..
From http://code.google.com/p/device-memory-readwrite/wiki/UsageWithExamples :
"...
Eg. 2: Reading the value of 'jiffies' on an x86 PC
The 'vm_img' kernel module mentioned earlier, also shows us the location of the 'jiffies_64' kernel global variable (which holds the current jiffies value); in the above run, it's kernel location turns out to be 0xc07c7a40. So:
We can see how it's updated...(in fact, CONFIG_HZ=250 on this system, and some + factor is expected as well...).
...
"
Pl see the project page for details.
It's been found to be quite useful for driver developers- for eg they can probe/change register values without writing code :)
Do give it a spin!
如果您安装了源代码,
应该显示 .c 和 .h 文件,如下所示:
If you have the sources installed,
schould reveal the .c and .h files, as in:
当您从内核代码中引用
jiffies
时,就会发生这种情况。您认为在正常使用过程中有哪些需要改进的地方?如果您需要地址,只需使用&jiffies
。When you reference
jiffies
from kernel code, that's exactly what happens. What do you think needs improving in normal usage? If you need the address just use&jiffies
.我认为你想要的是从用户空间访问 jiffies 值。
您可以编写一个小模块,将 jiffies 变量公开给 proc 文件。
I think what you want is to access jiffies values from userspace.
You can write a small module that expose the
jiffies
variable to a proc file.