Einzelnen Beitrag anzeigen

hathor
(Gast)

n/a Beiträge
 
#9

Re: core2duotemp.c to core2duotemp.pas

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