From: Peter Dinda Date: Sun, 24 Aug 2014 20:22:17 +0000 (-0500) Subject: Bug fix and cleanup X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=7a10bbf26095ed08095f38de6c1db4b3a131d6f0 Bug fix and cleanup - fix create/start thread distinction - clean up distinction to make it clearer what happens throughout vmm and kernel module - compilation tweak for swapping --- diff --git a/linux_module/palacios-stubs.c b/linux_module/palacios-stubs.c index 90b3ad4..5ef9c5c 100644 --- a/linux_module/palacios-stubs.c +++ b/linux_module/palacios-stubs.c @@ -84,7 +84,7 @@ static int init_print_buffers(void) if (!print_buffer[i]) { ERROR("Cannot allocate print buffer for cpu %d\n",i); deinit_print_buffers(); - return -1; + return -1; } memset(print_buffer[i],0,V3_PRINTK_BUF_SIZE); } @@ -417,7 +417,7 @@ static int lnx_thread_target(void * arg) { * Creates a kernel thread. */ void * -palacios_start_kernel_thread( +palacios_create_and_start_kernel_thread( int (*fn) (void * arg), void * arg, char * thread_name) { @@ -484,6 +484,27 @@ palacios_start_thread(void * th){ wake_up_process(thread); } + +/* + Convenience wrapper +*/ +void * +palacios_create_and_start_thread_on_cpu(int cpu_id, + int (*fn)(void * arg), + void * arg, + char * thread_name ) { + + void *t = palacios_create_thread_on_cpu(cpu_id, fn, arg, thread_name); + + if (t) { + palacios_start_thread(t); + } + + return t; +} + + + /** * Rebind a kernel thread to the specified CPU * The thread will be running on target CPU on return @@ -849,7 +870,7 @@ static struct v3_os_hooks palacios_os_hooks = { .hook_interrupt = palacios_hook_interrupt, .ack_irq = palacios_ack_interrupt, .get_cpu_khz = palacios_get_cpu_khz, - .start_kernel_thread = palacios_start_kernel_thread, + .start_kernel_thread = palacios_create_and_start_kernel_thread, .yield_cpu = palacios_yield_cpu, .sleep_cpu = palacios_sleep_cpu, .wakeup_cpu = palacios_wakeup_cpu, @@ -862,7 +883,7 @@ static struct v3_os_hooks palacios_os_hooks = { .get_cpu = palacios_get_cpu, .interrupt_cpu = palacios_interrupt_cpu, .call_on_cpu = palacios_xcall, - .create_thread_on_cpu = palacios_start_thread_on_cpu, + .create_thread_on_cpu = palacios_create_thread_on_cpu, .start_thread = palacios_start_thread, .move_thread_to_cpu = palacios_move_thread_to_cpu, }; diff --git a/linux_module/palacios-vnet.c b/linux_module/palacios-vnet.c index 4b23772..014d191 100644 --- a/linux_module/palacios-vnet.c +++ b/linux_module/palacios-vnet.c @@ -155,7 +155,7 @@ static struct vnet_host_hooks vnet_host_hooks = { .timer_stop = host_stop_timer, .timer_reset = host_reset_timer, - .thread_start = palacios_start_kernel_thread, + .thread_start = palacios_create_and_start_kernel_thread, .thread_sleep = host_kthread_sleep, .thread_wakeup = host_kthread_wakeup, .thread_stop = host_kthread_stop, diff --git a/linux_module/palacios.h b/linux_module/palacios.h index 3c023ff..f254522 100644 --- a/linux_module/palacios.h +++ b/linux_module/palacios.h @@ -163,8 +163,10 @@ void *palacios_valloc(unsigned int size); // use instead of vmalloc void palacios_vfree(void *); // use instead of vfree void *palacios_vaddr_to_paddr(void *vaddr); void *palacios_paddr_to_vaddr(void *paddr); -void *palacios_start_kernel_thread(int (*fn)(void * arg), void *arg, char *thread_name); -void *palacios_start_thread_on_cpu(int cpu_id, int (*fn)(void * arg), void *arg, char *thread_name); +void *palacios_create_and_start_kernel_thread(int (*fn)(void * arg), void *arg, char *thread_name); +void *palacios_create_thread_on_cpu(int cpu_id, int (*fn)(void * arg), void *arg, char *thread_name); +void palacios_start_thread(void *thread_ptr); +void *palacios_creeate_and_start_thread_on_cpu(int cpu_id, int (*fn)(void * arg), void *arg, char *thread_name); int palacios_move_thread_to_cpu(int new_cpu_id, void *thread_ptr); void palacios_yield_cpu(void); void palacios_sleep_cpu(unsigned int us); diff --git a/palacios/include/palacios/vmm.h b/palacios/include/palacios/vmm.h index db94298..9071fb7 100644 --- a/palacios/include/palacios/vmm.h +++ b/palacios/include/palacios/vmm.h @@ -192,7 +192,7 @@ int v3_get_vcore(struct guest_info *); -#define V3_CREATE_THREAD(fn, arg, name) ({ \ +#define V3_CREATE_AND_START_THREAD(fn, arg, name) ({ \ void * thread = NULL; \ extern struct v3_os_hooks * os_hooks; \ if ((os_hooks) && (os_hooks)->start_kernel_thread) { \ @@ -230,6 +230,14 @@ int v3_get_vcore(struct guest_info *); } \ }) +#define V3_CREATE_AND_START_THREAD_ON_CPU(cpu, fn, arg, name) ({ \ + void *thread = V3_CREATE_THREAD_ON_CPU(cpu,fn,arg,name); \ + if (thread) { \ + V3_START_THREAD(thread); \ + } \ + thread; \ + }) + #define V3_MOVE_THREAD_TO_CPU(pcpu, thread) ({ \ int ret = -1; \ extern struct v3_os_hooks * os_hooks; \ diff --git a/palacios/include/palacios/vmm_swapping.h b/palacios/include/palacios/vmm_swapping.h index ea5deb6..a5e1d3f 100644 --- a/palacios/include/palacios/vmm_swapping.h +++ b/palacios/include/palacios/vmm_swapping.h @@ -59,12 +59,12 @@ struct v3_swap_region_state { struct v3_mem_region; -typedef struct v3_xml v3_cfg_tree_t; +struct v3_xml; int v3_init_swapping(); int v3_deinit_swapping(); -int v3_init_swapping_vm(struct v3_vm_info *vm, v3_cfg_tree_t *config); +int v3_init_swapping_vm(struct v3_vm_info *vm, struct v3_xml *config); int v3_deinit_swapping_vm(struct v3_vm_info *vm); // not needed yet diff --git a/palacios/src/devices/telnet_cons.c b/palacios/src/devices/telnet_cons.c index 4e7471b..5ba8a1b 100644 --- a/palacios/src/devices/telnet_cons.c +++ b/palacios/src/devices/telnet_cons.c @@ -555,7 +555,7 @@ static int cons_init(struct v3_vm_info * vm, v3_cfg_tree_t * cfg) { v3_console_register_cga(frontend, &cons_ops, state); - V3_CREATE_THREAD(cons_server, state, "Telnet Console Network Server"); + V3_CREATE_AND_START_THREAD(cons_server, state, "Telnet Console Network Server"); return 0; } diff --git a/palacios/src/palacios/vmm_swapping.c b/palacios/src/palacios/vmm_swapping.c index a24ef42..90475d1 100644 --- a/palacios/src/palacios/vmm_swapping.c +++ b/palacios/src/palacios/vmm_swapping.c @@ -103,7 +103,7 @@ static int read_all(v3_file_t fd, void *buf, uint64_t len, uint64_t offset) #define CEIL_DIV(x,y) (((x)/(y)) + !!((x)%(y))) -int v3_init_swapping_vm(struct v3_vm_info *vm, v3_cfg_tree_t *config) +int v3_init_swapping_vm(struct v3_vm_info *vm, struct v3_xml *config) { v3_cfg_tree_t *swap_config; char *enable;