示例#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";
                    }
                }
            }
        }
示例#2
0
        public ServiceDialog(System.Drawing.Icon icon)
        {
            InitializeComponent();

            this.Icon = icon;

            makePermanentCheckBox.CheckedChanged += (s, e) => updateButton.Enabled = makePermanentCheckBox.Checked;
            turboCheckBox.CheckedChanged         += (s, e) =>
            {
                if (turboCheckBox.Checked)
                {
                    enableCustomCnQCheckBox.Checked = false;
                    enableCustomCnQCheckBox.Enabled = false;
                }
                else
                {
                    enableCustomCnQCheckBox.Enabled = true;
                }
            };
            enableCustomCnQCheckBox.CheckedChanged += (s, e) => tabControl1.Enabled = enableCustomCnQCheckBox.Checked;

            // select the current P-state settings as default settings
            updateButton_Click(updateButton, EventArgs.Empty);

            turboCheckBox.Enabled = K10Manager.IsTurboSupported();
            turboCheckBox.Checked = K10Manager.IsTurboSupported();

            balancedProfileControl.LoadFromRegistry();
            highPerformanceProfileControl.LoadFromRegistry();
            powerSaverProfileControl.LoadFromRegistry();

            var key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"Software\BrazosTweaker");

            if (key == null)
            {
                return;
            }

            for (int i = 0; i < (_maxPstate + 1); i++)
            {
                string text = (string)key.GetValue("P" + i);
                _pStates[i] = PState.Decode(text, i);
            }
            for (int i = 3; i < 5; i++)
            {
                string text = (string)key.GetValue("P" + i);
                _pStates[i] = PState.Decode(text, i);
            }

            RefreshPStatesLabel();

            makePermanentCheckBox.Checked = ((int)key.GetValue("EnableCustomPStates", 0) != 0);

            enableCustomCnQCheckBox.Checked = ((int)key.GetValue("EnableCustomCnQ", 0) != 0);

            key.Close();
        }
示例#3
0
        private void timer2_Tick(object sender, EventArgs e)
        {
            ecread.SuspendLayout();
            ecread.Text = statusinfo.GetECreadings();
            ecread.ResumeLayout();

            nbCfgTemp.SuspendLayout();
            nbCfgTemp.Text = K10Manager.GetTemp().ToString() + "°C";
            nbCfgTemp.ResumeLayout();

            //tabControl1.SuspendLayout();
            //statusinfo.LoadFromHardware();
            //tabControl1.ResumeLayout();
        }
示例#4
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public PStateControl()
        {
            InitializeComponent();


            // check if the CPU's maximum multi is limited (non Black Edition CPUs)
            if (_maxCOF < 0)
            {
                // in DesignMode, Program.Ols is null
                if (Program.Ols == null)
                {
                    _maxCOF    = 31.5;
                    _minVid    = 0.0125;
                    _maxVid    = 1.55;
                    _maxPstate = -1;
                }
                else
                {
                    _maxCOF    = K10Manager.MaxCOF();
                    _maxPstate = K10Manager.GetHighestPState();

                    //double _curDiv = K10Manager.CurrCOF();
                    //uint MainDivEn = K10Manager.MainCofEn();
                    K10Manager.GetVidLimits(out _minVid, out _maxVid);
                }
            }

            VidNumericUpDown.Minimum = (decimal)_minVid;
            CLKNumericUpDown.Minimum = 0;
            VidNumericUpDown.Maximum = (decimal)_maxVid;
            CLKNumericUpDown.Maximum = 200;

            // add as many NumericUpDown controls as there are CPU cores for the multis
            for (int i = 0; i < _numCores; i++)
            {
                var control = new NumericUpDown()
                {
                    AutoSize      = true,
                    DecimalPlaces = 2,
                    Increment     = (decimal)0.25,
                    Maximum       = (decimal)_maxCOF,
                    Minimum       = 1,
                    TabIndex      = i,
                    TextAlign     = HorizontalAlignment.Center,
                    Value         = 4,
                };
                toolTip1.SetToolTip(control, "Divider for core " + (i + 1) + ".\r\nReference clock (default: 100 MHz) times " + (_maxCOF + 16) + " divided by the chosen value yields the core speed.");

                control.ValueChanged += (s, e) => _modified = true;

                if (i == 0)
                {
                    control.ValueChanged += (s, e) =>
                    {
                        for (int j = 1; j < _numCores; j++)
                        {
                            var otherControl = (NumericUpDown)flowLayoutPanel1.Controls[j];
                            otherControl.Value = control.Value;
                        }
                    };
                }

                flowLayoutPanel1.Controls.Add(control);
            }

            VidNumericUpDown.ValueChanged += (s, e) => _modified = true;
            CLKNumericUpDown.ValueChanged += (s, e) => _modified = true;

            // set the tab order
            VidNumericUpDown.TabIndex = 3 + _numCores;
            CLKNumericUpDown.TabIndex = VidNumericUpDown.TabIndex + 1;
            refreshButton.TabIndex    = CLKNumericUpDown.TabIndex + 1;

            // compute the optimal width, based on the number of cores
            _optimalWidth = Cofstate.Width + Cofstate.Margin.Horizontal + flowLayoutPanel1.Controls.Count *
                            (flowLayoutPanel1.Controls[0].Width + flowLayoutPanel1.Controls[0].Margin.Horizontal) + 70;

            refreshButton.Click += (s, e) => LoadFromHardware(_index);
        }
