Clean up grading scripts.
[pintos-anon] / grading / vm / patches / 00random.patch
diff --git a/grading/vm/patches/00random.patch b/grading/vm/patches/00random.patch
new file mode 100644 (file)
index 0000000..6e74443
--- /dev/null
@@ -0,0 +1,41 @@
+Modifies bitmap_scan() to return a random set of bits instead of the
+first set.  Helps to stress-test VM implementation.
+
+diff -u pintos/src/lib/kernel/bitmap.c~ pintos/src/lib/kernel/bitmap.c
+--- pintos/src/lib/kernel/bitmap.c~    2004-10-06 14:29:56.000000000 -0700
++++ pintos/src/lib/kernel/bitmap.c     2004-11-03 14:35:22.000000000 -0800
+@@ -1,6 +1,7 @@
+ #include "bitmap.h"
+ #include <debug.h>
+ #include <limits.h>
++#include <random.h>
+ #include <round.h>
+ #include <stdio.h>
+ #include "threads/malloc.h"
+@@ -212,14 +213,25 @@ size_t
+ bitmap_scan (const struct bitmap *b, size_t start, size_t cnt, bool value) 
+ {
+   size_t idx, last;
++  size_t n = 0, m;
+   
+   ASSERT (b != NULL);
+   ASSERT (start <= b->bit_cnt);
+   for (idx = start, last = b->bit_cnt - cnt; idx <= last; idx++)
+     if (!contains (b, idx, idx + cnt, !value))
++      n++;
++  if (n == 0)
++    return BITMAP_ERROR;
++
++  random_init (0);
++  m = random_ulong () % n;
++  
++  for (idx = start, last = b->bit_cnt - cnt; idx <= last; idx++)
++    if (!contains (b, idx, idx + cnt, !value) && m-- == 0)
+       return idx;
+-  return BITMAP_ERROR;
++
++  NOT_REACHED ();
+ }
+ /* Finds the first group of CNT consecutive bits in B at or after