LWN.net Logo

How likely should likely() be?

How likely should likely() be?

Posted Feb 12, 2004 13:33 UTC (Thu) by zooko (subscriber, #2589)
Parent article: How likely should likely() be?

Can GCC's profile-directed optimization be used on the kernel?

If so, you would think that this would obviate the need for programmer-specified hints in the source code.


(Log in to post comments)

How likely should likely() be?

Posted Feb 14, 2004 20:48 UTC (Sat) by giraffedata (subscriber, #1954) [Link]

Except that programmer-specified hints are a lot easier. Also, the hint to the code reader can be valuable too.

Where the code reader is concerned, the likely() notation is awful. I read this as "if some_condition is likely, then ..." A more appropriate notation would be

  assert(likely(some_condition));
  if (some_condition) ...

Furthermore, just minimizing the average time spent doing the branch isn't the only reason to do branch prediction hints. Consider

  if (fast_response_required) ...

Even if fast_response_required is rarely true, I may want the code optimized for the case that it is. That gets me to

  optimize_for(fast_response_required)
or maybe
  if (fast_response_required) {
    optimize_for_this_case();
  }

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds