-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d943bb7
commit 41f62f3
Showing
3 changed files
with
156 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using System.Management; | ||
using System.Text; | ||
|
||
namespace Chaos.NaCl.Benchmark | ||
{ | ||
class Cpu | ||
{ | ||
public static uint CpuFreq = GetMaxCpuFreq(); | ||
|
||
private const uint CpuFreqFallback = 2901; | ||
|
||
public static void Setup() | ||
{ | ||
Process.GetCurrentProcess().ProcessorAffinity = (IntPtr)1; | ||
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime; | ||
} | ||
|
||
private static uint GetCpuFreq(string name) | ||
{ | ||
try | ||
{ | ||
using (ManagementBaseObject mo = new ManagementObject("Win32_Processor.DeviceID='CPU0'")) | ||
{ | ||
return (uint)(mo[name]); | ||
} | ||
} | ||
catch (Exception) | ||
{ | ||
Console.WriteLine("Could not get CPU Frequency"); | ||
return CpuFreqFallback; | ||
} | ||
} | ||
|
||
static uint GetCurrentCpuFreq() | ||
{ | ||
return GetCpuFreq("CurrentClockSpeed"); | ||
} | ||
|
||
public static uint GetMaxCpuFreq() | ||
{ | ||
return GetCpuFreq("MaxClockSpeed"); | ||
} | ||
|
||
public static void CheckCurrentCpuFreq() | ||
{ | ||
var currentFreq = GetCurrentCpuFreq(); | ||
if (currentFreq != CpuFreq) | ||
Console.WriteLine("Current CPU-Frequency: {0} MHz differs from max", currentFreq); | ||
} | ||
} | ||
} |