Changeset 34687d3
- Timestamp:
- Dec 17, 2020, 12:59:37 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 8235415
- Parents:
- 024fa4b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/readyQ/locality.go
r024fa4b r34687d3 17 17 type GoCtx struct { 18 18 s * semaphore.Weighted 19 d * [] uint6419 d unsafe.Pointer 20 20 c context.Context 21 id int 21 22 } 22 23 23 24 type Spot struct { 24 25 ptr uintptr 26 id int 25 27 } 26 28 … … 29 31 // Next threads unblocks current one and blocks in its place 30 32 // if share == true, exchange data in the process 31 func (this * Spot) put( ctx * GoCtx, data * [] uint64, share bool) (* [] uint64 ) {33 func (this * Spot) put( ctx * GoCtx, data * [] uint64, share bool) (* [] uint64, bool) { 32 34 new := uintptr(unsafe.Pointer(ctx)) 33 // fmt.Printf("Enter with %p\n", data)35 old_d := ctx.d 34 36 var raw uintptr 35 37 for true { 36 38 raw = this.ptr 37 39 if raw == uintptr(1) { 38 return nil 40 return nil, true 39 41 } 40 42 if atomic.CompareAndSwapUintptr(&this.ptr, raw, new) { … … 47 49 val = (*GoCtx)(unsafe.Pointer(raw)) 48 50 if share { 49 val.d = data 51 // fmt.Printf("[%d] - %d update %d: %p -> %p\n", this.id, ctx.id, val.id, val.d, data) 52 atomic.StorePointer(&val.d, unsafe.Pointer(data)) 50 53 } 51 54 55 // fmt.Printf("[%d] - %d release %d\n", this.id, ctx.id, val.id) 52 56 val.s.Release(1) 53 57 } 54 58 59 // fmt.Printf("[%d] - %d enter\n", this.id, ctx.id) 55 60 ctx.s.Acquire(ctx.c, 1) 56 // fmt.Printf("Leave with %p (was %p)\n", ctx.d, data) 57 return ctx.d 61 ret := (* [] uint64)(atomic.LoadPointer(&ctx.d)) 62 // fmt.Printf("[%d] - %d leave: %p -> %p\n", this.id, ctx.id, ret, old_d) 63 64 return ret, false 58 65 } 59 66 … … 76 83 } 77 84 78 func local(result chan uint64, start chan struct{}, size uint64, cnt uint64, channels [] Spot, share bool ) {85 func local(result chan uint64, start chan struct{}, size uint64, cnt uint64, channels [] Spot, share bool, id int) { 79 86 state := rand.Uint64() 80 87 var my_data [] uint64 … … 87 94 sem := semaphore.NewWeighted(1) 88 95 sem.Acquire(context.Background(), 1) 89 ctx := GoCtx{sem, data, context.Background()}96 ctx := GoCtx{sem, unsafe.Pointer(data), context.Background(), id} 90 97 91 98 count := uint64(0) … … 97 104 98 105 i := __xorshift64(&state) % uint64(len(channels)) 99 // data = channels[i].put(sem, data, share)100 data = channels[i].put(&ctx, data, share)106 var closed bool 107 data, closed = channels[i].put(&ctx, data, share) 101 108 count += 1 102 109 110 if closed { break } 103 111 if clock_mode && atomic.LoadInt32(&stop) == 1 { break } 104 112 if !clock_mode && count >= stop_count { break } … … 129 137 130 138 barrierStart := make(chan struct{}) 131 threads_left = int64(n threads)139 threads_left = int64(nprocs) 132 140 result := make(chan uint64) 133 141 channels := make([]Spot, nthreads - nprocs) 134 142 for i := range channels { 135 channels[i] = Spot{uintptr(0) }143 channels[i] = Spot{uintptr(0), i} 136 144 } 137 145 138 146 for i := 0; i < nthreads; i++ { 139 go local(result, barrierStart, size, cnt, channels, share )147 go local(result, barrierStart, size, cnt, channels, share, i) 140 148 } 141 149 fmt.Printf("Starting\n");
Note: See TracChangeset
for help on using the changeset viewer.