Question about patch "svm: fix incorrect TSC scaling"
Dongli Zhang
Reviewed-by Boris OstrovskyHi Haozhong and AMD SVM maintainers,
I am writing to ask about below patch as I am not familiar with AMD tsc scaling:
commit 11eeca65126e51f03a883907751d5ccbe4f35aa3
Author: Haozhong Zhang <[email protected]>
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.
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?
Thank you very much!
Dongli Zhang
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 36 lines
Quoted 1 line
Quoted 1 line · On 28.05.18 at 14:25, <[email protected]> wrote:
I am writing to ask about below patch as I am not familiar with AMD tsc scaling:
commit
11eeca65126e51f03a883907751d5ccbe4f35aa3
Author: Haozhong Zhang <[email protected]>
Date: Tue Dec 8 09:46:12 2015 +0100svm: fix incorrect TSC scaling
SVM TSC ratio is incorrectly used in the current
svm_get_tsc_offset(). This patch replaces the scaling logic insvm_get_tsc_offset()with a correct implementation.Signed-off-by Haozhong Zhang <[email protected]>Reviewed-by Boris Ostrovsky <[email protected]>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:
Quoted 8 lines
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).
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 45 lines · Jan Beulich
Quoted 36 lines
Quoted 1 line
Quoted 1 line · On 28.05.18 at 14:25, <[email protected]> wrote:
I am writing to ask about below patch as I am not familiar with AMD tsc scaling:
commit
11eeca65126e51f03a883907751d5ccbe4f35aa3
Author: Haozhong Zhang <[email protected]>
Date: Tue Dec 8 09:46:12 2015 +0100svm: fix incorrect TSC scaling
SVM TSC ratio is incorrectly used in the current
svm_get_tsc_offset(). This patch replaces the scaling logic insvm_get_tsc_offset()with a correct implementation.Signed-off-by Haozhong Zhang <[email protected]>Reviewed-by Boris Ostrovsky <[email protected]>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:
Quoted 8 lines
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?
Quoted 6 lines
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
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 21 lines · Dongli Zhang
Quoted 18 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 28.05.18 at 14:25, <[email protected]> wrote:
I am writing to ask about below patch as I am not familiar with AMD tsc scaling:
commit
11eeca65126e51f03a883907751d5ccbe4f35aa3
Author: Haozhong Zhang <[email protected]>
Date: Tue Dec 8 09:46:12 2015 +0100svm: fix incorrect TSC scaling
SVM TSC ratio is incorrectly used in the current
svm_get_tsc_offset(). This patch replaces the scaling logic insvm_get_tsc_offset()with a correct implementation.Signed-off-by Haozhong Zhang <[email protected]>Reviewed-by Boris Ostrovsky <[email protected]>
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
The below equation is used in the above patch:
-------------------------
host_tsc* ratio * 2^-32.
-------------------------
Indeed, I have an extra question that why 2^-32 is involved here?
Is it because we would like to ignore the frag part and only consider the leading integer part? Why not just use "host_tsc * ratio"?
Thank you very much!
Dongli Zhang
Quoted 29 lines
Quoted 22 lines
Quoted 13 lines
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:
Quoted 8 lines
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?
Quoted 6 lines
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).
Quoted 6 lines
Thank you very much for the explanation!
Now it is clear to me.
Dongli Zhang
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 27 lines
Quoted 1 line
Quoted 1 line · On 29.05.18 at 12:31, <[email protected]> wrote:
Quoted 23 lines · Dongli Zhang
Quoted 20 lines · Jan Beulich
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 28.05.18 at 14:25, <[email protected]> wrote:
I am writing to ask about below patch as I am not familiar with AMD tsc scaling:
commit
11eeca65126e51f03a883907751d5ccbe4f35aa3
Author: Haozhong Zhang <[email protected]>
Date: Tue Dec 8 09:46:12 2015 +0100svm: fix incorrect TSC scaling
SVM TSC ratio is incorrectly used in the current
svm_get_tsc_offset(). This patch replaces the scaling logic insvm_get_tsc_offset()with a correct implementation.Signed-off-by Haozhong Zhang <[email protected]>Reviewed-by Boris Ostrovsky <[email protected]>The below equation is used in the above patch:
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
-------------------------
host_tsc* ratio * 2^-32.
-------------------------Indeed, I have an extra question that why 2^-32 is involved here?
Is it because we would like to ignore the frag part and only consider the leading integer part? Why not just use "
host_tsc* ratio"?
Quoting the PM: "The TSC Ratio MSR specifies the TSCRatio value as a fixed-point binary number in 8.32 format, ..." IOW this is to convert ratio from its presentation (uint64_t) to its purpose (a fixed point value with 8 [really 32] bits representing the integer part and 32 bits of fraction). We very certainly don't want to ignore the fractional part.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel