private void timer1_Tick(object sender, EventArgs e) { if (monitorPstates) { //K10Manager.ResetEffFreq(); int currentNbPState = K10Manager.GetNbPState(); nbBar.Value = (2 - currentNbPState) * 50; nbPstateLabel.Text = currentNbPState.ToString() + " - " + freq[currentNbPState + 8].ToString() + "MHz"; // get the current P-state of the first core for (int i = 0; i < numCores; i++) { currentPStateCore[i] = K10Manager.GetCurrentPState(i); if (i == 0) { cpu1Bar.Value = (processBarSteps - currentPStateCore[i]) * (processBarPerc); pstateLabel1.Text = currentPStateCore[i].ToString() + " - " + freq[currentPStateCore[i]].ToString() + "MHz"; } else if (i == 1) { cpu2Bar.Value = (processBarSteps - currentPStateCore[i]) * (processBarPerc); pstateLabel2.Text = currentPStateCore[i].ToString() + " - " + freq[currentPStateCore[i]].ToString() + "MHz"; } else if (i == 2) { cpu3Bar.Value = (processBarSteps - currentPStateCore[i]) * (processBarPerc); pstateLabel3.Text = currentPStateCore[i].ToString() + " - " + freq[currentPStateCore[i]].ToString() + "MHz"; } else if (i == 3) { cpu4Bar.Value = (processBarSteps - currentPStateCore[i]) * (processBarPerc); pstateLabel4.Text = currentPStateCore[i].ToString() + " - " + freq[currentPStateCore[i]].ToString() + "MHz"; } } //RealFreq.SuspendLayout(); //RealFreq.Text = K10Manager.EffFreq().ToString(); //RealFreq.ResumeLayout(); } }
/// <summary> /// Saves the P-state to the cores' and NB MSRs. /// </summary> /// <param name="index">Index of the hardware P-state (0-4) to be modified. Adding NB P-state (8,9)</param> public void Save(int index) { //Brazos merge next line from BT //if (index < 0 || index > 4) if (index < 0 || index > 9) { throw new ArgumentOutOfRangeException("index"); } if (index < 8) //dealing with CPU P-States { uint msrIndex = 0xC0010064u + (uint)index; //Brazos merge next line commented out in BT int boostedStates = K10Manager.GetNumBoostedStates(); //Brazos merge next line active in BT //int boostedStates = 0; int indexSw = Math.Max(0, index - boostedStates); //Brazos merge next line active in BT //int tempPStateHw = (index <= boostedStates ? _maxPstate : 0); int tempPStateHw = (index <= boostedStates ? K10Manager.GetHighestPState() : 0); int tempPStateSw = Math.Max(0, tempPStateHw - boostedStates); // switch temporarily to the highest thread priority // (we try not to interfere with any kind of C&Q) var previousPriority = Thread.CurrentThread.Priority; Thread.CurrentThread.Priority = ThreadPriority.Highest; bool[] applyImmediately = new bool[_numCores]; for (int i = 0; i < _numCores; i++) { applyImmediately[i] = (K10Manager.GetCurrentPState(i) == index); // if the settings are to be applied immediately, switch temporarily to another P-state if (applyImmediately[i]) { K10Manager.SwitchToPState(tempPStateSw, i); } } Thread.Sleep(3); // let transitions complete for (int i = 0; i < _numCores; i++) { // save the new settings ulong msr = Program.Ols.ReadMsr(msrIndex, i); ulong mask = 0xFE00FFFFu; //Brazos + Llano Bits 15 .. 0 Vid + Mult if (Form1.family == 16) { mask = 0xFE01FFFFu; //Kabini Bits 16 .. 0 Vid + Mult msr = (msr & ~mask) | (_msrs[i].Encode(index) & mask); Program.Ols.WriteMsr(msrIndex, msr, i); } else { msr = (msr & ~mask) | (_msrs[i].Encode(index) & mask); Program.Ols.WriteMsr(msrIndex, msr, i); } // apply the new settings by switching back if (applyImmediately[i]) { K10Manager.SwitchToPState(indexSw, i); } } Thread.Sleep(3); // let transitions complete Thread.CurrentThread.Priority = previousPriority; } else if (index == 8 || index == 9) //dealing with NB P-State 0 { if (Form1.family == 16) //Kabini { // switch temporarily to the highest thread priority // (we try not to interfere with any kind of C&Q) var previousPriority = Thread.CurrentThread.Priority; Thread.CurrentThread.Priority = ThreadPriority.Highest; //check, if current NB P-State is the one, which is going to be modified //Brazos merge next line from BT index = index - 8; int curNbstate = K10Manager.GetNbPState(); int maxPstate = K10Manager.GetCurHighestPState(); if (index == 0) // NB P-state0 { for (int i = 0; i < _numCores; i++) { K10Manager.SwitchToPState(maxPstate, i); //switches to slowest core pstate to get to slowest NB pstate } Thread.Sleep(3); // let transitions complete //Kabini 16h //D18F5x160 NB P-state 0 //D18F5x164 NB P-state 1 //21 NbVid[7]. //16:10 NbVid[6:0]: Northbridge VID // save the new settings uint config = Program.Ols.ReadPciConfig(0xC5, 0x160); const uint mask = 0x0021F800; //enable overwrite of Vid only config = (config & ~mask) | (_msrs[0].Encode(index + 8) & mask); Program.Ols.WritePciConfig(0xC5, 0x160, config); for (int i = 0; i < _numCores; i++) { K10Manager.SwitchToPState(0, i); //switches to fastest core pstate to get to fastest NB pstate } Thread.Sleep(3); // let transitions complete } else if (index == 1) { for (int i = 0; i < _numCores; i++) { K10Manager.SwitchToPState(0, i); //switches to fastest core pstate to get to fastest NB pstate } Thread.Sleep(3); // let transitions complete // save the new settings uint config = Program.Ols.ReadPciConfig(0xC5, 0x164); const uint mask = 0x0021F800; //enable overwrite of Vid only config = (config & ~mask) | (_msrs[0].Encode(index + 8) & mask); Program.Ols.WritePciConfig(0xC5, 0x164, config); for (int i = 0; i < _numCores; i++) { K10Manager.SwitchToPState(maxPstate, i); //switches to slowest core pstate to get to slowest NB pstate } Thread.Sleep(3); // let transitions complete } //MessageBox.Show(message); Thread.CurrentThread.Priority = previousPriority; } else //Brazos + Llano { // switch temporarily to the highest thread priority // (we try not to interfere with any kind of C&Q) var previousPriority = Thread.CurrentThread.Priority; Thread.CurrentThread.Priority = ThreadPriority.Highest; //check, if current NB P-State is the one, which is going to be modified index = index - 8; int curNbstate = K10Manager.GetNbPState(); string message = "Start: " + curNbstate + "\n"; int changedNbstate = curNbstate; bool applyImmediately = (curNbstate != index); K10Manager.EnableNBPstateSwitching(); applyImmediately = (curNbstate != index); // if the settings are to be applied immediately, switch temporarily to another P-state if (applyImmediately) { K10Manager.SwitchToNbPState(index); for (int i = 0; i < 10; i++) { //Brazos merge BT uses Sleep 100 and i=1000 Thread.Sleep(20); // let transitions complete changedNbstate = K10Manager.GetNbPState(); if (changedNbstate == index) { message += "Time_init_switch: " + i + "\n"; i = 10; } } } curNbstate = K10Manager.GetNbPState(); if (index == 0) // NB P-state0 { // save the new settings uint config = Program.Ols.ReadPciConfig(0xC3, 0xDC); const uint mask = 0x0007F000; //enable overwrite of Vid only config = (config & ~mask) | (_msrs[0].Encode(index + 8) & mask); uint voltage = Program.Ols.ReadPciConfig(0xC3, 0x15C); const uint maskvolt = 0x00007F00; uint check = _msrs[0].Encode(index + 8) >> 12 & 0x7F; voltage = (voltage & ~maskvolt) | ((check << 8) & maskvolt); Program.Ols.WritePciConfig(0xC3, 0xDC, config); Program.Ols.WritePciConfig(0xC3, 0x15C, voltage); } else if (index == 1) { // save the new settings uint config = Program.Ols.ReadPciConfig(0xC6, 0x90); const uint mask = 0x00007F00; //enable VID modification only config = (config & ~mask) | (_msrs[0].Encode(index + 8) & mask); uint voltage = Program.Ols.ReadPciConfig(0xC3, 0x15C); const uint maskvolt = 0x0000007F; uint check = _msrs[0].Encode(index + 8) >> 8; voltage = (voltage & ~maskvolt) | (check & maskvolt); Program.Ols.WritePciConfig(0xC6, 0x90, config); Program.Ols.WritePciConfig(0xC3, 0x15C, voltage); } curNbstate = K10Manager.GetNbPState(); if (curNbstate == 0) { K10Manager.SwitchToNbPState(1); for (int i = 0; i < 10; i++) { //Brazos merge BT uses Sleep 100 and i=1000 Thread.Sleep(20); // let transitions complete changedNbstate = K10Manager.GetNbPState(); if (changedNbstate == 1) { message += "Time_P0_P1: " + i + "\n"; i = 10; } } K10Manager.SwitchToNbPState(0); for (int i = 0; i < 10; i++) { //Brazos merge BT uses Sleep 100 and i=1000 Thread.Sleep(20); // let transitions complete changedNbstate = K10Manager.GetNbPState(); if (changedNbstate == 0) { message += "Time_P1_P0: " + i + "\n"; i = 10; } } } else if (curNbstate == 1) { K10Manager.SwitchToNbPState(0); for (int i = 0; i < 10; i++) { //Brazos merge BT uses Sleep 100 and i=1000 Thread.Sleep(20); // let transitions complete changedNbstate = K10Manager.GetNbPState(); if (changedNbstate == 0) { message += "Time_P1_P0: " + i + "\n"; i = 10; } } K10Manager.SwitchToNbPState(1); for (int i = 0; i < 10; i++) { //Brazos merge BT uses Sleep 100 and i=1000 Thread.Sleep(20); // let transitions complete changedNbstate = K10Manager.GetNbPState(); if (changedNbstate == 1) { message += "Time_P0_P1: " + i + "\n"; i = 10; } } } //K10Manager.ExitDramSelfRefresh(); //K10Manager.EnDllShutDown(); K10Manager.DisableNBPstateSwitching(); //MessageBox.Show(message); Thread.CurrentThread.Priority = previousPriority; } } }