svn commit: r209119 - head/sys/sys

Bruce Evans brde at optusnet.com.au
Mon Jun 14 15:42:15 UTC 2010


On Mon, 14 Jun 2010, John Baldwin wrote:

> On Monday 14 June 2010 9:50:10 am mdf at freebsd.org wrote:
[bde wrote]
>>> BTW, one reason I liked BSD code more than gnu code is that it didn't
>>> use so many macros.  Macros should only exist when they are not just
>>> syntactic sugar, like DPCPU_SUM() and unlike CPU_FOREACH().
>>
>> As a style question, I do understand (generally) why too many macros
>> make the code confusing.  However, the *FOREACH macros all fit the
>> same pattern and having a macro to iterate protects one against
>> changes in the implementation -- there's a single location to change
>> if e.g. we want to make CPU_FOREACH use a bitwise operator to
>> determine the next non-zero bit, rather than testing each
>> individually.

I usually prefer readability to making the implementation easier to change.
Readability includes seeing all the details so that you can understand and
debug them.  Functions may also hide the details in an effectively similar
way for reading (browsing) but not from debugging.

> In the case of CPU_FOREACH() there is a very good chance that the
> implementation details will change when we switch from cpumask_t to cpuset_t,
> which is part of the reason I added it.  I am less of a fan of macros that
> just wrap TAILQ_FOREACH() (note that there isn't a PCPU_FOREACH() since you
> can already do this via SLIST_FOREACH() now for example) such as
> FOREACH_PROC_IN_SYSTEM().

I view the queue constructor and access macros as a necessary evil because
they can't be written as inline functions (except in C++?).  This doesn't
apply to the iterator macros.

> CPU_FOREACH() has additional logic in that it hides
> the CPU_ABSENT() stuff, so to me it doesn't quite fall in that class.  (Some
> code was using pcpu_find() instead of CPU_ABSENT() to determine absent CPUs as
> well FWIW.)

Maybe it is the magic in them that I dislike most.  I have yet to see
a debugger that can even automatically print the literal macro definition
when displaying lines near a macro, let alone prettyprint the
context-dependent macro expansion and allow stepping through or over
the expansion.  gdb has problems in this area even with inline functions.

Bruce


More information about the svn-src-head mailing list