Changeset 038a0bd for libcfa


Ignore:
Timestamp:
Jan 18, 2022, 8:49:43 PM (3 years ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
Children:
6a33e40
Parents:
b5f17e1 (diff), adfd125 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
libcfa/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/common.hfa

    rb5f17e1 r038a0bd  
    1 // 
     1//
    22// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
    33//
    44// The contents of this file are covered under the licence agreement in the
    55// file "LICENCE" distributed with Cforall.
    6 // 
    7 // common --
    8 // 
     6//
     7// common.hfa --
     8//
    99// Author           : Peter A. Buhr
    1010// Created On       : Wed Jul 11 17:54:36 2018
     
    1212// Last Modified On : Wed May  5 14:02:04 2021
    1313// Update Count     : 18
    14 // 
     14//
    1515
    1616#pragma once
  • libcfa/src/concurrency/io.cfa

    rb5f17e1 r038a0bd  
    144144                __ioarbiter_flush( ctx );
    145145
    146                 __STATS__( true, io.calls.flush++; )
    147                 int ret = syscall( __NR_io_uring_enter, ctx.fd, ctx.sq.to_submit, min_comp, min_comp > 0 ? IORING_ENTER_GETEVENTS : 0, (sigset_t *)0p, _NSIG / 8);
    148                 if( ret < 0 ) {
    149                         switch((int)errno) {
    150                         case EAGAIN:
    151                         case EINTR:
    152                         case EBUSY:
    153                                 // Update statistics
    154                                 __STATS__( false, io.calls.errors.busy ++; )
    155                                 return false;
    156                         default:
    157                                 abort( "KERNEL ERROR: IO_URING SYSCALL - (%d) %s\n", (int)errno, strerror(errno) );
     146                if(ctx.sq.to_submit != 0 || min_comp > 0) {
     147
     148                        __STATS__( true, io.calls.flush++; )
     149                        int ret = syscall( __NR_io_uring_enter, ctx.fd, ctx.sq.to_submit, min_comp, min_comp > 0 ? IORING_ENTER_GETEVENTS : 0, (sigset_t *)0p, _NSIG / 8);
     150                        if( ret < 0 ) {
     151                                switch((int)errno) {
     152                                case EAGAIN:
     153                                case EINTR:
     154                                case EBUSY:
     155                                        // Update statistics
     156                                        __STATS__( false, io.calls.errors.busy ++; )
     157                                        return false;
     158                                default:
     159                                        abort( "KERNEL ERROR: IO_URING SYSCALL - (%d) %s\n", (int)errno, strerror(errno) );
     160                                }
    158161                        }
    159                 }
    160 
    161                 __cfadbg_print_safe(io, "Kernel I/O : %u submitted to io_uring %d\n", ret, ctx.fd);
    162                 __STATS__( true, io.calls.submitted += ret; )
    163                 /* paranoid */ verify( ctx.sq.to_submit <= *ctx.sq.num );
    164                 /* paranoid */ verify( ctx.sq.to_submit >= ret );
    165 
    166                 ctx.sq.to_submit -= ret;
    167 
    168                 /* paranoid */ verify( ctx.sq.to_submit <= *ctx.sq.num );
    169 
    170                 // Release the consumed SQEs
    171                 __release_sqes( ctx );
    172 
    173                 /* paranoid */ verify( ! __preemption_enabled() );
    174 
    175                 ctx.proc->io.pending = false;
     162
     163                        __cfadbg_print_safe(io, "Kernel I/O : %u submitted to io_uring %d\n", ret, ctx.fd);
     164                        __STATS__( true, io.calls.submitted += ret; )
     165                        /* paranoid */ verify( ctx.sq.to_submit <= *ctx.sq.num );
     166                        /* paranoid */ verify( ctx.sq.to_submit >= ret );
     167
     168                        ctx.sq.to_submit -= ret;
     169
     170                        /* paranoid */ verify( ctx.sq.to_submit <= *ctx.sq.num );
     171
     172                        // Release the consumed SQEs
     173                        __release_sqes( ctx );
     174
     175                        /* paranoid */ verify( ! __preemption_enabled() );
     176
     177                        ctx.proc->io.pending = false;
     178                }
     179
    176180                ready_schedule_lock();
    177181                bool ret = __cfa_io_drain( proc );
  • libcfa/src/concurrency/kernel.hfa

    rb5f17e1 r038a0bd  
    6868                unsigned last;
    6969                signed   cpu;
    70                 // unsigned long long int cutoff;
    7170        } rdq;
    7271
     
    154153};
    155154
    156 struct __attribute__((aligned(128))) __cache_id_t {
     155struct __attribute__((aligned(16))) __cache_id_t {
    157156        volatile unsigned id;
    158157};
  • libcfa/src/concurrency/ready_queue.cfa

    rb5f17e1 r038a0bd  
    303303                        lanes.help[idx].dst = 0;
    304304                        lanes.help[idx].tri = 0;
    305                 }
    306 
    307                 caches = alloc( cpu_info.llc_count );
    308                 for( idx; (size_t)cpu_info.llc_count ) {
    309                         (caches[idx]){};
    310305                }
    311306        #else
     
    404399                /* paranoid */ verify(cpu < cpu_info.hthrd_count);
    405400                unsigned this_cache = cpu_info.llc_map[cpu].cache;
    406                 __atomic_store_n(&lanes.caches[this / READYQ_SHARD_FACTOR].id, this_cache, __ATOMIC_RELAXED);
     401
     402                // Super important: don't write the same value over and over again
     403                // We want to maximise our chances that his particular values stays in cache
     404                if(lanes.caches[this / READYQ_SHARD_FACTOR].id != this_cache)
     405                        __atomic_store_n(&lanes.caches[this / READYQ_SHARD_FACTOR].id, this_cache, __ATOMIC_RELAXED);
    407406
    408407                const unsigned long long ctsc = rdtscl();
     
    506505        }
    507506
    508         static inline int pop_getcpu(processor * proc, __ready_queue_caches_t * caches) {
    509                 const int prv = proc->rdq.cpu;
    510                 const int cpu = __kernel_getcpu();
    511                 if( prv != proc->rdq.cpu ) {
    512                         unsigned pidx = cpu_info.llc_map[prv].cache;
    513                         /* paranoid */ verify(pidx < cpu_info.llc_count);
    514 
    515                         unsigned nidx = cpu_info.llc_map[cpu].cache;
    516                         /* paranoid */ verify(pidx < cpu_info.llc_count);
    517 
    518                         depart(caches[pidx]);
    519                         arrive(caches[nidx]);
    520 
    521                         __STATS( /* cpu migs++ */ )
    522                 }
    523                 return proc->rdq.cpu = cpu;
    524         }
    525 
    526507        // Pop from the ready queue from a given cluster
    527508        __attribute__((hot)) thread$ * pop_fast(struct cluster * cltr) with (cltr->ready_queue) {
     
    530511
    531512                processor * const proc = kernelTLS().this_processor;
    532                 const int cpu = pop_getcpu( proc, caches );
    533                 // const int cpu = __kernel_getcpu();
     513                const int cpu = __kernel_getcpu();
    534514                /* paranoid */ verify(cpu >= 0);
    535515                /* paranoid */ verify(cpu < cpu_info.hthrd_count);
     
    548528                        unsigned long long max = 0;
    549529                        for(i; READYQ_SHARD_FACTOR) {
    550                                 unsigned long long tsc = moving_average(ctsc - ts(lanes.data[start + i]), lanes.tscs[start + i].ma);
     530                                unsigned long long tsc = moving_average(ctsc, ts(lanes.data[start + i]), lanes.tscs[start + i].ma);
    551531                                if(tsc > max) max = tsc;
    552532                        }
     
    569549                        unsigned long long max = 0;
    570550                        for(i; READYQ_SHARD_FACTOR) {
    571                                 unsigned long long tsc = moving_average(ctsc - ts(lanes.data[start + i]), lanes.tscs[start + i].ma);
     551                                unsigned long long tsc = moving_average(ctsc, ts(lanes.data[start + i]), lanes.tscs[start + i].ma);
    572552                                if(tsc > max) max = tsc;
    573553                        }
     
    577557                                proc->rdq.target = MAX;
    578558                                lanes.help[target / READYQ_SHARD_FACTOR].tri++;
    579                                 if(moving_average(ctsc - lanes.tscs[target].tv, lanes.tscs[target].ma) > cutoff) {
    580                                         __STATS( __tls_stats()->ready.pop.helped[target]++; )
     559                                if(moving_average(ctsc, lanes.tscs[target].tv, lanes.tscs[target].ma) > cutoff) {
    581560                                        thread$ * t = try_pop(cltr, target __STATS(, __tls_stats()->ready.pop.help));
    582561                                        proc->rdq.last = target;
     
    587566
    588567                        unsigned last = proc->rdq.last;
    589                         if(last != MAX && moving_average(ctsc - lanes.tscs[last].tv, lanes.tscs[last].ma) > cutoff) {
    590                                 __STATS( __tls_stats()->ready.pop.helped[last]++; )
     568                        if(last != MAX && moving_average(ctsc, lanes.tscs[last].tv, lanes.tscs[last].ma) > cutoff) {
    591569                                thread$ * t = try_pop(cltr, last __STATS(, __tls_stats()->ready.pop.help));
    592570                                if(t) return t;
Note: See TracChangeset for help on using the changeset viewer.