From 0184a841d3914bb78c7c6fa87ce9da86a2d5992a Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 31 Dec 2012 11:17:50 +0000 Subject: Begin sketching out the process interface. The coding style used here is not LLVM's style because this is modeled after a Boost interface and thus done in the style of a candidate C++ standard library interface. I'll probably end up proposing it as a standard C++ library if it proves to be reasonably portable and useful. This is just the most basic parts of the interface -- getting the process ID out of it. However, it helps sketch out some of the boiler plate such as the base class, derived class, shared code, and static factory function. It also introduces a unittest so that I can incrementally ensure this stuff works. However, I've not even compiled this code for Windows yet. I'll try to fix any Windows fallout from the bots, and if I can't fix it I'll revert and get someone on Windows to help out. There isn't a lot more that is mandatory, so soon I'll switch to just stubbing out the Windows side and get Michael Spencer to help with implementation as he can test it directly. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171289 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Process.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'lib/Support/Process.cpp') diff --git a/lib/Support/Process.cpp b/lib/Support/Process.cpp index 88ca7c3f22..8d1b64897c 100644 --- a/lib/Support/Process.cpp +++ b/lib/Support/Process.cpp @@ -11,8 +11,9 @@ // //===----------------------------------------------------------------------===// -#include "llvm/Support/Process.h" #include "llvm/Config/config.h" +#include "llvm/Support/Process.h" +#include "llvm/Support/ErrorHandling.h" namespace llvm { using namespace sys; @@ -22,6 +23,25 @@ using namespace sys; //=== independent code. //===----------------------------------------------------------------------===// +// Empty virtual destructor to anchor the vtable for the process class. +process::~process() {} + +self_process *process::get_self() { + // Use a function local static for thread safe initialization and allocate it + // as a raw pointer to ensure it is never destroyed. + static self_process *SP = new self_process(); + + return SP; +} + +// The destructor for the self_process subclass must never actually be +// executed. There should be at most one instance of this class, and that +// instance should live until the process terminates to avoid the potential for +// racy accesses during shutdown. +self_process::~self_process() { + llvm_unreachable("This destructor must never be executed!"); +} + } // Include the platform-specific parts of this class. -- cgit v1.2.3-18-g5258 From c9bdcac41213f3994709fd06de8d85dbc1b2daa1 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 31 Dec 2012 11:39:02 +0000 Subject: Suppress a MSVC warning complaining about the code working as intended. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171290 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Process.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lib/Support/Process.cpp') diff --git a/lib/Support/Process.cpp b/lib/Support/Process.cpp index 8d1b64897c..5f8655efc6 100644 --- a/lib/Support/Process.cpp +++ b/lib/Support/Process.cpp @@ -34,14 +34,27 @@ self_process *process::get_self() { return SP; } +#if defined(_MSC_VER) +// Visual Studio complains that the self_process destructor never exits. This +// doesn't make much sense, as that's the whole point of calling abort... Just +// silence this warning. +#pragma warning(push) +#pragma warning(disable:4722) +#endif + // The destructor for the self_process subclass must never actually be // executed. There should be at most one instance of this class, and that // instance should live until the process terminates to avoid the potential for // racy accesses during shutdown. self_process::~self_process() { + assert(TempDirectory->exists() && "Who has removed TempDirectory?"); llvm_unreachable("This destructor must never be executed!"); } +#if defined(_MSC_VER) +#pragma warning(pop) +#endif + } // Include the platform-specific parts of this class. -- cgit v1.2.3-18-g5258 From 8e98c1f2540be6e5adfcae15064a831fa0b3a8c9 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 31 Dec 2012 11:40:04 +0000 Subject: Delete a cut/paste-o from r171290. Very sorry about the noise. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171291 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Process.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/Support/Process.cpp') diff --git a/lib/Support/Process.cpp b/lib/Support/Process.cpp index 5f8655efc6..6e24c45fa0 100644 --- a/lib/Support/Process.cpp +++ b/lib/Support/Process.cpp @@ -47,7 +47,6 @@ self_process *process::get_self() { // instance should live until the process terminates to avoid the potential for // racy accesses during shutdown. self_process::~self_process() { - assert(TempDirectory->exists() && "Who has removed TempDirectory?"); llvm_unreachable("This destructor must never be executed!"); } -- cgit v1.2.3-18-g5258 From 9b4aba85a89f9347212e00f80953f2a685ffeb36 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 31 Dec 2012 11:45:20 +0000 Subject: Switch this code to a more idiomatic double using namespace directive. Fix a truly odd namespace qualifier that was flat out wrong in the process. The fully qualified namespace would have been llvm::sys::TimeValue, llvm::TimeValue makes no sense. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171292 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Process.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/Support/Process.cpp') diff --git a/lib/Support/Process.cpp b/lib/Support/Process.cpp index 6e24c45fa0..1e21d64e60 100644 --- a/lib/Support/Process.cpp +++ b/lib/Support/Process.cpp @@ -15,7 +15,7 @@ #include "llvm/Support/Process.h" #include "llvm/Support/ErrorHandling.h" -namespace llvm { +using namespace llvm; using namespace sys; //===----------------------------------------------------------------------===// @@ -54,7 +54,6 @@ self_process::~self_process() { #pragma warning(pop) #endif -} // Include the platform-specific parts of this class. #ifdef LLVM_ON_UNIX -- cgit v1.2.3-18-g5258 From 814afe91ccad0e5e1f767303d780fa0318fa5212 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 31 Dec 2012 23:23:35 +0000 Subject: Flesh out a page size accessor in the new API. Implement the old API in terms of the new one. This simplifies the implementation on Windows which can now re-use the self_process's once initialization. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171330 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Process.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/Support/Process.cpp') diff --git a/lib/Support/Process.cpp b/lib/Support/Process.cpp index 1e21d64e60..9d87b7744b 100644 --- a/lib/Support/Process.cpp +++ b/lib/Support/Process.cpp @@ -55,6 +55,14 @@ self_process::~self_process() { #endif +//===----------------------------------------------------------------------===// +// Implementations of legacy functions in terms of the new self_process object. + +unsigned Process::GetPageSize() { + return process::get_self()->page_size(); +} + + // Include the platform-specific parts of this class. #ifdef LLVM_ON_UNIX #include "Unix/Process.inc" -- cgit v1.2.3-18-g5258 From f5867ab7178784bc63a3deafcf4fb09260e4d19a Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Mon, 31 Dec 2012 23:31:56 +0000 Subject: Go ahead and get rid of the old page size interface and convert all the users over to the new one. No sense maintaining this "compatibility" layer it seems. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171331 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Process.cpp | 8 -------- 1 file changed, 8 deletions(-) (limited to 'lib/Support/Process.cpp') diff --git a/lib/Support/Process.cpp b/lib/Support/Process.cpp index 9d87b7744b..1e21d64e60 100644 --- a/lib/Support/Process.cpp +++ b/lib/Support/Process.cpp @@ -55,14 +55,6 @@ self_process::~self_process() { #endif -//===----------------------------------------------------------------------===// -// Implementations of legacy functions in terms of the new self_process object. - -unsigned Process::GetPageSize() { - return process::get_self()->page_size(); -} - - // Include the platform-specific parts of this class. #ifdef LLVM_ON_UNIX #include "Unix/Process.inc" -- cgit v1.2.3-18-g5258 From 58a2cbef4aac9ee7d530dfb690c78d6fc11a2371 Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Wed, 2 Jan 2013 10:22:59 +0000 Subject: Resort the #include lines in include/... and lib/... with the utils/sort_includes.py script. Most of these are updating the new R600 target and fixing up a few regressions that have creeped in since the last time I sorted the includes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171362 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Process.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/Support/Process.cpp') diff --git a/lib/Support/Process.cpp b/lib/Support/Process.cpp index 1e21d64e60..64a1fa237e 100644 --- a/lib/Support/Process.cpp +++ b/lib/Support/Process.cpp @@ -12,8 +12,8 @@ //===----------------------------------------------------------------------===// #include "llvm/Config/config.h" -#include "llvm/Support/Process.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/Process.h" using namespace llvm; using namespace sys; -- cgit v1.2.3-18-g5258 From 73c35d86b9d5236be5b3f49bc8df11008b96636e Mon Sep 17 00:00:00 2001 From: Chandler Carruth Date: Fri, 4 Jan 2013 23:19:55 +0000 Subject: Add time getters to the process interface for requesting the elapsed wall time, user time, and system time since a process started. For walltime, we currently use TimeValue's interface and a global initializer to compute a close approximation of total process runtime. For user time, this adds support for an somewhat more precise timing mechanism -- clock_gettime with the CLOCK_PROCESS_CPUTIME_ID clock selected. For system time, we have to do a full getrusage call to extract the system time from the OS. This is expensive but unavoidable. In passing, clean up the implementation of the old APIs and fix some latent bugs in the Windows code. This might have manifested on Windows ARM systems or other systems with strange 64-bit integer behavior. The old API for this both user time and system time simultaneously from a single getrusage call. While this results in fewer system calls, it also results in a lower precision user time and if only user time is desired, it introduces a higher overhead. It may be worthwhile to switch some of the pass timers to not track system time and directly track user and wall time. The old API also tracked walltime in a confusing way -- it just set it to the current walltime rather than providing any measure of wall time since the process started the way buth user and system time are tracked. The new API is more consistent here. The plan is to eventually implement these methods for a *child* process by using the wait3(2) system call to populate an rusage struct representing the whole subprocess execution. That way, after waiting on a child process its stats will become accurate and cheap to query. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@171551 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/Process.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib/Support/Process.cpp') diff --git a/lib/Support/Process.cpp b/lib/Support/Process.cpp index 64a1fa237e..2c0d37bb32 100644 --- a/lib/Support/Process.cpp +++ b/lib/Support/Process.cpp @@ -50,6 +50,31 @@ self_process::~self_process() { llvm_unreachable("This destructor must never be executed!"); } +/// \brief A helper function to compute the elapsed wall-time since the program +/// started. +/// +/// Note that this routine actually computes the elapsed wall time since the +/// first time it was called. However, we arrange to have it called during the +/// startup of the process to get approximately correct results. +static TimeValue getElapsedWallTime() { + static TimeValue &StartTime = *new TimeValue(TimeValue::now()); + return TimeValue::now() - StartTime; +} + +/// \brief A special global variable to ensure we call \c getElapsedWallTime +/// during global initialization of the program. +/// +/// Note that this variable is never referenced elsewhere. Doing so could +/// create race conditions during program startup or shutdown. +static volatile TimeValue DummyTimeValue = getElapsedWallTime(); + +// Implement this routine by using the static helpers above. They're already +// portable. +TimeValue self_process::get_wall_time() const { + return getElapsedWallTime(); +} + + #if defined(_MSC_VER) #pragma warning(pop) #endif -- cgit v1.2.3-18-g5258