示例#1
0
    def stop_exp(self):
        """Stops the Kronos experiment."""

        if self.is_virtual:
            print("Stopping Synchronized Experiment ...")
            kf.stopExp()
        if self.grpc_server_pid:
            os.kill(self.grpc_server_pid, signal.SIGINT)
示例#2
0
文件: net_power.py 项目: ITI/Melody
    def stop_synchronized_experiment(self):
        """Stop a synchronized kronos experiment if kronos is disabled

        :return: None
        """

        logging.info(
            "########################################################################"
        )
        if self.enable_kronos == 1:
            kronos_functions.stopExp()
            logging.info("Kronos >> Stopping synchronized experiment ...")
            self.trigger_all_processes(defines.EXIT_CMD)
            self.replay_orchestrator.send_command(defines.EXIT_CMD)
            logging.info("Kronos >> Stopped synchronized experiment")
        else:
            logging.info("Melody >> Stopping emulation ... ")
        logging.info(
            "########################################################################"
        )
示例#3
0
    def stop_exp(self):
        """Stops the Kronos experiment."""

        if self.is_virtual:
            print "Stopping Synchronized Experiment ..."
            kf.stopExp()
def main():

    parser = argparse.ArgumentParser()


    parser.add_argument('--cmds_to_run_file', dest='cmds_to_run_file',
                        help='path to file containing commands to run', \
                        type=str, default='cmds_to_run_file.txt')

    parser.add_argument('--progress_ns_per_round',
                        dest='progress_ns_per_round',
                        help='Number of insns per round',
                        type=int,
                        default=1000000)

    parser.add_argument('--num_progress_rounds',
                        dest='num_progress_rounds',
                        help='Number of rounds to run',
                        type=int,
                        default=1000)

    parser.add_argument('--exp_type',
                        dest='exp_type',
                        help='Number of rounds to run',
                        type=int,
                        default=EXP_CS)

    parser.add_argument('--num_timelines',
                        dest='num_timelines',
                        help='Number of timelines in CS experiment',
                        type=int,
                        default=1)

    args = parser.parse_args()
    log_fds = []
    tracer_pids = []
    cmds_to_run = []

    worker_threads = []

    logging.basicConfig(level=logging.INFO)

    if not os.path.isfile(args.cmds_to_run_file):
        logging.info("Commands file path is incorrect !")
        sys.exit(0)
    fd1 = open(args.cmds_to_run_file, "r")
    cmds_to_run = [x.strip() for x in fd1.readlines()]
    fd1.close()
    for i in range(0, len(cmds_to_run)):
        with open("/tmp/tracer_log_%d.txt" % (i), "w") as f:
            pass
    log_fds = [ os.open("/tmp/tracer_log_%d.txt" %(i), os.O_RDWR | os.O_CREAT ) \
        for i in range(0, len(cmds_to_run)) ]
    num_tracers = len(cmds_to_run)
    num_timelines = len(cmds_to_run)
    #num_timelines = args.num_timelines

    input('Press any key to continue !')
    for i in range(0, num_tracers):
        with open("/tmp/tracer_log_%d.txt" % (i), "w") as f:
            pass
    log_fds = [ os.open("/tmp/tracer_log_%d.txt" %(i), os.O_RDWR | os.O_CREAT ) \
        for i in range(0, num_tracers) ]

    logging.info("Initializing VT Module !")
    if kf.initializeVTExp(args.exp_type, num_timelines, num_tracers) < 0:
        logging.info(
            "VT module initialization failed ! Make sure you are running\
               the dilated kernel and kronos module is loaded !")
        sys.exit(0)

    input('Press any key to continue !')

    logging.info("Starting all commands to run !")

    for i in range(0, num_tracers):
        logging.info("Starting tracer: %d", i + 1)
        start_new_dilated_process(i % num_timelines, cmds_to_run[i],
                                  log_fds[i], args.exp_type)
    input('Press any key to continue !')

    logging.info("Synchronizing and freezing tracers ...")
    while kf.synchronizeAndFreeze() <= 0:
        logging.info("VT Module >> Synchronize and Freeze failed."
                     " Retrying in 1 sec")
        time.sleep(1)

    input('Press any key to continue !')

    for index in range(num_timelines):
        logging.info("Main    : create and start thread %d.", index)
        x = threading.Thread(target=worker_thread_fn,
                             args=(args.progress_ns_per_round,
                                   args.num_progress_rounds, index))
        worker_threads.append(x)
        x.start()

    for index, thread in enumerate(worker_threads):
        logging.info("Main    : before joining thread %d.", index)
        thread.join()
        logging.info("Main    : thread %d done", index)

    input("Press Enter to continue...")
    logging.info("Stopping Synchronized Experiment !")
    kf.stopExp()

    for fd in log_fds:
        os.close(fd)

    logging.info("Finished ! Logs of each ith tracer can be found "
                 "in /tmp/tracer_log_i.txt")
