Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/concurrency/kernel.hfa

    rdd4e2d7 r13c5e19  
    2323#include "coroutine.hfa"
    2424
     25#include "containers/stackLockFree.hfa"
     26
    2527extern "C" {
    2628#include <pthread.h>
     
    4749extern struct cluster * mainCluster;
    4850
    49 // Processor
     51// Processor id, required for scheduling threads
     52struct __processor_id_t {
     53        unsigned id;
     54
     55        #if !defined(__CFA_NO_STATISTICS__)
     56                struct __stats_t * stats;
     57        #endif
     58};
     59
    5060coroutine processorCtx_t {
    5161        struct processor * proc;
     
    5363
    5464// Wrapper around kernel threads
    55 struct processor {
     65struct __attribute__((aligned(128))) processor {
    5666        // Main state
     67        inline __processor_id_t;
     68
     69        // Cluster from which to get threads
     70        struct cluster * cltr;
     71
     72        // Set to true to notify the processor should terminate
     73        volatile bool do_terminate;
     74
    5775        // Coroutine ctx who does keeps the state of the processor
    5876        struct processorCtx_t runner;
    59 
    60         // Cluster from which to get threads
    61         struct cluster * cltr;
    6277
    6378        // Name of the processor
     
    8196        __bin_sem_t idle;
    8297
    83         // Termination
    84         // Set to true to notify the processor should terminate
    85         volatile bool do_terminate;
    86 
    8798        // Termination synchronisation (user semaphore)
    8899        semaphore terminated;
     
    92103
    93104        // Link lists fields
    94         struct __dbg_node_proc {
    95                 struct processor * next;
    96                 struct processor * prev;
    97         } node;
     105        Link(processor) link;
    98106
    99107#ifdef __CFA_DEBUG__
     
    110118static inline void  ?{}(processor & this, const char name[]) { this{name, *mainCluster }; }
    111119
    112 static inline [processor *&, processor *& ] __get( processor & this ) __attribute__((const)) { return this.node.[next, prev]; }
     120static inline Link(processor) * ?`next( processor * this ) { return &this->link; }
    113121
    114122//-----------------------------------------------------------------------------
     
    121129#define CFA_CLUSTER_IO_BUFFLEN_OFFSET        16
    122130
     131
     132//-----------------------------------------------------------------------------
     133// Cluster Tools
     134
     135// Intrusives lanes which are used by the relaxed ready queue
     136struct __attribute__((aligned(128))) __intrusive_lane_t;
     137void  ?{}(__intrusive_lane_t & this);
     138void ^?{}(__intrusive_lane_t & this);
     139
     140// Counter used for wether or not the lanes are all empty
     141struct __attribute__((aligned(128))) __snzi_node_t;
     142struct __snzi_t {
     143        unsigned mask;
     144        int root;
     145        __snzi_node_t * nodes;
     146};
     147
     148void  ?{}( __snzi_t & this, unsigned depth );
     149void ^?{}( __snzi_t & this );
     150
     151//TODO adjust cache size to ARCHITECTURE
     152// Structure holding the relaxed ready queue
     153struct __ready_queue_t {
     154        // Data tracking how many/which lanes are used
     155        // Aligned to 128 for cache locality
     156        __snzi_t snzi;
     157
     158        // Data tracking the actual lanes
     159        // On a seperate cacheline from the used struct since
     160        // used can change on each push/pop but this data
     161        // only changes on shrink/grow
     162        struct {
     163                // Arary of lanes
     164                __intrusive_lane_t * volatile data;
     165
     166                // Number of lanes (empty or not)
     167                volatile size_t count;
     168        } lanes;
     169};
     170
     171void  ?{}(__ready_queue_t & this);
     172void ^?{}(__ready_queue_t & this);
     173
    123174//-----------------------------------------------------------------------------
    124175// Cluster
    125 struct cluster {
    126         // Ready queue locks
    127         __spinlock_t ready_queue_lock;
    128 
     176struct __attribute__((aligned(128))) cluster {
    129177        // Ready queue for threads
    130         __queue_t($thread) ready_queue;
     178        __ready_queue_t ready_queue;
    131179
    132180        // Name of the cluster
     
    136184        Duration preemption_rate;
    137185
    138         // List of processors
    139         __spinlock_t idle_lock;
    140         __dllist_t(struct processor) procs;
    141         __dllist_t(struct processor) idles;
    142         unsigned int nprocessors;
     186        // List of idle processors
     187        StackLF(processor) idles;
     188        volatile unsigned int nprocessors;
    143189
    144190        // List of threads
     
    157203        #if !defined(__CFA_NO_STATISTICS__)
    158204                bool print_stats;
     205                struct __stats_t * stats;
    159206        #endif
    160207};
Note: See TracChangeset for help on using the changeset viewer.