From: adash Date: Tue, 11 Dec 2007 00:30:59 +0000 (+0000) Subject: Build C code for prefetches complete X-Git-Tag: preEdgeChange~342 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=fdc4207db804a60ca6b0a56903d9d6b5c3674286;p=IRC.git Build C code for prefetches complete fix minor bugs in trans.c --- diff --git a/Robust/src/Analysis/Prefetch/IndexDescriptor.java b/Robust/src/Analysis/Prefetch/IndexDescriptor.java index 5555b3d5..97a9158b 100644 --- a/Robust/src/Analysis/Prefetch/IndexDescriptor.java +++ b/Robust/src/Analysis/Prefetch/IndexDescriptor.java @@ -57,7 +57,7 @@ public class IndexDescriptor extends Descriptor { } public int getOffset() { - return offset; + return offset.intValue(); } public String toString() { diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 61d1a2d6..9b3e2149 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -1422,87 +1422,54 @@ public class BuildCode { } public void generateFlatPrefetchNode(FlatMethod fm, LocalityBinding lb, FlatPrefetchNode fpn, PrintWriter output) { - System.out.println("DEBUG -> Inside generateFlatPrefetchNode() " + fm.toString()); short[] arrayfields = null; Vector fieldoffset = new Vector(); + Vector endoffset = new Vector(); Vector oids = new Vector(); - short offsetcount = 0; + short offsetcount = 0; int tuplecount = 0; - int i; + int i,j; if (state.PREFETCH) { - System.out.println("The Prefetch pairs to be fetched are "+ fpn.hspp); Iterator it = fpn.hspp.iterator(); output.println("/* prefetch */"); - /* TODO Get rid of this */ + /* TODO Add support for arrays, Currently handles only field pointers*/ /* The while loop below removes all prefetch tuples with arrays from the set of prefetches */ while(it.hasNext()) { PrefetchPair pp = (PrefetchPair) it.next(); for(i = 0; i < pp.desc.size(); i++) { if(pp.getDescAt(i) instanceof IndexDescriptor) { fpn.hspp.remove((PrefetchPair) pp); - it = fpn.hspp.iterator(); //May not be the best way ...replace coding in a better fashion + it = fpn.hspp.iterator(); break; } } } - output.println(" int numtuples_" + count + " = " + fpn.getNumPairs() + ";"); - int[] endoffsetarry = new int[fpn.getNumPairs()]; - output.print(" unsigned int oidarray_" + count + "[] = {"); it = fpn.hspp.iterator(); + String oidlist = new String(); while(it.hasNext()) { PrefetchPair pp = (PrefetchPair) it.next(); - offsetcount = 0; - //TODO handle arrays in prefetch tuples, currently only handle fields Integer statusbase = locality.getNodePreTempInfo(lb,fpn).get(pp.base); - FieldDescriptor fd = (FieldDescriptor)pp.desc.get(0); - String oid = new String("(unsigned int) " + generateTemp(fm, pp.base, lb) + "->" + ((FieldDescriptor)fd).getSafeSymbol()); - oids.add(oid); - for(i = 1; i < pp.desc.size(); i++) { - Object desc = pp.desc.get(i); - offsetcount++; - TypeDescriptor newtd = ((FieldDescriptor)pp.getDescAt(i-1)).getType(); - String newfieldoffset = new String("(short)(&(((struct "+ newtd.getSafeSymbol()+" *)0)->"+ - ((FieldDescriptor)desc).getSafeSymbol()+ "))"); - fieldoffset.add(newfieldoffset); - } - if(tuplecount > 0) { - endoffsetarry[tuplecount] = endoffsetarry[tuplecount-1] + offsetcount; - }else { - endoffsetarry[tuplecount] = offsetcount; - } - - //if(statusbase == LocalityAnalysis.LOCAL) { + /* Find prefetches that can generate oid */ if(statusbase == LocalityAnalysis.GLOBAL) { - System.out.println("DEBUG-> Is Global"); - //Check to see if node is a inside or outside a transaction - /* - if(locality.getAtomic(lb).get(fpn).intValue() > 0) { - //TODO Is this correct ? or generate pointer code in C - // return; - } else { - output.println("/* PP: " + generateTemp(fm, pp.base, lb)); - } - */ - // Generate oid for base - } else { - for(i = 0; i generateFlatPrefetchNode() fd" + statusfd); - //find out the locality of the fieldDescriptor - if(statusfd == LocalityAnalysis.GLOBAL) { - //generate oid for it - } - } - } - } - tuplecount++; + if(locality.getAtomic(lb).get(fpn).intValue()>0) { /* Inside transaction */ + generateInsideTransCode(fm,lb,output, pp,oids,fieldoffset,endoffset,tuplecount); + } else {/* Outside Transaction */ + generateOutsideTransCode(fm,lb,pp,oids,fieldoffset,endoffset,tuplecount); + } + tuplecount++; + } else if(statusbase == LocalityAnalysis.LOCAL) { + generateLocalTransCode(fm,lb,pp,oids,fieldoffset,endoffset,tuplecount); + } else { + continue; + } } + + /*Create C code for numtuples */ + output.println(" int numtuples_" + count + " = " + tuplecount + ";"); /*Create C code for oid array */ + output.print(" unsigned int oidarray_" + count + "[] = {"); boolean needcomma=false; it = oids.iterator(); while(it.hasNext()) { @@ -1516,18 +1483,19 @@ public class BuildCode { /*Create C code for endoffset values */ output.print(" unsigned short endoffsetarry_" + count +"[] = {"); needcomma=false; - for(i = 0; i" + ((FieldDescriptor)fd).getSafeSymbol() + + " : NULL)"); + oids.add(oid); + } else { + IndexDescriptor id = (IndexDescriptor)newdesc; + String tstlbl = new String(); + for(i=0; i "+ + generateTemp(fm, pp.base, lb) + "->___length___) {"); + output.println(" failedboundschk();"); + output.println("}"); + String oid = new String("(unsigned int) (" + + generateTemp(fm, pp.base, lb) + " != NULL ? " + + generateTemp(fm, pp.base, lb) + "[" + tstlbl + "] : NULL)"); + oids.add(oid); + } + for(i = 1; i < pp.desc.size(); i++) { + TypeDescriptor newtd; + String newfieldoffset; + Object desc = pp.getDescAt(i); + offsetcount++; + if(desc instanceof FieldDescriptor) { + Object prevdesc = pp.getDescAt(i-1); + if(prevdesc instanceof IndexDescriptor){ + if((i-1) == 0) + newtd = pp.base.getType(); + //FIXME currently handles one dimensional arrays + newtd = ((FieldDescriptor)pp.getDescAt(i-2)).getType(); + } else { + newtd = ((FieldDescriptor)pp.getDescAt(i-1)).getType(); + } + newfieldoffset = new String("(short)(&(((struct "+ newtd.getSafeSymbol()+" *)0)->"+ + ((FieldDescriptor)desc).getSafeSymbol()+ "))"); + fieldoffset.add(newfieldoffset); + } else { + String tstlbl = new String(); + for(i=0; i<((IndexDescriptor)desc).tddesc.size(); i++) { + tstlbl += generateTemp(fm, ((IndexDescriptor)desc).getTempDescAt(i), lb) + "+"; + } + tstlbl += ((IndexDescriptor)desc).offset.toString(); + newfieldoffset = new String("(short)("+tstlbl+")"); + fieldoffset.add(newfieldoffset); + } + } + if(tuplecount > 0) { + int tmp = (int) ((Short)(endoffset.get(tuplecount-1))).shortValue() + (int) offsetcount; + short endoffsetval = (short) tmp; + endoffset.add(endoffsetval); + }else { + endoffset.add(offsetcount); + } + } + + public void generateOutsideTransCode(FlatMethod fm, LocalityBinding lb,PrefetchPair pp, Vector oids, Vector fieldoffset, Vector endoffset, int tuplecount) { + int i; + short offsetcount = 0; + + String oid = new String(" (unsigned int) (" + generateTemp(fm, pp.base, lb)+ ")"); + oids.add(oid); + for(i = 0; i < pp.desc.size(); i++) { + TypeDescriptor newtd; + String newfieldoffset; + Object desc = pp.getDescAt(i); + offsetcount++; + if(desc instanceof FieldDescriptor) { + if(i == 0){ + newtd = pp.base.getType(); + } else { + Object prevdesc = pp.getDescAt(i-1); + if(prevdesc instanceof IndexDescriptor){ + //FIXME currently handles one dimensional arrays + newtd = ((FieldDescriptor)pp.getDescAt(i-2)).getType(); + } else { + newtd = ((FieldDescriptor)pp.getDescAt(i-1)).getType(); + } + } + newfieldoffset = new String("(short)(&(((struct "+ newtd.getSafeSymbol()+" *)0)->"+ + ((FieldDescriptor)desc).getSafeSymbol()+ "))"); + } else { + String tstlbl = new String(); + for(i=0; i<((IndexDescriptor)desc).tddesc.size(); i++) { + tstlbl += generateTemp(fm, ((IndexDescriptor)desc).getTempDescAt(i), lb) + "+"; + } + tstlbl += ((IndexDescriptor)desc).offset.toString(); + newfieldoffset = new String("(short)("+tstlbl+")"); + } + fieldoffset.add(newfieldoffset); + } + if(tuplecount > 0) { + int tmp = (int) ((Short)(endoffset.get(tuplecount-1))).shortValue() + (int) offsetcount; + short endoffsetval = (short) tmp; + endoffset.add(endoffsetval); + }else { + endoffset.add(offsetcount); + } + tuplecount++; + } + + public void generateLocalTransCode(FlatMethod fm, LocalityBinding lb,PrefetchPair pp,Vector oids, Vector fieldoffset,Vector endoffset, int tuplecount) { + int i, j; + short offsetcount = 0; + + Vector prefix = new Vector(); + prefix.add(generateTemp(fm,pp.base,lb)); + String tstlbl = new String("(" + prefix.get(0) + " != NULL "); + for (i = 0; i < pp.desc.size(); i++) { + Object newdesc = pp.desc.get(i); + if(newdesc instanceof FieldDescriptor) { + FieldDescriptor fd = (FieldDescriptor) newdesc; + if(fd.isGlobal()){ + /* Field descriptor is global */ + String oid = new String(" (unsigned int) ("); + tstlbl += ") ? "; + for(j = 0; j < prefix.size(); j++) { + tstlbl += prefix.get(j) + "->"; + } + tstlbl += fd.getSafeSymbol() + ": NULL"; + oid += tstlbl+ " )"; + oids.add(oid); + for(j=i+1; j < pp.desc.size(); j++) { + TypeDescriptor newtd; + String newfieldoffset; + Object desc = pp.getDescAt(j); + offsetcount++; + if(desc instanceof FieldDescriptor) { + Object prevdesc = pp.getDescAt(j-1); + if(prevdesc instanceof IndexDescriptor){ + //FIXME currently handles one dimensional arrays + newtd = ((FieldDescriptor)pp.getDescAt(j-2)).getType(); + } else { + newtd = ((FieldDescriptor) pp.getDescAt(j-1)).getType(); + } + newfieldoffset = new String("(short)(&(((struct "+ newtd.getSafeSymbol()+" *)0)->"+ + ((FieldDescriptor)desc).getSafeSymbol()+ "))"); + } else { + String indexlbl = new String(); + for(i=0; i<((IndexDescriptor)desc).tddesc.size(); i++) { + indexlbl += generateTemp(fm, ((IndexDescriptor)desc).getTempDescAt(i), lb) + "+"; + } + indexlbl += ((IndexDescriptor)desc).offset.toString(); + newfieldoffset = new String("(short)("+indexlbl+")"); + } + fieldoffset.add(newfieldoffset); + } + if(tuplecount > 0) { + int tmp = (int) ((Short)(endoffset.get(tuplecount-1))).shortValue() + (int) offsetcount; + short endoffsetval = (short) tmp; + endoffset.add(endoffsetval); + }else { + endoffset.add(offsetcount); + } + tuplecount++; + break; //break from outer for loop + } else { + tstlbl += "&& "; + for(j = 0; j < prefix.size(); j++) { + tstlbl += prefix.get(j) + "->"; + } + prefix.add(fd.getSafeSymbol()); + tstlbl += fd.getSafeSymbol() + " != NULL"; + } + } else { /* if Index descriptor */ + String indexstring = new String(); + IndexDescriptor id = (IndexDescriptor) newdesc; + if(i == 0) { + indexstring = generateTemp(fm, pp.base, lb); + } else { + indexstring = ((FieldDescriptor)pp.getDescAt(i-1)).getSafeSymbol(); + } + tstlbl += "&& "; + for(j = 0; j < prefix.size(); j++) { + tstlbl += prefix.get(j) + "["; + } + indexstring += "["; + for(j=0; j0) - return; - /* Backup the temps. */ - for(Iterator tmpit=locality.getTemps(lb).get(faen).iterator();tmpit.hasNext();) { - TempDescriptor tmp=tmpit.next(); - output.println(generateTemp(fm, backuptable.get(tmp),lb)+"="+generateTemp(fm,tmp,lb)+";"); - } - output.println("goto transstart"+faen.getIdentifier()+";"); + /* Check to see if we need to generate code for this atomic */ + if (locality.getAtomic(lb).get(faen.getPrev(0)).intValue()>0) + return; + /* Backup the temps. */ + for(Iterator tmpit=locality.getTemps(lb).get(faen).iterator();tmpit.hasNext();) { + TempDescriptor tmp=tmpit.next(); + output.println(generateTemp(fm, backuptable.get(tmp),lb)+"="+generateTemp(fm,tmp,lb)+";"); + } + output.println("goto transstart"+faen.getIdentifier()+";"); - /******* Print code to retry aborted transaction *******/ - output.println("transretry"+faen.getIdentifier()+":"); + /******* Print code to retry aborted transaction *******/ + output.println("transretry"+faen.getIdentifier()+":"); - /* Restore temps */ - for(Iterator tmpit=locality.getTemps(lb).get(faen).iterator();tmpit.hasNext();) { - TempDescriptor tmp=tmpit.next(); - output.println(generateTemp(fm, tmp,lb)+"="+generateTemp(fm,backuptable.get(tmp),lb)+";"); - } + /* Restore temps */ + for(Iterator tmpit=locality.getTemps(lb).get(faen).iterator();tmpit.hasNext();) { + TempDescriptor tmp=tmpit.next(); + output.println(generateTemp(fm, tmp,lb)+"="+generateTemp(fm,backuptable.get(tmp),lb)+";"); + } + + /********* Need to revert local object store ********/ + String revertptr=generateTemp(fm, reverttable.get(lb),lb); - /********* Need to revert local object store ********/ - String revertptr=generateTemp(fm, reverttable.get(lb),lb); - output.println("while ("+revertptr+") {"); output.println("struct ___Object___ * tmpptr;"); output.println("tmpptr="+revertptr+"->"+nextobjstr+";"); diff --git a/Robust/src/Runtime/DSTM/interface/trans.c b/Robust/src/Runtime/DSTM/interface/trans.c index 08088586..65e48e52 100644 --- a/Robust/src/Runtime/DSTM/interface/trans.c +++ b/Robust/src/Runtime/DSTM/interface/trans.c @@ -87,25 +87,27 @@ void prefetch(int ntuples, unsigned int *oids, unsigned short *endoffsets, short /* Allocate for the queue node*/ char *node; - qnodesize = sizeof(prefetchqelem_t) + sizeof(int) + ntuples * (sizeof(short) + sizeof(unsigned int)) + endoffsets[ntuples - 1] * sizeof(short); - if((node = calloc(1, qnodesize)) == NULL) { - printf("Calloc Error %s, %d\n", __FILE__, __LINE__); - return; + if(ntuples > 0) { + qnodesize = sizeof(prefetchqelem_t) + sizeof(int) + ntuples * (sizeof(short) + sizeof(unsigned int)) + endoffsets[ntuples - 1] * sizeof(short); + if((node = calloc(1, qnodesize)) == NULL) { + printf("Calloc Error %s, %d\n", __FILE__, __LINE__); + return; + } + /* Set queue node values */ + len = sizeof(prefetchqelem_t); + memcpy(node + len, &ntuples, sizeof(int)); + len += sizeof(int); + memcpy(node + len, oids, ntuples*sizeof(unsigned int)); + len += ntuples * sizeof(unsigned int); + memcpy(node + len, endoffsets, ntuples*sizeof(short)); + len += ntuples * sizeof(short); + memcpy(node + len, arrayfields, endoffsets[ntuples-1]*sizeof(short)); + /* Lock and insert into primary prefetch queue */ + pthread_mutex_lock(&pqueue.qlock); + pre_enqueue((prefetchqelem_t *)node); + pthread_cond_signal(&pqueue.qcond); + pthread_mutex_unlock(&pqueue.qlock); } - /* Set queue node values */ - len = sizeof(prefetchqelem_t); - memcpy(node + len, &ntuples, sizeof(int)); - len += sizeof(int); - memcpy(node + len, oids, ntuples*sizeof(unsigned int)); - len += ntuples * sizeof(unsigned int); - memcpy(node + len, endoffsets, ntuples*sizeof(short)); - len += ntuples * sizeof(short); - memcpy(node + len, arrayfields, endoffsets[ntuples-1]*sizeof(short)); - /* Lock and insert into primary prefetch queue */ - pthread_mutex_lock(&pqueue.qlock); - pre_enqueue((prefetchqelem_t *)node); - pthread_cond_signal(&pqueue.qcond); - pthread_mutex_unlock(&pqueue.qlock); } /* This function starts up the transaction runtime. */ @@ -1102,10 +1104,10 @@ void checkPrefetchTuples(prefetchqelem_t *node) { } /* Check for redundant tuples by comparing oids of each tuple */ for(i = 0; i < ntuples; i++) { - if(oid[i] == -1) + if(oid[i] == 0) continue; for(j = i+1 ; j < ntuples; j++) { - if(oid[j] == -1) + if(oid[j] == 0) continue; /*If oids of tuples match */ if (oid[i] == oid[j]) { @@ -1146,7 +1148,7 @@ void checkPrefetchTuples(prefetchqelem_t *node) { } if(slength == count) { - oid[sindex] = -1; + oid[sindex] = 0; } } } @@ -1207,7 +1209,7 @@ void checkPreCache(prefetchqelem_t *node, int *numoffset, int counter, int loopc } if(flag == 0) { - oid[iter] = -1; + oid[iter] = 0; numoffset[iter] = 0; } } @@ -1230,7 +1232,7 @@ prefetchpile_t *makePreGroups(prefetchqelem_t *node, int *numoffset) { /* Check for redundant tuples by comparing oids of each tuple */ for(i = 0; i < ntuples; i++) { - if(oid[i] == -1) + if(oid[i] == 0) continue; /* For each tuple make piles */ if ((machinenum = lhashSearch(oid[i])) == 0) { @@ -1269,7 +1271,7 @@ prefetchpile_t *foundLocal(prefetchqelem_t *node) { numoffset[i] = endoffsets[i] - endoffsets[i-1]; } for(i = 0; i < ntuples; i++) { - if(oid[i] == -1) + if(oid[i] == 0) continue; /* If object found locally */ if((objheader = (objheader_t*) mhashSearch(oid[i])) != NULL) { @@ -1301,7 +1303,7 @@ prefetchpile_t *foundLocal(prefetchqelem_t *node) { /*If all offset oids are found locally,make the prefetch tuple invalid */ if(flag == 0) { - oid[i] = -1; + oid[i] = 0; numoffset[i] = 0; } } else { @@ -1531,11 +1533,11 @@ void getPrefetchResponse(int count, int sd) { prehashInsert(oid, modptr); } /* Lock the Prefetch Cache look up table*/ - //pthread_mutex_lock(&pflookup.lock); + pthread_mutex_lock(&pflookup.lock); /* Broadcast signal on prefetch cache condition variable */ pthread_cond_broadcast(&pflookup.cond); /* Unlock the Prefetch Cache look up table*/ - //pthread_mutex_unlock(&pflookup.lock); + pthread_mutex_unlock(&pflookup.lock); } else if(buffer[index] == OBJECT_NOT_FOUND) { /* Increment it to get the object */ /* TODO: For each object not found query DHT for new location and retrieve the object */ diff --git a/Robust/src/Tests/Atomic3.java b/Robust/src/Tests/Atomic3.java index 00128630..6eba697c 100644 --- a/Robust/src/Tests/Atomic3.java +++ b/Robust/src/Tests/Atomic3.java @@ -31,6 +31,7 @@ public class Atomic3 extends Thread { public int run() { int a; atomic { + //FIXME a bug value of trans commit is not saved a = root.value.intValue(); //a = root.item; } diff --git a/Robust/src/Tests/Prefetch/ArrayTest.java b/Robust/src/Tests/Prefetch/ArrayTest.java index 05130d4f..a580fab2 100644 --- a/Robust/src/Tests/Prefetch/ArrayTest.java +++ b/Robust/src/Tests/Prefetch/ArrayTest.java @@ -18,10 +18,13 @@ public class ArrayTest { for(int i=0;i