Back to index

numactl  2.0.8~rc4
Defines | Typedefs | Functions
tbitmap.c File Reference
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#include <ctype.h>
#include "numa.h"

Go to the source code of this file.

Defines

#define _GNU_SOURCE   1
#define ALIGN(x, a)   (((x)+(a)-1)&~((a)-1))
#define test_bit(i, p)   ((p)[(i) / BITS_PER_LONG] & (1UL << ((i)%BITS_PER_LONG)))
#define set_bit(i, p)   ((p)[(i) / BITS_PER_LONG] |= (1UL << ((i)%BITS_PER_LONG)))
#define clear_bit(i, p)   ((p)[(i) / BITS_PER_LONG] &= ~(1UL << ((i)%BITS_PER_LONG)))
#define BITS_PER_LONG   (sizeof(long)*8)
#define round_up(x, y)   (((x) + (y) - 1) & ~((y)-1))
#define CPU_BYTES(x)   (round_up(x, BITS_PER_LONG)/8)
#define CPU_LONGS(x)   (CPU_BYTES(x) / sizeof(long))
#define CHUNKSZ   32
#define nbits_to_hold_value(val)   fls(val)
#define unhex(c)   (isdigit(c) ? (c - '0') : (toupper(c) - 'A' + 10))
#define BASEDEC   10 /* fancier cpuset lists input in decimal */
#define MASKSIZE   300

Typedefs

typedef unsigned u32

Functions

int bitmap_scnprintf (char *buf, unsigned int buflen, struct bitmask *mask)
 bitmap_scnprintf - convert bitmap to an ASCII hex string.
int numa_parse_bitmap (char *buf, struct bitmask *mask)
int main (void)

Define Documentation

#define _GNU_SOURCE   1

Definition at line 2 of file tbitmap.c.

#define ALIGN (   x,
  a 
)    (((x)+(a)-1)&~((a)-1))

Definition at line 11 of file tbitmap.c.

#define BASEDEC   10 /* fancier cpuset lists input in decimal */

Definition at line 31 of file tbitmap.c.

#define BITS_PER_LONG   (sizeof(long)*8)

Definition at line 19 of file tbitmap.c.

#define CHUNKSZ   32

Definition at line 28 of file tbitmap.c.

#define clear_bit (   i,
 
)    ((p)[(i) / BITS_PER_LONG] &= ~(1UL << ((i)%BITS_PER_LONG)))

Definition at line 15 of file tbitmap.c.

#define CPU_BYTES (   x)    (round_up(x, BITS_PER_LONG)/8)

Definition at line 23 of file tbitmap.c.

#define CPU_LONGS (   x)    (CPU_BYTES(x) / sizeof(long))

Definition at line 24 of file tbitmap.c.

#define MASKSIZE   300

Definition at line 68 of file tbitmap.c.

#define nbits_to_hold_value (   val)    fls(val)

Definition at line 29 of file tbitmap.c.

#define round_up (   x,
 
)    (((x) + (y) - 1) & ~((y)-1))

Definition at line 21 of file tbitmap.c.

#define set_bit (   i,
 
)    ((p)[(i) / BITS_PER_LONG] |= (1UL << ((i)%BITS_PER_LONG)))

Definition at line 14 of file tbitmap.c.

#define test_bit (   i,
 
)    ((p)[(i) / BITS_PER_LONG] & (1UL << ((i)%BITS_PER_LONG)))

Definition at line 13 of file tbitmap.c.

#define unhex (   c)    (isdigit(c) ? (c - '0') : (toupper(c) - 'A' + 10))

Definition at line 30 of file tbitmap.c.


Typedef Documentation

typedef unsigned u32

Definition at line 18 of file tbitmap.c.


Function Documentation

int bitmap_scnprintf ( char *  buf,
unsigned int  buflen,
struct bitmask mask 
)

bitmap_scnprintf - convert bitmap to an ASCII hex string.

: byte buffer into which string is placed : reserved size of , in bytes : pointer to struct bitmask to convert

Hex digits are grouped into comma-separated sets of eight digits per set.

Definition at line 41 of file tbitmap.c.

{
        int i, word, bit, len = 0;
        unsigned long val;
        const char *sep = "";
        int chunksz;
        u32 chunkmask;

        chunksz = mask->size & (CHUNKSZ - 1);
        if (chunksz == 0)
                chunksz = CHUNKSZ;

        i = ALIGN(mask->size, CHUNKSZ) - CHUNKSZ;
        for (; i >= 0; i -= CHUNKSZ) {
                chunkmask = ((1ULL << chunksz) - 1);
                word = i / BITS_PER_LONG;
                bit = i % BITS_PER_LONG;
                val = (mask->maskp[word] >> bit) & chunkmask;
                len += snprintf(buf+len, buflen-len, "%s%0*lx", sep,
                        (chunksz+3)/4, val);
                chunksz = CHUNKSZ;
                sep = ",";
        }
        return len;
}

Here is the caller graph for this function:

int main ( void  )

Definition at line 70 of file tbitmap.c.

{
       char buf[1024];
       struct bitmask *mask, *mask2;
       int i;

       mask  = numa_bitmask_alloc(MASKSIZE);
       mask2 = numa_bitmask_alloc(MASKSIZE);

       printf("Testing bitmap functions\n");
       for (i = 0; i < MASKSIZE; i++) {
              numa_bitmask_clearall(mask);
              numa_bitmask_clearall(mask2);
              numa_bitmask_setbit(mask, i);
              bitmap_scnprintf(buf, sizeof(buf), mask);
              strcat(buf,"\n");
              if (numa_parse_bitmap(buf, mask2) < 0)
                     assert(0);
              if (memcmp(mask, mask2, sizeof(mask))) { 
                     bitmap_scnprintf(buf, sizeof(buf), mask2);
                     printf("mask2 differs: %s\n", buf);
                     assert(0);
              }
       }
       printf("Passed\n");
       return 0;
}

Here is the call graph for this function:

int numa_parse_bitmap ( char *  buf,
struct bitmask mask 
)

Here is the caller graph for this function: