Home | History | Annotate | Line # | Download | only in raidframe
rf_dag.h revision 1.1
      1  1.1  oster /*	$NetBSD: rf_dag.h,v 1.1 1998/11/13 04:20:27 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  *
     36  1.1  oster  * :
     37  1.1  oster  * Log: rf_dag.h,v
     38  1.1  oster  * Revision 1.35  1996/11/05 18:38:37  jimz
     39  1.1  oster  * add patch from galvarez (at) cs.ucsd.edu (Guillermo Alvarez)
     40  1.1  oster  * to fix dag_params memory-sizing problem (should be an array
     41  1.1  oster  * of the type, not an array of pointers to the type)
     42  1.1  oster  *
     43  1.1  oster  * Revision 1.34  1996/07/28  20:31:39  jimz
     44  1.1  oster  * i386netbsd port
     45  1.1  oster  * true/false fixup
     46  1.1  oster  *
     47  1.1  oster  * Revision 1.33  1996/07/22  19:52:16  jimz
     48  1.1  oster  * switched node params to RF_DagParam_t, a union of
     49  1.1  oster  * a 64-bit int and a void *, for better portability
     50  1.1  oster  * attempted hpux port, but failed partway through for
     51  1.1  oster  * lack of a single C compiler capable of compiling all
     52  1.1  oster  * source files
     53  1.1  oster  *
     54  1.1  oster  * Revision 1.32  1996/06/10  22:22:13  wvcii
     55  1.1  oster  * added two node status types for use in backward error
     56  1.1  oster  * recovery experiments.
     57  1.1  oster  *
     58  1.1  oster  * Revision 1.31  1996/06/09  02:36:46  jimz
     59  1.1  oster  * lots of little crufty cleanup- fixup whitespace
     60  1.1  oster  * issues, comment #ifdefs, improve typing in some
     61  1.1  oster  * places (esp size-related)
     62  1.1  oster  *
     63  1.1  oster  * Revision 1.30  1996/06/07  22:49:18  jimz
     64  1.1  oster  * fix up raidPtr typing
     65  1.1  oster  *
     66  1.1  oster  * Revision 1.29  1996/05/27  18:56:37  jimz
     67  1.1  oster  * more code cleanup
     68  1.1  oster  * better typing
     69  1.1  oster  * compiles in all 3 environments
     70  1.1  oster  *
     71  1.1  oster  * Revision 1.28  1996/05/24  22:17:04  jimz
     72  1.1  oster  * continue code + namespace cleanup
     73  1.1  oster  * typed a bunch of flags
     74  1.1  oster  *
     75  1.1  oster  * Revision 1.27  1996/05/24  04:28:55  jimz
     76  1.1  oster  * release cleanup ckpt
     77  1.1  oster  *
     78  1.1  oster  * Revision 1.26  1996/05/23  21:46:35  jimz
     79  1.1  oster  * checkpoint in code cleanup (release prep)
     80  1.1  oster  * lots of types, function names have been fixed
     81  1.1  oster  *
     82  1.1  oster  * Revision 1.25  1996/05/23  00:33:23  jimz
     83  1.1  oster  * code cleanup: move all debug decls to rf_options.c, all extern
     84  1.1  oster  * debug decls to rf_options.h, all debug vars preceded by rf_
     85  1.1  oster  *
     86  1.1  oster  * Revision 1.24  1996/05/18  19:51:34  jimz
     87  1.1  oster  * major code cleanup- fix syntax, make some types consistent,
     88  1.1  oster  * add prototypes, clean out dead code, et cetera
     89  1.1  oster  *
     90  1.1  oster  * Revision 1.23  1996/05/16  23:05:20  jimz
     91  1.1  oster  * Added dag_ptrs field, RF_DAG_PTRCACHESIZE
     92  1.1  oster  *
     93  1.1  oster  * The dag_ptrs field of the node is basically some scribble
     94  1.1  oster  * space to be used here. We could get rid of it, and always
     95  1.1  oster  * allocate the range of pointers, but that's expensive. So,
     96  1.1  oster  * we pick a "common case" size for the pointer cache. Hopefully,
     97  1.1  oster  * we'll find that:
     98  1.1  oster  * (1) Generally, nptrs doesn't exceed RF_DAG_PTRCACHESIZE by
     99  1.1  oster  *     only a little bit (least efficient case)
    100  1.1  oster  * (2) Generally, ntprs isn't a lot less than RF_DAG_PTRCACHESIZE
    101  1.1  oster  *     (wasted memory)
    102  1.1  oster  *
    103  1.1  oster  * Revision 1.22  1996/05/08  21:01:24  jimz
    104  1.1  oster  * fixed up enum type names that were conflicting with other
    105  1.1  oster  * enums and function names (ie, "panic")
    106  1.1  oster  * future naming trends will be towards RF_ and rf_ for
    107  1.1  oster  * everything raidframe-related
    108  1.1  oster  *
    109  1.1  oster  * Revision 1.21  1996/05/08  15:23:47  wvcii
    110  1.1  oster  * added new node states:  undone, recover, panic
    111  1.1  oster  *
    112  1.1  oster  * Revision 1.20  1995/12/01  14:59:19  root
    113  1.1  oster  * increased MAX_ANTECEDENTS from 10 to 20
    114  1.1  oster  * should consider getting rid of this (eliminate static array)
    115  1.1  oster  *
    116  1.1  oster  * Revision 1.19  1995/11/30  15:58:59  wvcii
    117  1.1  oster  * added copyright info
    118  1.1  oster  *
    119  1.1  oster  * Revision 1.18  1995/11/19  16:27:03  wvcii
    120  1.1  oster  * created struct dagList
    121  1.1  oster  *
    122  1.1  oster  * Revision 1.17  1995/11/07  15:43:01  wvcii
    123  1.1  oster  * added static array to DAGnode: antType
    124  1.1  oster  * added commitNode type
    125  1.1  oster  * added commit node counts to dag header
    126  1.1  oster  * added ptr (firstDag) to support multi-dag requests
    127  1.1  oster  * added succedent done/fired counts to nodes to support rollback
    128  1.1  oster  * added node status type "skipped"
    129  1.1  oster  * added hdr status types "rollForward, rollBackward"
    130  1.1  oster  * deleted hdr status type "disable"
    131  1.1  oster  * updated ResetNode & ResetDAGHeader to zero new fields
    132  1.1  oster  *
    133  1.1  oster  */
    134  1.1  oster 
    135  1.1  oster #ifndef _RF__RF_DAG_H_
    136  1.1  oster #define _RF__RF_DAG_H_
    137  1.1  oster 
    138  1.1  oster #include "rf_types.h"
    139  1.1  oster #include "rf_threadstuff.h"
    140  1.1  oster #include "rf_alloclist.h"
    141  1.1  oster #include "rf_stripelocks.h"
    142  1.1  oster #include "rf_layout.h"
    143  1.1  oster #include "rf_dagflags.h"
    144  1.1  oster #include "rf_acctrace.h"
    145  1.1  oster #include "rf_memchunk.h"
    146  1.1  oster 
    147  1.1  oster #define RF_THREAD_CONTEXT   0 /* we were invoked from thread context */
    148  1.1  oster #define RF_INTR_CONTEXT     1 /* we were invoked from interrupt context */
    149  1.1  oster #define RF_MAX_ANTECEDENTS 20 /* max num of antecedents a node may posses */
    150  1.1  oster 
    151  1.1  oster #ifdef KERNEL
    152  1.1  oster #include <sys/buf.h>
    153  1.1  oster #endif /* KERNEL */
    154  1.1  oster 
    155  1.1  oster struct RF_PropHeader_s { /* structure for propagation of results */
    156  1.1  oster   int               resultNum; /* bind result # resultNum */
    157  1.1  oster   int               paramNum;  /* to parameter # paramNum */
    158  1.1  oster   RF_PropHeader_t  *next;      /* linked list for multiple results/params */
    159  1.1  oster };
    160  1.1  oster 
    161  1.1  oster typedef enum RF_NodeStatus_e {
    162  1.1  oster   rf_bwd1,    /* node is ready for undo logging (backward error recovery only) */
    163  1.1  oster   rf_bwd2,    /* node has completed undo logging (backward error recovery only) */
    164  1.1  oster   rf_wait,    /* node is waiting to be executed */
    165  1.1  oster   rf_fired,   /* node is currently executing its do function */
    166  1.1  oster   rf_good,    /* node successfully completed execution of its do function */
    167  1.1  oster   rf_bad,     /* node failed to successfully execute its do function */
    168  1.1  oster   rf_skipped, /* not used anymore, used to imply a node was not executed */
    169  1.1  oster   rf_recover, /* node is currently executing its undo function */
    170  1.1  oster   rf_panic,   /* node failed to successfully execute its undo function */
    171  1.1  oster   rf_undone   /* node successfully executed its undo function */
    172  1.1  oster } RF_NodeStatus_t;
    173  1.1  oster 
    174  1.1  oster /*
    175  1.1  oster  * These were used to control skipping a node.
    176  1.1  oster  * Now, these are only used as comments.
    177  1.1  oster  */
    178  1.1  oster typedef enum RF_AntecedentType_e {
    179  1.1  oster   rf_trueData,
    180  1.1  oster   rf_antiData,
    181  1.1  oster   rf_outputData,
    182  1.1  oster   rf_control
    183  1.1  oster } RF_AntecedentType_t;
    184  1.1  oster 
    185  1.1  oster #define RF_DAG_PTRCACHESIZE   40
    186  1.1  oster #define RF_DAG_PARAMCACHESIZE 12
    187  1.1  oster 
    188  1.1  oster typedef RF_uint8 RF_DagNodeFlags_t;
    189  1.1  oster 
    190  1.1  oster struct RF_DagNode_s {
    191  1.1  oster   RF_NodeStatus_t status;          /* current status of this node */
    192  1.1  oster   int (*doFunc)(RF_DagNode_t *);   /* normal function */
    193  1.1  oster   int (*undoFunc)(RF_DagNode_t *); /* func to remove effect of doFunc */
    194  1.1  oster   int (*wakeFunc)(RF_DagNode_t *, int status);  /* func called when the node completes an I/O */
    195  1.1  oster   int numParams;                /* number of parameters required by *funcPtr */
    196  1.1  oster   int numResults;               /* number of results produced by *funcPtr */
    197  1.1  oster   int numAntecedents;           /* number of antecedents */
    198  1.1  oster   int numAntDone;               /* number of antecedents which have finished */
    199  1.1  oster   int numSuccedents;            /* number of succedents */
    200  1.1  oster   int numSuccFired;             /* incremented when a succedent is fired during forward execution */
    201  1.1  oster   int numSuccDone;              /* incremented when a succedent finishes during rollBackward */
    202  1.1  oster   int commitNode;               /* boolean flag - if true, this is a commit node */
    203  1.1  oster   RF_DagNode_t **succedents;    /* succedents, array size numSuccedents */
    204  1.1  oster   RF_DagNode_t **antecedents;   /* antecedents, array size numAntecedents */
    205  1.1  oster   RF_AntecedentType_t antType[RF_MAX_ANTECEDENTS]; /* type of each antecedent */
    206  1.1  oster   void **results;               /* array of results produced by *funcPtr */
    207  1.1  oster   RF_DagParam_t *params;        /* array of parameters required by *funcPtr */
    208  1.1  oster   RF_PropHeader_t **propList;   /* propagation list, size numSuccedents */
    209  1.1  oster   RF_DagHeader_t *dagHdr;       /* ptr to head of dag containing this node */
    210  1.1  oster   void *dagFuncData;            /* dag execution func uses this for whatever it wants */
    211  1.1  oster   RF_DagNode_t *next;
    212  1.1  oster   int nodeNum;                  /* used by PrintDAG for debug only */
    213  1.1  oster   int visited;                  /* used to avoid re-visiting nodes on DAG walks */
    214  1.1  oster                                 /* ANY CODE THAT USES THIS FIELD MUST MAINTAIN THE PROPERTY
    215  1.1  oster                                  * THAT AFTER IT FINISHES, ALL VISITED FLAGS IN THE DAG ARE IDENTICAL */
    216  1.1  oster   char *name;                   /* debug only */
    217  1.1  oster   RF_DagNodeFlags_t flags;      /* see below */
    218  1.1  oster   RF_DagNode_t  *dag_ptrs[RF_DAG_PTRCACHESIZE];     /* cache for performance */
    219  1.1  oster   RF_DagParam_t  dag_params[RF_DAG_PARAMCACHESIZE]; /* cache for performance */
    220  1.1  oster };
    221  1.1  oster 
    222  1.1  oster /*
    223  1.1  oster  * Bit values for flags field of RF_DagNode_t
    224  1.1  oster  */
    225  1.1  oster #define RF_DAGNODE_FLAG_NONE  0x00
    226  1.1  oster #define RF_DAGNODE_FLAG_YIELD 0x01 /* in the kernel, yield the processor before firing this node */
    227  1.1  oster 
    228  1.1  oster /* enable - DAG ready for normal execution, no errors encountered
    229  1.1  oster  * rollForward - DAG encountered an error after commit point, rolling forward
    230  1.1  oster  * rollBackward - DAG encountered an error prior to commit point, rolling backward
    231  1.1  oster  */
    232  1.1  oster typedef enum RF_DagStatus_e {
    233  1.1  oster   rf_enable,
    234  1.1  oster   rf_rollForward,
    235  1.1  oster   rf_rollBackward
    236  1.1  oster } RF_DagStatus_t;
    237  1.1  oster 
    238  1.1  oster #define RF_MAX_HDR_SUCC 1
    239  1.1  oster 
    240  1.1  oster #define RF_MAXCHUNKS 10
    241  1.1  oster 
    242  1.1  oster struct RF_DagHeader_s {
    243  1.1  oster   RF_DagStatus_t status;               /* status of this DAG */
    244  1.1  oster   int numSuccedents;                   /* DAG may be a tree, i.e. may have > 1 root */
    245  1.1  oster   int numCommitNodes;                  /* number of commit nodes in graph */
    246  1.1  oster   int numCommits;                      /* number of commit nodes which have been fired  */
    247  1.1  oster   RF_DagNode_t *succedents[RF_MAX_HDR_SUCC]; /* array of succedents, size numSuccedents */
    248  1.1  oster   RF_DagHeader_t *next;                /* ptr to allow a list of dags */
    249  1.1  oster   RF_AllocListElem_t *allocList;       /* ptr to list of ptrs to be freed prior to freeing DAG */
    250  1.1  oster   RF_AccessStripeMapHeader_t *asmList; /* list of access stripe maps to be freed */
    251  1.1  oster   int nodeNum;                         /* used by PrintDAG for debug only */
    252  1.1  oster   int numNodesCompleted;
    253  1.1  oster   RF_AccTraceEntry_t *tracerec;        /* perf mon only */
    254  1.1  oster 
    255  1.1  oster   void (*cbFunc)(void *);        /* function to call when the dag completes */
    256  1.1  oster   void *cbArg;                         /* argument for cbFunc */
    257  1.1  oster   char *creator;                       /* name of function used to create this dag */
    258  1.1  oster 
    259  1.1  oster   RF_Raid_t *raidPtr;                  /* the descriptor for the RAID device this DAG is for */
    260  1.1  oster   void *bp;                            /* the bp for this I/O passed down from the file system. ignored outside kernel */
    261  1.1  oster 
    262  1.1  oster   RF_ChunkDesc_t *memChunk[RF_MAXCHUNKS]; /* experimental- Chunks of memory to be retained upon DAG free for re-use */
    263  1.1  oster   int chunkIndex;                      /* the idea is to avoid calls to alloc and free */
    264  1.1  oster 
    265  1.1  oster   RF_ChunkDesc_t **xtraMemChunk;       /* escape hatch which allows SelectAlgorithm to merge memChunks from several dags */
    266  1.1  oster   int xtraChunkIndex;                  /* number of ptrs to valid chunks */
    267  1.1  oster   int xtraChunkCnt;                    /* number of ptrs to chunks allocated */
    268  1.1  oster 
    269  1.1  oster #ifdef SIMULATE
    270  1.1  oster   int done;                            /* Tag to tell if termination node has been fired */
    271  1.1  oster #endif /* SIMULATE */
    272  1.1  oster };
    273  1.1  oster 
    274  1.1  oster struct RF_DagList_s {
    275  1.1  oster   /* common info for a list of dags which will be fired sequentially */
    276  1.1  oster   int numDags;                 /* number of dags in the list */
    277  1.1  oster   int numDagsFired;            /* number of dags in list which have initiated execution */
    278  1.1  oster   int numDagsDone;             /* number of dags in list which have completed execution */
    279  1.1  oster   RF_DagHeader_t *dags;        /* list of dags */
    280  1.1  oster   RF_RaidAccessDesc_t *desc;   /* ptr to descriptor for this access */
    281  1.1  oster   RF_AccTraceEntry_t tracerec; /* perf mon info for dags (not user info) */
    282  1.1  oster };
    283  1.1  oster 
    284  1.1  oster /* resets a node so that it can be fired again */
    285  1.1  oster #define RF_ResetNode(_n_)  { \
    286  1.1  oster   (_n_)->status = rf_wait;   \
    287  1.1  oster   (_n_)->numAntDone = 0;     \
    288  1.1  oster   (_n_)->numSuccFired = 0;   \
    289  1.1  oster   (_n_)->numSuccDone = 0;    \
    290  1.1  oster   (_n_)->next = NULL;        \
    291  1.1  oster }
    292  1.1  oster 
    293  1.1  oster #ifdef SIMULATE
    294  1.1  oster #define RF_ResetDagHeader(_h_) { \
    295  1.1  oster   (_h_)->done = RF_FALSE;           \
    296  1.1  oster   (_h_)->numNodesCompleted = 0;  \
    297  1.1  oster   (_h_)->numCommits = 0;         \
    298  1.1  oster   (_h_)->status = rf_enable;     \
    299  1.1  oster }
    300  1.1  oster #else /* SIMULATE */
    301  1.1  oster #define RF_ResetDagHeader(_h_) { \
    302  1.1  oster   (_h_)->numNodesCompleted = 0;  \
    303  1.1  oster   (_h_)->numCommits = 0;         \
    304  1.1  oster   (_h_)->status = rf_enable;     \
    305  1.1  oster }
    306  1.1  oster #endif /* SIMULATE */
    307  1.1  oster 
    308  1.1  oster /* convience macro for declaring a create dag function */
    309  1.1  oster 
    310  1.1  oster #define RF_CREATE_DAG_FUNC_DECL(_name_) \
    311  1.1  oster void _name_ ( \
    312  1.1  oster 	RF_Raid_t             *raidPtr, \
    313  1.1  oster 	RF_AccessStripeMap_t  *asmap, \
    314  1.1  oster 	RF_DagHeader_t        *dag_h, \
    315  1.1  oster 	void                  *bp, \
    316  1.1  oster 	RF_RaidAccessFlags_t   flags, \
    317  1.1  oster 	RF_AllocListElem_t    *allocList)
    318  1.1  oster 
    319  1.1  oster #endif /* !_RF__RF_DAG_H_ */
    320