Bug 1645416 - Fix the TracePayload layout on 32bits and re-enable the static assert that check the struct has a size that is a power of two. r=achronop

Differential Revision: https://phabricator.services.mozilla.com/D80696
This commit is contained in:
Paul Adenot 2020-06-25 12:33:31 +00:00
Родитель b05ce30421
Коммит 39504b3094
2 изменённых файлов: 20 добавлений и 10 удалений

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

@ -51,21 +51,30 @@ class AsyncLogger {
char mPayload[PAYLOAD_TOTAL_SIZE - MPSC_MSG_RESERVERD];
};
// On 32bits the struct is packed differently and there is a hole we need to
// account for.
#if !defined(HAVE_64BIT_BUILD) && !(defined(XP_LINUX) && !defined(MOZ_WIDGET_ANDROID))
# define PADDING 8
#else
# define PADDING 0
#endif
// The order of the fields is important here to minimize padding.
struct TracePayload {
// The thread on which this tracepoint was gathered.
int mTID;
// If this marker is of phase X (COMPLETE), this holds the duration of the
// event in microseconds. Else, the value is not used.
uint32_t mDurationUs;
// If this marker is of phase B or E (begin or end), this is the time at
// which it was captured.
TimeStamp mTimestamp;
// If this marker is of phase X (COMPLETE), this holds the duration of the
// event in microseconds. Else, the value is not used.
uint32_t mDurationUs;
// The thread on which this tracepoint was gathered.
int mTID;
// An arbitrary string, usually containing a function signature or a
// recognizable tag of some sort, to be displayed when analyzing the
// profile.
char mName[PAYLOAD_TOTAL_SIZE - sizeof(TracingPhase) - sizeof(int) -
sizeof(uint32_t) - sizeof(TimeStamp) - MPSC_MSG_RESERVERD];
sizeof(uint32_t) - sizeof(TimeStamp) - MPSC_MSG_RESERVERD -
PADDING];
// A trace payload can be either:
// - Begin - this marks the beginning of a temporal region
// - End - this marks the end of a temporal region
@ -73,6 +82,7 @@ class AsyncLogger {
// temporal region
TracingPhase mPhase;
};
#undef PADDING
// aLogModuleName is the name of the MOZ_LOG module.
explicit AsyncLogger(const char* aLogModuleName,
AsyncLogger::AsyncLoggerOutputMode aMode =

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

@ -22,7 +22,7 @@ namespace mozilla {
// allows having a simpler design, we count on the fact that jemalloc will get
// the memory from a thread-local source most of the time. We'll replace
// this with a fixed-size ring buffer if this becomes an issue.
const size_t MPSC_MSG_RESERVERD = sizeof(void*);
const size_t MPSC_MSG_RESERVERD = sizeof(std::atomic<void*>);
template <typename T>
class MPSCQueue {
@ -32,8 +32,8 @@ class MPSCQueue {
Message(const Message& aMessage) = delete;
void operator=(const Message& aMessage) = delete;
T data;
std::atomic<Message*> mNext;
T data;
};
// The goal here is to make it easy on the allocator. We pack a pointer in the
@ -43,9 +43,9 @@ class MPSCQueue {
// making it cheap and, more importantly, lock-free enough. This has been
// measured to be cheap and reliable enough, but will be replaced in the
// longer run.
#if !defined(XP_WIN) && !defined(MOZ_WIDGET_ANDROID)
#if !(defined(ANDROID) && defined(__i386__))
static_assert(IsPowerOfTwo(sizeof(MPSCQueue<T>::Message)),
"MPSCQueue internal allocations must have a size that is a"
"MPSCQueue internal allocations must have a size that is a "
"power of two ");
#endif