Module: xenomai-3 Branch: next Commit: 7ccda01bf400a5ca802b7b0d1399e3bebb8bcc05 URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=7ccda01bf400a5ca802b7b0d1399e3bebb8bcc05
Author: Philippe Gerum <r...@xenomai.org> Date: Fri Jul 3 10:00:25 2015 +0200 cobalt/thread: introduce local information flags thread->local_info receives information bits which may be updated only by the thread concerned. Therefore, there is no need for serialization when changing this data. --- include/cobalt/kernel/thread.h | 18 +++++++++++++++++- include/cobalt/uapi/kernel/thread.h | 13 ++++++++----- kernel/cobalt/sched.c | 4 ++-- kernel/cobalt/thread.c | 29 ++++++++++++++++------------- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/include/cobalt/kernel/thread.h b/include/cobalt/kernel/thread.h index cc2e32c..ef7de04 100644 --- a/include/cobalt/kernel/thread.h +++ b/include/cobalt/kernel/thread.h @@ -85,10 +85,11 @@ struct xnthread_personality { }; struct xnthread { - struct xnarchtcb tcb; /* Architecture-dependent block */ + struct xnarchtcb tcb; /* Architecture-dependent block */ __u32 state; /* Thread state flags */ __u32 info; /* Thread information flags */ + __u32 local_info; /* Local thread information flags */ struct xnsched *sched; /* Thread scheduler */ struct xnsched_class *sched_class; /* Current scheduling class */ @@ -222,6 +223,21 @@ static inline void xnthread_clear_info(struct xnthread *thread, int bits) thread->info &= ~bits; } +static inline int xnthread_test_localinfo(struct xnthread *curr, int bits) +{ + return curr->local_info & bits; +} + +static inline void xnthread_set_localinfo(struct xnthread *curr, int bits) +{ + curr->local_info |= bits; +} + +static inline void xnthread_clear_localinfo(struct xnthread *curr, int bits) +{ + curr->local_info &= ~bits; +} + static inline struct xnarchtcb *xnthread_archtcb(struct xnthread *thread) { return &thread->tcb; diff --git a/include/cobalt/uapi/kernel/thread.h b/include/cobalt/uapi/kernel/thread.h index 6c714f7..5606d52 100644 --- a/include/cobalt/uapi/kernel/thread.h +++ b/include/cobalt/uapi/kernel/thread.h @@ -27,7 +27,7 @@ * @{ */ -/* State flags */ +/* State flags (shared) */ #define XNSUSP 0x00000001 /**< Suspended. */ #define XNPEND 0x00000002 /**< Sleep-wait for a resource. */ @@ -61,7 +61,7 @@ * @{ */ -/* Information flags */ +/* Information flags (shared) */ #define XNTIMEO 0x00000001 /**< Woken up due to a timeout condition */ #define XNRMID 0x00000002 /**< Pending on a removed resource */ @@ -70,9 +70,12 @@ #define XNWAKEN 0x00000010 /**< Thread waken up upon resource availability */ #define XNROBBED 0x00000020 /**< Robbed from resource ownership */ #define XNCANCELD 0x00000040 /**< Cancellation request is pending */ -#define XNMOVED 0x00000080 /**< CPU migration in primary mode occurred */ -#define XNPIALERT 0x00001000 /**< Priority inversion alert (SIGDEBUG sent) */ -#define XNLBALERT 0x00002000 /**< Scheduler lock break alert (SIGDEBUG sent) */ +#define XNPIALERT 0x00000080 /**< Priority inversion alert (SIGDEBUG sent) */ + +/* Local information flags (private to current thread) */ + +#define XNMOVED 0x00000001 /**< CPU migration in primary mode occurred */ +#define XNLBALERT 0x00000002 /**< Scheduler lock break alert (SIGDEBUG sent) */ /** @} */ diff --git a/kernel/cobalt/sched.c b/kernel/cobalt/sched.c index 73965e7..b9eff80 100644 --- a/kernel/cobalt/sched.c +++ b/kernel/cobalt/sched.c @@ -328,7 +328,7 @@ void ___xnsched_unlock(struct xnsched *sched) return; if (--curr->lock_count == 0) { - xnthread_clear_info(curr, XNLBALERT); + xnthread_clear_localinfo(curr, XNLBALERT); xnsched_run(); } } @@ -339,7 +339,7 @@ void ___xnsched_unlock_fully(struct xnsched *sched) struct xnthread *curr = sched->curr; curr->lock_count = 0; - xnthread_clear_info(curr, XNLBALERT); + xnthread_clear_localinfo(curr, XNLBALERT); xnsched_run(); } EXPORT_SYMBOL_GPL(___xnsched_unlock_fully); diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c index 541e8b1..5b00ad1 100644 --- a/kernel/cobalt/thread.c +++ b/kernel/cobalt/thread.c @@ -174,6 +174,7 @@ int __xnthread_init(struct xnthread *thread, thread->sched = sched; thread->state = flags; thread->info = 0; + thread->local_info = 0; thread->lock_count = 0; thread->rrperiod = XN_INFINITE; thread->wchan = NULL; @@ -983,9 +984,11 @@ out: return; lock_break: + /* NOTE: thread is current */ if (xnthread_test_state(thread, XNWARN) && - !xnthread_test_info(thread, XNLBALERT)) { - xnthread_set_info(thread, XNLBALERT | XNKICKED); + !xnthread_test_localinfo(thread, XNLBALERT)) { + xnthread_set_info(thread, XNKICKED); + xnthread_set_localinfo(thread, XNLBALERT); xnthread_signal(thread, SIGDEBUG, SIGDEBUG_LOCK_BREAK); } abort: @@ -1634,7 +1637,7 @@ EXPORT_SYMBOL_GPL(xnthread_join); */ int xnthread_migrate(int cpu) { - struct xnthread *thread; + struct xnthread *curr; struct xnsched *sched; int ret = 0; spl_t s; @@ -1646,20 +1649,20 @@ int xnthread_migrate(int cpu) goto unlock_and_exit; } - thread = xnthread_current(); - if (!cpu_isset(cpu, thread->affinity)) { + curr = xnthread_current(); + if (!cpu_isset(cpu, curr->affinity)) { ret = -EINVAL; goto unlock_and_exit; } sched = xnsched_struct(cpu); - if (sched == thread->sched) + if (sched == curr->sched) goto unlock_and_exit; - trace_cobalt_thread_migrate(thread, cpu); + trace_cobalt_thread_migrate(curr, cpu); /* Move to remote scheduler. */ - xnsched_migrate(thread, sched); + xnsched_migrate(curr, sched); /* * Migrate the thread's periodic timer. We don't have to care @@ -1667,19 +1670,19 @@ int xnthread_migrate(int cpu) * current thread, which is, well, running, so it can't be * sleeping on any timed wait at the moment. */ - __xntimer_migrate(&thread->ptimer, sched); + __xntimer_migrate(&curr->ptimer, sched); /* * Reset execution time measurement period so that we don't * mess up per-CPU statistics. */ - xnstat_exectime_reset_stats(&thread->stat.lastperiod); + xnstat_exectime_reset_stats(&curr->stat.lastperiod); /* * So that xnthread_relax() will pin the linux mate on the * same CPU next time the thread switches to secondary mode. */ - xnthread_set_info(thread, XNMOVED); + xnthread_set_localinfo(curr, XNMOVED); xnsched_run(); @@ -2040,8 +2043,8 @@ void xnthread_relax(int notify, int reason) xnthread_sync_window(thread); #ifdef CONFIG_SMP - if (xnthread_test_info(thread, XNMOVED)) { - xnthread_clear_info(thread, XNMOVED); + if (xnthread_test_localinfo(thread, XNMOVED)) { + xnthread_clear_localinfo(thread, XNMOVED); cpu = xnsched_cpu(thread->sched); set_cpus_allowed(p, cpumask_of_cpu(cpu)); } _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://xenomai.org/mailman/listinfo/xenomai-git