user/stressfs.c

49 lines
1// Demonstrate that moving the "acquire" in iderw after the loop that2// appends to the idequeue results in a race.34// For this to work, you should also add a spin within iderw's5// idequeue traversal loop.  Adding the following demonstrated a panic6// after about 5 runs of stressfs in QEMU on a 2.1GHz CPU:7//    for (i = 0; i < 40000; i++)8//      asm volatile("");910#include "kernel/types.h"11#include "kernel/stat.h"12#include "user/user.h"13#include "kernel/fs.h"14#include "kernel/fcntl.h"1516int17main(int argc, char *argv[])18{19  int fd, i;20  char path[] = "stressfs0";21  char data[512];2223  printf("stressfs starting\n");24  memset(data, 'a', sizeof(data));2526  for(i = 0; i < 4; i++)27    if(fork() > 0)28      break;2930  printf("write %d\n", i);3132  path[8] += i;33  fd = open(path, O_CREATE | O_RDWR);34  for(i = 0; i < 20; i++)35//    printf(fd, "%d\n", i);36    write(fd, data, sizeof(data));37  close(fd);3839  printf("read\n");4041  fd = open(path, O_RDONLY);42  for (i = 0; i < 20; i++)43    read(fd, data, sizeof(data));44  close(fd);4546  wait(0);4748  exit(0);49}50