Skip to content

Commit

Permalink
Initial port of amdmsrtweaker to Linux. (CAUTION: Completely untested!)
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Krampf committed Apr 18, 2013
1 parent f2edb3d commit 37ff883
Show file tree
Hide file tree
Showing 12 changed files with 806 additions and 1,221 deletions.
213 changes: 91 additions & 122 deletions AmdMsrTweaker.cpp
Expand Up @@ -5,8 +5,8 @@
* about permitted and prohibited uses of this code.
*/

#include <cstdio>
#include <iostream>
#include <conio.h>
#include "Info.h"
#include "Worker.h"
#include "WinRing0.h"
Expand All @@ -21,131 +21,100 @@ void WaitForKey();


/// <summary>Entry point for the program.</summary>
int main(int argc, const char* argv[])
{
// initialize WinRing0
if (!InitializeOls() || GetDllStatus() != 0)
{
cerr << "ERROR: WinRing0 initialization failed" << endl;
DeinitializeOls();

return 1;
}

try
{
Info info;
if (!info.Initialize())
{
cout << "ERROR: unsupported CPU" << endl;
DeinitializeOls();
WaitForKey();
return 2;
}

if (argc > 1)
{
Worker worker(info);

if (!worker.ParseParams(argc, argv))
{
DeinitializeOls();
WaitForKey();
return 3;
}

worker.ApplyChanges();
}
else
{
PrintInfo(info);
WaitForKey();
}
}
catch (const std::exception& e)
{
cerr << "ERROR: " << e.what() << endl;
DeinitializeOls();
WaitForKey();
return 10;
}

DeinitializeOls();

return 0;
int main(int argc, const char* argv[]) {
try {
Info info;
if (!info.Initialize()) {
cout << "ERROR: unsupported CPU" << endl;
WaitForKey();
return 2;
}

if (argc > 1) {
Worker worker(info);

if (!worker.ParseParams(argc, argv)) {
WaitForKey();
return 3;
}

worker.ApplyChanges();
} else {
PrintInfo(info);
WaitForKey();
}
} catch (const std::exception& e) {
cerr << "ERROR: " << e.what() << endl;
WaitForKey();
return 10;
}

return 0;
}


void PrintInfo(const Info& info)
{
cout << endl;
cout << "AmdMsrTweaker v1.1" << endl;
cout << endl;

cout << ".:. General" << endl << "---" << endl;
cout << " AMD family 0x" << std::hex << info.Family << ", model 0x" << info.Model << std::dec << " CPU, " << info.NumCores << " cores" << endl;
cout << " Default reference clock: " << info.multiScaleFactor * 100 << " MHz" << endl;
cout << " Available multipliers: " << (info.MinMulti / info.multiScaleFactor) << " .. " << (info.MaxSoftwareMulti / info.multiScaleFactor) << endl;
cout << " Available voltage IDs: " << info.MinVID << " .. " << info.MaxVID << " (" << info.VIDStep << " steps)" << endl;
cout << endl;

cout << ".:. Turbo" << endl << "---" << endl;
if (!info.IsBoostSupported)
cout << " not supported" << endl;
else
{
cout << " " << (info.IsBoostEnabled ? "enabled" : "disabled") << endl;
cout << " " << (info.IsBoostLocked ? "locked" : "unlocked") << endl;

if (info.MaxMulti != info.MaxSoftwareMulti)
cout << " Max multiplier: " << (info.MaxMulti / info.multiScaleFactor) << endl;
}
cout << endl;

cout << ".:. P-states" << endl << "---" << endl;
cout << " " << info.NumPStates << " of " << (info.Family == 0x10 ? 5 : 8) << " enabled (P0 .. P" << (info.NumPStates - 1) << ")" << endl;

if (info.IsBoostSupported && info.NumBoostStates > 0)
{
cout << " Turbo P-states:";
for (int i = 0; i < info.NumBoostStates; i++)
cout << " P" << i;
cout << endl;
}

cout << " ---" << endl;

for (int i = 0; i < info.NumPStates; i++)
{
const PStateInfo pi = info.ReadPState(i);

cout << " P" << i << ": " << (pi.Multi / info.multiScaleFactor) << "x at " << info.DecodeVID(pi.VID) << "V" << endl;

if (pi.NBPState >= 0)
{
cout << " NorthBridge in NB_P" << pi.NBPState;
if (pi.NBVID >= 0)
cout << " at " << info.DecodeVID(pi.NBVID) << "V";
cout << endl;
}
}

if (info.Family == 0x15)
{
cout << " ---" << endl;

for (int i = 0; i < info.NumNBPStates; i++)
{
const NBPStateInfo pi = info.ReadNBPState(i);
cout << " NB_P" << i << ": " << pi.Multi << "x at " << info.DecodeVID(pi.VID) << "V" << endl;
}
}
void PrintInfo(const Info& info) {
cout << endl;
cout << "AmdMsrTweaker v1.1" << endl;
cout << endl;

cout << ".:. General" << endl << "---" << endl;
cout << " AMD family 0x" << std::hex << info.Family << ", model 0x" << info.Model << std::dec << " CPU, " << info.NumCores << " cores" << endl;
cout << " Default reference clock: " << info.multiScaleFactor * 100 << " MHz" << endl;
cout << " Available multipliers: " << (info.MinMulti / info.multiScaleFactor) << " .. " << (info.MaxSoftwareMulti / info.multiScaleFactor) << endl;
cout << " Available voltage IDs: " << info.MinVID << " .. " << info.MaxVID << " (" << info.VIDStep << " steps)" << endl;
cout << endl;

cout << ".:. Turbo" << endl << "---" << endl;
if (!info.IsBoostSupported)
cout << " not supported" << endl;
else {
cout << " " << (info.IsBoostEnabled ? "enabled" : "disabled") << endl;
cout << " " << (info.IsBoostLocked ? "locked" : "unlocked") << endl;

if (info.MaxMulti != info.MaxSoftwareMulti)
cout << " Max multiplier: " << (info.MaxMulti / info.multiScaleFactor) << endl;
}
cout << endl;

cout << ".:. P-states" << endl << "---" << endl;
cout << " " << info.NumPStates << " of " << (info.Family == 0x10 ? 5 : 8) << " enabled (P0 .. P" << (info.NumPStates - 1) << ")" << endl;

if (info.IsBoostSupported && info.NumBoostStates > 0) {
cout << " Turbo P-states:";
for (int i = 0; i < info.NumBoostStates; i++)
cout << " P" << i;
cout << endl;
}

cout << " ---" << endl;

for (int i = 0; i < info.NumPStates; i++) {
const PStateInfo pi = info.ReadPState(i);

cout << " P" << i << ": " << (pi.Multi / info.multiScaleFactor) << "x at " << info.DecodeVID(pi.VID) << "V" << endl;

if (pi.NBPState >= 0) {
cout << " NorthBridge in NB_P" << pi.NBPState;
if (pi.NBVID >= 0)
cout << " at " << info.DecodeVID(pi.NBVID) << "V";
cout << endl;
}
}

if (info.Family == 0x15) {
cout << " ---" << endl;

for (int i = 0; i < info.NumNBPStates; i++) {
const NBPStateInfo pi = info.ReadNBPState(i);
cout << " NB_P" << i << ": " << pi.Multi << "x at " << info.DecodeVID(pi.VID) << "V" << endl;
}
}
}


void WaitForKey()
{
cout << endl << "Press any key to exit... ";
_getch();
cout << endl;
void WaitForKey() {
cout << endl << "Press any key to exit... ";
getchar();
cout << endl;
}
26 changes: 0 additions & 26 deletions AmdMsrTweaker.sln

This file was deleted.

0 comments on commit 37ff883

Please sign in to comment.