From 3943db776371b40e0c93e1244669bc9b78f8bbf1 Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Wed, 18 Oct 2006 14:46:48 +0100 Subject: [PATCH] [XEN] Can be built -std=gnu99 (except for .S files). Need to be careful with static initialisers: 1. *_LOCK_UNLOCKED, CPU_MASK_* no longer include a cast 2. Dynamic uses of the above are replaced by appropriate function invocations. Signed-off-by: Keir Fraser --- Config.mk | 2 ++ xen/Rules.mk | 10 ++++++++-- xen/acm/acm_core.c | 2 +- xen/arch/ia64/Rules.mk | 2 -- xen/arch/ia64/linux-xen/smpboot.c | 3 ++- xen/arch/powerpc/Makefile | 2 +- xen/arch/x86/Makefile | 2 +- xen/arch/x86/io_apic.c | 9 +++------ xen/arch/x86/irq.c | 2 +- xen/arch/x86/oprofile/xenoprof.c | 2 +- xen/common/domain.c | 2 +- xen/common/page_alloc.c | 2 +- xen/common/schedule.c | 2 +- xen/drivers/char/console.c | 2 +- xen/drivers/char/serial.c | 4 ++-- xen/include/asm-ia64/linux-xen/asm/spinlock.h | 6 +++--- xen/include/asm-powerpc/spinlock.h | 12 ++++++------ xen/include/asm-x86/spinlock.h | 8 ++++---- xen/include/xen/cpumask.h | 8 ++++---- xen/include/xen/spinlock.h | 8 ++++---- 20 files changed, 47 insertions(+), 43 deletions(-) diff --git a/Config.mk b/Config.mk index 4f1b1f7c1a..e626a26283 100644 --- a/Config.mk +++ b/Config.mk @@ -34,6 +34,8 @@ else CFLAGS += -g endif +CFLAGS += -std=gnu99 + CFLAGS += -Wall -Wstrict-prototypes # -Wunused-value makes GCC 4.x too aggressive for my taste: ignoring the diff --git a/xen/Rules.mk b/xen/Rules.mk index b3ae01dfc2..1522ba786b 100644 --- a/xen/Rules.mk +++ b/xen/Rules.mk @@ -63,8 +63,13 @@ endif AFLAGS-y += -D__ASSEMBLY__ ALL_OBJS := $(ALL_OBJS-y) + CFLAGS := $(strip $(CFLAGS) $(CFLAGS-y)) + +# Most CFLAGS are safe for assembly files: +# -std=gnu{89,99} gets confused by #-prefixed end-of-line comments AFLAGS := $(strip $(AFLAGS) $(AFLAGS-y)) +AFLAGS += $(patsubst -std=gnu%,,$(CFLAGS)) include Makefile @@ -102,10 +107,11 @@ _clean_%/: FORCE $(CC) $(CFLAGS) -c $< -o $@ %.o: %.S $(HDRS) Makefile - $(CC) $(CFLAGS) $(AFLAGS) -c $< -o $@ + $(CC) $(AFLAGS) -c $< -o $@ %.i: %.c $(HDRS) Makefile $(CPP) $(CFLAGS) $< -o $@ +# -std=gnu{89,99} gets confused by # as an end-of-line comment marker %.s: %.S $(HDRS) Makefile - $(CPP) $(CFLAGS) $(AFLAGS) $< -o $@ + $(CPP) $(AFLAGS) $< -o $@ diff --git a/xen/acm/acm_core.c b/xen/acm/acm_core.c index bafb177c3d..242b5c82f4 100644 --- a/xen/acm/acm_core.c +++ b/xen/acm/acm_core.c @@ -60,7 +60,7 @@ struct acm_operations *acm_secondary_ops = NULL; /* acm global binary policy (points to 'local' primary and secondary policies */ struct acm_binary_policy acm_bin_pol; /* acm binary policy lock */ -rwlock_t acm_bin_pol_rwlock = RW_LOCK_UNLOCKED; +DEFINE_RWLOCK(acm_bin_pol_rwlock); /* until we have endian support in Xen, we discover it at runtime */ u8 little_endian = 1; diff --git a/xen/arch/ia64/Rules.mk b/xen/arch/ia64/Rules.mk index 3c8663c90b..944d8d018e 100644 --- a/xen/arch/ia64/Rules.mk +++ b/xen/arch/ia64/Rules.mk @@ -13,8 +13,6 @@ endif # Used only by linux/Makefile. AFLAGS_KERNEL += -mconstant-gp -nostdinc $(CPPFLAGS) -# Note: .S -> .o rule uses AFLAGS and CFLAGS. - CFLAGS += -nostdinc -fno-builtin -fno-common -fno-strict-aliasing CFLAGS += -mconstant-gp #CFLAGS += -O3 # -O3 over-inlines making debugging tough! diff --git a/xen/arch/ia64/linux-xen/smpboot.c b/xen/arch/ia64/linux-xen/smpboot.c index ac96fb8cc9..4450ce9260 100644 --- a/xen/arch/ia64/linux-xen/smpboot.c +++ b/xen/arch/ia64/linux-xen/smpboot.c @@ -650,7 +650,8 @@ clear_cpu_sibling_map(int cpu) for_each_cpu_mask(i, cpu_core_map[cpu]) cpu_clear(cpu, cpu_core_map[i]); - cpu_sibling_map[cpu] = cpu_core_map[cpu] = CPU_MASK_NONE; + cpus_clear(cpu_sibling_map[cpu]); + cpus_clear(cpu_core_map[cpu]); } static void diff --git a/xen/arch/powerpc/Makefile b/xen/arch/powerpc/Makefile index 837364acc1..5db65c2c7c 100644 --- a/xen/arch/powerpc/Makefile +++ b/xen/arch/powerpc/Makefile @@ -141,7 +141,7 @@ asm-offsets.s: $(TARGET_SUBARCH)/asm-offsets.c $(HDRS) $(CC) $(CFLAGS) -S -o $@ $< xen.lds: xen.lds.S $(HDRS) - $(CC) $(CFLAGS) -P -E $(AFLAGS) -o $@ $< + $(CC) -P -E $(AFLAGS) -o $@ $< dom0.bin: $(DOM0_IMAGE) cp $< $@ diff --git a/xen/arch/x86/Makefile b/xen/arch/x86/Makefile index e8b1dd02e8..31f2793fb9 100644 --- a/xen/arch/x86/Makefile +++ b/xen/arch/x86/Makefile @@ -69,7 +69,7 @@ asm-offsets.s: $(TARGET_SUBARCH)/asm-offsets.c $(HDRS) $(CC) $(CFLAGS) -S -o $@ $< xen.lds: $(TARGET_SUBARCH)/xen.lds.S $(HDRS) - $(CC) $(CFLAGS) -P -E -Ui386 $(AFLAGS) -o $@ $< + $(CC) -P -E -Ui386 $(AFLAGS) -o $@ $< boot/mkelf32: boot/mkelf32.c $(HOSTCC) $(HOSTCFLAGS) -o $@ $< diff --git a/xen/arch/x86/io_apic.c b/xen/arch/x86/io_apic.c index 9a86c040d0..4b30851276 100644 --- a/xen/arch/x86/io_apic.c +++ b/xen/arch/x86/io_apic.c @@ -269,13 +269,10 @@ static void set_ioapic_affinity_irq(unsigned int irq, cpumask_t cpumask) int pin; struct irq_pin_list *entry = irq_2_pin + irq; unsigned int apicid_value; - cpumask_t tmp; - - cpus_and(tmp, cpumask, cpu_online_map); - if (cpus_empty(tmp)) - tmp = TARGET_CPUS; - cpus_and(cpumask, tmp, CPU_MASK_ALL); + cpus_and(cpumask, cpumask, cpu_online_map); + if (cpus_empty(cpumask)) + cpumask = TARGET_CPUS; apicid_value = cpu_mask_to_apicid(cpumask); /* Prepare to do the io_apic_write */ diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c index 4fa637ad01..4bad3ee23e 100644 --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -450,7 +450,7 @@ int pirq_guest_bind(struct vcpu *v, int irq, int will_share) action->in_flight = 0; action->shareable = will_share; action->ack_type = pirq_acktype(irq); - action->cpu_eoi_map = CPU_MASK_NONE; + cpus_clear(action->cpu_eoi_map); desc->depth = 0; desc->status |= IRQ_GUEST; diff --git a/xen/arch/x86/oprofile/xenoprof.c b/xen/arch/x86/oprofile/xenoprof.c index eca1f03d96..f60656ba8c 100644 --- a/xen/arch/x86/oprofile/xenoprof.c +++ b/xen/arch/x86/oprofile/xenoprof.c @@ -14,7 +14,7 @@ #define MAX_OPROF_SHARED_PAGES 32 /* Lock protecting the following global state */ -static spinlock_t xenoprof_lock = SPIN_LOCK_UNLOCKED; +static DEFINE_SPINLOCK(xenoprof_lock); struct domain *active_domains[MAX_OPROF_DOMAINS]; int active_ready[MAX_OPROF_DOMAINS]; diff --git a/xen/common/domain.c b/xen/common/domain.c index 2dde26eb75..f96becc578 100644 --- a/xen/common/domain.c +++ b/xen/common/domain.c @@ -27,7 +27,7 @@ #include /* Both these structures are protected by the domlist_lock. */ -rwlock_t domlist_lock = RW_LOCK_UNLOCKED; +DEFINE_RWLOCK(domlist_lock); struct domain *domain_hash[DOMAIN_HASH_SIZE]; struct domain *domain_list; diff --git a/xen/common/page_alloc.c b/xen/common/page_alloc.c index 70aab2799b..fbbe837780 100644 --- a/xen/common/page_alloc.c +++ b/xen/common/page_alloc.c @@ -704,7 +704,7 @@ void free_domheap_pages(struct page_info *pg, unsigned int order) { /* Freeing anonymous domain-heap pages. */ for ( i = 0; i < (1 << order); i++ ) - pg[i].u.free.cpumask = CPU_MASK_NONE; + cpus_clear(pg[i].u.free.cpumask); free_heap_pages(pfn_dom_zone_type(page_to_mfn(pg)), pg, order); drop_dom_ref = 0; } diff --git a/xen/common/schedule.c b/xen/common/schedule.c index b7ed65aa4c..fc2a927e2b 100644 --- a/xen/common/schedule.c +++ b/xen/common/schedule.c @@ -113,7 +113,7 @@ int sched_init_vcpu(struct vcpu *v, unsigned int processor) if ( is_idle_domain(d) || ((d->domain_id == 0) && opt_dom0_vcpus_pin) ) v->cpu_affinity = cpumask_of_cpu(processor); else - v->cpu_affinity = CPU_MASK_ALL; + cpus_setall(v->cpu_affinity); /* Initialise the per-domain timers. */ init_timer(&v->timer, vcpu_timer_fn, v, v->processor); diff --git a/xen/drivers/char/console.c b/xen/drivers/char/console.c index c3e17efe72..b43f8eafc7 100644 --- a/xen/drivers/char/console.c +++ b/xen/drivers/char/console.c @@ -418,7 +418,7 @@ void console_endboot(void) void console_force_unlock(void) { - console_lock = SPIN_LOCK_UNLOCKED; + spin_lock_init(&console_lock); serial_force_unlock(sercon_handle); console_start_sync(); } diff --git a/xen/drivers/char/serial.c b/xen/drivers/char/serial.c index 024de30ae9..cd909a6cef 100644 --- a/xen/drivers/char/serial.c +++ b/xen/drivers/char/serial.c @@ -295,8 +295,8 @@ void serial_force_unlock(int handle) if ( handle == -1 ) return; - port->rx_lock = SPIN_LOCK_UNLOCKED; - port->tx_lock = SPIN_LOCK_UNLOCKED; + spin_lock_init(&port->rx_lock); + spin_lock_init(&port->tx_lock); serial_start_sync(handle); } diff --git a/xen/include/asm-ia64/linux-xen/asm/spinlock.h b/xen/include/asm-ia64/linux-xen/asm/spinlock.h index 1c2034c80d..129fbf5156 100644 --- a/xen/include/asm-ia64/linux-xen/asm/spinlock.h +++ b/xen/include/asm-ia64/linux-xen/asm/spinlock.h @@ -33,7 +33,7 @@ typedef struct { #endif } spinlock_t; -#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 } +#define SPIN_LOCK_UNLOCKED /*(spinlock_t)*/ { 0 } #define spin_lock_init(x) ((x)->lock = 0) #ifdef ASM_SUPPORTED @@ -136,9 +136,9 @@ typedef struct { unsigned int break_lock; #endif } rwlock_t; -#define RW_LOCK_UNLOCKED (rwlock_t) { 0, 0 } +#define RW_LOCK_UNLOCKED /*(rwlock_t)*/ { 0, 0 } -#define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0) +#define rwlock_init(x) do { *(x) = (rwlock_t) RW_LOCK_UNLOCKED; } while(0) #define read_can_lock(rw) (*(volatile int *)(rw) >= 0) #define write_can_lock(rw) (*(volatile int *)(rw) == 0) diff --git a/xen/include/asm-powerpc/spinlock.h b/xen/include/asm-powerpc/spinlock.h index f6574d6b76..e65e0f2bc0 100644 --- a/xen/include/asm-powerpc/spinlock.h +++ b/xen/include/asm-powerpc/spinlock.h @@ -81,10 +81,10 @@ typedef union { #define __UNLOCKED (0U) #define __LOCKED (~__UNLOCKED) -#define SPIN_LOCK_UNLOCKED (spinlock_t) { __UNLOCKED } +#define SPIN_LOCK_UNLOCKED /*(spinlock_t)*/ { __UNLOCKED } static inline void spin_lock_init(spinlock_t *lock) { - *lock = SPIN_LOCK_UNLOCKED; + *lock = (spinlock_t) SPIN_LOCK_UNLOCKED; } static inline int spin_is_locked(spinlock_t *lock) @@ -103,7 +103,7 @@ static inline void _raw_spin_lock(spinlock_t *lock) static inline void _raw_spin_unlock(spinlock_t *lock) { sync_before_release(); - *lock = SPIN_LOCK_UNLOCKED; + *lock = (spinlock_t) SPIN_LOCK_UNLOCKED; } static inline int _raw_spin_trylock(spinlock_t *lock) @@ -121,10 +121,10 @@ typedef struct { volatile unsigned int lock; } rwlock_t; -#define RW_LOCK_UNLOCKED (rwlock_t) { __UNLOCKED } +#define RW_LOCK_UNLOCKED /*(rwlock_t)*/ { __UNLOCKED } static inline void rwlock_init(rwlock_t *lock) { - *lock = RW_LOCK_UNLOCKED; + *lock = (rwlock_t) RW_LOCK_UNLOCKED; } static inline void _raw_read_lock(rwlock_t *lock) @@ -152,7 +152,7 @@ static inline void _raw_write_lock(rwlock_t *lock) static inline void _raw_write_unlock(rwlock_t *lock) { sync_before_release(); - *lock = RW_LOCK_UNLOCKED; + *lock = (rwlock_t) RW_LOCK_UNLOCKED; } static inline void _raw_read_unlock(rwlock_t *lock) diff --git a/xen/include/asm-x86/spinlock.h b/xen/include/asm-x86/spinlock.h index 1d864188da..8c148e0240 100644 --- a/xen/include/asm-x86/spinlock.h +++ b/xen/include/asm-x86/spinlock.h @@ -12,9 +12,9 @@ typedef struct { u8 recurse_cnt; } spinlock_t; -#define SPIN_LOCK_UNLOCKED (spinlock_t) { 1, -1, 0 } +#define SPIN_LOCK_UNLOCKED /*(spinlock_t)*/ { 1, -1, 0 } -#define spin_lock_init(x) do { *(x) = SPIN_LOCK_UNLOCKED; } while(0) +#define spin_lock_init(x) do { *(x) = (spinlock_t) SPIN_LOCK_UNLOCKED; } while(0) #define spin_is_locked(x) (*(volatile char *)(&(x)->lock) <= 0) static inline void _raw_spin_lock(spinlock_t *lock) @@ -89,9 +89,9 @@ typedef struct { volatile unsigned int lock; } rwlock_t; -#define RW_LOCK_UNLOCKED (rwlock_t) { RW_LOCK_BIAS } +#define RW_LOCK_UNLOCKED /*(rwlock_t)*/ { RW_LOCK_BIAS } -#define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0) +#define rwlock_init(x) do { *(x) = (rwlock_t) RW_LOCK_UNLOCKED; } while(0) /* * On x86, we implement read-write locks as a 32-bit counter diff --git a/xen/include/xen/cpumask.h b/xen/include/xen/cpumask.h index 997efb1d45..d9296201cb 100644 --- a/xen/include/xen/cpumask.h +++ b/xen/include/xen/cpumask.h @@ -239,14 +239,14 @@ static inline int __next_cpu(int n, const cpumask_t *srcp, int nbits) #if NR_CPUS <= BITS_PER_LONG #define CPU_MASK_ALL \ -(cpumask_t) { { \ +/*(cpumask_t)*/ { { \ [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \ } } #else #define CPU_MASK_ALL \ -(cpumask_t) { { \ +/*(cpumask_t)*/ { { \ [0 ... BITS_TO_LONGS(NR_CPUS)-2] = ~0UL, \ [BITS_TO_LONGS(NR_CPUS)-1] = CPU_MASK_LAST_WORD \ } } @@ -254,12 +254,12 @@ static inline int __next_cpu(int n, const cpumask_t *srcp, int nbits) #endif #define CPU_MASK_NONE \ -(cpumask_t) { { \ +/*(cpumask_t)*/ { { \ [0 ... BITS_TO_LONGS(NR_CPUS)-1] = 0UL \ } } #define CPU_MASK_CPU0 \ -(cpumask_t) { { \ +/*(cpumask_t)*/ { { \ [0] = 1UL \ } } diff --git a/xen/include/xen/spinlock.h b/xen/include/xen/spinlock.h index 73184daad8..11f83119d4 100644 --- a/xen/include/xen/spinlock.h +++ b/xen/include/xen/spinlock.h @@ -42,10 +42,10 @@ #if (__GNUC__ > 2) typedef struct { } spinlock_t; -#define SPIN_LOCK_UNLOCKED (spinlock_t) { } +#define SPIN_LOCK_UNLOCKED /*(spinlock_t)*/ { } #else typedef struct { int gcc_is_buggy; } spinlock_t; -#define SPIN_LOCK_UNLOCKED (spinlock_t) { 0 } +#define SPIN_LOCK_UNLOCKED /*(spinlock_t)*/ { 0 } #endif #define spin_lock_init(lock) do { } while(0) @@ -58,10 +58,10 @@ typedef struct { int gcc_is_buggy; } spinlock_t; #if (__GNUC__ > 2) typedef struct { } rwlock_t; -#define RW_LOCK_UNLOCKED (rwlock_t) { } +#define RW_LOCK_UNLOCKED /*(rwlock_t)*/ { } #else typedef struct { int gcc_is_buggy; } rwlock_t; -#define RW_LOCK_UNLOCKED (rwlock_t) { 0 } +#define RW_LOCK_UNLOCKED /*(rwlock_t)*/ { 0 } #endif #define rwlock_init(lock) do { } while(0) -- 2.30.2