def main(directory=None):
    trace_dir = get_dir(directory)

    shutil.copyfile(ORIG_QEMU, TMP_QEMU)
    os.makedirs(trace_dir, exist_ok=True)
    vm = Qemu(disk_path=r"../vms/ubuntu-20.img",
              guest_ip="10.10.0.43",
              host_ip="10.10.0.44")
    vm.ethernet_dev = Qemu.QEMU_VIRTIO
    vm.qemu_config["latency_itr"] = 2
    vm.is_io_thread_nice = False
    vm.BOOTUP_WAIT = 15

    local_trace = Trace(localRoot, os.path.join(trace_dir, "trace_host"))
    local_trace.setup()

    local_trace.enable_event("kvm/kvm_write_tsc_offset")
    local_trace.enable_event("kvm/kvm_exit")
    local_trace.enable_event("kvm/kvm_entry")
    local_trace.enable_event("kvm/kvm_userspace_exit")

    local_trace.set_event_filter(
        "sched/sched_switch", r'prev_comm ~ "*qemu*" || next_comm ~ "*qemu*"')
    local_trace.enable_event("sched/sched_switch")

    # objdump -tT /tmp/qemu-system-x86_64 |grep .text|grep virtio_queue_notify_vq
    ## local_trace.uprobe_add("p:virtio_queue_notify_vq /tmp/qemu-system-x86_64:0x1bfba6")
    # local_trace.uprobe_add_event("p", "virtio_queue_notify_vq", TMP_QEMU, "virtio_queue_notify_vq")
    # objdump -tT /tmp/qemu-system-x86_64 |grep .text|grep kvm_vcpu_ioctl
    ## local_trace.uprobe_add("p:kvm_vcpu_ioctl /tmp/qemu-system-x86_64:0x16a886 cmd=%si")
    # local_trace.uprobe_add_event("p", "kvm_vcpu_ioctl", TMP_QEMU, "kvm_vcpu_ioctl", "cmd=%si")
    # local_trace.uprobe_enable()

    local_trace.empty_trace()
    local_trace.trace_on()
    local_trace.trace_to_local_file()

    vm.setup()
    vm.run()

    remote_trace = Trace(vm.root, os.path.join(trace_dir, "trace_guest"))
    remote_trace.setup()
    remote_trace.set_buffer_size(20000)
    remote_trace.enable_event("power/cpu_idle")
    remote_trace.enable_event("irq/irq_handler_entry")
    remote_trace.kprobe_add("p:notify_begin vp_notify")
    remote_trace.kprobe_add("r:notify_end vp_notify")
    remote_trace.kprobe_enable()
    remote_trace.trace_on()

    netperf = NetPerfLatency(None, runtime=2)
    local_trace.trace_marker(TRACE_BEGIN_MSG)
    netperf_perf = netperf.run_netperf(vm, msg_size=64)
    local_trace.trace_marker(TRACE_END_MSG)
    print("Netperf performance: %s" % (netperf_perf, ))
    logger.info("Netperf performance: %s", netperf_perf)

    remote_trace.trace_off()
    remote_trace.disable_all_events()
    local_trace.trace_off()
    local_trace.disable_all_events()

    netperf_perf = netperf.run_netperf(vm, msg_size=64)
    print("Base Netperf performance: %s" % (netperf_perf, ))
    logger.info("Base Netperf performance: %s", netperf_perf)

    remote_trace.read_trace_once(to_file=True)
    local_trace.trace_to_local_file_stop()

    local_trace.disable_all_events()

    # input()
    vm.teardown()
def main(directory=None):
    shutil.copyfile(ORIG_QEMU, TMP_QEMU)
    vm = Qemu(disk_path=r"../vms/ubuntu-20.img",
              guest_ip="10.10.0.43",
              host_ip="10.10.0.44")
    vm.ethernet_dev = Qemu.QEMU_VIRTIO
    # vm.qemu_config["latency_itr"] = 2

    local_trace = Trace(localRoot, "/tmp/trace_host")
    local_trace.setup()

    local_trace.enable_event("kvm/kvm_write_tsc_offset")
    local_trace.enable_event("kvm/kvm_exit")
    local_trace.enable_event("kvm/kvm_entry")
    local_trace.enable_event("kvm/kvm_userspace_exit")

    local_trace.set_event_filter(
        "sched/sched_switch", r'prev_comm ~ "*qemu*" || next_comm ~ "*qemu*"')
    local_trace.enable_event("sched/sched_switch")

    # objdump -tT /tmp/qemu-system-x86_64 |grep .text|grep virtio_queue_notify_vq
    # local_trace.uprobe_add("p:virtio_queue_notify_vq /tmp/qemu-system-x86_64:0x1bfba6")
    local_trace.uprobe_add_event("p", "virtio_queue_notify_vq", TMP_QEMU,
                                 "virtio_queue_notify_vq")
    # objdump -tT /tmp/qemu-system-x86_64 |grep .text|grep kvm_vcpu_ioctl
    # local_trace.uprobe_add("p:kvm_vcpu_ioctl /tmp/qemu-system-x86_64:0x16a886 cmd=%si")
    local_trace.uprobe_add_event("p", "kvm_vcpu_ioctl", TMP_QEMU,
                                 "kvm_vcpu_ioctl", "cmd=%si")
    local_trace.uprobe_enable()

    local_trace.empty_trace()
    local_trace.trace_on()
    local_trace.trace_to_local_file()

    vm.setup()
    vm.run()

    remote_trace = Trace(vm.root, "/tmp/trace_guest")
    remote_trace.setup()
    remote_trace.kprobe_add("p:notify_begin vp_notify")
    remote_trace.kprobe_add("r:notify_end vp_notify")
    remote_trace.kprobe_enable()
    remote_trace.trace_on()

    netperf = NetPerfLatency(None, runtime=2)
    netperf_perf = netperf.run_netperf(vm, msg_size=64)
    print("Netperf performance: %s" % (netperf_perf, ))
    logger.info("Netperf performance: %s", netperf_perf)

    remote_trace.trace_off()
    remote_trace.disable_all_events()
    local_trace.trace_off()
    local_trace.disable_all_events()

    netperf_perf = netperf.run_netperf(vm, msg_size=64)
    print("Netperf performance: %s" % (netperf_perf, ))
    logger.info("Netperf performance: %s", netperf_perf)

    remote_trace.read_trace_once(to_file=True)
    local_trace.trace_to_local_file_stop()

    local_trace.disable_all_events()

    # input()
    vm.teardown()

    if directory:
        os.makedirs(directory, exist_ok=True)
        shutil.copy("/tmp/trace_guest", directory)
        shutil.copy("/tmp/trace_host", directory)
