Alex Rivera | Logout

Is it possible to create threads without system calls in Linux x86 GAS assembly?

Asked 2009-04-03T17:31:43.667
47

Whilst learning the "assembler language" (in linux on a x86 architecture using the GNU as assembler), one of the aha moments was the possibility of using system calls. These system calls come in very handy and are sometimes even necessary as your program runs in user-space.
However system calls are rather expensive in terms of performance as they require an interrupt (and of course a system call) which means that a context switch must be made from your current active program in user-space to the system running in kernel-space.

The point I want to make is this: I'm currently implementing a compiler (for a university project) and one of the extra features I wanted to add is the support for multi-threaded code in order to enhance the performance of the compiled program. Because some of the multi-threaded code will be automatically generated by the compiler itself, this will almost guarantee that there will be really tiny bits of multi-threaded code in it as well. In order to gain a performance win, I must be sure that using threads will make this happen.

My fear however is that, in order to use threading, I must make system calls and the necessary interrupts. The tiny little (auto-generated) threads will therefore be highly affected by the time it takes to make these system calls, which could even lead to a performance loss...

my question is therefore twofold (with an extra bonus question underneath it):

  • Is it possible to write assembler code which can run multiple threads simultaneously on multiple cores at once, without the need of system calls?
  • Will I get a performance gain if I have really tiny threads (tiny as in the total execut
Edit
Report

1 Answer

3

First you should learn how to use threads in C (pthreads, POSIX theads). On GNU/Linux you will probably want to use POSIX threads or GLib threads. Then you can simply call the C from assembly code.

Here are some pointers:

  • Posix threads: link text
  • A tutorial where you will learn how to call C functions from assembly: link text
  • Butenhof's book on POSIX threads link text
answered 2009-04-10T14:39:15.400

Your Answer