[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] Question about patch "svm: fix incorrect TSC scaling"




On 05/29/2018 05:56 PM, Jan Beulich wrote:
>>>> On 28.05.18 at 14:25, <dongli.zhang@xxxxxxxxxx> wrote:
>> I am writing to ask about below patch as I am not familiar with AMD tsc
>> scaling:
>>
>>  commit 11eeca65126e51f03a883907751d5ccbe4f35aa3
>>  Author: Haozhong Zhang <haozhong.zhang@xxxxxxxxx>
>>  Date:   Tue Dec 8 09:46:12 2015 +0100
>>
>>      svm: fix incorrect TSC scaling
>>  
>>      SVM TSC ratio is incorrectly used in the current
>>      svm_get_tsc_offset(). This patch replaces the scaling logic in
>>      svm_get_tsc_offset() with a correct implementation.
>>  
>>      Signed-off-by: Haozhong Zhang <haozhong.zhang@xxxxxxxxx>
>>      Reviewed-by: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>
>>
>>
>> The below equation is used in the above patch:
>>
>> -------------------------
>> host_tsc * ratio * 2^-32.
>> -------------------------
>>
>>
>> While the below incorrect equation (indeed code) was used before above 
>> patch:
>>
>> ---------------------------------------------------------------
>> offset = (((host_tsc >> 32U) * (ratio >> 32U)) << 32U) +
>>          (host_tsc & 0xffffffffULL) * (ratio & 0xffffffffULL);
>> return guest_tsc - offset;
>> ---------------------------------------------------------------
>>
>> Can I summarize the above code as:
>>
>> tsc_h * mult * 2^32 + tsc_l * frag or
>>
>> tsc_h * int * 2^32 + tsc_l * frag ?
>>
>>
>> Would you please help confirm why the equation is replaced? Or would you 
>> please
>> help and let me know the chapter/page of AMD reference manual showing the
>> correct equation?
> 
> This has nothing to do with AMD's doc, but only with maths: To split
> a multiplication x * y when considering x = xh + xl (high and low parts)
> and y = yh + yl you get x * y = xh * yh + xh * yl + xl * yh + xl * xl.
> Width constraints make it unnecessary to calculate the xh * yh part
> here. The original expression, however, calculated something rather
> strange instead (only the xl * yl part was actually correct).

Thank you very much for the explanation!

Now it is clear to me.

Dongli Zhang

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.