Einzelnen Beitrag anzeigen

hathor
(Gast)

n/a Beiträge
 
#1

core2duotemp.c to core2duotemp.pas

  Alt 5. Aug 2007, 21: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