예제 #1
0
        ///////////////////////////////////////////for client
        //start main loop
        public void mainflow()
        {
            if (shutdownval)
            {
                Environment.Exit(0);
            }

            settings.checkTimeSync();   //update changed time settings

            //internal sync
            if (settings.timeSync && !controller.wrong && !pause) //skip when xtu settings bad, or user request
            {
                controller.XTUdaemon(settings, checker);

                //1. check config
                controller.generateCLKlist(settings, checker); //before batchCheck
                settings.batchCheckFiles();                    //no need to save io here
                if (settings.checkPowerCFGFlag)
                {
                    controller.initPowerCFG(settings);
                    controller.forceApply = true;   //just in case
                }

                //2. apply settings(add app if dont exist)
                var currfg = checker.detectFgProc(settings);
                checker.autoCheckInsert(currfg, settings, controller);
                //controller.setProcNice(currfg, settings);
                controller.setPower(currfg, settings);

                //3. check throttle

                /*
                 *
                 *  per profile scheduling.
                 *
                 *  store intermediate values on settingsmanager.
                 *
                 *  on throttle:
                 *      cpuload 80%(tweakable)
                 *      -get median upto throttleSync(tweakable)
                 *
                 *  if app on the same profile throttles:
                 *      profile gets modified affecting other relevant apps.
                 *
                 *  if app is not in any profile:
                 *      monitor performance for throttleSync(tweakable) cycles and assign to closest one.
                 *
                 */


                /*current app info
                 *  1. skip if its not in list
                 *  2. which throttle mode
                 */

                //reset timers (except newlist does it internally)
                if (prev_currfg != null)
                {
                    if (currfg.Id != prev_currfg.Id)
                    {
                        settings.resetThrottleSync();
                        settings.resetResurSync();
                    }
                }
                prev_currfg = currfg;

                //current profile:
                int currprof = controller.checkInList(currfg, settings);

                //if app has a profile:
                if (currprof != -1)
                {
                    if (checker.isCurrentlyThrottling(settings, controller))
                    {
                        int mode = settings.throttleMode; //save mode
                        settings.throttleMode = 0;        //reset

                        //median limit
                        int limit      = (int)settings.newlist_median.configList["newlist_median"]; //ex) 50
                        int listcount  = settings.generatedCLK.configList.Count();                  //ex) 12
                        int indexlimit = listcount - listcount * limit / 100;                       //ex) 6

                        //new clk value for cpu throttle (newclk)
                        var gclklist = checker.sortedCLKlist(settings);
                        int newindex = gclklist.IndexOf(controller.getCLK(false));
                        if (newindex > indexlimit)
                        {
                            newindex--;                            //ensure 0 is the end(noindex is -1)
                        }
                        int newclk = gclklist.ElementAt(newindex); //clk value goes in

                        //new xtu value for gpu throttle (newxtu)
                        float newxtu = controller.getXTU();
                        if (newxtu > controller.getBaseXTU(settings))
                        {
                            newxtu -= 0.5f;
                        }

                        switch (mode)
                        {
                        case 0: break;

                        case 1:     //cpu
                            settings.programs_running_cfg_cpu.appendChanges(currprof, newclk);

                            break;

                        case 2:     //gpu
                            settings.programs_running_cfg_xtu.appendChanges(currprof, newxtu);


                            break;
                        }
                    }
                    if (checker.isViableForResurrect(settings, controller))
                    {
                        int mode = settings.resurrectMode;
                        settings.resurrectMode = 0;

                        //median limit
                        int limit      = (int)settings.newlist_median.configList["newlist_median"]; //ex) 50
                        int listcount  = settings.generatedCLK.configList.Count();                  //ex) 12
                        int indexlimit = listcount - listcount * limit / 100;                       //ex) 6

                        string name = controller.checkNameInList(currfg, settings);
                        switch (mode)
                        {
                        case 0: break;

                        case 1:
                            if (currprof > 0)
                            {
                                settings.special_programs.appendChanges(name, currprof - 1);
                            }
                            break;

                        case 2:
                            if (currprof < indexlimit)
                            {
                                settings.special_programs.appendChanges(name, currprof + 1);
                            }
                            break;
                        }
                    }
                }
            }
            settings.updateTimeSync();
            checker.resettick();
        }
예제 #2
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;
        }