From 88fed09b126f1b2e8d85fc834e09b734661b539c Mon Sep 17 00:00:00 2001 From: Glenn Elliott Date: Mon, 12 Jul 2010 13:03:42 -0400 Subject: Restructure pi_semaphore struct for generic inheritance framework. First patch in a series to implement a generic priority inheritance framework that can be used by semaphores that use priority inheritance. This patch makes pi_semaphore a 'base class' for pi-protocols. pi_semaphore is updated to include a pi_sem_record field named stack_node. This stack_node is a linked-list node that a task holding the pi_semaphore instance adds to their semaphore stack. Note that the task's semaphore stack (or linked-list) simply chains stack_node's of held semaphores into a single linked-list. This is safe since there is only one semaphore holder at any given moment. Finally, FMLP-specific data members out to child class fmlp_semaphore. --- include/litmus/fdso.h | 2 +- include/litmus/rt_param.h | 22 ++++++++++++++++++++++ include/litmus/sched_plugin.h | 29 +++++++++++++++++++++++++---- litmus/Kconfig | 8 ++++++++ 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/include/litmus/fdso.h b/include/litmus/fdso.h index 61f1b5baf42c..b0e62a9098bd 100644 --- a/include/litmus/fdso.h +++ b/include/litmus/fdso.h @@ -62,7 +62,7 @@ static inline void* od_lookup(int od, obj_type_t type) return e && e->obj->type == type ? e->obj->obj : NULL; } -#define lookup_fmlp_sem(od)((struct pi_semaphore*) od_lookup(od, FMLP_SEM)) +#define lookup_fmlp_sem(od)((struct fmlp_semaphore*) od_lookup(od, FMLP_SEM)) #define lookup_srp_sem(od) ((struct srp_semaphore*) od_lookup(od, SRP_SEM)) #define lookup_ics(od) ((struct ics*) od_lookup(od, ICS_ID)) diff --git a/include/litmus/rt_param.h b/include/litmus/rt_param.h index a7a183f34a80..6f40b52f0802 100644 --- a/include/litmus/rt_param.h +++ b/include/litmus/rt_param.h @@ -92,6 +92,28 @@ struct rt_job { unsigned int job_no; }; +#ifdef CONFIG_PI_SEMAPHORES +/* Record for storing a held lock and associated priority inheritance. + * Records are stored in a linked-list stack to support priority + * inheritance of nested critical sections. + * + * When strung together in a stack, nodes provide a record + * of currently held semaphores and order in which they were + * acquired. + */ +struct pi_sem_record { + /* Pointer to inheritance-donating job. + * May be set to "self" if there is no active + * inheritance from this semaphore. + */ + struct task_struct *inh_task; + + struct list_head list; +}; + +typedef struct pi_sem_record pi_sem_record_t; +#endif + struct pfair_param; /* RT task parameters for scheduling extensions diff --git a/include/litmus/sched_plugin.h b/include/litmus/sched_plugin.h index 9c1c9f28ba79..071e809564b2 100644 --- a/include/litmus/sched_plugin.h +++ b/include/litmus/sched_plugin.h @@ -7,6 +7,7 @@ #include +#ifdef CONFIG_PI_SEMAPHORES /* struct for semaphore with priority inheritance */ struct pi_semaphore { atomic_t count; @@ -17,10 +18,29 @@ struct pi_semaphore { struct task_struct *task; struct task_struct* cpu_task[NR_CPUS]; } hp; + + /* lock stack */ + struct pi_sem_record stack_node; +}; + +static inline struct pi_semaphore* to_pi(void *sem) { + return (struct pi_semaphore*)sem; +} +#endif + +#ifdef CONFIG_FMLP +struct fmlp_semaphore { + struct pi_semaphore pi; /* must always be first. */ + /* current lock holder */ struct task_struct *holder; }; +static inline struct fmlp_semaphore* to_fmlp(struct pi_semaphore* sem) { + return (struct fmlp_semaphore*)sem; +} +#endif + /************************ setup/tear down ********************/ typedef long (*activate_plugin_t) (void); @@ -63,6 +83,7 @@ typedef void (*task_block_t) (struct task_struct *task); */ typedef void (*task_exit_t) (struct task_struct *); +#ifdef CONFIG_PI_SEMAPHORES /* Called when the new_owner is released from the wait queue * it should now inherit the priority from sem, _before_ it gets readded * to any queue @@ -79,7 +100,7 @@ typedef long (*return_priority_t) (struct pi_semaphore *sem); * priority is higher than that of the current holder. */ typedef long (*pi_block_t) (struct pi_semaphore *sem, struct task_struct *t); - +#endif @@ -124,9 +145,9 @@ struct sched_plugin { #ifdef CONFIG_FMLP /* priority inheritance */ unsigned int fmlp_active; - inherit_priority_t inherit_priority; - return_priority_t return_priority; - pi_block_t pi_block; + inherit_priority_t fmlp_inherit_priority; + return_priority_t fmlp_return_priority; + pi_block_t fmlp_pi_block; #endif } __attribute__ ((__aligned__(SMP_CACHE_BYTES))); diff --git a/litmus/Kconfig b/litmus/Kconfig index 9888589ef126..e00887e672df 100644 --- a/litmus/Kconfig +++ b/litmus/Kconfig @@ -58,9 +58,17 @@ config SRP Say Yes if you want FMLP local long critical section synchronization support. +config PI_SEMAPHORES + bool "Semaphores with Priority Inheritance" + default n + help + Generalized support for all Litmus priority inheriting semaphore + protocols. + config FMLP bool "FMLP support" depends on NP_SECTION + depends on PI_SEMAPHORES default n help Include support for deterministic multiprocessor real-time -- cgit v1.2.2