From: Paolo Bonzini <pbonzini@redhat.com>
To: Yunhong Jiang <yunhong.jiang@linux.intel.com>, kvm@vger.kernel.org
Cc: mtosatti@redhat.com, rkrcmar@redhat.com, kernellwp@gmail.com
Subject: Re: [RFC PATCH V3 2/5] Add function for left shift and 64 bit division
Date: Mon, 6 Jun 2016 14:37:24 +0200 [thread overview]
Message-ID: <8dbf2eaf-ea7d-b7d0-633e-889f2081912f@redhat.com> (raw)
In-Reply-To: <1465000951-13343-3-git-send-email-yunhong.jiang@linux.intel.com>
On 04/06/2016 02:42, Yunhong Jiang wrote:
> From: Yunhong Jiang <yunhong.jiang@intel.com>
>
> Sometimes we need convert from guest tsc to host tsc, which is:
> host_tsc = ((unsigned __int128)(guest_tsc - tsc_offset)
> << kvm_tsc_scaling_ratio_frac_bits)
> / vcpu->arch.tsc_scaling_ratio;
> where guest_tsc and host_tsc are both 64 bit.
>
> A helper function is provided to achieve this conversion. Only supported
> on x86_64 platform now. A generic solution can be provided in future if
> needed.
>
> Signed-off-by: Yunhong Jiang <yunhong.jiang@intel.com>
> ---
> arch/x86/include/asm/div64.h | 18 ++++++++++++++++++
Please put this in vmx.c instead. You can merge it with patch 3, even.
Thanks,
Paolo
> 1 file changed, 18 insertions(+)
>
> diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
> index ced283ac79df..6937d6d4c81a 100644
> --- a/arch/x86/include/asm/div64.h
> +++ b/arch/x86/include/asm/div64.h
> @@ -60,6 +60,24 @@ static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
> #define div_u64_rem div_u64_rem
>
> #else
> +#include <linux/types.h>
> +/* (a << shift) / divisor, return 1 if overflow otherwise 0 */
> +static inline int u64_shl_div_u64(u64 a, unsigned int shift,
> + u64 divisor, u64 *result)
> +{
> + u64 low = a << shift, high = a >> (64 - shift);
> +
> + /* To avoid the overflow on divq */
> + if (high > divisor)
> + return 1;
> +
> + /* Low hold the result, high hold rem which is discarded */
> + asm("divq %2\n\t" : "=a" (low), "=d" (high) :
> + "rm" (divisor), "0" (low), "1" (high));
> + *result = low;
> +
> + return 0;
> +}
> # include <asm-generic/div64.h>
> #endif /* CONFIG_X86_32 */
>
>
next prev parent reply other threads:[~2016-06-06 12:37 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-04 0:42 [RFC PATCH V3 0/5] Utilizing VMX preemption for timer virtualization Yunhong Jiang
2016-06-04 0:42 ` [RFC PATCH V3 1/5] Rename the vmx_pre/post_block to pi_pre/post_block Yunhong Jiang
2016-06-04 0:42 ` [RFC PATCH V3 2/5] Add function for left shift and 64 bit division Yunhong Jiang
2016-06-06 12:37 ` Paolo Bonzini [this message]
2016-06-04 0:42 ` [RFC PATCH V3 3/5] Utilize the vmx preemption timer Yunhong Jiang
2016-06-06 12:37 ` Paolo Bonzini
2016-06-04 0:42 ` [RFC PATCH V3 4/5] Separate the start_sw_tscdeadline Yunhong Jiang
2016-06-04 0:42 ` [RFC PATCH V3 5/5] Utilize the vmx preemption timer for tsc deadline timer Yunhong Jiang
2016-06-06 12:36 ` Paolo Bonzini
2016-06-06 12:45 ` [RFC PATCH V3 0/5] Utilizing VMX preemption for timer virtualization Paolo Bonzini
2016-06-06 18:26 ` yunhong jiang
2016-06-07 16:31 ` David Matlack
2016-06-07 19:30 ` David Matlack
2016-06-08 4:18 ` Wanpeng Li
2016-06-13 20:56 ` yunhong jiang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=8dbf2eaf-ea7d-b7d0-633e-889f2081912f@redhat.com \
--to=pbonzini@redhat.com \
--cc=kernellwp@gmail.com \
--cc=kvm@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=rkrcmar@redhat.com \
--cc=yunhong.jiang@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox