Bug 198665

Summary: battery drain during system shutdown
Product: Power Management Reporter: Gopal (s10gopal)
Component: Hibernation/SuspendAssignee: Rafael J. Wysocki (rjw)
Status: CLOSED PATCH_ALREADY_AVAILABLE    
Severity: high CC: andreanottoli, kai.heng.feng, linux, rui.zhang, s10gopal
Priority: P1    
Hardware: All   
OS: Linux   
See Also: https://launchpad.net/bugs/1745646
Kernel Version: 4.13-rc1 Subsystem:
Regression: Yes Bisected commit-id:

Description Gopal 2018-02-04 14:12:05 UTC
for more details please see https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1745646
Comment 1 Gopal 2018-02-04 14:24:14 UTC
Linux gopal-HP-Notebook 4.15.0-041500-generic #201802011154 SMP Thu Feb 1 11:55:45 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

GNU C               	5.4.0
GNU Make            	4.1
Binutils            	2.26.1
Util-linux          	2.27.1
Mount               	2.27.1
Module-init-tools   	22
E2fsprogs           	1.42.13
Pcmciautils         	018
PPP                 	2.4.7
Linux C Library     	2.23
Dynamic linker (ldd)	2.23
Linux C++ Library   	6.0.21
Procps              	3.3.10
Net-tools           	1.60
Kbd                 	1.15.5
Console-tools       	1.15.5
Sh-utils            	8.25
Udev                	229
Wireless-tools      	30
Modules Loaded      	ac97_bus acpi_pad acpi_thermal_rel aesni_intel aes_x86_64 ahci amdgpu amd_iommu_v2 amdkfd autofs4 bluetooth bnep btbcm btintel btrtl btusb chash coretemp crc32_pclmul crct10dif_pclmul cryptd crypto_simd drm drm_kms_helper ecdh_generic fb_sys_fops ghash_clmulni_intel glue_helper hp_wireless hp_wmi i2c_algo_bit i915 input_leds int3400_thermal int340x_thermal_zone intel_cstate intel_pch_thermal intel_powerclamp intel_rapl intel_rapl_perf intel_soc_dts_iosf intel_wmi_thunderbolt irqbypass joydev kvm libahci lp mac_hid media mei mei_me mii parport parport_pc pcbc ppdev processor_thermal_device psmouse r8169 rfcomm serio_raw shpchp snd snd_compress snd_hda_codec snd_hda_codec_generic snd_hda_codec_hdmi snd_hda_codec_realtek snd_hda_core snd_hda_ext_core snd_hda_intel snd_hwdep snd_pcm snd_pcm_dmaengine snd_rawmidi snd_seq snd_seq_device snd_seq_midi snd_seq_midi_event snd_soc_acpi snd_soc_core snd_soc_skl snd_soc_skl_ipc snd_soc_sst_dsp snd_soc_sst_ipc snd_timer soundcore sparse_keymap syscopyarea sysfillrect sysimgblt ttm uvcvideo video videobuf2_core videobuf2_memops videobuf2_v4l2 videobuf2_vmalloc videodev wmi wmi_bmof x86_pkg_temp_thermal
Comment 2 Gopal 2018-02-04 17:49:00 UTC
System: Host: gopal-HP-Notebook Kernel: 4.15.0-041500-generic x86_64 (64 bit gcc: 7.2.0)
           Desktop: Unity 7.4.0 (Gtk 3.18.9-1ubuntu3.3) dm: lightdm
           Distro: Ubuntu 16.04 xenial
Machine: System: HP product: HP Notebook v: Type1ProductConfigId
           Mobo: HP model: 81EC v: 61.58 Bios: Insyde v: F.40 date: 11/01/2017
           Chassis: type: 10
CPU: Dual core Intel Core i5-6200U (-HT-MCP-) cache: 3072 KB
           flags: (lm nx sse sse2 sse3 sse4_1 sse4_2 ssse3 vmx) bmips: 9600
           clock speeds: min/max: 400/2800 MHz 1: 987 MHz 2: 547 MHz
           3: 567 MHz 4: 541 MHz
Graphics: Card-1: Intel Sky Lake Integrated Graphics
           bus-ID: 00:02.0 chip-ID: 8086:1916
           Card-2: Advanced Micro Devices [AMD/ATI] Sun XT [Radeon HD 8670A/8670M/8690M / R5 M330]
           bus-ID: 01:00.0 chip-ID: 1002:6660
           Display Server: X.Org 1.19.5 drivers: (unloaded: fbdev,vesa)
           Resolution: 1366x768@60.02hz
           GLX Renderer: Mesa DRI Intel HD Graphics 520 (Skylake GT2)
           GLX Version: 3.0 Mesa 17.2.4 Direct Rendering: Yes
