From mboxrd@z Thu Jan 1 00:00:00 1970 From: Boris Ostrovsky Subject: Re: [PATCH 00/13] Add VMX TSC scaling support Date: Tue, 24 Nov 2015 09:19:55 -0500 Message-ID: <5654720B.6080801@oracle.com> References: <1443424438-13404-1-git-send-email-haozhong.zhang@intel.com> <20151122175416.GA21693@hzzhang-OptiPlex-9020.sh.intel.com> <565332B9.9040200@oracle.com> <20151124130532.GA8995@hzzhang-desktop.sh.intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; Format="flowed" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <20151124130532.GA8995@hzzhang-desktop.sh.intel.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Jan Beulich , Aravind Gopalakrishnan , Ian Jackson , Stefano Stabellini , Ian Campbell , Wei Liu , Keir Fraser , Andrew Cooper , Suravee Suthikulpanit , Jun Nakajima , Kevin Tian , George Dunlap , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.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