From: Peter Dinda Date: Thu, 18 Jun 2015 21:47:38 +0000 (-0500) Subject: Subset barrier support (counting barriers) X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=commitdiff_plain;h=7c0124e75c04de3d51a457f8788cbee61d51fd36 Subset barrier support (counting barriers) --- diff --git a/palacios/include/palacios/vmm_subset.h b/palacios/include/palacios/vmm_subset.h new file mode 100644 index 0000000..adc13de --- /dev/null +++ b/palacios/include/palacios/vmm_subset.h @@ -0,0 +1,68 @@ +/* + * This file is part of the Palacios Virtual Machine Monitor developed + * by the V3VEE Project with funding from the United States National + * Science Foundation and the Department of Energy. + * + * The V3VEE Project is a joint project between Northwestern University + * and the University of New Mexico. You can find out more at + * http://www.v3vee.org + * + * Copyright (c) 2015, Peter Dinda + * Copyright (c) 2015, The V3VEE Project + * All rights reserved. + * + * Author: Peter Dinda + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "V3VEE_LICENSE". + */ + +#ifndef __VMM_SUBSET_H__ +#define __VMM_SUBSET_H__ + +#ifdef __V3VEE__ + +#include + +/* Subset Barriers */ + +typedef struct v3_counting_barrier { + // number of threads that must arrive at the barrier + // note that this can only be set when there is no barreir in progress + uint64_t size; + uint64_t count[2]; + uint64_t cur; +} v3_counting_barrier_t; + + +static inline void v3_init_counting_barrier(v3_counting_barrier_t *b, uint64_t size) +{ + b->size=size; b->count[0]=b->count[1]=0; b->cur=0; +} + +static inline void v3_counting_barrier(volatile v3_counting_barrier_t *b) +{ + uint64_t old; + volatile uint64_t *curp = &(b->cur); + long mycur = *curp; + volatile uint64_t *countp = &(b->count[mycur]); + + old = __sync_fetch_and_add(countp,1); + + if (old==(b->size-1)) { + // I'm the last to the party + *curp ^= 0x1; + *countp = 0; + } else { + // k1om compiler does not know what "volatile" means + // hence this hand-coding. + do { + __asm__ __volatile__( "movq %1, %0" : "=r"(old) : "m"(*countp) : ); + } while (old); + } +} + + +#endif + +#endif