Audio: Card Intel Sunrise Point-LP HD Audio
           driver: snd_hda_intel bus-ID: 00:1f.3 chip-ID: 8086:9d70
           Sound: Advanced Linux Sound Architecture v: k4.15.0-041500-generic
Network: Card-1: Realtek RTL8101/2/6E PCI Express Fast/Gigabit Ethernet controller
           driver: r8169 v: 2.3LK-NAPI port: 3000
           bus-ID: 02:00.0 chip-ID: 10ec:8136
           IF: enp2s0 state: up speed: 100 Mbps duplex: full mac: <filter>
           Card-2: Broadcom BCM43142 802.11b/g/n
           bus-ID: 03:00.0 chip-ID: 14e4:4365
           IF: N/A state: N/A mac: N/A
Drives: HDD Total Size: 120.0GB (4.7% used)
           ID-1: /dev/sda model: ADATA_SP580 size: 120.0GB serial: H30276K015977 temp: 43C
Partition: ID-1: / size: 110G used: 5.3G (6%) fs: ext4 dev: /dev/sda1
RAID: System: supported: N/A
           No RAID devices: /proc/mdstat, md_mod kernel module present
           Unused Devices: none
Sensors: System Temperatures: cpu: 37.0C mobo: 29.8C
           Fan Speeds (in rpm): cpu: N/A
Repos: Active apt sources in file: /etc/apt/sources.list
           deb http://in.archive.ubuntu.com/ubuntu/ xenial main restricted
           deb http://in.archive.ubuntu.com/ubuntu/ xenial-updates main restricted
           deb http://in.archive.ubuntu.com/ubuntu/ xenial universe
           deb http://in.archive.ubuntu.com/ubuntu/ xenial-updates universe
           deb http://in.archive.ubuntu.com/ubuntu/ xenial multiverse
           deb http://in.archive.ubuntu.com/ubuntu/ xenial-updates multiverse
           deb http://in.archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
           deb http://security.ubuntu.com/ubuntu xenial-security main restricted
           deb http://security.ubuntu.com/ubuntu xenial-security universe
           deb http://security.ubuntu.com/ubuntu xenial-security multiverse
Info: Processes: 202 Uptime: 1:42 Memory: 1059.6/11900.5MB
           Init: systemd v: 229 runlevel: 5 default: 2 Gcc sys: 5.4.0
           Client: Shell (bash 4.3.481 running in gnome-terminal-) inxi: 2.2.35