示例#5
0
        /// <summary>
        /// Loads the P-state settings from each core's MSR.
        /// </summary>
        public void LoadFromHardware(int pstatetab)
        {
            if (_index < 0)
            {
                throw new InvalidOperationException("The PStateIndex property needs to be initialized first.");
            }

            if (pstatetab < 3)            //hardware loads for CPU
            {
                if (_index <= _maxPstate) //skip, in case just 2 CPU PStates are initialized
                {
                    _pState = PState.Load(_index);

                    double maxCpuVid = 0;
                    for (int i = 0; i < _pState.Msrs.Length; i++)
                    {
                        var msr = _pState.Msrs[i];

                        var control = (NumericUpDown)flowLayoutPanel1.Controls[i];
                        control.Value = (decimal)msr.Divider;

                        maxCpuVid = Math.Max(maxCpuVid, msr.Vid);
                    }

                    VidNumericUpDown.Value = Math.Min(VidNumericUpDown.Maximum, (decimal)maxCpuVid);
                    //int check = K10Manager.SetBIOSBusSpeed(80);
                    CLKNumericUpDown.Value = (decimal)K10Manager.GetBIOSBusSpeed();
                    pllfreq.Text           = "P" + _index + " Freq (CPU): " + (int)_pState.Msrs[0].PLL + "MHz";
                    Cofstate.Text          = "Mult = " + (K10Manager.CurrCOF() + 16) + " divided by ->";
                    Form1.freq[pstatetab]  = (int)_pState.Msrs[0].PLL;
                }
                else
                {
                    VidNumericUpDown.Value = (decimal)0.4;
                    CLKNumericUpDown.Value = 100;
                }
            }
            else if (pstatetab == 3)
            {
                //hardware loads for NB P0
                _pState = PState.Load(_index);
                var control = (NumericUpDown)flowLayoutPanel1.Controls[0];
                control.Value          = (decimal)K10Manager.GetNbDivPState0();
                VidNumericUpDown.Value = (decimal)(1.55 - 0.0125 * K10Manager.GetNbVidPState0());
                CLKNumericUpDown.Value = (decimal)K10Manager.GetBIOSBusSpeed();
                pllfreq.Text           = "P" + (_index - 3) + " Freq (GPU): " + (int)_pState.Msrs[0].PLL + "MHz";
                Cofstate.Text          = "Mult = " + (K10Manager.CurrCOF() + 16) + " divided by ->";
                Form1.freq[pstatetab]  = (int)_pState.Msrs[0].PLL;
            }
            else if (pstatetab == 4)
            {
                //hardware loads for NB P0
                _pState = PState.Load(_index);
                var control = (NumericUpDown)flowLayoutPanel1.Controls[0];
                control.Value          = (decimal)K10Manager.GetNbDivPState1();
                VidNumericUpDown.Value = (decimal)(1.55 - 0.0125 * K10Manager.GetNbVidPState1());
                CLKNumericUpDown.Value = (decimal)K10Manager.GetBIOSBusSpeed();
                pllfreq.Text           = "P" + (_index - 3) + " Freq (GPU): " + (int)_pState.Msrs[0].PLL + "MHz";
                Cofstate.Text          = "Mult = " + (K10Manager.CurrCOF() + 16) + " divided by ->";
                Form1.freq[pstatetab]  = (int)_pState.Msrs[0].PLL;
            }
            else if (pstatetab == 5) //settings for displaying registers
            {
                VidNumericUpDown.Value = 1;
                CLKNumericUpDown.Value = 100;
            }
            _modified = false;
        }
示例#6
0
        private void applyButton_Click(object sender, EventArgs e)
        {
            var key = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@"Software\BrazosTweaker");

            key.SetValue("EnableCustomPStates", (makePermanentCheckBox.Checked ? 1 : 0));

            if (makePermanentCheckBox.Checked)
            {
                for (int i = 0; i < (K10Manager.GetHighestPState() + 1); i++)                 //this is the part, where the CPU PStates are handled
                {
                    string valueName = "P" + i;

                    if (_pStates[i] != null)
                    {
                        key.SetValue(valueName, _pStates[i].Encode(i));
                    }
                    else
                    {
                        key.DeleteValue(valueName, false);
                    }
                }
                for (int i = 3; i < 5; i++) //this is the part for the NB PStates
                {
                    string valueName = "P" + i;

                    if (_pStates[i] != null)
                    {
                        key.SetValue(valueName, _pStates[i].Encode(i));
                    }
                    else
                    {
                        key.DeleteValue(valueName, false);
                    }
                }
            }

            key.SetValue("EnableCustomCnQ", (enableCustomCnQCheckBox.Checked ? 1 : 0));
            key.Close();

            if (enableCustomCnQCheckBox.Checked)
            {
                balancedProfileControl.Save();
                highPerformanceProfileControl.Save();
                powerSaverProfileControl.Save();
            }

            try
            {
                serviceController1.Refresh();
                var status = serviceController1.Status;
                if (status != ServiceControllerStatus.Stopped && status != ServiceControllerStatus.StopPending)
                {
                    serviceController1.Stop();
                }

                Cursor = Cursors.WaitCursor;
                serviceController1.WaitForStatus(ServiceControllerStatus.Stopped);
                serviceController1.Start();
                Cursor = Cursors.Default;

                Applied = true;
            }
            catch (Exception exception)
            {
                Cursor = Cursors.Default;

                MessageBox.Show("The service could not be (re)started:\n\n" + exception.Message,
                                "BrazosTweaker", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#7
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;
            }
        }
