Bug 288948

Summary: Kwin cpu leak
Product: [Plasma] kwin Reporter: Marian Kyral <mkyral>
Component: generalAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: thilo
Priority: NOR    
Version: 4.8.0   
Target Milestone: ---   
Platform: Gentoo Packages   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: sysprof file captured while kwin repaints the whole screen

Description Marian Kyral 2011-12-14 09:34:21 UTC
Version:           4.8.0 (using Devel) 
OS:                Linux

After upgrade to KDE 4.8 beta 1 (and now in beta 2) I noticed that after some time is the kwin cpu usage more then 20% even there are no effects running. Restart of kwin (kwin --replace) decrease kwin cpu usage to 0-2%. After some time, kwin cpu usage again more than 20%.

Reproducible: Always

Steps to Reproduce:
1) Work as usual and monitor kwin cpu usage.
2) When is kwin cpu usage high, restart kwin (ALT+F2 and kwin --replace)
3) Kwin cpu usage is low again.

Actual Results:  
Kwin uses about 20% of cpu after some time (hour and more). Even there is nothing to do - no effects active.

Expected Results:  
Kwin cpu usage should be minimal when nothing happen.

$ LANG=C kwin -v
Qt: 4.7.4
KDE Development Platform: 4.7.90 (4.8 Beta2 (4.7.90)
KWin: 4.7.90 (4.8 Beta2 (4.7.90)

GK: nVidia Corporation G98M [Quadro NVS 160M]
driver: [I] x11-drivers/nvidia-drivers (290.10@1.12.2011)

OpenGL composition enabled, OpenGL2 shaders and vertical synchronisation enabled.

$ cat kwinrc
[$Version]
update_info=kwin_remove_effects.upd:kwin4.7_effects

[Compositing]
AnimationSpeed=3
Backend=OpenGL
CheckIsSafe=true
DisableChecks=false
Enabled=true
GLDirect=true
GLLegacy=false
GLMode=SHM
GLTextureFilter=2
GLVSync=true
HiddenPreviews=5
OpenGLIsUnsafe=false
UnredirectFullscreen=true
XRenderSmoothScale=false

[Desktops]
Name_1=
Name_2=
Name_3=
Name_4=
Number=4

[Effect-BoxSwitch]
TabBox=false
TabBoxAlternative=false

[Effect-CoverSwitch]
TabBox=false

[Effect-Cube]
BackgroundColor=0,0,0
BorderActivate=9
BorderActivateCylinder=9
BorderActivateSphere=9
CapColor=197,197,197
CapDeformation=50
Caps=true
CloseOnMouseRelease=false
DisplayDesktopName=true
InvertKeys=false
InvertMouse=false
Opacity=80
OpacityDesktopOnly=false
Reflection=true
RotationDuration=0
TabBox=false
TexturedCaps=true
Wallpaper=
ZOrdering=true
ZPosition=100

[Effect-DesktopGrid]
BorderActivate=9

[Effect-FlipSwitch]
BorderActivate=9
BorderActivateAll=9
TabBox=false

[Effect-PresentWindows]
BorderActivate=9
BorderActivateAll=7
TabBox=true

[ElectricBorders]
Bottom=None
BottomLeft=None
BottomRight=None
Left=None
Right=None
Top=None
TopLeft=None
TopRight=None

[Plugins]
kwin4_effect_blurEnabled=false
kwin4_effect_boxswitchEnabled=false
kwin4_effect_coverswitchEnabled=false
kwin4_effect_cubeEnabled=false
kwin4_effect_cubeslideEnabled=false
kwin4_effect_dashboardEnabled=true
kwin4_effect_desktopgridEnabled=true
kwin4_effect_dialogparentEnabled=true
kwin4_effect_diminactiveEnabled=false
kwin4_effect_dimscreenEnabled=true
kwin4_effect_explosionEnabled=false
kwin4_effect_fadeEnabled=false
kwin4_effect_fadedesktopEnabled=false
kwin4_effect_fallapartEnabled=false
kwin4_effect_flipswitchEnabled=false
kwin4_effect_glideEnabled=true
kwin4_effect_highlightwindowEnabled=false
kwin4_effect_invertEnabled=false
kwin4_effect_loginEnabled=true
kwin4_effect_logoutEnabled=true
kwin4_effect_lookingglassEnabled=false
kwin4_effect_magiclampEnabled=false
kwin4_effect_magnifierEnabled=false
kwin4_effect_minimizeanimationEnabled=true
kwin4_effect_mousemarkEnabled=false
kwin4_effect_outlineEnabled=true
kwin4_effect_presentwindowsEnabled=true
kwin4_effect_resizeEnabled=false
kwin4_effect_scaleinEnabled=false
kwin4_effect_screenshotEnabled=true
kwin4_effect_sheetEnabled=false
kwin4_effect_showfpsEnabled=false
kwin4_effect_showpaintEnabled=false
kwin4_effect_slideEnabled=true
kwin4_effect_slidebackEnabled=false
kwin4_effect_slidingpopupsEnabled=true
kwin4_effect_snaphelperEnabled=false
kwin4_effect_startupfeedbackEnabled=true
kwin4_effect_taskbarthumbnailEnabled=true
kwin4_effect_thumbnailasideEnabled=false
kwin4_effect_trackmouseEnabled=false
kwin4_effect_translucencyEnabled=true
kwin4_effect_windowgeometryEnabled=false
kwin4_effect_wobblywindowsEnabled=true
kwin4_effect_zoomEnabled=false

[PopupInfo]
PopupHideDelay=1000
ShowPopup=false
TextOnly=false

[Style]
BorderSize=1
ButtonsOnLeft=MSF
ButtonsOnRight=HIAX
CustomButtonPositions=true
PluginLib=kwin3_oxygen
ShowToolTips=true

[SubSession: 11b8bc33-3c70-48e0-8173-79d17423ae4f]
active=-1
count=0

[SubSession: c37db738-92cd-459e-a174-d003feb33b94]
active=-1
count=0

[SubSession: fd198773-dd85-40a1-ac75-39f66fb73723]
active=-1
count=0

[Windows]
ActiveMouseScreen=false
AutoRaise=false
AutoRaiseInterval=750
AutogroupInForeground=false
AutogroupSimilarWindows=false
ClickRaise=true
DelayFocus=false
DelayFocusInterval=0
ElectricBorderCooldown=350
ElectricBorderDelay=150
ElectricBorderMaximize=true
ElectricBorderTiling=true
ElectricBorders=2
FocusPolicy=ClickToFocus
FocusStealingPreventionLevel=2
HideUtilityWindowsForInactive=true
InactiveTabsSkipTaskbar=false
Placement=Smart
RollOverDesktops=false
SeparateScreenFocus=false
ShadeHover=false
ShadeHoverInterval=250
TilingDefaultLayout=0
TilingOn=false
TilingRaisePolicy=0
Comment 1 Thomas Lübking 2011-12-14 14:39:47 UTC
Please check whether suspending / resuming the compositor is sufficient in this case and whether it happens with all window decorations.
Comment 2 Elias Probst 2011-12-14 15:27:44 UTC
Created attachment 66742 [details]
sysprof file captured while kwin repaints the whole screen

Same here:
Qt: 4.7.4
KDE Development Platform: 4.7.90 (4.8 Beta2 (4.7.90)
KWin: 4.7.90 (4.8 Beta2 (4.7.90)

OpenGL renderer string: Mesa DRI Intel(R) Sandybridge Mobile 
OpenGL version string: 2.1 Mesa 7.11

x11-drivers/xf86-video-intel-2.17.0.-r3

It turned out, that when the CPU usage is unusually high, the whole screen is reported as damaged, thus everything is constantly repainted (the whole screen flickers when enabling the "Show Paint" effect).

Attached is a sysprof file which probably provides more information.
Comment 3 Marian Kyral 2011-12-14 15:53:16 UTC
(In reply to comment #1)
> Please check whether suspending / resuming the compositor is sufficient in this
> case 

Yes, suspend/resume composition help.

> and whether it happens with all window decorations.
Sorry, I don't understood.
Comment 4 Thomas Lübking 2011-12-14 16:18:14 UTC
Option 1:
some window (would be plasma-desktop) has constant relatively small repaints but the damageratio is iscalculated / not reset ("kquitapp plasma-desktop" would resolve the issue as well)

Option 2: (more likely, relatively high load in builtin effects and QTimeLine)
some effect didn't catch the exit

@elias:
please post your enabled effects for a cross check:
grep -iE 'kwin4_effect_.*Enabled=true' `kde4-config --path config | cut -d":" -f1`/kwinrc | sed -e 's/kwin4_effect_//g; s/Enabled=true//g'

@Marian:
Deco aspect is atm. likely no more relevant

@Martin and ftr:
"qdbus org.kde.kwin /Compositor activeEffects" ... =)
(@anyone else: no - this doesn't exist atm.)
Comment 5 Martin Flöser 2011-12-14 16:27:55 UTC
> "qdbus org.kde.kwin /Compositor activeEffects" ... =)
> (@anyone else: no - this doesn't exist atm.)
qdbus org.kde.kwin /KWin toggleEffect "nameofeffect"

not elegant, but should do the same, shouldn't it?
Comment 6 Thomas Lübking 2011-12-14 17:02:22 UTC
i meant mor like this:

QStringList activeEffects;
for(QVector< KWin::EffectPair >::iterator it = loaded_effects.begin(); it != loaded_effects.end(); ++it) {
        if (it->second->isActive()) {
            activeEffects << it->second->metaObject()->className();
        }
    }

return activeEffects;
Comment 7 Martin Flöser 2011-12-14 17:09:23 UTC
ah that makes more sense now :-) and yeah that could help in such cases a lot
Comment 8 Marian Kyral 2011-12-30 22:23:36 UTC
Hi,
I just tested 4.8 RC1, situation still the same. I have to restart composition/kwin from time to time.
Comment 9 Thomas Lübking 2011-12-30 22:37:39 UTC
please cross check bug #290025 and disable the "sliding popups" effect. Also report on the outcome (so we can dupe the other bug in case)
Comment 10 Marian Kyral 2011-12-30 23:49:57 UTC
Ok,
I'll do it and let you know next week as I'm offline for next two days.
Comment 11 Thomas Lübking 2012-01-02 17:54:38 UTC
Git commit 089aeee91b807d13c0c2b86fa18d05776bef5190 by Thomas Lübking.
Committed on 29/12/2011 at 23:33.
Pushed by luebking into branch 'master'.

add dbus debug "activeEffects"

REVIEW: 103572
Related: bug 290025

M  +7    -0    kwin/composite.cpp
M  +12   -0    kwin/effects.cpp
M  +1    -0    kwin/effects.h
M  +3    -0    kwin/org.kde.KWin.xml
M  +1    -0    kwin/workspace.h

http://commits.kde.org/kde-workspace/089aeee91b807d13c0c2b86fa18d05776bef5190
Comment 12 Thomas Lübking 2012-01-02 18:22:55 UTC
Git commit 4d2f807179424424ac25df56b420622946fe505e by Thomas Lübking.
Committed on 29/12/2011 at 23:33.
Pushed by luebking into branch 'KDE/4.8'.

add dbus debug "activeEffects"

REVIEW: 103572
Related: bug 290025
(cherry picked from commit 089aeee91b807d13c0c2b86fa18d05776bef5190)

M  +7    -0    kwin/composite.cpp
M  +12   -0    kwin/effects.cpp
M  +1    -0    kwin/effects.h
M  +3    -0    kwin/org.kde.KWin.xml
M  +1    -0    kwin/workspace.h

http://commits.kde.org/kde-workspace/4d2f807179424424ac25df56b420622946fe505e
Comment 13 Marian Kyral 2012-01-04 10:26:40 UTC
Hi,
I disabled the "sliding popups" effect and now it is much better. I don't need to restart kwin anymore.

The activeEffects function shows me, the kwin4_effect_translucency is always active. I don't know, if it is correct.

$ qdbus org.kde.kwin /KWin activeEffects
kwin4_effect_translucency
Comment 14 Philipp Knechtges 2012-01-12 19:51:53 UTC
Git commit 2da6447499e363582e332f2e7a845265557c6353 by Philipp Knechtges.
Committed on 12/01/2012 at 20:40.
Pushed by knechtges into branch 'KDE/4.8'.

kwin: fixing high cpu usage in the fade effect

This is a condensed version of Martin's patch that fixes a high cpu
usage in KWin and X. It seems to be due to a window being created and
deleted at almost the same time, such that the fade effect never quits.
The bug was reliably reproducable with starting Amarok.
Related: bug 290025

M  +6    -4    kwin/effects/fade/fade.cpp

http://commits.kde.org/kde-workspace/2da6447499e363582e332f2e7a845265557c6353
Comment 15 Philipp Knechtges 2012-01-19 14:38:58 UTC
Git commit d07964e0af95911a97c3f474b694570cb279878c by Philipp Knechtges.
Committed on 19/01/2012 at 11:38.
Pushed by knechtges into branch 'KDE/4.8'.

kwin: fixing high cpu usage bugs

In some unfortunate situations it is possible that a window is deleted
before it is marked ready_for_painting=true. The last point is
especially troublesome for effects that reference the deleted window.

Many thanks to Elias Probst for all the testing.
Related: bug 290025
REVIEW: 103733

M  +9    -0    kwin/deleted.cpp
M  +2    -1    kwin/deleted.h

http://commits.kde.org/kde-workspace/d07964e0af95911a97c3f474b694570cb279878c
Comment 16 Philipp Knechtges 2012-02-10 10:03:33 UTC
Closing the bug as fixed. If somebody should still experience the issue, feel free to reopen.