示例#1
0
        public void Restore()
        {
            // P-states
            for (int i = 0; i < NumPstates; i++)
            {
                Pstate[i] = PstateAtStart[i];
            }

            PstateOc = PstateOcAtStart;

            BoostFreq[0] = Pstate[0];
            BoostFreq[1] = Pstate[0];
            BoostFreq[2] = Pstate[2];

            //ZenOc = ZenOcAtStart;

            // C-states
            ZenC6Core        = ZenC6CoreAtStart;
            ZenC6Package     = ZenC6PackageAtStart;
            ZenCorePerfBoost = ZenCorePerfBoostAtStart;

            ZenPPT    = 0;
            ZenEDC    = 0;
            ZenTDC    = 0;
            ZenScalar = 1;

            // Perf Bias
            PerformanceBias = PerfBias.Auto;
        }
示例#2
0
        public bool SetPerfBias(PerfBias pb)
        {
            uint pb1_eax = 0, pb1_edx = 0, pb2_eax = 0, pb2_edx = 0, pb3_eax = 0, pb3_edx = 0, pb4_eax = 0, pb4_edx = 0, pb5_eax = 0, pb5_edx = 0;

            // Read current settings
            if (ols.RdmsrTx(MSR_PERFBIAS1, ref pb1_eax, ref pb1_edx, (UIntPtr)1) != 1)
            {
                return(false);
            }
            if (ols.RdmsrTx(MSR_PERFBIAS2, ref pb2_eax, ref pb2_edx, (UIntPtr)1) != 1)
            {
                return(false);
            }
            if (ols.RdmsrTx(MSR_PERFBIAS3, ref pb3_eax, ref pb3_edx, (UIntPtr)1) != 1)
            {
                return(false);
            }
            if (ols.RdmsrTx(MSR_PERFBIAS4, ref pb4_eax, ref pb4_edx, (UIntPtr)1) != 1)
            {
                return(false);
            }
            if (ols.RdmsrTx(MSR_PERFBIAS5, ref pb5_eax, ref pb5_edx, (UIntPtr)1) != 1)
            {
                return(false);
            }

            // Clear by default
            pb1_eax &= 0xFFFFFFEF;
            pb2_eax &= 0xFF83FFFF;
            pb2_eax |= 0x02000000;
            pb3_eax &= 0xFFFFFFF8;
            pb4_eax &= 0xFFF9FFEF;
            pb5_eax &= 0xFFFFFFFE;

            // Specific settings
            switch (pb)
            {
            case PerfBias.None:
                pb1_eax |= 0x10;
                pb2_eax |= (8 & 0x1F) << 18;
                pb3_eax |= (7 & 0x7);
                pb4_eax |= 0x10;
                break;

            case PerfBias.Cinebench_R11p5:
                pb2_eax &= 0xF1FFFFEF;
                pb3_eax |= (7 & 0x7);
                pb4_eax |= 0x60010;
                break;

            /*case PerfBias.Cinebench_R15:
             *  pb2_eax |= (3 & 0x1F) << 18;
             *  pb2_eax &= 0xF1FFFFEF;
             *  pb3_eax |= (6 & 0x7);
             *  pb4_eax |= 0x10;
             *  pb5_eax |= 1;
             *  break;*/
            case PerfBias.Cinebench_R15:
                pb1_edx &= 0xFFF00F0F;
                pb2_eax |= (3 & 0x1F) << 18;
                pb2_eax &= 0xF1FFFFEF;
                pb3_eax |= (7 & 0x7);
                pb4_eax |= 0x10;
                pb5_eax |= 1;
                break;

            case PerfBias.Geekbench_3:
                //pb2_eax &= 0xF1FFFFEF;
                pb2_eax |= (4 & 0x1F) << 18;
                pb3_eax |= (7 & 0x7);
                pb4_eax |= 0x10;
                break;

            case PerfBias.Auto:
            default:
                return(false);
            }

            // Rewrite
            for (int i = 0; i < Threads; i++)
            {
                if (ols.WrmsrTx(MSR_PERFBIAS1, pb1_eax, pb1_edx, (UIntPtr)(((UInt64)1) << i)) != 1)
                {
                    return(false);
                }
                if (ols.WrmsrTx(MSR_PERFBIAS2, pb2_eax, pb2_edx, (UIntPtr)(((UInt64)1) << i)) != 1)
                {
                    return(false);
                }
                if (ols.WrmsrTx(MSR_PERFBIAS3, pb3_eax, pb3_edx, (UIntPtr)(((UInt64)1) << i)) != 1)
                {
                    return(false);
                }
                if (ols.WrmsrTx(MSR_PERFBIAS4, pb4_eax, pb4_edx, (UIntPtr)(((UInt64)1) << i)) != 1)
                {
                    return(false);
                }
                if (ols.WrmsrTx(MSR_PERFBIAS5, pb5_eax, pb5_edx, (UIntPtr)(((UInt64)1) << i)) != 1)
                {
                    return(false);
                }
            }

            PerformanceBias = pb;

            return(true);
        }
示例#3
0
        public CPUHandler()
        {
            ols = new Ols();

            // Check support library sutatus
            switch (ols.GetStatus())
            {
            case (uint)Ols.Status.NO_ERROR:
                break;

            case (uint)Ols.Status.DLL_NOT_FOUND:
                throw new System.ApplicationException("WinRing DLL_NOT_FOUND");

            case (uint)Ols.Status.DLL_INCORRECT_VERSION:
                throw new System.ApplicationException("WinRing DLL_INCORRECT_VERSION");

            case (uint)Ols.Status.DLL_INITIALIZE_ERROR:
                throw new System.ApplicationException("WinRing DLL_INITIALIZE_ERROR");
            }

            // Check WinRing0 status
            switch (ols.GetDllStatus())
            {
            case (uint)Ols.OlsDllStatus.OLS_DLL_NO_ERROR:
                break;

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_NOT_LOADED:
                throw new System.ApplicationException("WinRing OLS_DRIVER_NOT_LOADED");

            case (uint)Ols.OlsDllStatus.OLS_DLL_UNSUPPORTED_PLATFORM:
                throw new System.ApplicationException("WinRing OLS_UNSUPPORTED_PLATFORM");

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_NOT_FOUND:
                throw new System.ApplicationException("WinRing OLS_DLL_DRIVER_NOT_FOUND");

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_UNLOADED:
                throw new System.ApplicationException("WinRing OLS_DLL_DRIVER_UNLOADED");

            case (uint)Ols.OlsDllStatus.OLS_DLL_DRIVER_NOT_LOADED_ON_NETWORK:
                throw new System.ApplicationException("WinRing DRIVER_NOT_LOADED_ON_NETWORK");

            case (uint)Ols.OlsDllStatus.OLS_DLL_UNKNOWN_ERROR:
                throw new System.ApplicationException("WinRing OLS_DLL_UNKNOWN_ERROR");
            }

            // CPU Check. Compare family, model, ext family, ext model. Ignore stepping/revision
            switch (GetCpuInfo() & 0xFFFFFFF0)
            {
            case 0x00800F10:     // CPU \ Zen \ Summit Ridge \ ZP - B0 \ 14nm
            case 0x00800F00:     // CPU \ Zen \ Summit Ridge \ ZP - A0 \ 14nm
                this.cpuType = CPUType.Summit_Ridge;
                break;

            case 0x00800F80:     // CPU \ Zen + \ Pinnacle Ridge \ 12nm
                this.cpuType = CPUType.Pinnacle_Ridge;
                break;

            case 0x00810F80:     // APU \ Zen + \ Picasso \ 12nm
                this.cpuType = CPUType.Picasso;
                break;

            case 0x00810F00:     // APU \ Zen \ Raven Ridge \ RV - A0 \ 14nm
            case 0x00810F10:     // APU \ Zen \ Raven Ridge \ 14nm
            case 0x00820F00:     // APU \ Zen \ Raven Ridge 2 \ RV2 - A0 \ 14nm
                this.cpuType = CPUType.Raven_Ridge;
                break;

            case 0x00870F10:     // CPU \ Zen2 \ Matisse \ MTS - B0 \ 7nm + 14nm I/ O Die
            case 0x00870F00:     // CPU \ Zen2 \ Matisse \ MTS - A0 \ 7nm + 14nm I/ O Die
                this.cpuType = CPUType.Matisse;
                break;

            case 0x00830F00:
            case 0x00830F10:     // CPU \ Epyc 2 \ Rome \ 7nm
                this.cpuType = CPUType.Rome;
                break;

            default:
                this.cpuType = CPUType.Unsupported;
#if DEBUG
                this.cpuType = CPUType.DEBUG;
#endif
                break;
            }

            //this.cpuType = CPUType.Matisse;

            // Get number of threads
            this.Threads = Environment.ProcessorCount;

            // Create mutex handles
            hMutexPci     = new Mutex(false, "Global\\Access_PCI");
            SettingsStore = new Settings();

            if (!SettingsStore.SettingsReset)
            {
                SettingsSaved = true;
            }

            if (cpuType != CPUType.Unsupported)
            {
                TrayIconAtStart = SettingsStore.TrayIconAtStart;
                ApplyAtStart    = SettingsStore.ApplyAtStart;
                P80Temp         = SettingsStore.P80Temp;

                for (int i = 0; i < NumPstates; i++)
                {
                    Pstate[i] = SettingsStore.Pstate[i];
                }

                for (int i = 0; i < 3; i++)
                {
                    BoostFreq[i] = SettingsStore.BoostFreq[i];
                }

                PstateOc = SettingsStore.PstateOc;

                ZenC6Core        = SettingsStore.ZenC6Core;
                ZenC6Package     = SettingsStore.ZenC6Package;
                ZenCorePerfBoost = SettingsStore.ZenCorePerfBoost;
                ZenOc            = SettingsStore.ZenOc;
                ZenPPT           = SettingsStore.ZenPPT;
                ZenTDC           = SettingsStore.ZenTDC;
                ZenEDC           = SettingsStore.ZenEDC;
                ZenScalar        = SettingsStore.ZenScalar;

                //PerformanceEnhancer = SettingsStore.PerformanceEnhancer;
                PerformanceBias = SettingsStore.PerformanceBias;

                // Safety check
                if (SettingsStore.LastState != 0)
                {
                    ShutdownUnclean = true;
                }

                SettingsStore.LastState = 0x01;
                SettingsStore.Save();

                // Get current P-states
                PstateAtStart   = new UInt64[NumPstates];
                PstateOcAtStart = 0x0;

                uint edx = 0, eax = 0;

                for (uint i = 0; i < NumPstates; i++)
                {
                    if (ols.RdmsrTx(MSR_PStateDef0 + i, ref eax, ref edx, (UIntPtr)(1)) == 1)
                    {
                        PstateAtStart[i] = ((UInt64)edx << 32) | eax;
                        if (Pstate[i] == 0)
                        {
                            Pstate[i] = PstateAtStart[i];
                        }
                    }
                }

                BoostFreq[0] = Pstate[0];
                BoostFreq[1] = Pstate[0];
                BoostFreq[2] = Pstate[2];

                PstateOcAtStart = PstateAtStart[0];
                if (PstateOc == 0)
                {
                    PstateOc = PstateOcAtStart;
                }

                // Get current C-state settings
                if (ols.RdmsrTx(MSR_PMGT_MISC, ref eax, ref edx, (UIntPtr)(1)) == 1)
                {
                    ZenC6PackageAtStart = Convert.ToBoolean(edx & 1);
                    if (SettingsStore.SettingsReset)
                    {
                        ZenC6Package = ZenC6PackageAtStart;
                    }
                }
                if (ols.RdmsrTx(MSR_CSTATE_CONFIG, ref eax, ref edx, (UIntPtr)(1)) == 1)
                {
                    bool CCR0_CC6EN = Convert.ToBoolean((eax >> 6) & 1);
                    bool CCR1_CC6EN = Convert.ToBoolean((eax >> 14) & 1);
                    bool CCR2_CC6EN = Convert.ToBoolean((eax >> 22) & 1);
                    if (CCR0_CC6EN && CCR1_CC6EN && CCR2_CC6EN)
                    {
                        ZenC6CoreAtStart = true;
                    }
                    else
                    {
                        ZenC6CoreAtStart = false;
                    }
                    if (SettingsStore.SettingsReset)
                    {
                        ZenC6Core = ZenC6CoreAtStart;
                    }
                }

                // Get current CPB
                if (ols.RdmsrTx(MSR_HWCR, ref eax, ref edx, (UIntPtr)(1)) == 1)
                {
                    ZenCorePerfBoostAtStart = !Convert.ToBoolean((eax >> 25) & 1);
                    if (SettingsStore.SettingsReset)
                    {
                        ZenCorePerfBoost = ZenCorePerfBoostAtStart;
                    }
                }

                // Get OC Mode
                if (ols.RdmsrTx(MSR_PStateStat, ref eax, ref edx, (UIntPtr)(1)) == 1)
                {
                    ZenOcAtStart = Convert.ToBoolean((eax >> 1) & 1);
                    if (SettingsStore.SettingsReset)
                    {
                        ZenOc = ZenOcAtStart;
                    }
                }

                // Get Tctl offset
                GetTctlOffset(ref TctlOffset);
            }
            else if (cpuType == CPUType.DEBUG)
            {
                Pstate[0]               = Convert.ToUInt64("80000000000408A0", 16); //unchecked((UInt64)((1 & 1) << 63 | (0x10 & 0xFF) << 14 | (0x08 & 0xFF) << 8 | 0xA0 & 0xFF));
                Pstate[1]               = Convert.ToUInt64("8000000000080A90", 16); //unchecked((UInt64)((1 & 1) << 63 | (0x20 & 0xFF) << 14 | (0x0A & 0xFF) << 8 | 0x90 & 0xFF));
                Pstate[2]               = Convert.ToUInt64("8000000000100C80", 16); //unchecked((UInt64)((1 & 1) << 63 | (0x30 & 0xFF) << 14 | (0x0C & 0xFF) << 8 | 0x80 & 0xFF));
                BoostFreq[0]            = Pstate[0];
                BoostFreq[1]            = Pstate[0];
                BoostFreq[2]            = Pstate[2];
                PstateOc                = Pstate[0];
                ZenC6Core               = false;
                ZenC6CoreAtStart        = false;
                ZenC6Package            = false;
                ZenC6PackageAtStart     = false;
                ZenCorePerfBoost        = true;
                ZenCorePerfBoostAtStart = true;
                ZenOc        = false;
                ZenOcAtStart = false;
                TctlOffset   = 0;
            }
        }
