Esempio n. 1
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (monitorPstates)
            {
                int currentNbPState = K10Manager.GetNbPState();
                nbBar.Value        = (2 - currentNbPState) * 50;
                nbPstateLabel.Text = currentNbPState.ToString() + " - " + freq[currentNbPState + 3].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";
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Saves the P-state to the cores' MSRs.
        /// </summary>
        /// <param name="index">Index of the hardware P-state (0-4) to be modified.</param>
        public void Save(int index)
        {
            if (index < 0 || index > 4)
            {
                throw new ArgumentOutOfRangeException("index");
            }

            if (index < 3) //dealing with CPU P-States
            {
                uint msrIndex = 0xC0010064u + (uint)index;

                //int boostedStates = K10Manager.GetNumBoostedStates();
                int boostedStates = 0;
                int indexSw       = Math.Max(0, index - boostedStates);

                int tempPStateHw = (index <= boostedStates ? _maxPstate : 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);
                    const ulong mask = 0xFE00FFFFu;
                    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 == 3 || index == 4)   //dealing with NB P-State 0
            {
                // 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 - 3;
                int curNbstate = K10Manager.GetNbPState();

                string message = "Start: " + curNbstate;

                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++)
                    {
                        Thread.Sleep(100); // let transitions complete
                        changedNbstate = K10Manager.GetNbPState();
                        if (changedNbstate == index)
                        {
                            message += " Time_init_switch: " + i;
                            i        = 1000;
                        }
                    }
                }

                curNbstate = K10Manager.GetNbPState();

                if (index == 0) // NB P-state0
                {
                    //DRAM needs to be set into SelfRefresh
                    //K10Manager.DisDllShutDown();
                    //K10Manager.EnterDramSelfRefresh(); //NB Pstate HW switching needs to be disabled before NbPsCtrDis
                    // save the new settings
                    uint config = Program.Ols.ReadPciConfig(0xC3, 0xDC);
                    //const uint mask = 0x07F7F000; //enable overwrite of Vid and Div
                    const uint mask = 0x0007F000; //enable overwrite of Vid only
                    config = (config & ~mask) | (_msrs[0].Encode(index + 3) & mask);
                    uint voltage = Program.Ols.ReadPciConfig(0xC3, 0x15C);
                    //const uint maskvolt = 0x00007F00;
                    const uint maskvolt = 0x7F7F7F00; //overwriting VIDSelect2 and 3 in addition
                    uint       check    = _msrs[0].Encode(index + 3) >> 12 & 0x7F;
                    voltage = (voltage & ~maskvolt) | ((check << 24) | (check << 16) | (check << 8) & maskvolt);

                    Program.Ols.WritePciConfig(0xC3, 0xDC, config);
                    Program.Ols.WritePciConfig(0xC3, 0x15C, voltage);
                }
                else if (index == 1)
                {
                    // save the new settings
                    //K10Manager.DisDllShutDown();
                    //K10Manager.EnterDramSelfRefresh(); //NB Pstate HW switching needs to be disabled before NbPsCtrDis
                    uint config = Program.Ols.ReadPciConfig(0xC6, 0x90);
                    //const uint mask = 0x00007F7F; //enable DID and VID modification
                    const uint mask = 0x00007F00; //enable VID modification only
                    config = (config & ~mask) | (_msrs[0].Encode(index + 3) & mask);
                    uint       voltage  = Program.Ols.ReadPciConfig(0xC3, 0x15C);
                    const uint maskvolt = 0x0000007F;
                    uint       check    = _msrs[0].Encode(index + 3) >> 8;
                    voltage = (voltage & ~maskvolt) | (check & maskvolt);

                    Program.Ols.WritePciConfig(0xC6, 0x90, config);
                    Program.Ols.WritePciConfig(0xC3, 0x15C, voltage);
                }

                if (curNbstate == 0)
                {
                    K10Manager.SwitchToNbPState(1);
                    for (int i = 0; i < 10; i++)
                    {
                        Thread.Sleep(100); // let transitions complete
                        changedNbstate = K10Manager.GetNbPState();
                        if (changedNbstate == 1)
                        {
                            message += " Time_P0_P1: " + i;
                            i        = 1000;
                        }
                    }
                    K10Manager.SwitchToNbPState(0);
                    for (int i = 0; i < 10; i++)
                    {
                        Thread.Sleep(100); // let transitions complete
                        changedNbstate = K10Manager.GetNbPState();
                        if (changedNbstate == 0)
                        {
                            message += " Time_P1_P0: " + i;
                            i        = 1000;
                        }
                    }
                }
                else if (curNbstate == 1)
                {
                    K10Manager.SwitchToNbPState(0);
                    for (int i = 0; i < 10; i++)
                    {
                        Thread.Sleep(100); // let transitions complete
                        changedNbstate = K10Manager.GetNbPState();
                        if (changedNbstate == 0)
                        {
                            message += " Time_P1_P0: " + i;
                            i        = 1000;
                        }
                    }
                    K10Manager.SwitchToNbPState(1);
                    for (int i = 0; i < 10; i++)
                    {
                        Thread.Sleep(100); // let transitions complete
                        changedNbstate = K10Manager.GetNbPState();
                        if (changedNbstate == 1)
                        {
                            message += " Time_P0_P1: " + i;
                            i        = 1000;
                        }
                    }
                }

                //K10Manager.ExitDramSelfRefresh();
                //K10Manager.EnDllShutDown();

                K10Manager.DisableNBPstateSwitching();
                //MessageBox.Show(message);
                Thread.CurrentThread.Priority = previousPriority;
            }
        }