Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Programmieren allgemein (https://www.delphipraxis.net/40-programmieren-allgemein/)
-   -   core2duotemp.c to core2duotemp.pas (https://www.delphipraxis.net/97137-core2duotemp-c-core2duotemp-pas.html)

hathor 5. Aug 2007 20:03


core2duotemp.c to core2duotemp.pas
 
Wer kann das übersetzen oder ein DELPHI-Programm daraus machen?

Code:
/* ----------------------------------------------------------------------- *
 *   
 *   Copyright 2007 Florian Strunk - All Rights Reserved
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, Inc., 675 Mass Ave, Cambridge MA 02139,
 *   USA; either version 2 of the License.
 *
 * ----------------------------------------------------------------------- */

/*
 * core2duotemp.c
 *
 * Utility to read Temperature of Core2Duo with MSR.
 */


#include <errno.h>
#include <stdio.h>
#include <fcntl.h>
//#include <unistd.h>
#include <stdlib.h>
//#include <getopt.h>
#include <inttypes.h>
//#include <sys/types.h>


int main(int argc, char *argv[])
{

  uint32_t reg;
  uint32_t reftemp_reg;
  uint64_t data;
  uint64_t data_reftemp;
  uint32_t i;

  unsigned int highbit = 63, lowbit = 0, bits;
  uint64_t reftemp = 0;
  uint64_t temp = 0;

  int fd;
  uint32_t cpu = 0;
  char msr_file_name[64];


for (i=0; i<2; i++)
{

  cpu = i;

  sprintf(msr_file_name, "/dev/cpu/%d/msr", cpu);
  fd = open(msr_file_name, O_RDONLY);
  if ( fd < 0 ) {
    if ( errno == ENXIO ) {
      fprintf(stderr, "rdmsr: No CPU %d\n", cpu);
      exit(2);
    } else if ( errno == EIO ) {
      fprintf(stderr, "rdmsr: CPU %d doesn't support MSRs\n", cpu);
      exit(3);
    } else {
      perror("rdmsr:open");
      exit(127);
    }
  }

  // read register 0x19C bits 16 to 22
  // and register 0xEE if bit 30 of reg is 1 then reftemp 85 degrees C else 100 degrees C

  // temp = reftemp - value of reg 0x19C

  reg = 0x19C;
  if ( pread(fd, &data, sizeof data, reg) != sizeof data ) {
    perror("rdmsr:pread");
    exit(127);
  }

  reftemp_reg = 0xEE;

  if ( pread(fd, &data_reftemp, sizeof data_reftemp, reftemp_reg) != sizeof data_reftemp ) {
    perror("rdmsr:pread");
    exit(127);
  }

  close(fd);

  // for register 0xEE
  // if bit 30 of reg is 1 then reftemp 85 degrees C else 100 degrees C
  // look at C't 11/2007 page 218

  highbit=30;
  lowbit=30;
  bits = highbit-lowbit+1;
  if ( bits < 64 ) {
    /* Show only part of register */
    data_reftemp >>= lowbit;
    data_reftemp &= (1ULL << bits)-1;
  }

  if (data_reftemp == 1)
    {reftemp = 85;}
  else
  {
    reftemp = 100;
  }


  // only bit 16 to 22 of data
  highbit=22;
  lowbit=16;
  bits = highbit-lowbit+1;
  if ( bits < 64 ) {
    /* Show only part of register */
    data >>= lowbit;
    data &= (1ULL << bits)-1;
  }


  // temp = reftemp - value of reg 0x19C
  temp = reftemp - data;

  //printf("reftemp: %llu\n",reftemp);
  //printf("data: %llu\n",data);
  printf("CPU %lu: %llu\n",i,temp);

} // end for(i..
exit(0);
}
[edit=SirThornberry]Delphi-Tags durch C-Tags ersetzt - Mfg, SirThornberry[/edit]

cruiser 5. Aug 2007 20:07

Re: core2duotemp.c to core2duotemp.pas
 
Das sieht mir arg nach Linux/Unix only aus

Code:
// ...
cpu = i;

  sprintf(msr_file_name, "/dev/cpu/%d/msr", cpu); // <<<<<
  fd = open(msr_file_name, O_RDONLY);
  if ( fd < 0 ) {
    if ( errno == ENXIO )
// ...

hathor 5. Aug 2007 20:15

Re: core2duotemp.c to core2duotemp.pas
 
Richtig!

http://hardtest.florian-strunk.de/showthread.php?tid=15

cruiser 5. Aug 2007 20:18

Re: core2duotemp.c to core2duotemp.pas
 
Naja... brauchst du das für Linux (FreePascal/Kylix) oder under Windows?

Bei Windows hilft die vielleicht WMI weiter

hathor 5. Aug 2007 20:20

Re: core2duotemp.c to core2duotemp.pas
 
Für Windows.

WMI kann das nicht!

markusj 5. Aug 2007 21:34

Re: core2duotemp.c to core2duotemp.pas
 
Ich würde vermuten, dass das über den SMBus geht ... aber sicher bin ich mir nicht!

mfG
Markus

Razor 5. Aug 2007 21:41

Re: core2duotemp.c to core2duotemp.pas
 
Does this work couse i am interested :)

Muetze1 6. Aug 2007 01:13

Re: core2duotemp.c to core2duotemp.pas
 
You need the rights to access the machine specific registers (MSR) in your ring 3 application. This is more difficult...

hathor 7. Aug 2007 10:11

Re: core2duotemp.c to core2duotemp.pas
 
Habe was Neues gefunden - MSR auslesen:

Delphi-Quellcode:
/*-
 * Copyright (c) 2007 Michael Fuckner <michael@fuckner.net>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $Id: msr19c.c,v 1.3 2007/07/14 13:21:34 molli123 Exp $
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>

#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sysexits.h>
#include <unistd.h>

#include "cpu.h"

int main(argc, argv)
   int argc;
   char *argv[];
   {
   int fd;
   int ret;
   int i,j,cpu;
   int debug=0;

   /* Maximum Junction Temperature of current Core2Duo CPUs */
   static int tjmax = 85;

   cpu_msr_args_t args = {
      .msr = 0x19c,
   };

   cpu_cpuid_args_t args1 = {
      .level = 1,
   };

   if ((argc == 2) && strcmp(argv[1], "-v") == 0)
      debug=1;

   fd = open("/dev/cpu0", O_RDWR, 0);
   if (fd < 0)
      err(EX_NOINPUT, "open()");

   args1.level=0;
   ret = ioctl(fd, CPU_CPUID, &args1);
   if (ret < 0)
      err(EX_IOERR, "ioctl");
   if (debug)
   {
      printf ("Max input for reading Cpuid: %d\n", args1.data[0]);

      j= args1.data[0];
      for (i=0;i<=j;i++)
      {
         args1.level=i;
         ret = ioctl(fd, CPU_CPUID, &args1);
         if (ret < 0)
            err(EX_IOERR, "ioctl");
         fprintf(stderr, "CPUID %02d: %.8x %.8x %.8x %.8x\n", i,args1.data[0], args1.data[1], args1.data[2], args1.data[3]);
      }
 
   }

   if (args1.data[0] < 6)
      fprintf (stderr, "Reading CPUID 06H not supported, CPU too old\n");
   else
   {
      args1.level=6;
      ret = ioctl(fd, CPU_CPUID, &args1);
      if (ret < 0)
         err(EX_IOERR, "ioctl");
      if (debug)
         printf("cpuid6, bit0: %d\n",(args1.data[0] & 0x01));
      if (!(args1.data[0] & 0x01))
         fprintf (stderr,"Digital temperature sensor unsupported\n");
      else {
         ret = ioctl(fd, CPU_RDMSR, &args);
         if (ret < 0)
            err(EX_IOERR, "ioctl");
         if (debug)
         {
            printf ("Raw value msr 0x19c: %#.16llx\n\n", args.data);
            printf ("Reading valid: %d\n"             ,((args.data & 0x80000000) >>31));
            printf ("Resolution in Deg. Celsius: %d\n" ,((args.data & 0x78000000) >>27));
            printf ("Digital Readout: %d\n"           ,((args.data & 0x007F0000) >>16));
            printf ("Thermal Threshold #2 Log: %d\n"  ,((args.data & 0x00000200) >>9));
            printf ("Thermal Threshold #2 Status: %d\n",((args.data & 0x00000100) >>8));
            printf ("Thermal Threshold #1 Log: %d\n"  ,((args.data & 0x00000080) >>7));
            printf ("Thermal Threshold #1 Status: %d\n",((args.data & 0x00000040) >>6));
            printf ("Critical Temperature Log: %d\n"  ,((args.data & 0x00000020) >>5));
            printf ("Critical Temperature Status: %d\n",((args.data & 0x00000010) >>4));
            printf ("PROCHOT# or FORCEPR# Log: %d\n"  ,((args.data & 0x00000008) >>3));
            printf ("PROCHOT# or FORCEPR# Event: %d\n" ,((args.data & 0x00000004) >>2));
            printf ("Thermal Status Log: %d\n"        ,((args.data & 0x00000002) >>1));
            printf ("Thermal Status: %d\n"            ,((args.data & 0x00000001) >>0));
         }

         if (((args.data & 0x80000000) >>31) != 1)
            fprintf (stderr, "Reading invalid\n");
         else
            fprintf (stderr,"Temperature Core0: %d\n",(tjmax - ((args.data & 0x007F0000) >>16)));
      }
   }
   return 0;
}
Ich hoffe, dass nicht alle C-Freaks in Urlaub sind!
:cheers:

Wer mehr Infos braucht:
http://developer.intel.com/products/...uals/index.htm

Gruber_Hans_12345 7. Aug 2007 10:16

Re: core2duotemp.c to core2duotemp.pas
 
das ist wieder nur für linux und co

Code:
....
fd = open("/dev/cpu0", O_RDWR, 0);
...

Apollonius 7. Aug 2007 10:19

Re: core2duotemp.c to core2duotemp.pas
 
Wo genau liegen denn deine Probleme bei der Übersetzung. Ich vermute mal, dass du ein bisschen C kannst (Grundkenntnisse sind ja nicht schwierig), und ich habe jetzt ehrlich gesagt keine Lust, dass aus dem Stand zu übersetzen. Die cpu.h ist kein Standard, die bräuchte man zur Übersetzung auch.

hathor 7. Aug 2007 10:30

Re: core2duotemp.c to core2duotemp.pas
 
cpu.h ? - OK - here it is...
Delphi-Quellcode:

/*-
 * Copyright (c) 2006 Stanislav Sedov <stas@FreeBSD.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 * $MBSDlabs: devcpu/cpu/cpu.h,v 1.4 2006/12/08 22:32:35 stas Exp $
 *
 */

#ifndef _CPU_H_
#define _CPU_H_

typedef struct {
   int      msr;   /* MSR to read */
   uint64_t   data;
} cpu_msr_args_t;

typedef struct {
   int      level; /* CPUID level */
   uint32_t   data[4];
} cpu_cpuid_args_t;

typedef struct {
   void   *data;
   size_t   size;
} cpu_update_args_t;

#define CPU_RDMSR   _IOWR('c', 1, cpu_msr_args_t)
#define CPU_WRMSR   _IOWR('c', 2, cpu_msr_args_t)
#define CPU_CPUID   _IOWR('c', 3, cpu_cpuid_args_t)
#define CPU_UPDATE   _IOWR('c', 4, cpu_update_args_t)

#define INTEL_VENDOR_ID   "GenuineIntel"
#define AMD_VENDOR_ID   "AuthenticAMD"

#define MSR_K8_UCODE_UPDATE 0xc0010020

#endif /* _CPU_H_ */

Gruber_Hans_12345 7. Aug 2007 10:33

Re: core2duotemp.c to core2duotemp.pas
 
dir ist schon klar, das solche sachen NUR auf Linux systemen funktioniert?

hathor 7. Aug 2007 10:42

Re: core2duotemp.c to core2duotemp.pas
 
Zitat:

Zitat von Gruber_Hans_12345
dir ist schon klar, das solche sachen NUR auf Linux systemen funktioniert?

Du willst doch hoffentlich mit dieser unsinnigen Behauptung nicht alle Interessenten abschrecken - oder?

Die AMD-K8-Temperatur(en) kann man doch auch mit DELPHI unter WINDOWS auslesen - was habt Ihr denn alle für eine Riesenangst, wenn Ihr den Pfad der WINDOWS-(Un)tugend verlasst?

Seit Jahren wird dies und das behauptet von Leuten, die KEINE Ahnung haben, aber überall ihren Senf dazugeben müssen!!!

Gruber_Hans_12345 7. Aug 2007 10:53

Re: core2duotemp.c to core2duotemp.pas
 
Zitat:

Zitat von hathor
Zitat:

Zitat von Gruber_Hans_12345
dir ist schon klar, das solche sachen NUR auf Linux systemen funktioniert?

Du willst doch hoffentlich mit dieser unsinnigen Behauptung nicht alle Interessenten abschrecken - oder?

Die AMD-K8-Temperatur(en) kann man doch auch mit DELPHI unter WINDOWS auslesen - was habt Ihr denn alle für eine Riesenangst, wenn Ihr den Pfad der WINDOWS-(Un)tugend verlasst?

Seit Jahren wird dies und das behauptet von Leuten, die KEINE Ahnung haben, aber überall ihren Senf dazugeben müssen!!!

also ich glaub eich habe soviel ahnung von linux und windows, das ich ruhigen gewissen behaupten kann, das der obige code (speziell das fd = open("/dev/cpu0", O_RDWR, 0);) unter Windows NICHT funktionieren kann, und dieses Stückchen code ist dafür da, um alle infos auszulesen.
und da das System von /dev/cpu0 unter Windows nicht implementiert ist, muß man da mit sicherheit ganz andere wege suchen (du kannst ja mal versuchen in der registry zu suchen)

aber fakt ist, das der weg den c source zu übersetzen mit sicherheit scheitert wird (auf windows systemen)

Muetze1 7. Aug 2007 11:29

Re: core2duotemp.c to core2duotemp.pas
 
Zitat:

Zitat von hathor
Seit Jahren wird dies und das behauptet von Leuten, die KEINE Ahnung haben, aber überall ihren Senf dazugeben müssen!!!

Dann beweise doch bitte mal dass du Ahnung hast lese mal bitte ein MSR Register "mit DELPHI unter WINDOWS" aus und zeig mal den Code.

Gut gebrüllt, Löwe... :wall:

Um es nochmals zu wiederholen: Linux bietet mit den symbolischen Gerätelinks einen direkten Weg Informationen aus dem Ring-0 (Kernel) zur Anwenderschicht (Ring-3) zu übermitteln. Diesen Weg hast du unter Windows nicht. Du hast somit das Problem keinen Aufruf in deiner Ring-3 Applikation zu machen um ein MSR Register auszulesen (RDMSR). Statt dessen haut dir Windows auf die Finger mit einer Exception über eine priviligierte Anweisung.

Probier es aus:
Delphi-Quellcode:
function TryIt; Assembler;
asm
  pushad
  mov eax, 1
  RDMSR
  popad
end;
/EDIT: Wobei ich mich gerade Frage, ob der interne Assembler die Instruction RDMSR über decodiert. Das muss wahrscheinlich mit define byte hardcodiert werden...

hathor 7. Aug 2007 11:47

Re: core2duotemp.c to core2duotemp.pas
 
Liste der Anhänge anzeigen (Anzahl: 1)
amd64coretemp

Bei Intel Prozessoren werden die Temperaturen aus dem MSR (Model Specific Register) und bei AMD Prozessoren aus einem Register in der NB ausgelesen.

Muetze1 7. Aug 2007 12:06

Re: core2duotemp.c to core2duotemp.pas
 
Zitat:

Zitat von hathor
Bei Intel Prozessoren werden die Temperaturen aus dem MSR (Model Specific Register) und bei AMD Prozessoren aus einem Register in der NB ausgelesen.

Löst wie angesprochen noch immer nicht das Problem bei den intel Core2Duo bzw. Intel CPUs mit Sensor. Schliesslich liegt genau dort das angesprochene Problem.

Mark90 7. Aug 2007 16:17

Re: core2duotemp.c to core2duotemp.pas
 
HI,

auf Codegear habe ich vorkurzem gesehen, dass man (ich schätzte mal sofern man c++ builder und delphi hat) auch c++ units oder komponenten in delphi oder anders rum verwenden kann. Ich hab den artikel nicht gelesen und kann daher auch nicht bestätigen ob dies geht!

wenn es gienge wäre es auf jedenfall eine teure angelegenheit!

Muetze1 7. Aug 2007 18:02

Re: core2duotemp.c to core2duotemp.pas
 
Zitat:

Zitat von Mark90
auf Codegear habe ich vorkurzem gesehen, dass man (ich schätzte mal sofern man c++ builder und delphi hat) auch c++ units oder komponenten in delphi oder anders rum verwenden kann. Ich hab den artikel nicht gelesen und kann daher auch nicht bestätigen ob dies geht!

wenn es gienge wäre es auf jedenfall eine teure angelegenheit!

Schön, nett aber überhaupt nicht neu. Damit programmiere ich täglich auf Arbeit: C++ Teile und Delphi Programmteile zusammen ein Programm. Und was bringt uns das nun in diesem Thread? Auch wenn das C++ Quellcode ist, das ist Schnuppe. Das ist nicht der Grund, warum man es nicht portieren kann, sondern weil der Code spezielle Geräte eines Linux Betriebssystems verwendet und somit nicht unter Windows lauffähig ist, da es diese Geräte dort nicht gibt. Es ist eine Sache des Betriebssystems, nicht der Sprache...

Mark90 7. Aug 2007 18:39

Re: core2duotemp.c to core2duotemp.pas
 
Zitat:

Zitat von Muetze1
Zitat:

Zitat von Mark90
auf Codegear habe ich vorkurzem gesehen, dass man (ich schätzte mal sofern man c++ builder und delphi hat) auch c++ units oder komponenten in delphi oder anders rum verwenden kann. Ich hab den artikel nicht gelesen und kann daher auch nicht bestätigen ob dies geht!

wenn es gienge wäre es auf jedenfall eine teure angelegenheit!

Schön, nett aber überhaupt nicht neu. Damit programmiere ich täglich auf Arbeit: C++ Teile und Delphi Programmteile zusammen ein Programm. Und was bringt uns das nun in diesem Thread? Auch wenn das C++ Quellcode ist, das ist Schnuppe. Das ist nicht der Grund, warum man es nicht portieren kann, sondern weil der Code spezielle Geräte eines Linux Betriebssystems verwendet und somit nicht unter Windows lauffähig ist, da es diese Geräte dort nicht gibt. Es ist eine Sache des Betriebssystems, nicht der Sprache...

Reg dich mal ab!!

DataCool 7. Aug 2007 20:21

Re: core2duotemp.c to core2duotemp.pas
 
Muetze hat aber Recht !!!!

Greetz DataCool

Razor 13. Aug 2007 23:15

Re: core2duotemp.c to core2duotemp.pas
 
The MSR address is 19C. H = Hexadecimal. :wink:

Muetze1 14. Aug 2007 06:50

Re: core2duotemp.c to core2duotemp.pas
 
/EDIT: What the hell: I do never post to any of your threads again - as I said. Sorry - was my fault.

Razor 14. Aug 2007 10:45

Re: core2duotemp.c to core2duotemp.pas
 
What are you talking about,ofcourse it will work i got this info from core temp author.. :P

Razor 24. Aug 2007 14:16

Re: core2duotemp.c to core2duotemp.pas
 
Has anybody tested this becouse if you translate i can send it to friends who can test. :)

