예제 #1
0
        public Form1()
        {
            InitializeComponent();

            family     = K10Manager.GetFamily();
            numPstates = K10Manager.GetHighestPState();
            clock      = K10Manager.GetBIOSBusSpeed();
            //Brazos merge next line removed in BT
            //numBoostedPstates = K10Manager.GetNumBoostedStates();
            numBoostedPstates = 0;
            processBarSteps   = numPstates + numBoostedPstates + 1;
            processBarPerc    = 100 / processBarSteps;

            if ((family != 12) && (family != 14) && (family != 16))
            {
                MessageBox.Show("Your CPU/APU from AMD family: " + family + "h is not supported!");
            }

            //needed to reduces flickering
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);


            if (numCores == 3)
            {
                this.Controls.Remove(this.pstateLabel4);
                this.Controls.Remove(this.core4label);
                this.Controls.Remove(this.cpu4Bar);
                ShiftTable(-15);
            }
            else if (numCores == 2)
            {
                this.Controls.Remove(this.pstateLabel4);
                this.Controls.Remove(this.core4label);
                this.Controls.Remove(this.cpu4Bar);
                this.Controls.Remove(this.pstateLabel3);
                this.Controls.Remove(this.core3label);
                this.Controls.Remove(this.cpu3Bar);
                ShiftTable(-30);
            }
            else if (numCores == 1)
            {
                this.Controls.Remove(this.pstateLabel4);
                this.Controls.Remove(this.core4label);
                this.Controls.Remove(this.cpu4Bar);
                this.Controls.Remove(this.pstateLabel3);
                this.Controls.Remove(this.core3label);
                this.Controls.Remove(this.cpu3Bar);
                this.Controls.Remove(this.pstateLabel2);
                this.Controls.Remove(this.core2label);
                this.Controls.Remove(this.cpu2Bar);
                ShiftTable(-50);
            }

            notifyIcon.Icon             = this.Icon;
            notifyIcon.ContextMenuStrip = new ContextMenuStrip();
            notifyIcon.Visible          = true;

            if (family == 16)
            {
                //MessageBox.Show("Jetzt wird ein Log für den Editor erstellt!");
                //log_now();
            }
            //Brazos merge next line was active in BT
            //this.Width += p0StateControl.GetDeltaOptimalWidth();

            //Brazos merge p3 trough p7 inactive in BT
            //BT also provides integer value to Load for PState, which shouldn't be needed

            //MessageBox.Show("Jetzt werden die Register der GPU gelesen!");
            nbp0StateControl.LoadFromHardware();
            nbp1StateControl.LoadFromHardware();
            //MessageBox.Show("Jetzt werden zusätzliche Register gelesen!");
            statusinfo.LoadFromHardware();

            //MessageBox.Show("Jetzt werden die Register der CPU gelesen!");
            p0StateControl.LoadFromHardware();
            p1StateControl.LoadFromHardware();
            p2StateControl.LoadFromHardware();
            p3StateControl.LoadFromHardware();
            p4StateControl.LoadFromHardware();
            p5StateControl.LoadFromHardware();
            p6StateControl.LoadFromHardware();
            p7StateControl.LoadFromHardware();

            //MessageBox.Show("Alle Register gelesen!");

            if (!_useWindowsPowerSchemes)
            {
                // use FusionTweaker's power schemes (via the registry)
                powerSchemesComboBox.Items.Add(new PowerScheme()
                {
                    Name = "Balanced"
                });
                powerSchemesComboBox.Items.Add(new PowerScheme()
                {
                    Name = "High performance"
                });
                powerSchemesComboBox.Items.Add(new PowerScheme()
                {
                    Name = "Power saver"
                });

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

                if (key == null)
                {
                    powerSchemesComboBox.SelectedIndex = 0;
                }
                else
                {
                    powerSchemesComboBox.SelectedIndex = (int)key.GetValue("PowerScheme", 0);
                    key.Close();
                }

                InitializeNotifyIconContextMenu();

                powerSchemesComboBox.SelectedIndexChanged += (s, e) =>
                {
                    var k = Microsoft.Win32.Registry.LocalMachine.CreateSubKey(@"Software\FusionTweaker");
                    k.SetValue("PowerScheme", powerSchemesComboBox.SelectedIndex);
                    k.Close();
                    SynchronizeNotifyIconContextMenu();
                };

                return;
            }

            int    guidSize = 16;
            IntPtr guid     = Marshal.AllocHGlobal(guidSize);

            // get the GUID of the current power scheme
            IntPtr activeGuidPointer;

            if (PowerGetActiveScheme(IntPtr.Zero, out activeGuidPointer) != 0)
            {
                throw new Exception("PowerGetActiveScheme()");
            }
            Guid activeGuid = (Guid)Marshal.PtrToStructure(activeGuidPointer, typeof(Guid));

            LocalFree(activeGuidPointer);

            // iterate over all power schemes
            for (int i = 0; true; i++)
            {
                if (PowerEnumerate(IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, 0x10, i, guid, ref guidSize) != 0)
                {
                    break;
                }

                // get the required buffer size
                int size = 0;
                if (PowerReadFriendlyName(IntPtr.Zero, guid, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, ref size) != 0)
                {
                    break;//throw new Exception("PowerReadFriendlyName()");
                }
                IntPtr stringBuffer = Marshal.AllocHGlobal(size);

                // get the scheme name
                if (PowerReadFriendlyName(IntPtr.Zero, guid, IntPtr.Zero, IntPtr.Zero, stringBuffer, ref size) != 0)
                {
                    throw new Exception("PowerReadFriendlyName()");
                }

                var item = new PowerScheme()
                {
                    Guid = (Guid)Marshal.PtrToStructure(guid, typeof(Guid)),
                    Name = Marshal.PtrToStringUni(stringBuffer)
                };

                Marshal.FreeHGlobal(stringBuffer);

                powerSchemesComboBox.Items.Add(item);

                if (item.Guid == activeGuid)
                {
                    powerSchemesComboBox.SelectedIndex = i;
                }
            }

            Marshal.FreeHGlobal(guid);

            InitializeNotifyIconContextMenu();

            powerSchemesComboBox.SelectedIndexChanged += (s, e) =>
            {
                var item = (PowerScheme)powerSchemesComboBox.SelectedItem;
                if (PowerSetActiveScheme(IntPtr.Zero, ref item.Guid) != 0)
                {
                    throw new Exception("PowerSetActiveScheme()");
                }
                SynchronizeNotifyIconContextMenu();
            };
        }
