Linux - KernelThis forum is for all discussion relating to the Linux kernel.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to read the temp values from each core to build a thermal scheduler. For this reason I must know how do I read the temp values from the temp-sonsors/driver. tempX_Input has the value from the required core. I can read them in console, but how can I read them in my c-files? Does anyone have a glue?
Please provide more details. Do you right now have a kernel driver available to you that will present the necessary sensor-values as a pseudo-subdirectory of pseudo-files in the /proc directory?
If the answer is "yes," then the solution to your problem is very simple: just open the "file" and read from it, then close it. fopen..fread..fclose. (You can also keep it open and "seek" back to the beginning of the thing, but since the file is actually imaginary, it really won't make much difference.)
You can also find "C" examples for reading the contents of a "directory," to find out what "files" are inside of it, if your program needs to figure-out the names of the "files" that you need to open.
You can read the /proc pseudo filesystem in exactly the same way as you would read any real file. open()/read()/seek()/close() are the functions you will probably need to use. Since your intent seems to be some kind of logging system, you will need to establish some way of doing periodic reads. On each read you will need to seek() to the beginning of the file, and then read() the data. It is probably more overhead to close and re-open the file on each read, but if the interval between reads is long (I'll say seconds, at least, or tens of seconds), then perhaps closing and re-opening is not a big deal.
\It is probably more overhead to close and re-open the file on each read, but if the interval between reads is long (I'll say seconds, at least, or tens of seconds), then perhaps closing and re-opening is not a big deal.
--- rod.
... my thought in the above quote being that, "even though it's more overhead, it probably just won't matter." There are no physical delays involved here. Just "get 'er done."
Here are some more details. I'm using an Intel Desktop Board D525W with Intel Atom Processor. Linux 3.7.3 is used. Via "sensors" I can read the temp, voltage,... values for the 2 Core-System. The used driver to read the values are "w83627ehf/w83627dhg". With the command sched_debug(file "debug.c" in directory "kernel/sched/"), I can read witch task is running on witch core,... I minimized the output and there I want to add the information about the temp of each core. It looks like this(only the tempvalues are missing):
I already tried it with fopen, local with another project, it's no problem. But when compiling the kernel, it always throws errors. Including the stdio.h is throwing errors too. Can't find file,...
Oh, you didn't say you wanted to do this from kernel space. That's a whole different thing. You cannot use standard IO from the kernel. Perhaps a mod can move this to the kernel forum, or you can rephrase your question in a new thread there.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.