Razor 24. Aug 2007 14:37

Re: core2duotemp.c to core2duotemp.pas
 
Okay i found this can somebody translate this please! :wink:


Zitat:

Code:
#include <float.h>
#include <stdio.h>
#include <windows.h>
 
#include "C2DTemp.h"
#include "RivaTunerExports.h"
#include "MonitoringSourceDesc.h"

HINSTANCE      g_hModule      = NULL;
HMODULE         g_hHost         = NULL;

READ_MSR_PROC      g_pReadMSR      = NULL;

DWORD         g_dwCPU         = 0;
BOOL         g_bHasDTS      = FALSE;
FLOAT         g_fTjmax      = 100.0f;

const char * const   szDim         = "°C";
const char * const   szDesc         = "CPU temperature as reported by on-die Digital Thermal Sensor";
const char * const   szGroup         = "CPU";

BOOL DetectCPUFeatures(void)
{
   const char   ven_intel[12] = {'G','e','n','u','i','n','e','I','n','t','e','l'};
   char      vendor[12];
   DWORD      last_fn = 0, fn6_eax = 0;

   memset(vendor, 0, 12);

   // try to execute CPUID instruction
   __try {
      __asm   {
         xor      eax, eax
         xor      ebx, ebx
         xor      ecx, ecx
         xor      edx, edx
         cpuid
         mov      dword ptr [last_fn], eax
         mov      dword ptr [vendor], ebx
         mov      dword ptr [vendor + 4], edx
         mov      dword ptr [vendor + 8], ecx
      }
   }
   __except (GetExceptionCode() == STATUS_ILLEGAL_INSTRUCTION) {
      return FALSE;
   }

   // Is it GenuineIntel CPU?
   if (strncmp(vendor, ven_intel, 12) != 0) {
      return FALSE;
   }

   // Does it support Digital Thermal Sensor and Power Management CPUID leaf?
   if (last_fn < 6) {
      return FALSE;
   }

   __asm   {
      mov      eax, 6
      cpuid
      mov      dword ptr [fn6_eax], eax
   }

   // Is Digital Thermal Sensor feature supported?
   if ((fn6_eax & 0x1) == 0) {
      return FALSE;
   }

   return TRUE;
}

BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
{
   UNREFERENCED_PARAMETER(lpReserved);

   if (dwReason == DLL_PROCESS_ATTACH) {
      g_hModule = hInstance;
      g_bHasDTS = DetectCPUFeatures();
   }

   return TRUE;
}

C2DTEMP_API DWORD GetSourcesNum(void)
{
   SYSTEM_INFO   si;

   GetSystemInfo(&si);

   g_dwCPU = si.dwNumberOfProcessors;

   return g_dwCPU;
}

C2DTEMP_API BOOL GetSourceDesc(DWORD dwIndex, LPMONITORING_SOURCE_DESC pDesc)
{
   DWORD   hi, lo;

   if (g_pReadMSR == NULL) {
      g_hHost = GetModuleHandle(NULL);

      if (g_hHost == NULL) {
         return FALSE;
      }

      g_pReadMSR = (READ_MSR_PROC)GetProcAddress(g_hHost, "ReadMSR");

      if (g_pReadMSR == NULL) {
         return FALSE;
      }

      if (!g_bHasDTS) {
         return FALSE;
      } else {
         // Try to detect Tjunction
         if (!g_pReadMSR(0xEE, &hi, &lo)) {
            return FALSE;
         }
         if (lo & 0x40000000) {
            g_fTjmax = 85.0f;
         }
      }
   }

   sprintf(pDesc->szName, "CPU%ld temperature", dwIndex);
   strcpy(pDesc->szDim   , szDim);
   strcpy(pDesc->szDesc   , szDesc);

   if (pDesc->dwVersion >= 0x00010002) {
      strcpy(pDesc->szGroup, szGroup);
   }

   pDesc->fltMaxLimit   = 100.0f;
   pDesc->fltMinLimit   = 0.0f;
   pDesc->fltGridDim   = 10.0f;

   return TRUE;
}

