morandg
morandg

Reputation: 1066

select() system call is CPU consuming

I wrote an application that accept different remote client and is based select() 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 strace -c:

% time     seconds  usecs/call     calls    errors syscall
------ ----------- ----------- --------- --------- ----------------
 98.47    3.680000      204444        18           select
...

However, if I send continuously data to the application from my remote clients, select uses much less CPU!

% 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
...

I'm wondering if select() 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!

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 pthread, critical section, ... ?

I read two interesting articles on the Internet:

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?

EDIT:
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 ...

Upvotes: 2

Views: 3280

Answers (1)

mensi
mensi

Reputation: 9826

strace -c does not measure CPU time spent but overall time spent in the syscall. See its manpage:

Count time, calls, and errors for each system call and report a summary on program exit.

So it would actually be bad if you wouldn't have select at a high percentage on low load!

You can use perf (linux-tools package on debian/ubuntu) to measure overall performance, including kernel code.

Upvotes: 7

Related Questions