Re: [PATCH] mask ADT: new mask.h file [2/22]

Paul Jackson
2004-04-05T07:48:34Z

In my previous reply to Rusty, I wrote:
> struct cpumap { DECLARE_BITMAP(bits, NR_CPUS); };
> struct cpumask s, d1, d2;
> bitmap_or(s.bits, d1.bits, d2.bits);

Brain dead code alert (as well as a typo alert for the 'cpumap') - that
last line needs to be:

bitmap_or(s.bits, d1.bits, d2.bits, NR_CPUS);

Which is why the 60 odd cpumask and nodemask specific operation macros
exist, to avoid having to explicitly specify the bitsize on each call

In other words, I understand that the following three possibilities
exist for coding these masks:

/* specify bitsize both on declarations and operations */
struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); };
struct cpumask s, d1, d2;
bitmap_or(s.bits, d1.bits, d2.bits, NR_CPUS); /* explicit bitsize */

or:

/* specify bitsize on declaration; use specialized operations */
struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); };
struct cpumask s, d1, d2;
cpus_or(s.bits, d1.bits, d2.bits); /* 'cpu' implies NR_CPUS */

or:

/* carry the bitsize in the structure [pseudo C alert] */
struct mask { int nbits = NR_CPUS; DECLARE_BITMAP(bits, NR_CPUS); };
struct mask s, d1, d2;
mask_or(s.bits, d1.bits, d2.bits); /* mask_* ops get size from struct */

Am I missing any choices? Which do you prefer?

I understand that the kernel currently does the 2nd choice, encoding the
bitsize in the operation name.

My personal preference is to continue doing this 2nd choice.