annotate uprogs/stressfs.c @ 0:ed10291ff195

first commit
author mir3636
date Sun, 06 Jan 2019 19:27:03 +0900
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
ed10291ff195 first commit
mir3636
parents:
diff changeset
1 // Demonstrate that moving the "acquire" in iderw after the loop that
ed10291ff195 first commit
mir3636
parents:
diff changeset
2 // appends to the idequeue results in a race.
ed10291ff195 first commit
mir3636
parents:
diff changeset
3
ed10291ff195 first commit
mir3636
parents:
diff changeset
4 // For this to work, you should also add a spin within iderw's
ed10291ff195 first commit
mir3636
parents:
diff changeset
5 // idequeue traversal loop. Adding the following demonstrated a panic
ed10291ff195 first commit
mir3636
parents:
diff changeset
6 // after about 5 runs of stressfs in QEMU on a 2.1GHz CPU:
ed10291ff195 first commit
mir3636
parents:
diff changeset
7 // for (i = 0; i < 40000; i++)
ed10291ff195 first commit
mir3636
parents:
diff changeset
8 // asm volatile("");
ed10291ff195 first commit
mir3636
parents:
diff changeset
9
ed10291ff195 first commit
mir3636
parents:
diff changeset
10 #include "types.h"
ed10291ff195 first commit
mir3636
parents:
diff changeset
11 #include "stat.h"
ed10291ff195 first commit
mir3636
parents:
diff changeset
12 #include "user.h"
ed10291ff195 first commit
mir3636
parents:
diff changeset
13 #include "fs.h"
ed10291ff195 first commit
mir3636
parents:
diff changeset
14 #include "fcntl.h"
ed10291ff195 first commit
mir3636
parents:
diff changeset
15
ed10291ff195 first commit
mir3636
parents:
diff changeset
16 int
ed10291ff195 first commit
mir3636
parents:
diff changeset
17 main(int argc, char *argv[])
ed10291ff195 first commit
mir3636
parents:
diff changeset
18 {
ed10291ff195 first commit
mir3636
parents:
diff changeset
19 int fd, i;
ed10291ff195 first commit
mir3636
parents:
diff changeset
20 char path[] = "stressfs0";
ed10291ff195 first commit
mir3636
parents:
diff changeset
21 char data[512];
ed10291ff195 first commit
mir3636
parents:
diff changeset
22
ed10291ff195 first commit
mir3636
parents:
diff changeset
23 printf(1, "stressfs starting\n");
ed10291ff195 first commit
mir3636
parents:
diff changeset
24 memset(data, 'a', sizeof(data));
ed10291ff195 first commit
mir3636
parents:
diff changeset
25
ed10291ff195 first commit
mir3636
parents:
diff changeset
26 for(i = 0; i < 4; i++)
ed10291ff195 first commit
mir3636
parents:
diff changeset
27 if(fork() > 0)
ed10291ff195 first commit
mir3636
parents:
diff changeset
28 break;
ed10291ff195 first commit
mir3636
parents:
diff changeset
29
ed10291ff195 first commit
mir3636
parents:
diff changeset
30 printf(1, "write %d\n", i);
ed10291ff195 first commit
mir3636
parents:
diff changeset
31
ed10291ff195 first commit
mir3636
parents:
diff changeset
32 path[8] += i;
ed10291ff195 first commit
mir3636
parents:
diff changeset
33 fd = open(path, O_CREATE | O_RDWR);
ed10291ff195 first commit
mir3636
parents:
diff changeset
34 for(i = 0; i < 20; i++)
ed10291ff195 first commit
mir3636
parents:
diff changeset
35 // printf(fd, "%d\n", i);
ed10291ff195 first commit
mir3636
parents:
diff changeset
36 write(fd, data, sizeof(data));
ed10291ff195 first commit
mir3636
parents:
diff changeset
37 close(fd);
ed10291ff195 first commit
mir3636
parents:
diff changeset
38
ed10291ff195 first commit
mir3636
parents:
diff changeset
39 printf(1, "read\n");
ed10291ff195 first commit
mir3636
parents:
diff changeset
40
ed10291ff195 first commit
mir3636
parents:
diff changeset
41 fd = open(path, O_RDONLY);
ed10291ff195 first commit
mir3636
parents:
diff changeset
42 for (i = 0; i < 20; i++)
ed10291ff195 first commit
mir3636
parents:
diff changeset
43 read(fd, data, sizeof(data));
ed10291ff195 first commit
mir3636
parents:
diff changeset
44 close(fd);
ed10291ff195 first commit
mir3636
parents:
diff changeset
45
ed10291ff195 first commit
mir3636
parents:
diff changeset
46 wait();
ed10291ff195 first commit
mir3636
parents:
diff changeset
47
ed10291ff195 first commit
mir3636
parents:
diff changeset
48 exit();
ed10291ff195 first commit
mir3636
parents:
diff changeset
49 }