[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-changelog] [xen-unstable] [merge] with xen-unstable
# HG changeset patch # User Christian Limpach <Christian.Limpach@xxxxxxxxxxxxx> # Date 1169219504 0 # Node ID 9a0b157a0ab0f0472dcfd08be69a5e16edf4143d # Parent 3c8bb086025ee18f077582a5343da631c67fbaca # Parent e9e327c3e81b2d5682307246f81d4cb53d2975f0 [merge] with xen-unstable Signed-off-by: Christian Limpach <Christian.Limpach@xxxxxxxxxxxxx> --- extras/mini-os/time.c | 225 ---------------------------------------- extras/mini-os/arch/x86/mm.c | 1 extras/mini-os/arch/x86/sched.c | 20 --- extras/mini-os/arch/x86/time.c | 225 ++++++++++++++++++++++++++++++++++++++++ extras/mini-os/include/sched.h | 3 extras/mini-os/lib/math.c | 5 extras/mini-os/lib/xmalloc.c | 6 + extras/mini-os/netfront.c | 2 extras/mini-os/sched.c | 26 +++- extras/mini-os/xenbus/xenbus.c | 2 tools/libxc/xc_domain.c | 23 ++-- tools/libxc/xc_load_elf.c | 10 - tools/libxc/xc_private.c | 31 +++++ tools/libxc/xc_private.h | 3 tools/libxc/xc_tbuf.c | 12 +- tools/xcutils/readnotes.c | 2 xen/common/bitmap.c | 51 +++++++++ xen/common/domctl.c | 21 ++- xen/common/elf.c | 10 - xen/include/xen/bitmap.h | 3 20 files changed, 397 insertions(+), 284 deletions(-) diff -r 3c8bb086025e -r 9a0b157a0ab0 extras/mini-os/arch/x86/mm.c --- a/extras/mini-os/arch/x86/mm.c Fri Jan 19 14:48:57 2007 +0000 +++ b/extras/mini-os/arch/x86/mm.c Fri Jan 19 15:11:44 2007 +0000 @@ -61,6 +61,7 @@ void new_pt_frame(unsigned long *pt_pfn, mmu_update_t mmu_updates[1]; struct mmuext_op pin_request; + prot_e = prot_t = pincmd = 0; DEBUG("Allocating new L%d pt frame for pt_pfn=%lx, " "prev_l_mfn=%lx, offset=%lx", level, *pt_pfn, prev_l_mfn, offset); diff -r 3c8bb086025e -r 9a0b157a0ab0 extras/mini-os/arch/x86/sched.c --- a/extras/mini-os/arch/x86/sched.c Fri Jan 19 14:48:57 2007 +0000 +++ b/extras/mini-os/arch/x86/sched.c Fri Jan 19 15:11:44 2007 +0000 @@ -91,10 +91,11 @@ static void stack_push(struct thread *th *((unsigned long *)thread->sp) = value; } -struct thread* create_thread(char *name, void (*function)(void *), void *data) +/* Architecture specific setup of thread creation */ +struct thread* arch_create_thread(char *name, void (*function)(void *), + void *data) { struct thread *thread; - unsigned long flags; thread = xmalloc(struct thread); /* Allocate 2 pages for stack, stack will be 2pages aligned */ @@ -110,23 +111,8 @@ struct thread* create_thread(char *name, stack_push(thread, (unsigned long) function); stack_push(thread, (unsigned long) data); thread->ip = (unsigned long) thread_starter; - - /* Not runable, not exited, not sleeping */ - thread->flags = 0; - thread->wakeup_time = 0LL; - set_runnable(thread); - local_irq_save(flags); - if(idle_thread != NULL) { - list_add_tail(&thread->thread_list, &idle_thread->thread_list); - } else if(function != idle_thread_fn) - { - printk("BUG: Not allowed to create thread before initialising scheduler.\n"); - BUG(); - } - local_irq_restore(flags); return thread; } - void run_idle_thread(void) { diff -r 3c8bb086025e -r 9a0b157a0ab0 extras/mini-os/arch/x86/time.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extras/mini-os/arch/x86/time.c Fri Jan 19 15:11:44 2007 +0000 @@ -0,0 +1,225 @@ +/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- + **************************************************************************** + * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge + * (C) 2002-2003 - Keir Fraser - University of Cambridge + * (C) 2005 - Grzegorz Milos - Intel Research Cambridge + * (C) 2006 - Robert Kaiser - FH Wiesbaden + **************************************************************************** + * + * File: time.c + * Author: Rolf Neugebauer and Keir Fraser + * Changes: Grzegorz Milos + * + * Description: Simple time and timer functions + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + */ + + +#include <os.h> +#include <traps.h> +#include <types.h> +#include <hypervisor.h> +#include <events.h> +#include <time.h> +#include <lib.h> + +/************************************************************************ + * Time functions + *************************************************************************/ + +/* These are peridically updated in shared_info, and then copied here. */ +struct shadow_time_info { + u64 tsc_timestamp; /* TSC at last update of time vals. */ + u64 system_timestamp; /* Time, in nanosecs, since boot. */ + u32 tsc_to_nsec_mul; + u32 tsc_to_usec_mul; + int tsc_shift; + u32 version; +}; +static struct timespec shadow_ts; +static u32 shadow_ts_version; + +static struct shadow_time_info shadow; + + +#ifndef rmb +#define rmb() __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory") +#endif + +#define HANDLE_USEC_OVERFLOW(_tv) \ + do { \ + while ( (_tv)->tv_usec >= 1000000 ) \ + { \ + (_tv)->tv_usec -= 1000000; \ + (_tv)->tv_sec++; \ + } \ + } while ( 0 ) + +static inline int time_values_up_to_date(void) +{ + struct vcpu_time_info *src = &HYPERVISOR_shared_info->vcpu_info[0].time; + + return (shadow.version == src->version); +} + + +/* + * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction, + * yielding a 64-bit result. + */ +static inline u64 scale_delta(u64 delta, u32 mul_frac, int shift) +{ + u64 product; +#ifdef __i386__ + u32 tmp1, tmp2; +#endif + + if ( shift < 0 ) + delta >>= -shift; + else + delta <<= shift; + +#ifdef __i386__ + __asm__ ( + "mul %5 ; " + "mov %4,%%eax ; " + "mov %%edx,%4 ; " + "mul %5 ; " + "add %4,%%eax ; " + "xor %5,%5 ; " + "adc %5,%%edx ; " + : "=A" (product), "=r" (tmp1), "=r" (tmp2) + : "a" ((u32)delta), "1" ((u32)(delta >> 32)), "2" (mul_frac) ); +#else + __asm__ ( + "mul %%rdx ; shrd $32,%%rdx,%%rax" + : "=a" (product) : "0" (delta), "d" ((u64)mul_frac) ); +#endif + + return product; +} + + +static unsigned long get_nsec_offset(void) +{ + u64 now, delta; + rdtscll(now); + delta = now - shadow.tsc_timestamp; + return scale_delta(delta, shadow.tsc_to_nsec_mul, shadow.tsc_shift); +} + + +static void get_time_values_from_xen(void) +{ + struct vcpu_time_info *src = &HYPERVISOR_shared_info->vcpu_info[0].time; + + do { + shadow.version = src->version; + rmb(); + shadow.tsc_timestamp = src->tsc_timestamp; + shadow.system_timestamp = src->system_time; + shadow.tsc_to_nsec_mul = src->tsc_to_system_mul; + shadow.tsc_shift = src->tsc_shift; + rmb(); + } + while ((src->version & 1) | (shadow.version ^ src->version)); + + shadow.tsc_to_usec_mul = shadow.tsc_to_nsec_mul / 1000; +} + + + + +/* monotonic_clock(): returns # of nanoseconds passed since time_init() + * Note: This function is required to return accurate + * time even in the absence of multiple timer ticks. + */ +u64 monotonic_clock(void) +{ + u64 time; + u32 local_time_version; + + do { + local_time_version = shadow.version; + rmb(); + time = shadow.system_timestamp + get_nsec_offset(); + if (!time_values_up_to_date()) + get_time_values_from_xen(); + rmb(); + } while (local_time_version != shadow.version); + + return time; +} + +static void update_wallclock(void) +{ + shared_info_t *s = HYPERVISOR_shared_info; + + do { + shadow_ts_version = s->wc_version; + rmb(); + shadow_ts.ts_sec = s->wc_sec; + shadow_ts.ts_nsec = s->wc_nsec; + rmb(); + } + while ((s->wc_version & 1) | (shadow_ts_version ^ s->wc_version)); +} + + +void gettimeofday(struct timeval *tv) +{ + u64 nsec = monotonic_clock(); + nsec += shadow_ts.ts_nsec; + + + tv->tv_sec = shadow_ts.ts_sec; + tv->tv_sec += NSEC_TO_SEC(nsec); + tv->tv_usec = NSEC_TO_USEC(nsec % 1000000000UL); +} + + +void block_domain(s_time_t until) +{ + struct timeval tv; + gettimeofday(&tv); + if(monotonic_clock() < until) + { + HYPERVISOR_set_timer_op(until); + HYPERVISOR_sched_op(SCHEDOP_block, 0); + } +} + + +/* + * Just a dummy + */ +static void timer_handler(evtchn_port_t ev, struct pt_regs *regs, void *ign) +{ + get_time_values_from_xen(); + update_wallclock(); +} + + + +void init_time(void) +{ + printk("Initialising timer interface\n"); + bind_virq(VIRQ_TIMER, &timer_handler, NULL); +} diff -r 3c8bb086025e -r 9a0b157a0ab0 extras/mini-os/include/sched.h --- a/extras/mini-os/include/sched.h Fri Jan 19 14:48:57 2007 +0000 +++ b/extras/mini-os/include/sched.h Fri Jan 19 15:11:44 2007 +0000 @@ -31,6 +31,9 @@ void idle_thread_fn(void *unused); #define switch_threads(prev, next) arch_switch_threads(prev, next) + /* Architecture specific setup of thread creation. */ +struct thread* arch_create_thread(char *name, void (*function)(void *), + void *data); void init_sched(void); void run_idle_thread(void); diff -r 3c8bb086025e -r 9a0b157a0ab0 extras/mini-os/lib/math.c --- a/extras/mini-os/lib/math.c Fri Jan 19 14:48:57 2007 +0000 +++ b/extras/mini-os/lib/math.c Fri Jan 19 15:11:44 2007 +0000 @@ -56,6 +56,10 @@ */ #include <types.h> + + /* On ia64 these functions lead to crashes. These are replaced by + * assembler functions. */ +#if !defined(__ia64__) /* * Depending on the desired operation, we view a `long long' (aka quad_t) in @@ -380,3 +384,4 @@ __umoddi3(u_quad_t a, u_quad_t b) return (r); } +#endif /* !defined(__ia64__) */ diff -r 3c8bb086025e -r 9a0b157a0ab0 extras/mini-os/lib/xmalloc.c --- a/extras/mini-os/lib/xmalloc.c Fri Jan 19 14:48:57 2007 +0000 +++ b/extras/mini-os/lib/xmalloc.c Fri Jan 19 15:11:44 2007 +0000 @@ -48,6 +48,12 @@ struct xmalloc_hdr /* Total including this hdr. */ size_t size; struct list_head freelist; +#if defined(__ia64__) + // Needed for ia64 as long as the align parameter in _xmalloc() + // is not supported. + uint64_t pad; +#endif + } __cacheline_aligned; static void maybe_split(struct xmalloc_hdr *hdr, size_t size, size_t block) diff -r 3c8bb086025e -r 9a0b157a0ab0 extras/mini-os/netfront.c --- a/extras/mini-os/netfront.c Fri Jan 19 14:48:57 2007 +0000 +++ b/extras/mini-os/netfront.c Fri Jan 19 15:11:44 2007 +0000 @@ -327,7 +327,6 @@ done: printk("backend at %s\n",backend); printk("mac is %s\n",mac); - char *res; char path[256]; sprintf(path,"%s/state",backend); @@ -336,7 +335,6 @@ done: xenbus_wait_for_value(path,"4"); //free(backend); - free(res); printk("**************************\n"); diff -r 3c8bb086025e -r 9a0b157a0ab0 extras/mini-os/sched.c --- a/extras/mini-os/sched.c Fri Jan 19 14:48:57 2007 +0000 +++ b/extras/mini-os/sched.c Fri Jan 19 15:11:44 2007 +0000 @@ -155,11 +155,27 @@ void schedule(void) if(prev != next) switch_threads(prev, next); } - -/* Gets run when a new thread is scheduled the first time ever, - defined in x86_[32/64].S */ -extern void thread_starter(void); - +struct thread* create_thread(char *name, void (*function)(void *), void *data) +{ + struct thread *thread; + unsigned long flags; + /* Call architecture specific setup. */ + thread = arch_create_thread(name, function, data); + /* Not runable, not exited, not sleeping */ + thread->flags = 0; + thread->wakeup_time = 0LL; + set_runnable(thread); + local_irq_save(flags); + if(idle_thread != NULL) { + list_add_tail(&thread->thread_list, &idle_thread->thread_list); + } else if(function != idle_thread_fn) + { + printk("BUG: Not allowed to create thread before initialising scheduler.\n"); + BUG(); + } + local_irq_restore(flags); + return thread; +} void exit_thread(void) { diff -r 3c8bb086025e -r 9a0b157a0ab0 extras/mini-os/time.c --- a/extras/mini-os/time.c Fri Jan 19 14:48:57 2007 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,225 +0,0 @@ -/* -*- Mode:C; c-basic-offset:4; tab-width:4 -*- - **************************************************************************** - * (C) 2003 - Rolf Neugebauer - Intel Research Cambridge - * (C) 2002-2003 - Keir Fraser - University of Cambridge - * (C) 2005 - Grzegorz Milos - Intel Research Cambridge - * (C) 2006 - Robert Kaiser - FH Wiesbaden - **************************************************************************** - * - * File: time.c - * Author: Rolf Neugebauer and Keir Fraser - * Changes: Grzegorz Milos - * - * Description: Simple time and timer functions - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to - * deal in the Software without restriction, including without limitation the - * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or - * sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - */ - - -#include <os.h> -#include <traps.h> -#include <types.h> -#include <hypervisor.h> -#include <events.h> -#include <time.h> -#include <lib.h> - -/************************************************************************ - * Time functions - *************************************************************************/ - -/* These are peridically updated in shared_info, and then copied here. */ -struct shadow_time_info { - u64 tsc_timestamp; /* TSC at last update of time vals. */ - u64 system_timestamp; /* Time, in nanosecs, since boot. */ - u32 tsc_to_nsec_mul; - u32 tsc_to_usec_mul; - int tsc_shift; - u32 version; -}; -static struct timespec shadow_ts; -static u32 shadow_ts_version; - -static struct shadow_time_info shadow; - - -#ifndef rmb -#define rmb() __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : :"memory") -#endif - -#define HANDLE_USEC_OVERFLOW(_tv) \ - do { \ - while ( (_tv)->tv_usec >= 1000000 ) \ - { \ - (_tv)->tv_usec -= 1000000; \ - (_tv)->tv_sec++; \ - } \ - } while ( 0 ) - -static inline int time_values_up_to_date(void) -{ - struct vcpu_time_info *src = &HYPERVISOR_shared_info->vcpu_info[0].time; - - return (shadow.version == src->version); -} - - -/* - * Scale a 64-bit delta by scaling and multiplying by a 32-bit fraction, - * yielding a 64-bit result. - */ -static inline u64 scale_delta(u64 delta, u32 mul_frac, int shift) -{ - u64 product; -#ifdef __i386__ - u32 tmp1, tmp2; -#endif - - if ( shift < 0 ) - delta >>= -shift; - else - delta <<= shift; - -#ifdef __i386__ - __asm__ ( - "mul %5 ; " - "mov %4,%%eax ; " - "mov %%edx,%4 ; " - "mul %5 ; " - "add %4,%%eax ; " - "xor %5,%5 ; " - "adc %5,%%edx ; " - : "=A" (product), "=r" (tmp1), "=r" (tmp2) - : "a" ((u32)delta), "1" ((u32)(delta >> 32)), "2" (mul_frac) ); -#else - __asm__ ( - "mul %%rdx ; shrd $32,%%rdx,%%rax" - : "=a" (product) : "0" (delta), "d" ((u64)mul_frac) ); -#endif - - return product; -} - - -static unsigned long get_nsec_offset(void) -{ - u64 now, delta; - rdtscll(now); - delta = now - shadow.tsc_timestamp; - return scale_delta(delta, shadow.tsc_to_nsec_mul, shadow.tsc_shift); -} - - -static void get_time_values_from_xen(void) -{ - struct vcpu_time_info *src = &HYPERVISOR_shared_info->vcpu_info[0].time; - - do { - shadow.version = src->version; - rmb(); - shadow.tsc_timestamp = src->tsc_timestamp; - shadow.system_timestamp = src->system_time; - shadow.tsc_to_nsec_mul = src->tsc_to_system_mul; - shadow.tsc_shift = src->tsc_shift; - rmb(); - } - while ((src->version & 1) | (shadow.version ^ src->version)); - - shadow.tsc_to_usec_mul = shadow.tsc_to_nsec_mul / 1000; -} - - - - -/* monotonic_clock(): returns # of nanoseconds passed since time_init() - * Note: This function is required to return accurate - * time even in the absence of multiple timer ticks. - */ -u64 monotonic_clock(void) -{ - u64 time; - u32 local_time_version; - - do { - local_time_version = shadow.version; - rmb(); - time = shadow.system_timestamp + get_nsec_offset(); - if (!time_values_up_to_date()) - get_time_values_from_xen(); - rmb(); - } while (local_time_version != shadow.version); - - return time; -} - -static void update_wallclock(void) -{ - shared_info_t *s = HYPERVISOR_shared_info; - - do { - shadow_ts_version = s->wc_version; - rmb(); - shadow_ts.ts_sec = s->wc_sec; - shadow_ts.ts_nsec = s->wc_nsec; - rmb(); - } - while ((s->wc_version & 1) | (shadow_ts_version ^ s->wc_version)); -} - - -void gettimeofday(struct timeval *tv) -{ - u64 nsec = monotonic_clock(); - nsec += shadow_ts.ts_nsec; - - - tv->tv_sec = shadow_ts.ts_sec; - tv->tv_sec += NSEC_TO_SEC(nsec); - tv->tv_usec = NSEC_TO_USEC(nsec % 1000000000UL); -} - - -void block_domain(s_time_t until) -{ - struct timeval tv; - gettimeofday(&tv); - if(monotonic_clock() < until) - { - HYPERVISOR_set_timer_op(until); - HYPERVISOR_sched_op(SCHEDOP_block, 0); - } -} - - -/* - * Just a dummy - */ -static void timer_handler(evtchn_port_t ev, struct pt_regs *regs, void *ign) -{ - get_time_values_from_xen(); - update_wallclock(); -} - - - -void init_time(void) -{ - printk("Initialising timer interface\n"); - bind_virq(VIRQ_TIMER, &timer_handler, NULL); -} diff -r 3c8bb086025e -r 9a0b157a0ab0 extras/mini-os/xenbus/xenbus.c --- a/extras/mini-os/xenbus/xenbus.c Fri Jan 19 14:48:57 2007 +0000 +++ b/extras/mini-os/xenbus/xenbus.c Fri Jan 19 15:11:44 2007 +0000 @@ -103,7 +103,7 @@ static void xenbus_thread_func(void *ign static void xenbus_thread_func(void *ign) { struct xsd_sockmsg msg; - unsigned prod; + unsigned prod = 0; for (;;) { diff -r 3c8bb086025e -r 9a0b157a0ab0 tools/libxc/xc_domain.c --- a/tools/libxc/xc_domain.c Fri Jan 19 14:48:57 2007 +0000 +++ b/tools/libxc/xc_domain.c Fri Jan 19 15:11:44 2007 +0000 @@ -96,16 +96,19 @@ int xc_vcpu_setaffinity(int xc_handle, { DECLARE_DOMCTL; int ret = -1; + uint8_t local[sizeof (cpumap)]; domctl.cmd = XEN_DOMCTL_setvcpuaffinity; domctl.domain = (domid_t)domid; domctl.u.vcpuaffinity.vcpu = vcpu; - set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, - (uint8_t *)&cpumap); + bitmap_64_to_byte(local, &cpumap, sizeof (cpumap)); + + set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, local); + domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap) * 8; - if ( lock_pages(&cpumap, sizeof(cpumap)) != 0 ) + if ( lock_pages(local, sizeof(local)) != 0 ) { PERROR("Could not lock memory for Xen hypercall"); goto out; @@ -113,7 +116,7 @@ int xc_vcpu_setaffinity(int xc_handle, ret = do_domctl(xc_handle, &domctl); - unlock_pages(&cpumap, sizeof(cpumap)); + unlock_pages(local, sizeof(local)); out: return ret; @@ -127,16 +130,16 @@ int xc_vcpu_getaffinity(int xc_handle, { DECLARE_DOMCTL; int ret = -1; + uint8_t local[sizeof (cpumap)]; domctl.cmd = XEN_DOMCTL_getvcpuaffinity; domctl.domain = (domid_t)domid; domctl.u.vcpuaffinity.vcpu = vcpu; - set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, - (uint8_t *)cpumap); - domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(*cpumap) * 8; + set_xen_guest_handle(domctl.u.vcpuaffinity.cpumap.bitmap, local); + domctl.u.vcpuaffinity.cpumap.nr_cpus = sizeof(cpumap) * 8; - if ( lock_pages(cpumap, sizeof(*cpumap)) != 0 ) + if ( lock_pages(local, sizeof(local)) != 0 ) { PERROR("Could not lock memory for Xen hypercall"); goto out; @@ -144,8 +147,8 @@ int xc_vcpu_getaffinity(int xc_handle, ret = do_domctl(xc_handle, &domctl); - unlock_pages(cpumap, sizeof(*cpumap)); - + unlock_pages(local, sizeof (local)); + bitmap_byte_to_64(cpumap, local, sizeof (local)); out: return ret; } diff -r 3c8bb086025e -r 9a0b157a0ab0 tools/libxc/xc_load_elf.c --- a/tools/libxc/xc_load_elf.c Fri Jan 19 14:48:57 2007 +0000 +++ b/tools/libxc/xc_load_elf.c Fri Jan 19 15:11:44 2007 +0000 @@ -177,7 +177,7 @@ static unsigned long long xen_guest_nume /* * Interface to the Xen ELF notes. */ -#define ELFNOTE_NAME(_n_) ((const void*)(_n_) + sizeof(*(_n_))) +#define ELFNOTE_NAME(_n_) ((const char*)(_n_) + sizeof(*(_n_))) #define ELFNOTE_DESC(_n_) (ELFNOTE_NAME(_n_) + (((_n_)->namesz+3)&~3)) #define ELFNOTE_NEXT(_n_) (ELFNOTE_DESC(_n_) + (((_n_)->descsz+3)&~3)) @@ -190,7 +190,7 @@ static int is_xen_elfnote_section(const for ( note = (const Elf_Note *)(image + shdr->sh_offset); note < (const Elf_Note *)(image + shdr->sh_offset + shdr->sh_size); - note = ELFNOTE_NEXT(note) ) + note = (const Elf_Note *)ELFNOTE_NEXT(note) ) { if ( !strncmp(ELFNOTE_NAME(note), "Xen", 4) ) return 1; @@ -209,7 +209,7 @@ static const Elf_Note *xen_elfnote_looku for ( note = (const Elf_Note *)dsi->__elfnote_section; note < (const Elf_Note *)dsi->__elfnote_section_end; - note = ELFNOTE_NEXT(note) ) + note = (const Elf_Note *)ELFNOTE_NEXT(note) ) { if ( strncmp(ELFNOTE_NAME(note), "Xen", 4) ) continue; @@ -338,9 +338,9 @@ static int parseelfimage(const char *ima image + ehdr->e_shoff + (h*ehdr->e_shentsize)); if ( !is_xen_elfnote_section(image, shdr) ) continue; - dsi->__elfnote_section = (const void *)image + shdr->sh_offset; + dsi->__elfnote_section = (const char *)image + shdr->sh_offset; dsi->__elfnote_section_end = - (const void *)image + shdr->sh_offset + shdr->sh_size; + (const char *)image + shdr->sh_offset + shdr->sh_size; break; } diff -r 3c8bb086025e -r 9a0b157a0ab0 tools/libxc/xc_private.c --- a/tools/libxc/xc_private.c Fri Jan 19 14:48:57 2007 +0000 +++ b/tools/libxc/xc_private.c Fri Jan 19 15:11:44 2007 +0000 @@ -502,6 +502,37 @@ char *safe_strerror(int errcode) return errbuf; } +void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits) +{ + uint64_t l; + int i, j, b; + + for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) { + l = lp[i]; + for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) { + bp[b+j] = l; + l >>= 8; + nbits -= 8; + } + } +} + +void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits) +{ + uint64_t l; + int i, j, b; + + for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) { + l = 0; + for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) { + l <<= 8; + l |= bp[b+j]; + nbits -= 8; + } + lp[i] = l; + } +} + /* * Local variables: * mode: C diff -r 3c8bb086025e -r 9a0b157a0ab0 tools/libxc/xc_private.h --- a/tools/libxc/xc_private.h Fri Jan 19 14:48:57 2007 +0000 +++ b/tools/libxc/xc_private.h Fri Jan 19 15:11:44 2007 +0000 @@ -155,4 +155,7 @@ int xc_waitdomain_core(int xc_handle, in int xc_waitdomain_core(int xc_handle, int domain, int *status, int options, vcpu_guest_context_t *ctxt); +void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits); +void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits); + #endif /* __XC_PRIVATE_H__ */ diff -r 3c8bb086025e -r 9a0b157a0ab0 tools/libxc/xc_tbuf.c --- a/tools/libxc/xc_tbuf.c Fri Jan 19 14:48:57 2007 +0000 +++ b/tools/libxc/xc_tbuf.c Fri Jan 19 15:11:44 2007 +0000 @@ -96,15 +96,19 @@ int xc_tbuf_set_cpu_mask(int xc_handle, { DECLARE_SYSCTL; int ret = -1; + uint64_t mask64 = mask; + uint8_t bytemap[sizeof(mask64)]; sysctl.cmd = XEN_SYSCTL_tbuf_op; sysctl.interface_version = XEN_SYSCTL_INTERFACE_VERSION; sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_set_cpu_mask; - set_xen_guest_handle(sysctl.u.tbuf_op.cpu_mask.bitmap, (uint8_t *)&mask); - sysctl.u.tbuf_op.cpu_mask.nr_cpus = sizeof(mask) * 8; + bitmap_64_to_byte(bytemap, &mask64, sizeof (mask64)); - if ( lock_pages(&mask, sizeof(mask)) != 0 ) + set_xen_guest_handle(sysctl.u.tbuf_op.cpu_mask.bitmap, bytemap); + sysctl.u.tbuf_op.cpu_mask.nr_cpus = sizeof(bytemap) * 8; + + if ( lock_pages(&bytemap, sizeof(bytemap)) != 0 ) { PERROR("Could not lock memory for Xen hypercall"); goto out; @@ -112,7 +116,7 @@ int xc_tbuf_set_cpu_mask(int xc_handle, ret = do_sysctl(xc_handle, &sysctl); - unlock_pages(&mask, sizeof(mask)); + unlock_pages(&bytemap, sizeof(bytemap)); out: return ret; diff -r 3c8bb086025e -r 9a0b157a0ab0 tools/xcutils/readnotes.c --- a/tools/xcutils/readnotes.c Fri Jan 19 14:48:57 2007 +0000 +++ b/tools/xcutils/readnotes.c Fri Jan 19 15:11:44 2007 +0000 @@ -13,7 +13,7 @@ #include <xen/elfnote.h> -#define ELFNOTE_NAME(_n_) ((void*)(_n_) + sizeof(*(_n_))) +#define ELFNOTE_NAME(_n_) ((char*)(_n_) + sizeof(*(_n_))) #define ELFNOTE_DESC(_n_) (ELFNOTE_NAME(_n_) + (((_n_)->n_namesz+3)&~3)) #define ELFNOTE_NEXT(_n_) (ELFNOTE_DESC(_n_) + (((_n_)->n_descsz+3)&~3)) diff -r 3c8bb086025e -r 9a0b157a0ab0 xen/common/bitmap.c --- a/xen/common/bitmap.c Fri Jan 19 14:48:57 2007 +0000 +++ b/xen/common/bitmap.c Fri Jan 19 15:11:44 2007 +0000 @@ -10,6 +10,7 @@ #include <xen/errno.h> #include <xen/bitmap.h> #include <xen/bitops.h> +#include <asm/byteorder.h> /* * bitmaps provide an array of bits, implemented using an an @@ -467,3 +468,53 @@ int bitmap_allocate_region(unsigned long return 0; } EXPORT_SYMBOL(bitmap_allocate_region); + +#ifdef __BIG_ENDIAN + +void bitmap_long_to_byte(uint8_t *bp, const unsigned long *lp, int nbits) +{ + unsigned long l; + int i, j, b; + + for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) { + l = lp[i]; + for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) { + bp[b+j] = l; + l >>= 8; + nbits -= 8; + } + } +} + +void bitmap_byte_to_long(unsigned long *lp, const uint8_t *bp, int nbits) +{ + unsigned long l; + int i, j, b; + + for (i = 0, b = 0; nbits > 0; i++, b += sizeof(l)) { + l = 0; + for (j = 0; (j < sizeof(l)) && (nbits > 0); j++) { + l <<= 8; + l |= bp[b+j]; + nbits -= 8; + } + lp[i] = l; + } +} + +#elif defined(__LITTLE_ENDIAN) + +void bitmap_long_to_byte(uint8_t *bp, const unsigned long *lp, int nbits) +{ + memcpy(bp, lp, (nbits+7)/8); +} + +void bitmap_byte_to_long(unsigned long *lp, const uint8_t *bp, int nbits) +{ + /* We may need to pad the final longword with zeroes. */ + if (nbits & (BITS_PER_LONG-1)) + lp[BITS_TO_LONGS(nbits)-1] = 0; + memcpy(lp, bp, (nbits+7)/8); +} + +#endif diff -r 3c8bb086025e -r 9a0b157a0ab0 xen/common/domctl.c --- a/xen/common/domctl.c Fri Jan 19 14:48:57 2007 +0000 +++ b/xen/common/domctl.c Fri Jan 19 15:11:44 2007 +0000 @@ -18,6 +18,7 @@ #include <xen/console.h> #include <xen/iocap.h> #include <xen/guest_access.h> +#include <xen/bitmap.h> #ifdef CONFIG_COMPAT #include <xen/compat.h> #endif @@ -40,16 +41,17 @@ void cpumask_to_xenctl_cpumap( { unsigned int guest_bytes, copy_bytes, i; uint8_t zero = 0; + uint8_t bytemap[(NR_CPUS + 7) / 8]; if ( guest_handle_is_null(xenctl_cpumap->bitmap) ) return; guest_bytes = (xenctl_cpumap->nr_cpus + 7) / 8; - copy_bytes = min_t(unsigned int, guest_bytes, (NR_CPUS + 7) / 8); - - copy_to_guest(xenctl_cpumap->bitmap, - (uint8_t *)cpus_addr(*cpumask), - copy_bytes); + copy_bytes = min_t(unsigned int, guest_bytes, sizeof(bytemap)); + + bitmap_long_to_byte(bytemap, cpus_addr(*cpumask), NR_CPUS); + + copy_to_guest(xenctl_cpumap->bitmap, &bytemap[0], copy_bytes); for ( i = copy_bytes; i < guest_bytes; i++ ) copy_to_guest_offset(xenctl_cpumap->bitmap, i, &zero, 1); @@ -59,18 +61,19 @@ void xenctl_cpumap_to_cpumask( cpumask_t *cpumask, struct xenctl_cpumap *xenctl_cpumap) { unsigned int guest_bytes, copy_bytes; + uint8_t bytemap[(NR_CPUS + 7) / 8]; guest_bytes = (xenctl_cpumap->nr_cpus + 7) / 8; - copy_bytes = min_t(unsigned int, guest_bytes, (NR_CPUS + 7) / 8); + copy_bytes = min_t(unsigned int, guest_bytes, sizeof(bytemap)); cpus_clear(*cpumask); if ( guest_handle_is_null(xenctl_cpumap->bitmap) ) return; - copy_from_guest((uint8_t *)cpus_addr(*cpumask), - xenctl_cpumap->bitmap, - copy_bytes); + copy_from_guest(&bytemap[0], xenctl_cpumap->bitmap, copy_bytes); + + bitmap_byte_to_long(cpus_addr(*cpumask), bytemap, NR_CPUS); } #endif /* COMPAT */ diff -r 3c8bb086025e -r 9a0b157a0ab0 xen/common/elf.c --- a/xen/common/elf.c Fri Jan 19 14:48:57 2007 +0000 +++ b/xen/common/elf.c Fri Jan 19 15:11:44 2007 +0000 @@ -102,7 +102,7 @@ static unsigned long long xen_guest_nume /* * Interface to the Xen ELF notes. */ -#define ELFNOTE_NAME(_n_) ((const void*)(_n_) + sizeof(*(_n_))) +#define ELFNOTE_NAME(_n_) ((const char*)(_n_) + sizeof(*(_n_))) #define ELFNOTE_DESC(_n_) (ELFNOTE_NAME(_n_) + (((_n_)->namesz+3)&~3)) #define ELFNOTE_NEXT(_n_) (ELFNOTE_DESC(_n_) + (((_n_)->descsz+3)&~3)) @@ -115,7 +115,7 @@ static int is_xen_elfnote_section(const for ( note = (const Elf_Note *)(image + shdr->sh_offset); note < (const Elf_Note *)(image + shdr->sh_offset + shdr->sh_size); - note = ELFNOTE_NEXT(note) ) + note = (const Elf_Note *)ELFNOTE_NEXT(note) ) { if ( !strncmp(ELFNOTE_NAME(note), "Xen", 4) ) return 1; @@ -134,7 +134,7 @@ static const Elf_Note *xen_elfnote_looku for ( note = (const Elf_Note *)dsi->__elfnote_section; note < (const Elf_Note *)dsi->__elfnote_section_end; - note = ELFNOTE_NEXT(note) ) + note = (const Elf_Note *)ELFNOTE_NEXT(note) ) { if ( strncmp(ELFNOTE_NAME(note), "Xen", 4) ) continue; @@ -227,9 +227,9 @@ int parseelfimage(struct domain_setup_in image + ehdr->e_shoff + (h*ehdr->e_shentsize)); if ( !is_xen_elfnote_section(image, shdr) ) continue; - dsi->__elfnote_section = (const void *)image + shdr->sh_offset; + dsi->__elfnote_section = (const char *)image + shdr->sh_offset; dsi->__elfnote_section_end = - (const void *)image + shdr->sh_offset + shdr->sh_size; + (const char *)image + shdr->sh_offset + shdr->sh_size; break; } diff -r 3c8bb086025e -r 9a0b157a0ab0 xen/include/xen/bitmap.h --- a/xen/include/xen/bitmap.h Fri Jan 19 14:48:57 2007 +0000 +++ b/xen/include/xen/bitmap.h Fri Jan 19 15:11:44 2007 +0000 @@ -251,6 +251,9 @@ static inline void bitmap_shift_left(uns __bitmap_shift_left(dst, src, n, nbits); } +void bitmap_long_to_byte(uint8_t *bp, const unsigned long *lp, int nbits); +void bitmap_byte_to_long(unsigned long *lp, const uint8_t *bp, int nbits); + #endif /* __ASSEMBLY__ */ #endif /* __XEN_BITMAP_H */ _______________________________________________ Xen-changelog mailing list Xen-changelog@xxxxxxxxxxxxxxxxxxx http://lists.xensource.com/xen-changelog
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |