workqueue: prepare for concurrency managed workqueue, take#3
Tejun Heo
maintainerPATCH 9/14 workqueue: misc/cosmetic updates
In reply to Tejun HeoMake the following updates in preparation of concurrency managed workqueue. None of these changes causes any visible behavior difference.
* Add comments and adjust indentations to data structures and several functions.
* Rename wq_per_cpu() to get_cwq() and swap the position of two parameters for consistency. Convert a direct per_cpu_ptr() access to wq->cpu_wq to get_cwq().
* Add work_static() and Update set_wq_data() such that it sets the flags part to WORK_STRUCT_PENDING | WORK_STRUCT_STATIC if static | @extra_flags.
* Move santiy check on work->entry emptiness from queue_work_on() to __queue_work() which all queueing paths share.
* Make __queue_work() take @cpu and @wq instead of @cwq.
* Restructure flush_work() and __create_workqueue_key() to make them easier to modify.
--- include/linux/workqueue.h | 5 ++ kernel/workqueue.c | 127 +++++++++++++++++++++++++++++---------------- 2 files changed, 88 insertions(+), 44 deletions(-)
include/linux/workqueue.h +5 -0
@@ -96,9 +96,14 @@ struct execute_work {#ifdef CONFIG_DEBUG_OBJECTS_WORK extern void __init_work (struct work_struct *work,int onstack);extern void destroy_work_on_stack (struct work_struct *work); +static inline bool work_static (struct work_struct *work) +{ +return test_bit (WORK_STRUCT_STATIC ,work_data_bits (work)); +}#else static inline void __init_work (struct work_struct *work,int onstack) { }static inline void destroy_work_on_stack (struct work_struct *work) { } +static inline bool work_static (struct work_struct *work) {return false; }#endif /*
kernel/workqueue.c +83 -44
282 lines not on this page · raw message
Signature · 1 line
1.6.5.3
Tejun Heo
maintainerPATCH 7/14 acpi: use queue_work_on() instead of binding workqueue worker to cpu0
In reply to Tejun HeoACPI works need to be executed on cpu0 and acpi/osl.c achieves this by creating singlethread workqueue and then binding it to cpu0 from a work which is quite unorthodox. Make it create regular workqueues and use queue_work_on() instead. This is in preparation of concurrency managed workqueue and the extra workers won't be a problem after it's implemented.
--- drivers/acpi/osl.c | 41 ++++++++++++----------------------------- 1 files changed, 12 insertions(+), 29 deletions(-)
drivers/acpi/osl.c +12 -29
@@ -191,36 +191,11 @@ acpi_status __init acpi_os_initialize(void)return AE_OK ; } -static void bind_to_cpu0 (struct work_struct *work) -{ -set_cpus_allowed_ptr (current,cpumask_of (0 )); -kfree (work); -} - -static void bind_workqueue (struct workqueue_struct *wq) -{ -struct work_struct *work; - - work =kzalloc (sizeof (struct work_struct ),GFP_KERNEL ); -INIT_WORK (work, bind_to_cpu0); -queue_work (wq, work); -} -acpi_status acpi_os_initialize1 (void ) { -/* -* On some machines, a software-initiated SMI causes corruption unless -* the SMI runs on CPU 0. An SMI can be initiated by any AML, but -* typically it's done in GPE-related methods that are run via -* workqueues, so we can avoid the known corruption cases by binding -* the workqueues to CPU 0. -*/ - kacpid_wq =create_singlethread_workqueue ("kacpid" ); -bind_workqueue (kacpid_wq); - kacpi_notify_wq =create_singlethread_workqueue ("kacpi_notify" ); -bind_workqueue (kacpi_notify_wq); - kacpi_hotplug_wq =create_singlethread_workqueue ("kacpi_hotplug" ); -bind_workqueue (kacpi_hotplug_wq); + kacpid_wq =create_workqueue ("kacpid" ); + kacpi_notify_wq =create_workqueue ("kacpi_notify" ); + kacpi_hotplug_wq =create_workqueue ("kacpi_hotplug" );BUG_ON (!kacpid_wq);BUG_ON (!kacpi_notify_wq);BUG_ON (!kacpi_hotplug_wq);
@@ -759,7 +734,15 @@ static acpi_status __acpi_os_execute(acpi_execute_type type, (type ==OSL_NOTIFY_HANDLER ? kacpi_notify_wq : kacpid_wq); dpc->wait = hp ?1 :0 ;INIT_WORK (&dpc->work, acpi_os_execute_deferred); - ret =queue_work (queue, &dpc->work); + +/* +* On some machines, a software-initiated SMI causes corruption unless +* the SMI runs on CPU 0. An SMI can be initiated by any AML, but +* typically it's done in GPE-related methods that are run via +* workqueues, so we can avoid the known corruption cases by always +* queueing on CPU 0. +*/ + ret =queue_work_on (0 , queue, &dpc->work);if (!ret) { printk(KERN_ERR PREFIX
Signature · 1 line
1.6.5.3
Tejun Heo
maintainerPATCH 10/14 workqueue: merge feature parameters into flags
In reply to Tejun HeoCurrently, __create_workqueue_key() takes @singlethread and @freezeable paramters and store them separately in workqueue_struct. Merge them into a single flags parameter and field and use WQ_FREEZEABLE and WQ_SINGLE_THREAD.
--- include/linux/workqueue.h | 25 +++++++++++++++---------- kernel/workqueue.c | 17 +++++++---------- 2 files changed, 22 insertions(+), 20 deletions(-)
include/linux/workqueue.h +15 -10
@@ -184,13 +184,17 @@ static inline bool work_static(struct work_struct *work) { return false; }#define work_clear_pending (work) \ clear_bit(WORK_STRUCT_PENDING, work_data_bits(work)) +enum { +WQ_FREEZEABLE =1 <<0 ,/* freeze during suspend */ +WQ_SINGLE_THREAD =1 <<1 ,/* no per-cpu worker */ +};extern struct workqueue_struct * -__create_workqueue_key (const char *name,int singlethread,int freezeable, +__create_workqueue_key (const char *name,unsigned int flags,struct lock_class_key *key,const char *lock_name);#ifdef CONFIG_LOCKDEP -#define __create_workqueue (name, singlethread, freezeable) \ +#define __create_workqueue (name, flags) \ ({ \ static struct lock_class_key __key; \ const char *__lock_name; \
@@ -200,19 +204,20 @@ __create_workqueue_key(const char *name, int singlethread, int freezeable, else \ __lock_name = #name; \ \ - __create_workqueue_key((name), (singlethread), \ - (freezeable), &__key, \ + __create_workqueue_key((name), (flags), &__key, \ __lock_name); \ })#else -#define __create_workqueue (name, singlethread, freezeable) \ - __create_workqueue_key((name), (singlethread), (freezeable), \ - NULL, NULL) +#define __create_workqueue (name, flags) \ + __create_workqueue_key((name), (flags), NULL, NULL)#endif -#define create_workqueue (name) __create_workqueue((name), 0, 0) -#define create_freezeable_workqueue (name) __create_workqueue((name), 1, 1) -#define create_singlethread_workqueue (name) __create_workqueue((name), 1, 0) +#define create_workqueue (name) \ + __create_workqueue((name), 0) +#define create_freezeable_workqueue (name) \ + __create_workqueue((name), WQ_FREEZEABLE | WQ_SINGLE_THREAD) +#define create_singlethread_workqueue (name) \ + __create_workqueue((name), WQ_SINGLE_THREAD)extern void destroy_workqueue (struct workqueue_struct *wq);
kernel/workqueue.c +7 -10
@@ -67,11 +67,10 @@ struct cpu_workqueue_struct {* per-CPU workqueues: */ struct workqueue_struct { +unsigned int flags;/* I: WQ_* flags */ struct cpu_workqueue_struct *cpu_wq;/* I: cwq's */ struct list_head list;/* W: list of all workqueues */ const char *name;/* I: workqueue name */ -int singlethread; -int freezeable;/* Freeze threads during suspend */ #ifdef CONFIG_LOCKDEP struct lockdep_map lockdep_map;#endif
@@ -203,9 +202,9 @@ static const struct cpumask *cpu_singlethread_map __read_mostly;static cpumask_var_t cpu_populated_map__read_mostly ;/* If it's single threaded, it isn't in the list of workqueues. */ -static inline int is_wq_single_threaded (struct workqueue_struct *wq) +static inline bool is_wq_single_threaded (struct workqueue_struct *wq) { -return wq->singlethread; +return wq->flags &WQ_SINGLE_THREAD ; }static const struct cpumask *wq_cpu_map (struct workqueue_struct *wq)
@@ -456,7 +455,7 @@ static int worker_thread(void *__cwq)struct cpu_workqueue_struct *cwq = __cwq;DEFINE_WAIT (wait); -if (cwq->wq->freezeable) +if (cwq->wq->flags &WQ_FREEZEABLE )set_freezable ();for (;;) {
@@ -981,8 +980,7 @@ static void start_workqueue_thread(struct cpu_workqueue_struct *cwq, int cpu) }struct workqueue_struct *__create_workqueue_key (const char *name, -int singlethread, -int freezeable, +unsigned int flags,struct lock_class_key *key,const char *lock_name) {
@@ -998,13 +996,12 @@ struct workqueue_struct *__create_workqueue_key(const char *name,if (!wq->cpu_wq) goto err; + wq->flags = flags; wq->name = name;lockdep_init_map (&wq->lockdep_map, lock_name, key,0 ); - wq->singlethread = singlethread; - wq->freezeable = freezeable;INIT_LIST_HEAD (&wq->list); -if (singlethread) { +if (flags &WQ_SINGLE_THREAD ) { cwq =init_cpu_workqueue (wq, singlethread_cpu); err =create_workqueue_thread (cwq, singlethread_cpu);start_workqueue_thread (cwq,-1 );
Signature · 1 line
1.6.5.3
Tejun Heo
maintainerPATCH 12/14 workqueue: define both bit position and mask for work flags
In reply to Tejun HeoWork flags are about to see more traditional mask handling. Define WORK_STRUCT_*_BIT as the bit position constant and redefine WORK_STRUCT_* as bit masks.
--- include/linux/workqueue.h | 15 +++++++++------ kernel/workqueue.c | 14 +++++++------- 2 files changed, 16 insertions(+), 13 deletions(-)
include/linux/workqueue.h +9 -6
@@ -23,8 +23,11 @@ typedef void (*work_func_t)(struct work_struct *work);#define work_data_bits (work) ((unsigned long *)(&(work)->data))enum { -WORK_STRUCT_PENDING =0 ,/* work item is pending execution */ -WORK_STRUCT_STATIC =1 ,/* static initializer (debugobjects) */ +WORK_STRUCT_PENDING_BIT =0 ,/* work item is pending execution */ +WORK_STRUCT_STATIC_BIT =1 ,/* static initializer (debugobjects) */ + +WORK_STRUCT_PENDING =1 <<WORK_STRUCT_PENDING_BIT , +WORK_STRUCT_STATIC =1 <<WORK_STRUCT_STATIC_BIT ,/* * Reserve 3bits off of cwq pointer. This is enough and
@@ -47,7 +50,7 @@ struct work_struct { };#define WORK_DATA_INIT () ATOMIC_LONG_INIT(0) -#define WORK_DATA_STATIC_INIT () ATOMIC_LONG_INIT(2) +#define WORK_DATA_STATIC_INIT () ATOMIC_LONG_INIT(WORK_STRUCT_STATIC)struct delayed_work {struct work_struct work;
@@ -109,7 +112,7 @@ extern void __init_work(struct work_struct *work, int onstack);extern void destroy_work_on_stack (struct work_struct *work);static inline bool work_static (struct work_struct *work) { -return test_bit (WORK_STRUCT_STATIC ,work_data_bits (work)); +return test_bit (WORK_STRUCT_STATIC_BIT ,work_data_bits (work)); }#else static inline void __init_work (struct work_struct *work,int onstack) { }
@@ -178,7 +181,7 @@ static inline bool work_static(struct work_struct *work) { return false; }* @work: The work item in question */ #define work_pending (work) \ - test_bit(WORK_STRUCT_PENDING, work_data_bits(work)) + test_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))/** * delayed_work_pending - Find out whether a delayable work item is currently
@@ -193,7 +196,7 @@ static inline bool work_static(struct work_struct *work) { return false; }* @work: The work item in question */ #define work_clear_pending (work) \ - clear_bit(WORK_STRUCT_PENDING, work_data_bits(work)) + clear_bit(WORK_STRUCT_PENDING_BIT, work_data_bits(work))enum {WQ_FREEZEABLE =1 <<0 ,/* freeze during suspend */
kernel/workqueue.c +7 -7
@@ -117,7 +117,7 @@ static int work_fixup_activate(void *addr, enum debug_obj_state state)* statically initialized. We just make sure that it * is tracked in the object tracker. */ -if (test_bit (WORK_STRUCT_STATIC ,work_data_bits (work))) { +if (test_bit (WORK_STRUCT_STATIC_BIT ,work_data_bits (work))) {debug_object_init (work, &work_debug_descr);debug_object_activate (work, &work_debug_descr);return 0 ;
@@ -234,8 +234,8 @@ static inline void set_wq_data(struct work_struct *work,BUG_ON (!work_pending (work));atomic_long_set (&work->data, (unsigned long )cwq | - (work_static (work) ? (1UL <<WORK_STRUCT_STATIC ) :0 ) | - (1UL <<WORK_STRUCT_PENDING ) | extra_flags); + (work_static (work) ?WORK_STRUCT_STATIC :0 ) | +WORK_STRUCT_PENDING | extra_flags); } static inline
@@ -325,7 +325,7 @@ queue_work_on(int cpu, struct workqueue_struct *wq, struct work_struct *work) {int ret =0 ; -if (!test_and_set_bit (WORK_STRUCT_PENDING ,work_data_bits (work))) { +if (!test_and_set_bit (WORK_STRUCT_PENDING_BIT ,work_data_bits (work))) {__queue_work (cpu, wq, work); ret =1 ; }
@@ -375,7 +375,7 @@ int queue_delayed_work_on(int cpu, struct workqueue_struct *wq,struct timer_list *timer = &dwork->timer;struct work_struct *work = &dwork->work; -if (!test_and_set_bit (WORK_STRUCT_PENDING ,work_data_bits (work))) { +if (!test_and_set_bit (WORK_STRUCT_PENDING_BIT ,work_data_bits (work))) {BUG_ON (timer_pending (timer));BUG_ON (!list_empty (&work->entry));
@@ -511,7 +511,7 @@ static void insert_wq_barrier(struct cpu_workqueue_struct *cwq,* might deadlock. */ INIT_WORK_ON_STACK (&barr->work, wq_barrier_func); -__set_bit (WORK_STRUCT_PENDING ,work_data_bits (&barr->work)); +__set_bit (WORK_STRUCT_PENDING_BIT ,work_data_bits (&barr->work));init_completion (&barr->done);debug_work_activate (&barr->work);
@@ -623,7 +623,7 @@ static int try_to_grab_pending(struct work_struct *work)struct cpu_workqueue_struct *cwq;int ret =-1 ; -if (!test_and_set_bit (WORK_STRUCT_PENDING ,work_data_bits (work))) +if (!test_and_set_bit (WORK_STRUCT_PENDING_BIT ,work_data_bits (work)))return 0 ;/*
Signature · 1 line
1.6.5.3
Tejun Heo
maintainerPATCH 5/14 sched: refactor try_to_wake_up() and implement try_to_wake_up_local()
In reply to Tejun HeoFactor ttwu_activate() and ttwu_woken_up() out of try_to_wake_up() and use them to implement try_to_wake_up_local(). try_to_wake_up_local() is similar to try_to_wake_up() but it assumes the caller has this_rq() locked and the target task is bound to this_rq(). try_to_wake_up_local() can be called from wakeup and sleep scheduler notifiers.
The factoring out doesn't affect try_to_wake_up() much code-generation-wise. Depending on configuration options, it ends up generating the same object code as before or slightly different one due to different register assignment.
The refactoring and local wake up function implementation using refactored functions are based on Peter Zijlstra's suggestion.
--- include/linux/sched.h | 2 + kernel/sched.c | 148 ++++++++++++++++++++++++++++++++++++------------- 2 files changed, 111 insertions(+), 39 deletions(-)
include/linux/sched.h +2 -0
@@ -2057,6 +2057,8 @@ extern void release_uids(struct user_namespace *ns);extern void do_timer (unsigned long ticks); +extern bool try_to_wake_up_local (struct task_struct *p,unsigned int state, +int wake_flags);extern int wake_up_state (struct task_struct *tsk,unsigned int state);extern int wake_up_process (struct task_struct *tsk); extern void wake_up_new_task(struct task_struct *tsk,
kernel/sched.c +109 -39
181 lines not on this page · raw message
Signature · 1 line
1.6.5.3
Tejun Heo
maintainerPATCH 13/14 workqueue: separate out process_one_work()
In reply to Tejun HeoSeparate out process_one_work() out of run_workqueue(). This patch doesn't cause any behavior change.
--- kernel/workqueue.c | 100 +++++++++++++++++++++++++++++++-------------------- 1 files changed, 61 insertions(+), 39 deletions(-)
kernel/workqueue.c +61 -39
@@ -397,51 +397,73 @@ int queue_delayed_work_on(int cpu, struct workqueue_struct *wq, }EXPORT_SYMBOL_GPL (queue_delayed_work_on); +/** +* process_one_work - process single work +* @cwq: cwq to process work for +* @work: work to process +* +* Process @work. This function contains all the logics necessary to +* process a single work including synchronization against and +* interaction with other workers on the same cpu, queueing and +* flushing. As long as context requirement is met, any worker can +* call this function to process a work. +* +* CONTEXT: +* spin_lock_irq(cwq->lock) which is released and regrabbed. +*/ +static void process_one_work (struct cpu_workqueue_struct *cwq, +struct work_struct *work) +{ +work_func_t f = work->func; +#ifdef CONFIG_LOCKDEP +/* +* It is permissible to free the struct work_struct from +* inside the function that is called from it, this we need to +* take into account for lockdep too. To avoid bogus "held +* lock freed" warnings as well as problems when looking into +* work->lockdep_map, make a copy and use that here. +*/ +struct lockdep_map lockdep_map = work->lockdep_map; +#endif +/* claim and process */ +trace_workqueue_execution (cwq->thread, work); +debug_work_deactivate (work); + cwq->current_work = work; +list_del_init (&work->entry); + +spin_unlock_irq (&cwq->lock); + +BUG_ON (get_wq_data (work) != cwq); +work_clear_pending (work); +lock_map_acquire (&cwq->wq->lockdep_map); +lock_map_acquire (&lockdep_map); +f (work); +lock_map_release (&lockdep_map); +lock_map_release (&cwq->wq->lockdep_map); + +if (unlikely (in_atomic () ||lockdep_depth (current) >0 )) { +printk (KERN_ERR "BUG: workqueue leaked lock or atomic: " +"%s/0x%08x/%d\n" , + current->comm,preempt_count (),task_pid_nr (current)); +printk (KERN_ERR " last function: " ); +print_symbol ("%s\n" , (unsigned long )f); +debug_show_held_locks (current); +dump_stack (); + } + +spin_lock_irq (&cwq->lock); + +/* we're done with it, release */ + cwq->current_work =NULL ; +} +static void run_workqueue (struct cpu_workqueue_struct *cwq) {spin_lock_irq (&cwq->lock);while (!list_empty (&cwq->worklist)) {struct work_struct *work =list_entry (cwq->worklist.next, struct work_struct, entry); -work_func_t f = work->func; -#ifdef CONFIG_LOCKDEP -/* -* It is permissible to free the struct work_struct -* from inside the function that is called from it, -* this we need to take into account for lockdep too. -* To avoid bogus "held lock freed" warnings as well -* as problems when looking into work->lockdep_map, -* make a copy and use that here. -*/ -struct lockdep_map lockdep_map = work->lockdep_map; -#endif -trace_workqueue_execution (cwq->thread, work); -debug_work_deactivate (work); - cwq->current_work = work; -list_del_init (cwq->worklist.next); -spin_unlock_irq (&cwq->lock); - -BUG_ON (get_wq_data (work) != cwq); -work_clear_pending (work); -lock_map_acquire (&cwq->wq->lockdep_map); -lock_map_acquire (&lockdep_map); -f (work); -lock_map_release (&lockdep_map); -lock_map_release (&cwq->wq->lockdep_map); - -if (unlikely (in_atomic () ||lockdep_depth (current) >0 )) { -printk (KERN_ERR "BUG: workqueue leaked lock or atomic: " -"%s/0x%08x/%d\n" , - current->comm,preempt_count (), -task_pid_nr (current)); -printk (KERN_ERR " last function: " ); -print_symbol ("%s\n" , (unsigned long )f); -debug_show_held_locks (current); -dump_stack (); - } - -spin_lock_irq (&cwq->lock); - cwq->current_work =NULL ; +process_one_work (cwq, work); }spin_unlock_irq (&cwq->lock); }
Signature · 1 line
1.6.5.3
Tejun Heo
maintainerPATCH 3/14 sched: rename preempt_notifier to sched_notifier and always enable it
In reply to Tejun HeoRename preempt_notifier to sched_notifier, move it from preempt.h to sched.h, drop sched_ prefixes from ops names and make sched_notifier always enabled.
This is to prepare for adding more notification hooks. This patch doesn't make any functional changes.
--- arch/ia64/kvm/Kconfig | 1 - arch/powerpc/kvm/Kconfig | 1 - arch/s390/kvm/Kconfig | 1 - arch/x86/kvm/Kconfig | 1 - include/linux/kvm_host.h | 4 +-- include/linux/preempt.h | 43 ------------------------------- include/linux/sched.h | 44 ++++++++++++++++++++++++++++--- init/Kconfig | 4 --- kernel/sched.c | 64 +++++++++++++++------------------------------- virt/kvm/kvm_main.c | 26 ++++++++---------- 10 files changed, 74 insertions(+), 115 deletions(-)
arch/ia64/kvm/Kconfig +0 -1
@@ -22,7 +22,6 @@ config KVM depends on HAVE_KVM && MODULES && EXPERIMENTAL # for device assignment: depends on PCI - select PREEMPT_NOTIFIERS select ANON_INODES select HAVE_KVM_IRQCHIP select KVM_APIC_ARCHITECTURE
arch/powerpc/kvm/Kconfig +0 -1
@@ -18,7 +18,6 @@ if VIRTUALIZATION config KVM bool - select PREEMPT_NOTIFIERS select ANON_INODES config KVM_440
arch/s390/kvm/Kconfig +0 -1
@@ -18,7 +18,6 @@ if VIRTUALIZATION config KVM tristate "Kernel-based Virtual Machine (KVM) support" depends on HAVE_KVM && EXPERIMENTAL - select PREEMPT_NOTIFIERS select ANON_INODES select S390_SWITCH_AMODE ---help---
arch/x86/kvm/Kconfig +0 -1
@@ -22,7 +22,6 @@ config KVM depends on HAVE_KVM # for device assignment: depends on PCI - select PREEMPT_NOTIFIERS select MMU_NOTIFIER select ANON_INODES select HAVE_KVM_IRQCHIP
include/linux/kvm_host.h +1 -3
@@ -74,9 +74,7 @@ void kvm_io_bus_unregister_dev(struct kvm *kvm, struct kvm_io_bus *bus,struct kvm_vcpu {struct kvm *kvm; -#ifdef CONFIG_PREEMPT_NOTIFIERS -struct preempt_notifier preempt_notifier; -#endif +struct sched_notifier sched_notifier;int vcpu_id;struct mutex mutex;int cpu;
include/linux/preempt.h +0 -43
47 lines not on this page · raw message
include/linux/sched.h +40 -4
56 lines not on this page · raw message
init/Kconfig +0 -4
@@ -1206,7 +1206,3 @@ config STOP_MACHINE Need stop_machine() primitive. source "block/Kconfig" - -config PREEMPT_NOTIFIERS - bool -
kernel/sched.c +21 -43
118 lines not on this page · raw message
virt/kvm/kvm_main.c +12 -14
@@ -79,7 +79,7 @@ static cpumask_var_t cpus_hardware_enabled;struct kmem_cache *kvm_vcpu_cache;EXPORT_SYMBOL_GPL (kvm_vcpu_cache); -static __read_mostly struct preempt_ops kvm_preempt_ops; +static __read_mostly struct sched_notifier_ops kvm_sched_notifier_ops;struct dentry *kvm_debugfs_dir;
@@ -713,7 +713,7 @@ void vcpu_load(struct kvm_vcpu *vcpu)mutex_lock (&vcpu->mutex); cpu =get_cpu (); -preempt_notifier_register (&vcpu->preempt_notifier); +sched_notifier_register (&vcpu->sched_notifier);kvm_arch_vcpu_load (vcpu, cpu);put_cpu (); }
@@ -722,7 +722,7 @@ void vcpu_put(struct kvm_vcpu *vcpu) {preempt_disable ();kvm_arch_vcpu_put (vcpu); -preempt_notifier_unregister (&vcpu->preempt_notifier); +sched_notifier_unregister (&vcpu->sched_notifier);preempt_enable ();mutex_unlock (&vcpu->mutex); }
@@ -1772,7 +1772,7 @@ static int kvm_vm_ioctl_create_vcpu(struct kvm *kvm, u32 id)if (IS_ERR (vcpu))return PTR_ERR (vcpu); -preempt_notifier_init (&vcpu->preempt_notifier, &kvm_preempt_ops); +sched_notifier_init (&vcpu->sched_notifier, &kvm_sched_notifier_ops); r =kvm_arch_vcpu_setup (vcpu);if (r)
@@ -2690,23 +2690,21 @@ static struct sys_device kvm_sysdev = {struct page *bad_page;pfn_t bad_pfn; -static inline -struct kvm_vcpu *preempt_notifier_to_vcpu (struct preempt_notifier *pn) +static inline struct kvm_vcpu *sched_notifier_to_vcpu (struct sched_notifier *sn) { - return container_of(pn, struct kvm_vcpu, preempt_notifier); + return container_of(sn, struct kvm_vcpu, sched_notifier); } -static void kvm_sched_in (struct preempt_notifier *pn,int cpu) +static void kvm_sched_in (struct sched_notifier *sn,int cpu) { -struct kvm_vcpu *vcpu =preempt_notifier_to_vcpu (pn); +struct kvm_vcpu *vcpu =sched_notifier_to_vcpu (sn);kvm_arch_vcpu_load (vcpu, cpu); } -static void kvm_sched_out (struct preempt_notifier *pn, -struct task_struct *next) +static void kvm_sched_out (struct sched_notifier *sn,struct task_struct *next) { -struct kvm_vcpu *vcpu =preempt_notifier_to_vcpu (pn); +struct kvm_vcpu *vcpu =sched_notifier_to_vcpu (sn);kvm_arch_vcpu_put (vcpu); }
@@ -2780,8 +2778,8 @@ int kvm_init(void *opaque, unsigned int vcpu_size, goto out_free; } - kvm_preempt_ops.sched_in = kvm_sched_in; - kvm_preempt_ops.sched_out = kvm_sched_out; + kvm_sched_notifier_ops.in = kvm_sched_in; + kvm_sched_notifier_ops.out = kvm_sched_out;kvm_init_debug ();
Signature · 1 line
1.6.5.3
Tejun Heo
maintainerPATCH 11/14 workqueue: update cwq alignement and make one more flag bit available
In reply to Tejun HeoCurrently cwqs are aligned to cacheline and lower two bits of work_struct->data are considered to be available and used as flags. Make the alignement requirement official by defining WORK_STRUCT_FLAG_BITS and aligning cwqs to two's power of it.
This is in preparation of concurrency managed workqueue and cwqs being aligned to cacheline wouldn't matter as much. While at it, this patch reserves one more bit for work flags and make sure the resulting alignment is at least equal to or larger than that of long long.
--- include/linux/workqueue.h | 19 +++++++++++++++---- kernel/workqueue.c | 15 +++++++++++++-- 2 files changed, 28 insertions(+), 6 deletions(-)
include/linux/workqueue.h +15 -4
@@ -22,12 +22,23 @@ typedef void (*work_func_t)(struct work_struct *work);*/ #define work_data_bits (work) ((unsigned long *)(&(work)->data)) +enum { +WORK_STRUCT_PENDING =0 ,/* work item is pending execution */ +WORK_STRUCT_STATIC =1 ,/* static initializer (debugobjects) */ + +/* +* Reserve 3bits off of cwq pointer. This is enough and +* provides acceptable alignment on both 32 and 64bit +* machines. +*/ +WORK_STRUCT_FLAG_BITS =3 , + +WORK_STRUCT_FLAG_MASK = (1UL <<WORK_STRUCT_FLAG_BITS ) -1 , +WORK_STRUCT_WQ_DATA_MASK = ~WORK_STRUCT_FLAG_MASK , +}; +struct work_struct {atomic_long_t data; -#define WORK_STRUCT_PENDING 0/* T if work item pending execution */ -#define WORK_STRUCT_STATIC 1/* static initializer (debugobjects) */ -#define WORK_STRUCT_FLAG_MASK (3UL) -#define WORK_STRUCT_WQ_DATA_MASK (~WORK_STRUCT_FLAG_MASK)struct list_head entry;work_func_t func;#ifdef CONFIG_LOCKDEP
kernel/workqueue.c +13 -2
@@ -48,7 +48,9 @@/* * The per-CPU workqueue (if single thread, we always use the first -* possible cpu). +* possible cpu). The lower WORK_STRUCT_FLAG_BITS of +* work_struct->data are used for flags and thus cwqs need to be +* aligned at two's power of the number of flag bits. */ struct cpu_workqueue_struct {
@@ -60,7 +62,7 @@ struct cpu_workqueue_struct {struct workqueue_struct *wq;/* I: the owning workqueue */ struct task_struct *thread; -}____cacheline_aligned ; +} __attribute__((aligned(1 << WORK_STRUCT_FLAG_BITS)));/* * The externally visible workqueue abstraction is an array of
@@ -1198,6 +1200,15 @@ EXPORT_SYMBOL_GPL(work_on_cpu);void __init init_workqueues (void ) { +/* +* cwqs are forced aligned according to WORK_STRUCT_FLAG_BITS. +* Make sure that the alignment isn't lower than that of +* unsigned long long in case this code survives for longer +* than twenty years. :-P +*/ +BUILD_BUG_ON (__alignof__(struct cpu_workqueue_struct ) < + __alignof__(unsigned long long )); +alloc_cpumask_var (&cpu_populated_map,GFP_KERNEL );cpumask_copy (cpu_populated_map, cpu_online_mask);
Signature · 1 line
1.6.5.3
Tejun Heo
maintainerPATCH 8/14 stop_machine: reimplement without using workqueue
In reply to Tejun Heostop_machine() is the only user of RT workqueue. Reimplement it using kthreads directly and rip RT support from workqueue. This is in preparation of concurrency managed workqueue.
--- include/linux/stop_machine.h | 6 ++ include/linux/workqueue.h | 20 +++--- init/main.c | 2 + kernel/stop_machine.c | 151 ++++++++++++++++++++++++++++++++++------- kernel/workqueue.c | 6 -- 5 files changed, 142 insertions(+), 43 deletions(-)
include/linux/stop_machine.h +6 -0
@@ -53,6 +53,11 @@ int stop_machine_create(void);*/ void stop_machine_destroy (void ); +/** +* init_stop_machine: initialize stop_machine during boot +*/ +void init_stop_machine (void ); +#else static inline int stop_machine(int (*fn)(void *), void *data,
@@ -67,6 +72,7 @@ static inline int stop_machine(int (*fn)(void *), void *data,static inline int stop_machine_create (void ) {return 0 ; }static inline void stop_machine_destroy (void ) { } +static inline void init_stop_machine (void ) { }#endif /* CONFIG_SMP */ #endif /* _LINUX_STOP_MACHINE */
include/linux/workqueue.h +9 -11
@@ -181,12 +181,11 @@ static inline void destroy_work_on_stack(struct work_struct *work) { }extern struct workqueue_struct * -__create_workqueue_key (const char *name,int singlethread, -int freezeable,int rt,struct lock_class_key *key, -const char *lock_name); +__create_workqueue_key (const char *name,int singlethread,int freezeable, +struct lock_class_key *key,const char *lock_name);#ifdef CONFIG_LOCKDEP -#define __create_workqueue (name, singlethread, freezeable, rt) \ +#define __create_workqueue (name, singlethread, freezeable) \ ({ \ static struct lock_class_key __key; \ const char *__lock_name; \
@@ -197,19 +196,18 @@ __create_workqueue_key(const char *name, int singlethread, __lock_name = #name; \ \ __create_workqueue_key((name), (singlethread), \ - (freezeable), (rt), &__key, \ + (freezeable), &__key, \ __lock_name); \ })#else -#define __create_workqueue (name, singlethread, freezeable, rt) \ - __create_workqueue_key((name), (singlethread), (freezeable), (rt), \ +#define __create_workqueue (name, singlethread, freezeable) \ + __create_workqueue_key((name), (singlethread), (freezeable), \ NULL, NULL)#endif -#define create_workqueue (name) __create_workqueue((name), 0, 0, 0) -#define create_rt_workqueue (name) __create_workqueue((name), 0, 0, 1) -#define create_freezeable_workqueue (name) __create_workqueue((name), 1, 1, 0) -#define create_singlethread_workqueue (name) __create_workqueue((name), 1, 0, 0) +#define create_workqueue (name) __create_workqueue((name), 0, 0) +#define create_freezeable_workqueue (name) __create_workqueue((name), 1, 1) +#define create_singlethread_workqueue (name) __create_workqueue((name), 1, 0)extern void destroy_workqueue (struct workqueue_struct *wq);
init/main.c +2 -0
@@ -34,6 +34,7 @@#include <linux/security.h> #include <linux/smp.h> #include <linux/workqueue.h> +#include <linux/stop_machine.h> #include <linux/profile.h> #include <linux/rcupdate.h> #include <linux/moduleparam.h>
@@ -779,6 +780,7 @@ static void __init do_initcalls(void)static void __init do_basic_setup (void ) {init_workqueues (); +init_stop_machine ();cpuset_init_smp ();usermodehelper_init ();init_tmpfs ();
kernel/stop_machine.c +125 -26
229 lines not on this page · raw message
kernel/workqueue.c +0 -6
@@ -62,7 +62,6 @@ struct workqueue_struct {const char *name;int singlethread;int freezeable;/* Freeze threads during suspend */ -int rt;#ifdef CONFIG_LOCKDEP struct lockdep_map lockdep_map;#endif
@@ -913,7 +912,6 @@ init_cpu_workqueue(struct workqueue_struct *wq, int cpu)static int create_workqueue_thread (struct cpu_workqueue_struct *cwq,int cpu) { -struct sched_param param = { .sched_priority =MAX_RT_PRIO -1 };struct workqueue_struct *wq = cwq->wq;const char *fmt =is_wq_single_threaded (wq) ?"%s" :"%s/%d" ;struct task_struct *p;
@@ -929,8 +927,6 @@ static int create_workqueue_thread(struct cpu_workqueue_struct *cwq, int cpu)*/ if (IS_ERR (p))return PTR_ERR (p); -if (cwq->wq->rt) -sched_setscheduler_nocheck (p,SCHED_FIFO , ¶m); cwq->thread = p;trace_workqueue_creation (cwq->thread, cpu);
@@ -952,7 +948,6 @@ static void start_workqueue_thread(struct cpu_workqueue_struct *cwq, int cpu)struct workqueue_struct *__create_workqueue_key (const char *name,int singlethread,int freezeable, -int rt,struct lock_class_key *key,const char *lock_name) {
@@ -974,7 +969,6 @@ struct workqueue_struct *__create_workqueue_key(const char *name,lockdep_init_map (&wq->lockdep_map, lock_name, key,0 ); wq->singlethread = singlethread; wq->freezeable = freezeable; - wq->rt = rt;INIT_LIST_HEAD (&wq->list);if (singlethread) {
Signature · 1 line
1.6.5.3
Tejun Heo
maintainerPATCH 2/14 workqueue: Add debugobjects support
In reply to Tejun HeoFrom: Thomas Gleixner <[email protected]>
Add debugobject support to track the life time of work_structs.
While at it, remove duplicate definition ofINIT_DELAYED_WORK_ON_STACK().
--- arch/x86/kernel/smpboot.c | 4 +- include/linux/workqueue.h | 38 +++++++++---- kernel/workqueue.c | 131 +++++++++++++++++++++++++++++++++++++++++++- lib/Kconfig.debug | 8 +++ 4 files changed, 166 insertions(+), 15 deletions(-)
arch/x86/kernel/smpboot.c +3 -1
@@ -687,7 +687,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu) .done = COMPLETION_INITIALIZER_ONSTACK(c_idle.done), }; -INIT_WORK (&c_idle.work, do_fork_idle); +INIT_WORK_ON_STACK (&c_idle.work, do_fork_idle);alternatives_smp_switch (1 );
@@ -713,6 +713,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu)if (IS_ERR (c_idle.idle)) {printk ("failed fork for CPU %d\n" , cpu); +destroy_work_on_stack (&c_idle.work);return PTR_ERR (c_idle.idle); }
@@ -831,6 +832,7 @@ do_rest:smpboot_restore_warm_reset_vector (); } +destroy_work_on_stack (&c_idle.work);return boot_error; }
include/linux/workqueue.h +27 -11
@@ -25,6 +25,7 @@ typedef void (*work_func_t)(struct work_struct *work);struct work_struct {atomic_long_t data;#define WORK_STRUCT_PENDING 0/* T if work item pending execution */ +#define WORK_STRUCT_STATIC 1/* static initializer (debugobjects) */ #define WORK_STRUCT_FLAG_MASK (3UL)#define WORK_STRUCT_WQ_DATA_MASK (~WORK_STRUCT_FLAG_MASK)struct list_head entry;
@@ -35,6 +36,7 @@ struct work_struct { };#define WORK_DATA_INIT () ATOMIC_LONG_INIT(0) +#define WORK_DATA_STATIC_INIT () ATOMIC_LONG_INIT(2)struct delayed_work {struct work_struct work;
@@ -63,7 +65,7 @@ struct execute_work {#endif #define __WORK_INITIALIZER (n, f) { \ - .data = WORK_DATA_INIT(), \ + .data = WORK_DATA_STATIC_INIT(), \ .entry = { &(n).entry, &(n).entry }, \ .func = (f), \ __WORK_INIT_LOCKDEP_MAP(#n, &(n)) \
@@ -91,6 +93,14 @@ struct execute_work {#define PREPARE_DELAYED_WORK (_work, _func) \ PREPARE_WORK(&(_work)->work, (_func)) +#ifdef CONFIG_DEBUG_OBJECTS_WORK +extern void __init_work (struct work_struct *work,int onstack); +extern void destroy_work_on_stack (struct work_struct *work); +#else +static inline void __init_work (struct work_struct *work,int onstack) { } +static inline void destroy_work_on_stack (struct work_struct *work) { } +#endif +/* * initialize all of a work item in one go *
@@ -99,24 +109,36 @@ struct execute_work {* to generate better code. */ #ifdef CONFIG_LOCKDEP -#define INIT_WORK (_work, _func) \ +#define __INIT_WORK (_work, _func, _onstack) \ do { \ static struct lock_class_key __key; \ \ + __init_work((_work), _onstack); \ (_work)->data = (atomic_long_t) WORK_DATA_INIT(); \ lockdep_init_map(&(_work)->lockdep_map, #_work, &__key, 0);\ INIT_LIST_HEAD(&(_work)->entry); \ PREPARE_WORK((_work), (_func)); \ } while (0)#else -#define INIT_WORK (_work, _func) \ +#define __INIT_WORK (_work, _func, _onstack) \ do { \ + __init_work((_work), _onstack); \ (_work)->data = (atomic_long_t) WORK_DATA_INIT(); \ INIT_LIST_HEAD(&(_work)->entry); \ PREPARE_WORK((_work), (_func)); \ } while (0)#endif +#define INIT_WORK (_work, _func) \ + do { \ + __INIT_WORK((_work), (_func), 0); \ + } while (0) + +#define INIT_WORK_ON_STACK (_work, _func) \ + do { \ + __INIT_WORK((_work), (_func), 1); \ + } while (0) +#define INIT_DELAYED_WORK (_work, _func) \ do { \ INIT_WORK(&(_work)->work, (_func)); \
@@ -125,22 +147,16 @@ struct execute_work {#define INIT_DELAYED_WORK_ON_STACK (_work, _func) \ do { \ - INIT_WORK(&(_work)->work, (_func)); \ + INIT_WORK_ON_STACK(&(_work)->work, (_func)); \ init_timer_on_stack(&(_work)->timer); \ } while (0) -#define INIT_DELAYED_WORK_DEFERRABLE (_work, _func) \ +#define INIT_DELAYED_WORK_DEFERRABLE (_work, _func) \ do { \ INIT_WORK(&(_work)->work, (_func)); \ init_timer_deferrable(&(_work)->timer); \ } while (0) -#define INIT_DELAYED_WORK_ON_STACK (_work, _func) \ - do { \ - INIT_WORK(&(_work)->work, (_func)); \ - init_timer_on_stack(&(_work)->timer); \ - } while (0) -/** * work_pending - Find out whether a work item is currently pending * @work: The work item in question
kernel/workqueue.c +128 -3
185 lines not on this page · raw message
lib/Kconfig.debug +8 -0
@@ -298,6 +298,14 @@ config DEBUG_OBJECTS_TIMERS timer routines to track the life time of timer objects and validate the timer operations. +config DEBUG_OBJECTS_WORK + bool "Debug work objects" + depends on DEBUG_OBJECTS + help + If you say Y here, additional code will be inserted into the + work queue routines to track the life time of work objects and + validate the work operations. + config DEBUG_OBJECTS_ENABLE_DEFAULT int "debug_objects bootup default value (0-1)" range 0 1
Signature · 1 line
1.6.5.3
Tejun Heo
maintainerPATCH 6/14 sched: implement force_cpus_allowed()
In reply to Tejun Heoset_cpus_allowed_ptr() modifies the allowed cpu mask of a task. The function performs the following checks before applying new mask.
* Check whether PF_THREAD_BOUND is set. This is set for bound kthreads so that they can't be moved around.
* Check whether the target cpu is still marked active - cpu_active(). Active state is cleared early while downing a cpu.
This patch adds force_cpus_allowed() which bypasses the above two checks. The caller is responsible for guaranteeing that the destination cpu doesn't go down until force_cpus_allowed() finishes.
The first check is bypassed by factoring out actual migration part into __set_cpus_allowed() from set_cpus_allowed_ptr() and calling the inner function from force_cpus_allowed().
The second check is buried deep down in __migrate_task() which is executed by migration threads. @force parameter is added to __migrate_task(). As the only way to pass parameters from __set_cpus_allowed() is through migration_req, migration_req->force is added and the @force parameter is passed down to __migrate_task().
Please note the naming discrepancy between set_cpus_allowed_ptr() and the new functions. The _ptr suffix is from the days when cpumask api wasn't mature and future changes should drop it from set_cpus_allowed_ptr() too.
force_cpus_allowed() will be used for concurrency-managed workqueue.
--- include/linux/sched.h | 7 ++++ kernel/sched.c | 89 +++++++++++++++++++++++++++++++++---------------- 2 files changed, 67 insertions(+), 29 deletions(-)
include/linux/sched.h +7 -0
@@ -1851,6 +1851,8 @@ static inline void rcu_copy_process(struct task_struct *p)#ifdef CONFIG_SMP extern int set_cpus_allowed_ptr (struct task_struct *p,const struct cpumask *new_mask); +extern int force_cpus_allowed (struct task_struct *p, +const struct cpumask *new_mask);#else static inline int set_cpus_allowed_ptr (struct task_struct *p,const struct cpumask *new_mask)
@@ -1859,6 +1861,11 @@ static inline int set_cpus_allowed_ptr(struct task_struct *p,return -EINVAL ; return 0; } +static inline int force_cpus_allowed (struct task_struct *p, +const struct cpumask *new_mask) +{ +return set_cpus_allowed_ptr (p, new_mask); +}#endif #ifndef CONFIG_CPUMASK_OFFSTACK
kernel/sched.c +60 -29
172 lines not on this page · raw message
Signature · 1 line
1.6.5.3
Tejun Heo
maintainerPATCH 4/14 sched: update sched_notifier and add wakeup/sleep notifications
In reply to Tejun HeoUpdate sched_notifier such that
* in and out ops are symmetric in the parameter they take.
* Use single fire_sched_notifier() macro instead of separate function for each op.
* Allow NULL ops.
* Add wakeup and sleep notifications.
--- include/linux/sched.h | 20 +++++++++++++------- kernel/sched.c | 41 ++++++++++++++++++----------------------- virt/kvm/kvm_main.c | 4 ++-- 3 files changed, 33 insertions(+), 32 deletions(-)
include/linux/sched.h +13 -7
@@ -1214,15 +1214,21 @@ struct sched_notifier;/** * sched_notifier_ops - notifiers called for scheduling events -* @in: we're about to be rescheduled: -* notifier: struct sched_notifier for the task being scheduled -* cpu: cpu we're scheduled on -* @out: we've just been preempted -* notifier: struct sched_notifier for the task being preempted -* next: the task that's kicking us out +* @wakeup: we're waking up +* notifier: struct sched_notifier for the task being woken up +* @sleep: we're going to bed +* notifier: struct sched_notifier for the task sleeping +* @in: we're now running on the cpu +* notifier: struct sched_notifier for the task being scheduled in +* prev: the task which ran before us +* @out: we're leaving the cpu +* notifier: struct sched_notifier for the task being scheduled out +* next: the task which will run after us */ struct sched_notifier_ops { -void (*in)(struct sched_notifier *notifier,int cpu); +void (*wakeup)(struct sched_notifier *notifier); +void (*sleep)(struct sched_notifier *notifier); +void (*in)(struct sched_notifier *notifier,struct task_struct *prev);void (*out)(struct sched_notifier *notifier,struct task_struct *next); };
kernel/sched.c +18 -23
79 lines not on this page · raw message
virt/kvm/kvm_main.c +2 -2
@@ -2695,11 +2695,11 @@ static inline struct kvm_vcpu *sched_notifier_to_vcpu(struct sched_notifier *sn) return container_of(sn, struct kvm_vcpu, sched_notifier); } -static void kvm_sched_in (struct sched_notifier *sn,int cpu) +static void kvm_sched_in (struct sched_notifier *sn,struct task_struct *prev) {struct kvm_vcpu *vcpu =sched_notifier_to_vcpu (sn); -kvm_arch_vcpu_load (vcpu, cpu); +kvm_arch_vcpu_load (vcpu,smp_processor_id ()); }static void kvm_sched_out (struct sched_notifier *sn,struct task_struct *next)
Signature · 1 line
1.6.5.3
Tejun Heo
maintainerPATCH 14/14 workqueue: temporarily disable workqueue tracing
In reply to Tejun HeoStrip tracing code from workqueue and disable workqueue tracing. This is temporary measure till concurrency managed workqueue is complete.
--- kernel/trace/Kconfig | 4 +++- kernel/workqueue.c | 14 +++----------- 2 files changed, 6 insertions(+), 12 deletions(-)
kernel/trace/Kconfig +3 -1
@@ -393,7 +393,9 @@ config KMEMTRACE If unsure, say N. config WORKQUEUE_TRACER - bool "Trace workqueues" +# Temporarily disabled during workqueue reimplementation +# bool "Trace workqueues" + def_bool n select GENERIC_TRACER help The workqueue tracer provides some statistical informations
kernel/workqueue.c +3 -11
@@ -33,8 +33,6 @@#include <linux/kallsyms.h> #include <linux/debug_locks.h> #include <linux/lockdep.h> -#define CREATE_TRACE_POINTS -#include <trace/events/workqueue.h> /* * Structure fields follow one of the following exclusion rules.
@@ -238,10 +236,10 @@ static inline void set_wq_data(struct work_struct *work, WORK_STRUCT_PENDING | extra_flags); } -static inline -struct cpu_workqueue_struct *get_wq_data (struct work_struct *work) +static inline struct cpu_workqueue_struct *get_wq_data (struct work_struct *work) { -return (void *) (atomic_long_read (&work->data) &WORK_STRUCT_WQ_DATA_MASK ); +return (void *)(atomic_long_read (&work->data) & +WORK_STRUCT_WQ_DATA_MASK ); }/**
@@ -260,8 +258,6 @@ static void insert_work(struct cpu_workqueue_struct *cwq, struct work_struct *work, struct list_head *head, unsigned int extra_flags) { - trace_workqueue_insertion(cwq->thread, work); -/* we own @work, set data and link */ set_wq_data (work ,cwq ,extra_flags );
@@ -426,7 +422,6 @@ static void process_one_work(struct cpu_workqueue_struct *cwq,struct lockdep_map lockdep_map = work->lockdep_map;#endif /* claim and process */ -trace_workqueue_execution (cwq->thread, work);debug_work_deactivate (work); cwq->current_work = work;list_del_init (&work->entry);
@@ -987,8 +982,6 @@ static int create_workqueue_thread(struct cpu_workqueue_struct *cwq, int cpu)return PTR_ERR (p); cwq->thread = p; -trace_workqueue_creation (cwq->thread, cpu); -return 0 ; }
@@ -1093,7 +1086,6 @@ static void cleanup_workqueue_thread(struct cpu_workqueue_struct *cwq)* checks list_empty(), and a "normal" queue_work() can't use * a dead CPU. */ -trace_workqueue_destruction (cwq->thread);kthread_stop (cwq->thread); cwq->thread =NULL ; }
Signature · 1 line
1.6.5.3
Tejun Heo
maintainerPATCH 1/14 sched, kvm: fix race condition involving sched_in_preempt_notifers
In reply to Tejun HeoIn finish_task_switch(), fire_sched_in_preempt_notifiers() is called after finish_lock_switch(). However, depending on architecture, preemption can be enabled after finish_lock_switch() which breaks the semantics of preempt notifiers. Move it before finish_arch_switch(). This also makes in notifiers symmetric to out notifiers in terms of locking - now both are called under rq lock.
--- kernel/sched.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
kernel/sched.c +1 -1
@@ -2751,9 +2751,9 @@ static void finish_task_switch(struct rq *rq, struct task_struct *prev) prev_state = prev->state;finish_arch_switch (prev);perf_event_task_sched_in (current,cpu_of (rq)); +fire_sched_in_preempt_notifiers (current);finish_lock_switch (rq, prev); -fire_sched_in_preempt_notifiers (current);if (mm)mmdrop (mm);if (unlikely (prev_state ==TASK_DEAD )) {
Signature · 1 line
1.6.5.3
Tejun Heo
maintainerPATCH 1/1 workqueue: prepare for concurrency managed workqueue, take#3
Hello, all.
This patchset is the third take of prep-for-concurrent-managed-wq patchset. Changes from the last take[L] are
* sched_notifier wakeup notification firing location moved so that it happens after wake up is complete to allow calling local wake up function from wakeup notifier.
* sched-implement-sched_notifier_wake_up_process() replaced with sched-refactor-try_to_wake_up-and-implement-try_to_wake_up_local. Instead of implementing separately, common part is factored out from try_to_wake_up() and used to implement try_to_wake_up_local() as suggested by Peter Zijlstra.
* Patch description updated on sched-implement-force_cpus_allowed.
* 0015-0019 dropped from this series. Updated versions will be posted in another patchset with other patches.
This patchset contains the following 14 patches.
0001-sched-kvm-fix-race-condition-involving-sched_in_pree.patch 0002-workqueue-Add-debugobjects-support.patch 0003-sched-rename-preempt_notifier-to-sched_notifier-and-.patch 0004-sched-update-sched_notifier-and-add-wakeup-sleep-not.patch 0005-sched-refactor-try_to_wake_up-and-implement-try_to_w.patch 0006-sched-implement-force_cpus_allowed.patch 0007-acpi-use-queue_work_on-instead-of-binding-workqueue-.patch 0008-stop_machine-reimplement-without-using-workqueue.patch 0009-workqueue-misc-cosmetic-updates.patch 0010-workqueue-merge-feature-parameters-into-flags.patch 0011-workqueue-update-cwq-alignement-and-make-one-more-fl.patch 0012-workqueue-define-both-bit-position-and-mask-for-work.patch 0013-workqueue-separate-out-process_one_work.patch 0014-workqueue-temporarily-disable-workqueue-tracing.patch
This patchset is available in the following git tree.
git://git.kernel.org/pub/scm/linux/kernel/git/tj/wq.git review-wq-prep
Please note that the above tree is temporary. It needs to be rebased once 0001 appears in upstream.
This patchset contains the following changes.
arch/ia64/kvm/Kconfig | 1 arch/powerpc/kvm/Kconfig | 1 arch/s390/kvm/Kconfig | 1 arch/x86/kernel/smpboot.c | 4 arch/x86/kvm/Kconfig | 1 drivers/acpi/osl.c | 41 +--- include/linux/kvm_host.h | 4 include/linux/preempt.h | 43 ---- include/linux/sched.h | 59 +++++- include/linux/stop_machine.h | 6 include/linux/workqueue.h | 96 ++++++---- init/Kconfig | 4 init/main.c | 2 kernel/sched.c | 316 ++++++++++++++++++++------------ kernel/stop_machine.c | 151 +++++++++++++-- kernel/trace/Kconfig | 4 kernel/workqueue.c | 412 ++++++++++++++++++++++++++++++------------- lib/Kconfig.debug | 8 virt/kvm/kvm_main.c | 28 +- 19 files changed, 786 insertions(+), 396 deletions(-)
Thanks.
--
tejun
Quoted 5 lines · Tejun Heo
Hello, all.
This patchset is the third take of prep-for-concurrent-managed-wq patchset.
The kvm and sched_notifier changes are fine as far as I'm concerned.
Signature · 1 line
error compiling committee.c: too many arguments to function
Tejun Heo
maintainerHello,
This patchset has been pushed out to linux-next via wq#for-next. This patchset will NOT be submitted for merge when 33 -rc1 window opens. I'm aiming for 34 merge.
Thanks.
Signature · 1 line
tejun