5

About how many clock cycles does it take to make a simple, non-blocking system call on Linux?

Would I expect anything different from OS X?

I wonder about calls such as setsockopt, which might be used to provide an optional hint to improve performance, yet has its own intrinsic cost.

Potatoswatter
  • 134,909
  • 25
  • 265
  • 421

1 Answers1

6

It really depends on the system call and on the hardware.

The overhead of making a syscall is not very big! this gives less than a microsecond (i.e. a hundred processor clock cycles). Some syscalls are using vdso(7) to reduce that overhead.

However, for a given syscall, the kernel is doing some work. Depending on the actual involved syscall, this may take a lot of time.

For setsockopt(2) it should depend on which options you are setting.

In general, Linux socket implementation is quite good, and most of the time is spent on the actual network (i.e. Ethernet, etc....).

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547
  • I'd actually expect Mac OS X finishing (respectable) second due to its hybrid kernel architecture. Of course it correct to assume that it really depends on the nature of the specific system call. – mfro Mar 29 '14 at 19:05
  • 2
    Update: Spectre / Meltdown mitigation make system calls significantly more expensive. Like [1800 cycles on a Skylake](https://stackoverflow.com/questions/48913091/fastest-linux-system-call#comment84843442_48914200), most of it in the `wrmsr` to flush branch predictors. – Peter Cordes Aug 05 '18 at 23:41