Пример #1
0
        public TweakerController(Logger log, TweakerChecker checker, SettingsManager sm)
        {
            this.log     = log;
            this.checker = checker;
            try
            {
                pshell                                  = new Process();
                pshell.StartInfo                        = new ProcessStartInfo();
                pshell.StartInfo.FileName               = "powershell";
                pshell.StartInfo.Arguments              = "get-command xtucli";
                pshell.StartInfo.UseShellExecute        = false;
                pshell.StartInfo.RedirectStandardOutput = true;
                pshell.StartInfo.CreateNoWindow         = true;

                //check if exists
                log.WriteLog("checking XTU cmdlet");
                pshell.Start();
                pshell.PriorityClass = ProcessPriorityClass.Idle;   //make sure it dont disrupt others
                pshell.WaitForExit();

                if (pshell.ExitCode == 1)
                {
                    log.WriteLog("XTU cmdlet missing, cannot continue.");
                    wrong = true;
                }
            }
            catch (Exception e)
            {
                log.WriteLog(e.ToString());
            }
            finally {
                log.WriteLog("XTU ok");
            }


            pshell.StartInfo.FileName = "xtucli";

            powercfg                                  = new Process();
            powercfg.StartInfo                        = new ProcessStartInfo();
            powercfg.StartInfo.FileName               = "powercfg";
            powercfg.StartInfo.Arguments              = "";
            powercfg.StartInfo.UseShellExecute        = false;
            powercfg.StartInfo.RedirectStandardOutput = true;
            powercfg.StartInfo.CreateNoWindow         = true;

            //max xtu
            if (sm.xtudefault.getCount() == 0)
            {
                MaxXTU = getXTU();  //get initial xtu value
                sm.xtudefault.configList.Add("xtudefault", MaxXTU);
                sm.xtudefault.completeWriteBack();
            }
            else
            {
                MaxXTU  = float.Parse(sm.xtudefault.configList["xtudefault"].ToString());
                lastXTU = MaxXTU;
            }
            BaseXTU = getBaseXTU(sm);
        }
Пример #2
0
        //prevent slowdown on high cpu apps by delaying
        public void XTUdaemon(SettingsManager sm, TweakerChecker tc)
        {
            int currpwr = tc.autofilterPWR(tc.getPWR());
            int load    = tc.getLoad();

            if (load >= (int)sm.throttle_median.configList["throttle_median"])
            {
                xtuapplynested = false;
                return;
            }
            if (xtuapplyvalue != 0.0)
            {
                xtuapplynested = true;
            }
        }
Пример #3
0
        //init every objects here!
        public ThrottleScheduler(int msec)
        {
            this.msec = msec;
            checker   = new TweakerChecker();

            //messy init
            settings = new SettingsManager();
            settings.initPath();
            log = new Logger(settings.path, settings.cfgname);
            settings.initConfig(log);
            checker.initPWR(log);
            checker.initTemp();

            //timesync
            settings.initTimeSync(msec);

            controller = new TweakerController(log, checker, settings);

            //initial load
            initflow();
        }
