Lines Matching refs:stimer

43 static void stimer_mark_pending(struct kvm_vcpu_hv_stimer *stimer,
202 struct kvm_vcpu_hv_stimer *stimer; in kvm_hv_notify_acked_sint() local
208 for (idx = 0; idx < ARRAY_SIZE(hv_vcpu->stimer); idx++) { in kvm_hv_notify_acked_sint()
209 stimer = &hv_vcpu->stimer[idx]; in kvm_hv_notify_acked_sint()
210 if (stimer->msg_pending && stimer->config.enable && in kvm_hv_notify_acked_sint()
211 !stimer->config.direct_mode && in kvm_hv_notify_acked_sint()
212 stimer->config.sintx == sint) in kvm_hv_notify_acked_sint()
213 stimer_mark_pending(stimer, false); in kvm_hv_notify_acked_sint()
565 static void stimer_mark_pending(struct kvm_vcpu_hv_stimer *stimer, in stimer_mark_pending() argument
568 struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer); in stimer_mark_pending()
570 set_bit(stimer->index, in stimer_mark_pending()
577 static void stimer_cleanup(struct kvm_vcpu_hv_stimer *stimer) in stimer_cleanup() argument
579 struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer); in stimer_cleanup()
581 trace_kvm_hv_stimer_cleanup(hv_stimer_to_vcpu(stimer)->vcpu_id, in stimer_cleanup()
582 stimer->index); in stimer_cleanup()
584 hrtimer_cancel(&stimer->timer); in stimer_cleanup()
585 clear_bit(stimer->index, in stimer_cleanup()
587 stimer->msg_pending = false; in stimer_cleanup()
588 stimer->exp_time = 0; in stimer_cleanup()
593 struct kvm_vcpu_hv_stimer *stimer; in stimer_timer_callback() local
595 stimer = container_of(timer, struct kvm_vcpu_hv_stimer, timer); in stimer_timer_callback()
596 trace_kvm_hv_stimer_callback(hv_stimer_to_vcpu(stimer)->vcpu_id, in stimer_timer_callback()
597 stimer->index); in stimer_timer_callback()
598 stimer_mark_pending(stimer, true); in stimer_timer_callback()
608 static int stimer_start(struct kvm_vcpu_hv_stimer *stimer) in stimer_start() argument
613 time_now = get_time_ref_counter(hv_stimer_to_vcpu(stimer)->kvm); in stimer_start()
616 if (stimer->config.periodic) { in stimer_start()
617 if (stimer->exp_time) { in stimer_start()
618 if (time_now >= stimer->exp_time) { in stimer_start()
621 div64_u64_rem(time_now - stimer->exp_time, in stimer_start()
622 stimer->count, &remainder); in stimer_start()
623 stimer->exp_time = in stimer_start()
624 time_now + (stimer->count - remainder); in stimer_start()
627 stimer->exp_time = time_now + stimer->count; in stimer_start()
630 hv_stimer_to_vcpu(stimer)->vcpu_id, in stimer_start()
631 stimer->index, in stimer_start()
632 time_now, stimer->exp_time); in stimer_start()
634 hrtimer_start(&stimer->timer, in stimer_start()
636 100 * (stimer->exp_time - time_now)), in stimer_start()
640 stimer->exp_time = stimer->count; in stimer_start()
641 if (time_now >= stimer->count) { in stimer_start()
648 stimer_mark_pending(stimer, false); in stimer_start()
652 trace_kvm_hv_stimer_start_one_shot(hv_stimer_to_vcpu(stimer)->vcpu_id, in stimer_start()
653 stimer->index, in stimer_start()
654 time_now, stimer->count); in stimer_start()
656 hrtimer_start(&stimer->timer, in stimer_start()
657 ktime_add_ns(ktime_now, 100 * (stimer->count - time_now)), in stimer_start()
662 static int stimer_set_config(struct kvm_vcpu_hv_stimer *stimer, u64 config, in stimer_set_config() argument
666 old_config = {.as_uint64 = stimer->config.as_uint64}; in stimer_set_config()
667 struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer); in stimer_set_config()
679 trace_kvm_hv_stimer_set_config(hv_stimer_to_vcpu(stimer)->vcpu_id, in stimer_set_config()
680 stimer->index, config, host); in stimer_set_config()
682 stimer_cleanup(stimer); in stimer_set_config()
686 stimer->config.as_uint64 = new_config.as_uint64; in stimer_set_config()
688 if (stimer->config.enable) in stimer_set_config()
689 stimer_mark_pending(stimer, false); in stimer_set_config()
694 static int stimer_set_count(struct kvm_vcpu_hv_stimer *stimer, u64 count, in stimer_set_count() argument
697 struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer); in stimer_set_count()
703 trace_kvm_hv_stimer_set_count(hv_stimer_to_vcpu(stimer)->vcpu_id, in stimer_set_count()
704 stimer->index, count, host); in stimer_set_count()
706 stimer_cleanup(stimer); in stimer_set_count()
707 stimer->count = count; in stimer_set_count()
708 if (stimer->count == 0) in stimer_set_count()
709 stimer->config.enable = 0; in stimer_set_count()
710 else if (stimer->config.auto_enable) in stimer_set_count()
711 stimer->config.enable = 1; in stimer_set_count()
713 if (stimer->config.enable) in stimer_set_count()
714 stimer_mark_pending(stimer, false); in stimer_set_count()
719 static int stimer_get_config(struct kvm_vcpu_hv_stimer *stimer, u64 *pconfig) in stimer_get_config() argument
721 *pconfig = stimer->config.as_uint64; in stimer_get_config()
725 static int stimer_get_count(struct kvm_vcpu_hv_stimer *stimer, u64 *pcount) in stimer_get_count() argument
727 *pcount = stimer->count; in stimer_get_count()
788 static int stimer_send_msg(struct kvm_vcpu_hv_stimer *stimer) in stimer_send_msg() argument
790 struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer); in stimer_send_msg()
791 struct hv_message *msg = &stimer->msg; in stimer_send_msg()
799 bool no_retry = stimer->config.periodic; in stimer_send_msg()
801 payload->expiration_time = stimer->exp_time; in stimer_send_msg()
804 stimer->config.sintx, msg, in stimer_send_msg()
808 static int stimer_notify_direct(struct kvm_vcpu_hv_stimer *stimer) in stimer_notify_direct() argument
810 struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer); in stimer_notify_direct()
813 .vector = stimer->config.apic_vector in stimer_notify_direct()
821 static void stimer_expiration(struct kvm_vcpu_hv_stimer *stimer) in stimer_expiration() argument
823 int r, direct = stimer->config.direct_mode; in stimer_expiration()
825 stimer->msg_pending = true; in stimer_expiration()
827 r = stimer_send_msg(stimer); in stimer_expiration()
829 r = stimer_notify_direct(stimer); in stimer_expiration()
830 trace_kvm_hv_stimer_expiration(hv_stimer_to_vcpu(stimer)->vcpu_id, in stimer_expiration()
831 stimer->index, direct, r); in stimer_expiration()
833 stimer->msg_pending = false; in stimer_expiration()
834 if (!(stimer->config.periodic)) in stimer_expiration()
835 stimer->config.enable = 0; in stimer_expiration()
842 struct kvm_vcpu_hv_stimer *stimer; in kvm_hv_process_stimers() local
849 for (i = 0; i < ARRAY_SIZE(hv_vcpu->stimer); i++) in kvm_hv_process_stimers()
851 stimer = &hv_vcpu->stimer[i]; in kvm_hv_process_stimers()
852 if (stimer->config.enable) { in kvm_hv_process_stimers()
853 exp_time = stimer->exp_time; in kvm_hv_process_stimers()
859 stimer_expiration(stimer); in kvm_hv_process_stimers()
862 if ((stimer->config.enable) && in kvm_hv_process_stimers()
863 stimer->count) { in kvm_hv_process_stimers()
864 if (!stimer->msg_pending) in kvm_hv_process_stimers()
865 stimer_start(stimer); in kvm_hv_process_stimers()
867 stimer_cleanup(stimer); in kvm_hv_process_stimers()
880 for (i = 0; i < ARRAY_SIZE(hv_vcpu->stimer); i++) in kvm_hv_vcpu_uninit()
881 stimer_cleanup(&hv_vcpu->stimer[i]); in kvm_hv_vcpu_uninit()
910 static void stimer_prepare_msg(struct kvm_vcpu_hv_stimer *stimer) in stimer_prepare_msg() argument
912 struct hv_message *msg = &stimer->msg; in stimer_prepare_msg()
920 payload->timer_index = stimer->index; in stimer_prepare_msg()
925 static void stimer_init(struct kvm_vcpu_hv_stimer *stimer, int timer_index) in stimer_init() argument
927 memset(stimer, 0, sizeof(*stimer)); in stimer_init()
928 stimer->index = timer_index; in stimer_init()
929 hrtimer_init(&stimer->timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); in stimer_init()
930 stimer->timer.function = stimer_timer_callback; in stimer_init()
931 stimer_prepare_msg(stimer); in stimer_init()
952 for (i = 0; i < ARRAY_SIZE(hv_vcpu->stimer); i++) in kvm_hv_vcpu_init()
953 stimer_init(&hv_vcpu->stimer[i], i); in kvm_hv_vcpu_init()