source: src/libcfa/concurrency/kernel @ e60e0dc

aaron-thesisarm-ehcleanup-dtorsdeferred_resndemanglerjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprnew-envno_listpersistent-indexerresolv-newwith_gc
Last change on this file since e60e0dc was e60e0dc, checked in by Thierry Delisle <tdelisle@…>, 5 years ago

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

  • Property mode set to 100644
File size: 3.5 KB
Line 
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//
8// kernel --
9//
10// Author           : Thierry Delisle
11// Created On       : Tue Jan 17 12:27:26 2017
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
20#include <stdbool.h>
21
22#include "invoke.h"
23
24extern "C" {
25#include <pthread.h>
26}
27
28//-----------------------------------------------------------------------------
29// Locks
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
34
35struct semaphore {
36        spinlock lock;
37        int count;
38        __thread_queue_t waiting;
39};
40
41void  ?{}(semaphore * this, int count = 1);
42void ^?{}(semaphore * this);
43void P(semaphore * this);
44void V(semaphore * this);
45
46
47//-----------------------------------------------------------------------------
48// Cluster
49struct cluster {
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
53};
54
55void ?{}(cluster * this);
56void ^?{}(cluster * this);
57
58//-----------------------------------------------------------------------------
59// Processor
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)
63struct FinishAction {
64        FinishOpCode action_code;
65        thread_desc * thrd;
66        spinlock * lock;
67        spinlock ** locks;
68        unsigned short lock_count;
69        thread_desc ** thrds;
70        unsigned short thrd_count;
71};
72static inline void ?{}(FinishAction * this) {
73        this->action_code = No_Action;
74        this->thrd = NULL;
75        this->lock = NULL;
76}
77static inline void ^?{}(FinishAction * this) {}
78
79// Processor
80// Wrapper around kernel threads
81struct processor {
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
86
87        // Termination
88        volatile bool do_terminate;                     // Set to true to notify the processor should terminate
89        semaphore terminated;                           // Termination synchronisation
90
91        // RunThread data
92        struct FinishAction finish;                     // Action to do after a thread is ran
93
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
97
98#ifdef __CFA_DEBUG__
99        char * last_enable;                             // Last function to enable preemption on this processor
100#endif
101};
102
103void ?{}(processor * this);
104void ?{}(processor * this, cluster * cltr);
105void ^?{}(processor * this);
106
107#endif //KERNEL_H
108
109// Local Variables: //
110// mode: CFA //
111// tab-width: 6 //
112// End: //
Note: See TracBrowser for help on using the repository browser.