예제 #2
0
        /// <summary>
        /// Loads the P-state settings from each core's MSR.
        /// </summary>
        public void LoadFromHardware()
        {
            if (_index < 0)
            {
                throw new InvalidOperationException("The PStateIndex property needs to be initialized first.");
            }

            if (_index < 8) //hardware loads for CPU
            {
                //FT if (_index <= K10Manager.GetHighestPState() + K10Manager.GetNumBoostedStates()) //skip, in case index is bigger than initialized CPU PStates
                if (_index <= 7)//_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++)//iterating through cores
                    {
                        var msr = _pState.Msrs[i];

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

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

                    VidNumericUpDown.Value = Math.Min(VidNumericUpDown.Maximum, (decimal)maxCpuVid);
                    //int check = K10Manager.SetBIOSBusSpeed(80);
                    pllfreq.Text    = "P" + _index + " Freq (CPU): ";
                    clockvalue.Text = K10Manager.GetBIOSBusSpeed() + "MHz";
                    freqvalue.Text  = (int)_pState.Msrs[0].PLL + "MHz";
                    if ((Form1.family == 12) || (Form1.family == 16))   //Llano + Kabini
                    {
                        Cofstate.Text = "Mult = ";
                    }
                    else     //Brazos
                    {
                        Cofstate.Text = "Mult = " + (K10Manager.CurrCOF() + 16) + " divided by ->";
                    }
                    Form1.freq[_index] = (int)_pState.Msrs[0].PLL;
                    if (PStateIndex <= _maxPstate)
                    {
                        checkBox_Penable.Checked = true;
                        checkBox_Penable.Enabled = false;
                    }
                    else
                    {
                        checkBox_Penable.Checked = false;
                        checkBox_Penable.Enabled = false;
                    }
                }
                else
                {
                    VidNumericUpDown.Value = (decimal)0.4;
                }
            }
            else if (_index == 8)
            {
                //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());
                pllfreq.Text             = "NB P0 Freq (GPU): ";
                Cofstate.Text            = "Mult = " + (K10Manager.CurrCOF() + 16) + " divided by ->";
                clockvalue.Text          = K10Manager.GetBIOSBusSpeed() + "MHz";
                freqvalue.Text           = (int)_pState.Msrs[0].PLL + "MHz";
                Form1.freq[_index]       = (int)_pState.Msrs[0].PLL;
                checkBox_Penable.Checked = true;
                checkBox_Penable.Enabled = false;
            }
            else if (_index == 9)
            {
                //hardware loads for NB P1
                _pState = PState.Load(_index);
                var control = (NumericUpDown)flowLayoutPanel1.Controls[0];
                control.Value            = (decimal)K10Manager.GetNbDivPState1();
                VidNumericUpDown.Value   = (decimal)(1.55 - 0.0125 * K10Manager.GetNbVidPState1());
                pllfreq.Text             = "NB P1 Freq (GPU): ";
                clockvalue.Text          = K10Manager.GetBIOSBusSpeed() + "MHz";
                freqvalue.Text           = (int)_pState.Msrs[0].PLL + "MHz";
                Cofstate.Text            = "Mult = " + (K10Manager.CurrCOF() + 16) + " divided by ->";
                Form1.freq[_index]       = (int)_pState.Msrs[0].PLL;
                checkBox_Penable.Checked = true;
                checkBox_Penable.Enabled = false;
            }
            else if (_index == 10) //settings for displaying registers
            {
                VidNumericUpDown.Value = 1;
            }

            _modified = false;
        }