C2DTEMP_API FLOAT GetSourceData(DWORD dwIndex)
{
static   FLOAT      val[32] = { FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX,
                FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX,
                FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX,
                FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX,
                FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX,
                FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX,
                FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX,
                FLT_MAX, FLT_MAX, FLT_MAX, FLT_MAX
         };

   DWORD_PTR   dwMask, dwProcessAffinityMask, dwSystemAffinityMask;
   DWORD      hi, lo;

   // Is DTS supported by this CPU?
   if (!g_bHasDTS) {
      return FLT_MAX;
   }

   // NOTE: This should be done by RivaTuner before calling plugins
   //       Will be removed when Alexey implements it internally

   // Get current process and system affinity mask
   if (!GetProcessAffinityMask(GetCurrentProcess(), &dwProcessAffinityMask, &dwSystemAffinityMask)) {
      return FLT_MAX;
   }
   
   // Temporarily enable execution on all the CPUs in the system
   if (!SetProcessAffinityMask(GetCurrentProcess(), dwSystemAffinityMask)) {
      return FLT_MAX;
   }

   dwMask = 1 << dwIndex;

   // Move the thread to the proper core
   if (!SetThreadAffinityMask(GetCurrentThread(), dwMask)) {
      return FLT_MAX;
   }

   // Read IA32_THERM_STATUS MSR
   if (!g_pReadMSR(0x19C, &hi, &lo)) {
      return FLT_MAX;
   }

   // Is reading valid?
   // If not, just return previous value
   if ((lo & 0x80000000) == 0) {
      return val[dwIndex];
   }

   val[dwIndex] = g_fTjmax - (FLOAT)((lo >> 16) & 0x7F);

   return val[dwIndex];
}

