source: libcfa/src/concurrency/kernel.hfa @ 69914cbc

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 69914cbc was 69914cbc, checked in by Michael Brooks <mlbrooks@…>, 3 years ago

Replacing "Mike's old linked list" with "Mike's new linked list," including replatforming uses of the old one.

libcfa/src/containers/list.hfa ---[becomes]--> tests/zombies/linked-list-perf/mike-old.hfa
libcfa/src/containers/list2.hfa ---[becomes]--> libcfa/src/containers/list.hfa

There are no more multiple versions of "Mike's list" in libcfa, nor tests thereof.

The libcfa concurrency uses (alarm, kernel and ready_queue) are hereby ported to "Mike's new."

A best-effort port of executor, which was found not compiling with errors that seem unrelated to the linked list, is attempted too.

  • Property mode set to 100644
File size: 8.4 KB
RevLine 
[8118303]1//
2// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
[454f478]7// kernel -- Header containing the core of the kernel API
[8118303]8//
9// Author           : Thierry Delisle
[75f3522]10// Created On       : Tue Jan 17 12:27:26 2017
[6b0b624]11// Last Modified By : Peter A. Buhr
[e3fea42]12// Last Modified On : Tue Feb  4 12:29:26 2020
13// Update Count     : 22
[8118303]14//
15
[6b0b624]16#pragma once
[8118303]17
[bd98b58]18#include "invoke.h"
[73abe95]19#include "time_t.hfa"
[d76bd79]20#include "coroutine.hfa"
[bd98b58]21
[1eb239e4]22#include "containers/list.hfa"
[64a7146]23
[8def349]24extern "C" {
[c402739f]25        #include <bits/pthreadtypes.h>
[454f478]26        #include <pthread.h>
[c402739f]27        #include <linux/types.h>
[8def349]28}
29
[454f478]30#ifdef __CFA_WITH_VERIFY__
31        extern bool __cfaabi_dbg_in_kernel();
32#endif
33
[78da4ab]34//-----------------------------------------------------------------------------
35// I/O
36struct cluster;
37struct $io_context;
38struct $io_arbiter;
39
40struct io_context_params {
41        int num_entries;
42};
43
44void  ?{}(io_context_params & this);
45
[bd98b58]46//-----------------------------------------------------------------------------
[de94a60]47// Processor
[de6319f]48extern struct cluster * mainCluster;
[bd98b58]49
[9b1dcc2]50// Processor id, required for scheduling threads
[8834751]51
[9b1dcc2]52
[094476d]53coroutine processorCtx_t {
54        struct processor * proc;
55};
56
[e60e0dc]57// Wrapper around kernel threads
[37ba662]58struct __attribute__((aligned(128))) processor {
[025278e]59        // Cluster from which to get threads
[de94a60]60        struct cluster * cltr;
[025278e]61
[431cd4f]62        // Ready Queue state per processor
63        struct {
64                unsigned short its;
65                unsigned short itr;
66                unsigned id;
67                unsigned target;
68                unsigned long long int cutoff;
69        } rdq;
[bd0bdd37]70
[37ba662]71        // Set to true to notify the processor should terminate
72        volatile bool do_terminate;
73
74        // Coroutine ctx who does keeps the state of the processor
75        struct processorCtx_t runner;
76
[de6319f]77        // Name of the processor
78        const char * name;
79
[025278e]80        // Handle to pthreads
81        pthread_t kernel_thread;
[2ac095d]82
[c993b15]83        // Unique id for the processor (not per cluster)
84        unsigned unique_id;
85
[78da4ab]86        struct {
[dddb3dd0]87                $io_context * ctx;
88                bool pending;
89                bool dirty;
[78da4ab]90        } io;
91
[e60e0dc]92        // Preemption data
[025278e]93        // Node which is added in the discrete event simulaiton
94        struct alarm_node_t * preemption_alarm;
95
96        // If true, a preemption was triggered in an unsafe region, the processor must preempt as soon as possible
97        bool pending_preemption;
[c81ebf9]98
[92e7631]99        // Idle lock (kernel semaphore)
[dddb3dd0]100        int idle;
[85b1deb]101
[92e7631]102        // Termination synchronisation (user semaphore)
[454f478]103        oneshot terminated;
[de94a60]104
[27f5f71]105        // pthread Stack
106        void * stack;
107
[de94a60]108        // Link lists fields
[69914cbc]109        inline dlink(processor);
[14a61b5]110
[a1538cd]111        // special init fields
112        // This is needed for memcached integration
113        // once memcached experiments are done this should probably be removed
114        // it is not a particularly safe scheme as it can make processors less homogeneous
115        struct {
[a5e7233]116                $thread * thrd;
[a1538cd]117        } init;
118
[a67c5b6]119        struct KernelThreadData * local_data;
120
[c34ebf2]121        #if !defined(__CFA_NO_STATISTICS__)
[69fbc61]122                int print_stats;
[c34ebf2]123                bool print_halts;
124        #endif
125
[e60e0dc]126#ifdef __CFA_DEBUG__
[025278e]127        // Last function to enable preemption on this processor
[cdbfab0]128        const char * last_enable;
[e60e0dc]129#endif
[c84e80a]130};
[69914cbc]131P9_EMBEDDED( processor, dlink(processor) )
[c84e80a]132
[a5e7233]133void  ?{}(processor & this, const char name[], struct cluster & cltr);
[242a902]134void ^?{}(processor & this);
[c84e80a]135
[a5e7233]136static inline void  ?{}(processor & this)                        { this{ "Anonymous Processor", *mainCluster}; }
137static inline void  ?{}(processor & this, struct cluster & cltr) { this{ "Anonymous Processor", cltr}; }
138static inline void  ?{}(processor & this, const char name[])     { this{name, *mainCluster}; }
[de6319f]139
[7768b8d]140//-----------------------------------------------------------------------------
141// Cluster Tools
[dca5802]142
[9cc3a18]143// Intrusives lanes which are used by the ready queue
[61d7bec]144struct __attribute__((aligned(128))) __intrusive_lane_t;
[dca5802]145void  ?{}(__intrusive_lane_t & this);
146void ^?{}(__intrusive_lane_t & this);
[7768b8d]147
[9cc3a18]148// Aligned timestamps which are used by the relaxed ready queue
149struct __attribute__((aligned(128))) __timestamp_t;
150void  ?{}(__timestamp_t & this);
151void ^?{}(__timestamp_t & this);
152
[b798713]153//TODO adjust cache size to ARCHITECTURE
[dca5802]154// Structure holding the relaxed ready queue
[37ba662]155struct __ready_queue_t {
[dca5802]156        // Data tracking the actual lanes
157        // On a seperate cacheline from the used struct since
158        // used can change on each push/pop but this data
159        // only changes on shrink/grow
[37ba662]160        struct {
[dca5802]161                // Arary of lanes
162                __intrusive_lane_t * volatile data;
163
[9cc3a18]164                // Array of times
165                __timestamp_t * volatile tscs;
166
[dca5802]167                // Number of lanes (empty or not)
[b798713]168                volatile size_t count;
[dca5802]169        } lanes;
[b798713]170};
171
172void  ?{}(__ready_queue_t & this);
173void ^?{}(__ready_queue_t & this);
174
[1eb239e4]175// Idle Sleep
[6a9b12b]176struct __cluster_proc_list {
[1eb239e4]177        // Spin lock protecting the queue
178        volatile uint64_t lock;
179
180        // Total number of processors
181        unsigned total;
182
183        // Total number of idle processors
184        unsigned idle;
185
186        // List of idle processors
[69914cbc]187        dlist(processor) idles;
[fc59b580]188
189        // List of active processors
[69914cbc]190        dlist(processor) actives;
[1eb239e4]191};
192
[de94a60]193//-----------------------------------------------------------------------------
194// Cluster
[37ba662]195struct __attribute__((aligned(128))) cluster {
[de94a60]196        // Ready queue for threads
[b798713]197        __ready_queue_t ready_queue;
[de94a60]198
199        // Name of the cluster
200        const char * name;
201
202        // Preemption rate on this cluster
203        Duration preemption_rate;
204
[64a7146]205        // List of idle processors
[6a9b12b]206        __cluster_proc_list procs;
[de94a60]207
[d4e68a6]208        // List of threads
[a1a17a7]209        __spinlock_t thread_list_lock;
[ac2b598]210        __dllist_t(struct $thread) threads;
[d4e68a6]211        unsigned int nthreads;
[a1a17a7]212
[de94a60]213        // Link lists fields
[ea8b2f7]214        struct __dbg_node_cltr {
[de94a60]215                cluster * next;
216                cluster * prev;
217        } node;
[92976d9]218
[f00b26d4]219        struct {
[78da4ab]220                $io_arbiter * arbiter;
221                io_context_params params;
[f00b26d4]222        } io;
[038be32]223
224        #if !defined(__CFA_NO_STATISTICS__)
[8834751]225                struct __stats_t * stats;
[69fbc61]226                int print_stats;
[038be32]227        #endif
[de94a60]228};
229extern Duration default_preemption();
230
[f00b26d4]231void ?{} (cluster & this, const char name[], Duration preemption_rate, unsigned num_io, const io_context_params & io_params);
[de94a60]232void ^?{}(cluster & this);
233
[f00b26d4]234static inline void ?{} (cluster & this)                                            { io_context_params default_params;    this{"Anonymous Cluster", default_preemption(), 1, default_params}; }
235static inline void ?{} (cluster & this, Duration preemption_rate)                  { io_context_params default_params;    this{"Anonymous Cluster", preemption_rate, 1, default_params}; }
236static inline void ?{} (cluster & this, const char name[])                         { io_context_params default_params;    this{name, default_preemption(), 1, default_params}; }
237static inline void ?{} (cluster & this, unsigned num_io)                           { io_context_params default_params;    this{"Anonymous Cluster", default_preemption(), num_io, default_params}; }
238static inline void ?{} (cluster & this, Duration preemption_rate, unsigned num_io) { io_context_params default_params;    this{"Anonymous Cluster", preemption_rate, num_io, default_params}; }
239static inline void ?{} (cluster & this, const char name[], unsigned num_io)        { io_context_params default_params;    this{name, default_preemption(), num_io, default_params}; }
240static inline void ?{} (cluster & this, const io_context_params & io_params)                                            { this{"Anonymous Cluster", default_preemption(), 1, io_params}; }
241static inline void ?{} (cluster & this, Duration preemption_rate, const io_context_params & io_params)                  { this{"Anonymous Cluster", preemption_rate, 1, io_params}; }
242static inline void ?{} (cluster & this, const char name[], const io_context_params & io_params)                         { this{name, default_preemption(), 1, io_params}; }
243static inline void ?{} (cluster & this, unsigned num_io, const io_context_params & io_params)                           { this{"Anonymous Cluster", default_preemption(), num_io, io_params}; }
244static inline void ?{} (cluster & this, Duration preemption_rate, unsigned num_io, const io_context_params & io_params) { this{"Anonymous Cluster", preemption_rate, num_io, io_params}; }
245static inline void ?{} (cluster & this, const char name[], unsigned num_io, const io_context_params & io_params)        { this{name, default_preemption(), num_io, io_params}; }
[de94a60]246
[c7a900a]247static inline [cluster *&, cluster *& ] __get( cluster & this ) __attribute__((const)) { return this.node.[next, prev]; }
[de94a60]248
[8fc652e0]249static inline struct processor * active_processor() { return publicTLS_get( this_processor ); } // UNSAFE
250static inline struct cluster   * active_cluster  () { return publicTLS_get( this_processor )->cltr; }
[d4e68a6]251
[038be32]252#if !defined(__CFA_NO_STATISTICS__)
[8fc652e0]253        void print_stats_now( cluster & this, int flags );
254
[69fbc61]255        static inline void print_stats_at_exit( cluster & this, int flags ) {
256                this.print_stats |= flags;
[038be32]257        }
[c34ebf2]258
[69fbc61]259        static inline void print_stats_at_exit( processor & this, int flags ) {
260                this.print_stats |= flags;
[c34ebf2]261        }
262
263        void print_halts( processor & this );
[038be32]264#endif
265
[8118303]266// Local Variables: //
[6b0b624]267// mode: c //
268// tab-width: 4 //
[8118303]269// End: //
Note: See TracBrowser for help on using the repository browser.