MHz calculate_cpu_frequency(){ // We expect the cpu_sampling_irq_handler to push in samples; while (_cpu_timestamps.size() < do_samples_) OS::halt(); debug("_cpu_sampling_freq_divider_ : %i \n",_cpu_sampling_freq_divider_); #ifdef DEBUG for (auto t : _cpu_timestamps) debug("%lu \n",(uint32_t)t); #endif // Subtract the time it takes to measure time :-) auto t1 = OS::cycles_since_boot(); OS::cycles_since_boot(); auto t3 = OS::cycles_since_boot(); auto overhead = (t3 - t1) * 2; debug ("Overhead: %lu \n", (uint32_t)overhead); for (size_t i = 1; i < _cpu_timestamps.size(); i++){ // Compute delta in cycles auto cycles = _cpu_timestamps[i] - _cpu_timestamps[i-1] + overhead; // Cycles pr. second == Hertz auto freq = cycles / (1 / test_frequency().count()); _cpu_freq_samples.push_back(freq); debug("%lu - %lu = Delta: %lu Current PIT-Freq: %f Hz CPU Freq: %f MHz \n", (uint32_t)_cpu_timestamps[i], (uint32_t)_cpu_timestamps[i-1], (uint32_t)cycles, Hz(test_frequency()), freq); } #ifdef DEBUG double sum = 0; for (auto freq : _cpu_freq_samples) sum += freq; double mean = sum / _cpu_freq_samples.size(); #endif std::sort(_cpu_freq_samples.begin(), _cpu_freq_samples.end()); double median = _cpu_freq_samples[_cpu_freq_samples.size() / 2]; debug("<cpu_freq> MEAN: %f MEDIAN: %f \n",mean, median); _CPUFreq_ = median; return MHz(median); }
static BOOL WINAPI dsenum_callback(LPGUID lpGuid, LPCSTR lpcstrDescription, LPCSTR lpcstrModule, LPVOID lpContext) { HRESULT rc; trace("*** Testing %s - %s ***\n",lpcstrDescription,lpcstrModule); /* Don't test the primary device */ if (!number++) { ok (!lpcstrModule[0], "lpcstrModule(%s) != NULL\n", lpcstrModule); return 1; } rc = test_dsound(lpGuid); if (rc == DSERR_NODRIVER) trace(" No Driver\n"); else if (rc == DSERR_ALLOCATED) trace(" Already In Use\n"); else if (rc == E_FAIL) trace(" No Device\n"); else { test_block_align(lpGuid); test_primary(lpGuid); test_primary_secondary(lpGuid); test_secondary(lpGuid); test_frequency(lpGuid); } return 1; }