From: adash Date: Wed, 5 Aug 2009 00:49:31 +0000 (+0000) Subject: simple microbenchmark to study locking X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=3fec921fdc80a1eb929551b4d78de3e862c91160;p=IRC.git simple microbenchmark to study locking --- diff --git a/Robust/src/Benchmarks/SingleTM/MicroBenchmarks/README b/Robust/src/Benchmarks/SingleTM/MicroBenchmarks/README new file mode 100644 index 00000000..e2467520 --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/MicroBenchmarks/README @@ -0,0 +1,24 @@ +SingleObjectMod.java: +---------------------- + Completes two transactions on single object type inside one loop iteration. The first transaction reads from the + object while the second transaction randomly generates an index and writes into the object. + + The contention is controlled by decreasing and increasing the size of the shared object array. Also + we get high contention by increasing the number of loop iterations to regulate the number of + transactions that will commit. + + Compiling and Running + ---------------------- + + To build: + make stmlock + e.g. ~/research/Robust/src/Benchmarks/SingleTM/MicroBenchmarks$ make clean && make stmlock + + To run: + ./STATSSingleObjectMod.bin -t + -size + -l + + low contention: -t 8 -size 5000 -l 100 + high contention: -t 8 -size 5 -l 500000 + diff --git a/Robust/src/Benchmarks/SingleTM/MicroBenchmarks/SingleObjectMod.java b/Robust/src/Benchmarks/SingleTM/MicroBenchmarks/SingleObjectMod.java new file mode 100644 index 00000000..8658663f --- /dev/null +++ b/Robust/src/Benchmarks/SingleTM/MicroBenchmarks/SingleObjectMod.java @@ -0,0 +1,106 @@ +public class SingleObjectMod extends Thread { + int nthreads; + int arrysize; + int loopsize; + int threadid; + intwrapper[] mainobj; + Random rand; + + public SingleObjectMod() { + + } + + public SingleObjectMod(int nthreads, int arrysize, int loopsize, int threadid, intwrapper[] mainobj, Random rand) { + this.nthreads = nthreads; + this.arrysize = arrysize; + this.loopsize = loopsize; + this.threadid = threadid; + this.mainobj = mainobj; + this.rand = rand; + } + + public static void parseCmdLine(String args[], SingleObjectMod som) { + int i = 0; + String arg; + while(i < args.length && args[i].startsWith("-")) { + arg = args[i++]; + //check options + if(arg.equals("-t")) { + if(i < args.length) { + som.nthreads = new Integer(args[i++]).intValue(); + } + } else if(arg.equals("-size")) { + if(i < args.length) { + som.arrysize = new Integer(args[i++]).intValue(); + } + } else if(arg.equals("-l")) { + if(i < args.length) { + som.loopsize = new Integer(args[i++]).intValue(); + } + } else { + System.out.println("Incorrect argument"); + System.out.println("usage: ./SingleObjectMod -t -size -l \n"); + } + } + } + + public void run() { + int index, val; + Random rand = new Random(); + rand.random_alloc(); + rand.random_seed(threadid); + int partitionSize = (loopsize + nthreads/2) /nthreads; + int start = threadid * partitionSize; + int stop; + if(threadid == (nthreads - 1)) + stop = loopsize; + else + stop = start + partitionSize; + //System.out.println("Start = " + start+ " stop= " + stop + " partitionSize= " + partitionSize+ " nthreads= " + nthreads); + for(int i = start; i < stop; i++) { + // Only read values from an object + atomic { + index = (int)(rand.random_generate() % arrysize); + val = mainobj[index]; + } + + // Write values + atomic { + index = (int)(rand.random_generate() % arrysize); + mainobj[index] = index; + } + } + } + + public static void main(String[] args) { + SingleObjectMod som = new SingleObjectMod(); + SingleObjectMod.parseCmdLine(args, som); + som.mainobj = new intwrapper[som.arrysize]; + + Random rand = new Random(); + rand.random_alloc(); + + for(int i = 0; i