AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren

core2duotemp.c to core2duotemp.pas

Ein Thema von hathor · begonnen am 5. Aug 2007 · letzter Beitrag vom 31. Mai 2008
Antwort Antwort
Seite 1 von 7  1 23     Letzte » 
hathor
(Gast)

n/a Beiträge
 
#1

core2duotemp.c to core2duotemp.pas

  Alt 5. Aug 2007, 20:03
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]
  Mit Zitat antworten Zitat
Benutzerbild von cruiser
cruiser

Registriert seit: 23. Dez 2003
Ort: Königsbrück/Sachsen
455 Beiträge
 
Delphi 7 Enterprise
 
#2

Re: core2duotemp.c to core2duotemp.pas

  Alt 5. Aug 2007, 20:07
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 )
// ...
  Mit Zitat antworten Zitat
hathor
(Gast)

n/a Beiträge
 
#3

Re: core2duotemp.c to core2duotemp.pas

  Alt 5. Aug 2007, 20:15
Richtig!

http://hardtest.florian-strunk.de/showthread.php?tid=15
  Mit Zitat antworten Zitat
Benutzerbild von cruiser
cruiser

Registriert seit: 23. Dez 2003
Ort: Königsbrück/Sachsen
455 Beiträge
 
Delphi 7 Enterprise
 
#4

Re: core2duotemp.c to core2duotemp.pas

  Alt 5. Aug 2007, 20:18
Naja... brauchst du das für Linux (FreePascal/Kylix) oder under Windows?

Bei Windows hilft die vielleicht WMI weiter
  Mit Zitat antworten Zitat
hathor
(Gast)

n/a Beiträge
 
#5

Re: core2duotemp.c to core2duotemp.pas

  Alt 5. Aug 2007, 20:20
Für Windows.

WMI kann das nicht!
  Mit Zitat antworten Zitat
markusj

Registriert seit: 9. Dez 2005
Ort: Kandel
408 Beiträge
 
#6

Re: core2duotemp.c to core2duotemp.pas

  Alt 5. Aug 2007, 21:34
Ich würde vermuten, dass das über den SMBus geht ... aber sicher bin ich mir nicht!

mfG
Markus
Markus
  Mit Zitat antworten Zitat
Razor
(Gast)

n/a Beiträge
 
#7

Re: core2duotemp.c to core2duotemp.pas

  Alt 5. Aug 2007, 21:41
Does this work couse i am interested
  Mit Zitat antworten Zitat
Muetze1
(Gast)

n/a Beiträge
 
#8

Re: core2duotemp.c to core2duotemp.pas

  Alt 6. Aug 2007, 01:13
You need the rights to access the machine specific registers (MSR) in your ring 3 application. This is more difficult...
  Mit Zitat antworten Zitat
hathor
(Gast)

n/a Beiträge
 
#9

Re: core2duotemp.c to core2duotemp.pas

  Alt 7. Aug 2007, 10:11
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!


Wer mehr Infos braucht:
http://developer.intel.com/products/...uals/index.htm
  Mit Zitat antworten Zitat
Gruber_Hans_12345

Registriert seit: 14. Aug 2004
1.426 Beiträge
 
Delphi 2007 Professional
 
#10

Re: core2duotemp.c to core2duotemp.pas

  Alt 7. Aug 2007, 10:16
das ist wieder nur für linux und co

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

2B or not 2B, that is FF
  Mit Zitat antworten Zitat
Themen-Optionen Thema durchsuchen
Thema durchsuchen:

Erweiterte Suche
Ansicht

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:57 Uhr.
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