[edit=SirThornberry]c-Tag eingefügt - bitte zukünftig die richtigen Tags verwenden und nicht bei Zitaten ein Code-Tag und bei Code ein Zitat-Tag - Mfg, SirThornberry[/edit]

christian_u 24. Aug 2007 14:58

Re: core2duotemp.c to core2duotemp.pas
 
*ACK*

Unter Windows müsste man einen Treiber schreiben und auf den kann man dann auch mit Delphi zugreifen.
Treiberentwicklung selbst ist mit Delphi auch nicht möglich.

Razor 24. Aug 2007 15:01

Re: core2duotemp.c to core2duotemp.pas
 
I made a driver already :)

christian_u 24. Aug 2007 16:46

Re: core2duotemp.c to core2duotemp.pas
 
you made an driver, and dont understand this little bit of c code upside ?

Razor 27. Aug 2007 09:48

Re: core2duotemp.c to core2duotemp.pas
 
I mean i already have a driver and no i dont understand that code in C. :(

Razor 27. Aug 2007 13:21

Re: core2duotemp.c to core2duotemp.pas
 
Can somebody translate this so i can test it with my driver? :)

devidespe 27. Aug 2007 18:32

Re: core2duotemp.c to core2duotemp.pas
 
@Razor:

I would say its very complex to translate C code into Delphi, and another problem is the driver you have. Every driver contains other methods with different calling parameters, so nobody knows how to access your specific driver.

