Changeset 34687d3


Ignore:
Timestamp:
Dec 17, 2020, 12:59:37 PM (4 years ago)
Author:
Thierry Delisle <tdelisle@…>
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
Message:

Added some debugging comments and a return value if closed

File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/readyQ/locality.go

    r024fa4b r34687d3  
    1717type GoCtx struct {
    1818        s * semaphore.Weighted
    19         d * [] uint64
     19        d unsafe.Pointer
    2020        c context.Context
     21        id int
    2122}
    2223
    2324type Spot struct {
    2425        ptr uintptr
     26        id int
    2527}
    2628
     
    2931// Next threads unblocks current one and blocks in its place
    3032// if share == true, exchange data in the process
    31 func (this * Spot) put( ctx * GoCtx, data * [] uint64, share bool) (* [] uint64) {
     33func (this * Spot) put( ctx * GoCtx, data * [] uint64, share bool) (* [] uint64, bool) {
    3234        new := uintptr(unsafe.Pointer(ctx))
    33         // fmt.Printf("Enter with %p\n", data)
     35        old_d := ctx.d
    3436        var raw uintptr
    3537        for true {
    3638                raw = this.ptr
    3739                if raw == uintptr(1) {
    38                         return nil
     40                        return nil, true
    3941                }
    4042                if atomic.CompareAndSwapUintptr(&this.ptr, raw, new) {
     
    4749                val = (*GoCtx)(unsafe.Pointer(raw))
    4850                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))
    5053                }
    5154
     55                // fmt.Printf("[%d] - %d release %d\n", this.id, ctx.id, val.id)
    5256                val.s.Release(1)
    5357        }
    5458
     59        // fmt.Printf("[%d] - %d enter\n", this.id, ctx.id)
    5560        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
    5865}
    5966
     
    7683}
    7784
    78 func local(result chan uint64, start chan struct{}, size uint64, cnt uint64, channels [] Spot, share bool) {
     85func local(result chan uint64, start chan struct{}, size uint64, cnt uint64, channels [] Spot, share bool, id int) {
    7986        state := rand.Uint64()
    8087        var my_data [] uint64
     
    8794        sem := semaphore.NewWeighted(1)
    8895        sem.Acquire(context.Background(), 1)
    89         ctx := GoCtx{sem, data, context.Background()}
     96        ctx := GoCtx{sem, unsafe.Pointer(data), context.Background(), id}
    9097
    9198        count := uint64(0)
     
    97104
    98105                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)
    101108                count += 1
    102109
     110                if closed { break }
    103111                if  clock_mode && atomic.LoadInt32(&stop) == 1 { break }
    104112                if !clock_mode && count >= stop_count { break }
     
    129137
    130138        barrierStart := make(chan struct{})
    131         threads_left = int64(nthreads)
     139        threads_left = int64(nprocs)
    132140        result  := make(chan uint64)
    133141        channels := make([]Spot, nthreads - nprocs)
    134142        for i := range channels {
    135                 channels[i] = Spot{uintptr(0)}
     143                channels[i] = Spot{uintptr(0), i}
    136144        }
    137145
    138146        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)
    140148        }
    141149        fmt.Printf("Starting\n");
Note: See TracChangeset for help on using the changeset viewer.