Back to index

numactl  2.0.8~rc4
tshared.c
Go to the documentation of this file.
00001 #include <numa.h>
00002 #include <numaif.h>
00003 #include <stdio.h>
00004 #include <stdlib.h>
00005 #include <sys/wait.h>
00006 #include <unistd.h>
00007 
00008 #define err(x) perror(x),exit(1)
00009 
00010 enum SZ { 
00011        MEMSZ = 100<<20, 
00012        NTHR = 10,
00013 }; 
00014 
00015 /* test if shared interleaving state works. */
00016 int main(void)
00017 { 
00018        int i, k;
00019        char *mem;
00020        int pagesz = getpagesize();
00021        int max_node;
00022 
00023        if (numa_available() < 0) {
00024               printf("no NUMA API available\n"); 
00025               exit(1);
00026        }
00027        max_node = numa_max_node(); 
00028        mem = numa_alloc_interleaved(MEMSZ); 
00029        for (i = 0; i < NTHR; i++) { 
00030               if (fork() == 0) { 
00031                      for (k = i*pagesz; k < MEMSZ; k += pagesz * NTHR) { 
00032                             mem[k] = 1;
00033                      } 
00034                      _exit(0); 
00035               } 
00036        } 
00037        for (i = 0; i < NTHR; i++)
00038               wait(NULL);
00039        k = 0; 
00040        for (i = 0; i < MEMSZ; i += pagesz) { 
00041               int nd; 
00042               if (get_mempolicy(&nd, NULL, 0, mem + i, MPOL_F_NODE|MPOL_F_ADDR) < 0)
00043                      err("get_mempolicy");
00044               if (nd != k) 
00045                      printf("offset %d node %d expected %d\n", i, nd, k); 
00046               k = (k+1)%(max_node+1); 
00047        } 
00048        
00049        return 0;
00050 }