From f34e11b10099371e861fa417c8336d26c24ad578 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 18 Oct 2010 10:12:23 +0000 Subject: Look at GNUPG_RNDW32_NOPERF --- random/ChangeLog | 5 ++++ random/rndw32.c | 75 +++++++++++++++++++++++++++++++++----------------------- 2 files changed, 49 insertions(+), 31 deletions(-) diff --git a/random/ChangeLog b/random/ChangeLog index 9feb32c7..f70f30b4 100644 --- a/random/ChangeLog +++ b/random/ChangeLog @@ -1,3 +1,8 @@ +2010-10-18 Werner Koch + + * rndw32.c (registry_poll): Disable performace fata gathering if + GNUPG_RNDW32_NOPERF has been set. + 2010-04-27 Marcus Brinkmann * rndw32ce.c (fillup_buffer): Rewrite without using nested diff --git a/random/rndw32.c b/random/rndw32.c index 852f9aca..c48eba76 100644 --- a/random/rndw32.c +++ b/random/rndw32.c @@ -418,45 +418,58 @@ registry_poll (void (*add)(const void*, size_t, enum random_origins), this can consume tens of MB of memory and huge amounts of CPU time while it gathers its data, and even running once can still consume about 1/2MB of memory */ - pPerfData = gcry_xmalloc (cbPerfData); - for (iterations=0; iterations < 10; iterations++) + if (getenv ("GNUPG_RNDW32_NOPERF")) { - dwSize = cbPerfData; - if ( debug_me ) - log_debug ("rndw32#slow_gatherer_nt: get perf data\n" ); - - status = RegQueryValueEx (HKEY_PERFORMANCE_DATA, "Global", NULL, - NULL, (LPBYTE) pPerfData, &dwSize); - if (status == ERROR_SUCCESS) - { - if (!memcmp (pPerfData->Signature, L"PERF", 8)) - (*add) ( pPerfData, dwSize, requester ); - else - log_debug ("rndw32: no PERF signature\n"); - break; - } - else if (status == ERROR_MORE_DATA) + static int shown; + + if (!shown) { - cbPerfData += PERFORMANCE_BUFFER_STEP; - pPerfData = gcry_xrealloc (pPerfData, cbPerfData); + shown = 1; + log_info ("note: get performance data has been disabled\n"); } - else + } + else + { + pPerfData = gcry_xmalloc (cbPerfData); + for (iterations=0; iterations < 10; iterations++) { - static int been_here; - - /* Silence the error message. In particular under Wine (as - of 2008) we would get swamped with such diagnotiscs. One - such diagnotiscs should be enough. */ - if (been_here != status) + dwSize = cbPerfData; + if ( debug_me ) + log_debug ("rndw32#slow_gatherer_nt: get perf data\n" ); + + status = RegQueryValueEx (HKEY_PERFORMANCE_DATA, "Global", NULL, + NULL, (LPBYTE) pPerfData, &dwSize); + if (status == ERROR_SUCCESS) { - been_here = status; - log_debug ("rndw32: get performance data problem: ec=%ld\n", - status); + if (!memcmp (pPerfData->Signature, L"PERF", 8)) + (*add) ( pPerfData, dwSize, requester ); + else + log_debug ("rndw32: no PERF signature\n"); + break; + } + else if (status == ERROR_MORE_DATA) + { + cbPerfData += PERFORMANCE_BUFFER_STEP; + pPerfData = gcry_xrealloc (pPerfData, cbPerfData); + } + else + { + static int been_here; + + /* Silence the error message. In particular under Wine (as + of 2008) we would get swamped with such diagnotiscs. One + such diagnotiscs should be enough. */ + if (been_here != status) + { + been_here = status; + log_debug ("rndw32: get performance data problem: ec=%ld\n", + status); + } + break; } - break; } + gcry_free (pPerfData); } - gcry_free (pPerfData); /* Although this isn't documented in the Win32 API docs, it's necessary to explicitly close the HKEY_PERFORMANCE_DATA key after use (it's -- cgit v1.2.1