From 5f1c38764d4d23587234740d215342e7daf11f87 Mon Sep 17 00:00:00 2001 From: Jeffrey Altman Date: Fri, 25 Jun 2004 20:48:44 +0000 Subject: [PATCH] hyperthreading-bad-20040625 Give folks an option of running afsd_service.exe on fewer processors than are installed in the machine. A new registry value TransarcAfsDaemon/Parameters MaxCPUs allows a restriction to be applied. Set to 1 to use a single CPU (or hyperthreading instance) The restriction is applied with SetProcessAffinityMask() --- src/WINNT/afsd/afsd_init.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/WINNT/afsd/afsd_init.c b/src/WINNT/afsd/afsd_init.c index 5da8aceba4..e7bc28a383 100644 --- a/src/WINNT/afsd/afsd_init.c +++ b/src/WINNT/afsd/afsd_init.c @@ -205,6 +205,7 @@ int afsd_InitCM(char **reasonP) long logChunkSize; long stats; long traceBufSize; + long maxcpus; long ltt, ltto; long rx_mtu, rx_nojumbo; char rootCellName[256]; @@ -258,6 +259,42 @@ int afsd_InitCM(char **reasonP) osi_panic(buf, __FILE__, __LINE__); } + dummyLen = sizeof(maxcpus); + code = RegQueryValueEx(parmKey, "MaxCPUs", NULL, NULL, + (BYTE *) &maxcpus, &dummyLen); + if (code == ERROR_SUCCESS) { + HANDLE hProcess; + DWORD_PTR processAffinityMask, systemAffinityMask; + + hProcess = OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_SET_INFORMATION, + FALSE, GetCurrentProcessId()); + if ( hProcess != NULL && + GetProcessAffinityMask(hProcess, &processAffinityMask, &systemAffinityMask) ) + { + int i, n, bits; + DWORD_PTR mask, newAffinityMask; + +#if defined(_WIN64) + bits = 64; +#else + bits = 32; +#endif + for ( i=0, n=0, mask=1, newAffinityMask=0; i