Blog Code Forum

CoreMod

From Wiki.cyring.fr

(Difference between revisions)
Jump to: navigation, search
 
(19 intermediate revisions not shown)
Line 14: Line 14:
<br />
<br />
==== Compiling ====
==== Compiling ====
-
<syntaxhighlight lang="c">
+
<syntaxhighlight lang="bash">
-
$ gcc coremod.c -o coremod
+
$ make
-
</syntaxhighlight>
+
-
- or -
+
-
<syntaxhighlight lang="c">
+
-
$ clang coremod.c -o coremod
+
</syntaxhighlight>
</syntaxhighlight>
 +
<pre>
 +
Compiling : Done.
 +
Linking  : Done.
 +
Ready    : ./bin/coremod
 +
Remark    : You must be root to run CoreMod
 +
</pre>
<br />
<br />
 +
==== Debugging ====
==== Debugging ====
-
First of all, compile sources with the -g switch then launch the debugger<br />
+
First of all, compile sources with the -g switch enabled, if not already, in the Makefile's CFLAGS, then launch the debugger<br />
<syntaxhighlight lang="c">
<syntaxhighlight lang="c">
-
$ kdesu ddd ./coremod
+
$ kdesu ddd ./bin/coremod
</syntaxhighlight>
</syntaxhighlight>
<br />
<br />
 +
==== Usage ====
==== Usage ====
Two kernel modules must be loaded
Two kernel modules must be loaded
Line 38: Line 42:
</syntaxhighlight>
</syntaxhighlight>
<br />
<br />
 +
http://blog.cyring.fr/wp-content/uploads/2012/07/CyrIng_coremod_screen12.jpg
 +
<br /><br />
Usage is straightforward. Just enter the corresponding initial character to the function you want to execute.
Usage is straightforward. Just enter the corresponding initial character to the function you want to execute.
 +
<br />
Thus to show the core temperature, press the following keys:<br />
Thus to show the core temperature, press the following keys:<br />
* [s]
* [s]
Line 44: Line 51:
* [c]
* [c]
* [Enter]
* [Enter]
-
And for instance to go back to previous menu level:<br />
+
and for instance, to go back to previous menu level:<br />
* [<]
* [<]
* [Enter]
* [Enter]
<br />
<br />
Discover the other functions to dump your components !
Discover the other functions to dump your components !
 +
<br /><br />
 +
http://blog.cyring.fr/wp-content/uploads/2012/07/CyrIng_coremod_screen17.jpg
 +
<br />
<br />
<br />
-
==== Contact ====
 
-
=== Releases ===
 
-
==== Release 2012-0.1.2 ====
 
-
===== coremod.h =====
 
-
===== coremod.c =====
 
-
==== Release 2012-0.1.1 ====
 
-
===== coremod.c =====
 
-
<syntaxhighlight lang="c" line start="1">
 
-
// coremod.c - CyrIng 2012
 
