Index: sreadahead.1
===================================================================
--- sreadahead.1	(.../tags/sreadahead-1.0)	(revision 0)
+++ sreadahead.1	(.../trunk)	(revision 38)
@@ -0,0 +1,35 @@
+.TH sreadahead 8 "2009-02-07" "" ""
+.SH NAME
+sreadahead \- a readahead implementation optimized for solid state devices
+.SH SYNOPSIS
+.B sreadahead
+[OPTION]...
+.SH DESCRIPTION
+.B sreadahead
+is a daemon that reads data sequential by use from disk. Sreadahead does this by
+retrieving the read order (in timestamp format) from an actual boot sequence and
+storing a list of data that was read during that boot sequence in a flat
+database. On the next boot this file can be used to load all the data described
+in the database into memory and in order of use.
+.SH OPTIONS
+.TP
+.B \-t\fR \fIN\fR, \fB\-\-time\fR=\fIN
+make sreadahead stop after N seconds instead of the default 15 seconds
+.TP
+.B \-d\fR, \fB\-\-debug
+print debug output to stdout
+.TP
+.B \-h\fR, \fB\-\-help
+show a help message and exit
+.TP
+.B \-v\fR, \fB\-\-version
+show version information and exit
+.SH AUTHOR
+.PP
+sreadahead is written by the Intel Corporation. This manual page was written by
+Tobias Klauser <tklauser@distanz.ch> for the Debian system (but may be used by
+others).
+.SH SEE ALSO
+.PP
+.BR readahead(2),
+.BR readahead-list(8)
Index: sreadahead.c
===================================================================
--- sreadahead.c	(.../tags/sreadahead-1.0)	(revision 38)
+++ sreadahead.c	(.../trunk)	(revision 38)
@@ -23,7 +23,6 @@
 
 #include <fcntl.h>
 #include <sys/types.h>
-#include <sys/stat.h>
 #include <sys/syscall.h>
 #include <sys/mount.h>
 #include <sys/signal.h>
@@ -41,8 +40,11 @@
 #elif defined(__x86_64__)
 #  define HAVE_IO_PRIO
 #  define __NR_ioprio_set 251
+#elif defined(__powerpc__)
+#  define HAVE_IO_PRIO
+#  define __NR_ioprio_set 273
 #else /* not fatal */
-#  warn "Architecture does not support ioprio modification"
+#  warning "Architecture does not support ioprio modification"
 #endif
 #define IOPRIO_WHO_PROCESS 1
 #define IOPRIO_CLASS_IDLE 3
@@ -57,6 +59,8 @@
 #define MAXFL 128
 #define MAXRECS 6	/* reduce nr of fragments to this amount */
 
+#define DEFAULT_MAX_TIME 15 /* should be enough for every OS to boot */
+
 /*
  * By default, the kernel reads ahead for 128kb. This throws off our
  * measurements since we don't need the extra 128kb for each file.
@@ -284,16 +288,22 @@
 	int i;
 
 	if (!r)
-		goto remove;
+		return 0;
 
-	memset(record, 0, sizeof(record));
-
 	file = fopen(r->filename, "r");
 	if (!file)
-		goto remove;
+		return 0;
 
 	fd = fileno(file);
 	fstat(fd, &statbuf);
+	/* prevent accidentally reading from a pipe */
+	if (!(S_ISREG(statbuf.st_mode))) {
+		fclose(file);
+		return 0;
+	}
+
+	memset(record, 0, sizeof(record));
+
 	mmapptr = mmap(NULL, statbuf.st_size, PROT_READ, MAP_SHARED, fd, 0);
 
 	mincorebuf = malloc(statbuf.st_size/4096 + 1);
@@ -341,7 +351,7 @@
 	if (rcount > 0) {
 		/* some empty files slip through */
 		if (record[0].len == 0)
-			goto remove;
+			return 0;
 
 		if (debug) {
 			int tlen = 0;
@@ -361,9 +371,6 @@
 		memcpy(r->data, record, sizeof(r->data));
 		return 1;
 	}
-
-remove:
-	return 0;
 }
 
 static void get_ra_blocks(void)
@@ -461,7 +468,7 @@
 	readahead_set_len(RA_NORMAL);
 
 	/*
-	 * by now the init process should have mounted debugf on a logical
+	 * by now the init process should have mounted debugfs on a logical
 	 * location like /sys/kernel/debug, but if not then we temporarily
 	 * re-mount it ourselves
 	 */
@@ -473,6 +480,8 @@
 			exit(EXIT_FAILURE);
 		}
 		chdir(DEBUGFS_MNT);
+	} else {
+		chdir("..");
 	}
 
 	/* stop tracing */
@@ -592,9 +601,11 @@
 static void print_usage(const char *name)
 {
 	printf("Usage: %s [OPTION...]\n", name);
-	printf("  -d, --debug           Print debug output to stdout\n");
-	printf("  -h, --help            Show this help message\n");
-	printf("  -v, --version         Show version information and exit\n");
+	printf("  -t N, --time=N        Wait for N seconds before creating new\n");
+	printf("                        pack file (default %d)\n", DEFAULT_MAX_TIME);
+	printf("  -d,   --debug         Print debug output to stdout\n");
+	printf("  -h,   --help          Show this help message\n");
+	printf("  -v,   --version       Show version information and exit\n");
 	exit(EXIT_SUCCESS);
 }
 
@@ -610,18 +621,20 @@
 	FILE *file;
 	int pid = 0;
 	pthread_t one, two, three, four;
+	int max_time = DEFAULT_MAX_TIME;
 
 	while (1) {
 		static struct option opts[] = {
 			{ "debug", 0, NULL, 'd' },
 			{ "help", 0, NULL, 'h' },
 			{ "version", 0, NULL, 'v' },
+			{ "time", 1, NULL, 't' },
 			{ 0, 0, NULL, 0 }
 		};
 		int c;
 		int index = 0;
 
-		c = getopt_long(argc, argv, "dhv", opts, &index);
+		c = getopt_long(argc, argv, "dhvt:", opts, &index);
 		if (c == -1)
 			break;
 		switch (c) {
@@ -634,6 +647,9 @@
 		case 'h':
 			print_usage(argv[0]);
 			break;
+		case 't':
+			max_time = atoi(optarg);
+			break;
 		default:
 			;
 		}
@@ -647,12 +663,8 @@
 		if (!fork()) {
 			/* child */
 			signal(SIGUSR1, trace_stop);
+			sleep(max_time);
 			/*
-			 * "" 15 seconds should be enough for everyone to boot""
-			 * -- Auke Kok, 2009
-			 */
-			sleep(15);
-			/*
 			 * abort if we don't get a signal, so we can stop
 			 * the tracing and minimize the trace buffer size
 			 */
Index: Makefile
===================================================================
--- Makefile	(.../tags/sreadahead-1.0)	(revision 38)
+++ Makefile	(.../trunk)	(revision 38)
@@ -1,4 +1,4 @@
-CFLAGS ?= -Os -march=i686 -g
+CFLAGS ?= -Os -march=native -g
 PROGS = sreadahead
 
 VERSION = "1.0"
@@ -14,7 +14,9 @@
 install: all
 	mkdir -p $(DESTDIR)/sbin
 	mkdir -p $(DESTDIR)/var/lib/sreadahead/debugfs
+	mkdir -p $(DESTDIR)/usr/share/man/man1
 	install -p -m 755 $(PROGS) $(DESTDIR)/sbin
+	install -p -m 644 sreadahead.1 $(DESTDIR)/usr/share/man/man1
 
 dist:
 	svn export . sreadahead-$(VERSION)

Property changes on: .
___________________________________________________________________
Deleted: svn:mergeinfo

