public float GetCurrentFrequencyRatio(out float error) { ulong mcnt_start, acnt_start, mcnt_stop, acnt_stop; ulong err_start, err_stop; do { uint eax_m = 0, edx_m = 0, eax_a = 0, edx_a = 0, eax_e = 0, edx_e = 0; ThreadAffinity.Set(ThreadAffinityMask); _ols.RdmsrTx(0xe8, ref eax_a, ref edx_a, PThread); _ols.RdmsrTx(0xe7, ref eax_m, ref edx_m, PThread); _ols.RdmsrTx(0xe8, ref eax_e, ref edx_e, PThread); mcnt_start = ((ulong)edx_m << 32) + eax_m; acnt_start = ((ulong)edx_a << 32) + eax_a; err_start = ((ulong)edx_a << 32) + eax_e; System.Threading.Thread.Sleep(20); _ols.RdmsrTx(0xe8, ref eax_a, ref edx_a, PThread); _ols.RdmsrTx(0xe7, ref eax_m, ref edx_m, PThread); _ols.RdmsrTx(0xe8, ref eax_e, ref edx_e, PThread); mcnt_stop = ((ulong)edx_m << 32) + eax_m; acnt_stop = ((ulong)edx_a << 32) + eax_a; err_stop = ((ulong)edx_a << 32) + eax_e; ThreadAffinity.Set(ThreadAffinityMask); } while (acnt_stop <= acnt_start || mcnt_stop <= mcnt_start); float res = (float)(acnt_stop - acnt_start) / (mcnt_stop - mcnt_start); error = Math.Abs(res - (float)(err_stop - err_start) / (mcnt_stop - mcnt_start)) / res; return(res); }
/* * public double GetCurrentFrequency() * { * ulong mask = 1UL << Thread; * ulong start_tsc, stop_tsc; * ulong start_pmc, stop_pmc; * ThreadAffinity.Set(mask); * if (GetPMCTSC(out start_pmc, out start_tsc)) * { * System.Threading.Thread.Sleep(30); * ThreadAffinity.Set(mask); * if (GetPMCTSC(out stop_pmc, out stop_tsc)) * { * return (double)(stop_pmc - start_pmc) / (stop_tsc - start_tsc); * } * } * ThreadAffinity.Set(mask); * return 0; * } */ public double Frequency() { ulong mask = 1UL << Thread; ThreadAffinity.Set(mask); EstimatePerformanceMonitoringCounterFrequency(out double outFreq, out double outError); ThreadAffinity.Set(mask); return(outFreq); }
public double GetCurrentFrequency() { ulong mask = 1UL << Thread; ulong mcnt_start, acnt_start, mcnt_stop, acnt_stop; uint eax_m = 0, edx_m = 0, eax_a = 0, edx_a = 0; int cnt = 0; ThreadAffinity.Set(mask); while (_ols.RdmsrTx(0xe8, ref eax_a, ref edx_a, pthread) == 0 || _ols.RdmsrTx(0xe7, ref eax_m, ref edx_m, pthread) == 0) { if (cnt < 4) { cnt++; } else { return(0); } } mcnt_start = ((ulong)edx_m << 32) + eax_m; acnt_start = ((ulong)edx_a << 32) + eax_a; cnt = 0; System.Threading.Thread.Sleep(30); while (_ols.RdmsrTx(0xe8, ref eax_a, ref edx_a, pthread) == 0 || _ols.RdmsrTx(0xe7, ref eax_m, ref edx_m, pthread) == 0) { if (cnt < 4) { cnt++; } else { return(0); } } mcnt_stop = ((ulong)edx_m << 32) + eax_m; acnt_stop = ((ulong)edx_a << 32) + eax_a; ThreadAffinity.Set(mask); return(2.7 * (acnt_stop - acnt_start) / (mcnt_stop - mcnt_start)); }