source: src/libcfa/concurrency/kernel @ cd99ef1

ADTaaron-thesisarm-ehast-experimentalcleanup-dtorsdeferred_resndemanglerenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerpthread-emulationqualifiedEnumresolv-newwith_gc
Last change on this file since cd99ef1 was e60e0dc, checked in by Thierry Delisle <tdelisle@…>, 7 years ago

Some cleanu[ in the kernel, notably phasing out the system processor

  • Property mode set to 100644
File size: 3.5 KB
RevLine 
[8118303]1//                              -*- Mode: CFA -*-
2//
3// Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
4//
5// The contents of this file are covered under the licence agreement in the
6// file "LICENCE" distributed with Cforall.
7//
[75a17f1]8// kernel --
[8118303]9//
10// Author           : Thierry Delisle
[75f3522]11// Created On       : Tue Jan 17 12:27:26 2017
[8118303]12// Last Modified By : Thierry Delisle
13// Last Modified On : --
14// Update Count     : 0
15//
16
17#ifndef KERNEL_H
18#define KERNEL_H
19
[c84e80a]20#include <stdbool.h>
[8118303]21
[bd98b58]22#include "invoke.h"
23
[8def349]24extern "C" {
25#include <pthread.h>
26}
27
[db6f06a]28//-----------------------------------------------------------------------------
29// Locks
[e60e0dc]30void lock      ( spinlock * DEBUG_CTX_PARAM2 );       // Lock the spinlock, spin if already acquired
31void lock_yield( spinlock * DEBUG_CTX_PARAM2 );       // Lock the spinlock, yield repeatedly if already acquired
32bool try_lock  ( spinlock * DEBUG_CTX_PARAM2 );       // Lock the spinlock, return false if already acquired
33void unlock    ( spinlock * );                        // Unlock the spinlock
[db6f06a]34
[bdeba0b]35struct semaphore {
36        spinlock lock;
37        int count;
38        __thread_queue_t waiting;
[9c31349]39};
40
[bdeba0b]41void  ?{}(semaphore * this, int count = 1);
42void ^?{}(semaphore * this);
43void P(semaphore * this);
44void V(semaphore * this);
[9c31349]45
[db6f06a]46
[bd98b58]47//-----------------------------------------------------------------------------
48// Cluster
49struct cluster {
[e60e0dc]50        spinlock ready_queue_lock;                      // Ready queue locks
51        __thread_queue_t ready_queue;                   // Ready queue for threads
52        unsigned long long int preemption;              // Preemption rate on this cluster
[bd98b58]53};
54
55void ?{}(cluster * this);
56void ^?{}(cluster * this);
57
58//-----------------------------------------------------------------------------
59// Processor
[0c78741]60enum FinishOpCode { No_Action, Release, Schedule, Release_Schedule, Release_Multi, Release_Multi_Schedule };
61
62//TODO use union, many of these fields are mutually exclusive (i.e. MULTI vs NOMULTI)
[db6f06a]63struct FinishAction {
64        FinishOpCode action_code;
[348006f]65        thread_desc * thrd;
[db6f06a]66        spinlock * lock;
[0c78741]67        spinlock ** locks;
68        unsigned short lock_count;
69        thread_desc ** thrds;
70        unsigned short thrd_count;
[8fcbb4c]71};
[2ac095d]72static inline void ?{}(FinishAction * this) {
[db6f06a]73        this->action_code = No_Action;
74        this->thrd = NULL;
75        this->lock = NULL;
76}
77static inline void ^?{}(FinishAction * this) {}
[8fcbb4c]78
[e60e0dc]79// Processor
80// Wrapper around kernel threads
[c84e80a]81struct processor {
[e60e0dc]82        // Main state
83        struct processorCtx_t * runner;                 // Coroutine ctx who does keeps the state of the processor
84        cluster * cltr;                                 // Cluster from which to get threads
85        pthread_t kernel_thread;                        // Handle to pthreads
[db6f06a]86
[e60e0dc]87        // Termination
88        volatile bool do_terminate;                     // Set to true to notify the processor should terminate
89        semaphore terminated;                           // Termination synchronisation
[c81ebf9]90
[e60e0dc]91        // RunThread data
92        struct FinishAction finish;                     // Action to do after a thread is ran
[c81ebf9]93
[e60e0dc]94        // Preemption data
95        struct alarm_node_t * preemption_alarm;         // Node which is added in the discrete event simulaiton
96        bool pending_preemption;                        // If true, a preemption was triggered in an unsafe region, the processor must preempt as soon as possible
[4e6fb8e]97
[e60e0dc]98#ifdef __CFA_DEBUG__
99        char * last_enable;                             // Last function to enable preemption on this processor
100#endif
[c84e80a]101};
102
[8def349]103void ?{}(processor * this);
[bd98b58]104void ?{}(processor * this, cluster * cltr);
[c84e80a]105void ^?{}(processor * this);
106
[8118303]107#endif //KERNEL_H
108
109// Local Variables: //
[fa21ac9]110// mode: CFA //
111// tab-width: 6 //
[8118303]112// End: //
Note: See TracBrowser for help on using the repository browser.