The simplest way is to read the Intel® 64 and IA-32 Architectures Software Developer's Manual, where chapter 13 (Power And Thermal Management) contains the needed ways to gain the core temperatures. Before that you have to check the processor requirements, and if they are available (via the CPUID command, some bits in the Feature capabilities). The CPUID command is accessable in combination with Delphi itself, for the MSR access you need a device driver with ring 0 access and a delphi application with admin rights to load it.

If you have the routines to read MSR and CPUID functions, the temperature readout is quite simple. Just read the chapter 13 within the above Intel document. If there are other questions just ask. But be sure that nobody translates C code or wrote the Delphi code for you.

Hope that helps...

Razor 27. Aug 2007 18:35

Re: core2duotemp.c to core2duotemp.pas
 
I posted a new topic go look there it contains full source code for this problem. :?

alice 1. Sep 2007 19:02

Re: core2duotemp.c to core2duotemp.pas
 
Zitat:

Zitat von Razor
I posted a new topic go look there it contains full source code for this problem. :?

where?

cu

alice

Razor 9. Nov 2007 10:33

Re: core2duotemp.c to core2duotemp.pas
 
Nonono wroong...ill explain it how it works

There are 2 registers $19C and $EE

If we want to check if a intel core cpu has dts we first use MSREAD command we check and we read $19C but the return must be 1 couse if its 0 the cpu dosent have DTS( Digital Thermal Sensor ).

