Blog Code Forum

CoreMod

From Wiki.cyring.fr

(Difference between revisions)
Jump to: navigation, search
Line 1: Line 1:
-
===== Source file =====
+
=== How To ===
 +
==== Requirements ====
 +
Mandatory,
 +
* The GNU/Linux x86_64 3.x : [http://www.kernel.org/ linux]<br />
 +
* The GNU Compiler Collection: [http://gcc.gnu.org gcc] - or - The C language family frontend for LLVM: [http://clang.llvm.org/ clang]<br />
 +
* Being root !
 +
* The Intel(R) Core(TM) i7, i5 Processors<br />
 +
<br />
 +
Optionally,
 +
* The GNU Debugger: [http://www.gnu.org/software/gdb/ gdb]<br />
 +
* and a graphical front-end for gdb: [http://www.gnu.org/software/ddd/ ddd]<br />
 +
* The [http://www.intel.com/content/www/us/en/architecture-and-technology/64-ia-32-architectures-software-developer-vol-3a-3b-system-programming-manual.html Intel 64 and IA-32 Architectures Software Developer’s Manual] Volume 3<br />
 +
* The [http://www.dmtf.org/standards/smbios SMBIOS Reference Specification] (C) Distributed Management Task Force<br />
 +
<br />
 +
==== Compiling ====
 +
<syntaxhighlight lang="c">
 +
$ gcc coremod.c -o coremod
 +
</syntaxhighlight>
 +
- or -
 +
<syntaxhighlight lang="c">
 +
$ clang coremod.c -o coremod
 +
</syntaxhighlight>
 +
<br />
 +
==== Debugging ====
 +
First of all, compile sources with the -g switch then launch the debugger<br />
 +
<syntaxhighlight lang="c">
 +
$ kdesu ddd ./coremod
 +
</syntaxhighlight>
 +
<br />
 +
==== Usage ====
 +
Two kernel modules must be loaded
 +
# msr
 +
# dmi-sysfs
 +
<br />
 +
Execute CoreMod as root
 +
<syntaxhighlight lang="bash">
 +
# ./coremod
 +
</syntaxhighlight>
 +
<br />
 +
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:<br />
 +
* [s]
 +
* [Enter]
 +
* [c]
 +
* [Enter]
 +
And for instance to go back to previous menu level:<br />
 +
* [<]
 +
* [Enter]
 +
<br />
 +
Discover the other functions to dump your components !
 +
<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">
<syntaxhighlight lang="c" line start="1">
// coremod.c - CyrIng 2012
// coremod.c - CyrIng 2012
Line 88: Line 145:
return(rc);
return(rc);
}
}
-
</syntaxhighlight>
 
-
<br />
 
-
===== Compiling and debugging file =====
 
-
<syntaxhighlight lang="c">
 
-
$ gcc -g coremod.c -o coremod
 
-
$ kdesu ddd ./coremod
 
</syntaxhighlight>
</syntaxhighlight>

Revision as of 20:51, 9 July 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

$ gcc coremod.c -o coremod

- or -

$ clang coremod.c -o coremod


Debugging

First of all, compile sources with the -g switch then launch the debugger

$ kdesu ddd ./coremod


Usage

Two kernel modules must be loaded

  1. msr
  2. dmi-sysfs


Execute CoreMod as root

# ./coremod


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 !

Contact

Releases

Release 2012-0.1.2

coremod.h
coremod.c

Release 2012-0.1.1

coremod.c
  1. // coremod.c - CyrIng 2012
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <unistd.h>
  6. #include <sys/stat.h>
  7. #include <fcntl.h>
  8.  
  9. // Intel® 64 and IA-32 Architectures Software Developer’s Manual
  10. // Vol. 3C § 34-1
  11. // Table 34-2. IA-32 Architectural MSRs
  12.  
  13. #define	IA32_PERF_STATUS	0x198
  14.  
  15. // System Management BIOS (SMBIOS) Reference Specification
  16. // Version: 2.7.1 § 7.5
  17. // Table 20 – Processor Information (Type 4) Structure
  18.  
  19. #define	SMBIOS_PROCINFO_STRUCTURE	4
  20. #define	SMBIOS_PROCINFO_INSTANCE	0
  21. #define	SMBIOS_PROCINFO_EXTCLK		0x12
  22.  
  23.  
  24. int Read_MSR(int cpu, off_t offset, unsigned long long *msr) {
  25. 	ssize_t	retval=0;
  26. 	char	pathname[32]="";
  27. 	int		fd=0, rc=-1;
  28.  
  29. 	sprintf(pathname, "/dev/cpu/%d/msr", cpu);
  30. 	if( (fd=open(pathname, O_RDONLY)) != -1 ) {
  31. 		retval=pread(fd, msr, sizeof *msr, offset);
  32. 		close(fd);
  33. 		rc=(retval != sizeof *msr) ? -1 : 0;
  34. 	}
  35. 	return(rc);
  36. }
  37.  
  38. int Read_SMBIOS(int structure, int instance, off_t offset, void *buf, size_t nbyte) {
  39. 	ssize_t	retval=0;
  40. 	char	pathname[]="/sys/firmware/dmi/entries/999-99/raw";
  41. 	int		fd=0, rc=-1;
  42.  
  43. 	sprintf(pathname, "/sys/firmware/dmi/entries/%d-%d/raw", structure, instance);
  44. 	if( (fd=open(pathname, O_RDONLY)) != -1 ) {
  45. 		retval=pread(fd, buf, nbyte, offset);
  46. 		close(fd);
  47. 		rc=(retval != nbyte) ? -1 : 0;
  48. 	}
  49. 	return(rc);
  50. }
  51.  
  52. int	Get_Ratio(int target) {
  53. 	unsigned long long msr=0;
  54.  
  55. 	if( Read_MSR(target, IA32_PERF_STATUS, &msr) != -1)
  56. 		return((int) msr);
  57. 	else
  58. 		return(0);
  59. }
  60.  
  61. int External_Clock() {
  62. 	int	clock=0;
  63.  
  64. 	if( Read_SMBIOS(SMBIOS_PROCINFO_STRUCTURE, SMBIOS_PROCINFO_INSTANCE, SMBIOS_PROCINFO_EXTCLK, &clock, 1) != -1)
  65. 		return(clock);
  66. 	else
  67. 		return(0);
  68. }
  69.  
  70. int main(int argc, char *argv[]) {
  71. 	int	target=0, first=0, last=0, clock=0, ratio=0, rc=0;
  72.  
  73. 	switch(argc) {
  74. 	  case 2:	first = atoi(argv[1]);
  75. 				last  = first;
  76. 	  break;
  77. 	  case 3:	first = atoi(argv[1]);
  78. 				last  = atoi(argv[2]);
  79. 	  break;
  80. 	}
  81. 	if((clock=External_Clock())!=0)
  82. 	  for(target=first; target<=last && (ratio=Get_Ratio(target)) != 0; target++)
  83. 		printf("Processor#%d : Ratio[%d] x Clock[%d] = %d Mhz\n", target, ratio, clock, ratio*clock);
  84. 	else
  85. 		rc=-1;
  86. 	return(rc);
  87. }
Personal tools