Re: [Lse-tech] [PATCH] new bitmap list format (for cpusets)

Paul Jackson
2004-08-10T23:45:32Z

Martin wrote:
> OK, that [removal of prefix char fluff^Wstuff] looks a lot more palletable ;-)

Good.

> it looks like you're only parsing on the read-side to me

I couldn't parse this comment, but hopefully I'll answer this below ...

> I can't see any [bitmap_scnlistprintf] callers,

The first caller of the bitmap list format stuff is the next patch - the
cpuset patch.

The bitmap list printing call stack for cpumasks is:

kernel/cpuset.c: cpuset_common_file_read()
kernel/cpuset.c: cpuset_sprintf_cpulist()
include/linux/cpumask.h: __cpulist_scnprintf()
lib/bitmap.c: bitmap_scnlistprintf()

Similarly for nodemasks.

That's why the very first two lines of the bitmap list patch comment
state:

A bitmap print and parse format that provides lists of ranges of
numbers, to be first used for by cpusets (next patch).

;).

> do we really need both cpumask_parse and __cpumask_parse in front of
> bitmap_parse?

Yes. Look through cpumask.h and nodemask.h. You will see this use of
a #define macro wrapping a static inline macro repeatedly. The #define
macro is needed to implement the implied call-by-reference convention,
and the static inline is needed to add some type checking.

Note that while the C syntax for using these cpu and node mask operators
_looks_ like it is passing the mask by value at the point marked "<==",
which would copy a possibly multiple word mask on the stack, in the
code:

static int cpuset_sprintf_cpulist(char *page, struct cpuset *cs)
{
cpumask_t mask;
...
return cpulist_scnprintf(page, PAGE_SIZE, mask); /* <== */
}

this code is _really_ passing a pointer (unsigned long *) on the stack
to the actual implementing code, in lib/bitmap.c:bitmap_scnlistprintf().

The key ingredient that the #define macro adds is the '&' char, turning
normal C call-by-value conventions into an implied call-by-reference.

This somewhat un-C-like calling convention (more like Pascal call by
reference) existed for cpumasks before I came on the scene, with my
various cleanups of the bitmap and cpumask code over the last 10 months.
I found the convention pleasing enough, if odd, so I preserved it, for
most of the cpumask calls, and now (thanks to Matthew Dobson) the
nodemask calls as well.

In summary, the #define macros are needed in cpumask.h and nodemask.h to
alter the usual C call-by-value conventions, and the static inline
macros are needed to provide some static type checking of the arguments.

... at least I hope that was your question.

--
I won't rest till it's the best ...
Programmer, Linux Scalability
Paul Jackson <pj@sgi.com> 1.650.933.1373