Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


Subset barrier support (counting barriers)
[palacios.git] / palacios / include / palacios / vmm_subset.h
1 /*
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2015, Peter Dinda <pdinda@northwestern.edu>
11  * Copyright (c) 2015, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Peter Dinda <pdinda@northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20 #ifndef __VMM_SUBSET_H__
21 #define __VMM_SUBSET_H__
22
23 #ifdef __V3VEE__
24
25 #include <palacios/vmm_types.h>
26
27 /* Subset Barriers */
28
29 typedef struct v3_counting_barrier {
30     // number of threads that must arrive at the barrier
31     // note that this can only be set when there is no barreir in progress
32     uint64_t      size;
33     uint64_t      count[2];
34     uint64_t      cur;
35 } v3_counting_barrier_t;
36
37
38 static inline void v3_init_counting_barrier(v3_counting_barrier_t *b, uint64_t size)
39 {
40     b->size=size; b->count[0]=b->count[1]=0; b->cur=0;
41 }
42
43 static inline void v3_counting_barrier(volatile v3_counting_barrier_t *b)
44 {
45     uint64_t old;
46     volatile uint64_t *curp = &(b->cur);
47     long mycur = *curp;
48     volatile uint64_t *countp = &(b->count[mycur]);
49  
50     old = __sync_fetch_and_add(countp,1);
51
52     if (old==(b->size-1)) { 
53         // I'm the last to the party
54         *curp ^= 0x1;
55         *countp = 0;
56     } else {
57         // k1om compiler does not know what "volatile" means
58         // hence this hand-coding.
59         do { 
60             __asm__ __volatile__( "movq %1, %0" : "=r"(old) : "m"(*countp) : );
61         } while (old);
62     }
63 }
64
65
66 #endif
67
68 #endif