title: select() system call is CPU consuming
body: <p>I wrote an application that accept different remote client and is based <code>select()</code> to distribute the job to different handlers. I noticed that on one platform running an ARM926EJ-S and a kernel 2.6.33-rc4, the application uses a lot of CPU! Here is what I could see by running my application for 30 seconds with <em>strace -c</em>:</p>
  
  <pre><code>% time     seconds  usecs/call     calls    errors syscall
  ------ ----------- ----------- --------- --------- ----------------
   98.47    3.680000      204444        18           select
  ...
  </code></pre>
  
  <p>However, if I send continuously data to the application from my remote clients, select uses much less CPU!</p>
  
  <pre><code>% time     seconds  usecs/call     calls    errors syscall
  ------ ----------- ----------- --------- --------- ----------------
   44.69    0.340278         175      1945           gettimeofday
   40.71    0.310000       25833        12           select
    3.94    0.030000       30000         1           fsync
  ...
  </code></pre>
  
  <p>I'm wondering if <code>select()</code> is implemented with a busy waiting. However, on an older platform, running a MIPS processor and a 2.6.30.10 Linux kernel this problem didn't appear, despite I should cross-compile strace to confirm that ...! And as data are "rarely" sent, I'm mostly in the worst case!</p>
  
  <p>I'm wondering where the problem could come from! C Library? Linux kernel? On the other hand, I'm not sure if writting a multi threaded application will result in better performance because of <code>pthread</code>, critical section, ... ?</p>
  
  <p>I read two interesting articles on the Internet:</p>
  
  <ul>
  <li><a href="http://kdb.snu.ac.kr/~tsangbi/References/network/1998%20Scalable%20kernel%20performance%20for%20internet%20servers%20under%20realistic%20loads.pdf" rel="nofollow"><em>"Scalable kernel performance for Internet servers under realistic loads"</em></a></li>
  <li><a href="http://static.usenix.org/event/usenix99/full_papers/banga/banga_html/final2.html" rel="nofollow"><em>"A scalable and explicit event delivery mechanism for UNIX"</em></a></li>
  </ul>
  
  <p>Unfortunately they are pretty old (from '98/'99) I'd like to know if someone else faced that kind of problem or if you had any other suggestion to improve performance or point to the real problem?</p>
  
  <p><strong>EDIT</strong>:<br>
  I noticed that more clients are connected more my application uses CPU, this despite the clients don't send any data! As the most time is spent in select, I though that the select itself that consumes more CPU!
  What other free tools could I used under ARM to profile my application and point the problem? Valgrind doesn't work (yet) on ARM9 ...</p>