Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 1 Jun 2010 18:03:27 +0200
From:      David DEMELIER <demelier.david@gmail.com>
To:        Ian Smith <smithi@nimnet.asn.au>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Automatic shutdown with devd.
Message-ID:  <AANLkTilLGKhJ5MuzgDopTNYwh2FKo1Mbnrph_MXnVGpe@mail.gmail.com>
In-Reply-To: <20100602001405.T27982@sola.nimnet.asn.au>
References:  <20100601120131.A070C10657ED@hub.freebsd.org> <20100602001405.T27982@sola.nimnet.asn.au>

next in thread | previous in thread | raw e-mail | index | archive | help
2010/6/1 Ian Smith <smithi@nimnet.asn.au>:
> In freebsd-questions Digest, Vol 313, Issue 4, Message: 26
> On Tue, 1 Jun 2010 10:55:08 +0200 David DEMELIER <demelier.david@gmail.co=
m> wrote:
>
> =C2=A0> I recently asked to make an automatic shutdown when I excess a
> =C2=A0> specific percent. I ran devd with -Dd flags to run in background =
and
> =C2=A0> when the battery was at a critical state it said :
> =C2=A0>
> =C2=A0> Processing event '!system=3DACPI subsystem=3DCMBAT type=3D\_SB_.B=
AT0 notify=3D0x80'
> =C2=A0> Pushing table
> =C2=A0> setting system=3DACPI
> =C2=A0> setting subsystem=3DCMBAT
> =C2=A0> setting type=3D\_SB_.BAT0
> =C2=A0> setting notify=3D0x80
>
> You should be aware that notify 0x80 for CMBAT indicates 'BST' or
> Battery State Change; you'll get these on shifting to any new state.
>
> You can check the new state with 'sysctl -n hw.acpi.battery.state'.
> 'acpiconf -i0' shows a translation between state masks and names.
>
> =C2=A0> Then I tried (for testing) something like this in my /etc/devd.co=
nf
> =C2=A0>
> =C2=A0> notify 10 {
> =C2=A0> =C2=A0 =C2=A0 =C2=A0 =C2=A0 match "system" =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0"ACPI";
> =C2=A0> =C2=A0 =C2=A0 =C2=A0 =C2=A0 match "subsystem" =C2=A0 =C2=A0 =C2=
=A0 "CMBAT";
> =C2=A0> =C2=A0 =C2=A0 =C2=A0 =C2=A0 match "notify" =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0"0x80";
> =C2=A0> =C2=A0 =C2=A0 =C2=A0 =C2=A0 action "logger LETGOSHUTDOWN";
> =C2=A0> };
> =C2=A0>
> =C2=A0> And then I can see the following output in /var/log/messages :
> =C2=A0>
> =C2=A0> Jun =C2=A01 10:48:54 Melon power_profile: changed to 'performance=
'
>
> Reflecting your AC line state changing from Battery to AC. =C2=A0devd.con=
f
> and /etc/rc.d/power_profile have good clues for handling devd notifies.
>
> =C2=A0> Jun =C2=A01 10:48:56 Melon root: LETGOSHUTDOWN
> =C2=A0> Jun =C2=A01 10:49:12 Melon root: LETGOSHUTDOWN
> =C2=A0> Jun =C2=A01 10:51:06 Melon last message repeated 2 times
> =C2=A0>
> =C2=A0> It works, but the problem is that it makes this even the cable is
> =C2=A0> plugged ! i.e : the computer was not powered on so with 3% of
> =C2=A0> remaining time but AC plugged in after booting it (always with th=
e AC
> =C2=A0> plugged in) these messages appears too. I guess the ACPI/CMBAT do=
 not
> =C2=A0> care if there is an AC plugged in or not.
>
> See /sys/dev/acpica/acpi_cmbat.c for the gory details.
>
> Yes, ACAD and CMBAT are independent subsystems, so rather than an inline
> action like "logger .." here, you might follow the examples to run your
> own script, passing the notify to that (if you may also want to check
> for notify 0x81, BIF battery info changes, though these occur rarely)
>

So I will check deeper.

> =C2=A0> Is there a way to make this conditional to do only if the laptop =
is
> =C2=A0> not charging, AC plugged in ?
>
> Your script can check whether the AC power is on with:
>
> =C2=A0 =C2=A0 =C2=A0 =C2=A0AC=3D`sysctl -n hw.acpi.acline`
> =C2=A0 =C2=A0 =C2=A0 =C2=A0if [ $AC =3D 1 ]; then
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0exit 0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0# or whatever, when on AC power
> =C2=A0 =C2=A0 =C2=A0 =C2=A0elif [ $AC =3D 0 ]; then
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 # do whatever when on battery
> =C2=A0 =C2=A0 =C2=A0 =C2=A0else
> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0: =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 # AC/Battery state unknown ..
> =C2=A0 =C2=A0 =C2=A0 =C2=A0fi
>
> You could try just logging all state changes for a while; from critical
> charging to charging to high to discharging to critical discharging, I
> think that's the lot .. you can also check hw.acpi.battery.life etc.
>

Okay I will try a script like this one.

> However, your system should do an 'emergency suspend' on critical low
> battery anyway .. usually set at 1% capacity but some BIOS will let you
> adjust that (see acpiconf -i0). =C2=A0Only if suspend/resume works of cou=
rse.
>

It would be great if suspend/resume would works yes ! For the moment
it's not the case :

http://www.freebsd.org/cgi/query-pr.cgi?pr=3Di386/146715

Thanks for your answer ;-)

--=20
Demelier David



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AANLkTilLGKhJ5MuzgDopTNYwh2FKo1Mbnrph_MXnVGpe>