LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 02-18-2013, 06:29 AM   #1
Florian.Cerny
LQ Newbie
 
Registered: Feb 2013
Posts: 2

Rep: Reputation: Disabled
Question Read temp sensors values in proc-file


Hell,

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?

Best regards

Flo
 
Old 02-18-2013, 01:05 PM   #2
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,671
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
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.
 
1 members found this post helpful.
Old 02-18-2013, 01:27 PM   #3
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.

--- rod.
 
Old 02-18-2013, 06:34 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,671
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
Quote:
Originally Posted by theNbomr View Post
\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."
 
Old 02-19-2013, 02:50 AM   #5
Florian.Cerny
LQ Newbie
 
Registered: Feb 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks for your responses.

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):

Code:
Sched Debug Version: v0.10, 3.7.3 #23


cpu#0 
Freq: 1800.006 MHz
Temp_input: XX
Temp_critical: XX

runnable: tasks:
            task   PID         tree-key  switches  prio     exec-runtime         sum-exec        sum-sleep
----------------------------------------------------------------------------------------------------------
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,...

Now I tried another possibility:

Code:
static void read_file(char *filename)
{
  int fd;
  char buf[1];

  mm_segment_t old_fs = get_fs();
  set_fs(KERNEL_DS);

  fd = sys_open(filename, O_RDONLY, 0);
  if (fd >= 0) {
    printk(KERN_DEBUG);
    while (sys_read(fd, buf, 1) == 1)
      printk("%c", buf[0]);
    printk("\n");
    sys_close(fd);
  }
  set_fs(old_fs);
}
Without any output.

The file I want to read is located here:
/sys/class/hwmon/hwmon1/device/tempX_input ( X = 2 or 3, depending with temp sensor)

Hopefully these are more information for you. Thanks in advance for your thoughts and help.

Best regards

Flo
 
Old 02-19-2013, 08:29 AM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
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.

--- rod.
 
Old 02-19-2013, 05:27 PM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,671
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
You shouldn't be attempting to read /proc entries from kernel space. Why are you attempting to do this "from kernel space?"
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Read in values from a file khandu Programming 8 01-12-2012 12:00 AM
Which one is CPU temp in lm-sensors dreamlemon Debian 4 06-27-2010 01:34 PM
Temp sensors and readings on slack 10.2 need help please Old_Fogie Slackware 25 07-10-2006 04:18 AM
Sensors - cpu temp, etc - Write this rc* file, which one? xodustrance Linux - Software 2 04-25-2004 08:30 PM
linxu temp monitor/sensors k3v0 Linux - Software 1 11-29-2002 11:01 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 01:05 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration