mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 1/2] hpfall: reduce risk that hpfall can do harm
@ 2009-07-25 18:55 Frans Pop
  2009-07-25 19:00 ` [PATCH 2/2] hpfall: accept disk device to unload as argument Frans Pop
  2009-08-08  1:01 ` [PATCH 1/2] hpfall: reduce risk that hpfall can do harm Jiri Kosina
  0 siblings, 2 replies; 5+ messages in thread
From: Frans Pop @ 2009-07-25 18:55 UTC (permalink / raw)
  To: linux-kernel; +Cc: Jiri Kosina, Christian Thaeter, Pavel Machek

From: Christian Thaeter <ct@pipapo.org>

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>
---

This patch was posted some time back by Christian and acked by Pavel, but
was never picked up: http://lkml.org/lkml/2009/3/25/505.
All I've done is cleaned up whitespace and the commit message.

The patch is on top of my patch to clean up checkpatch errors which is
already in the trivial tree for .32. As this is only example code, I guess
this could go through trivial too.


diff --git a/Documentation/hwmon/hpfall.c b/Documentation/hwmon/hpfall.c
index d2f6711..a3cfe1a 100644
--- a/Documentation/hwmon/hpfall.c
+++ b/Documentation/hwmon/hpfall.c
@@ -16,6 +16,8 @@
 #include <stdint.h>
 #include <errno.h>
 #include <signal.h>
+#include <sys/mman.h>
+#include <sched.h>
 
 void write_int(char *path, int i)
 {
@@ -62,6 +64,7 @@ void ignore_me(void)
 int main(int argc, char *argv[])
 {
 	int fd, ret;
+	struct sched_param param;
 
 	fd = open("/dev/freefall", O_RDONLY);
 	if (fd < 0) {
@@ -69,6 +72,11 @@ int main(int argc, char *argv[])
 		return EXIT_FAILURE;
 	}
 
+	daemon(0, 0);
+	param.sched_priority = sched_get_priority_max(SCHED_FIFO);
+	sched_setscheduler(0, SCHED_FIFO, &param);
+	mlockall(MCL_CURRENT|MCL_FUTURE);
+
 	signal(SIGALRM, ignore_me);
 
 	for (;;) {

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-08-08  1:03 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-25 18:55 [PATCH 1/2] hpfall: reduce risk that hpfall can do harm Frans Pop
2009-07-25 19:00 ` [PATCH 2/2] hpfall: accept disk device to unload as argument Frans Pop
2009-07-25 20:48   ` Pavel Machek
2009-08-08  1:03     ` Jiri Kosina
2009-08-08  1:01 ` [PATCH 1/2] hpfall: reduce risk that hpfall can do harm Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®