![]() |
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); ... |
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.
|
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_ */ |
Re: core2duotemp.c to core2duotemp.pas
dir ist schon klar, das solche sachen NUR auf Linux systemen funktioniert?
|
Re: core2duotemp.c to core2duotemp.pas
Zitat:
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!!! |
Re: core2duotemp.c to core2duotemp.pas
Zitat:
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) |
Re: core2duotemp.c to core2duotemp.pas
Zitat:
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:
/EDIT: Wobei ich mich gerade Frage, ob der interne Assembler die Instruction RDMSR über decodiert. Das muss wahrscheinlich mit define byte hardcodiert werden...
function TryIt; Assembler;
asm pushad mov eax, 1 RDMSR popad end; |
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. |
Re: core2duotemp.c to core2duotemp.pas
Zitat:
|
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! |
Re: core2duotemp.c to core2duotemp.pas
Zitat:
|
Re: core2duotemp.c to core2duotemp.pas
Zitat:
|
Re: core2duotemp.c to core2duotemp.pas
Muetze hat aber Recht !!!!
Greetz DataCool |
Re: core2duotemp.c to core2duotemp.pas
The MSR address is 19C. H = Hexadecimal. :wink:
|
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.
|
Re: core2duotemp.c to core2duotemp.pas
What are you talking about,ofcourse it will work i got this info from core temp author.. :P
|
Re: core2duotemp.c to core2duotemp.pas
Has anybody tested this becouse if you translate i can send it to friends who can test. :)
|
Re: core2duotemp.c to core2duotemp.pas
Okay i found this can somebody translate this please! :wink:
Zitat:
|
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. |
Re: core2duotemp.c to core2duotemp.pas
I made a driver already :)
|
Re: core2duotemp.c to core2duotemp.pas
you made an driver, and dont understand this little bit of c code upside ?
|
Re: core2duotemp.c to core2duotemp.pas
I mean i already have a driver and no i dont understand that code in C. :(
|
Re: core2duotemp.c to core2duotemp.pas
Can somebody translate this so i can test it with my driver? :)
|
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 ![]() 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... |
Re: core2duotemp.c to core2duotemp.pas
I posted a new topic go look there it contains full source code for this problem. :?
|
Re: core2duotemp.c to core2duotemp.pas
Zitat:
cu alice |
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 |
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... |
Re: core2duotemp.c to core2duotemp.pas
Yes but how do we get Delta? :)
|
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. |
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 12:34 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