Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/12227
Change subject: base: If valgrind is available, tell it about Fiber stacks.
......................................................................
base: If valgrind is available, tell it about Fiber stacks.
Valgrind can get confused when switching stacks between different
Fibers. If valgrind (and its headers) are available, this change adds
calls to some hooks so valgrind knows where the new stacks are and
doesn't report a bunch of false positives.
Change-Id: I00aefe60372be6de7371dec29427d7182dbee7b6
---
M SConstruct
M src/base/fiber.cc
M src/base/fiber.hh
3 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/SConstruct b/SConstruct
index 5209aa6..79522e4 100755
--- a/SConstruct
+++ b/SConstruct
@@ -783,6 +783,10 @@
conf.CheckLibWithHeader('protobuf', 'google/protobuf/message.h',
'C++', 'GOOGLE_PROTOBUF_VERIFY_VERSION;')
+# Valgrind gets much less confused if you tell it when you're using
+# alternative stacks.
+main['HAVE_VALGRIND'] = conf.CheckCHeader('valgrind/valgrind.h')
+
# If we have the compiler but not the library, print another warning.
if main['PROTOC'] and not main['HAVE_PROTOBUF']:
print(termcap.Yellow + termcap.Bold +
@@ -1012,8 +1016,8 @@
# These variables get exported to #defines in config/*.hh (see
src/SConscript).
export_vars +=
['USE_FENV', 'SS_COMPATIBLE_FP', 'TARGET_ISA', 'TARGET_GPU_ISA',
'CP_ANNOTATE', 'USE_POSIX_CLOCK', 'USE_KVM', 'USE_TUNTAP',
- 'PROTOCOL', 'HAVE_PROTOBUF', 'HAVE_PERF_ATTR_EXCLUDE_HOST',
- 'USE_PNG']
+ 'PROTOCOL', 'HAVE_PROTOBUF', 'HAVE_VALGRIND',
+ 'HAVE_PERF_ATTR_EXCLUDE_HOST', 'USE_PNG']
###################################################
#
diff --git a/src/base/fiber.cc b/src/base/fiber.cc
index f10f1fb..9e6e2bf 100644
--- a/src/base/fiber.cc
+++ b/src/base/fiber.cc
@@ -29,10 +29,13 @@
#include "base/fiber.hh"
+#include <valgrind/valgrind.h>
+
#include <cerrno>
#include <cstring>
#include "base/logging.hh"
+#include "config/have_valgrind.hh"
using namespace std;
@@ -71,7 +74,11 @@
link(primaryFiber()),
stack(stack_size ? new uint8_t[stack_size] : nullptr),
stackSize(stack_size), started(false), _finished(false)
-{}
+{
+#if HAVE_VALGRIND
+ valgrindStackId = VALGRIND_STACK_REGISTER(stack, stack + stack_size);
+#endif
+}
Fiber::Fiber(Fiber *link, size_t stack_size) :
link(link), stack(stack_size ? new uint8_t[stack_size] : nullptr),
@@ -81,6 +88,9 @@
Fiber::~Fiber()
{
panic_if(stack && _currentFiber == this, "Fiber stack is in use.");
+#if HAVE_VALGRIND
+ VALGRIND_STACK_DEREGISTER(valgrindStackId);
+#endif
delete [] stack;
}
diff --git a/src/base/fiber.hh b/src/base/fiber.hh
index 5f7285b..3d82075 100644
--- a/src/base/fiber.hh
+++ b/src/base/fiber.hh
@@ -44,6 +44,8 @@
#include <cstddef>
#include <cstdint>
+#include "config/have_valgrind.hh"
+
/**
* This class represents a fiber, which is a light weight sort of thread
which
* is cooperatively scheduled and runs sequentially with other fibers,
swapping
@@ -106,6 +108,9 @@
// The stack for this context, or a nullptr if allocated elsewhere.
uint8_t *stack;
size_t stackSize;
+#if HAVE_VALGRIND
+ unsigned valgrindStackId;
+#endif
bool started;
bool _finished;
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12227
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I00aefe60372be6de7371dec29427d7182dbee7b6
Gerrit-Change-Number: 12227
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev