[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Xen-devel] [PATCH 00/13] Add VMX TSC scaling support
- To: Jan Beulich <jbeulich@xxxxxxxx>, Aravind Gopalakrishnan <Aravind.Gopalakrishnan@xxxxxxx>, Ian Jackson <ian.jackson@xxxxxxxxxxxxx>, Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>, Ian Campbell <ian.campbell@xxxxxxxxxx>, Wei Liu <wei.liu2@xxxxxxxxxx>, Keir Fraser <keir@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Suravee Suthikulpanit <suravee.suthikulpanit@xxxxxxx>, Jun Nakajima <jun.nakajima@xxxxxxxxx>, Kevin Tian <kevin.tian@xxxxxxxxx>, George Dunlap <George.Dunlap@xxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxx
- From: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
- Date: Tue, 24 Nov 2015 09:19:55 -0500
- Delivery-date: Tue, 24 Nov 2015 14:22:18 +0000
- List-id: Xen developer discussion <xen-devel.lists.xen.org>
On 11/24/2015 08:05 AM, Haozhong Zhang wrote:
This bug can be fixed either later by patch 5 which introduces a
common function hvm_scale_tsc() to scale TSC, or by replacing above
underlined code with a simplified and inlined version of
hvm_scale_tsc() as below:
uint64_t mult, frac;
mult = ratio >> 32;
frac = ratio & ((1ULL << 32) - 1);
offset = host_tsc * mult;
offset += (host_tsc >> 32) * frac;
offset += ((host_tsc & ((1ULL << 32) - 1)) * frac) >> 32;
I am not sure I understand the last line (or maybe 2 lines)
Just simple math with carefulness to avoid 64-bit integer overflow:
suppose the most significant 32 bits of host_tsc and ratio are tsc_h
and mult, and the least significant 32 bits of them are tsc_l and
frac, then
host_tsc * ratio * 2^-32
= host_tsc * (mult * 2^32 + frac) * 2^-32
= host_tsc * mult + (tsc_h * 2^32 + tsc_l) * frac * 2^-32
= host_tsc * mult + tsc_h * frac + ((tsc_l * frac) >> 32)
Ok, now I see. Please include this in patch comments.
-boris
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel
|