1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
// IBM_PROLOG_BEGIN_TAG
// This is an automatically generated prolog.
//
// $Source: src/include/kernel/taskmgr.H $
//
// IBM CONFIDENTIAL
//
// COPYRIGHT International Business Machines Corp. 2010 - 2011
//
// p1
//
// Object Code Only (OCO) source materials
// Licensed Internal Code Source Materials
// IBM HostBoot Licensed Internal Code
//
// The source code for this program is not published or other-
// wise divested of its trade secrets, irrespective of what has
// been deposited with the U.S. Copyright Office.
//
// Origin: 30
//
// IBM_PROLOG_END
#ifndef __KERNEL_TASKMGR_H
#define __KERNEL_TASKMGR_H
#include <kernel/types.h>
#include <util/lockfree/counter.H>
#include <kernel/vmmmgr.H>
#include <sys/task.h>
#include <util/locked/list.H>
#include <kernel/spinlock.H>
// Forward declaration.
struct task_tracking_t;
struct task_wait_t;
/** Typedef for a list of task_tracking_t's. */
typedef Util::Locked::List<task_tracking_t, tid_t> task_tracking_list_t;
/** @struct task_tracking_t
* Stores the parent/child relationships and join information for tasks.
*
* The task_tracking_t's become a tree so that we can create a ps-like
* debug output and so that a task can do a wait() on all of its children.
*/
struct task_tracking_t
{
typedef tid_t key_type;
/** previous pointer for list. */
task_tracking_t* prev;
/** next pointer for list. */
task_tracking_t* next;
/** pointer to parent's tracking info. */
task_tracking_t* parent;
/** list of all children. */
task_tracking_list_t children;
/** tid as a key for list. */
key_type key;
/** Pointer to task structure if it is still running. */
task_t* task;
/** Crash/clean-exit status if task has ended. */
int status;
/** Return-value to task_end2() if task has ended. */
void* retval;
/** Task-wait state object. */
task_wait_t* wait_info;
/** Record the original entry point of the thread for debug purpose. */
void* entry_point;
};
/** @struct task_wait_t
* Stores the parameters for the task_wait syscall for a task which is
* deferred due to the syscall.
*/
struct task_wait_t
{
/** Tid waiting on (or -1 for any). */
int64_t tid;
/** Address to return the child status. */
int* status;
/** Address to return the child return-value. */
void** retval;
};
/** @class TaskManager
* Kernel management class to deal with task creation / exit.
*/
class TaskManager
{
public:
/** @brief Returns a pointer to the currently running task on this
* CPU.
*
* @retval NULL - Kernel has never started running any tasks.
* @retval non-NULL - The task most recently running and/or will be
* running when kernel returns to user-space.
*/
static task_t* getCurrentTask();
/** @brief Sets the current task pointer in this CPU object.
*
* @param[in] t - The task to assign on this CPU.
*/
static void setCurrentTask(task_t* t);
/** Typedef for task entry points. */
typedef void(*task_fn_t)(void*);
/** @brief Create a new task object.
*
* @param[in] t - The entry point to start the task at.
* @param[in] p - An argument pointer to pass to the task.
* @param[in] kernelParent - Should the kernel be assigned the parent
* of the new task.
*/
static task_t* createTask(task_fn_t t, void* p,
bool kernelParent = false);
/** @brief End / destroy a task object.
*
* @param[in] t - The task to end.
* @param[in] retval - Return value from the task.
* @param[in] status - TASK_STATUS_* enumeration of how the task ended.
*
* @note This function obtains the VMM-subsystem spinlock as part of
* releasing the task stack.
*/
static void endTask(task_t* t, void* retval, int status);
/** @brief Perform the 'task_wait' for a task.
*
* Returns the child information if the requested child has already
* ended or defers the task if the child requested is still running.
*
* @param[in] t - The task requesting the wait.
* @param[in] tid - The child task requested to wait on or -1 for any.
* @param[out] status - The address to write the child status.
* @param[out] retval - The address to write the child retval.
*/
static void waitTask(task_t* t, int64_t tid,
int* status, void** retval);
friend class CpuManager;
protected:
TaskManager();
~TaskManager() {};
/** Create a new task where the entry point is idleTaskLoop. */
static task_t* createIdleTask();
private:
/** Get the next TID in the task sequence. */
tid_t getNextTid() { return iv_nextTid.next(); };
/** Run the idle task loop */
static void idleTaskLoop(void*);
// Internal implementations of non-static / non-_ functions.
task_t* _createIdleTask();
task_t* _createTask(task_fn_t, void*, bool, bool);
void _endTask(task_t*, void*, int);
void _waitTask(task_t*, int64_t, int*, void**);
/** Remove a tracker from the tracker-tree and delete it.
*
* @param[in] t - The tracker to remove.
* @note Spinlock-locking of the tracker-tree is the
* responsibility of the caller.
*/
void removeTracker(task_tracking_t* t);
/** Atomic monotonically increasing counter to use for TIDs. */
Util::Lockfree::Counter<tid_t> iv_nextTid;
/** Task-tracking tree spinlock. */
Spinlock iv_spinlock;
/** Task-tracking tree. */
task_tracking_list_t iv_taskList;
};
#endif
|