Threading libsmbclient - a proposal.

Howard Chu hyc at
Sat Apr 4 17:23:26 GMT 2009

> Date: Sat, 4 Apr 2009 10:16:24 +0200
> From: Volker Lendecke<Volker.Lendecke at SerNet.DE>

> On Fri, Apr 03, 2009 at 12:51:05PM -0400, Derrell Lipman wrote:
>> And we probably want to avoid even that, particularly in areas of code that
>> are executed frequently. Function calls can be expensive. It's probably much
>> more efficient to say "if (func_ptr != NULL) (*func_ptr)(params);" than to
>> call a dummy function via func_ptr. That could all be hidden behind a macro,
>> though, so the code isn't cluttered by it.
> Are function calls really expensive these days? With all the
> levels of caches these days and just silly fast CPUs, isn't
> it more important to be cache friendly? When I added the
> "unlikely" to the DEBUG macros, it actually made a
> difference when looking at our cache footprint with
> cachegrind. And that made a few percent difference for
> netbench.

It obviously depends on a lot of factors, but in my experience it's still 
better to test inline in the caller than to make the dummy call. The 
difference becomes more pronounced as the number of function arguments increases.

If you're looking at it from a really low-level view (which I guess you are, 
since you tried cachegrind) then you have to remember that compiler hints like 
"unlikely" can't help you all that much. The compiler tries to arrange static 
branch prediction to keep the most-likely path inline, and branch to the 
less-likely path. But in this case, it still has to branch around the 
not-taken path, so the compiler hint doesn't help the code density at all.

Cache footprint is still important of course. On a heavily loaded system, 
slapd compiled with gcc -Os runs a few percent faster than with -O3. On 
lighter loads, -O3 is faster. So there's other considerations and you can't 
make a one-size-fits-all solution.

Digressing for a bit: we really need a SMP-aware version of cachegrind; it 
only simulates a single core and single cache hierarchy. It would be nice to 
have a tool that simulates multiple cores so you can trace cache line 
conflicts between cores...

   -- Howard Chu
   CTO, Symas Corp. 
   Director, Highland Sun
   Chief Architect, OpenLDAP

More information about the samba-technical mailing list