# Help with Power Management

## iopi

Hi -- I'm pretty unfamiliar with power management; I had KDE on my laptop and powerdevil seemed to work well, but I've recently switched to a simplistic openbox desktop.

I followed http://www.gentoo.org/doc/en/power-management-guide.xml and have acpid and laptop-mode-tools emerged.

My ultimate goal right now is to lock my screen on laptop lid close and maybe sleep/hibernate.  I edited my acpid default.sh to have a button event for lid.  Right now I just want to test that this event is even happening but I get nothing.

lm_lid.sh 

```

#!/bin/bash

echo "test" > /home/iopi/powereeee

test -x /usr/sbin/laptop_mode || exit 0

# lid button pressed/released event handler

/usr/sbin/laptop_mode auto

```

I've done a tail on state and it stays at open

```

tailf /proc/acpi/button/lid/LID0/state    

state:      open

```

In general, my laptop is almost always plugged in to power.

Guidance would be much appreciated  :Smile: .  I'm not even sure if acpid is the way to go.  I gave a shot at running powerdevil in the background (kded4 and then calling powerdevil module) -- works mostly; the lock screen command doesn't work and some of the other kde calls.  I'm wondering if maybe powerdevil has a script for each of the action items?

Thanks!

----------

## Hu

You say you "get nothing."  Does this mean that the shown lm_lid.sh is not executed at all?  Please post the full text of your acpid configuration files.  Also, install net-misc/socat, run socat - unix:/var/run/acpid.socket, close and reopen the lid, then post the output from that command.  This will show us the string that acpid matched against your configuration files.

----------

## iopi

I'm pretty sure lm_lid.sh is not being executed at all since I do not have the file in my /home/iopi

I tried the command you gave me and closed/opened the lid.  But no output.  I tried both on root and normal user.   Is there a more current route I should be going then acpid?   Below are my various configs/outputs/kernel config.

```

iopi@gentoo-laptop /etc/acpi $ socat - unix:/var/run/acpid.socket

```

ACPI is started

```

gentoo-laptop acpi # /etc/init.d/acpid start

 * WARNING: acpid has already been started

```

ACPI config:

default.sh

```

#!/bin/sh

# /etc/acpi/default.sh

# Default acpi script that takes an entry for all actions

set $*

group=${1%%/*}

action=${1#*/}

device=$2

id=$3

value=$4

log_unhandled() {

   logger "ACPI event unhandled: $*"

}

case "$group" in

   button)

      case "$action" in

         power)

            /sbin/init 0

            ;;

         # if your laptop doesnt turn on/off the display via hardware

         # switch and instead just generates an acpi event, you can force

         # X to turn off the display via dpms.  note you will have to run

         # 'xhost +local:0' so root can access the X DISPLAY.

         lid)

            /etc/acpid/actions/lm_lid.sh

         #   xset dpms force off

            ;;

         *)   log_unhandled $* ;;

      esac

      ;;

   ac_adapter)

      case "$value" in

         # Add code here to handle when the system is unplugged

         # (maybe change cpu scaling to powersave mode).  For

         # multicore systems, make sure you set powersave mode

         # for each core!

         #*0)

         #   cpufreq-set -g powersave

         #   ;;

         # Add code here to handle when the system is plugged in

         # (maybe change cpu scaling to performance mode).  For

         # multicore systems, make sure you set performance mode

         # for each core!

         #*1)

         #   cpufreq-set -g performance

         #   ;;

         *)   log_unhandled $* ;;

      esac

      ;;

   *)   log_unhandled $* ;;

esac

```

events/lm_lid

```

event=button[ /]lid

action=/etc/acpi/actions/lm_lid.sh %e

```

actions/lm_lid.sh

```

#!/bin/bash

echo "test" > /home/iopi/powereeee

test -x /usr/sbin/laptop_mode || exit 0

# lid button pressed/released event handler

/usr/sbin/laptop_mode auto

```

Relevant Kernel

```

  │ │           [*] Suspend to RAM and standby                                                      

  │ │           [*] Hibernation (aka 'suspend to disk')                                           

  │ │           ()    Default resume partition                                                   

  │ │           [ ] Run-time PM core functionality                                                

  │ │           [*] Power Management Debug Support                                            

  │ │           [ ]   Extra PM attributes in sysfs for low-level debugging/testing               

  │ │           [ ]   Test suspend/resume and wakealarm during bootup                      

  │ │           [*] Suspend/resume event tracing                                                  

  │ │           [*] ACPI (Advanced Configuration and Power Interface) Support  --->              

  │ │           [ ] SFI (Simple Firmware Interface) Support  --->                         

  │ │               CPU Frequency scaling  --->                                               

  │ │           -*- CPU idle PM support                                                     

  │ │           [ ]   Cpuidle Driver for Intel Processors                                         

  │ │               Memory power savings  --->                

  │ │           --- ACPI (Advanced Configuration and Power Interface) Support                  

  │ │           [*]   Deprecated /proc/acpi files                                             

  │ │           [ ]   Deprecated power /proc/acpi directories                                  

  │ │           < >   EC read/write access through /sys/kernel/debug/ec                          

  │ │           [*]   Deprecated /proc/acpi/event support                                           

  │ │           <*>   AC Adapter                                                                     

  │ │           <*>   Battery                                                                        

  │ │           -*-   Button                                                                        

  │ │           -*-   Video                                                                       

  │ │           <*>   Fan                                                                           

  │ │           [*]   Dock                                                                          

  │ │           <*>   Processor                                                                     

  │ │           < >   Processor Aggregator                                                          

  │ │           <*>   Thermal Zone                                                                

  │ │           -*-   NUMA support                                                                 

  │ │           [ ]   Debug Statements                                                              

  │ │           < >   PCI slot detection driver                                                    

  │ │           -*-   Container and Module Devices (EXPERIMENTAL)                                  

  │ │           < >   Smart Battery System                                                          

  │ │           < >   Hardware Error Device                                                       

  │ │           < >   Allow ACPI methods to be inserted/replaced at run time                     

  │ │           [ ]   ACPI Platform Error Interface (APEI)                                                                          

```

----------

## Hu

I disable the deprecated ACPI reporting mechanisms and let acpid listen via netlink.  It looks like acpid is not receiving the event at all.  If it did, you would have received output from the socat run, even if all your other configuration files were wrong.

----------

## iopi

So disable the reporting mechanism in the kernel and retry?  Is there anything I need to do to get netlink set up?

----------

## Hu

You probably already have it set up.  The acpid messages will tell you whether it successfully listens to netlink.

----------

## iopi

Recompiled the kernel as suggested

