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>
pull/14/head
Michele Calgaro 9 months ago
parent c3b2fad5e6
commit 06709e03b7
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -150,7 +150,8 @@ tdepowersave::tdepowersave( bool force_acpi_check, bool trace_func ) : KSystemTr
BAT_WARN_ICON_Timer = new TQTimer(this); BAT_WARN_ICON_Timer = new TQTimer(this);
connect(BAT_WARN_ICON_Timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(do_setIconBG())); 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(); initMenu();
update(); update();
@ -169,6 +170,7 @@ tdepowersave::~tdepowersave(){
delete display; delete display;
delete settings; delete settings;
delete autoSuspend; delete autoSuspend;
delete m_autoDimmTimer;
#ifdef ENABLE_YAST_ENTRY #ifdef ENABLE_YAST_ENTRY
delete yast2; delete yast2;
#endif #endif
@ -1074,25 +1076,22 @@ void tdepowersave::do_downDimm() {
kdDebugFuncIn(trace); kdDebugFuncIn(trace);
if (hwinfo->supportBrightness()) { if (hwinfo->supportBrightness()) {
if (!AUTODIMM_Timer->isActive()) { if (!m_autoDimmTimer->isActive()) {
int dimmToLevel = (int)round(hwinfo->getMaxBrightnessLevel() * settings->autoDimmTo / 100.0); int dimmToLevel = (int)round(hwinfo->getMaxBrightnessLevel() * settings->autoDimmTo / 100.0);
// check if we really need to dimm down // check if we really need to dimm down
if (dimmToLevel < hwinfo->getCurrentBrightnessLevel()) { if (dimmToLevel < hwinfo->getCurrentBrightnessLevel()) {
int steps = hwinfo->getCurrentBrightnessLevel() - dimmToLevel; m_dimmRequestedLevel = dimmToLevel;
int timePerStep = (1500 / steps); m_dimmStep = (hwinfo->getCurrentBrightnessLevel() - dimmToLevel) / 10 + 1;
m_dimmTimeoutCounter = 0;
autoDimmDown = true; autoDimmDown = true;
m_autoDimmTimer->start(100, false);
AUTODIMM_Timer = new TQTimer(this);
connect(AUTODIMM_Timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(do_dimm()));
AUTODIMM_Timer->start(timePerStep, false);
} else { } else {
kdWarning() << "Don't dimm down, current level is already lower than requested Level" << endl; kdWarning() << "Don't dimm down, current level is already lower than requested Level" << endl;
} }
} else { } else {
// wait until the timer is stopped, try later! // 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 //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 (hwinfo->supportBrightness()) {
if (!AUTODIMM_Timer->isActive()) { if (!m_autoDimmTimer->isActive()) {
int dimmToLevel = (int)round(hwinfo->getMaxBrightnessLevel() * settings->autoDimmTo / 100.0); int dimmToLevel = (int)round(hwinfo->getMaxBrightnessLevel() * settings->brightnessValue / 100.0);
// check if we really need to dimm up // check if we really need to dimm up
if (dimmToLevel > hwinfo->getCurrentBrightnessLevel()) { if (dimmToLevel > hwinfo->getCurrentBrightnessLevel()) {
int steps = dimmToLevel - hwinfo->getCurrentBrightnessLevel(); m_dimmRequestedLevel = dimmToLevel;
int timePerStep = (750 / steps); m_dimmStep = (dimmToLevel - hwinfo->getCurrentBrightnessLevel()) / 10 + 1;
m_dimmTimeoutCounter = 0;
autoDimmDown = false; autoDimmDown = false;
m_autoDimmTimer->start(100, 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);
} else { } else {
kdWarning() << "Don't dimm up, current level is already above requested Level" << endl; kdWarning() << "Don't dimm up, current level is already above requested Level" << endl;
} }
// start autodimm again
setAutoDimm(false);
} else { } else {
// wait until the timer is stopped, try later! // 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() { void tdepowersave::do_dimm() {
kdDebugFuncIn(trace); kdDebugFuncIn(trace);
if (m_dimmStep <= 0 || m_dimmTimeoutCounter > 30)
{
m_autoDimmTimer->stop();
return;
}
++m_dimmTimeoutCounter;
int current = hwinfo->getCurrentBrightnessLevel(); int current = hwinfo->getCurrentBrightnessLevel();
if (autoDimmDown) { if (autoDimmDown) {
// dimm the display down // dimm the display down
if (current > (int)round(hwinfo->getMaxBrightnessLevel() * settings->autoDimmTo / 100.0)) { if (current > 0 && current > (m_dimmRequestedLevel * 1.005)) {
hwinfo->setBrightnessLevel(current -1); hwinfo->setBrightnessLevel(current - m_dimmStep);
} else { } else {
AUTODIMM_Timer->stop(); m_autoDimmTimer->stop();
m_dimmStep = 0;
// start checking if the user get active again // start checking if the user get active again
// NOTE: we start this here because the X-Server detect brightness changes as // NOTE: we start this here because the X-Server detect brightness changes as
@ -1167,10 +1170,11 @@ void tdepowersave::do_dimm() {
} }
} else { } else {
// dimm the display up // dimm the display up
if (current < (int)round(hwinfo->getMaxBrightnessLevel() * settings->autoDimmTo / 100.0)) { if (current < (m_dimmRequestedLevel * 0.995)) {
hwinfo->setBrightnessLevel(current +1); hwinfo->setBrightnessLevel(current + m_dimmStep);
} else { } else {
AUTODIMM_Timer->stop(); m_autoDimmTimer->stop();
m_dimmStep = 0;
} }
} }

@ -159,6 +159,11 @@ private:
*/ */
bool autoDimmDown; bool autoDimmDown;
// used during dimm down/up transitions
int m_dimmRequestedLevel;
int m_dimmStep;
int m_dimmTimeoutCounter;
//! to temporary hold the resume result //! to temporary hold the resume result
int resume_result; int resume_result;
@ -266,12 +271,12 @@ private:
* The timerinterval is defined in \ref BAT_icon_BG_intervall . * The timerinterval is defined in \ref BAT_icon_BG_intervall .
*/ */
TQTimer *BAT_WARN_ICON_Timer; TQTimer *BAT_WARN_ICON_Timer;
//! Timer to dimm down/up the brightness //! Timer to dimm down/up the brightness
/*! /*!
* This timer is used dimm the display up and down. The timerinterval * This timer is used to dimm the display up and down.
* depends on calculated timePerStep in the calling function.
*/ */
TQTimer *AUTODIMM_Timer; TQTimer *m_autoDimmTimer;
//! draw all icon related things for \ref redrawPixmap() //! draw all icon related things for \ref redrawPixmap()
void drawIcon(); void drawIcon();

Loading…
Cancel
Save