From 36a216eefc8c1d46bc6704cd355d55abbea33c41 Mon Sep 17 00:00:00 2001 From: Jason Molenda Date: Thu, 24 Jul 2014 01:36:24 +0000 Subject: [PATCH] Increase the gdb-remote packet timeout for the first packet we send to the remote side (QStartNoAckMode) - it may take a little longer than normal to get a reply. In debugserver, hardcode the priority for several threads so they aren't de-prioritized when a user app is using system resources. Also, set the names of the threads. llvm-svn: 213828 --- .../gdb-remote/GDBRemoteCommunicationClient.cpp | 12 +++++++- lldb/tools/debugserver/source/DNB.cpp | 32 ++++++++++++++++++++++ .../tools/debugserver/source/MacOSX/MachProcess.mm | 9 ++++++ lldb/tools/debugserver/source/MacOSX/MachTask.mm | 19 +++++++++++++ lldb/tools/debugserver/source/RNBContext.cpp | 19 +++++++++++++ lldb/tools/debugserver/source/RNBRemote.cpp | 19 +++++++++++++ lldb/tools/debugserver/source/debugserver.cpp | 17 ++++++++++++ 7 files changed, 126 insertions(+), 1 deletion(-) diff --git a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp index 9bc0a96..3eb3d97 100644 --- a/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp +++ b/lldb/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp @@ -227,8 +227,18 @@ GDBRemoteCommunicationClient::QueryNoAckModeSupported () m_send_acks = true; m_supports_not_sending_acks = eLazyBoolNo; + // This is the first real packet that we'll send in a debug session and it may take a little + // longer than normal to receive a reply. Wait at least 6 seconds for a reply to this packet. + + const uint32_t minimum_timeout = 6; + uint32_t old_timeout = GetPacketTimeoutInMicroSeconds() / lldb_private::TimeValue::MicroSecPerSec; + SetPacketTimeout (std::max (old_timeout, minimum_timeout)); + StringExtractorGDBRemote response; - if (SendPacketAndWaitForResponse("QStartNoAckMode", response, false) == PacketResult::Success) + PacketResult packet_send_result = SendPacketAndWaitForResponse("QStartNoAckMode", response, false); + SetPacketTimeout (old_timeout); + + if (packet_send_result == PacketResult::Success) { if (response.IsOKResponse()) { diff --git a/lldb/tools/debugserver/source/DNB.cpp b/lldb/tools/debugserver/source/DNB.cpp index abd1661..304c655 100644 --- a/lldb/tools/debugserver/source/DNB.cpp +++ b/lldb/tools/debugserver/source/DNB.cpp @@ -26,6 +26,11 @@ #include #include +#if defined (__APPLE__) +#include +#include +#endif + #define TRY_KQUEUE 1 #ifdef TRY_KQUEUE @@ -141,6 +146,19 @@ kqueue_thread (void *arg) { int kq_id = (int) (intptr_t) arg; +#if defined (__APPLE__) + pthread_setname_np ("kqueue thread"); +#if defined (__arm__) || defined (__arm64__) || defined (__aarch64__) + struct sched_param thread_param; + int thread_sched_policy; + if (pthread_getschedparam(pthread_self(), &thread_sched_policy, &thread_param) == 0) + { + thread_param.sched_priority = 47; + pthread_setschedparam(pthread_self(), thread_sched_policy, &thread_param); + } +#endif +#endif + struct kevent death_event; while (1) { @@ -265,6 +283,20 @@ waitpid_thread (void *arg) { const pid_t pid = (pid_t)(intptr_t)arg; int status; + +#if defined (__APPLE__) + pthread_setname_np ("waitpid thread"); +#if defined (__arm__) || defined (__arm64__) || defined (__aarch64__) + struct sched_param thread_param; + int thread_sched_policy; + if (pthread_getschedparam(pthread_self(), &thread_sched_policy, &thread_param) == 0) + { + thread_param.sched_priority = 47; + pthread_setschedparam(pthread_self(), thread_sched_policy, &thread_param); + } +#endif +#endif + while (1) { pid_t child_pid = waitpid(pid, &status, 0); diff --git a/lldb/tools/debugserver/source/MacOSX/MachProcess.mm b/lldb/tools/debugserver/source/MacOSX/MachProcess.mm index 565a4ef..98cf95e 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachProcess.mm +++ b/lldb/tools/debugserver/source/MacOSX/MachProcess.mm @@ -22,6 +22,7 @@ #include #include #include +#include #include "MacOSX/CFUtils.h" #include "SysSignal.h" @@ -1445,6 +1446,10 @@ MachProcess::STDIOThread(void *arg) MachProcess *proc = (MachProcess*) arg; DNBLogThreadedIf(LOG_PROCESS, "MachProcess::%s ( arg = %p ) thread starting...", __FUNCTION__, arg); +#if defined (__APPLE__) + pthread_setname_np ("stdio monitoring thread"); +#endif + // We start use a base and more options so we can control if we // are currently using a timeout on the mach_msg. We do this to get a // bunch of related exceptions on our exception port so we can process @@ -1611,6 +1616,10 @@ MachProcess::ProfileThread(void *arg) MachProcess *proc = (MachProcess*) arg; DNBLogThreadedIf(LOG_PROCESS, "MachProcess::%s ( arg = %p ) thread starting...", __FUNCTION__, arg); +#if defined (__APPLE__) + pthread_setname_np ("performance profiling thread"); +#endif + while (proc->IsProfilingEnabled()) { nub_state_t state = proc->GetState(); diff --git a/lldb/tools/debugserver/source/MacOSX/MachTask.mm b/lldb/tools/debugserver/source/MacOSX/MachTask.mm index fa7bf24..c14b377 100644 --- a/lldb/tools/debugserver/source/MacOSX/MachTask.mm +++ b/lldb/tools/debugserver/source/MacOSX/MachTask.mm @@ -23,6 +23,11 @@ #include #import +#if defined (__APPLE__) +#include +#include +#endif + // C++ Includes #include #include @@ -640,6 +645,7 @@ bool MachTask::StartExceptionThread(DNBError &err) { DNBLogThreadedIf(LOG_EXCEPTIONS, "MachTask::%s ( )", __FUNCTION__); + task_t task = TaskPortForProcessID(err); if (MachTask::IsValid(task)) { @@ -731,6 +737,19 @@ MachTask::ExceptionThread (void *arg) MachProcess *mach_proc = mach_task->Process(); DNBLogThreadedIf(LOG_EXCEPTIONS, "MachTask::%s ( arg = %p ) starting thread...", __FUNCTION__, arg); +#if defined (__APPLE__) + pthread_setname_np ("exception monitoring thread"); +#if defined (__arm__) || defined (__arm64__) || defined (__aarch64__) + struct sched_param thread_param; + int thread_sched_policy; + if (pthread_getschedparam(pthread_self(), &thread_sched_policy, &thread_param) == 0) + { + thread_param.sched_priority = 47; + pthread_setschedparam(pthread_self(), thread_sched_policy, &thread_param); + } +#endif +#endif + // We keep a count of the number of consecutive exceptions received so // we know to grab all exceptions without a timeout. We do this to get a // bunch of related exceptions on our exception port so we can process diff --git a/lldb/tools/debugserver/source/RNBContext.cpp b/lldb/tools/debugserver/source/RNBContext.cpp index b9189df..960d6d99 100644 --- a/lldb/tools/debugserver/source/RNBContext.cpp +++ b/lldb/tools/debugserver/source/RNBContext.cpp @@ -16,6 +16,11 @@ #include #include +#if defined (__APPLE__) +#include +#include +#endif + #include "RNBRemote.h" #include "DNB.h" #include "DNBLog.h" @@ -145,6 +150,20 @@ RNBContext::ThreadFunctionProcessStatus(void *arg) nub_process_t pid = ctx.ProcessID(); DNBLogThreadedIf(LOG_RNB_PROC, "RNBContext::%s (arg=%p, pid=%4.4x): thread starting...", __FUNCTION__, arg, pid); ctx.Events().SetEvents (RNBContext::event_proc_thread_running); + +#if defined (__APPLE__) + pthread_setname_np ("child process status watcher thread"); +#if defined (__arm__) || defined (__arm64__) || defined (__aarch64__) + struct sched_param thread_param; + int thread_sched_policy; + if (pthread_getschedparam(pthread_self(), &thread_sched_policy, &thread_param) == 0) + { + thread_param.sched_priority = 47; + pthread_setschedparam(pthread_self(), thread_sched_policy, &thread_param); + } +#endif +#endif + bool done = false; while (!done) { diff --git a/lldb/tools/debugserver/source/RNBRemote.cpp b/lldb/tools/debugserver/source/RNBRemote.cpp index c731fbe..aa5bcd1 100644 --- a/lldb/tools/debugserver/source/RNBRemote.cpp +++ b/lldb/tools/debugserver/source/RNBRemote.cpp @@ -20,6 +20,11 @@ #include #include +#if defined (__APPLE__) +#include +#include +#endif + #include "DNB.h" #include "DNBDataRef.h" #include "DNBLog.h" @@ -755,6 +760,20 @@ RNBRemote::ThreadFunctionReadRemoteData(void *arg) RNBRemoteSP remoteSP(g_remoteSP); if (remoteSP.get() != NULL) { + +#if defined (__APPLE__) + pthread_setname_np ("read gdb-remote packets thread"); +#if defined (__arm__) || defined (__arm64__) || defined (__aarch64__) + struct sched_param thread_param; + int thread_sched_policy; + if (pthread_getschedparam(pthread_self(), &thread_sched_policy, &thread_param) == 0) + { + thread_param.sched_priority = 47; + pthread_setschedparam(pthread_self(), thread_sched_policy, &thread_param); + } +#endif +#endif + RNBRemote* remote = remoteSP.get(); PThreadEvent& events = remote->Context().Events(); events.SetEvents (RNBContext::event_read_thread_running); diff --git a/lldb/tools/debugserver/source/debugserver.cpp b/lldb/tools/debugserver/source/debugserver.cpp index 07d674d..c46d63d 100644 --- a/lldb/tools/debugserver/source/debugserver.cpp +++ b/lldb/tools/debugserver/source/debugserver.cpp @@ -25,6 +25,10 @@ #include #include // for _NSGetEnviron() +#if defined (__APPLE__) +#include +#endif + #include "CFString.h" #include "DNB.h" #include "DNBLog.h" @@ -877,6 +881,19 @@ main (int argc, char *argv[]) { const char *argv_sub_zero = argv[0]; // save a copy of argv[0] for error reporting post-launch +#if defined (__APPLE__) + pthread_setname_np ("main thread"); +#if defined (__arm__) || defined (__arm64__) || defined (__aarch64__) + struct sched_param thread_param; + int thread_sched_policy; + if (pthread_getschedparam(pthread_self(), &thread_sched_policy, &thread_param) == 0) + { + thread_param.sched_priority = 47; + pthread_setschedparam(pthread_self(), thread_sched_policy, &thread_param); + } +#endif +#endif + g_isatty = ::isatty (STDIN_FILENO); // ::printf ("uid=%u euid=%u gid=%u egid=%u\n", -- 2.7.4