Exemplo n.º 3
0
class TracePerformance:
    def __init__(self,
                 vm: VM,
                 directory=None,
                 netperf=None,
                 msg_size=64,
                 title="",
                 auto_dir=False,
                 name=None):
        self._vm = vm
        if directory:
            self._dir = directory
        else:
            self._dir = TMP_DIR

        if auto_dir:
            self._dir = os.path.join(
                self._dir, "{name}-{size}".format(name=self._vm.name,
                                                  size=msg_size))
            if name:
                self._dir += "-{name}".format(name=name)

        logger.info("Dir: %s", self._dir)

        if netperf:
            self._netperf = netperf
        else:
            self._netperf = NetPerfLatency()
        self._msg_size = msg_size
        self._title = title

        # vm.netserver_core = "2"
        self.trace_parser = None

        self._host_tracer = None
        self._guest_tracer = None

        self._old_cpumask = ""

    def init_env(self, delete=False):
        if delete:
            if os.path.exists(self._dir):
                shutil.rmtree(self._dir, ignore_errors=True)

        os.makedirs(self._dir, exist_ok=True)

        if ORIG_QEMU != TMP_QEMU:
            shutil.copyfile(ORIG_QEMU, TMP_QEMU)
        root_logger = logging.getLogger()
        root_logger.addHandler(
            logging.FileHandler(os.path.join(self._dir, "log")))

        self.trace_parser = Traces(self._dir)

    def host_traces(self):
        assert self._host_tracer is None

        self._host_tracer = Trace(localRoot,
                                  os.path.join(self._dir, "trace_host"))
        self._host_tracer.setup()
        self._host_tracer.set_buffer_size(2000000)
        sleep(1)

        # if self._vm.cpu_to_pin:
        #     self._host_tracer.write_value("tracing_cpumask", str(1 << (int(self._vm.cpu_to_pin))))

        # clock sync with VM
        self._host_tracer.enable_event("kvm/kvm_write_tsc_offset")

        # interrupts
        # self._host_tracer.enable_event("kvm/kvm_set_irq")
        # self._host_tracer.enable_event("kvm/kvm_msi_set_irq")
        # self._host_tracer.enable_event("kvm/kvm_inj_virq")
        # self._host_tracer.enable_event("kvm/kvm_ioapic_set_irq")

        # exit events
        self._host_tracer.enable_event("kvm/kvm_exit")
        self._host_tracer.enable_event("kvm/kvm_entry")
        # self._host_tracer.enable_event("kvm/kvm_userspace_exit")
        self._host_tracer.enable_event("kvm/kvm_mmio")
        self._host_tracer.enable_event("kvm/kvm_msr")

        # sched
        self._host_tracer.set_event_filter(
            "sched/sched_switch",
            r'prev_comm ~ "*qemu*" || next_comm ~ "*qemu*"')
        self._host_tracer.enable_event("sched/sched_switch")

        # self._host_tracer.set_event_filter("sched/sched_wakeup", r'comm~"*qemu*"')
        # self._host_tracer.enable_event("sched/sched_wakeup")

        # self._host_tracer.set_event_filter("sched/sched_waking", r'comm~"*qemu*"')
        # self._host_tracer.enable_event("sched/sched_waking")
        # self._host_tracer.uprobe_add_event("p", "e1000_set_kick", self._vm.exe, "e1000_set_kick")
        # self._host_tracer.uprobe_add_event("p", "e1000_kick_cb", self._vm.exe, "e1000_kick_cb")
        # self._host_tracer.uprobe_add_event("p", "qemu_mutex_lock_iothread", self._vm.exe, "qemu_mutex_lock_iothread")
        # self._host_tracer.uprobe_add_event("r", "qemu_mutex_lock_iothread_end", self._vm.exe, "qemu_mutex_lock_iothread")
        # self._host_tracer.uprobe_add_event("p", "qemu_mutex_unlock_iothread", self._vm.exe, "qemu_mutex_unlock_iothread")
        # self._host_tracer.uprobe_add_event("r", "qemu_mutex_unlock_iothread_end", self._vm.exe, "qemu_mutex_unlock_iothread")
        self._host_tracer.enable_event("irq/irq_handler_entry")
        self._host_tracer.enable_event("irq/irq_handler_exit")
        self._host_tracer.enable_event("irq_vectors")

        self._host_tracer.enable_event("syscalls")

        # self._host_tracer.kprobe_add("p:import_iovec import_iovec")
        # self._host_tracer.kprobe_add("r:import_iovec_end import_iovec")
        # self._host_tracer.kprobe_add("p:tun_get_user tun_get_user")
        # self._host_tracer.kprobe_add("r:tun_get_user_end tun_get_user")
        #
        # self._host_tracer.kprobe_add("p:netif_receive_skb netif_receive_skb")
        # self._host_tracer.kprobe_add("r:netif_receive_skb_end netif_receive_skb")
        # # self._host_tracer.enable_event("net/netif_receive_skb")
        # # self._host_tracer.enable_event("net/netif_receive_skb_entry")
        # # self._host_tracer.enable_event("net/netif_rx_ni_entry")

        self._host_tracer.kprobe_enable()
        self._host_tracer.uprobe_enable()
        self._host_tracer.empty_trace()
        self._host_tracer.trace_on()

    def guest_traces(self):
        assert self._guest_tracer is None

        self._guest_tracer = Trace(self._vm.root,
                                   os.path.join(self._dir, "trace_guest"))
        self._guest_tracer.setup()
        self._guest_tracer.set_buffer_size(600000)

        self._guest_tracer.enable_event("power/cpu_idle")
        self._guest_tracer.enable_event("syscalls/sys_enter_sendto")
        # self._guest_tracer.enable_event("syscalls/sys_enter_recvfrom")
        self._guest_tracer.enable_event("syscalls/sys_exit_recvfrom")

        #sched
        self._guest_tracer.set_event_filter(
            "sched/sched_switch",
            r'prev_comm ~ "*netperf*" || next_comm ~ "*netperf*"')
        self._guest_tracer.enable_event("sched/sched_switch")

        # net
        self._guest_tracer.enable_event("net/net_dev_start_xmit")
        self._guest_tracer.enable_event("net/net_dev_xmit")
        self._guest_tracer.enable_event("net/net_dev_recv_start")
        self._guest_tracer.enable_event("net/net_dev_recv_end")

        self._guest_tracer.enable_event("net/net_exit_before")
        self._guest_tracer.enable_event("net/net_exit_after")

        # irq
        self._guest_tracer.enable_event("irq/irq_handler_entry")
        self._guest_tracer.enable_event("irq/irq_handler_exit")
        self._host_tracer.enable_event("irq_vectors")

        self._guest_tracer.enable_event("napi")

        # self._guest_tracer.enable_event("tcp/tcp_xmit_break")

        self._guest_tracer.kprobe_add("p:recv_start virtnet_receive")
        self._guest_tracer.kprobe_add("r:recv_end virtnet_receive")

        self._guest_tracer.kprobe_add("p:recv_start e1000_clean_rx_irq")
        self._guest_tracer.kprobe_add("r:recv_end e1000_clean_rx_irq")

        self._guest_tracer.kprobe_add("p:napi_receive_start napi_gro_receive")
        self._guest_tracer.kprobe_add("r:napi_receive_end napi_gro_receive")

        self._guest_tracer.kprobe_add(
            "p:e1000_update_stats e1000_update_stats")
        self._guest_tracer.kprobe_add(
            "r:e1000_update_stats_end e1000_update_stats")

        # recieve checksum validation
        self._guest_tracer.kprobe_add("p:dev_gro_receive dev_gro_receive")
        self._guest_tracer.kprobe_add("r:dev_gro_receive_end dev_gro_receive")

        # tcp stack boundries
        self._guest_tracer.kprobe_add(
            "p:netif_receive_skb_internal netif_receive_skb_internal")
        self._guest_tracer.kprobe_add(
            "r:netif_receive_skb_internal_end netif_receive_skb_internal")
        self._guest_tracer.kprobe_add(
            "p:dev_hard_start_xmit dev_hard_start_xmit")
        self._guest_tracer.kprobe_add(
            "r:dev_hard_start_xmit_end dev_hard_start_xmit")

        # self._guest_tracer.kprobe_add("p:ip_rcv_finish ip_rcv_finish")
        # self._guest_tracer.kprobe_add("r:ip_rcv_finish_end ip_rcv_finish")
        # self._guest_tracer.kprobe_add("p:tcp_write_xmit tcp_write_xmit")
        # self._guest_tracer.kprobe_add("r:tcp_write_xmit_end tcp_write_xmit")
        #
        # self._guest_tracer.kprobe_add("p:dev_queue_xmit dev_queue_xmit")
        # self._guest_tracer.kprobe_add("r:dev_queue_xmit_end dev_queue_xmit")
        #
        # self._guest_tracer.kprobe_add("p:tcp_v4_rcv tcp_v4_rcv")
        # self._guest_tracer.kprobe_add("r:tcp_v4_rcv_end tcp_v4_rcv")
        #
        # for n in ("tcp_v4_do_rcv", "tcp_rcv_established", "__tcp_push_pending_frames", "tcp_write_xmit"):
        #     self._guest_tracer.kprobe_add("p:{name} {name}".format(name=n))
        #     self._guest_tracer.kprobe_add("r:{name}_end {name}".format(name=n))

        # self._guest_tracer.kprobe_add("p:validate_xmit_skb_list validate_xmit_skb_list")
        # self._guest_tracer.kprobe_add("r:validate_xmit_skb_list_end validate_xmit_skb_list")

        # self._guest_tracer.kprobe_add("p:tcp_ack tcp_ack")
        # self._guest_tracer.kprobe_add("r:tcp_ack_end tcp_ack")

        # self._guest_tracer.write_value("current_tracer", "function_graph")
        # self._guest_tracer.write_value("set_graph_function", "netif_receive_skb_internal")

        self._guest_tracer.kprobe_enable()
        self._guest_tracer.uprobe_enable()

        self._guest_tracer.empty_trace()
        self._guest_tracer.trace_on()

    def run_netperf(self, runtime=None):
        self._host_tracer.trace_marker(TRACE_BEGIN_MSG, cpu=2)
        if runtime is not None:
            self._netperf.runtime = runtime
        netperf_perf = self._netperf.run_netperf(self._vm,
                                                 msg_size=self._msg_size)
        self._host_tracer.trace_marker(TRACE_END_MSG, cpu=2)
        print("Netperf performance: %s" % (netperf_perf, ))
        logger.info("Netperf performance: %s", netperf_perf)

    def copy_maps(self):
        try:
            os.unlink(os.path.join(self._dir, "maps"))
        except:
            pass
        shutil.copy("/proc/{}/maps".format(self._vm.get_pid()),
                    os.path.join(self._dir, "maps"))

    def merge_traces(self):
        logger.info("Merging traces")
        self.trace_parser.parse()
        self.trace_parser.write_to_file(self._dir, True)

    def run(self):

        try:
            self._vm.setup()
            self.host_traces()
            self._vm.run()
            self.guest_traces()
            self.run_netperf()
            self._host_tracer.trace_off()
            self._guest_tracer.trace_off()

            logger.info("Test again without traces:")
            self.run_netperf(10)
            self.run_netperf(10)
            self.run_netperf(10)

        finally:
            try:
                self._guest_tracer.read_trace_once(to_file=True)
                self._host_tracer.read_trace_once(to_file=True, cpu="2")
                # self._host_tracer.read_trace_once(to_file=True, filename=os.path.join(self._dir, "full_trace"))
                self._host_tracer.set_buffer_size(1000)
            except:
                import traceback
                traceback.print_exc()
            self.copy_maps()
            self._vm.teardown()
            try:
                self._host_tracer.disable_all_events()
            except:
                pass

        self.merge_traces()

    def stats(self):
        new_stats = MainStats(self.trace_parser,
                              os.path.join(self._dir, "new"),
                              size=self._msg_size)
        os.makedirs(os.path.join(self._dir, "new"), exist_ok=True)
        # new_stats.attr = "time_median"
        new_stats.attr = "time_avg"
        new_stats.run(new_stats.TYP_VIRTIO if "virtio" in
                      self._vm.name else new_stats.TYP_E1000)
Exemplo n.º 4
0
def main(directory=None):
    trace_dir = get_dir(directory)

    if ORIG_QEMU != TMP_QEMU:
        shutil.copyfile(ORIG_QEMU, TMP_QEMU)
    os.makedirs(trace_dir, exist_ok=True)

    netserver_start()
    # vm = QemuE1000NG(disk_path=r"../vms/ubuntu-20.img",
    #                  guest_ip="10.10.0.43",
    #                  host_ip="10.10.0.44")
    # vm.netperf_test_params = "-C"
    # vm.kernel_cmdline_additional = "e1000.NG_flags=1" # skb_orphan
    # vm.e1000_options["NG_interrupt_mode"] = 2
    # vm.large_queue = True
    # vm.queue_size = 1024*4
    # vm.e1000_options["NG_parabatch"] = "on"
    # vm.e1000_options["NG_interrupt_mode"] = 1
    # vm.e1000_options["NG_interrupt_mul"] = 1
    # vm.e1000_options["NG_disable_iothread_lock"] = "on"
    vm = create_vm_e1000_halt_no_rdt()

    # para halt mode
    # vm.e1000_options["NG_parahalt"] = "on"
    # # vm.e1000_options["NG_disable_iothread_lock"] = "on"
    # # vm.e1000_options["NG_tx_iothread"]z = "off"
    # vm.e1000_options["NG_interrupt_mode"] = 0
    # vm.e1000_options["NG_interrupt_mul"] = 0
    # vm.e1000_options["mitigation"] = "off"
    # vm.large_queue = True
    # vm.queue_size = 512

    # vm.ethernet_dev = 'e1000-82545em'
    # vm.addiotional_guest_command = 'sudo ethtool -C eth0 rx-usecs 3000'

    local_trace = Trace(localRoot, os.path.join(trace_dir, "trace_host"))
    local_trace.setup()
    local_trace.set_buffer_size(1000000)

    local_trace.enable_event("kvm/kvm_write_tsc_offset")
    local_trace.enable_event("kvm/kvm_set_irq")
    local_trace.enable_event("kvm/kvm_msi_set_irq")
    local_trace.enable_event("kvm/kvm_inj_virq")
    local_trace.enable_event("kvm/kvm_ioapic_set_irq")
    local_trace.enable_event("kvm/kvm_exit")
    local_trace.enable_event("kvm/kvm_entry")
    local_trace.enable_event("kvm/kvm_userspace_exit")
    local_trace.enable_event("kvm/kvm_mmio")

    local_trace.set_event_filter(
        "sched/sched_switch", r'prev_comm ~ "*qemu*" || next_comm ~ "*qemu*"')
    local_trace.enable_event("sched/sched_switch")

    local_trace.set_event_filter("sched/sched_wakeup", r'comm~"*qemu*"')
    local_trace.enable_event("sched/sched_wakeup")

    local_trace.set_event_filter("sched/sched_waking", r'comm~"*qemu*"')
    local_trace.enable_event("sched/sched_waking")

    # objdump -tT /tmp/qemu-system-x86_64 |grep .text|grep virtio_queue_notify_vq
    ## local_trace.uprobe_add("p:virtio_queue_notify_vq /tmp/qemu-system-x86_64:0x1bfba6")
    # local_trace.uprobe_add_event("p", "virtio_queue_notify_vq", TMP_QEMU, "virtio_queue_notify_vq")
    # objdump -tT /tmp/qemu-system-x86_64 |grep .text|grep kvm_vcpu_ioctl
    ## local_trace.uprobe_add("p:kvm_vcpu_ioctl /tmp/qemu-system-x86_64:0x16a886 cmd=%si")
    # local_trace.uprobe_add_event("p", "kvm_vcpu_ioctl", TMP_QEMU, "kvm_vcpu_ioctl", "cmd=%si")
    local_trace.uprobe_add_event("p", "tap_write_packet", TMP_QEMU,
                                 "tap_write_packet")
    local_trace.uprobe_add_event("p", "e1000_set_kick", TMP_QEMU,
                                 "e1000_set_kick")
    local_trace.uprobe_add_event("r", "e1000_set_kick_end", TMP_QEMU,
                                 "e1000_set_kick")
    local_trace.uprobe_add_event(
        "p", "e1000_receive_batch_finished", TMP_QEMU,
        "e1000_receive_batch_finished",
        "packets=%si interrupt_packets=+209052\(%di\):u32")
    local_trace.uprobe_add_event("r", "tap_recv_packets_end", TMP_QEMU,
                                 "tap_send")
    local_trace.uprobe_add_event("p", "tap_recv_packets", TMP_QEMU, "tap_send")

    local_trace.uprobe_add_event("r",
                                 "all_cpu_idle_end",
                                 TMP_QEMU,
                                 "all_cpu_threads_idle_ex",
                                 misc=r"result=\$retval")
    local_trace.uprobe_add_event("p", "all_cpu_idle", TMP_QEMU,
                                 "all_cpu_threads_idle_ex")
    # local_trace.uprobe_add_event("p", "qemu_bh_schedule", TMP_QEMU, "qemu_bh_schedule")
    local_trace.uprobe_add_event("p", "set_tctl", TMP_QEMU, "set_tctl")
    local_trace.uprobe_add_event("p", "e1000_mit_timer", TMP_QEMU,
                                 "e1000_mit_timer")

    # local_trace.uprobe_add_event("p", "qemu_clock_run_all_timers", TMP_QEMU, "qemu_clock_run_all_timers")
    # local_trace.uprobe_add_event("r", "qemu_clock_run_all_timers_end", TMP_QEMU, "qemu_clock_run_all_timers", misc=r"result=\$retval")
    # local_trace.uprobe_add_event("r", "timerlistgroup_deadline_ns", TMP_QEMU, "timerlistgroup_deadline_ns", misc=r"result=\$retval")
    # local_trace.uprobe_add_event("r", "os_host_main_loop_wait", TMP_QEMU, "os_host_main_loop_wait", misc=r"result=\$retval")
    local_trace.uprobe_add_event("p", "aio_bh_call", TMP_QEMU, "aio_bh_call")
    local_trace.uprobe_add_event("p", "e1000_net_bh_tx", TMP_QEMU,
                                 "e1000_net_bh_tx")
    local_trace.uprobe_add_event("p", "qemu_bh_schedule", TMP_QEMU,
                                 "qemu_bh_schedule")
    local_trace.uprobe_add_event("r", "qemu_bh_schedule_end", TMP_QEMU,
                                 "qemu_bh_schedule")
    local_trace.uprobe_add_event("p", "event_notifier_set", TMP_QEMU,
                                 "event_notifier_set")
    local_trace.uprobe_add_event("r", "event_notifier_set_end", TMP_QEMU,
                                 "event_notifier_set")
    local_trace.uprobe_add_event("p", "notify_event_cb", TMP_QEMU,
                                 "notify_event_cb")
    local_trace.uprobe_add_event("p", "event_notifier_test_and_clear",
                                 TMP_QEMU, "event_notifier_test_and_clear")
    local_trace.uprobe_add_event("p", "aio_notify", TMP_QEMU, "aio_notify")
    local_trace.uprobe_add_event("r", "aio_notify_end", TMP_QEMU, "aio_notify")

    # local_trace.uprobe_add_event("p", "e1000_mmio_write", TMP_QEMU, "e1000_mmio_write")
    local_trace.uprobe_enable()

    local_trace.empty_trace()
    local_trace.trace_on()
    # local_trace.trace_to_local_file()

    vm.setup()
    vm.run()
    local_trace.set_event_filter("syscalls",
                                 r'common_pid=={}'.format(vm.get_pid()))
    local_trace.enable_event("syscalls")

    remote_trace = Trace(vm.root, os.path.join(trace_dir, "trace_guest"))
    remote_trace.setup()
    remote_trace.set_buffer_size(200000)
    remote_trace.enable_event("tcp")
    remote_trace.enable_event("net")
    remote_trace.enable_event("irq")
    remote_trace.enable_event("irq_vectors")
    remote_trace.enable_event("napi")
    remote_trace.enable_event("power/cpu_idle")
    remote_trace.enable_event("syscalls/sys_enter_sendto")
    remote_trace.enable_event("syscalls/sys_enter_recvfrom")
    # remote_trace.enable_event("irq/irq_handler_entry")
    # remote_trace.enable_event("e1000/e1000_pre_mem_op")
    # remote_trace.enable_event("e1000/e1000_post_mem_op")
    # remote_trace.enable_event("e1000/e1000_set_tdt")
    # remote_trace.enable_event("e1000/e1000_post_set_tdt")
    # remote_trace.kprobe_add("p:notify_begin vp_notify")
    # remote_trace.kprobe_add("r:notify_end vp_notify")
    remote_trace.kprobe_add("p:e1000_clean e1000_clean")
    remote_trace.kprobe_add("p:e1000_kick e1000_qemu_kick")
    remote_trace.kprobe_add("p:e1000_kick_halt e1000_halt_kick")
    remote_trace.kprobe_enable()

    # netperf = NetPerfTCP(None, runtime=15)
    netperf = NetPerfLatency(None, runtime=15)
    # netperf_perf = netperf.run_netperf(vm, msg_size="64K")
    # print("Netperf performance: %s" % (netperf_perf, ))
    # logger.info("Netperf performance: %s", netperf_perf)
    # input("Press Enter to start tracing")

    remote_trace.trace_on()

    run_command_async("tcpdump -i tap0 -s 100 -w {} -W 1 -G 7".format(
        os.path.join(trace_dir, "e1000.cap")))
    remote_trace.trace_marker(TRACE_BEGIN_MSG)
    netperf.runtime = 3
    netperf_perf = netperf.run_netperf(vm, msg_size=MSG_SIZE)
    remote_trace.trace_marker(TRACE_END_MSG)
    print("Netperf performance: %s" % (netperf_perf, ))
    logger.info("Netperf performance: %s", netperf_perf)

    remote_trace.trace_off()
    remote_trace.disable_all_events()
    local_trace.trace_off()
    local_trace.disable_all_events()

    netperf.runtime = 15
    netperf_perf = netperf.run_netperf(vm, msg_size=MSG_SIZE)
    print("Base Netperf performance: %s" % (netperf_perf, ))
    logger.info("Base Netperf performance: %s", netperf_perf)

    local_trace.read_trace_once(to_file=True)
    remote_trace.read_trace_once(to_file=True)
    # local_trace.trace_to_local_file_stop()

    local_trace.disable_all_events()

    try:
        os.unlink(os.path.join(trace_dir, "maps"))
    except:
        pass
    shutil.copy("/proc/{}/maps".format(vm.get_pid()),
                os.path.join(trace_dir, "maps"))

    # input()

    vm.teardown()
    netserver_stop()
def main(directory=None):
    shutil.copyfile(ORIG_QEMU, TMP_QEMU)
    vm = QemuE1000Max(disk_path=r"../vms/ubuntu-20.img",
                                   guest_ip="10.10.0.43",
                                   host_ip="10.10.0.44")
    vm.qemu_config["latency_itr"] = 2
    vm.ethernet_dev = 'e1000-82545em'
    vm.addiotional_guest_command = 'sudo ethtool -C eth0 rx-usecs 3000'

    local_trace = Trace(localRoot, "/tmp/trace_host")
    local_trace.setup()

    local_trace.enable_event("kvm/kvm_write_tsc_offset")
    local_trace.enable_event("kvm/kvm_exit")
    local_trace.enable_event("kvm/kvm_entry")
    local_trace.enable_event("kvm/kvm_userspace_exit")

    local_trace.set_event_filter("sched/sched_switch", r'prev_comm ~ "*qemu*" || next_comm ~ "*qemu*"')
    local_trace.enable_event("sched/sched_switch")

    local_trace.uprobe_add_event("p", "set_tctl", TMP_QEMU, "set_tctl")
    local_trace.uprobe_add_event("p", "kvm_vcpu_ioctl", TMP_QEMU, "kvm_vcpu_ioctl", "cmd=%si")
    local_trace.uprobe_enable()

    local_trace.empty_trace()
    local_trace.trace_on()
    local_trace.trace_to_local_file()

    vm.setup()
    vm.run()

    remote_trace = Trace(vm.root, "/tmp/trace_guest")
    remote_trace.setup()
    # remote_trace.kprobe_add("p:e1000_tdt_begin e1000_tx_queue")
    remote_trace.enable_event("e1000/e1000_set_tdt")
    # remote_trace.kprobe_add("r:e1000_tdt_end e1000_tx_queue")
    remote_trace.enable_event("e1000/e1000_post_set_tdt")
    remote_trace.kprobe_add("p:e1000_intr e1000_intr")
    remote_trace.kprobe_enable()
    remote_trace.trace_on()

    netperf = NetPerfLatency(None, runtime=2)
    netperf_perf = netperf.run_netperf(vm, msg_size=64)
    print("Netperf performance: %s" % (netperf_perf, ))
    logger.info("Netperf performance: %s", netperf_perf)

    remote_trace.trace_off()
    remote_trace.disable_all_events()
    local_trace.trace_off()
    local_trace.disable_all_events()

    netperf_perf = netperf.run_netperf(vm, msg_size=64)
    print("Netperf performance: %s" % (netperf_perf,))
    logger.info("Netperf performance: %s", netperf_perf)

    remote_trace.read_trace_once(to_file=True)
    local_trace.trace_to_local_file_stop()

    local_trace.disable_all_events()

    # input()
    vm.teardown()

    if directory:
        os.makedirs(directory, exist_ok=True)
        shutil.copy("/tmp/trace_guest", directory)
        shutil.copy("/tmp/trace_host", directory)
Exemplo n.º 6
0
def main(directory=None, netperf_msg_size=None):
    trace_dir = get_dir(directory)

    if netperf_msg_size is None:
        netperf_msg_size = MSG_SIZE

    if ORIG_QEMU != TMP_QEMU:
        shutil.copyfile(ORIG_QEMU, TMP_QEMU)
    os.makedirs(trace_dir, exist_ok=True)

    netserver_start()
    logger.info("msg size = %s", netperf_msg_size)

    vm = QemuNG(disk_path=r"../vms/ubuntu-20.img",
                guest_ip="10.10.0.43",
                host_ip="10.10.0.44")
    vm.ethernet_dev = Qemu.QEMU_VIRTIO
    vm.e1000_options["NG_notify_batch"] = "on"
    vm.BOOTUP_WAIT = 15

    local_trace = Trace(localRoot, os.path.join(trace_dir, "trace_host"))
    local_trace.setup()
    local_trace.set_buffer_size(100000)

    local_trace.enable_event("kvm/kvm_write_tsc_offset")
    local_trace.enable_event("kvm/kvm_set_irq")
    local_trace.enable_event("kvm/kvm_msi_set_irq")
    local_trace.enable_event("kvm/kvm_inj_virq")
    local_trace.enable_event("kvm/kvm_ioapic_set_irq")
    local_trace.enable_event("kvm/kvm_exit")
    local_trace.enable_event("kvm/kvm_entry")
    local_trace.enable_event("kvm/kvm_userspace_exit")
    local_trace.enable_event("kvm")

    local_trace.set_event_filter(
        "sched/sched_switch", r'prev_comm ~ "*qemu*" || next_comm ~ "*qemu*"')
    local_trace.enable_event("sched/sched_switch")

    local_trace.set_event_filter("sched/sched_wakeup", '\"comm~*qemu*\"')
    local_trace.enable_event("sched/sched_wakeup")

    local_trace.set_event_filter("sched/sched_waking", '\"comm~*qemu*\"')
    local_trace.enable_event("sched/sched_waking")

    # objdump -tT /tmp/qemu-system-x86_64 |grep .text|grep virtio_queue_notify_vq
    ## local_trace.uprobe_add("p:virtio_queue_notify_vq /tmp/qemu-system-x86_64:0x1bfba6")
    # local_trace.uprobe_add_event("p", "virtio_queue_notify_vq", TMP_QEMU, "virtio_queue_notify_vq")
    # objdump -tT /tmp/qemu-system-x86_64 |grep .text|grep kvm_vcpu_ioctl
    ## local_trace.uprobe_add("p:kvm_vcpu_ioctl /tmp/qemu-system-x86_64:0x16a886 cmd=%si")
    # local_trace.uprobe_add_event("p", "kvm_vcpu_ioctl", TMP_QEMU, "kvm_vcpu_ioctl", "cmd=%si")

    local_trace.uprobe_add_event("p", "tap_write_packet", TMP_QEMU,
                                 "tap_write_packet")
    local_trace.uprobe_add_event("p", "tap_recv_packets", TMP_QEMU, "tap_send")
    local_trace.uprobe_add_event("r", "tap_recv_packets_end", TMP_QEMU,
                                 "tap_send")
    local_trace.uprobe_add_event("p", "virtio_irq", TMP_QEMU, "virtio_irq")

    # local_trace.uprobe_add_event("p", "virtio_queue_notify_vq", TMP_QEMU, "virtio_queue_notify_vq")
    # local_trace.uprobe_add_event("p", "e1000_set_kick", TMP_QEMU, "e1000_set_kick")
    # local_trace.uprobe_add_event("p", "e1000_receive_batch_finished", TMP_QEMU, "e1000_receive_batch_finished")
    local_trace.uprobe_enable()

    local_trace.empty_trace()
    local_trace.trace_on()
    # local_trace.trace_to_local_file()

    vm.setup()
    vm.run()

    remote_trace = Trace(vm.root, os.path.join(trace_dir, "trace_guest"))
    remote_trace.setup()
    remote_trace.set_buffer_size(100000)
    remote_trace.enable_event("tcp")
    remote_trace.enable_event("net")
    remote_trace.enable_event("irq")
    remote_trace.enable_event("irq_vectors")
    remote_trace.enable_event("napi")
    remote_trace.enable_event("power/cpu_idle")
    remote_trace.enable_event("syscalls/sys_enter_sendto")
    remote_trace.enable_event("syscalls/sys_enter_recvfrom")
    remote_trace.enable_event("net/net_dev_xmit")

    # remote_trace.enable_event("irq/irq_handler_entry")
    # remote_trace.enable_event("e1000/e1000_pre_mem_op")
    # remote_trace.enable_event("e1000/e1000_post_mem_op")
    # remote_trace.enable_event("e1000/e1000_set_tdt")
    # remote_trace.enable_event("e1000/e1000_post_set_tdt")

    remote_trace.kprobe_add("p:notify_begin virtqueue_kick")
    remote_trace.kprobe_add("r:notify_end virtqueue_kick")

    # remote_trace.kprobe_enable()
    remote_trace.trace_on()

    netperf = NetPerfTCP(None, runtime=2)
    run_command_async("tcpdump -i tap0 -s 100 -w {} -W 1 -G 7".format(
        os.path.join(trace_dir, "virtio.cap")))
    remote_trace.trace_marker(TRACE_BEGIN_MSG)
    netperf_perf = netperf.run_netperf(vm, msg_size=netperf_msg_size)
    remote_trace.trace_marker(TRACE_END_MSG)
    print("Netperf performance: %s" % (netperf_perf, ))
    logger.info("Netperf performance: %s", netperf_perf)

    remote_trace.trace_off()
    remote_trace.disable_all_events()
    local_trace.trace_off()
    local_trace.disable_all_events()

    netperf_perf = netperf.run_netperf(vm, msg_size=netperf_msg_size)
    print("Base Netperf performance: %s" % (netperf_perf, ))
    logger.info("Base Netperf performance: %s", netperf_perf)

    local_trace.read_trace_once(to_file=True)
    remote_trace.read_trace_once(to_file=True)
    # local_trace.trace_to_local_file_stop()

    local_trace.disable_all_events()

    # input("Press Enter to exit")
    vm.teardown()
    netserver_stop()
def main(directory=None):
    trace_dir = get_dir(directory)

    if ORIG_QEMU != TMP_QEMU:
        shutil.copyfile(ORIG_QEMU, TMP_QEMU)
    os.makedirs(trace_dir, exist_ok=True)

    netserver_start()
    vm = QemuE1000NG(disk_path=r"../vms/ubuntu-20.img",
                     guest_ip="10.10.0.43",
                     host_ip="10.10.0.44")
    # vm.netperf_test_params = "-C"
    # vm.large_queue = True
    # vm.queue_size = 1024*4
    # vm.e1000_options["NG_parabatch"] = "on"
    vm.e1000_options["NG_interrupt_mode"] = 3
    vm.kernel_cmdline_additional = "e1000.NG_flags=1"
    vm.is_io_thread_nice = False
    vm.bootwait = 10
    vm.e1000_options["NG_interrupt_min"] = 900

    local_trace = Trace(localRoot, os.path.join(trace_dir, "trace_host"))
    local_trace.setup()
    local_trace.set_buffer_size(100000)

    local_trace.enable_event("kvm/kvm_write_tsc_offset")
    local_trace.enable_event("kvm/kvm_set_irq")
    local_trace.enable_event("kvm/kvm_msi_set_irq")
    local_trace.enable_event("kvm/kvm_inj_virq")
    local_trace.enable_event("kvm/kvm_ioapic_set_irq")
    local_trace.enable_event("kvm/kvm_exit")
    local_trace.enable_event("kvm/kvm_entry")
    local_trace.enable_event("kvm/kvm_userspace_exit")

    local_trace.set_event_filter("sched/sched_switch", r'prev_comm ~ "*qemu*" || next_comm ~ "*qemu*"')
    local_trace.enable_event("sched/sched_switch")

    # objdump -tT /tmp/qemu-system-x86_64 |grep .text|grep virtio_queue_notify_vq
    ## local_trace.uprobe_add("p:virtio_queue_notify_vq /tmp/qemu-system-x86_64:0x1bfba6")
    # local_trace.uprobe_add_event("p", "virtio_queue_notify_vq", TMP_QEMU, "virtio_queue_notify_vq")
    # objdump -tT /tmp/qemu-system-x86_64 |grep .text|grep kvm_vcpu_ioctl
    ## local_trace.uprobe_add("p:kvm_vcpu_ioctl /tmp/qemu-system-x86_64:0x16a886 cmd=%si")
    # local_trace.uprobe_add_event("p", "kvm_vcpu_ioctl", TMP_QEMU, "kvm_vcpu_ioctl", "cmd=%si")
    local_trace.uprobe_add_event("p", "tap_write_packet", TMP_QEMU, "tap_write_packet")
    local_trace.uprobe_add_event("p", "e1000_set_kick", TMP_QEMU, "e1000_set_kick")
    local_trace.uprobe_add_event("p", "e1000_receive_batch_finished", TMP_QEMU, "e1000_receive_batch_finished",
                                 "packets=%si interrupt_packets=+209052\(%di\):u32")
    local_trace.uprobe_add_event("r", "tap_recv_packets_end", TMP_QEMU, "tap_send")
    local_trace.uprobe_add_event("p", "tap_recv_packets", TMP_QEMU, "tap_send")

    local_trace.uprobe_add_event("r", "all_cpu_idle_end", TMP_QEMU, "all_cpu_threads_idle_ex", misc=r"result=\$retval")
    local_trace.uprobe_add_event("p", "all_cpu_idle", TMP_QEMU, "all_cpu_threads_idle_ex")
    # local_trace.uprobe_add_event("p", "e1000_mmio_write", TMP_QEMU, "e1000_mmio_write")
    local_trace.uprobe_enable()

    local_trace.empty_trace()
    local_trace.trace_on()
    # local_trace.trace_to_local_file()

    vm.setup()
    vm.run()

    remote_trace = Trace(vm.root, os.path.join(trace_dir, "trace_guest"))
    remote_trace.setup()
    remote_trace.set_buffer_size(100000)
    remote_trace.enable_event("tcp")
    remote_trace.enable_event("net")
    remote_trace.enable_event("irq")
    remote_trace.enable_event("irq_vectors")
    remote_trace.enable_event("napi")
    remote_trace.enable_event("power/cpu_idle")
    remote_trace.enable_event("syscalls/sys_enter_sendto")
    remote_trace.enable_event("syscalls/sys_enter_recvfrom")
    # remote_trace.enable_event("irq/irq_handler_entry")
    # remote_trace.enable_event("e1000/e1000_pre_mem_op")
    # remote_trace.enable_event("e1000/e1000_post_mem_op")
    # remote_trace.enable_event("e1000/e1000_set_tdt")
    # remote_trace.enable_event("e1000/e1000_post_set_tdt")
    # remote_trace.kprobe_add("p:notify_begin vp_notify")
    # remote_trace.kprobe_add("r:notify_end vp_notify")
    remote_trace.kprobe_add("p:e1000_clean e1000_clean")
    remote_trace.kprobe_add("p:e1000_kick e1000_qemu_kick")
    remote_trace.kprobe_enable()

    netperf = NetPerfLatency(None, runtime=15)
    # netperf_perf = netperf.run_netperf(vm, msg_size="64K")
    # print("Netperf performance: %s" % (netperf_perf, ))
    # logger.info("Netperf performance: %s", netperf_perf)
    # input("Press Enter to start tracing")

    remote_trace.trace_on()

    run_command_async("tcpdump -i tap0 -s 100 -w {} -W 1 -G 7".format(os.path.join(trace_dir, "e1000.cap")))
    remote_trace.trace_marker(TRACE_BEGIN_MSG)
    netperf.runtime = 5
    netperf_perf = netperf.run_netperf(vm, msg_size=MSG_SIZE)
    remote_trace.trace_marker(TRACE_END_MSG)
    print("Netperf performance: %s" % (netperf_perf, ))
    logger.info("Netperf performance: %s", netperf_perf)

    remote_trace.trace_off()
    remote_trace.disable_all_events()
    local_trace.trace_off()
    local_trace.disable_all_events()

    netperf.runtime = 15
    netperf_perf = netperf.run_netperf(vm, msg_size=MSG_SIZE)
    print("Base Netperf performance: %s" % (netperf_perf,))
    logger.info("Base Netperf performance: %s", netperf_perf)

    local_trace.read_trace_once(to_file=True)
    remote_trace.read_trace_once(to_file=True)
    # local_trace.trace_to_local_file_stop()

    local_trace.disable_all_events()

    vm.teardown()
    netserver_stop()