Пример #4
0
        //generate CLK list
        //CLK = powerplan value, PWR = real clockspeed

        /*
         *  profile number: (ascending order)
         *      least = CPU high/ GPU low
         *      most = CPU low/ GPU high
         *
         *      **by default least is done to monitor correct cpu load for new apps.
         *
         *
         *
         *
         */
        public void generateCLKlist(SettingsManager sm, TweakerChecker tc)
        {
            sm.IPClocked = true;

            if (!forceApply)
            {
                if ((sm.generatedCLK.getCount() > 1) &&
                    (sm.generatedXTU.getCount() > 1) &&
                    (sm.programs_running_cfg_cpu.getCount() > 1) &&
                    (sm.programs_running_cfg_xtu.getCount() > 1)
                    )
                {
                    return; //all generated
                }
            }
            forceApply = false;

            int clkbackuph  = getCLK(false);
            int clkbackupl  = getCLK(true);
            float xtubackup = getXTU();

            forceApply = true;
            sm.generatedCLK.configList.Clear();
            sm.generatedXTU.configList.Clear();
            sm.programs_running_cfg_cpu.configList.Clear();
            sm.programs_running_cfg_xtu.configList.Clear();

            //else
            log.WriteLog("================start of CLK + XTU list generation================");
            log.WriteLog("do NOT run anything power intensive!!!");

            Dictionary <int, int> hello = new Dictionary <int, int>();

            int bcount     = 0; //val
            int bcontender = 0; //key

            int prevPWR = int.MaxValue;
            int exPWR   = prevPWR;

            //start looping from 100 down to 0
            int x = 0;
            for (int i = 100; i >= 0; i--)
            {
                tc.resettick();
                runpowercfg("/setdcvalueindex " + powerplan + " " + processor + " " + procsubh + " " + i);
                runpowercfg("/setacvalueindex " + powerplan + " " + processor + " " + procsubh + " " + i);
                runpowercfg("/setdcvalueindex " + powerplan + " " + processor + " " + procsubl + " " + i);
                runpowercfg("/setacvalueindex " + powerplan + " " + processor + " " + procsubl + " " + i);
                runpowercfg("/setactive " + powerplan); //apply

                if (prevPWR != tc.getPWR())
                {
                    prevPWR = tc.getPWR();

                    //add
                    sm.generatedCLK.configList.Add(i, prevPWR);
                    sm.programs_running_cfg_cpu.configList.Add(x++, i);
                    log.WriteLog("new CLK: " + i + " clockspeed: " + prevPWR);

                    //contender
                    log.WriteLog("diff: " + (exPWR - prevPWR));
                    if (!hello.ContainsKey(exPWR - prevPWR))
                    {
                        hello.Add(exPWR - prevPWR, 1);
                    }
                    else
                    {
                        hello[exPWR - prevPWR]++;
                    }
                    exPWR = prevPWR;
                }
            }

            //calculate artificial base xtu(basextu func unreliable)

            /* howto:
             *      1. find lowest clockspeed stepping difference(contender)
             *      2. maxxtu - (hi - lo cpustep) / contender * xtustep
             */
            foreach (KeyValuePair <int, int> kv in hello)
            {
                if (bcount < kv.Value)
                {
                    bcount     = kv.Value;
                    bcontender = kv.Key;
                }
            }

            log.WriteLog("bcontender: " + bcontender);

            BaseXTU = (float)Math.Round(
                (MaxXTU * 100 - (tc.getTurboPWR() - prevPWR) / bcontender * 50) / 100 * 2, MidpointRounding.AwayFromZero) / 2;


            //calculate proper xtu for each clk value
            float ratio   = (MaxXTU - BaseXTU) * 100 / (tc.getTurboPWR() - (int)sm.generatedCLK.configList.Last().Value);
            float xtutemp = MaxXTU * 100;
            var listtemp  = tc.sortedCLKlist(sm);
            try
            {
                foreach (int j in listtemp)
                {
                    xtutemp -= ((int)sm.generatedCLK.configList[listtemp[x - 1]] - (int)sm.generatedCLK.configList[listtemp[x - 2]]) * ratio;
                    float xtutemp2 = (float)Math.Round(xtutemp / 100 * 2, MidpointRounding.AwayFromZero) / 2;

                    sm.generatedXTU.configList.Add(j, xtutemp2);
                    sm.programs_running_cfg_xtu.configList.Add(--x, xtutemp2);

                    log.WriteLog("new XTU: " + xtutemp2 + " for CLK: " + j);
                }
            }
            catch (Exception) { }
            sm.generatedXTU.configList.Add(100, BaseXTU);
            sm.programs_running_cfg_xtu.configList.Add(--x, BaseXTU);

            //write back
            log.WriteLog("writeback to file commencing...");
            sm.generatedCLK.completeWriteBack();
            sm.generatedXTU.completeWriteBack();
            sm.programs_running_cfg_cpu.completeWriteBack();
            sm.programs_running_cfg_xtu.completeWriteBack();

            setCLK(sm, clkbackuph, false);  //restore old clk
            setCLK(sm, clkbackupl, true);   //restore old clk
            setXTU(sm, xtubackup);          //restore old xtu
            log.WriteLog("================end of CLK + XTU list generation================");

            sm.IPClocked = false;
        }