Comment 4 Gopal 2018-02-04 17:54:27 UTC
Feb 04 19:15:31 gopal-HP-Notebook kernel: acpi PNP0A08:00: _OSC failed (AE_ERROR); disabling ASPM
Feb 04 19:15:31 gopal-HP-Notebook kernel: ACPI Warning: GPE type mismatch (level/edge) (20170831/evxface-826)
Feb 04 19:15:31 gopal-HP-Notebook kernel: RAS: Correctable Errors collector initialized.
Feb 04 19:15:31 gopal-HP-Notebook kernel: ata1.00: READ LOG DMA EXT failed, trying PIO
Feb 04 19:15:31 gopal-HP-Notebook kernel: ata1.00: failed to set xfermode (err_mask=0x40)
Feb 04 19:15:32 gopal-HP-Notebook kernel: EXT4-fs (sda1): re-mounted. Opts: errors=remount-ro
Feb 04 19:15:32 gopal-HP-Notebook gpu-manager[530]: Error: can't open /lib/modules/4.15.0-041500-generic/updates/dkms
Feb 04 19:15:32 gopal-HP-Notebook gpu-manager[530]: Error: can't open /lib/modules/4.15.0-041500-generic/updates/dkms
Feb 04 19:15:32 gopal-HP-Notebook gpu-manager[530]: update-alternatives: error: no alternatives for x86_64-linux-gnu_gfxcore_conf
Feb 04 19:15:32 gopal-HP-Notebook kernel: bluetooth hci0: Direct firmware load for brcm/BCM.hcd failed with error -2
Feb 04 19:15:32 gopal-HP-Notebook thermald[639]: sysfs read failed max_brightness
Feb 04 19:15:32 gopal-HP-Notebook thermald[639]: Zone update failed: unable to bind
Feb 04 19:15:32 gopal-HP-Notebook thermald[639]: Zone update failed: unable to bind
Feb 04 19:15:32 gopal-HP-Notebook thermald[639]: Zone update failed: unable to bind
Feb 04 19:15:32 gopal-HP-Notebook NetworkManager[631]: <warn>  [1517751932.7615] SettingsPlugin-Ofono: file doesn't exist: /var/lib/ofono
Feb 04 19:15:32 gopal-HP-Notebook snapd[640]: 2018/02/04 19:15:32.813892 stateengine.go:98: state ensure error: Get https://api.snapcraft.io/api/v1/snaps/sections: dial tcp: lookup api.snapcraft.io on [::1]:53: read udp [::1]:51569->[::1]:53: read: connection refused
Feb 04 19:15:33 gopal-HP-Notebook kernel: hp_wmi: query 0xd returned error 0x5
Feb 04 19:15:33 gopal-HP-Notebook NetworkManager[631]: nm_device_get_device_type: assertion 'NM_IS_DEVICE (self)' failed
Feb 04 19:15:33 gopal-HP-Notebook NetworkManager[631]: <warn>  [1517751933.0558] failed to enumerate oFono devices: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.ofono was not provided by any .service files
Feb 04 19:15:34 gopal-HP-Notebook org.a11y.Bus[1032]: ** (process:1135): WARNING **: Failed to register client: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files
Feb 04 19:15:34 gopal-HP-Notebook bluetoothd[1151]: Failed to obtain handles for "Service Changed" characteristic
Feb 04 19:15:34 gopal-HP-Notebook bluetoothd[1151]: Error adding Link Loss service
Feb 04 19:15:34 gopal-HP-Notebook bluetoothd[1151]: gatt-time-server: Input/output error (5)
Feb 04 19:15:34 gopal-HP-Notebook bluetoothd[1151]: Sap driver initialization failed.
Feb 04 19:15:36 gopal-HP-Notebook org.gnome.ScreenSaver[1032]: ** (gnome-screensaver:1269): WARNING **: Couldn't get presence status: The name org.gnome.SessionManager was not provided by any .service files
Feb 04 19:15:36 gopal-HP-Notebook org.gnome.ScreenSaver[1032]: ** (gnome-screensaver:1269): WARNING **: Config key not handled: picture-opacity
Feb 04 19:15:36 gopal-HP-Notebook org.gnome.ScreenSaver[1032]: ** (gnome-screensaver:1269): WARNING **: Config key not handled: primary-color
Feb 04 19:15:36 gopal-HP-Notebook org.gnome.ScreenSaver[1032]: ** (gnome-screensaver:1269): WARNING **: Config key not handled: secondary-color
Feb 04 19:15:36 gopal-HP-Notebook org.gnome.ScreenSaver[1032]: ** (gnome-screensaver:1269): WARNING **: Config key not handled: color-shading-type
Feb 04 19:15:36 gopal-HP-Notebook org.gnome.ScreenSaver[1032]: ** (gnome-screensaver:1269): WARNING **: Config key not handled: show-notifications
Feb 04 19:15:36 gopal-HP-Notebook org.gnome.ScreenSaver[1032]: ** (gnome-screensaver:1269): WARNING **: Config key not handled: picture-options
Feb 04 19:15:36 gopal-HP-Notebook org.gnome.ScreenSaver[1032]: ** (gnome-screensaver:1269): WARNING **: Config key not handled: show-full-name-in-top-bar
Feb 04 19:15:36 gopal-HP-Notebook org.gnome.ScreenSaver[1032]: ** (gnome-screensaver:1269): WARNING **: Config key not handled: picture-uri
Feb 04 19:15:36 gopal-HP-Notebook org.gnome.ScreenSaver[1032]: ** (gnome-screensaver:1269): WARNING **: Config key not handled: disable-command-line
Feb 04 19:15:36 gopal-HP-Notebook org.gnome.ScreenSaver[1032]: ** (gnome-screensaver:1269): WARNING **: Config key not handled: disable-application-handlers
Feb 04 19:15:36 gopal-HP-Notebook org.gnome.ScreenSaver[1032]: ** (gnome-screensaver:1269): WARNING **: Config key not handled: user-administration-disabled
Feb 04 19:15:36 gopal-HP-Notebook org.gnome.ScreenSaver[1032]: ** (gnome-screensaver:1269): WARNING **: Config key not handled: disable-printing
Feb 04 19:15:36 gopal-HP-Notebook org.gnome.ScreenSaver[1032]: ** (gnome-screensaver:1269): WARNING **: Config key not handled: disable-log-out
Feb 04 19:15:36 gopal-HP-Notebook org.gnome.ScreenSaver[1032]: ** (gnome-screensaver:1269): WARNING **: Config key not handled: disable-print-setup
Feb 04 19:15:36 gopal-HP-Notebook org.gnome.ScreenSaver[1032]: ** (gnome-screensaver:1269): WARNING **: Config key not handled: disable-save-to-disk
Feb 04 19:15:36 gopal-HP-Notebook pulseaudio[1306]: [pulseaudio] backend-ofono.c: Failed to register as a handsfree audio agent with ofono: org.freedesktop.DBus.Error.ServiceUnknown: The name org.ofono was not provided by any .service files
Feb 04 19:15:36 gopal-HP-Notebook gnome-session[1184]: (process:1371): indicator-application-service-WARNING **: Unable to get watcher name 'org.kde.StatusNotifierWatcher'
Feb 04 19:15:36 gopal-HP-Notebook gnome-session[1184]: (process:1371): indicator-application-service-WARNING **: Name Lost
Feb 04 19:15:36 gopal-HP-Notebook dnsmasq[1426]: warning: no upstream servers configured
Feb 04 19:15:37 gopal-HP-Notebook org.freedesktop.fwupd[539]: (fwupd:1417): Fu-WARNING **: Failed to coldplug: UEFI firmware updating not supported
Feb 04 19:15:56 gopal-HP-Notebook gnome-session[1184]: (zeitgeist-datahub:1633): Gtk-WARNING **: Attempting to read the recently used resources file at '/home/gopal/.local/share/recently-used.xbel', but the parser failed: Failed to open file '/home/gopal/.local/share/recently-used.xbel': Permission denied.
Feb 04 19:15:56 gopal-HP-Notebook org.gnome.zeitgeist.Engine[1032]: ** (zeitgeist-datahub:1653): WARNING **: zeitgeist-datahub.vala:229: Unable to get name "org.gnome.zeitgeist.datahub" on the bus!
Feb 04 19:36:44 gopal-HP-Notebook com.canonical.Unity.Scope.Applications[1032]: Error loading package indexes: Couldn't stat '/var/cache/software-center/xapian'
Feb 04 19:36:44 gopal-HP-Notebook com.canonical.Unity.Scope.Applications[1032]: (unity-scope-loader:2170): unity-applications-daemon-CRITICAL **: daemon.vala:144: Failed to load Software Center index. 'Apps Available for Download' will not be listed
Feb 04 20:15:36 gopal-HP-Notebook org.gnome.evolution.dataserver.Sources5[1032]: ** (evolution-source-registry:1297): WARNING **: secret_service_search_sync: must specify at least one attribute to match
Feb 04 20:32:27 gopal-HP-Notebook upowerd[1214]: (upowerd:1214): UPower-Linux-WARNING **: energy 36.748400 bigger than full 36.733600
Comment 5 Gopal 2018-02-04 17:58:18 UTC
many other laptop users are also facing the same issue . The problem don't occur when i install windows 10 . Now, only ubuntu is installed.
i am using latest bios insyde20 rev 5.(latest)
WOL disabled and no usb device connected
checked my battery .
it don't happen when i remove battery and plug it again after shutdown.
tried laptop_mode_tools and tpl too
Comment 6 Zhang Rui 2018-02-05 01:46:53 UTC
*** Bug 198663 has been marked as a duplicate of this bug. ***
Comment 7 Zhang Rui 2018-02-05 02:02:42 UTC
(In reply to Gopal from comment #5)
> it don't happen when i remove battery and plug it again after shutdown.
> tried laptop_mode_tools and tpl too

Let's see how fast the battery drains. To do this,
please attach the output of "grep . /sys/class/power_supply/*/*" just before shutdown, and then leave the laptop for like 1 hour, boot it again and attach the output of "grep . /sys/class/power_supply/*/*"
and please do this test for both bad and good case, where good case means you can remove the battery and plug it again after shutdown.
Comment 8 Gopal 2018-02-05 10:22:09 UTC
Before shutdown http://paste.ubuntu.com/26523794/
Comment 9 Gopal 2018-02-05 11:32:40 UTC
bad case http://paste.ubuntu.com/26524029/
Comment 10 Gopal 2018-02-05 11:34:13 UTC
again shutting down http://paste.ubuntu.com/26524034/
Comment 11 Gopal 2018-02-05 12:27:12 UTC
best case http://paste.ubuntu.com/26524216/
Comment 12 TJ 2018-02-05 21:02:22 UTC
I see a lot of reports of this problem in HP online forums, but also for other manufacturers too.

The general consensus is that when powered off something on the motherboard is still drawing power.

There are reports of various components being the cause, from the Intel Management Engine (PCH) supervisor processor to built-in devices on the USB not being fully powered down.

This last one (some USB device) is the easiest to investigate and control from Linux.

Install the 'powertop' package and run the tool:

$ sudo powertop

Explore to get familiar with navigation and what information is available, then tab over to the "Tunables" page.

Instructions are at the bottom of the page.

Start off by changing the "Autosuspend for USB device * Host Controller" options so they all are in state "Good". This should ensure the USB internal hub is powered off and therefore no USB devices are powered.

Do your power-off test (preferably overnight) by collecting the state of the battery before and after shutdown as requested by Zhang Rui and report back, attaching the two captured /sys/class/power_supply/ logs and state:

1) how long the PC was shutdown
2) which powertop Tunables were changed

If that does not help try changing settings for remaining USB devices, especially if there is a USB Bluetooth device, and testing again.

As an alternative, before starting the experiment, you might find it worth using

$ sudo powertop --calibrate

This puts the system through an extended set of measurement tests to determine how much power each component is using. This can take several minutes so be patient as it suspends devices, adjusts backlight, and does other actions that might make you think the PC has crashed.
Comment 13 Gopal 2018-02-06 14:25:15 UTC
sudo powertop --calibrate
modprobe cpufreq_stats failedLoaded 41 prior measurements
Cannot load from file /var/cache/powertop/saved_parameters.powertop
File will be loaded after taking minimum number of measurement(s) with battery only 
RAPL device for cpu 0
RAPL Using PowerCap Sysfs : Domain Mask f
RAPL device for cpu 0
RAPL Using PowerCap Sysfs : Domain Mask f
Devfreq not enabled
Cannot load from file /var/cache/powertop/saved_parameters.powertop
File will be loaded after taking minimum number of measurement(s) with battery only 
Starting PowerTOP power estimate calibration 
Calibrating idle
System is not available
To show power estimates do 181 measurement(s) connected to battery only
System is not available
Calibrating: disk usage 
Calibrating backlight
.... device /sys/class/backlight/intel_backlight/brightness 
Calibrating idle
System is not available
System is not available
Calibrating: CPU usage on 1 threads
Calibrating: CPU usage on 4 threads
Calibrating: CPU wakeup power consumption
Calibrating: CPU wakeup power consumption
Calibrating: CPU wakeup power consumption
Calibrating USB devices
.... device /sys/bus/usb/devices/usb1/power/control 
.... device /sys/bus/usb/devices/1-5/power/control 
.... device /sys/bus/usb/devices/usb2/power/control 
.... device /sys/bus/usb/devices/1-4/power/control 
Calibrating radio devices
.... device /sys/class/rfkill/rfkill0/soft 
.... device /sys/class/rfkill/rfkill0/soft 
Finishing PowerTOP power estimate calibration 
Parameters after calibration:


