Bug 1880373 - cache the CPU frequency in ProcInfo_win before enabling the sandbox in utility processes, r=gerard-majax.

Depends on D201884

Differential Revision: https://phabricator.services.mozilla.com/D201885
This commit is contained in:
Florian Quèze 2024-02-15 16:20:45 +00:00
Родитель 3c7da682b6
Коммит 4a4a3befb2
3 изменённых файлов: 27 добавлений и 10 удалений

Просмотреть файл

@ -7,6 +7,7 @@
#include "mozilla/ipc/IOThreadChild.h"
#include "mozilla/GeckoArgs.h"
#include "mozilla/ProcInfo.h"
#if defined(XP_WIN)
# include "nsExceptionHandler.h"
@ -90,6 +91,10 @@ bool UtilityProcessImpl::Init(int aArgc, char* aArgv[]) {
// lower the sandbox in processes where the policy will prevent loading.
LoadLibraryOrCrash(L"winmm.dll");
// Call this once before enabling the sandbox, it will cache its result
// in a static variable.
GetCpuFrequencyMHz();
if (*sandboxingKind == SandboxingKind::GENERIC_UTILITY) {
// Preload audio generic libraries required for ffmpeg only
UtilityAudioDecoderParent::GenericPreloadForSandbox();

Просмотреть файл

@ -73,6 +73,10 @@ using UtilityActorName = mozilla::dom::WebIDLUtilityActorName;
// String that will be used e.g. to annotate crash reports
nsCString GetUtilityActorName(const UtilityActorName aActorName);
#ifdef XP_WIN
int GetCpuFrequencyMHz();
#endif
/* Get the CPU frequency to use to convert cycle time values to actual time.
* @returns the TSC (Time Stamp Counter) frequency in MHz, or 0 if converting
* cycle time values should not be attempted. */

Просмотреть файл

@ -32,17 +32,9 @@ static uint64_t ToNanoSeconds(const FILETIME& aFileTime) {
return usec.QuadPart * 100;
}
int GetCycleTimeFrequencyMHz() {
int GetCpuFrequencyMHz() {
static const int frequency = []() {
// Having a constant TSC is required to convert cycle time to actual time.
// In automation, having short CPU times reported as 0 is more of a problem
// than having an imprecise value. The fallback method can't report CPU
// times < 1/64s.
if (!mozilla::has_constant_tsc() && !xpc::IsInAutomation()) {
return 0;
}
// Now get the nominal CPU frequency.
// Get the nominal CPU frequency.
HKEY key;
static const WCHAR keyName[] =
L"HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0";
@ -64,6 +56,22 @@ int GetCycleTimeFrequencyMHz() {
return frequency;
}
int GetCycleTimeFrequencyMHz() {
static const int frequency = []() {
// Having a constant TSC is required to convert cycle time to actual time.
// In automation, having short CPU times reported as 0 is more of a problem
// than having an imprecise value. The fallback method can't report CPU
// times < 1/64s.
if (!mozilla::has_constant_tsc() && !xpc::IsInAutomation()) {
return 0;
}
return GetCpuFrequencyMHz();
}();
return frequency;
}
nsresult GetCpuTimeSinceProcessStartInMs(uint64_t* aResult) {
int frequencyInMHz = GetCycleTimeFrequencyMHz();
if (frequencyInMHz) {