-
#include <stdio.h>
+
=== Contact ===
-
#include <stdlib.h>
+
Feel free to [http://blog.cyring.fr/about/?lang=en contact] us for any suggestion or question.
-
#include <unistd.h>
+
<br />
-
#include <sys/stat.h>
+
<br />
-
#include <fcntl.h>
+
-
// Intel® 64 and IA-32 Architectures Software Developer’s Manual
+
=== Versions ===
-
// Vol. 3C § 34-1
+
===== Nightly Build =====
-
// Table 34-2. IA-32 Architectural MSRs
+
:[http://code.cyring.fr/FTS/?PATH=Source/C/CoreMod/Nightly_Build/Latest Latest]
-
#define IA32_PERF_STATUS 0x198
+
===== Release 2012-0.1.4 =====
-
 
+
:[http://code.cyring.fr/FTS/?PATH=Source/C/CoreMod/Previous_Build/2012-0.1.4 2012-0.1.4]
-
// System Management BIOS (SMBIOS) Reference Specification
+
===== Release 2012-0.1.3 =====
-
// Version: 2.7.1 § 7.5
+
:[http://code.cyring.fr/FTS/?PATH=Source/C/CoreMod/Previous_Build/2012-0.1.3 2012-0.1.3]
-
// Table 20 – Processor Information (Type 4) Structure
+
===== Release 2012-0.1.2 =====
-
 
+
:[http://code.cyring.fr/FTS/?PATH=Source/C/CoreMod/Previous_Build/2012-0.1.2 2012-0.1.2]
-
#define SMBIOS_PROCINFO_STRUCTURE 4
+
===== Release 2012-0.1.1 =====
-
#define SMBIOS_PROCINFO_INSTANCE 0
+
:[http://code.cyring.fr/FTS/?PATH=Source/C/CoreMod/Previous_Build/2012-0.1.1 2012-0.1.1]
-
#define SMBIOS_PROCINFO_EXTCLK 0x12
+
-
 
+
-
 
+
-
int Read_MSR(int cpu, off_t offset, unsigned long long *msr) {
+
-
ssize_t retval=0;
+
-
char pathname[32]="";
+
-
int fd=0, rc=-1;
+
-
 
+
-
sprintf(pathname, "/dev/cpu/%d/msr", cpu);
+
-
if( (fd=open(pathname, O_RDONLY)) != -1 ) {
+
-
retval=pread(fd, msr, sizeof *msr, offset);
+
-
close(fd);
+
-
rc=(retval != sizeof *msr) ? -1 : 0;
+
-
}
+
-
return(rc);
+
-
}
+
-
 
+
-
int Read_SMBIOS(int structure, int instance, off_t offset, void *buf, size_t nbyte) {
+
-
ssize_t retval=0;
+
-
char pathname[]="/sys/firmware/dmi/entries/999-99/raw";
+
-
int fd=0, rc=-1;
+
-
 
+
-
sprintf(pathname, "/sys/firmware/dmi/entries/%d-%d/raw", structure, instance);
+
-
if( (fd=open(pathname, O_RDONLY)) != -1 ) {
+
-
retval=pread(fd, buf, nbyte, offset);
+
-
close(fd);
+
-
rc=(retval != nbyte) ? -1 : 0;
+
-
}
+
-
return(rc);
+
-
}
+
-
 
+
-
int Get_Ratio(int target) {
+
-
unsigned long long msr=0;
+
-
 
+
-
if( Read_MSR(target, IA32_PERF_STATUS, &msr) != -1)
+
-
return((int) msr);
+
-
else
+
-
return(0);
+
-
}
+
-
 
+
-
int External_Clock() {
+
-
int clock=0;
+
-
+
-
if( Read_SMBIOS(SMBIOS_PROCINFO_STRUCTURE, SMBIOS_PROCINFO_INSTANCE, SMBIOS_PROCINFO_EXTCLK, &clock, 1) != -1)
+
-
return(clock);
+
-
else
+
-
return(0);
+
-
}
+
-
 
+
-
int main(int argc, char *argv[]) {
+
-
int target=0, first=0, last=0, clock=0, ratio=0, rc=0;
+
-
+
-
switch(argc) {
+
-
  case 2: first = atoi(argv[1]);
+
-
last  = first;
+
-
  break;
+
-
  case 3: first = atoi(argv[1]);
+
-
last  = atoi(argv[2]);
+
-
  break;
+
-
}
+
-
if((clock=External_Clock())!=0)
+
-
  for(target=first; target<=last && (ratio=Get_Ratio(target)) != 0; target++)
+
-
printf("Processor#%d : Ratio[%d] x Clock[%d] = %d Mhz\n", target, ratio, clock, ratio*clock);
+
-
else
+
-
rc=-1;
+
-
return(rc);
+
-
}
+
-
</syntaxhighlight>
+

Latest revision as of 10:04, 19 November 2012

Contents

How To

Requirements

Mandatory,

  • The GNU/Linux x86_64 3.x : linux
  • The GNU Compiler Collection: gcc - or - The C language family frontend for LLVM: clang
  • Being root !
  • The Intel(R) Core(TM) i7, i5 Processors


Optionally,


Compiling

$ make
Compiling : Done.
Linking   : Done.
Ready     : ./bin/coremod
Remark    : You must be root to run CoreMod


Debugging

First of all, compile sources with the -g switch enabled, if not already, in the Makefile's CFLAGS, then launch the debugger

$ kdesu ddd ./bin/coremod


Usage

Two kernel modules must be loaded

  1. msr
  2. dmi-sysfs


Execute CoreMod as root

# ./coremod


CyrIng_coremod_screen12.jpg

Usage is straightforward. Just enter the corresponding initial character to the function you want to execute.
Thus to show the core temperature, press the following keys:

  • [s]
  • [Enter]
  • [c]
  • [Enter]

and for instance, to go back to previous menu level:

  • [<]
  • [Enter]


Discover the other functions to dump your components !

CyrIng_coremod_screen17.jpg

Contact

Feel free to contact us for any suggestion or question.

Versions

Nightly Build
Latest
Release 2012-0.1.4
2012-0.1.4
Release 2012-0.1.3
2012-0.1.3
Release 2012-0.1.2
2012-0.1.2
Release 2012-0.1.1
2012-0.1.1
Personal tools