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 8 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);
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;
}
}

@ -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();

Loading…
Cancel
Save