Module: xenomai-2.6 Branch: master Commit: 700b7374db69700eb739032a588472714a6c54f0 URL: http://git.xenomai.org/?p=xenomai-2.6.git;a=commit;h=700b7374db69700eb739032a588472714a6c54f0
Author: Philippe Gerum <r...@xenomai.org> Date: Wed May 2 10:17:11 2012 +0200 nucleus: enable back PREEMPT_RT support --- include/asm-generic/wrappers.h | 6 ++++- ksrc/arch/generic/compat.c | 2 +- ksrc/arch/generic/hal.c | 48 ++++++++++++++++++++++++++++++++++++++++ ksrc/drivers/can/rtcan_dev.c | 2 +- ksrc/nucleus/pipe.c | 13 +++++----- ksrc/nucleus/registry.c | 2 +- ksrc/nucleus/shadow.c | 2 +- 7 files changed, 63 insertions(+), 12 deletions(-) diff --git a/include/asm-generic/wrappers.h b/include/asm-generic/wrappers.h index 407c203..af927b5 100644 --- a/include/asm-generic/wrappers.h +++ b/include/asm-generic/wrappers.h @@ -637,7 +637,11 @@ static inline void wrap_proc_dir_entry_owner(struct proc_dir_entry *entry) #ifndef DEFINE_SEMAPHORE /* Legacy DECLARE_MUTEX vanished in 2.6.37 */ -#define DEFINE_SEMAPHORE(sem) DECLARE_MUTEX(sem) +#define DEFINE_BINARY_SEMAPHORE(sem) DECLARE_MUTEX(sem) +#elif CONFIG_PREEMPT_RT +#define DEFINE_BINARY_SEMAPHORE(sem) DEFINE_SEMAPHORE(sem, 1) +#else +#define DEFINE_BINARY_SEMAPHORE(sem) DEFINE_SEMAPHORE(sem) #endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37) && defined(CONFIG_GENERIC_HARDIRQS) diff --git a/ksrc/arch/generic/compat.c b/ksrc/arch/generic/compat.c index 0e83095..8af69da 100644 --- a/ksrc/arch/generic/compat.c +++ b/ksrc/arch/generic/compat.c @@ -20,7 +20,7 @@ struct kthread_stop_block { int ret; }; -static DEFINE_SEMAPHORE(kthread_stop_sem); +static DEFINE_BINARY_SEMAPHORE(kthread_stop_sem); static struct kthread_stop_block kthread_stop_info; diff --git a/ksrc/arch/generic/hal.c b/ksrc/arch/generic/hal.c index 79466f8..438e09c 100644 --- a/ksrc/arch/generic/hal.c +++ b/ksrc/arch/generic/hal.c @@ -493,6 +493,46 @@ void rthal_apc_free(int apc) clear_bit(apc, &rthal_apc_map); } +#ifdef CONFIG_PREEMPT_RT + +static inline int setup_apc_handler(void) +{ + int cpu; + + for_each_online_cpu(cpu) { + rthal_apc_servers[cpu] = + kthread_create(rthal_apc_thread, + (void *)(unsigned long)cpu, + "apc/%d", cpu); + if (rthal_apc_servers[cpu] == NULL) + return -ENOMEM; + wake_up_process(rthal_apc_servers[cpu]); + } + + return 0; +} + +static inline void cleanup_apc_handler(void) +{ + int cpu; + + for_each_online_cpu(cpu) { + if (rthal_apc_servers[cpu]) + kthread_stop(rthal_apc_servers[cpu]); + } +} + +#else /* !CONFIG_PREEMPT_RT */ + +static inline int setup_apc_handler(void) +{ + return 0; +} + +static inline void cleanup_apc_handler(void) { } + +#endif /* !CONFIG_PREEMPT_RT */ + int rthal_init(void) { int err; @@ -548,6 +588,10 @@ int rthal_init(void) goto out_free_irq; } + err = setup_apc_handler(); + if (err) + goto fail; + err = rthal_register_domain(&rthal_domain, "Xenomai", RTHAL_DOMAIN_ID, @@ -575,6 +619,8 @@ int rthal_init(void) rthal_virtualize_irq(rthal_current_domain, rthal_apc_virq, NULL, NULL, NULL, 0); + cleanup_apc_handler(); + out_free_irq: rthal_free_virq(rthal_apc_virq); @@ -593,6 +639,8 @@ void rthal_exit(void) rthal_free_virq(rthal_apc_virq); } + cleanup_apc_handler(); + if (rthal_init_done) rthal_unregister_domain(&rthal_domain); diff --git a/ksrc/drivers/can/rtcan_dev.c b/ksrc/drivers/can/rtcan_dev.c index c3e9e5e..c53dddf 100644 --- a/ksrc/drivers/can/rtcan_dev.c +++ b/ksrc/drivers/can/rtcan_dev.c @@ -38,7 +38,7 @@ static rtdm_lock_t rtcan_devices_rt_lock = RTDM_LOCK_UNLOCKED; static int rtcan_global_init_done; -DEFINE_SEMAPHORE(rtcan_devices_nrt_lock); +DEFINE_BINARY_SEMAPHORE(rtcan_devices_nrt_lock); /* Spinlock for all reception lists and also for some members in * struct rtcan_socket */ diff --git a/ksrc/nucleus/pipe.c b/ksrc/nucleus/pipe.c index 1d5e39a..064aa52 100644 --- a/ksrc/nucleus/pipe.c +++ b/ksrc/nucleus/pipe.c @@ -174,14 +174,14 @@ static void xnpipe_wakeup_proc(void *cookie) xnlock_get_irqsave(&nklock, s); } } -#ifdef CONFIG_SMP +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT) /* - * A waiter may have entered/left the queue - * from another CPU, so we need to refetch the - * sleep queue head to be safe. + * Assume a waiter might have entered/left the + * queue, so we need to refetch the sleep + * queue head to be safe. */ nh = getheadq(&xnpipe_sleepq); -#endif /* CONFIG_SMP */ +#endif } } @@ -190,7 +190,6 @@ static void xnpipe_wakeup_proc(void *cookie) * subscribers. */ nh = getheadq(&xnpipe_asyncq); - while ((h = nh) != NULL) { nh = nextq(&xnpipe_asyncq, h); state = link2xnpipe(h, alink); @@ -200,7 +199,7 @@ static void xnpipe_wakeup_proc(void *cookie) xnlock_put_irqrestore(&nklock, s); kill_fasync(&state->asyncq, xnpipe_asyncsig, POLL_IN); xnlock_get_irqsave(&nklock, s); -#ifdef CONFIG_SMP +#if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT_RT) nh = getheadq(&xnpipe_asyncq); #endif } diff --git a/ksrc/nucleus/registry.c b/ksrc/nucleus/registry.c index 6f505dd..eceadad 100644 --- a/ksrc/nucleus/registry.c +++ b/ksrc/nucleus/registry.c @@ -223,7 +223,7 @@ void xnregistry_cleanup(void) #ifdef CONFIG_XENO_OPT_VFILE -static DEFINE_SEMAPHORE(export_mutex); +static DEFINE_BINARY_SEMAPHORE(export_mutex); /* * The following stuff implements the mechanism for delegating diff --git a/ksrc/nucleus/shadow.c b/ksrc/nucleus/shadow.c index 835ac3a..05b7a1b 100644 --- a/ksrc/nucleus/shadow.c +++ b/ksrc/nucleus/shadow.c @@ -113,7 +113,7 @@ static int nucleus_muxid = -1; static struct semaphore completion_mutex; -static DEFINE_SEMAPHORE(registration_mutex); +static DEFINE_BINARY_SEMAPHORE(registration_mutex); static inline struct task_struct *get_switch_lock_owner(void) { _______________________________________________ Xenomai-git mailing list Xenomai-git@gna.org https://mail.gna.org/listinfo/xenomai-git