From 54bfab9cb07e72157aa5295902263f4b2e37ed0b Mon Sep 17 00:00:00 2001 From: Jed Davis Date: Thu, 11 Jul 2013 23:41:19 -0400 Subject: [PATCH] Bug 892201: replace SPS signal handler completion busy loop with POSIX semaphore. r=benwa --HG-- extra : rebase_source : 48bfcc1a352ae600dd1294d5b5e122ad0c58a745 --- tools/profiler/platform-linux.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tools/profiler/platform-linux.cc b/tools/profiler/platform-linux.cc index ef0f68b1bb9..abafadc5f18 100644 --- a/tools/profiler/platform-linux.cc +++ b/tools/profiler/platform-linux.cc @@ -53,6 +53,7 @@ #include // open #include // open #include // sysconf +#include #ifdef __GLIBC__ #include // backtrace, backtrace_symbols #endif // def __GLIBC__ @@ -62,6 +63,7 @@ #include "platform.h" #include "GeckoProfilerImpl.h" #include "mozilla/Mutex.h" +#include "mozilla/Atomics.h" #include "ProfileEntry.h" #include "nsThreadUtils.h" #include "TableTicker.h" @@ -140,7 +142,8 @@ struct SamplerRegistry { Sampler *SamplerRegistry::sampler = NULL; -static ThreadProfile* sCurrentThreadProfile = NULL; +static mozilla::Atomic sCurrentThreadProfile; +static sem_t sSignalHandlingDone; static void ProfilerSaveSignalHandler(int signal, siginfo_t* info, void* context) { Sampler::GetActiveSampler()->RequestSave(); @@ -204,6 +207,7 @@ static void ProfilerSignalHandler(int signal, siginfo_t* info, void* context) { Sampler::GetActiveSampler()->Tick(sample); sCurrentThreadProfile = NULL; + sem_post(&sSignalHandlingDone); } int tgkill(pid_t tgid, pid_t tid, int signalno) { @@ -270,8 +274,7 @@ static void* SignalSender(void* arg) { } // Wait for the signal handler to run before moving on to the next one - while (sCurrentThreadProfile) - sched_yield(); + sem_wait(&sSignalHandlingDone); } } @@ -304,6 +307,13 @@ void Sampler::Start() { SamplerRegistry::AddActiveSampler(this); + // Initialize signal handler communication + sCurrentThreadProfile = NULL; + if (sem_init(&sSignalHandlingDone, /* pshared: */ 0, /* value: */ 0) != 0) { + LOG("Error initializing semaphore"); + return; + } + // Request profiling signals. LOG("Request signal"); struct sigaction sa;