Lines Matching refs:stimer

65 static void stimer_mark_pending(struct kvm_vcpu_hv_stimer *stimer,
224 struct kvm_vcpu_hv_stimer *stimer;
230 for (idx = 0; idx < ARRAY_SIZE(hv_vcpu->stimer); idx++) {
231 stimer = &hv_vcpu->stimer[idx];
232 if (stimer->msg_pending && stimer->config.enable &&
233 !stimer->config.direct_mode &&
234 stimer->config.sintx == sint)
235 stimer_mark_pending(stimer, false);
587 static void stimer_mark_pending(struct kvm_vcpu_hv_stimer *stimer,
590 struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer);
592 set_bit(stimer->index,
599 static void stimer_cleanup(struct kvm_vcpu_hv_stimer *stimer)
601 struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer);
603 trace_kvm_hv_stimer_cleanup(hv_stimer_to_vcpu(stimer)->vcpu_id,
604 stimer->index);
606 hrtimer_cancel(&stimer->timer);
607 clear_bit(stimer->index,
609 stimer->msg_pending = false;
610 stimer->exp_time = 0;
615 struct kvm_vcpu_hv_stimer *stimer;
617 stimer = container_of(timer, struct kvm_vcpu_hv_stimer, timer);
618 trace_kvm_hv_stimer_callback(hv_stimer_to_vcpu(stimer)->vcpu_id,
619 stimer->index);
620 stimer_mark_pending(stimer, true);
627 * a) stimer->count is not equal to 0
628 * b) stimer->config has HV_STIMER_ENABLE flag
630 static int stimer_start(struct kvm_vcpu_hv_stimer *stimer)
635 time_now = get_time_ref_counter(hv_stimer_to_vcpu(stimer)->kvm);
638 if (stimer->config.periodic) {
639 if (stimer->exp_time) {
640 if (time_now >= stimer->exp_time) {
643 div64_u64_rem(time_now - stimer->exp_time,
644 stimer->count, &remainder);
645 stimer->exp_time =
646 time_now + (stimer->count - remainder);
649 stimer->exp_time = time_now + stimer->count;
652 hv_stimer_to_vcpu(stimer)->vcpu_id,
653 stimer->index,
654 time_now, stimer->exp_time);
656 hrtimer_start(&stimer->timer,
658 100 * (stimer->exp_time - time_now)),
662 stimer->exp_time = stimer->count;
663 if (time_now >= stimer->count) {
670 stimer_mark_pending(stimer, false);
674 trace_kvm_hv_stimer_start_one_shot(hv_stimer_to_vcpu(stimer)->vcpu_id,
675 stimer->index,
676 time_now, stimer->count);
678 hrtimer_start(&stimer->timer,
679 ktime_add_ns(ktime_now, 100 * (stimer->count - time_now)),
684 static int stimer_set_config(struct kvm_vcpu_hv_stimer *stimer, u64 config,
688 old_config = {.as_uint64 = stimer->config.as_uint64};
689 struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer);
701 trace_kvm_hv_stimer_set_config(hv_stimer_to_vcpu(stimer)->vcpu_id,
702 stimer->index, config, host);
704 stimer_cleanup(stimer);
708 stimer->config.as_uint64 = new_config.as_uint64;
710 if (stimer->config.enable)
711 stimer_mark_pending(stimer, false);
716 static int stimer_set_count(struct kvm_vcpu_hv_stimer *stimer, u64 count,
719 struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer);
725 trace_kvm_hv_stimer_set_count(hv_stimer_to_vcpu(stimer)->vcpu_id,
726 stimer->index, count, host);
728 stimer_cleanup(stimer);
729 stimer->count = count;
731 if (stimer->count == 0)
732 stimer->config.enable = 0;
733 else if (stimer->config.auto_enable)
734 stimer->config.enable = 1;
737 if (stimer->config.enable)
738 stimer_mark_pending(stimer, false);
743 static int stimer_get_config(struct kvm_vcpu_hv_stimer *stimer, u64 *pconfig)
745 *pconfig = stimer->config.as_uint64;
749 static int stimer_get_count(struct kvm_vcpu_hv_stimer *stimer, u64 *pcount)
751 *pcount = stimer->count;
812 static int stimer_send_msg(struct kvm_vcpu_hv_stimer *stimer)
814 struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer);
815 struct hv_message *msg = &stimer->msg;
823 bool no_retry = stimer->config.periodic;
825 payload->expiration_time = stimer->exp_time;
828 stimer->config.sintx, msg,
832 static int stimer_notify_direct(struct kvm_vcpu_hv_stimer *stimer)
834 struct kvm_vcpu *vcpu = hv_stimer_to_vcpu(stimer);
837 .vector = stimer->config.apic_vector
845 static void stimer_expiration(struct kvm_vcpu_hv_stimer *stimer)
847 int r, direct = stimer->config.direct_mode;
849 stimer->msg_pending = true;
851 r = stimer_send_msg(stimer);
853 r = stimer_notify_direct(stimer);
854 trace_kvm_hv_stimer_expiration(hv_stimer_to_vcpu(stimer)->vcpu_id,
855 stimer->index, direct, r);
857 stimer->msg_pending = false;
858 if (!(stimer->config.periodic))
859 stimer->config.enable = 0;
866 struct kvm_vcpu_hv_stimer *stimer;
873 for (i = 0; i < ARRAY_SIZE(hv_vcpu->stimer); i++)
875 stimer = &hv_vcpu->stimer[i];
876 if (stimer->config.enable) {
877 exp_time = stimer->exp_time;
883 stimer_expiration(stimer);
886 if ((stimer->config.enable) &&
887 stimer->count) {
888 if (!stimer->msg_pending)
889 stimer_start(stimer);
891 stimer_cleanup(stimer);
904 for (i = 0; i < ARRAY_SIZE(hv_vcpu->stimer); i++)
905 stimer_cleanup(&hv_vcpu->stimer[i]);
936 static void stimer_prepare_msg(struct kvm_vcpu_hv_stimer *stimer)
938 struct hv_message *msg = &stimer->msg;
946 payload->timer_index = stimer->index;
951 static void stimer_init(struct kvm_vcpu_hv_stimer *stimer, int timer_index)
953 memset(stimer, 0, sizeof(*stimer));
954 stimer->index = timer_index;
955 hrtimer_init(&stimer->timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
956 stimer->timer.function = stimer_timer_callback;
957 stimer_prepare_msg(stimer);
978 for (i = 0; i < ARRAY_SIZE(hv_vcpu->stimer); i++)
979 stimer_init(&hv_vcpu->stimer[i], i);