changeset 89:42ee2ebed153

Schedulers should pessimistically allow large tasks.
author shade
date Thu, 13 Mar 2014 16:12:47 +0400
parents 899fa0979e1d
children 755271d4752e
files jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java jcstress-core/src/main/java/org/openjdk/jcstress/Options.java jcstress-core/src/main/java/org/openjdk/jcstress/infra/Scheduler.java
diffstat 3 files changed, 9 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java	Thu Mar 13 01:23:56 2014 +0400
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/JCStress.java	Thu Mar 13 16:12:47 2014 +0400
@@ -83,9 +83,9 @@
  */
 public class JCStress {
     final ExecutorService pool;
-    private final PrintStream out;
-    NetworkInputCollector networkCollector;
-    Scheduler scheduler;
+    final PrintStream out;
+    volatile NetworkInputCollector networkCollector;
+    volatile Scheduler scheduler;
 
     public JCStress() {
         this.pool = Executors.newCachedThreadPool(new ThreadFactory() {
@@ -114,7 +114,6 @@
 
             networkCollector = new NetworkInputCollector(sink);
 
-            // FIXME: Scheduler will stuck itself if there is a test requiring more than $userCPUs.
             scheduler = new Scheduler(opts.getUserCPUs());
 
             if (opts.shouldFork()) {
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/Options.java	Thu Mar 13 01:23:56 2014 +0400
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/Options.java	Thu Mar 13 16:12:47 2014 +0400
@@ -45,11 +45,6 @@
  * @author Aleksey Shipilev (aleksey.shipilev@oracle.com)
  */
 public class Options {
-    public static final String STATE_FILE = "test.state";
-
-    // the largest test it 4 threads wide
-    private static final int MIN_THREADS = 4;
-
     private String resultDir;
     private String testFilter;
     private int minStride, maxStride;
@@ -193,7 +188,6 @@
         } else {
             this.userCPUs = set.valueOf(cpus);
         }
-        this.userCPUs = Math.max(MIN_THREADS, this.userCPUs);
 
         if (userCPUs > systemCPUs) {
             forceYield = true;
--- a/jcstress-core/src/main/java/org/openjdk/jcstress/infra/Scheduler.java	Thu Mar 13 01:23:56 2014 +0400
+++ b/jcstress-core/src/main/java/org/openjdk/jcstress/infra/Scheduler.java	Thu Mar 13 16:12:47 2014 +0400
@@ -48,20 +48,24 @@
             return t;
         }
     });
+    private final int totalTokens;
 
     public Scheduler(int totalTokens) {
+        this.totalTokens = totalTokens;
         this.sentinel = new Semaphore(totalTokens);
     }
 
     public void schedule(final ScheduledTask task) throws InterruptedException {
-        sentinel.acquire(task.getTokens());
+        // Make fat tasks bypass in exclusive mode
+        final int tokensAcquired = Math.min(task.getTokens(), totalTokens);
+        sentinel.acquire(tokensAcquired);
         services.submit(new Runnable() {
             @Override
             public void run() {
                 try {
                     task.run();
                 } finally {
-                    sentinel.release(task.getTokens());
+                    sentinel.release(tokensAcquired);
                 }
             }
         });