示例#4
0
        private bool ReadSettingsFromFile()
        {
            try
            {
                using (FileStream fs = new FileStream(FullFilePath, FileMode.Open))
                {
                    using (XmlReader reader = XmlReader.Create(fs))
                    {
                        // Find ZenStates Element
                        while (reader.Read() && reader.NodeType == XmlNodeType.Element && reader.Name == "ZenStates")
                        {
                        }

                        // Find Application Element
                        while (reader.Read() && reader.NodeType == XmlNodeType.Element && reader.Name == "Application")
                        {
                        }

                        // Read Application Element variables
                        while (reader.Read() && reader.NodeType != XmlNodeType.EndElement)
                        {
                            if (reader.NodeType == XmlNodeType.Element)
                            {
                                switch (reader.Name)
                                {
                                case "ServiceVersion": ServiceVersion = (byte)reader.ReadElementContentAsInt(); break;

                                case "SettingsReset": SettingsReset = reader.ReadElementContentAsString() == "True" ? true : false; break;

                                case "LastState": LastState = (byte)reader.ReadElementContentAsInt(); break;
                                }
                            }
                        }

                        // Find Settings Element
                        while (reader.Read() && reader.NodeType == XmlNodeType.Element && reader.Name == "Settings")
                        {
                        }

                        // Read Settings Element variables
                        while (reader.Read() && reader.NodeType != XmlNodeType.EndElement)
                        {
                            if (reader.NodeType == XmlNodeType.Element)
                            {
                                switch (reader.Name)
                                {
                                case "TrayIconAtStart": TrayIconAtStart = reader.ReadElementContentAsString() == "True" ? true : false; break;

                                case "ApplyAtStart": ApplyAtStart = reader.ReadElementContentAsString() == "True" ? true : false;; break;

                                case "P80Temp": P80Temp = reader.ReadElementContentAsString() == "True" ? true : false; break;

                                case "P0": Pstate[0] = Convert.ToUInt64(reader.ReadElementContentAsString(), 16); break;

                                case "P1": Pstate[1] = Convert.ToUInt64(reader.ReadElementContentAsString(), 16); break;

                                case "P2": Pstate[2] = Convert.ToUInt64(reader.ReadElementContentAsString(), 16); break;

                                case "Boost0": BoostFreq[0] = Convert.ToUInt64(reader.ReadElementContentAsString(), 16); break;

                                case "Boost1": BoostFreq[1] = Convert.ToUInt64(reader.ReadElementContentAsString(), 16); break;

                                case "Boost2": BoostFreq[2] = Convert.ToUInt64(reader.ReadElementContentAsString(), 16); break;

                                case "PstateOc": PstateOc = Convert.ToUInt64(reader.ReadElementContentAsString(), 16); break;

                                case "ZenC6Core": ZenC6Core = reader.ReadElementContentAsString() == "True" ? true : false; break;

                                case "ZenC6Package": ZenC6Package = reader.ReadElementContentAsString() == "True" ? true : false; break;

                                case "ZenCorePerfBoost": ZenCorePerfBoost = reader.ReadElementContentAsString() == "True" ? true : false; break;

                                case "ZenOc": ZenOc = reader.ReadElementContentAsString() == "True" ? true : false; break;

                                case "ZenPPT": ZenPPT = reader.ReadElementContentAsInt(); break;

                                case "ZenTDC": ZenTDC = reader.ReadElementContentAsInt(); break;

                                case "ZenEDC": ZenEDC = reader.ReadElementContentAsInt(); break;

                                case "ZenScalar": ZenScalar = reader.ReadElementContentAsInt(); break;

                                case "PerformanceBias": PerformanceBias = (CPUHandler.PerfBias)reader.ReadElementContentAsInt(); break;
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //throw new Exception("Settings: " + ex.Message);
                return(false);
            }

            return(true);
        }