HDAPS

From ThinkWiki
Jump to: navigation, search

HDAPS - IBM Active Protection System Linux Driver

This is the Linux driver for monitoring the accelerometer known as IBM Active Protection System.

The driver only enables reading of the acceleration data. It does not perform automatic disk head parking. But there are already some other useful applications for HDAPS, using the /sys interface it provides.

ATTENTION!
There are two versions of the hdaps driver, one in the Linux kernel mainline, and another provided by tp_smapi. Use of the tp_smapi version of hdaps is strongly recommended by the current hdaps developers.

Features

  • provides accelerometer values via sysfs
  • provides a joystick type input device

Project Homepage / Availability

  • Project Homepage
  • The driver is included in the 2.6-mm series of kernels since August, 26th 2005.
  • The driver is now in the mainline (2.6.14).
  • The tp_smapi package contains some patches to this driver. These are necessary for some recent models, and recommended for all.

Status

A driver is included in recent Linux kernels and is actively maintained, but it is very inferior to the driver in tp_smapi (which provides its own hdaps module).

How to install the driver

Recent Linux kernels include the hdaps driver. However, the driver in the mainline Linux kernel has two problems with recent models:

  • It doesn't whitelist them (you have to edit hdaps_init() in drivers/hwmon/hdaps.c to include a line like HDAPS_DMI_MATCH_LENOVO("ThinkPad T60"))
  • It doesn't work reliably, e.g., it may read out constant values (0,0). See here.

To solve both problems, install the modified hdaps that is bundled with tp_smapi.

Harddisk Protection

As mentioned above, the hdaps kernel driver is only responsible for reading the accelerometer data and exporting it through the sysfs interface. In order to use this information to protect the disk, some additional steps are required.

See How to protect the harddisk through APS.

Input device support

In more recent versions of the Linux kernel,bVy6hxT the hdaps exports event devices with the accelerometer data. These devices can be used as-is by some programs (e.g. hdapsd), but for most they must be handled by the additional kernel module joydev.

When both modules are loaded, joydev will provide standard joystick device emulation for hdaps (standard hdaps exports just one joystick device. enhanced hdaps from tp_smapi will export two due to issues still unsolved on joydev, but the second one must not be used as a joystick).

ATTENTION!
Letting a program bind to these joystick devices can cause surprising results if you are not aware of it. e.g.: mplayer can act quite strangely. Also, letting a program bind to the second joystick device from enhanced HDAPS is guaranteed to be trouble

Udev can be used to create device nodes in /dev for use by user space programs that access the joystick, and to set appropriate permissions.

In order for non-root users to access these device files, their permissions must be tweaked a little through an appropriate udev rule and corresponding "joy" group.

# addgroup joy
# adduser <you> joy
# echo 'SUBSYSTEM=="input", KERNEL=="js*", MODE="0660", GROUP="joy"' >> /etc/udev/hdaps-joy.rules
# ln -s ../hdaps-joy.rules /etc/udev/rules.d/z60_hdaps-joy.rules

Programs you can use to test and calibrate the device files include jscalibrator (gui) and jstest/jscal (cli) packaged together (at least in Debian) simply as "joystick".

Applications

Disk head parking

You will need the kernel patch below and the hdapsd userspace daemon. The GUI monitoring is optional.

See How to protect the harddisk through APS for more information.

Kernel patch

Due to significant changes in the way the libata module which handles disk i/o, applying any of the currently available patches to kernel 2.6.24 will intermittently cause system hangs when the queue is frozen (i.e., the heads are parked). It is recommended either that you stay at kernel 2.6.23 or do without disk protection in 2.6.24 until the kinks have been worked out. There has been significant work on the part of Elias Oltmanns, author of the more recent patches, to get this worked out and eventually get shock protection built into the mainline kernel.

Below are some links to patches for various Linux kernel versions. As noted above, your mileage may vary with the 2.6.24-rc3 patch as it was after this release candidate that things stopped working nicely.

Hint:
To apply a patch, change to the root directory of the kernel tree and run
patch -p1 -l < hdaps_xx.patch
Userspace daemon

This version optionally reduces timer interrupts (as measured by PowerTOP), and thereby reduces power consumption on modern ("tickless") Linux kernels. Interrupt reduction requires the hdaps kernel module from tp_smapi 0.32 or newer, and a udev rule. If these are not present, it will default to an older polling method that is slightly more power-hungry. The udev rule helps hdapsd find the input device, and on most distributions it can be created as follows:

# echo 'KERNEL=="event[0-9]*", ATTRS{phys}=="hdaps/input1",ATTRS{modalias}=="input:b0019v1014p5054e4801-*",SYMLINK+="input/hdaps/accelerometer-event"' \
  > /etc/udev/rules.d/51-hdaps.rules

Then reboot or run # /sbin/udevtrigger, and verify that the /dev/input/hdaps/accelerometer-event symlink exists.

Hint:
Gentoo users : due to new interface your initscript won't be longer working. Read documentation before upgrading to this version.

Use an overlay listed bellow with updated versions of related packages

NOTE!
Linux 2.6.33.2: with the hdaps driver from tp_smapi-0.40, hdapsd don't need udev help any more. hdapsd will loop all the event devices at /dev/input/event* to find out the accelerometer event. Kernel has to enable the input event interface (Device Drivers->input Device support ->Event interface), otherwise the /dev/input/event* will not be populated.
GUI monitoring

Security & safety

Tilt monitoring

  • gkhdaps a GKrellM applet displaying tilt data
  • gnome-tilt a gnome applet showing tilt data

Visualisation of ThinkPad orientation

Games

  • Neverball is quite fun with HDAPS. (You'll need to have the HDAPS joystick device)
  • Turn your ThinkPad into a Jedi Weapon (hey, it works for Mac laptops)

Other

  • smack.py - switch workspace by smacking your laptop, inspired by the SmackBook (uses EWMH)
    • an improved version adds stabilization (by comparing smacks to previous ones, uses EWMH)
    • another approach adds stabilization (by requiring a certain type of value deflection, uses xmacroplay)
    • GTollina is another smack program for use with compiz (video here).
  • xmms-smack.py - move through your xmms playlist by smacking, based on the two smack scripts above.
  • KnockBasedCommands - Execute commands by tapping your laptop.
  • rotate.py - rotate desktop by turning your laptop
  • Enhanced smack script ess.py is based on the smacks scripts listed in this section. It includes stabilization, a lot of tuning options and it handles both axis (at best you should be able to map 8 commands, even if it is possible I was not able to do so). It is not perfect but on my Thinkpad it works better than the other scripts.

Interesting links related to this project