aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/hwmon
diff options
context:
space:
mode:
authorChristian Thaeter <ct@pipapo.org>2009-07-25 14:55:15 -0400
committerJiri Kosina <jkosina@suse.cz>2009-09-21 09:14:57 -0400
commit2bace8b95108746f6123d312f47f5bda4eb17a26 (patch)
treeb6db4a0a0c1aa9c261e4adaeb4dcae5ed7ff4350 /Documentation/hwmon
parent8103b5cc6216d461047514d188248bd14873624a (diff)
trivial: doc: hpfall: reduce risk that hpfall can do harm
Improve the example code to be at least useable, as in not causing harm (as shown below). Code can still be improved further, but this adds some basic safeguards. 1. hpfall *MUST* mlockall(MCL_CURRENT|MCL_FUTURE); itself! Since the Program sits and waits most of the time it becomes very likely swapped out. If it gets woken up when the laptop drops from the table while it is swapped out it actually triggers harddrive activity! 2. Daemonize hpfall using 'daemon(0,0)' (quick and dirty). 3. Give hpfall realtime priority. Should give a chance that it has less latency when woken up. Signed-off-by: Christian Thaeter <ct@pipapo.org> Signed-off-by: Frans Pop <elendil@planet.nl> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'Documentation/hwmon')
-rw-r--r--Documentation/hwmon/hpfall.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Documentation/hwmon/hpfall.c b/Documentation/hwmon/hpfall.c
index d2f6711b468b..a3cfe1a5f964 100644
--- a/Documentation/hwmon/hpfall.c
+++ b/Documentation/hwmon/hpfall.c
@@ -16,6 +16,8 @@
16#include <stdint.h> 16#include <stdint.h>
17#include <errno.h> 17#include <errno.h>
18#include <signal.h> 18#include <signal.h>
19#include <sys/mman.h>
20#include <sched.h>
19 21
20void write_int(char *path, int i) 22void write_int(char *path, int i)
21{ 23{
@@ -62,6 +64,7 @@ void ignore_me(void)
62int main(int argc, char *argv[]) 64int main(int argc, char *argv[])
63{ 65{
64 int fd, ret; 66 int fd, ret;
67 struct sched_param param;
65 68
66 fd = open("/dev/freefall", O_RDONLY); 69 fd = open("/dev/freefall", O_RDONLY);
67 if (fd < 0) { 70 if (fd < 0) {
@@ -69,6 +72,11 @@ int main(int argc, char *argv[])
69 return EXIT_FAILURE; 72 return EXIT_FAILURE;
70 } 73 }
71 74
75 daemon(0, 0);
76 param.sched_priority = sched_get_priority_max(SCHED_FIFO);
77 sched_setscheduler(0, SCHED_FIFO, &param);
78 mlockall(MCL_CURRENT|MCL_FUTURE);
79
72 signal(SIGALRM, ignore_me); 80 signal(SIGALRM, ignore_me);
73 81
74 for (;;) { 82 for (;;) {