Parameter state 
----------------------------------
Value		Name
 0.50		alsa-codec-power (13)
 0.00		backlight (4)
 0.00		backlight-boost-100 (8)
 0.00		backlight-boost-40 (6)
 0.00		backlight-boost-80 (7)
 0.00		backlight-power (5)
 0.67		base power (69)
 1.56		cpu-consumption (3)
39.50		cpu-wakeups (2)
 0.00		disk-operations (72)
 0.20		disk-operations-hard (71)
 0.00		enp2s0-link-100 (17)
 0.00		enp2s0-link-1000 (18)
 0.00		enp2s0-link-high (19)
 0.00		enp2s0-packets (20)
 0.00		enp2s0-powerunsave (16)
 0.00		enp2s0-up (15)
 0.56		gpu-operations (70)
 0.00		radio:hci0 (14)
 0.00		runtime-0000:00:00.0 (22)
 0.00		runtime-0000:00:02.0 (25)
 0.00		runtime-0000:00:04.0 (34)
 0.00		runtime-0000:00:14.0 (26)
 0.00		runtime-0000:00:14.2 (23)
 0.00		runtime-0000:00:16.0 (36)
 0.00		runtime-0000:00:17.0 (28)
 0.00		runtime-0000:00:1c.0 (31)
 0.00		runtime-0000:00:1c.4 (24)
 0.00		runtime-0000:00:1c.5 (35)
 0.00		runtime-0000:00:1f.0 (32)
 0.00		runtime-0000:00:1f.2 (29)
 0.00		runtime-0000:00:1f.3 (21)
 0.00		runtime-0000:00:1f.4 (27)
 0.00		runtime-0000:01:00.0 (37)
 0.00		runtime-0000:02:00.0 (33)
 0.00		runtime-0000:03:00.0 (30)
 0.00		runtime-ACPI0003:00 (55)
 0.00		runtime-ACPI000C:00 (64)
 0.00		runtime-Fixed MDIO bus.0 (58)
 0.00		runtime-HPQ6001:00 (42)
 0.00		runtime-INT0800:00 (44)
 0.00		runtime-INT3400:00 (38)
 0.00		runtime-PNP0103:00 (40)
 0.00		runtime-PNP0C09:00 (50)
 0.00		runtime-PNP0C0A:00 (51)
 0.00		runtime-PNP0C0B:00 (43)
 0.00		runtime-PNP0C0B:01 (53)
 0.00		runtime-PNP0C0B:02 (41)
 0.00		runtime-PNP0C0B:03 (52)
 0.00		runtime-PNP0C0B:04 (63)
 0.00		runtime-PNP0C0D:00 (49)
 0.00		runtime-PNP0C14:00 (48)
 0.00		runtime-PNP0C14:01 (61)
 0.00		runtime-alarmtimer (46)
 0.00		runtime-coretemp.0 (47)
 0.00		runtime-hp-wmi (54)
 0.00		runtime-i2c-0 (68)
 0.00		runtime-i2c-1 (66)
 0.00		runtime-i2c-2 (67)
 0.00		runtime-i2c-3 (65)
 0.00		runtime-i8042 (62)
 0.00		runtime-microcode (45)
 0.00		runtime-pcspkr (56)
 0.00		runtime-reg-dummy (39)
 0.00		runtime-serial8250 (60)
 0.00		runtime-snd-soc-dummy (59)
 0.00		runtime-vesa-framebuffer.0 (57)
 0.10		usb-device-04f2-b56c (10)
 0.10		usb-device-0a5c-216d (12)
 0.10		usb-device-1d6b-0002 (9)
 0.10		usb-device-1d6b-0003 (11)
 0.10		xwakes (73)