示例#8
0
        public static PStateMsr Decode(uint value, int pstate)
        {
            //uint maxDiv = (uint)K10Manager.MaxCOF();
            uint maxDiv = (uint)K10Manager.CurrCOF();
            uint clk    = (uint)K10Manager.GetBIOSBusSpeed();
            bool turbo  = K10Manager.IsTurboSupported();

            if (pstate < 3)
            {
                if (pstate <= K10Manager.GetHighestPState())
                {
                    uint cpuDidLSD = (value >> 0) & 0x0F;
                    uint cpuDidMSD = (value >> 4) & 0x1F;
                    uint cpuVid    = (value >> 9) & 0x7F;

                    double Div    = cpuDidMSD + (cpuDidLSD * 0.25) + 1;
                    double DivPLL = cpuDidMSD + (cpuDidLSD * 0.25) + 1;
                    if (maxDiv == 16 && Div < 2) //E-350 seems to restrict PLL frequencies higher than 1.6GHz
                    {
                        DivPLL = 2;
                    }
                    else if (maxDiv == 24 && Div < 4 && !turbo) //C-50 seems to restrict PLL frequencies higher than 1.0GHz
                    {
                        DivPLL = 4;
                    }
                    else if (maxDiv == 24 && Div < 3 && turbo) //C-60 (with turbo seems to restrict PLL frequencies higher than 1.33GHz
                    {
                        DivPLL = 3;
                    }

                    var msr = new PStateMsr()
                    {
                        Divider = Div,
                        Vid     = 1.55 - 0.0125 * cpuVid,
                        CLK     = clk,
                        PLL     = (16 + maxDiv) / DivPLL * clk
                    };
                    return(msr);
                }
                else
                {
                    var msr = new PStateMsr()
                    {
                        Divider = 10,
                        Vid     = 0.4,
                        CLK     = 100,
                        PLL     = 1000
                    };
                    return(msr);
                }
            }
            else if (pstate == 3)
            {
                uint   nclk    = ((value >> 20) & 0x7F);
                uint   nbVid   = ((value >> 12) & 0x7F);
                double nclkdiv = 1;
                //NCLK Div 2-16 ind 0.25 steps / Div 16-32 in 0.5 steps / Div 32-63 in 1.0 steps
                if (nclk >= 8 && nclk <= 63)
                {
                    nclkdiv = nclk * 0.25;
                }
                else if (nclk >= 64 && nclk <= 95)
                {
                    nclkdiv = (nclk - 64) * 0.5 - 16;
                }
                else if (nclk >= 96 && nclk <= 127)
                {
                    nclkdiv = nclk - 64;
                }
                else
                {
                    nclkdiv = 1;
                }
                var msr = new PStateMsr()
                {
                    Divider = nclkdiv,
                    Vid     = 1.55 - 0.0125 * nbVid,
                    CLK     = clk,
                    PLL     = (16 + maxDiv) / nclkdiv * clk
                };
                return(msr);
            }
            else if (pstate == 4)
            {
                uint   nclk    = ((value >> 0) & 0x7F);
                uint   nbVid   = ((value >> 8) & 0x7F);
                double nclkdiv = 1;
                //NCLK Div 2-16 ind 0.25 steps / Div 16-32 in 0.5 steps / Div 32-63 in 1.0 steps
                if (nclk >= 8 && nclk <= 63)
                {
                    nclkdiv = nclk * 0.25;
                }
                else if (nclk >= 64 && nclk <= 95)
                {
                    nclkdiv = (nclk - 64) * 0.5 - 16;
                }
                else if (nclk >= 96 && nclk <= 127)
                {
                    nclkdiv = nclk - 64;
                }
                else
                {
                    nclkdiv = 1;
                }
                var msr = new PStateMsr()
                {
                    Divider = nclkdiv,
                    Vid     = 1.55 - 0.0125 * nbVid,
                    CLK     = clk,
                    PLL     = (16 + maxDiv) / nclkdiv * clk
                };
                return(msr);
            }
            else
            {
                var msr = new PStateMsr()
                {
                    Divider = 10,
                    Vid     = 0.4,
                    CLK     = 100,
                    PLL     = 1000
                };
                return(msr);
            }
        }