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