Threads in Firefox (from Ubuntu 12.04)

Doing a simple gdb attach on a recent version of Firefox (v23.0) I was very surprised by the complexity of the threading available:

Id Target Id Frame
34 Thread 0x7f0164575700 (LWP 2272) "dconf worker" 0x00007f016fdb6313 in poll () from /lib/x86_64-linux-gnu/libc.so.6
33 Thread 0x7f0161fda700 (LWP 2273) "gdbus" 0x00007f016fdb6313 in poll ()
from /lib/x86_64-linux-gnu/libc.so.6
32 Thread 0x7f016035d700 (LWP 2274) "Gecko_IOThread" 0x00007f016fdbdee9 in syscall () from /lib/x86_64-linux-gnu/libc.so.6
31 Thread 0x7f015f0ff700 (LWP 2275) "Socket Thread" 0x00007f016fdb6313 in poll () from /lib/x86_64-linux-gnu/libc.so.6

Or to summarize is a more easy to read manner:

“dconf worker”
“gdbus”
“Gecko_IOThread”
“Socket Thread”
“JS GC Helper”
“JS Sour~ Thread”
“JS Watchdog”
“Hang Monitor”
“Timer”
“Cert Verify”
“mozStorage #1″
“mozStorage #2″
“mozStorage #3″
“Proxy R~olution”
“Cache I/O”
“mozStorage #4″
“MediaManager”
“DOM Worker”
“HTML5 Parser”
“mozStorage #5″
“URL Classifier”
“localStorage DB”
“mozStorage #6″
“mozStorage #7″
“DOM Worker”
“mozStorage #8″
“mozStorage #9″
“mozStorage #10″
“Analysis Helper”
“threaded-ml”
“Image Scaler”
“mozStorage #11″
“ImageDecoder #5″
“firefox”

Firstly, what are each of these threads doing in Firefox? How does it really help in the browsing process?

WHere is the source codes for these?

What are the corresponding or equivalent functionality/features in Chrome browser?

Anyway to debug the runtime behavior of these threads?

How to trace through the different parts of the threads at runtime?

This is threading in Firefox:

https://developer.mozilla.org/en-US/docs/Code_snippets/Threads

Concept of “web worker” in Firefox (which essentially is THREADS?) and “ChromeWorker”:

https://developer.mozilla.org/en-US/docs/Web/Guide/Performance/Using_web_workers

https://developer.mozilla.org/en-US/docs/Web/API/ChromeWorker

Thread manager:

https://developer.mozilla.org/en/docs/The_Thread_Manager

Firefox management of threads:

http://forums.mozillazine.org/viewtopic.php?p=702985

And for debugging:

http://superuser.com/questions/311932/peeking-inside-firefox-whats-maxing-out-the-cpu?rq=1

http://kb.mozillazine.org/Problematic_extensions

http://support.mozilla.org/en-US/kb/firefox-uses-too-many-cpu-resources-how-fix?redirectlocale=en-US&redirectslug=Firefox+consumes+a+lot+of+CPU+resources

To get the source code for Firefox, “apt-get source firefox” is issued.

Switching to the first thread “dconf worker” and looking at the backtrace:

(gdb) thread 23
[Switching to thread 23 (Thread 0xb41b8b40 (LWP 3934))]
#0 0xb77ba424 in __kernel_vsyscall ()
(gdb) bt
#0 0xb77ba424 in __kernel_vsyscall ()
#1 0xb7583690 in __GI___poll (fds=0xb72159f8, nfds=1, timeout=-1)
at ../sysdeps/unix/sysv/linux/poll.c:87
#2 0xb50bda7b in g_poll () from /lib/i386-linux-gnu/libglib-2.0.so.0
#3 0xb50b00ae in ?? () from /lib/i386-linux-gnu/libglib-2.0.so.0
#4 0xb50b056b in g_main_loop_run () from /lib/i386-linux-gnu/libglib-2.0.so.0
#5 0xb428a134 in ?? ()
from /usr/lib/i386-linux-gnu/gio/modules/libdconfsettings.so
#6 0xb50d36b3 in ?? () from /lib/i386-linux-gnu/libglib-2.0.so.0
#7 0xb7652d4c in start_thread (arg=0xb41b8b40) at pthread_create.c:308
#8 0xb7591dde in clone () at ../sysdeps/unix/sysv/linux/i386/clone.S:130
(gdb)

And looking into Gecko_IOThread:

Inside the file “BrowserProcessSubThread.cpp”:

// Friendly names for the well-known threads.
static const char* kBrowserThreadNames[BrowserProcessSubThread::ID_COUNT] = {
"Gecko_IOThread", // IO
// "Chrome_FileThread", // FILE
// "Chrome_DBThread", // DB
// "Chrome_HistoryThread", // HISTORY
#if defined(OS_LINUX)
"Gecko_Background_X11Thread", // BACKGROUND_X11
#endif
};

And hunting for more names inside the source codes:

./xpcom/threads/LazyIdleThread.cpp:
PR_SetCurrentThreadName(mName.get());

./xpcom/threads/nsProcessCommon.cpp:
PR_SetCurrentThreadName("RunProcess");

./xpcom/threads/TimerThread.cpp:
PR_SetCurrentThreadName("Timer");

./xpcom/threads/HangMonitor.cpp:
PR_SetCurrentThreadName("Hang Monitor");

./startupcache/StartupCache.cpp:
PR_SetCurrentThreadName("StartupCache");

./netwerk/base/src/nsSocketTransportService2.cpp:
PR_SetCurrentThreadName("Socket Thread");

./netwerk/base/src/nsPACMan.cpp:
PR_SetCurrentThreadName("Proxy Resolution");

./netwerk/wifi/nsWifiMonitor.cpp:
PR_SetCurrentThreadName("Wifi Monitor");

./netwerk/system/win32/nsNotifyAddrListener.cpp:
PR_SetCurrentThreadName("Link Monitor");

./toolkit/xre/EventTracer.cpp:
PR_SetCurrentThreadName("Event Tracer");


Wow…there appear a lot more threads not running….

Advertisements

One response to this post.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: