View Issue Details

IDProjectCategoryView StatusLast Update
0000801JEDI Code LibraryJclSysInfopublic2005-02-16 01:34
Reportersnoopy_spyAssigned ToRobert Rossmair 
PrioritynormalSeveritymajorReproducibilitysometimes
Status closedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0000801: JclSysInfo.GetCPUSpeed - division by zero
DescriptionWith my new PC (3.06 GB HT) i have the problem that in the loop the calculated Ticks sometime only reach 0


Additional Informationfunction GetCPUSpeed(var CpuSpeed: TFreqInfo): Boolean;
var
  T0, T1: TULargeInteger;
  CountFreq: TULargeInteger;
  Freq, Freq2, Freq3, Total: Integer;
  TotalCycles, Cycles: Int64;
  Stamp0, Stamp1: Int64;
  TotalTicks, Ticks: Cardinal;
  Tries, Priority: Integer;
  Thread: THandle;
begin
  Stamp0 := 0;
  Stamp1 := 0;
  Freq := 0;
  Freq2 := 0;
  Freq3 := 0;
  Tries := 0;
  TotalCycles := 0;
  TotalTicks := 0;
  Total := 0;

  Thread := GetCurrentThread();
  Result := QueryPerformanceFrequency(Int64(CountFreq));
  if Result then
  begin
    while ((Tries < 3 ) or ((Tries < 20) and ((Abs(3 * Freq - Total) > 3) or
      (Abs(3 * Freq2 - Total) > 3) or (Abs(3 * Freq3 - Total) > 3)))) do
    begin
      Inc(Tries);
      Freq3 := Freq2;
      Freq2 := Freq;
      QueryPerformanceCounter(Int64(T0));
      T1.LowPart := T0.LowPart;
      T1.HighPart := T0.HighPart;

      Priority := GetThreadPriority(Thread);
      if Priority <> THREAD_PRIORITY_ERROR_RETURN then
        SetThreadPriority(Thread, THREAD_PRIORITY_TIME_CRITICAL);
      try
        while (T1.LowPart - T0.LowPart) < 50 do
        begin
          QueryPerformanceCounter(Int64(T1));
          Stamp0 := ReadTimeStampCounter;
        end;
        T0.LowPart := T1.LowPart;
        T0.HighPart := T1.HighPart;

        while (T1.LowPart - T0.LowPart) < 1000 do
        begin
          QueryPerformanceCounter(Int64(T1));
          Stamp1 := ReadTimeStampCounter;
        end;
      finally
        if Priority <> THREAD_PRIORITY_ERROR_RETURN then
          SetThreadPriority(Thread, Priority);
      end;

      Cycles := Stamp1 - Stamp0;
      Ticks := T1.LowPart - T0.LowPart;
      Ticks := Ticks * 100000;
      Ticks := Round(Ticks / (CountFreq.LowPart / 10));
      TotalTicks := TotalTicks + Ticks;
      TotalCycles := TotalCycles + Cycles;
      if Ticks > 0 then
          Freq := Round(Cycles / Ticks); <= Here is the division by zero !!!
      Total := Freq + Freq2 + Freq3;
TagsNo tags attached.
Fixed in GIT commit
Fixed in SVN revision
IDE version

Relationships

duplicate of 0000401 closedRobert Rossmair ERangeError in GetCPUSpeed 
has duplicate 0002112 closedmthoma Floating point division by zero (GetCpuSpeed) 

Activities

Robert Rossmair

2003-06-28 12:59

developer   ~0002272

See 0000401 for fixed JclSysInfo.pas

Issue History

Date Modified Username Field Change
2004-09-03 10:03 Robert Rossmair Relationship added has duplicate 0002112
2005-02-16 01:34 Robert Rossmair Status resolved => closed