Changeset 024fa4b
- Timestamp:
- Dec 16, 2020, 4:49:31 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:
- 34687d3
- Parents:
- fd84538
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
benchmark/readyQ/locality.go
rfd84538 r024fa4b 18 18 s * semaphore.Weighted 19 19 d * [] uint64 20 c context.Context 20 21 } 21 22 … … 24 25 } 25 26 26 func (this * Spot) put( s * semaphore.Weighted, data [] uint64, share bool) ([] uint64) { 27 ctx := GoCtx{s, &data} 28 27 // Main handshake of the code 28 // Single seat, first thread arriving waits 29 // Next threads unblocks current one and blocks in its place 30 // if share == true, exchange data in the process 31 func (this * Spot) put( ctx * GoCtx, data * [] uint64, share bool) (* [] uint64) { 32 new := uintptr(unsafe.Pointer(ctx)) 33 // fmt.Printf("Enter with %p\n", data) 29 34 var raw uintptr 30 35 for true { … … 33 38 return nil 34 39 } 35 if atomic.CompareAndSwapUintptr(&this.ptr, raw, uintptr(unsafe.Pointer(&ctx))) {40 if atomic.CompareAndSwapUintptr(&this.ptr, raw, new) { 36 41 break 37 42 } … … 39 44 40 45 if raw != uintptr(0) { 41 val := (*GoCtx)(unsafe.Pointer(raw)) 46 var val *GoCtx 47 val = (*GoCtx)(unsafe.Pointer(raw)) 42 48 if share { 43 val.d = &data49 val.d = data 44 50 } 45 51 … … 47 53 } 48 54 49 ctx.s.Acquire(c ontext.Background(), 1)50 51 return *ctx.d55 ctx.s.Acquire(ctx.c, 1) 56 // fmt.Printf("Leave with %p (was %p)\n", ctx.d, data) 57 return ctx.d 52 58 } 53 59 … … 72 78 func local(result chan uint64, start chan struct{}, size uint64, cnt uint64, channels [] Spot, share bool) { 73 79 state := rand.Uint64() 74 var data [] uint6475 data = make([]uint64, size)80 var my_data [] uint64 81 my_data = make([]uint64, size) 76 82 for i := uint64(0); i < size; i++ { 77 data[i] = 083 my_data[i] = 0 78 84 } 85 data := &my_data 79 86 80 87 sem := semaphore.NewWeighted(1) 81 88 sem.Acquire(context.Background(), 1) 89 ctx := GoCtx{sem, data, context.Background()} 82 90 83 91 count := uint64(0) … … 85 93 for true { 86 94 for i := uint64(0); i < cnt; i++ { 87 data[__xorshift64(&state) % size] += 195 (*data)[__xorshift64(&state) % size] += 1 88 96 } 89 97 90 98 i := __xorshift64(&state) % uint64(len(channels)) 91 data = channels[i].put(sem, data, share) 99 // data = channels[i].put(sem, data, share) 100 data = channels[i].put(&ctx, data, share) 92 101 count += 1 93 102 94 103 if clock_mode && atomic.LoadInt32(&stop) == 1 { break } 95 104 if !clock_mode && count >= stop_count { break } 96 if uint64(len( data)) != size {105 if uint64(len(*data)) != size { 97 106 panic("Data has weird size") 98 107 } … … 150 159 global_counter := uint64(0) 151 160 for i := 0; i < nthreads; i++ { 152 global_counter += <- result 161 r := <- result 162 global_counter += r 163 fmt.Printf("%d\n", r) 153 164 } 154 165
Note: See TracChangeset
for help on using the changeset viewer.