Back to index

numactl  2.0.8~rc4
Defines | Enumerations | Functions
tshared.c File Reference
#include <numa.h>
#include <numaif.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <unistd.h>

Go to the source code of this file.

Defines

#define err(x)   perror(x),exit(1)

Enumerations

enum  SZ { MEMSZ = 100<<20, NTHR = 10 }

Functions

int main (void)

Define Documentation

#define err (   x)    perror(x),exit(1)

Definition at line 8 of file tshared.c.


Enumeration Type Documentation

enum SZ
Enumerator:
MEMSZ 
NTHR 

Definition at line 10 of file tshared.c.

        { 
       MEMSZ = 100<<20, 
       NTHR = 10,
}; 

Function Documentation

int main ( void  )

Definition at line 16 of file tshared.c.

{ 
       int i, k;
       char *mem;
       int pagesz = getpagesize();
       int max_node;

       if (numa_available() < 0) {
              printf("no NUMA API available\n"); 
              exit(1);
       }
       max_node = numa_max_node(); 
       mem = numa_alloc_interleaved(MEMSZ); 
       for (i = 0; i < NTHR; i++) { 
              if (fork() == 0) { 
                     for (k = i*pagesz; k < MEMSZ; k += pagesz * NTHR) { 
                            mem[k] = 1;
                     } 
                     _exit(0); 
              } 
       } 
       for (i = 0; i < NTHR; i++)
              wait(NULL);
       k = 0; 
       for (i = 0; i < MEMSZ; i += pagesz) { 
              int nd; 
              if (get_mempolicy(&nd, NULL, 0, mem + i, MPOL_F_NODE|MPOL_F_ADDR) < 0)
                     err("get_mempolicy");
              if (nd != k) 
                     printf("offset %d node %d expected %d\n", i, nd, k); 
              k = (k+1)%(max_node+1); 
       } 
       
       return 0;
} 

Here is the call graph for this function: