summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@linaro.org>2014-07-01 11:37:15 +0200
committerDaniel Lezcano <daniel.lezcano@linaro.org>2014-07-01 11:37:15 +0200
commit9a5e43861207057ecf1e1bc232c32f55e5ee1a93 (patch)
tree867be45559a4f1a4dd91cdaeeeaa8f0913d2d021
parentcea7881da79342c03c6d21ea3f3d24c3ff830c8b (diff)
Add number of processes options
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
-rw-r--r--iolatsimu.c132
1 files changed, 88 insertions, 44 deletions
diff --git a/iolatsimu.c b/iolatsimu.c
index 2d8badc..119e844 100644
--- a/iolatsimu.c
+++ b/iolatsimu.c
@@ -3,6 +3,8 @@
#include <stdlib.h>
#include <unistd.h>
#include <sys/time.h>
+#include <sys/types.h>
+#include <sys/wait.h>
#include <fcntl.h>
#include "list.h"
@@ -44,6 +46,7 @@
*
*/
#define BUCKET_INTERVAL 500
+static int bucket_interval = BUCKET_INTERVAL;
/*
* Number of successive hits for the same bucket. That is the thresold
@@ -148,7 +151,9 @@ static int bucket_guessed_index(void)
* more weight the next one. If a bucket is in the process
* of being hit several times, take it into account.
*/
- score = bucket->hits / (1 << weight);
+ score = bucket->hits / ((2 * weight) + 1);
+
+ weight++;
if (score < score_max)
continue;
@@ -165,7 +170,7 @@ static int bucket_guessed_index(void)
*/
static int bucket_index(int latency)
{
- return latency / BUCKET_INTERVAL;
+ return latency / bucket_interval;
}
/*
@@ -228,12 +233,13 @@ static void bucket_show(void)
bucket = list_entry(list, struct bucket, list);
- printf("bucket %d: %d\n",
+ printf("[pid %d] bucket %d: %d\n", getpid(),
bucket->index, bucket->hits);
}
- printf("Number of correct predictions: %d/%d (%.2f%%)\n",
- success, nrlatency, ((float)success / (float)nrlatency) * 100.0);
+ printf("[pid %d] Number of correct predictions: %d/%d (%.2f%%)\n",
+ getpid(), success, nrlatency,
+ ((float)success / (float)nrlatency) * 100.0);
}
/*
@@ -246,6 +252,7 @@ static void bucket_show(void)
#define NROFFSET 256
#define PAGESIZE 16384
+// #define PAGESIZE 1048576 16384
static char buffer[PAGESIZE];
@@ -265,13 +272,18 @@ void write_file(int fd)
int mktempfile(const char *dirname)
{
char *name;
+ int fd;
- if (asprintf(&name, "%s/XXXXXX", dirname) < 0) {
+ if (asprintf(&name, "%s/iosimul-XXXXXX", dirname) < 0) {
perror("asprintf");
return -1;
}
- return mkstemp(name);
+ fd = mkstemp(name);
+ if (fd >= 0)
+ unlink(name);
+
+ return fd;
}
int main(int argc, char *argv[])
@@ -281,65 +293,97 @@ int main(int argc, char *argv[])
int i;
unsigned long int latency;
const char *dirname = "/tmp";
- int fd;
+ int fd, pid;
+ int nrchild = 1;
/*
* Optionnally we can specify the directory to test the
- * latencies
+ * latencies, ...
*/
- if (argc == 2)
+ if (argc > 1)
dirname = argv[1];
/*
- * Make temporary file, we don't want to pollute the file system
- * with big files if this program crashes
+ * ... the bucket interval, ...
*/
- fd = mktempfile(dirname);
- if (fd < 0) {
- perror("mktempfile");
- return -1;
- }
-
- write_file(fd);
+ if (argc > 2)
+ bucket_interval = atoi(argv[2]);
/*
- * Initialize the random seed with the number of current usec.
- * This random value will be used to access the file randomly, no
- * sequential accesses which can be optimized by the hardware
+ * ... the number of processes
*/
- gettimeofday(&begin, NULL);
- srandom(begin.tv_usec);
+ if (argc > 3)
+ nrchild = atoi(argv[3]);
- for (i = 0; i < 10000; i++) {
+ for (i = 0; i < nrchild; i++) {
- /*
- * Compute the offset address to read from
- */
- offset = (random() % NROFFSET) * PAGESIZE;
+ pid = fork();
- /*
- * man posix_fadvise
- */
- posix_fadvise(fd, offset, PAGESIZE, POSIX_FADV_DONTNEED);
+ if (pid < 0) {
+ perror("fork");
+ return -1;
+ }
+
+ if (pid)
+ continue;
/*
- * Measure the time to read a PAGESIZE buffer
+ * Make temporary file, we don't want to pollute the file system
+ * with big files if this program crashes
*/
- gettimeofday(&begin, NULL);
- pread(fd, buffer, PAGESIZE, offset);
- gettimeofday(&end, NULL);
- latency = ((end.tv_sec - begin.tv_sec) * 1000000) + (
- end.tv_usec - begin.tv_usec);
+ fd = mktempfile(dirname);
+ if (fd < 0) {
+ perror("mktempfile");
+ return -1;
+ }
+
+ write_file(fd);
/*
- * Fill a bucket with this latency
+ * Initialize the random seed with the number of
+ * current usec. This random value will be used to
+ * access the file randomly, no sequential accesses
+ * which can be optimized by the hardware
*/
- bucket_fill(latency);
+ gettimeofday(&begin, NULL);
+ srandom(begin.tv_usec);
+
+ for (i = 0; i < 10000; i++) {
+
+ /*
+ * Compute the offset address to read from
+ */
+ offset = (random() % NROFFSET) * PAGESIZE;
+
+ /*
+ * man posix_fadvise
+ */
+ posix_fadvise(fd, offset, PAGESIZE,
+ POSIX_FADV_DONTNEED);
+
+ /*
+ * Measure the time to read a PAGESIZE buffer
+ */
+ gettimeofday(&begin, NULL);
+ pread(fd, buffer, PAGESIZE, offset);
+ gettimeofday(&end, NULL);
+ latency = ((end.tv_sec - begin.tv_sec) * 1000000) + (
+ end.tv_usec - begin.tv_usec);
+
+ /*
+ * Fill a bucket with this latency
+ */
+ bucket_fill(latency);
+ }
+
+ bucket_show();
+
+ close(fd);
+
+ return 0;
}
- bucket_show();
-
- close(fd);
+ while (wait(NULL) == 0);
return 0;
}