![]() |
core2duotemp.c to core2duotemp.pas
Wer kann das übersetzen oder ein DELPHI-Programm daraus machen?
Code:
[edit=SirThornberry]Delphi-Tags durch C-Tags ersetzt - Mfg, SirThornberry[/edit]
/* ----------------------------------------------------------------------- *
* * 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); } |
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 ) // ... |
Re: core2duotemp.c to core2duotemp.pas
|
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 |
Re: core2duotemp.c to core2duotemp.pas
Für Windows.
WMI kann das nicht! |
Re: core2duotemp.c to core2duotemp.pas
Ich würde vermuten, dass das über den SMBus geht ... aber sicher bin ich mir nicht!
mfG Markus |
Re: core2duotemp.c to core2duotemp.pas
Does this work couse i am interested :)
|
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...
|
Re: core2duotemp.c to core2duotemp.pas
Habe was Neues gefunden - MSR auslesen:
Delphi-Quellcode:
Ich hoffe, dass nicht alle C-Freaks in Urlaub sind!
/*-
* 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; } :cheers: Wer mehr Infos braucht: ![]() |
Re: core2duotemp.c to core2duotemp.pas
das ist wieder nur für linux und co
Code:
....
fd = open("/dev/cpu0", O_RDWR, 0); ... |
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:44 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz