From: Jack Lange Date: Wed, 12 Jan 2011 22:19:38 +0000 (-0600) Subject: free up telemetry state and free backend state for the virtio devices X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=commitdiff_plain;h=aac189310cca0f5f14543d91413d3b5b58250a3e;p=palacios.git free up telemetry state and free backend state for the virtio devices --- diff --git a/palacios/include/palacios/vmm_telemetry.h b/palacios/include/palacios/vmm_telemetry.h index 88e3cce..8fab683 100644 --- a/palacios/include/palacios/vmm_telemetry.h +++ b/palacios/include/palacios/vmm_telemetry.h @@ -53,6 +53,8 @@ struct v3_core_telemetry { void v3_init_telemetry(struct v3_vm_info * vm); void v3_init_core_telemetry(struct guest_info * info); +void v3_deinit_telemetry(struct v3_vm_info * vm); +void v3_deinit_core_telemetry(struct guest_info * core); void v3_telemetry_start_exit(struct guest_info * info); void v3_telemetry_end_exit(struct guest_info * info, uint_t exit_code); diff --git a/palacios/src/devices/lnx_virtio_blk.c b/palacios/src/devices/lnx_virtio_blk.c index 2c871d9..7e26b30 100644 --- a/palacios/src/devices/lnx_virtio_blk.c +++ b/palacios/src/devices/lnx_virtio_blk.c @@ -472,7 +472,18 @@ static int virtio_io_read(struct guest_info * core, uint16_t port, void * dst, u static int virtio_free(struct virtio_dev_state * virtio) { + struct virtio_blk_state * blk_state = NULL; + struct virtio_blk_state * tmp = NULL; + + list_for_each_entry_safe(blk_state, tmp, &(virtio->dev_list), dev_link) { + + // unregister from PCI + + list_del(&(blk_state->dev_link)); + V3_Free(blk_state); + } + V3_Free(virtio); return 0; @@ -555,6 +566,10 @@ static int register_dev(struct virtio_dev_state * virtio, struct virtio_blk_stat blk_state->pci_dev = pci_dev; + + + /* Add backend to list of devices */ + list_add(&(blk_state->dev_link), &(virtio->dev_list)); /* Block configuration */ blk_state->virtio_cfg.host_features = VIRTIO_SEG_MAX; diff --git a/palacios/src/devices/lnx_virtio_nic.c b/palacios/src/devices/lnx_virtio_nic.c index 899909f..ca56633 100644 --- a/palacios/src/devices/lnx_virtio_nic.c +++ b/palacios/src/devices/lnx_virtio_nic.c @@ -649,9 +649,18 @@ exit: return ret_val; } -static int virtio_free(struct virtio_net_state * virtio) { - - // unregister from PCI +static int virtio_free(struct virtio_dev_state * virtio) { + struct virtio_net_state * backend = NULL; + struct virtio_net_state * tmp = NULL; + + + list_for_each_entry_safe(backend, tmp, &(virtio->dev_list), dev_link) { + + // unregister from PCI + + list_del(&(backend->dev_link)); + V3_Free(backend); + } V3_Free(virtio); return 0; @@ -770,6 +779,10 @@ static int register_dev(struct virtio_dev_state * virtio, virtio_init_state(net_state); + + /* Add backend to list of devices */ + list_add(&(net_state->dev_link), &(virtio->dev_list)); + return 0; } diff --git a/palacios/src/palacios/vm_guest.c b/palacios/src/palacios/vm_guest.c index 36ec7d2..072ffac 100644 --- a/palacios/src/palacios/vm_guest.c +++ b/palacios/src/palacios/vm_guest.c @@ -575,7 +575,7 @@ int v3_free_vm_internal(struct v3_vm_info * vm) { v3_deinit_hypercall_map(vm); #ifdef CONFIG_TELEMETRY - //v3_deinit_telemetry(vm); + v3_deinit_telemetry(vm); #endif return 0; @@ -659,6 +659,10 @@ int v3_free_core(struct guest_info * core) { v3_free_passthrough_pts(core); +#ifdef CONFIG_TELEMETRY + v3_deinit_core_telemetry(core); +#endif + switch (cpu_type) { #ifdef CONFIG_SVM case V3_SVM_CPU: diff --git a/palacios/src/palacios/vmm_telemetry.c b/palacios/src/palacios/vmm_telemetry.c index fae3c76..2fdca40 100644 --- a/palacios/src/palacios/vmm_telemetry.c +++ b/palacios/src/palacios/vmm_telemetry.c @@ -50,6 +50,10 @@ struct exit_event { }; +static int free_callback(struct v3_vm_info * vm, struct telemetry_cb * cb); +static int free_exit(struct guest_info * core, struct exit_event * event); + + void v3_init_telemetry(struct v3_vm_info * vm) { struct v3_telemetry_state * telemetry = &(vm->telemetry); @@ -61,6 +65,16 @@ void v3_init_telemetry(struct v3_vm_info * vm) { INIT_LIST_HEAD(&(telemetry->cb_list)); } +void v3_deinit_telemetry(struct v3_vm_info * vm) { + struct telemetry_cb * cb = NULL; + struct telemetry_cb * tmp = NULL; + + list_for_each_entry_safe(cb, tmp, &(vm->telemetry.cb_list), cb_node) { + free_callback(vm, cb); + } +} + + void v3_init_core_telemetry(struct guest_info * core) { struct v3_core_telemetry * telemetry = &(core->core_telem); @@ -72,6 +86,18 @@ void v3_init_core_telemetry(struct guest_info * core) { telemetry->exit_root.rb_node = NULL; } +void v3_deinit_core_telemetry(struct guest_info * core) { + struct rb_node * node = v3_rb_first(&(core->core_telem.exit_root)); + struct exit_event * evt = NULL; + + while (node) { + evt = rb_entry(node, struct exit_event, tree_node); + node = v3_rb_next(node); + + free_exit(core, evt); + } +} + static inline struct exit_event * __insert_event(struct guest_info * info, @@ -141,6 +167,15 @@ static inline struct exit_event * create_exit(uint_t exit_code) { return evt; } + + +static int free_exit(struct guest_info * core, struct exit_event * evt) { + v3_rb_erase(&(evt->tree_node), &(core->core_telem.exit_root)); + V3_Free(evt); + return 0; +} + + void v3_telemetry_start_exit(struct guest_info * info) { rdtscll(info->core_telem.vmm_start_tsc); } @@ -190,6 +225,14 @@ void v3_add_telemetry_cb(struct v3_vm_info * vm, +static int free_callback(struct v3_vm_info * vm, struct telemetry_cb * cb) { + list_del(&(cb->cb_node)); + V3_Free(cb); + + return 0; +} + + void v3_print_telemetry(struct v3_vm_info * vm) { struct v3_telemetry_state * telemetry = &(vm->telemetry); uint64_t invoke_tsc = 0;