首页
社区
课程
招聘
关于CPU主频。。。。
2006-6-9 13:21 7555

关于CPU主频。。。。

2006-6-9 13:21
7555
如果想要获得CPU主频,是不是只有RDTSC一种途径??

但是我感觉这种方法会有误差。。。。。。

还有没有其它方法可以准确的获得CPU主频

[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

收藏
点赞7
打赏
分享
最新回复 (11)
雪    币: 1022
活跃值: (31)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
lingyu 1 2006-6-10 00:54
2
0
http://bbs.pediy.com/showthread.php?s=&threadid=21646&highlight=%D3%D0%C8%CB%B2%BB%C3%F7%B0%D7CPUID%D6%B8%C1%EE%B5%C4%D3%C3%B7%A8
雪    币: 208
活跃值: (371)
能力值: ( LV12,RANK:330 )
在线值:
发帖
回帖
粉丝
moodsky 8 2006-6-10 12:26
3
0
[ZT]

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
function GetCpuSpeed: Comp;
{ function to return the CPU clock speed only.}  
{ Usage: MessageDlg(format('%.1f MHz', [GetCpuSpeed]),
mtConfirmation, [mbOk], 0); }  
var  
  t: DWORD;
  mhi, mlo, nhi, nlo: DWORD;
  t0, t1, chi, clo, shr32: Comp;  
begin  
  shr32 := 65536;
  shr32 := shr32 * 65536;  

  t := GetTickCount;  
  while t = GetTickCount do begin end;  
  asm  
    DB 0FH  
    DB 031H  
    mov mhi,edx  
    mov mlo,eax  
  end;  

  while GetTickCount < (t + 1000) do begin end;
asm
DB 0FH
DB 031H
mov nhi,edx
mov nlo,eax
end;

chi := mhi;
if mhi < 0 then chi := chi + shr32;

clo := mlo;
if mlo < 0 then clo := clo + shr32;

t0 := chi * shr32 + clo;

chi := nhi;
if nhi < 0 then chi := chi + shr32;

clo := nlo;
if nlo < 0 then clo := clo + shr32;

t1 := chi * shr32 + clo;

Result := (t1 - t0) / 1E6;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  MessageDlg(format('%.1f MHz', [GetCpuSpeed]),mtConfirmation, [mbOk], 0);
end;

end.
雪    币: 414
活跃值: (531)
能力值: ( LV9,RANK:170 )
在线值:
发帖
回帖
粉丝
nig 4 2006-6-10 12:32
4
0
还挺准确,我的机器是2638MHz,
离真实值有一点差别.
系统是XP
雪    币: 235
活跃值: (100)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
lemony 1 2006-6-11 00:30
5
0
#include <windows.h>
#include <stdio.h>

void main()
{
        char CPUHZ[100];

        __asm
        {
                mov eax, 0x80000004
                cpuid
                mov dword ptr CPUHZ,ecx
                mov dword ptr CPUHZ + 4,edx
        }

        printf("CPU主频为:%s\r\n",CPUHZ);
}

其实就这么简单,呵呵,还需要计算吗??

这样取出来的多准确啊。。。。。。
雪    币: 1852
活跃值: (504)
能力值: (RANK:1010 )
在线值:
发帖
回帖
粉丝
北极星2003 25 2006-6-11 00:51
6
0
最初由 lemony 发布
#include <windows.h>
#include <stdio.h>

void main()
{
........


又学了一招
雪    币: 235
活跃值: (100)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
lemony 1 2006-6-11 00:58
7
0
可惜不支持P4一下的CPU。。。。。。。
雪    币: 288
活跃值: (415)
能力值: ( LV9,RANK:290 )
在线值:
发帖
回帖
粉丝
Pr0Zel 7 2006-6-11 11:30
8
0
Originally posted by lemony
#include <windows.h>
#include <stdio.h>

void main()
{
........

这是把CPU的字串读出来
不代表真实的频率
雪    币: 208
活跃值: (371)
能力值: ( LV12,RANK:330 )
在线值:
发帖
回帖
粉丝
moodsky 8 2006-6-11 11:58
9
0
最初由 lemony 发布
#include <windows.h>
#include <stdio.h>

void main()
{
........


楼主问的是不是就一种途径,CPUID谁不知道啊,真是的!
雪    币: 235
活跃值: (100)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
lemony 1 2006-6-11 12:55
10
0
最初由 moodsky 发布
楼主问的是不是就一种途径,CPUID谁不知道啊,真是的!


不知道是我的表达方式有问题,还是你的理解能力有问题。。。。。。

。。。。。。。。。。。。。。。。。。。。。

I'm wrong,may be
雪    币: 208
活跃值: (371)
能力值: ( LV12,RANK:330 )
在线值:
发帖
回帖
粉丝
moodsky 8 2006-6-11 13:19
11
0
最初由 lemony 发布
还有没有其它方法可以准确的获得CPU主频


雪    币: 560
活跃值: (309)
能力值: ( LV13,RANK:1370 )
在线值:
发帖
回帖
粉丝
laomms 34 2006-6-11 14:00
12
0
VB Inlineasm实现:
Private Sub Command1_Click()
    Dim myLong(2) As Long
    Dim I As Long
    Dim lngPointer1 As Long, lngPointer2 As Long, lngPointer3 As Long
    Dim lngCPUFeatures(4) As Long, lngCacheInfo(4) As Long
    lngPointer1 = VarPtr(myLong(0))
    lngPointer2 = VarPtr(lngCPUFeatures(0))
    lngPointer3 = VarPtr(lngCacheInfo(0))
   
    Text1.Text = asmCPUID(lngPointer1, lngPointer2, lngPointer3)
End Sub

=================ASM Module================
Public Function asmCPUID(ByVal lngPointer1 As Long, ByVal lngPointer2 As Long, ByVal lngPointer3 As Long) As Long
'#ASM_START
'.686

' push ebp
' mov ebp, esp

' push ecx
' push edx
' push edi

' mov eax, 0
' CPUID
'
' mov edi, DWORD PTR [ebp+8]
' mov [edi], ebx
'
' mov edi, DWORD PTR [ebp+8]
' Add edi, 4
' mov [edi], edx
'
' mov edi, DWORD PTR [ebp+8]
' Add edi, 8
' mov [edi], ecx
' ;\
';-------------------------------------------------------------------------------------
' cmp eax, 0
' je ExitASM
'
';-------------------------------------------------------------------------------------
'
' mov eax, 1
' CPUID
'
' mov edi, [ebp+12] ;//Pointer to array2
' mov [edi], eax
'
' Add edi, 4
' mov [edi], ebx
'
' Add edi, 4
' mov [edi], ecx
'
' Add edi, 4
' mov [edi], edx
'
';----------------
' mov eax, 0
' CPUID
'
' cmp eax, 1
' jng ExitASM
' mov eax, 2
' CPUID
'
' mov edi, [ebp+16]
' mov [edi], eax
'
' Add edi, 4
' mov [edi], ebx
'
' Add edi, 4
' mov [edi], ecx
'
' Add edi, 4
' mov [edi], edx
';-----------------
'ExitASM:
' pop edi
' pop edx
' pop ecx

' mov esp, ebp
' pop ebp
' ret 12
'#ASM_END
End Function
上传的附件:
游客
登录 | 注册 方可回帖
返回