From mboxrd@z Thu Jan 1 00:00:00 1970 From: Alan Jenkins Subject: Re: [RFC PATCH V2 4/4] Utilize the vmx preemption timer for tsc deadline timer Date: Thu, 26 May 2016 15:05:04 +0100 Message-ID: References: <1464128852-14138-1-git-send-email-yunhong.jiang@linux.intel.com> <1464128852-14138-5-git-send-email-yunhong.jiang@linux.intel.com> <4d3a7b46-f663-92f0-8d3d-d95cf9aa10f2@redhat.com> <20160525154420.2c7fdcd3@jnakajim-build> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org, mtosatti@redhat.com, rkrcmar@redhat.com, kernellwp@gmail.com To: yunhong jiang , Paolo Bonzini Return-path: Received: from mail-wm0-f67.google.com ([74.125.82.67]:35057 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754013AbcEZOFI (ORCPT ); Thu, 26 May 2016 10:05:08 -0400 Received: by mail-wm0-f67.google.com with SMTP id e3so5785646wme.2 for ; Thu, 26 May 2016 07:05:08 -0700 (PDT) In-Reply-To: <20160525154420.2c7fdcd3@jnakajim-build> Sender: kvm-owner@vger.kernel.org List-ID: On 25/05/16 23:44, yunhong jiang wrote: > On Wed, 25 May 2016 13:52:56 +0200 > Paolo Bonzini wrote: > > Yes, this should save two VMCS access on the vcpu_run(). Will do this way. > >> >> The hardest part is converting guest_tsc to host_tsc. From >> >> guest_tsc = (host_tsc * vcpu->arch.tsc_scaling_ratio >> >> kvm_tsc_scaling_ratio_frac_bits) + tsc_offset >> >> you have >> >> host_tsc = ((unsigned __int128)(guest_tsc - tsc_offset) >> << kvm_tsc_scaling_ratio_frac_bits) >> / vcpu->arch.tsc_scaling_ratio; >> >> ... except that you need a division with a 128-bit dividend and a >> 64-bit divisor here, and there is no such thing in Linux. It's okay >> if you restrict this to 64-bit hosts and use the divq assembly >> instruction directly. (You also need to trap the divide overflow >> exception; if there is an overflow just disable the preemption >> timer). On 32-bit systems, it's okay to force-disable >> set_hv_timer/cancel_hv_timer, i.e. set them to NULL. > > I'm scared by this conversion :) Sure will hav a try. Need firstly check > how the scale_tsc works. aaaaaaaaaaaa 1. Against my interests: have you actually confirmed the VMX preemption timer is affected by guest TSC scaling? It's not explicit in the SDM. The way it's described for allocating timeslices to the guest, IMO it makes more sense if it is not scaled. 2. Paolo, any chance I could also get away with requiring 64-bit? I.e. #ifdef CONFIG_X86_64 #define HAVE_LAPIC_TIMER_ADVANCE 1 #endif Regards Alan