rf_dag.h revision 1.3 1 /* $NetBSD: rf_dag.h,v 1.3 1999/02/05 00:06:07 oster Exp $ */
2 /*
3 * Copyright (c) 1995 Carnegie-Mellon University.
4 * All rights reserved.
5 *
6 * Author: William V. Courtright II, Mark Holland
7 *
8 * Permission to use, copy, modify and distribute this software and
9 * its documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
13 *
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
17 *
18 * Carnegie Mellon requests users of this software to return to
19 *
20 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
24 *
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
27 */
28
29 /****************************************************************************
30 * *
31 * dag.h -- header file for DAG-related data structures *
32 * *
33 ****************************************************************************/
34
35 #ifndef _RF__RF_DAG_H_
36 #define _RF__RF_DAG_H_
37
38 #include "rf_types.h"
39 #include "rf_threadstuff.h"
40 #include "rf_alloclist.h"
41 #include "rf_stripelocks.h"
42 #include "rf_layout.h"
43 #include "rf_dagflags.h"
44 #include "rf_acctrace.h"
45 #include "rf_memchunk.h"
46
47 #define RF_THREAD_CONTEXT 0 /* we were invoked from thread context */
48 #define RF_INTR_CONTEXT 1 /* we were invoked from interrupt context */
49 #define RF_MAX_ANTECEDENTS 20 /* max num of antecedents a node may posses */
50
51 #include <sys/buf.h>
52
53 struct RF_PropHeader_s { /* structure for propagation of results */
54 int resultNum; /* bind result # resultNum */
55 int paramNum; /* to parameter # paramNum */
56 RF_PropHeader_t *next; /* linked list for multiple results/params */
57 };
58
59 typedef enum RF_NodeStatus_e {
60 rf_bwd1, /* node is ready for undo logging (backward
61 * error recovery only) */
62 rf_bwd2, /* node has completed undo logging (backward
63 * error recovery only) */
64 rf_wait, /* node is waiting to be executed */
65 rf_fired, /* node is currently executing its do function */
66 rf_good, /* node successfully completed execution of
67 * its do function */
68 rf_bad, /* node failed to successfully execute its do
69 * function */
70 rf_skipped, /* not used anymore, used to imply a node was
71 * not executed */
72 rf_recover, /* node is currently executing its undo
73 * function */
74 rf_panic, /* node failed to successfully execute its
75 * undo function */
76 rf_undone /* node successfully executed its undo
77 * function */
78 } RF_NodeStatus_t;
79 /*
80 * These were used to control skipping a node.
81 * Now, these are only used as comments.
82 */
83 typedef enum RF_AntecedentType_e {
84 rf_trueData,
85 rf_antiData,
86 rf_outputData,
87 rf_control
88 } RF_AntecedentType_t;
89 #define RF_DAG_PTRCACHESIZE 40
90 #define RF_DAG_PARAMCACHESIZE 12
91
92 typedef RF_uint8 RF_DagNodeFlags_t;
93
94 struct RF_DagNode_s {
95 RF_NodeStatus_t status; /* current status of this node */
96 int (*doFunc) (RF_DagNode_t *); /* normal function */
97 int (*undoFunc) (RF_DagNode_t *); /* func to remove effect of
98 * doFunc */
99 int (*wakeFunc) (RF_DagNode_t *, int status); /* func called when the
100 * node completes an I/O */
101 int numParams; /* number of parameters required by *funcPtr */
102 int numResults; /* number of results produced by *funcPtr */
103 int numAntecedents; /* number of antecedents */
104 int numAntDone; /* number of antecedents which have finished */
105 int numSuccedents; /* number of succedents */
106 int numSuccFired; /* incremented when a succedent is fired
107 * during forward execution */
108 int numSuccDone; /* incremented when a succedent finishes
109 * during rollBackward */
110 int commitNode; /* boolean flag - if true, this is a commit
111 * node */
112 RF_DagNode_t **succedents; /* succedents, array size
113 * numSuccedents */
114 RF_DagNode_t **antecedents; /* antecedents, array size
115 * numAntecedents */
116 RF_AntecedentType_t antType[RF_MAX_ANTECEDENTS]; /* type of each
117 * antecedent */
118 void **results; /* array of results produced by *funcPtr */
119 RF_DagParam_t *params; /* array of parameters required by *funcPtr */
120 RF_PropHeader_t **propList; /* propagation list, size
121 * numSuccedents */
122 RF_DagHeader_t *dagHdr; /* ptr to head of dag containing this node */
123 void *dagFuncData; /* dag execution func uses this for whatever
124 * it wants */
125 RF_DagNode_t *next;
126 int nodeNum; /* used by PrintDAG for debug only */
127 int visited; /* used to avoid re-visiting nodes on DAG
128 * walks */
129 /* ANY CODE THAT USES THIS FIELD MUST MAINTAIN THE PROPERTY THAT AFTER
130 * IT FINISHES, ALL VISITED FLAGS IN THE DAG ARE IDENTICAL */
131 char *name; /* debug only */
132 RF_DagNodeFlags_t flags;/* see below */
133 RF_DagNode_t *dag_ptrs[RF_DAG_PTRCACHESIZE]; /* cache for performance */
134 RF_DagParam_t dag_params[RF_DAG_PARAMCACHESIZE]; /* cache for performance */
135 };
136 /*
137 * Bit values for flags field of RF_DagNode_t
138 */
139 #define RF_DAGNODE_FLAG_NONE 0x00
140 #define RF_DAGNODE_FLAG_YIELD 0x01 /* in the kernel, yield the processor
141 * before firing this node */
142
143 /* enable - DAG ready for normal execution, no errors encountered
144 * rollForward - DAG encountered an error after commit point, rolling forward
145 * rollBackward - DAG encountered an error prior to commit point, rolling backward
146 */
147 typedef enum RF_DagStatus_e {
148 rf_enable,
149 rf_rollForward,
150 rf_rollBackward
151 } RF_DagStatus_t;
152 #define RF_MAX_HDR_SUCC 1
153
154 #define RF_MAXCHUNKS 10
155
156 struct RF_DagHeader_s {
157 RF_DagStatus_t status; /* status of this DAG */
158 int numSuccedents; /* DAG may be a tree, i.e. may have > 1 root */
159 int numCommitNodes; /* number of commit nodes in graph */
160 int numCommits; /* number of commit nodes which have been
161 * fired */
162 RF_DagNode_t *succedents[RF_MAX_HDR_SUCC]; /* array of succedents,
163 * size numSuccedents */
164 RF_DagHeader_t *next; /* ptr to allow a list of dags */
165 RF_AllocListElem_t *allocList; /* ptr to list of ptrs to be freed
166 * prior to freeing DAG */
167 RF_AccessStripeMapHeader_t *asmList; /* list of access stripe maps
168 * to be freed */
169 int nodeNum; /* used by PrintDAG for debug only */
170 int numNodesCompleted;
171 RF_AccTraceEntry_t *tracerec; /* perf mon only */
172
173 void (*cbFunc) (void *); /* function to call when the dag
174 * completes */
175 void *cbArg; /* argument for cbFunc */
176 char *creator; /* name of function used to create this dag */
177
178 RF_Raid_t *raidPtr; /* the descriptor for the RAID device this DAG
179 * is for */
180 void *bp; /* the bp for this I/O passed down from the
181 * file system. ignored outside kernel */
182
183 RF_ChunkDesc_t *memChunk[RF_MAXCHUNKS]; /* experimental- Chunks of
184 * memory to be retained upon
185 * DAG free for re-use */
186 int chunkIndex; /* the idea is to avoid calls to alloc and
187 * free */
188
189 RF_ChunkDesc_t **xtraMemChunk; /* escape hatch which allows
190 * SelectAlgorithm to merge memChunks
191 * from several dags */
192 int xtraChunkIndex; /* number of ptrs to valid chunks */
193 int xtraChunkCnt; /* number of ptrs to chunks allocated */
194
195 };
196
197 struct RF_DagList_s {
198 /* common info for a list of dags which will be fired sequentially */
199 int numDags; /* number of dags in the list */
200 int numDagsFired; /* number of dags in list which have initiated
201 * execution */
202 int numDagsDone; /* number of dags in list which have completed
203 * execution */
204 RF_DagHeader_t *dags; /* list of dags */
205 RF_RaidAccessDesc_t *desc; /* ptr to descriptor for this access */
206 RF_AccTraceEntry_t tracerec; /* perf mon info for dags (not user
207 * info) */
208 };
209 /* resets a node so that it can be fired again */
210 #define RF_ResetNode(_n_) { \
211 (_n_)->status = rf_wait; \
212 (_n_)->numAntDone = 0; \
213 (_n_)->numSuccFired = 0; \
214 (_n_)->numSuccDone = 0; \
215 (_n_)->next = NULL; \
216 }
217
218 #define RF_ResetDagHeader(_h_) { \
219 (_h_)->numNodesCompleted = 0; \
220 (_h_)->numCommits = 0; \
221 (_h_)->status = rf_enable; \
222 }
223
224 /* convience macro for declaring a create dag function */
225
226 #define RF_CREATE_DAG_FUNC_DECL(_name_) \
227 void _name_ ( \
228 RF_Raid_t *raidPtr, \
229 RF_AccessStripeMap_t *asmap, \
230 RF_DagHeader_t *dag_h, \
231 void *bp, \
232 RF_RaidAccessFlags_t flags, \
233 RF_AllocListElem_t *allocList)
234
235 #endif /* !_RF__RF_DAG_H_ */
236