```

dmesg | grep -i acpi

[    0.000000]  BIOS-e820: 00000000db470000 - 00000000db4f1000 (ACPI NVS)

[    0.000000]  BIOS-e820: 00000000db780000 - 00000000db79f000 (ACPI NVS)

[    0.000000]  BIOS-e820: 00000000db7e2000 - 00000000db7ff000 (ACPI data)

[    0.000000] ACPI: RSDP 00000000000f65e0 00024 (v02 PTLTD )

[    0.000000] ACPI: XSDT 00000000db7f427a 0005C (v01 SECCSD LH43STAR 06040000  LTP 00000000)

[    0.000000] ACPI: FACP 00000000db7e4000 000F4 (v03 INTEL  CALPELLA 06040000 PTEC 00000001)

[    0.000000] ACPI: DSDT 00000000db7e5000 0A8F4 (v02 Intel  CALPELLA 06040000 INTL 20060912)

[    0.000000] ACPI: FACS 00000000db79bfc0 00040

[    0.000000] ACPI: HPET 00000000db7fed6a 00038 (v01 INTEL  CALPELLA 06040000 PTEC 00000001)

[    0.000000] ACPI: MCFG 00000000db7feda2 0003C (v01 INTEL  CALPELLA 06040000 PTEC 00000001)

[    0.000000] ACPI: SLIC 00000000db7fedde 00176 (v01 SECCSD LH43STAR 06040000  LTP 00000000)

[    0.000000] ACPI: APIC 00000000db7fef54 00084 (v01 PTLTD  ? APIC   06040000  LTP 00000000)

[    0.000000] ACPI: BOOT 00000000db7fefd8 00028 (v01 PTLTD  $SBFTBL$ 06040000  LTP 00000001)

[    0.000000] ACPI: SSDT 00000000db7e3000 009F1 (v01  PmRef    CpuPm 00003000 INTL 20061109)

[    0.000000] ACPI: Local APIC address 0xfee00000

[    0.000000] ACPI: PM-Timer IO Port: 0x408

[    0.000000] ACPI: Local APIC address 0xfee00000

[    0.000000] ACPI: LAPIC (acpi_id[0x00] lapic_id[0x00] enabled)

[    0.000000] ACPI: LAPIC (acpi_id[0x01] lapic_id[0x04] enabled)

[    0.000000] ACPI: LAPIC (acpi_id[0x02] lapic_id[0x01] enabled)

[    0.000000] ACPI: LAPIC (acpi_id[0x03] lapic_id[0x05] enabled)

[    0.000000] ACPI: LAPIC_NMI (acpi_id[0x00] high edge lint[0x1])

[    0.000000] ACPI: LAPIC_NMI (acpi_id[0x01] high edge lint[0x1])

[    0.000000] ACPI: LAPIC_NMI (acpi_id[0x02] high edge lint[0x1])

[    0.000000] ACPI: LAPIC_NMI (acpi_id[0x03] high edge lint[0x1])

[    0.000000] ACPI: IOAPIC (id[0x02] address[0xfec00000] gsi_base[0])

[    0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 0 global_irq 2 high edge)

[    0.000000] ACPI: INT_SRC_OVR (bus 0 bus_irq 9 global_irq 9 high level)

[    0.000000] ACPI: IRQ0 used by override.

[    0.000000] ACPI: IRQ2 used by override.

[    0.000000] ACPI: IRQ9 used by override.

[    0.000000] Using ACPI (MADT) for SMP configuration information

[    0.000000] ACPI: HPET id: 0x8086a701 base: 0xfed00000

[    0.003854] ACPI: Core revision 20110413

[    0.408743] PM: Registering ACPI NVS region at db470000 (528384 bytes)

[    0.408854] PM: Registering ACPI NVS region at db780000 (126976 bytes)

[    0.409550] ACPI: bus type pci registered

[    0.431630] ACPI: EC: Look up EC in DSDT

[    0.436280] [Firmware Bug]: ACPI: BIOS _OSI(Linux) query ignored

[    0.438985] ACPI: SSDT 00000000db71aa18 00474 (v01  PmRef  Cpu0Ist 00003000 INTL 20061109)

[    0.439498] ACPI: Dynamic OEM Table Load:

[    0.439680] ACPI: SSDT           (null) 00474 (v01  PmRef  Cpu0Ist 00003000 INTL 20061109)

[    0.440021] ACPI: SSDT 00000000db718698 005D9 (v01  PmRef  Cpu0Cst 00003001 INTL 20061109)

[    0.440519] ACPI: Dynamic OEM Table Load:

[    0.440701] ACPI: SSDT           (null) 005D9 (v01  PmRef  Cpu0Cst 00003001 INTL 20061109)

[    0.446912] ACPI: SSDT 00000000db719a98 00303 (v01  PmRef    ApIst 00003000 INTL 20061109)

[    0.447461] ACPI: Dynamic OEM Table Load:

[    0.447638] ACPI: SSDT           (null) 00303 (v01  PmRef    ApIst 00003000 INTL 20061109)

[    0.451790] ACPI: SSDT 00000000db717d98 00119 (v01  PmRef    ApCst 00003000 INTL 20061109)

[    0.452308] ACPI: Dynamic OEM Table Load:

[    0.452483] ACPI: SSDT           (null) 00119 (v01  PmRef    ApCst 00003000 INTL 20061109)

[    0.459497] ACPI: Interpreter enabled

[    0.459595] ACPI: (supports S0 S3 S4 S5)

[    0.459876] ACPI: Using IOAPIC for interrupt routing

[    0.460557] [Firmware Bug]: ACPI: No _BQC method, cannot determine initial brightness

[    0.460958] [Firmware Bug]: ACPI: No _BQC method, cannot determine initial brightness

[    0.468502] ACPI: Power Resource [FN00] (off)

[    0.468780] ACPI: Power Resource [FN01] (off)

[    0.469332] ACPI: EC: GPE = 0x17, I/O: command/status = 0x66, data = 0x62

[    0.469664] ACPI: No dock devices found.

[    0.469761] PCI: Using host bridge windows from ACPI; if necessary, use "pci=nocrs" and report a bug

[    0.470251] ACPI: PCI Root Bridge [PCI0] (domain 0000 [bus 00-3e])

[    0.477137] ACPI: PCI Interrupt Routing Table [\_SB_.PCI0._PRT]

[    0.477288] ACPI: PCI Interrupt Routing Table [\_SB_.PCI0.P0P1._PRT]

[    0.477387] ACPI: PCI Interrupt Routing Table [\_SB_.PCI0.RP01._PRT]

[    0.477439] ACPI: PCI Interrupt Routing Table [\_SB_.PCI0.RP04._PRT]

[    0.481499] ACPI: PCI Root Bridge [CPBG] (domain 0000 [bus 3f])

[    0.482239] ACPI: PCI Interrupt Link [LNKA] (IRQs *11)

[    0.482495] ACPI: PCI Interrupt Link [LNKB] (IRQs *10)

[    0.482753] ACPI: PCI Interrupt Link [LNKC] (IRQs 5) *10

[    0.483054] ACPI: PCI Interrupt Link [LNKD] (IRQs *5)

[    0.483310] ACPI: PCI Interrupt Link [LNKE] (IRQs 11) *0, disabled.

[    0.483652] ACPI: PCI Interrupt Link [LNKF] (IRQs 10) *0, disabled.

[    0.483996] ACPI: PCI Interrupt Link [LNKG] (IRQs 5) *7

[    0.484293] ACPI: PCI Interrupt Link [LNKH] (IRQs 5) *11

[    0.486093] PCI: Using ACPI for IRQ routing

[    0.498042] pnp: PnP ACPI init

[    0.498140] ACPI: bus type pnp registered

[    0.498733] pnp 00:00: Plug and Play ACPI device, IDs PNP0a08 PNP0a03 (active)

[    0.499088] pnp 00:01: Plug and Play ACPI device, IDs PNP0200 (active)

[    0.499152] pnp 00:02: Plug and Play ACPI device, IDs INT0800 (active)

[    0.499315] pnp 00:03: Plug and Play ACPI device, IDs PNP0103 (active)

[    0.499386] pnp 00:04: Plug and Play ACPI device, IDs PNP0c04 (active)

[    0.500319] system 00:05: Plug and Play ACPI device, IDs PNP0c02 (active)

[    0.500628] system 00:06: Plug and Play ACPI device, IDs PNP0c02 (active)

[    0.500722] pnp 00:07: Plug and Play ACPI device, IDs PNP0b00 (active)

[    0.500795] pnp 00:08: Plug and Play ACPI device, IDs PNP0303 (active)

[    0.500878] pnp 00:09: Plug and Play ACPI device, IDs PNP0f13 (active)

[    0.502453] system 00:0a: Plug and Play ACPI device, IDs PNP0c02 (active)

[    0.502894] pnp 00:0b: Plug and Play ACPI device, IDs PNP0a03 (active)

[    0.502906] pnp: PnP ACPI: found 12 devices

[    0.503001] ACPI: ACPI bus type pnp unregistered

[    0.617631] ACPI: AC Adapter [ADP1] (on-line)

[    0.618326] ACPI: Lid Switch [LID0]

[    0.618653] ACPI: Power Button [PWRB]

[    0.619568] ACPI: Sleep Button [SLPB]

[    0.619868] ACPI: Power Button [PWRF]

[    0.620087] ACPI: Fan [FAN0] (off)

[    0.620267] ACPI: Fan [FAN1] (off)

[    0.620403] ACPI: acpi_idle registered with cpuidle

[    0.624425] ACPI: Thermal Zone [TZ00] (47 C)

[    0.625191] ACPI: Thermal Zone [TZ01] (47 C)

[    0.630686] ACPI: Battery Slot [BAT1] (battery present)

[    1.070913] acpi device:0c: registered as cooling_device6

[    1.071209] ACPI: Video Device [GFX0] (multi-head: yes  rom: no  post: no)

```

```

dmesg | grep -i netlink

[    0.517892] audit: initializing netlink socket (disabled)

[    1.218360] Netfilter messages via NETLINK v0.30.

[    1.221613] ctnetlink v0.93: registering with nfnetlink.

[    1.227713] Initializing XFRM netlink socket

```

----------

