Ignore:
File:
1 edited

Legend:

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

    r13c5e19 rdd4e2d7  
    2222#include "time_t.hfa"
    2323#include "coroutine.hfa"
    24 
    25 #include "containers/stackLockFree.hfa"
    2624
    2725extern "C" {
     
    4947extern struct cluster * mainCluster;
    5048
    51 // Processor id, required for scheduling threads
    52 struct __processor_id_t {
    53         unsigned id;
    54 
    55         #if !defined(__CFA_NO_STATISTICS__)
    56                 struct __stats_t * stats;
    57         #endif
    58 };
    59 
     49// Processor
    6050coroutine processorCtx_t {
    6151        struct processor * proc;
     
    6353
    6454// Wrapper around kernel threads
    65 struct __attribute__((aligned(128))) processor {
     55struct processor {
    6656        // Main state
    67         inline __processor_id_t;
     57        // Coroutine ctx who does keeps the state of the processor
     58        struct processorCtx_t runner;
    6859
    6960        // Cluster from which to get threads
    7061        struct cluster * cltr;
    71 
    72         // Set to true to notify the processor should terminate
    73         volatile bool do_terminate;
    74 
    75         // Coroutine ctx who does keeps the state of the processor
    76         struct processorCtx_t runner;
    7762
    7863        // Name of the processor
     
    9681        __bin_sem_t idle;
    9782
     83        // Termination
     84        // Set to true to notify the processor should terminate
     85        volatile bool do_terminate;
     86
    9887        // Termination synchronisation (user semaphore)
    9988        semaphore terminated;
     
    10392
    10493        // Link lists fields
    105         Link(processor) link;
     94        struct __dbg_node_proc {
     95                struct processor * next;
     96                struct processor * prev;
     97        } node;
    10698
    10799#ifdef __CFA_DEBUG__
     
    118110static inline void  ?{}(processor & this, const char name[]) { this{name, *mainCluster }; }
    119111
    120 static inline Link(processor) * ?`next( processor * this ) { return &this->link; }
     112static inline [processor *&, processor *& ] __get( processor & this ) __attribute__((const)) { return this.node.[next, prev]; }
    121113
    122114//-----------------------------------------------------------------------------
     
    129121#define CFA_CLUSTER_IO_BUFFLEN_OFFSET        16
    130122
    131 
    132 //-----------------------------------------------------------------------------
    133 // Cluster Tools
    134 
    135 // Intrusives lanes which are used by the relaxed ready queue
    136 struct __attribute__((aligned(128))) __intrusive_lane_t;
    137 void  ?{}(__intrusive_lane_t & this);
    138 void ^?{}(__intrusive_lane_t & this);
    139 
    140 // Counter used for wether or not the lanes are all empty
    141 struct __attribute__((aligned(128))) __snzi_node_t;
    142 struct __snzi_t {
    143         unsigned mask;
    144         int root;
    145         __snzi_node_t * nodes;
    146 };
    147 
    148 void  ?{}( __snzi_t & this, unsigned depth );
    149 void ^?{}( __snzi_t & this );
    150 
    151 //TODO adjust cache size to ARCHITECTURE
    152 // Structure holding the relaxed ready queue
    153 struct __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 
    171 void  ?{}(__ready_queue_t & this);
    172 void ^?{}(__ready_queue_t & this);
    173 
    174123//-----------------------------------------------------------------------------
    175124// Cluster
    176 struct __attribute__((aligned(128))) cluster {
     125struct cluster {
     126        // Ready queue locks
     127        __spinlock_t ready_queue_lock;
     128
    177129        // Ready queue for threads
    178         __ready_queue_t ready_queue;
     130        __queue_t($thread) ready_queue;
    179131
    180132        // Name of the cluster
     
    184136        Duration preemption_rate;
    185137
    186         // List of idle processors
    187         StackLF(processor) idles;
    188         volatile unsigned int nprocessors;
     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;
    189143
    190144        // List of threads
     
    203157        #if !defined(__CFA_NO_STATISTICS__)
    204158                bool print_stats;
    205                 struct __stats_t * stats;
    206159        #endif
    207160};
Note: See TracChangeset for help on using the changeset viewer.