Example #1
0
def runAlgoNAA(save, bin, thrille, sched, en, addrlist, err):
    # NAA
    simpsched_NAA = noniterativeAA.noniterativeAA(save, bin, thrille, sched, en, addrlist, err)

    blockremoval.outputResult(simpsched_NAA, err, addrlist, bin, thrille, save)

    NAAsched, NAAenabled, NAAaddrlist, NAAcondlist = blockremoval.readInNewSchedule(save)

    assert simpsched_NAA == NAAsched
    return NAAsched, NAAenabled, NAAaddrlist, NAAcondlist
Example #2
0
def runAlgoNBB(save, bin, thrille, sched, en, addrlist, err):
    # NBB
    simpsched_NBB = noniterativeBB.noniterativeBB(save, bin, thrille, sched, en, addrlist, err)

    blockremoval.outputResult(simpsched_NBB, err, addrlist, bin, thrille, save)

    NBBsched, NBBenabled, NBBaddrlist, NBBcondlist = blockremoval.readInNewSchedule(save)

    assert simpsched_NBB == NBBsched
    return NBBsched, NBBenabled, NBBaddrlist, NBBcondlist
def main():
    checkEnvironment()
    input_schedule = sys.argv[1]
    output_schedule = sys.argv[2]
    binary_file = sys.argv[3]
    thrille_root = os.environ.get('THRILLE_ROOT')
    sched, enabled, addrlist, condlist = \
            blockremoval.readInNewSchedule(sys.argv[1])
    error = blockremoval.recordFailure(sys.argv[1])

    assert blockremoval.testSchedule(sched, error, addrlist, binary_file, \
            thrille_root)

    start_blocks = blockremoval.getTotalBlocks(sched)
    start_context = \
            preemptremoval.countContextSwitches(sched, enabled, condlist)
    start_npcs = \
            preemptremoval.countNonpreemptiveCS(sched, enabled, condlist)
    start_preemptions = \
            preemptremoval.countPreemptions(sched, enabled, condlist)

    assert (start_npcs + start_preemptions) == start_context, "sanity fail"

    simpsched = noniterativeAA(output_schedule, binary_file,\
            thrille_root, sched,\
            enabled, addrlist, error)

    blockremoval.outputResult(simpsched, error, addrlist,\
            binary_file, thrille_root, output_schedule)

    sched, enabled, addrlist, condlist = \
            blockremoval.readInNewSchedule(output_schedule)
    end_blocks = blockremoval.getTotalBlocks(sched)
    end_context = \
            preemptremoval.countContextSwitches(sched, enabled, condlist)
    end_npcs = \
            preemptremoval.countNonpreemptiveCS(sched, enabled, condlist)
    end_preemptions = \
            preemptremoval.countPreemptions(sched, enabled, condlist)
    assert (end_npcs + end_preemptions) == end_context, "sanity fail"

    print "Start:\n\tblocks:", start_blocks, 
    print "\n\tcontext switches:", start_context, "\n\t\tpreemptions:",
    print start_preemptions, "\n\t\tnon-preemptive switches:", start_npcs

    print
    print "End:\n\tblocks:", end_blocks,
    print "\n\tcontext switches:", end_context, "\n\t\tpreemptions:",
    print end_preemptions, "\n\t\tnon-preemptive switches:", end_npcs
Example #4
0
def main():
    checkEnvironment()
    input_schedule = sys.argv[1]
    output_schedule = sys.argv[2]
    binary_file = sys.argv[3]
    thrille_root = os.environ.get('THRILLE_ROOT')
    sched, enabled, addrlist, condlist = \
            blockremoval.readInNewSchedule(sys.argv[1])
    error = blockremoval.recordFailure(sys.argv[1])

    assert blockremoval.testSchedule(sched, error, addrlist, \
            binary_file, thrille_root)

    start_blocks = blockremoval.getTotalBlocks(sched)
    start_context = \
            preemptremoval.countContextSwitches(sched, enabled, condlist)
    start_npcs = \
            preemptremoval.countNonpreemptiveCS(sched, enabled, condlist)
    start_preemptions = \
            preemptremoval.countPreemptions(sched, enabled, condlist)

    assert (start_npcs + start_preemptions) == start_context, "sanity fail"
    
    simpsched = noniterativeBB(output_schedule, binary_file,\
            thrille_root, sched,\
            enabled, addrlist, error)
    
    blockremoval.outputResult(simpsched, error, addrlist, \
            binary_file, thrille_root, output_schedule)

    sched, enabled, addrlist, condlist = \
            blockremoval.readInNewSchedule(output_schedule)
    end_blocks = blockremoval.getTotalBlocks(sched)
    end_context = \
            preemptremoval.countContextSwitches(sched, enabled, condlist)
    end_npcs = \
            preemptremoval.countNonpreemptiveCS(sched, enabled, condlist)
    end_preemptions = \
            preemptremoval.countPreemptions(sched, enabled, condlist)
    assert (end_npcs + end_preemptions) == end_context, "sanity fail"

    print "Start:\n\tblocks:", start_blocks, 
    print "\n\tcontext switches:", start_context, "\n\t\tpreemptions:",
    print start_preemptions, "\n\t\tnon-preemptive switches:", start_npcs

    print
    print "End:\n\tblocks:", end_blocks,
    print "\n\tcontext switches:", end_context, "\n\t\tpreemptions:",
    print end_preemptions, "\n\t\tnon-preemptive switches:", end_npcs
Example #5
0
def noniterativeBB(output_schedule, binary_file, thrille_root,\
        sched, enabled, addrlist, error):
    brsched = blockremoval.blockRemovalAlgorithmB( \
            binary_file, thrille_root, sched, enabled, addrlist, error)
    
    outdir, out = os.path.split(output_schedule)
    tmpout = os.path.join(outdir, "block-sched")

    blockremoval.outputResult(brsched, error, addrlist, binary_file,\
            thrille_root, tmpout) 
    newsched, newenabled, newaddrlist, newcondlist  = \
            blockremoval.readInNewSchedule(tmpout)

    assert blockremoval.recordFailure(tmpout) == error, "err fail"

    simpsched = preemptremoval.preemptRemovalAlgorithmB(binary_file, \
            output_schedule, thrille_root, newsched, newenabled, \
            newaddrlist, newcondlist, error)
    return simpsched
Example #6
0
def runAlgoIBB(save, bin, thrille, sched, en, addrlist, err):
    prev_IBBsched = sched
    prev_IBBenabled = en
    IBBsched = []
    IBBenabled = []
    IBBaddrlist = []
    IBBcondlist = []
    while True:
        simpsched_IBB = noniterativeBB.noniterativeBB(save, bin, thrille, prev_IBBsched, prev_IBBenabled, addrlist, err)

        blockremoval.outputResult(simpsched_IBB, err, addrlist, bin, thrille, save)

        IBBsched, IBBenabled, IBBaddrlist, IBBcondlist = blockremoval.readInNewSchedule(save)

        assert simpsched_IBB == IBBsched
        assert IBBaddrlist == addrlist

        if IBBsched == prev_IBBsched:
            break
        else:
            prev_IBBsched = IBBsched
            prev_IBBenabled = IBBenabled

    return IBBsched, IBBenabled, IBBaddrlist, IBBcondlist
Example #7
0
def runAlgoIAA(save, bin, thrille, sched, en, addrlist, err):
    prev_IAAsched = sched
    prev_IAAenabled = en
    IAAsched = []
    IAAenabled = []
    IAAaddrlist = []
    IAAcondlist = []
    while True:
        simpsched_IAA = noniterativeAA.noniterativeAA(save, bin, thrille, prev_IAAsched, prev_IAAenabled, addrlist, err)

        blockremoval.outputResult(simpsched_IAA, err, addrlist, bin, thrille, save)

        IAAsched, IAAenabled, IAAaddrlist, IAAcondlist = blockremoval.readInNewSchedule(save)

        assert simpsched_IAA == IAAsched
        assert IAAaddrlist == addrlist

        if IAAsched == prev_IAAsched:
            break
        else:
            prev_IAAsched = IAAsched
            prev_IAAenabled = IAAenabled

    return IAAsched, IAAenabled, IAAaddrlist, IAAcondlist
Example #8
0
def main():
    checkEnvironment()
    times_to_repeat = int(sys.argv[1])
    save_directory = sys.argv[2]
    binary_file = sys.argv[3]
    thrille_root = os.environ.get("THRILLE_ROOT")
    fout = open(os.path.join(save_directory, "simpl-runstat"), "w")
    my_bin_save = os.path.join(save_directory, "bin")
    os.mkdir(my_bin_save)
    shutil.copy(os.path.join(thrille_root, "bin", "libserializer.so"), os.path.join(my_bin_save, "libserializer.so"))
    shutil.copy(
        os.path.join(thrille_root, "bin", "libstrictserial.so"), os.path.join(my_bin_save, "libstrictserial.so")
    )
    shutil.copy(
        os.path.join(thrille_root, "bin", "librandomschedule.so"), os.path.join(my_bin_save, "librandomschedule.so")
    )
    shutil.copy(os.path.join(thrille_root, "bin", "librandact.so"), os.path.join(my_bin_save, "librandact.so"))
    shutil.copy(os.path.join(thrille_root, "bin", "librace.so"), os.path.join(my_bin_save, "librace.so"))
    shutil.copy(os.path.join(thrille_root, "bin", "liblockrace.so"), os.path.join(my_bin_save, "liblockrace.so"))

    # figure out how to remove svn
    os.mkdir(os.path.join(save_directory, "src"))

    shutil.copytree(os.path.join(thrille_root, "src"), os.path.join(save_directory, "src", "src"))
    shutil.copytree(os.path.join(thrille_root, "scripts"), os.path.join(save_directory, "src", "scripts"))
    fout.write("Command that was run:\n")
    for x in sys.argv:
        fout.write(x + " ")
    fout.write("\n\n")

    # lists for tracking statistics
    start_list = []
    naa_list = []
    nbb_list = []
    iaa_list = []
    ibb_list = []
    i = 0
    while i < times_to_repeat:
        my_save_dir = ""
        if i < 10:
            my_save_dir = os.path.join(save_directory, "run0" + str(i))
        else:
            my_save_dir = os.path.join(save_directory, "run" + str(i))
        os.mkdir(my_save_dir)

        startsched, startenabled, startaddrlist, startcondlist, error = getNewErrorSchedule(binary_file, thrille_root)

        # save the error schedule we are starting with
        # and ensure it's legitimate
        blockremoval.outputResult(
            startsched, error, startaddrlist, binary_file, thrille_root, os.path.join(my_save_dir, "start-sched")
        )

        start_list.append((startsched, startenabled, startcondlist))

        # NAA
        output_schedule = os.path.join(my_save_dir, "simp-sched-NAA")
        NAAsched, NAAenabled, NAAaddrlist, NAAcondlist = runAlgoNAA(
            output_schedule, binary_file, thrille_root, startsched, startenabled, startaddrlist, error
        )
        assert NAAaddrlist == startaddrlist
        naa_list.append((NAAsched, NAAenabled, NAAcondlist))

        # NBB
        output_schedule = os.path.join(my_save_dir, "simp-sched-NBB")
        NBBsched, NBBenabled, NBBaddrlist, NBBcondlist = runAlgoNBB(
            output_schedule, binary_file, thrille_root, startsched, startenabled, startaddrlist, error
        )
        assert NBBaddrlist == startaddrlist
        nbb_list.append((NBBsched, NBBenabled, NBBcondlist))

        # IAA - iterate until fixed point
        output_schedule = os.path.join(my_save_dir, "simp-sched-IAA")
        IAAsched, IAAenabled, IAAaddrlist, IAAcondlist = runAlgoIAA(
            output_schedule, binary_file, thrille_root, startsched, startenabled, startaddrlist, error
        )
        assert IAAaddrlist == startaddrlist
        assert len(IAAsched) <= len(NAAsched)
        iaa_list.append((IAAsched, IAAenabled, IAAcondlist))

        # IBB - iterate until fixed point
        output_schedule = os.path.join(my_save_dir, "simp-sched-IBB")
        IBBsched, IBBenabled, IBBaddrlist, IBBcondlist = runAlgoIBB(
            output_schedule, binary_file, thrille_root, startsched, startenabled, startaddrlist, error
        )
        assert IBBaddrlist == startaddrlist
        assert len(IBBsched) <= len(NBBsched)
        ibb_list.append((IBBsched, IBBenabled, IBBcondlist))

        assert len(start_list) == len(naa_list)
        assert len(naa_list) == len(nbb_list)
        assert len(nbb_list) == len(iaa_list)
        assert len(iaa_list) == len(ibb_list)
        sched, en, cond = start_list[-1]
        outputScheduleInformation("Start", sched, en, cond)
        sched, en, cond = naa_list[-1]
        outputScheduleInformation("NAA", sched, en, cond)
        sched, en, cond = nbb_list[-1]
        outputScheduleInformation("NBB", sched, en, cond)
        sched, en, cond = iaa_list[-1]
        outputScheduleInformation("IAA", sched, en, cond)
        sched, en, cond = ibb_list[-1]
        outputScheduleInformation("IBB", sched, en, cond)

        tmpout = open(os.path.join(my_save_dir, "README"), "w")
        sys.stdout = tmpout
        sched, en, cond = start_list[-1]
        outputScheduleInformation("Start", sched, en, cond)
        sched, en, cond = naa_list[-1]
        outputScheduleInformation("NAA", sched, en, cond)
        sched, en, cond = nbb_list[-1]
        outputScheduleInformation("NBB", sched, en, cond)
        sched, en, cond = iaa_list[-1]
        outputScheduleInformation("IAA", sched, en, cond)
        sched, en, cond = ibb_list[-1]
        outputScheduleInformation("IBB", sched, en, cond)
        tmpout.write("\n")
        sys.stdout.flush()
        sys.stdout = sys.__stdout__
        tmpout.close()

        fout.write("**RUN " + str(i) + "\n")
        sys.stdout = fout
        sched, en, cond = start_list[-1]
        outputScheduleInformation("Start", sched, en, cond)
        sched, en, cond = naa_list[-1]
        outputScheduleInformation("NAA", sched, en, cond)
        sched, en, cond = nbb_list[-1]
        outputScheduleInformation("NBB", sched, en, cond)
        sched, en, cond = iaa_list[-1]
        outputScheduleInformation("IAA", sched, en, cond)
        sched, en, cond = ibb_list[-1]
        outputScheduleInformation("IBB", sched, en, cond)
        fout.write("\n")
        sys.stdout.flush()
        sys.stdout = sys.__stdout__
        i += 1
def preemptRemovalAlgorithmB(binary_file, output_schedule, thrille_root, \
        sched, enabled, addrlist, condlist, error):
    start_preemptions = countPreemptions(sched, enabled, condlist)
    minimal_frontier = 0
    number_success = 0
    while minimal_frontier < len(sched):
        curr_thread = sched[minimal_frontier]
        target = minimal_frontier + 1
        if target < len(sched):
            if curr_thread == sched[target]:
                minimal_frontier += 1
                continue
            if curr_thread not in enabled[target]:
                minimal_frontier += 1
                continue
        while target < len(sched):
            if sched[target] == curr_thread:
                newsched = moveSwitchAfterFrontier(sched, \
                        minimal_frontier, target)
                success = blockremoval.testSchedule(newsched, error, addrlist,\
                        binary_file, thrille_root)
                if (success):
                    old_sched_len = len(sched)
                    binpath, binfile = os.path.split(binary_file)
                    fin = os.path.join(binpath, thrille_output_schedule)
                    sched, enabled, addrlist, condlist = \
                            blockremoval.readInNewSchedule(fin)
                    if ("segfault" not in error):
                        assert old_sched_len == len(sched)
                    else:
                        if len(sched) != old_sched_len:
                            print "Segfault weirdness"
                            print "old schedule length:", old_sched_len
                            print "new schedule length:", len(sched)

                    print "Preemptions at start:", start_preemptions
                    print "Preemptions now:", countPreemptions(sched, \
                            enabled, condlist)
                    print "Frontier at", minimal_frontier, "out of", 
                    print len(sched)
                    print "Number of swaps:", number_success
                    number_success += 1
                    if number_success % 50 == 0:
                        print "***OUTPUT***"
                        blockremoval.outputResult(sched, error, addrlist, \
                                binary_file, thrille_root, output_schedule)
                    break
                else:
                    print "Preemptions at start:", start_preemptions
                    print "Preemptions now:", countPreemptions(sched, \
                            enabled, condlist)
                    print "Frontier at", minimal_frontier, "out of",
                    print len(sched)
                    print "Number of swaps:", number_success
                    break
            else:
                target += 1
        minimal_frontier += 1
    assert blockremoval.testSchedule(sched, error, addrlist, binary_file, \
            thrille_root), "sanity fail"
    return sched
Example #10
0
def preemptRemovalAlgorithmB(binary_file, output_schedule, thrille_root, \
        sched, enabled, addrlist, condlist, error):
    start_preemptions = countPreemptions(sched, enabled, condlist)
    minimal_frontier = 0
    number_success = 0
    while minimal_frontier < len(sched):
        curr_thread = sched[minimal_frontier]
        target = minimal_frontier + 1
        if target < len(sched):
            if curr_thread == sched[target]:
                minimal_frontier += 1
                continue
            if curr_thread not in enabled[target]:
                minimal_frontier += 1
                continue
        while target < len(sched):
            if sched[target] == curr_thread:
                newsched = moveSwitchAfterFrontier(sched, \
                        minimal_frontier, target)
                success = blockremoval.testSchedule(newsched, error, addrlist,\
                        binary_file, thrille_root)
                if (success):
                    old_sched_len = len(sched)
                    binpath, binfile = os.path.split(binary_file)
                    fin = os.path.join(binpath, thrille_output_schedule)
                    sched, enabled, addrlist, condlist = \
                            blockremoval.readInNewSchedule(fin)
                    if ("segfault" not in error):
                        assert old_sched_len == len(sched)
                    else:
                        if len(sched) != old_sched_len:
                            print "Segfault weirdness"
                            print "old schedule length:", old_sched_len
                            print "new schedule length:", len(sched)

                    print "Preemptions at start:", start_preemptions
                    print "Preemptions now:", countPreemptions(sched, \
                            enabled, condlist)
                    print "Frontier at", minimal_frontier, "out of",
                    print len(sched)
                    print "Number of swaps:", number_success
                    number_success += 1
                    if number_success % 50 == 0:
                        print "***OUTPUT***"
                        blockremoval.outputResult(sched, error, addrlist, \
                                binary_file, thrille_root, output_schedule)
                    break
                else:
                    print "Preemptions at start:", start_preemptions
                    print "Preemptions now:", countPreemptions(sched, \
                            enabled, condlist)
                    print "Frontier at", minimal_frontier, "out of",
                    print len(sched)
                    print "Number of swaps:", number_success
                    break
            else:
                target += 1
        minimal_frontier += 1
    assert blockremoval.testSchedule(sched, error, addrlist, binary_file, \
            thrille_root), "sanity fail"
    return sched