mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Frans Pop <elendil@planet.nl>
To: linux-kernel@vger.kernel.org
Cc: Jiri Kosina <trivial@kernel.org>,
	Christian Thaeter <ct@pipapo.org>, Pavel Machek <pavel@ucw.cz>
Subject: [PATCH 1/2] hpfall: reduce risk that hpfall can do harm
Date: Sat, 25 Jul 2009 20:55:15 +0200	[thread overview]
Message-ID: <200907252055.16416.elendil@planet.nl> (raw)

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 (;;) {

             reply	other threads:[~2009-07-25 18:55 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-25 18:55 Frans Pop [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200907252055.16416.elendil@planet.nl \
    --to=elendil@planet.nl \
    --cc=ct@pipapo.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@ucw.cz \
    --cc=trivial@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®