diff options
author | Petr Mladek <pmladek@suse.com> | 2016-10-19 07:50:47 -0400 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2016-12-08 09:31:11 -0500 |
commit | 36da91bdf568e804aac3ef02a5e3d867585f08fb (patch) | |
tree | b1bd594acd9e661f26cdcb2afc4c0f0949555682 /arch/x86/kvm/i8254.c | |
parent | 16c2aec6a295f8a4916dbcbaa5051cf5c78be56a (diff) |
KVM: x86: Handle the kthread worker using the new API
Use the new API to create and destroy the "kvm-pit" kthread
worker. The API hides some implementation details.
In particular, kthread_create_worker() allocates and initializes
struct kthread_worker. It runs the kthread the right way
and stores task_struct into the worker structure.
kthread_destroy_worker() flushes all pending works, stops
the kthread and frees the structure.
This patch does not change the existing behavior except for
dynamically allocating struct kthread_worker and storing
only the pointer of this structure.
It is compile tested only because I did not find an easy
way how to run the code. Well, it should be pretty safe
given the nature of the change.
Signed-off-by: Petr Mladek <pmladek@suse.com>
Message-Id: <1476877847-11217-1-git-send-email-pmladek@suse.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm/i8254.c')
-rw-r--r-- | arch/x86/kvm/i8254.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/arch/x86/kvm/i8254.c b/arch/x86/kvm/i8254.c index 16a7134eedac..a78b445ce411 100644 --- a/arch/x86/kvm/i8254.c +++ b/arch/x86/kvm/i8254.c | |||
@@ -212,7 +212,7 @@ static void kvm_pit_ack_irq(struct kvm_irq_ack_notifier *kian) | |||
212 | */ | 212 | */ |
213 | smp_mb(); | 213 | smp_mb(); |
214 | if (atomic_dec_if_positive(&ps->pending) > 0) | 214 | if (atomic_dec_if_positive(&ps->pending) > 0) |
215 | kthread_queue_work(&pit->worker, &pit->expired); | 215 | kthread_queue_work(pit->worker, &pit->expired); |
216 | } | 216 | } |
217 | 217 | ||
218 | void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu) | 218 | void __kvm_migrate_pit_timer(struct kvm_vcpu *vcpu) |
@@ -272,7 +272,7 @@ static enum hrtimer_restart pit_timer_fn(struct hrtimer *data) | |||
272 | if (atomic_read(&ps->reinject)) | 272 | if (atomic_read(&ps->reinject)) |
273 | atomic_inc(&ps->pending); | 273 | atomic_inc(&ps->pending); |
274 | 274 | ||
275 | kthread_queue_work(&pt->worker, &pt->expired); | 275 | kthread_queue_work(pt->worker, &pt->expired); |
276 | 276 | ||
277 | if (ps->is_periodic) { | 277 | if (ps->is_periodic) { |
278 | hrtimer_add_expires_ns(&ps->timer, ps->period); | 278 | hrtimer_add_expires_ns(&ps->timer, ps->period); |
@@ -667,10 +667,8 @@ struct kvm_pit *kvm_create_pit(struct kvm *kvm, u32 flags) | |||
667 | pid_nr = pid_vnr(pid); | 667 | pid_nr = pid_vnr(pid); |
668 | put_pid(pid); | 668 | put_pid(pid); |
669 | 669 | ||
670 | kthread_init_worker(&pit->worker); | 670 | pit->worker = kthread_create_worker(0, "kvm-pit/%d", pid_nr); |
671 | pit->worker_task = kthread_run(kthread_worker_fn, &pit->worker, | 671 | if (IS_ERR(pit->worker)) |
672 | "kvm-pit/%d", pid_nr); | ||
673 | if (IS_ERR(pit->worker_task)) | ||
674 | goto fail_kthread; | 672 | goto fail_kthread; |
675 | 673 | ||
676 | kthread_init_work(&pit->expired, pit_do_work); | 674 | kthread_init_work(&pit->expired, pit_do_work); |
@@ -713,7 +711,7 @@ fail_register_speaker: | |||
713 | fail_register_pit: | 711 | fail_register_pit: |
714 | mutex_unlock(&kvm->slots_lock); | 712 | mutex_unlock(&kvm->slots_lock); |
715 | kvm_pit_set_reinject(pit, false); | 713 | kvm_pit_set_reinject(pit, false); |
716 | kthread_stop(pit->worker_task); | 714 | kthread_destroy_worker(pit->worker); |
717 | fail_kthread: | 715 | fail_kthread: |
718 | kvm_free_irq_source_id(kvm, pit->irq_source_id); | 716 | kvm_free_irq_source_id(kvm, pit->irq_source_id); |
719 | fail_request: | 717 | fail_request: |
@@ -730,8 +728,7 @@ void kvm_free_pit(struct kvm *kvm) | |||
730 | kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &pit->speaker_dev); | 728 | kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &pit->speaker_dev); |
731 | kvm_pit_set_reinject(pit, false); | 729 | kvm_pit_set_reinject(pit, false); |
732 | hrtimer_cancel(&pit->pit_state.timer); | 730 | hrtimer_cancel(&pit->pit_state.timer); |
733 | kthread_flush_work(&pit->expired); | 731 | kthread_destroy_worker(pit->worker); |
734 | kthread_stop(pit->worker_task); | ||
735 | kvm_free_irq_source_id(kvm, pit->irq_source_id); | 732 | kvm_free_irq_source_id(kvm, pit->irq_source_id); |
736 | kfree(pit); | 733 | kfree(pit); |
737 | } | 734 | } |