Lines Matching refs:stimer
46 static void stimer_mark_pending(struct kvm_vcpu_hv_stimer *stimer,
198 struct kvm_vcpu_hv_stimer *stimer; in kvm_hv_notify_acked_sint() local
204 for (idx = 0; idx < ARRAY_SIZE(hv_vcpu->stimer); idx++) { in kvm_hv_notify_acked_sint()
205 stimer = &hv_vcpu->stimer[idx]; in kvm_hv_notify_acked_sint()
206 if (stimer->msg_pending && stimer->config.enable && in kvm_hv_notify_acked_sint()
207 !stimer->config.direct_mode && in kvm_hv_notify_acked_sint()
208 stimer->config.sintx == sint) in kvm_hv_notify_acked_sint()
209 stimer_mark_pending(stimer, false); in kvm_hv_notify_acked_sint()
555 static void stimer_mark_pending(struct kvm_vcpu_hv_stimer *stimer, in stimer_mark_pending() argument
558 struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer); in stimer_mark_pending()
560 set_bit(stimer->index, in stimer_mark_pending()
567 static void stimer_cleanup(struct kvm_vcpu_hv_stimer *stimer) in stimer_cleanup() argument
569 struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer); in stimer_cleanup()
571 trace_kvm_hv_stimer_cleanup(hv_stimer_to_vcpu(stimer)->vcpu_id, in stimer_cleanup()
572 stimer->index); in stimer_cleanup()
574 hrtimer_cancel(&stimer->timer); in stimer_cleanup()
575 clear_bit(stimer->index, in stimer_cleanup()
577 stimer->msg_pending = false; in stimer_cleanup()
578 stimer->exp_time = 0; in stimer_cleanup()
583 struct kvm_vcpu_hv_stimer *stimer; in stimer_timer_callback() local
585 stimer = container_of(timer, struct kvm_vcpu_hv_stimer, timer); in stimer_timer_callback()
586 trace_kvm_hv_stimer_callback(hv_stimer_to_vcpu(stimer)->vcpu_id, in stimer_timer_callback()
587 stimer->index); in stimer_timer_callback()
588 stimer_mark_pending(stimer, true); in stimer_timer_callback()
598 static int stimer_start(struct kvm_vcpu_hv_stimer *stimer) in stimer_start() argument
603 time_now = get_time_ref_counter(hv_stimer_to_vcpu(stimer)->kvm); in stimer_start()
606 if (stimer->config.periodic) { in stimer_start()
607 if (stimer->exp_time) { in stimer_start()
608 if (time_now >= stimer->exp_time) { in stimer_start()
611 div64_u64_rem(time_now - stimer->exp_time, in stimer_start()
612 stimer->count, &remainder); in stimer_start()
613 stimer->exp_time = in stimer_start()
614 time_now + (stimer->count - remainder); in stimer_start()
617 stimer->exp_time = time_now + stimer->count; in stimer_start()
620 hv_stimer_to_vcpu(stimer)->vcpu_id, in stimer_start()
621 stimer->index, in stimer_start()
622 time_now, stimer->exp_time); in stimer_start()
624 hrtimer_start(&stimer->timer, in stimer_start()
626 100 * (stimer->exp_time - time_now)), in stimer_start()
630 stimer->exp_time = stimer->count; in stimer_start()
631 if (time_now >= stimer->count) { in stimer_start()
638 stimer_mark_pending(stimer, false); in stimer_start()
642 trace_kvm_hv_stimer_start_one_shot(hv_stimer_to_vcpu(stimer)->vcpu_id, in stimer_start()
643 stimer->index, in stimer_start()
644 time_now, stimer->count); in stimer_start()
646 hrtimer_start(&stimer->timer, in stimer_start()
647 ktime_add_ns(ktime_now, 100 * (stimer->count - time_now)), in stimer_start()
652 static int stimer_set_config(struct kvm_vcpu_hv_stimer *stimer, u64 config, in stimer_set_config() argument
656 old_config = {.as_uint64 = stimer->config.as_uint64}; in stimer_set_config()
657 struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer); in stimer_set_config()
669 trace_kvm_hv_stimer_set_config(hv_stimer_to_vcpu(stimer)->vcpu_id, in stimer_set_config()
670 stimer->index, config, host); in stimer_set_config()
672 stimer_cleanup(stimer); in stimer_set_config()
676 stimer->config.as_uint64 = new_config.as_uint64; in stimer_set_config()
678 if (stimer->config.enable) in stimer_set_config()
679 stimer_mark_pending(stimer, false); in stimer_set_config()
684 static int stimer_set_count(struct kvm_vcpu_hv_stimer *stimer, u64 count, in stimer_set_count() argument
687 struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer); in stimer_set_count()
693 trace_kvm_hv_stimer_set_count(hv_stimer_to_vcpu(stimer)->vcpu_id, in stimer_set_count()
694 stimer->index, count, host); in stimer_set_count()
696 stimer_cleanup(stimer); in stimer_set_count()
697 stimer->count = count; in stimer_set_count()
698 if (stimer->count == 0) in stimer_set_count()
699 stimer->config.enable = 0; in stimer_set_count()
700 else if (stimer->config.auto_enable) in stimer_set_count()
701 stimer->config.enable = 1; in stimer_set_count()
703 if (stimer->config.enable) in stimer_set_count()
704 stimer_mark_pending(stimer, false); in stimer_set_count()
709 static int stimer_get_config(struct kvm_vcpu_hv_stimer *stimer, u64 *pconfig) in stimer_get_config() argument
711 *pconfig = stimer->config.as_uint64; in stimer_get_config()
715 static int stimer_get_count(struct kvm_vcpu_hv_stimer *stimer, u64 *pcount) in stimer_get_count() argument
717 *pcount = stimer->count; in stimer_get_count()
778 static int stimer_send_msg(struct kvm_vcpu_hv_stimer *stimer) in stimer_send_msg() argument
780 struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer); in stimer_send_msg()
781 struct hv_message *msg = &stimer->msg; in stimer_send_msg()
789 bool no_retry = stimer->config.periodic; in stimer_send_msg()
791 payload->expiration_time = stimer->exp_time; in stimer_send_msg()
794 stimer->config.sintx, msg, in stimer_send_msg()
798 static int stimer_notify_direct(struct kvm_vcpu_hv_stimer *stimer) in stimer_notify_direct() argument
800 struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer); in stimer_notify_direct()
803 .vector = stimer->config.apic_vector in stimer_notify_direct()
811 static void stimer_expiration(struct kvm_vcpu_hv_stimer *stimer) in stimer_expiration() argument
813 int r, direct = stimer->config.direct_mode; in stimer_expiration()
815 stimer->msg_pending = true; in stimer_expiration()
817 r = stimer_send_msg(stimer); in stimer_expiration()
819 r = stimer_notify_direct(stimer); in stimer_expiration()
820 trace_kvm_hv_stimer_expiration(hv_stimer_to_vcpu(stimer)->vcpu_id, in stimer_expiration()
821 stimer->index, direct, r); in stimer_expiration()
823 stimer->msg_pending = false; in stimer_expiration()
824 if (!(stimer->config.periodic)) in stimer_expiration()
825 stimer->config.enable = 0; in stimer_expiration()
832 struct kvm_vcpu_hv_stimer *stimer; in kvm_hv_process_stimers() local
839 for (i = 0; i < ARRAY_SIZE(hv_vcpu->stimer); i++) in kvm_hv_process_stimers()
841 stimer = &hv_vcpu->stimer[i]; in kvm_hv_process_stimers()
842 if (stimer->config.enable) { in kvm_hv_process_stimers()
843 exp_time = stimer->exp_time; in kvm_hv_process_stimers()
849 stimer_expiration(stimer); in kvm_hv_process_stimers()
852 if ((stimer->config.enable) && in kvm_hv_process_stimers()
853 stimer->count) { in kvm_hv_process_stimers()
854 if (!stimer->msg_pending) in kvm_hv_process_stimers()
855 stimer_start(stimer); in kvm_hv_process_stimers()
857 stimer_cleanup(stimer); in kvm_hv_process_stimers()
870 for (i = 0; i < ARRAY_SIZE(hv_vcpu->stimer); i++) in kvm_hv_vcpu_uninit()
871 stimer_cleanup(&hv_vcpu->stimer[i]); in kvm_hv_vcpu_uninit()
900 static void stimer_prepare_msg(struct kvm_vcpu_hv_stimer *stimer) in stimer_prepare_msg() argument
902 struct hv_message *msg = &stimer->msg; in stimer_prepare_msg()
910 payload->timer_index = stimer->index; in stimer_prepare_msg()
915 static void stimer_init(struct kvm_vcpu_hv_stimer *stimer, int timer_index) in stimer_init() argument
917 memset(stimer, 0, sizeof(*stimer)); in stimer_init()
918 stimer->index = timer_index; in stimer_init()
919 hrtimer_init(&stimer->timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); in stimer_init()
920 stimer->timer.function = stimer_timer_callback; in stimer_init()
921 stimer_prepare_msg(stimer); in stimer_init()
939 for (i = 0; i < ARRAY_SIZE(hv_vcpu->stimer); i++) in kvm_hv_vcpu_init()
940 stimer_init(&hv_vcpu->stimer[i], i); in kvm_hv_vcpu_init()