def main():

    parser = argparse.ArgumentParser()


    parser.add_argument('--cmds_to_run_file', dest='cmds_to_run_file',
                        help='path to file containing commands to run', \
                        type=str, default='cmds_to_run_file.txt')

    parser.add_argument('--num_insns_per_round',
                        dest='num_insns_per_round',
                        help='Number of insns per round',
                        type=int,
                        default=1000000)

    parser.add_argument('--num_progress_rounds',
                        dest='num_progress_rounds',
                        help='Number of rounds to run',
                        type=int,
                        default=2000)

    parser.add_argument('--rel_cpu_speed', dest='rel_cpu_speed',
                        help='relative cpu speed', type=float, \
                        default=1.0)

    args = parser.parse_args()
    log_fds = []
    tracer_pids = []
    cmds_to_run = []

    if not os.path.isfile(args.cmds_to_run_file):
        print("Commands file path is incorrect !")
        sys.exit(0)
    fd1 = open(args.cmds_to_run_file, "r")
    cmds_to_run = [x.strip() for x in fd1.readlines()]
    fd1.close()
    for i in range(0, len(cmds_to_run)):
        with open("/tmp/tracer_log%d.txt" % (i), "w") as f:
            pass
    log_fds = [ os.open("/tmp/tracer_log%d.txt" %(i), os.O_RDWR | os.O_CREAT ) \
        for i in range(0, len(cmds_to_run)) ]
    num_tracers = len(cmds_to_run)

    input('Press any key to continue !')
    for i in range(0, num_tracers):
        with open("/tmp/tracer_log%d.txt" % (i), "w") as f:
            pass
    log_fds = [ os.open("/tmp/tracer_log%d.txt" %(i), os.O_RDWR | os.O_CREAT ) \
        for i in range(0, num_tracers) ]

    print("Initializing VT Module !")
    if kf.initializeExp(num_tracers) < 0:
        print("VT module initialization failed ! Make sure you are running "
              "the dilated kernel and kronos module is loaded !")
        sys.exit(0)

    input('Press any key to continue !')

    print("Starting all commands to run !")

    for i in range(0, num_tracers):
        print("Starting tracer: %d" % (i + 1))
        start_new_dilated_process(num_tracers, cmds_to_run[i], log_fds[i],
                                  args.rel_cpu_speed)

    print("Synchronizing anf freezing tracers ...")
    while kf.synchronizeAndFreeze() <= 0:
        print("VT Module >> Synchronize and Freeze failed. Retrying in 1 sec")
        time.sleep(1)

    input('Press any key to continue !')
    print("Starting Synchronized Experiment !")
    start_time = float(time.time())
    if args.num_progress_rounds > 0:
        print("Running for %d rounds ... " % (args.num_progress_rounds))
        num_finised_rounds = 0
        step_size = min(10, args.num_progress_rounds)
        while num_finised_rounds < args.num_progress_rounds:
            kf.progressBy(args.num_insns_per_round, step_size)
            num_finised_rounds += step_size
            #input("Press Enter to continue...")
            print("Ran %d rounds ..." % (num_finised_rounds),
                  " elapsed time ...",
                  float(time.time()) - start_time)

    elapsed_time = float(time.time()) - start_time
    print("Total time elapsed (secs) = ", elapsed_time)
    input("Press Enter to continue...")
    print("Stopping Synchronized Experiment !")
    kf.stopExp()

    for fd in log_fds:
        os.close(fd)

    print(
        "Finished ! Logs of each ith tracer can be found in /tmp/tracer_logi.txt"
    )
def main():

    parser = argparse.ArgumentParser()

    parser.add_argument('--cmds_to_run_file', dest='cmds_to_run_file',
                        help='path to file containing commands to run', \
                        type=str, default='cmds_to_run_file.txt')

    parser.add_argument(
        '--run_in_one_tracer',
        dest='run_in_one_tracer',
        help='True/False runs all commands in one tracer if True',
        default="False")

    parser.add_argument('--rel_cpu_speed', dest='rel_cpu_speed',
                        help='relative cpu speed', type=float, \
                        default=1.5)

    parser.add_argument('--num_insns_per_round',
                        dest='num_insns_per_round',
                        help='Number of insns per round',
                        type=int,
                        default=10000)

    parser.add_argument('--num_progress_rounds',
                        dest='num_progress_rounds',
                        help='Number of rounds to run',
                        type=int,
                        default=10000)
    parser.add_argument('--num_times',
                        dest='num_times',
                        help='Number of times to re-run experiment',
                        type=int,
                        default=1)
    parser.add_argument('--output_dir',
                        dest='output_dir',
                        type=str,
                        default='/tmp')
    args = parser.parse_args()

    count = 1
    while count <= args.num_times:

        log_fds = []
        tracer_pids = []
        cmds_to_run = []

        if args.run_in_one_tracer == "True":
            fd = os.open("/tmp/tracer_log.txt", os.O_RDWR | os.O_CREAT)
            log_fds.append(fd)
            num_tracers = 1
        else:
            if not os.path.isfile(args.cmds_to_run_file):
                print "Commands file path is incorrect !"
                sys.exit(0)
            fd1 = open(args.cmds_to_run_file, "r")
            cmds_to_run = [x.strip() for x in fd1.readlines()]
            fd1.close()
            for i in xrange(0, len(cmds_to_run)):
                with open("/tmp/tracer_log%d.txt" % (i), "w") as f:
                    pass
            log_fds = [ os.open("/tmp/tracer_log%d.txt" %(i), os.O_RDWR | os.O_CREAT ) \
                      for i in xrange(0, len(cmds_to_run)) ]
            num_tracers = len(cmds_to_run)

        print "Initializing Kronos !"
        if kf.initializeExp(1) < 0:
            print "Kronos initialization failed ! Make sure you are running\
                the dilated kernel and kronos module is loaded !"

            sys.exit(0)

        print "Starting all commands to run !"
        if args.run_in_one_tracer == "True":
            start_all_cmds_in_one_tracer(args.cmds_to_run_file, args.rel_cpu_speed,\
                args.num_insns_per_round, log_fds[0])
        else:
            for i in xrange(0, len(cmds_to_run)):
                print "Starting tracer for cmd: %s" % (cmds_to_run[i])
                start_new_dilated_process(cmds_to_run[i], args.rel_cpu_speed, \
                    args.num_insns_per_round, log_fds[i])

        print "Synchronizing anf freezing tracers ..."
        while kf.synchronizeAndFreeze(num_tracers) <= 0:
            print "Kronos >> Synchronize and Freeze failed. Retrying in 1 sec"
            time.sleep(1)

        print "Starting Synchronized Experiment !"
        kf.startExp()

        if args.num_progress_rounds > 0:
            print "Running for %d rounds ... " % (args.num_progress_rounds)

            num_finised_rounds = 0
            step_size = min(100, args.num_progress_rounds)
            start_time = float(time.time())
            kf.progress_n_rounds(args.num_progress_rounds)
            #while num_finised_rounds < args.num_progress_rounds:
            #    kf.progress_n_rounds(step_size)
            #    num_finised_rounds += step_size
            #    print "Ran %d rounds ..." %(num_finised_rounds)
        elapsed_time = float(time.time()) - start_time
        total_elapsed_virtual_time = float(
            args.num_progress_rounds * args.num_insns_per_round) / 1000000000.0
        print "Stopping Synchronized Experiment !"
        kf.stopExp()
        with open('/tmp/exp_stats.txt', 'w') as f:
            f.write('overhead ratio: %f\n' %
                    (elapsed_time / total_elapsed_virtual_time))
            f.write('total_elapsed_virtual_time: %f\n' %
                    (total_elapsed_virtual_time))
            f.write('elapsed_time: %f\n' % (elapsed_time))

        for fd in log_fds:
            os.close(fd)

        os.system('mkdir -p %s/run_%d' % (args.output_dir, count))
        os.system('cp /tmp/tracer* %s/run_%d' % (args.output_dir, count))
        os.system('cp /tmp/exp_stats.txt %s/run_%d' % (args.output_dir, count))
        print "Finished ! Logs of each ith tracer can be found in %s/run_%d" % (
            args.output_dir, count)
        count += 1