diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2015-06-24 23:01:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2015-06-24 23:01:36 -0400 |
commit | 1e467e68e51b116e026247d0defc806b462c095e (patch) | |
tree | 87203f5dbb1cb24402aa966153ce49d176cc47db /tools | |
parent | 14738e03312ff1137109d68bcbf103c738af0f4a (diff) | |
parent | 36f95a0b34cb980dcfff9c1082ca5d8f0dc5e78b (diff) |
Merge tag 'docs-for-linus' of git://git.lwn.net/linux-2.6
Pull documentation updates from Jonathan Corbet:
"The main thing here is Ingo's big subdirectory documenting feature
support for each architecture. Beyond that, it's the usual pile of
fixes, tweaks, and small additions"
* tag 'docs-for-linus' of git://git.lwn.net/linux-2.6: (79 commits)
doc:md: fix typo in md.txt.
Documentation/mic/mpssd: don't build x86 userspace when cross compiling
Documentation/prctl: don't build tsc tests when cross compiling
Documentation/vDSO: don't build tests when cross compiling
Doc:ABI/testing: Fix typo in sysfs-bus-fcoe
Doc: Docbook: Change wikipedia's URL from http to https in scsi.tmpl
Doc: Change wikipedia's URL from http to https
Documentation/kernel-parameters: add missing pciserial to the earlyprintk
Doc:pps: Fix typo in pps.txt
kbuild : Fix documentation of INSTALL_HDR_PATH
Documentation: filesystems: updated struct file_operations documentation in vfs.txt
kbuild: edit explanation of clean-files variable
Doc: ja_JP: Fix typo in HOWTO
Move freefall program from Documentation/ to tools/
Documentation: ARM: EXYNOS: Describe boot loaders interface
Doc:nfc: Fix typo in nfc-hci.txt
vfs: Minor documentation fix
Doc: networking: txtimestamp: fix printf format warning
Documentation, intel_pstate: Improve legacy mode internal governors description
Documentation: extend use case for EXPORT_SYMBOL_GPL()
...
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile | 14 | ||||
-rw-r--r-- | tools/laptop/freefall/Makefile | 17 | ||||
-rw-r--r-- | tools/laptop/freefall/freefall.c | 174 |
3 files changed, 203 insertions, 2 deletions
diff --git a/tools/Makefile b/tools/Makefile index b35102721cbb..b113078fb7ad 100644 --- a/tools/Makefile +++ b/tools/Makefile | |||
@@ -23,6 +23,7 @@ help: | |||
23 | @echo ' vm - misc vm tools' | 23 | @echo ' vm - misc vm tools' |
24 | @echo ' x86_energy_perf_policy - Intel energy policy tool' | 24 | @echo ' x86_energy_perf_policy - Intel energy policy tool' |
25 | @echo ' tmon - thermal monitoring and tuning tool' | 25 | @echo ' tmon - thermal monitoring and tuning tool' |
26 | @echo ' freefall - laptop accelerometer program for disk protection' | ||
26 | @echo '' | 27 | @echo '' |
27 | @echo 'You can do:' | 28 | @echo 'You can do:' |
28 | @echo ' $$ make -C tools/ <tool>_install' | 29 | @echo ' $$ make -C tools/ <tool>_install' |
@@ -72,6 +73,9 @@ turbostat x86_energy_perf_policy: FORCE | |||
72 | tmon: FORCE | 73 | tmon: FORCE |
73 | $(call descend,thermal/$@) | 74 | $(call descend,thermal/$@) |
74 | 75 | ||
76 | freefall: FORCE | ||
77 | $(call descend,laptop/$@) | ||
78 | |||
75 | acpi_install: | 79 | acpi_install: |
76 | $(call descend,power/$(@:_install=),install) | 80 | $(call descend,power/$(@:_install=),install) |
77 | 81 | ||
@@ -90,10 +94,13 @@ turbostat_install x86_energy_perf_policy_install: | |||
90 | tmon_install: | 94 | tmon_install: |
91 | $(call descend,thermal/$(@:_install=),install) | 95 | $(call descend,thermal/$(@:_install=),install) |
92 | 96 | ||
97 | freefall_install: | ||
98 | $(call descend,laptop/$(@:_install=),install) | ||
99 | |||
93 | install: acpi_install cgroup_install cpupower_install hv_install firewire_install lguest_install \ | 100 | install: acpi_install cgroup_install cpupower_install hv_install firewire_install lguest_install \ |
94 | perf_install selftests_install turbostat_install usb_install \ | 101 | perf_install selftests_install turbostat_install usb_install \ |
95 | virtio_install vm_install net_install x86_energy_perf_policy_install \ | 102 | virtio_install vm_install net_install x86_energy_perf_policy_install \ |
96 | tmon | 103 | tmon freefall_install |
97 | 104 | ||
98 | acpi_clean: | 105 | acpi_clean: |
99 | $(call descend,power/acpi,clean) | 106 | $(call descend,power/acpi,clean) |
@@ -122,8 +129,11 @@ turbostat_clean x86_energy_perf_policy_clean: | |||
122 | tmon_clean: | 129 | tmon_clean: |
123 | $(call descend,thermal/tmon,clean) | 130 | $(call descend,thermal/tmon,clean) |
124 | 131 | ||
132 | freefall_clean: | ||
133 | $(call descend,laptop/freefall,clean) | ||
134 | |||
125 | clean: acpi_clean cgroup_clean cpupower_clean hv_clean firewire_clean lguest_clean \ | 135 | clean: acpi_clean cgroup_clean cpupower_clean hv_clean firewire_clean lguest_clean \ |
126 | perf_clean selftests_clean turbostat_clean usb_clean virtio_clean \ | 136 | perf_clean selftests_clean turbostat_clean usb_clean virtio_clean \ |
127 | vm_clean net_clean x86_energy_perf_policy_clean tmon_clean | 137 | vm_clean net_clean x86_energy_perf_policy_clean tmon_clean freefall_clean |
128 | 138 | ||
129 | .PHONY: FORCE | 139 | .PHONY: FORCE |
diff --git a/tools/laptop/freefall/Makefile b/tools/laptop/freefall/Makefile new file mode 100644 index 000000000000..48c6c9328419 --- /dev/null +++ b/tools/laptop/freefall/Makefile | |||
@@ -0,0 +1,17 @@ | |||
1 | PREFIX ?= /usr | ||
2 | SBINDIR ?= sbin | ||
3 | INSTALL ?= install | ||
4 | CC = $(CROSS_COMPILE)gcc | ||
5 | |||
6 | TARGET = freefall | ||
7 | |||
8 | all: $(TARGET) | ||
9 | |||
10 | %: %.c | ||
11 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< | ||
12 | |||
13 | clean: | ||
14 | $(RM) $(TARGET) | ||
15 | |||
16 | install: freefall | ||
17 | $(INSTALL) -D -m 755 $(TARGET) $(DESTDIR)$(PREFIX)/$(SBINDIR)/$(TARGET) | ||
diff --git a/tools/laptop/freefall/freefall.c b/tools/laptop/freefall/freefall.c new file mode 100644 index 000000000000..5e44b20b1848 --- /dev/null +++ b/tools/laptop/freefall/freefall.c | |||
@@ -0,0 +1,174 @@ | |||
1 | /* Disk protection for HP/DELL machines. | ||
2 | * | ||
3 | * Copyright 2008 Eric Piel | ||
4 | * Copyright 2009 Pavel Machek <pavel@ucw.cz> | ||
5 | * Copyright 2012 Sonal Santan | ||
6 | * Copyright 2014 Pali Rohár <pali.rohar@gmail.com> | ||
7 | * | ||
8 | * GPLv2. | ||
9 | */ | ||
10 | |||
11 | #include <stdio.h> | ||
12 | #include <stdlib.h> | ||
13 | #include <unistd.h> | ||
14 | #include <fcntl.h> | ||
15 | #include <sys/stat.h> | ||
16 | #include <sys/types.h> | ||
17 | #include <string.h> | ||
18 | #include <stdint.h> | ||
19 | #include <errno.h> | ||
20 | #include <signal.h> | ||
21 | #include <sys/mman.h> | ||
22 | #include <sched.h> | ||
23 | #include <syslog.h> | ||
24 | |||
25 | static int noled; | ||
26 | static char unload_heads_path[64]; | ||
27 | static char device_path[32]; | ||
28 | static const char app_name[] = "FREE FALL"; | ||
29 | |||
30 | static int set_unload_heads_path(char *device) | ||
31 | { | ||
32 | if (strlen(device) <= 5 || strncmp(device, "/dev/", 5) != 0) | ||
33 | return -EINVAL; | ||
34 | strncpy(device_path, device, sizeof(device_path) - 1); | ||
35 | |||
36 | snprintf(unload_heads_path, sizeof(unload_heads_path) - 1, | ||
37 | "/sys/block/%s/device/unload_heads", device+5); | ||
38 | return 0; | ||
39 | } | ||
40 | |||
41 | static int valid_disk(void) | ||
42 | { | ||
43 | int fd = open(unload_heads_path, O_RDONLY); | ||
44 | |||
45 | if (fd < 0) { | ||
46 | perror(unload_heads_path); | ||
47 | return 0; | ||
48 | } | ||
49 | |||
50 | close(fd); | ||
51 | return 1; | ||
52 | } | ||
53 | |||
54 | static void write_int(char *path, int i) | ||
55 | { | ||
56 | char buf[1024]; | ||
57 | int fd = open(path, O_RDWR); | ||
58 | |||
59 | if (fd < 0) { | ||
60 | perror("open"); | ||
61 | exit(1); | ||
62 | } | ||
63 | |||
64 | sprintf(buf, "%d", i); | ||
65 | |||
66 | if (write(fd, buf, strlen(buf)) != strlen(buf)) { | ||
67 | perror("write"); | ||
68 | exit(1); | ||
69 | } | ||
70 | |||
71 | close(fd); | ||
72 | } | ||
73 | |||
74 | static void set_led(int on) | ||
75 | { | ||
76 | if (noled) | ||
77 | return; | ||
78 | write_int("/sys/class/leds/hp::hddprotect/brightness", on); | ||
79 | } | ||
80 | |||
81 | static void protect(int seconds) | ||
82 | { | ||
83 | const char *str = (seconds == 0) ? "Unparked" : "Parked"; | ||
84 | |||
85 | write_int(unload_heads_path, seconds*1000); | ||
86 | syslog(LOG_INFO, "%s %s disk head\n", str, device_path); | ||
87 | } | ||
88 | |||
89 | static int on_ac(void) | ||
90 | { | ||
91 | /* /sys/class/power_supply/AC0/online */ | ||
92 | return 1; | ||
93 | } | ||
94 | |||
95 | static int lid_open(void) | ||
96 | { | ||
97 | /* /proc/acpi/button/lid/LID/state */ | ||
98 | return 1; | ||
99 | } | ||
100 | |||
101 | static void ignore_me(int signum) | ||
102 | { | ||
103 | protect(0); | ||
104 | set_led(0); | ||
105 | } | ||
106 | |||
107 | int main(int argc, char **argv) | ||
108 | { | ||
109 | int fd, ret; | ||
110 | struct stat st; | ||
111 | struct sched_param param; | ||
112 | |||
113 | if (argc == 1) | ||
114 | ret = set_unload_heads_path("/dev/sda"); | ||
115 | else if (argc == 2) | ||
116 | ret = set_unload_heads_path(argv[1]); | ||
117 | else | ||
118 | ret = -EINVAL; | ||
119 | |||
120 | if (ret || !valid_disk()) { | ||
121 | fprintf(stderr, "usage: %s <device> (default: /dev/sda)\n", | ||
122 | argv[0]); | ||
123 | exit(1); | ||
124 | } | ||
125 | |||
126 | fd = open("/dev/freefall", O_RDONLY); | ||
127 | if (fd < 0) { | ||
128 | perror("/dev/freefall"); | ||
129 | return EXIT_FAILURE; | ||
130 | } | ||
131 | |||
132 | if (stat("/sys/class/leds/hp::hddprotect/brightness", &st)) | ||
133 | noled = 1; | ||
134 | |||
135 | if (daemon(0, 0) != 0) { | ||
136 | perror("daemon"); | ||
137 | return EXIT_FAILURE; | ||
138 | } | ||
139 | |||
140 | openlog(app_name, LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1); | ||
141 | |||
142 | param.sched_priority = sched_get_priority_max(SCHED_FIFO); | ||
143 | sched_setscheduler(0, SCHED_FIFO, ¶m); | ||
144 | mlockall(MCL_CURRENT|MCL_FUTURE); | ||
145 | |||
146 | signal(SIGALRM, ignore_me); | ||
147 | |||
148 | for (;;) { | ||
149 | unsigned char count; | ||
150 | |||
151 | ret = read(fd, &count, sizeof(count)); | ||
152 | alarm(0); | ||
153 | if ((ret == -1) && (errno == EINTR)) { | ||
154 | /* Alarm expired, time to unpark the heads */ | ||
155 | continue; | ||
156 | } | ||
157 | |||
158 | if (ret != sizeof(count)) { | ||
159 | perror("read"); | ||
160 | break; | ||
161 | } | ||
162 | |||
163 | protect(21); | ||
164 | set_led(1); | ||
165 | if (1 || on_ac() || lid_open()) | ||
166 | alarm(2); | ||
167 | else | ||
168 | alarm(20); | ||
169 | } | ||
170 | |||
171 | closelog(); | ||
172 | close(fd); | ||
173 | return EXIT_SUCCESS; | ||
174 | } | ||