diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2023-08-22 17:19:34 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2023-09-06 11:03:44 +0900 |
commit | 06709e03b7fb6cc2259f421b80cddc55a8d3e659 (patch) | |
tree | 9d5ec6f265b72ffca89b17ca2b73c118512bb550 /src | |
parent | c3b2fad5e680e600fdee13981c43d342483d5635 (diff) | |
download | tdepowersave-06709e03b7fb6cc2259f421b80cddc55a8d3e659.tar.gz tdepowersave-06709e03b7fb6cc2259f421b80cddc55a8d3e659.zip |
Solve issue with CPU using 100% resources when autodimm was activated. This resolves issue TDE/tde#136.
The problem was hardware dependent and only noticable when the backlight
card has hundreds or thousands of steps. This was causing non-stop
calls to setBrightness, which did not have enough CPU time to complete
its task before the next call, resulting in the CPU eating up all
resources, non stop.
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'src')
-rw-r--r-- | src/tdepowersave.cpp | 62 | ||||
-rw-r--r-- | src/tdepowersave.h | 11 |
2 files changed, 41 insertions, 32 deletions
diff --git a/src/tdepowersave.cpp b/src/tdepowersave.cpp index 41ade35..931944b 100644 --- a/src/tdepowersave.cpp +++ b/src/tdepowersave.cpp @@ -150,7 +150,8 @@ tdepowersave::tdepowersave( bool force_acpi_check, bool trace_func ) : KSystemTr BAT_WARN_ICON_Timer = new TQTimer(this); connect(BAT_WARN_ICON_Timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(do_setIconBG())); - AUTODIMM_Timer = new TQTimer(this); + m_autoDimmTimer = new TQTimer(this); + connect(m_autoDimmTimer, TQT_SIGNAL(timeout()), this, TQT_SLOT(do_dimm())); initMenu(); update(); @@ -169,6 +170,7 @@ tdepowersave::~tdepowersave(){ delete display; delete settings; delete autoSuspend; + delete m_autoDimmTimer; #ifdef ENABLE_YAST_ENTRY delete yast2; #endif @@ -1074,25 +1076,22 @@ void tdepowersave::do_downDimm() { kdDebugFuncIn(trace); if (hwinfo->supportBrightness()) { - if (!AUTODIMM_Timer->isActive()) { + if (!m_autoDimmTimer->isActive()) { int dimmToLevel = (int)round(hwinfo->getMaxBrightnessLevel() * settings->autoDimmTo / 100.0); // check if we really need to dimm down if (dimmToLevel < hwinfo->getCurrentBrightnessLevel()) { - int steps = hwinfo->getCurrentBrightnessLevel() - dimmToLevel; - int timePerStep = (1500 / steps); - + m_dimmRequestedLevel = dimmToLevel; + m_dimmStep = (hwinfo->getCurrentBrightnessLevel() - dimmToLevel) / 10 + 1; + m_dimmTimeoutCounter = 0; autoDimmDown = true; - - AUTODIMM_Timer = new TQTimer(this); - connect(AUTODIMM_Timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(do_dimm())); - AUTODIMM_Timer->start(timePerStep, false); + m_autoDimmTimer->start(100, false); } else { kdWarning() << "Don't dimm down, current level is already lower than requested Level" << endl; } } else { // wait until the timer is stopped, try later! - TQTimer::singleShot(1500, this, TQT_SLOT(do_downDimm())); + TQTimer::singleShot(2000, this, TQT_SLOT(do_downDimm())); } } @@ -1113,28 +1112,24 @@ void tdepowersave::do_upDimm() { //NOTE we go back to the value of the scheme and not the last on, to reduce trouble with the scheme if (hwinfo->supportBrightness()) { - if (!AUTODIMM_Timer->isActive()) { - int dimmToLevel = (int)round(hwinfo->getMaxBrightnessLevel() * settings->autoDimmTo / 100.0); + if (!m_autoDimmTimer->isActive()) { + int dimmToLevel = (int)round(hwinfo->getMaxBrightnessLevel() * settings->brightnessValue / 100.0); // check if we really need to dimm up if (dimmToLevel > hwinfo->getCurrentBrightnessLevel()) { - int steps = dimmToLevel - hwinfo->getCurrentBrightnessLevel(); - int timePerStep = (750 / steps); - + m_dimmRequestedLevel = dimmToLevel; + m_dimmStep = (dimmToLevel - hwinfo->getCurrentBrightnessLevel()) / 10 + 1; + m_dimmTimeoutCounter = 0; autoDimmDown = false; - - AUTODIMM_Timer = new TQTimer(this); - connect(AUTODIMM_Timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(do_dimm())); - AUTODIMM_Timer->start(timePerStep, false); - - // start autodimm again - setAutoDimm(false); + m_autoDimmTimer->start(100, false); } else { kdWarning() << "Don't dimm up, current level is already above requested Level" << endl; } + // start autodimm again + setAutoDimm(false); } else { // wait until the timer is stopped, try later! - TQTimer::singleShot(750, this, TQT_SLOT(do_downDimm())); + TQTimer::singleShot(2000, this, TQT_SLOT(do_downDimm())); } } @@ -1151,14 +1146,22 @@ void tdepowersave::do_upDimm() { void tdepowersave::do_dimm() { kdDebugFuncIn(trace); + if (m_dimmStep <= 0 || m_dimmTimeoutCounter > 30) + { + m_autoDimmTimer->stop(); + return; + } + + ++m_dimmTimeoutCounter; int current = hwinfo->getCurrentBrightnessLevel(); if (autoDimmDown) { // dimm the display down - if (current > (int)round(hwinfo->getMaxBrightnessLevel() * settings->autoDimmTo / 100.0)) { - hwinfo->setBrightnessLevel(current -1); + if (current > 0 && current > (m_dimmRequestedLevel * 1.005)) { + hwinfo->setBrightnessLevel(current - m_dimmStep); } else { - AUTODIMM_Timer->stop(); + m_autoDimmTimer->stop(); + m_dimmStep = 0; // start checking if the user get active again // NOTE: we start this here because the X-Server detect brightness changes as @@ -1167,10 +1170,11 @@ void tdepowersave::do_dimm() { } } else { // dimm the display up - if (current < (int)round(hwinfo->getMaxBrightnessLevel() * settings->autoDimmTo / 100.0)) { - hwinfo->setBrightnessLevel(current +1); + if (current < (m_dimmRequestedLevel * 0.995)) { + hwinfo->setBrightnessLevel(current + m_dimmStep); } else { - AUTODIMM_Timer->stop(); + m_autoDimmTimer->stop(); + m_dimmStep = 0; } } diff --git a/src/tdepowersave.h b/src/tdepowersave.h index 326d8be..675850a 100644 --- a/src/tdepowersave.h +++ b/src/tdepowersave.h @@ -159,6 +159,11 @@ private: */ bool autoDimmDown; + // used during dimm down/up transitions + int m_dimmRequestedLevel; + int m_dimmStep; + int m_dimmTimeoutCounter; + //! to temporary hold the resume result int resume_result; @@ -266,12 +271,12 @@ private: * The timerinterval is defined in \ref BAT_icon_BG_intervall . */ TQTimer *BAT_WARN_ICON_Timer; + //! Timer to dimm down/up the brightness /*! - * This timer is used dimm the display up and down. The timerinterval - * depends on calculated timePerStep in the calling function. + * This timer is used to dimm the display up and down. */ - TQTimer *AUTODIMM_Timer; + TQTimer *m_autoDimmTimer; //! draw all icon related things for \ref redrawPixmap() void drawIcon(); |