Changeset 024fa4b


Ignore:
Timestamp:
Dec 16, 2020, 4:49:31 PM (9 months ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
arm-eh, jacob/cs343-translation, master, new-ast-unique-expr
Children:
34687d3
Parents:
fd84538
Message:

Eliminated mallocs in main loop of program

File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/readyQ/locality.go

    rfd84538 r024fa4b  
    1818        s * semaphore.Weighted
    1919        d * [] uint64
     20        c context.Context
    2021}
    2122
     
    2425}
    2526
    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
     31func (this * Spot) put( ctx * GoCtx, data * [] uint64, share bool) (* [] uint64) {
     32        new := uintptr(unsafe.Pointer(ctx))
     33        // fmt.Printf("Enter with %p\n", data)
    2934        var raw uintptr
    3035        for true {
     
    3338                        return nil
    3439                }
    35                 if atomic.CompareAndSwapUintptr(&this.ptr, raw, uintptr(unsafe.Pointer(&ctx))) {
     40                if atomic.CompareAndSwapUintptr(&this.ptr, raw, new) {
    3641                        break
    3742                }
     
    3944
    4045        if raw != uintptr(0) {
    41                 val := (*GoCtx)(unsafe.Pointer(raw))
     46                var val *GoCtx
     47                val = (*GoCtx)(unsafe.Pointer(raw))
    4248                if share {
    43                         val.d = &data
     49                        val.d = data
    4450                }
    4551
     
    4753        }
    4854
    49         ctx.s.Acquire(context.Background(), 1)
    50 
    51         return *ctx.d
     55        ctx.s.Acquire(ctx.c, 1)
     56        // fmt.Printf("Leave with %p (was %p)\n", ctx.d, data)
     57        return ctx.d
    5258}
    5359
     
    7278func local(result chan uint64, start chan struct{}, size uint64, cnt uint64, channels [] Spot, share bool) {
    7379        state := rand.Uint64()
    74         var data [] uint64
    75         data = make([]uint64, size)
     80        var my_data [] uint64
     81        my_data = make([]uint64, size)
    7682        for i := uint64(0); i < size; i++ {
    77                 data[i] = 0
     83                my_data[i] = 0
    7884        }
     85        data := &my_data
    7986
    8087        sem := semaphore.NewWeighted(1)
    8188        sem.Acquire(context.Background(), 1)
     89        ctx := GoCtx{sem, data, context.Background()}
    8290
    8391        count := uint64(0)
     
    8593        for true {
    8694                for i := uint64(0); i < cnt; i++ {
    87                         data[__xorshift64(&state) % size] += 1
     95                        (*data)[__xorshift64(&state) % size] += 1
    8896                }
    8997
    9098                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)
    92101                count += 1
    93102
    94103                if  clock_mode && atomic.LoadInt32(&stop) == 1 { break }
    95104                if !clock_mode && count >= stop_count { break }
    96                 if uint64(len(data)) != size {
     105                if uint64(len(*data)) != size {
    97106                        panic("Data has weird size")
    98107                }
     
    150159        global_counter := uint64(0)
    151160        for i := 0; i < nthreads; i++ {
    152                 global_counter += <- result
     161                r := <- result
     162                global_counter += r
     163                fmt.Printf("%d\n", r)
    153164        }
    154165
Note: See TracChangeset for help on using the changeset viewer.