• Andrew Morton's avatar
    [PATCH] new /proc/irq cpumask format; consolidate cpumask display and input code · 409c7f3a
    Andrew Morton authored
    From: Paul Jackson <pj@sgi.com>
    
    This patch is a followup to one from Bill Irwin.  On Nov
    17, he had consolidated the half-dozen chunks of code
    that displayed cpumasks in /proc/irq/prof_cpu_mask and
    /proc/irq/<pid>/smp_affinity into a single routine, which he
    called format_cpumask().
    
    I believe that Andrew Morton has accepted Bill's patch into
    his 2.6.0-test10-mm1 patch set as the "format_cpumask" patch.
    I hope that the following patch will replace Bill's patch.
    I look forward to Bill's feedback on this patch.
    
    The following patch carries Bill's work further:
    
     1) It also consolidates the input side (write syscalls).
     2) It adapts a new format, same on input and output.
     3) The core routines work for any multi-word bitmask,
        not just cpumasks.
     4) The core routines avoid overrunning their output
        buffers.
    
    Note esp. for David Mosberger:
    
        The small patch I sent you and the linux-ia64 list
        yesterday entitled: "check user access ok writing
        /proc/irq/<pid>/smp_affinity" for arch ia64 only is
        _separate_ from the following patch.  Neither presumes the
        other.  However, they do collide on one line.  Last one in
        is a Monkey's Uncle and will need an updated patch from me
        (or otherwise need to resolve the one obvious collision).
    
    Details of the following patch:
    
    Both the display and input of cpumasks on 9 arch's are
    consolidated into a single pair of routines, which use the
    same format for input and output, as recommended by Tony
    Luck.  The two common routines work on any multi-word bitmask
    (array of unsigned longs).  A pair of trivial inline wrappers
    cpumask_snprintf() and cpumask_parse() hide this generality
    for the common case of cpumask input and output.
    
    My real motivation for consolidating this code will become
    visible later - when I seek to add a nodemask_t that resembles
    cpumask_t (just a different length).  These common underlying
    routines will be used there as well, following up on a suggestion
    of Christoph Hellwig that I investigate implementing nodemask_t
    as an ADT sharing infrastructure with cpumask_t.  However, I
    believe that this patch stands on its own merit, consolidating
    a couple hundred lines of duplicated code, and making the
    cpumask display format usable on very large systems.
    
    There are two exceptions to the consolidation - the alpha and
    sparc64 arch's manipulate bare unsigned longs, not cpumask_t's,
    on input (write syscall), and do stuff that was more funky than
    I could make sense of.  So the input side of these two arch's
    was left as-is.  I'd welcome someone with access to either of
    these systems to provide additional patches.
    
    The new format consists of multiple 32 bit words, separated by
    commas, displayed and input in hex.  The following comment from
    this patch describes this format further:
    
    * The ascii representation of multi-word bit masks displays each
    * 32bit word in hex (not zero filled), and for masks longer than
    * one word, uses a comma separator between words.  Words are
    * displayed in big-endian order most significant first.  And hex
    * digits within a word are also in big-endian order, of course.
    *
    * Examples:
    *   A mask with just bit 0 set displays as "1".
    *   A mask with just bit 127 set displays as "80000000,0,0,0".
    *   A mask with just bit 64 set displays as "1,0,0".
    *   A mask with bits 0, 1, 2, 4, 8, 16, 32 and 64 set displays
    *     as "1,1,10117".  The first "1" is for bit 64, the second
    *     for bit 32, the third for bit 16, and so forth, to the
    *     "7", which is for bits 2, 1 and 0.
    *   A mask with bits 32 through 39 set displays as "ff,0".
    
    The essential reason for adding the comma breaks was to make
    the long masks from our (SGI's) big 512 CPU systems parsable by
    humans.  An unbroken string of 128 hex digits is pretty difficult
    to read.  For those who are compiling systems with CONFIG_NR_CPUS
    of 32 or less, there should be no visible change in format.
    
    There are of course a thousand possible output formats that
    meet similar criteria.  If someone wants to lobby for and seek
    consensus behind another such format, that's fine.  Now that
    the format is consolidated into a single pair of routines,
    it should be easy to adapt whatever we choose.
    
    Internally, the display routine uses snprintf to track the
    remaining space in its output buffer, to avoid the risk of
    overrunning it.
    
    A new file, lib/mask.c, is added to the lib directory, to
    hold the two common routines.  I anticipate adding a few more
    common routines for generic support of multi-word bit masks to
    lib/mask.c, in subsequent patches that will add a nodemask_t
    type as an ADT sharing implementation with cpumask_t.
    409c7f3a
irq.c 19.3 KB