[Lldb-commits] [lldb] r213828 - Increase the gdb-remote packet timeout for the first packet we send

Jason Molenda jmolenda at apple.com
Wed Jul 23 18:36:24 PDT 2014


Author: jmolenda
Date: Wed Jul 23 20:36:24 2014
New Revision: 213828

URL: http://llvm.org/viewvc/llvm-project?rev=213828&view=rev
Log:
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.

<rdar://problem/17509866>

Modified:
    lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
    lldb/trunk/tools/debugserver/source/DNB.cpp
    lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.mm
    lldb/trunk/tools/debugserver/source/MacOSX/MachTask.mm
    lldb/trunk/tools/debugserver/source/RNBContext.cpp
    lldb/trunk/tools/debugserver/source/RNBRemote.cpp
    lldb/trunk/tools/debugserver/source/debugserver.cpp

Modified: lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp?rev=213828&r1=213827&r2=213828&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/GDBRemoteCommunicationClient.cpp Wed Jul 23 20:36:24 2014
@@ -227,8 +227,18 @@ GDBRemoteCommunicationClient::QueryNoAck
         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())
             {

Modified: lldb/trunk/tools/debugserver/source/DNB.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/DNB.cpp?rev=213828&r1=213827&r2=213828&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/DNB.cpp (original)
+++ lldb/trunk/tools/debugserver/source/DNB.cpp Wed Jul 23 20:36:24 2014
@@ -26,6 +26,11 @@
 #include <vector>
 #include <libproc.h>
 
+#if defined (__APPLE__)
+#include <pthread.h>
+#include <sched.h>
+#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);

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.mm?rev=213828&r1=213827&r2=213828&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.mm (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachProcess.mm Wed Jul 23 20:36:24 2014
@@ -22,6 +22,7 @@
 #include <sys/stat.h>
 #include <sys/sysctl.h>
 #include <unistd.h>
+#include <pthread.h>
 #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();

Modified: lldb/trunk/tools/debugserver/source/MacOSX/MachTask.mm
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/MacOSX/MachTask.mm?rev=213828&r1=213827&r2=213828&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/MacOSX/MachTask.mm (original)
+++ lldb/trunk/tools/debugserver/source/MacOSX/MachTask.mm Wed Jul 23 20:36:24 2014
@@ -23,6 +23,11 @@
 #include <mach/mach_vm.h>
 #import <sys/sysctl.h>
 
+#if defined (__APPLE__)
+#include <pthread.h>
+#include <sched.h>
+#endif
+
 // C++ Includes
 #include <iomanip>
 #include <sstream>
@@ -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

Modified: lldb/trunk/tools/debugserver/source/RNBContext.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBContext.cpp?rev=213828&r1=213827&r2=213828&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/RNBContext.cpp (original)
+++ lldb/trunk/tools/debugserver/source/RNBContext.cpp Wed Jul 23 20:36:24 2014
@@ -16,6 +16,11 @@
 #include <sys/stat.h>
 #include <sstream>
 
+#if defined (__APPLE__)
+#include <pthread.h>
+#include <sched.h>
+#endif
+
 #include "RNBRemote.h"
 #include "DNB.h"
 #include "DNBLog.h"
@@ -145,6 +150,20 @@ RNBContext::ThreadFunctionProcessStatus(
     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)
     {

Modified: lldb/trunk/tools/debugserver/source/RNBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/RNBRemote.cpp?rev=213828&r1=213827&r2=213828&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/RNBRemote.cpp (original)
+++ lldb/trunk/tools/debugserver/source/RNBRemote.cpp Wed Jul 23 20:36:24 2014
@@ -20,6 +20,11 @@
 #include <sys/stat.h>
 #include <sys/sysctl.h>
 
+#if defined (__APPLE__)
+#include <pthread.h>
+#include <sched.h>
+#endif
+
 #include "DNB.h"
 #include "DNBDataRef.h"
 #include "DNBLog.h"
@@ -755,6 +760,20 @@ RNBRemote::ThreadFunctionReadRemoteData(
     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);

Modified: lldb/trunk/tools/debugserver/source/debugserver.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/tools/debugserver/source/debugserver.cpp?rev=213828&r1=213827&r2=213828&view=diff
==============================================================================
--- lldb/trunk/tools/debugserver/source/debugserver.cpp (original)
+++ lldb/trunk/tools/debugserver/source/debugserver.cpp Wed Jul 23 20:36:24 2014
@@ -25,6 +25,10 @@
 #include <sys/types.h>
 #include <crt_externs.h> // for _NSGetEnviron()
 
+#if defined (__APPLE__)
+#include <sched.h>
+#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",





More information about the lldb-commits mailing list