Score:    5.0  (15731.6)
Guess:    0.7
Actual:  10.4
Comment 14 Gopal 2018-02-06 14:56:29 UTC
Thee battery reports a discharge rate of 10.6 W
Default powertop https://paste.ubuntu.com/26530113/
All set to GOOD
Before shutdown http://paste.ubuntu.com/26530231/
Comment 15 Gopal 2018-02-06 21:26:39 UTC
bad case after powertop http://paste.ubuntu.com/26532153/
Comment 16 Gopal 2018-02-07 09:28:31 UTC
before shutdown(6 Feb 2018 21:28:06)http://paste.ubuntu.com/26532160/
bad case(Wed, 7 Feb 2018 08:39:52) https://paste.ubuntu.com/26534603/
Comment 17 Gopal 2018-02-11 11:50:21 UTC
After installing Ubuntu 14.04.05 LTS , i think my problem is solved 
WOL is on.
Before shutdown https://paste.ubuntu.com/=jyDm4qrdR7/
After 15 hours, the bad case is https://paste.ubuntu.com/=qFTztm4jrJ/.
Comment 18 Gopal 2018-02-11 12:11:07 UTC
SOSreport of ubuntu 14.04.05LTS, https://drive.google.com/open?id=1Hl-G1IFmMSP-Xv0fa9EBnUFylbGxDcTY
Comment 19 Zhang Rui 2018-02-12 02:53:09 UTC
so the problem exists with Ubuntu 16.04, which uses 4.15.0-041500-generic kernel, and can not be reproduced with Ubuntu 14.04. which uses a pretty old kernel?

what kernel version are you using with 14.04?
can you please confirm
1. if the problem still exists with the latest upstream kernel?
2. if the problem is gone with a vanilla kernel with the same version as you're using with Ubuntu 14.04?

I want to confirm this is an upstream kernel regression instead of a distro kernel issue.
Comment 20 Gopal 2018-02-12 05:00:01 UTC
i'm using 4.4.0-31-generic .
Yes it still exists with the latest upstream kernel . 

I tried to install old kernel in ubuntu 16.04 (4.10 ,4.11 ,4.8) but my laptop became super laggy . Random processor was going to 99% in use and rest 3 were around 12% in use.
Comment 21 Gopal 2018-03-30 20:53:15 UTC
how to fix it?
Comment 22 Gopal 2018-03-31 11:35:31 UTC
Linux gopal-HP-Notebook 4.9.0-040900-generic #201612111631 SMP Sun Dec 11 21:33:00 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

before shutdown : http://paste.ubuntu.com/p/5ZhtmvgdxW/
Comment 23 Gopal 2018-03-31 15:32:21 UTC
after 4 hours  http://paste.ubuntu.com/p/wK4M3h63Kd/
Comment 24 Gopal 2018-03-31 17:22:20 UTC
Linux gopal-HP-Notebook 4.10.0-041000-generic #201702191831 SMP Sun Feb 19 23:33:19 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

before shutdown http://paste.ubuntu.com/p/TBGrfwNCky/
Comment 25 Gopal 2018-04-01 04:17:56 UTC
worst case : http://paste.ubuntu.com/p/wxvYkm2NWR/
Comment 26 Gopal 2018-04-01 04:42:08 UTC
Linux gopal-HP-Notebook 4.13.0-041300-generic #201709031731 SMP Sun Sep 3 21:33:09 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

before shutdown http://paste.ubuntu.com/p/dNckNGq5dX/
Comment 27 Gopal 2018-04-01 08:49:54 UTC
http://paste.ubuntu.com/p/z4YzsPCptx/

Problem exists on kernel 4.13. Now trying 4.11
Comment 28 Gopal 2018-04-01 09:13:55 UTC
Linux gopal-HP-Notebook 4.11.0-041100-generic #201705041534 SMP Thu May 4 19:36:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

before shutdown : http://paste.ubuntu.com/p/FGNP4DBxw7/
Comment 29 Gopal 2018-04-01 13:00:07 UTC
worst case : http://paste.ubuntu.com/p/SgfWvT9C9d/
Comment 30 Gopal 2018-04-01 18:46:35 UTC
Linux gopal-HP-Notebook 4.12.0-041200-generic #201707022031 SMP Mon Jul 3 00:32:52 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

before shutdown : http://paste.ubuntu.com/p/ZkbNttX625/
Comment 31 Gopal 2018-04-02 03:51:59 UTC
worst case : http://paste.ubuntu.com/p/WwKtycckSr/
Comment 32 Zhang Rui 2018-04-02 07:27:27 UTC
could you please check if this is related to https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=694926?
Comment 33 Gopal 2018-04-02 17:47:08 UTC
(In reply to Zhang Rui from comment #32)
> could you please check if this is related to
> https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=694926?

already tried http://iam.tj/prototype/enhancements/Windows-acpi_osi.html
Comment 34 Gopal 2018-04-02 18:52:20 UTC
the problem dont exists in kernel 4.12 . it exists in kernel 4.13 .
Comment 35 Zhang Rui 2018-04-03 02:40:00 UTC
(In reply to Gopal from comment #33)
> (In reply to Zhang Rui from comment #32)
> > could you please check if this is related to
> > https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=694926?
> 
> already tried http://iam.tj/prototype/enhancements/Windows-acpi_osi.html

no, I'm not talking about acpi_osi=, what I'm suggesting is to disable "hwclock --systohc" during shutdown.
Comment 36 Gopal 2018-04-03 10:10:44 UTC
Linux gopal-HP-Notebook 4.16.0-041600-generic #201804012230 SMP Sun Apr 1 22:31:39 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

i have disabled hwclock --systohc. Battery log before shutdown : http://paste.ubuntu.com/p/CCcKW3VpVB/
Comment 37 Gopal 2018-04-03 16:16:26 UTC
worst case : http://paste.ubuntu.com/p/4G3w2XBK7q/
Comment 38 Gopal 2018-04-09 05:42:26 UTC
de3ef1eb1cd0cc3a75f7a3661e10ed827f370ab8 is the first bad commit
commit de3ef1eb1cd0cc3a75f7a3661e10ed827f370ab8
Author: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Date: Sat Jun 24 01:58:53 2017 +0200

    PM / core: Drop run_wake flag from struct dev_pm_info

    The run_wake flag in struct dev_pm_info is used to indicate whether
    or not the device is capable of generating remote wakeup signals at
    run time (or in the system working state), but the distinction
    between runtime remote wakeup and system wakeup signaling has always
    been rather artificial. The only practical reason for it to exist
    at the core level was that ACPI and PCI treated those two cases
    differently, but that's not the case any more after recent changes.

    For this reason, get rid of the run_wake flag and, when applicable,
    use device_set_wakeup_capable() and device_can_wakeup() instead of
    device_set_run_wake() and device_run_wake(), respectively.

    Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
    Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
    Acked-by: Bjorn Helgaas <bhelgaas@google.com>

:040000 040000 b7e983a56143bcad79fcdb47c0af4e26c4c7d7f4 a41d44ab0981a6325dd132c733e00ef8747e175b M Documentation
:040000 040000 9df91d40497710be13ccd56f73f974b087de0037 e14e2b8fc91b14391e62d226b80216a17b51961e M drivers
:040000 040000 6bf369eb0d91309a77ccdb94ec417d62a5716cfd 87d9359a0e260ba93f314ba48b899daeb07f1076 M include
Comment 39 Gopal 2018-04-09 06:05:04 UTC
http://paste.ubuntu.com/p/6y3XBgs5xJ/
Comment 40 Zhang Rui 2018-05-07 06:46:49 UTC
gopal, then can you please confirm 
1. the problem exists with kernel "git checkout de3ef1eb1cd0cc3a75f7a3661e10ed827f370ab8"
2. the problem does not exist with kernel "git checkout de3ef1eb1cd0cc3a75f7a3661e10ed827f370ab8~"
Comment 42 Gopal 2018-05-13 10:55:32 UTC
BugLink: http://bugs.launchpad.net/bugs/1765646

== SRU Justification ==
A regression was introduced in 4.13-rc1 and newer kernels.  This
regression caused battery drain during system suspend, hibernation or 
shutdown for some PCI devices that are not allowed by user space to wake 
up the system from sleep (or power off).

This fix has been submitted upstream and cc'd to stable.  However, it
has not landed in linux-next or mainline yet, so it is being sent as
SAUCE.

== Fix ==
UBUNTU: SAUCE: PCI / PM: Check device_may_wakeup() in pci_enable_wake()

== Regression Potential ==
Medium.  Commit fixes a current regresssion, but affects PCI power management.  
It will also be submitted to upstream stable and have additional review.
The commit is a clean cherry pick, builds successfully and was confirmed
to resolve regression.

== Test Case ==
A test kernel was built with this patch and tested by the original bug reporter.
The bug reporter states the test kernel resolved the bug.

Rafael J. Wysocki (1):
  PCI / PM: Check device_may_wakeup() in pci_enable_wake()

 drivers/pci/pci.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

-- 
2.7.4
Comment 43 Gopal 2018-05-13 10:57:15 UTC
From: "Rafael J. Wysocki" <rafael.j.wysocki at intel.com>

BugLink: http://bugs.launchpad.net/bugs/1765646

Commit 0847684cfc5f0 (PCI / PM: Simplify device wakeup settings code)
went too far and dropped the device_may_wakeup() check from
pci_enable_wake() which causes wakeup to be enabled during system
suspend, hibernation or shutdown for some PCI devices that are not
allowed by user space to wake up the system from sleep (or power off).

As a result of this excessive power is drawn by some of the affected
systems while in sleep states or off.

Restore the device_may_wakeup() check in pci_enable_wake(), but make
sure that the PCI bus type's runtime suspend callback will not call
device_may_wakeup() which is about system wakeup from sleep and not
about device wakeup from runtime suspend.

Fixes: 0847684cfc5f0 (PCI / PM: Simplify device wakeup settings code)
Reported-by: Joseph Salisbury <joseph.salisbury at canonical.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki at intel.com>
Signed-off-by: Joseph Salisbury <joseph.salisbury at canonical.com>
---
 drivers/pci/pci.c | 29 +++++++++++++++++++++++------
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 8eac876..b1faa84 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1893,7 +1893,7 @@ void pci_pme_active(struct pci_dev *dev, bool enable)
 EXPORT_SYMBOL(pci_pme_active);
 
 /**
- * pci_enable_wake - enable PCI device as wakeup event source
+ * __pci_enable_wake - enable PCI device as wakeup event source
  * @dev: PCI device affected
  * @state: PCI state from which device will issue wakeup events
  * @enable: True to enable event generation; false to disable
@@ -1911,7 +1911,7 @@ EXPORT_SYMBOL(pci_pme_active);
  * Error code depending on the platform is returned if both the platform and
  * the native mechanism fail to enable the generation of wake-up events
  */
-int pci_enable_wake(struct pci_dev *dev, pci_power_t state, bool enable)
+static int __pci_enable_wake(struct pci_dev *dev, pci_power_t state, bool enable)
 {
 	int ret = 0;
 
@@ -1952,6 +1952,23 @@ int pci_enable_wake(struct pci_dev *dev, pci_power_t state, bool enable)
 
 	return ret;
 }
+
+/**
+ * pci_enable_wake - change wakeup settings for a PCI device
+ * @pci_dev: Target device
+ * @state: PCI state from which device will issue wakeup events
+ * @enable: Whether or not to enable event generation
+ *
+ * If @enable is set, check device_may_wakeup() for the device before calling
+ * __pci_enable_wake() for it.
+ */
+int pci_enable_wake(struct pci_dev *pci_dev, pci_power_t state, bool enable)
+{
+	if (enable && !device_may_wakeup(&pci_dev->dev))
+		return -EINVAL;
+
+	return __pci_enable_wake(pci_dev, state, enable);
+}
 EXPORT_SYMBOL(pci_enable_wake);
 
 /**
@@ -1964,9 +1981,9 @@ EXPORT_SYMBOL(pci_enable_wake);
  * should not be called twice in a row to enable wake-up due to PCI PM vs ACPI
  * ordering constraints.
  *
- * This function only returns error code if the device is not capable of
- * generating PME# from both D3_hot and D3_cold, and the platform is unable to
- * enable wake-up power for it.
+ * This function only returns error code if the device is not allowed to wake
+ * up the system from sleep or it is not capable of generating PME# from both
+ * D3_hot and D3_cold and the platform is unable to enable wake-up power for it.
  */
 int pci_wake_from_d3(struct pci_dev *dev, bool enable)
 {
@@ -2097,7 +2114,7 @@ int pci_finish_runtime_suspend(struct pci_dev *dev)
 
 	dev->runtime_d3cold = target_state == PCI_D3cold;
 
-	pci_enable_wake(dev, target_state, pci_dev_run_wake(dev));
+	__pci_enable_wake(dev, target_state, pci_dev_run_wake(dev));
 
 	error = pci_set_power_state(dev, target_state);
 
-- 
2.7.4
Comment 44 Zhang Rui 2018-05-30 05:38:57 UTC
*** Bug 199171 has been marked as a duplicate of this bug. ***