Next up we try to detect the Tjunction wich on core cpus is 85 and 100 C with this register $EE.

so if the register $EE reads 0x40000000 then the Tjunction is 85C else its 100C.

And folow a simple formula : Core temp = Tjunction - Delta

And since i study electronics these stuff is similar in Zener diode and Silicon Diode ;).

My Core temp for Intel's core cpuz is 85%. :P

hathor 9. Nov 2007 11:05

Re: core2duotemp.c to core2duotemp.pas
 
In my first post, You can read:

// and register 0xEE if bit 30 of reg is 1 then reftemp 85 degrees C else 100 degrees C...

Razor 9. Nov 2007 11:06

Re: core2duotemp.c to core2duotemp.pas
 
Yes but how do we get Delta? :)

hathor 9. Nov 2007 11:14

Re: core2duotemp.c to core2duotemp.pas
 
// temp = reftemp - value of reg 0x19C
temp = reftemp - data;

MSR 0x19C contains the temperature data, this data is represented as Delta in C° between current temperature and Tjunction.

Razor 9. Nov 2007 11:22

Re: core2duotemp.c to core2duotemp.pas
 
Liste der Anhänge anzeigen (Anzahl: 1)
Those who have core 2 duo please test this... :)


Alle Zeitangaben in WEZ +1. Es ist jetzt 03:44 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz