📄 rf_aselect.c
字号:
/* * Copyright (c) 1995 Carnegie-Mellon University. * All rights reserved. * * Author: Mark Holland, William V. Courtright II * * Permission to use, copy, modify and distribute this software and * its documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie the * rights to redistribute these changes. *//***************************************************************************** * * aselect.c -- algorithm selection code * *****************************************************************************//* * $Locker: $ * $Log: rf_aselect.c,v $ * Revision 1.35 1996/07/28 20:31:39 jimz * i386netbsd port * true/false fixup * * Revision 1.34 1996/07/27 18:39:39 jimz * cleanup sweep * * Revision 1.33 1996/07/22 19:52:16 jimz * switched node params to RF_DagParam_t, a union of * a 64-bit int and a void *, for better portability * attempted hpux port, but failed partway through for * lack of a single C compiler capable of compiling all * source files * * Revision 1.32 1996/06/12 03:29:40 jimz * Note: things that call InitHdrNode should check * for successful return. * * Revision 1.31 1996/06/07 21:33:04 jimz * begin using consistent types for sector numbers, * stripe numbers, row+col numbers, recon unit numbers * * Revision 1.30 1996/06/05 18:06:02 jimz * Major code cleanup. The Great Renaming is now done. * Better modularity. Better typing. Fixed a bunch of * synchronization bugs. Made a lot of global stuff * per-desc or per-array. Removed dead code. * * Revision 1.29 1996/05/31 22:26:54 jimz * fix a lot of mapping problems, memory allocation problems * found some weird lock issues, fixed 'em * more code cleanup * * Revision 1.28 1996/05/30 11:29:41 jimz * Numerous bug fixes. Stripe lock release code disagreed with the taking code * about when stripes should be locked (I made it consistent: no parity, no lock) * There was a lot of extra serialization of I/Os which I've removed- a lot of * it was to calculate values for the cache code, which is no longer with us. * More types, function, macro cleanup. Added code to properly quiesce the array * on shutdown. Made a lot of stuff array-specific which was (bogusly) general * before. Fixed memory allocation, freeing bugs. * * Revision 1.27 1996/05/27 18:56:37 jimz * more code cleanup * better typing * compiles in all 3 environments * * Revision 1.26 1996/05/24 22:17:04 jimz * continue code + namespace cleanup * typed a bunch of flags * * Revision 1.25 1996/05/24 04:28:55 jimz * release cleanup ckpt * * Revision 1.24 1996/05/23 21:46:35 jimz * checkpoint in code cleanup (release prep) * lots of types, function names have been fixed * * Revision 1.23 1996/05/23 00:33:23 jimz * code cleanup: move all debug decls to rf_options.c, all extern * debug decls to rf_options.h, all debug vars preceded by rf_ * * Revision 1.22 1996/05/18 19:51:34 jimz * major code cleanup- fix syntax, make some types consistent, * add prototypes, clean out dead code, et cetera * * Revision 1.21 1996/05/08 21:01:24 jimz * fixed up enum type names that were conflicting with other * enums and function names (ie, "panic") * future naming trends will be towards RF_ and rf_ for * everything raidframe-related * * Revision 1.20 1996/05/03 19:45:35 wvcii * removed includes of old deg creation files * updated SelectAlgorithm comments * * Revision 1.19 1995/12/12 18:10:06 jimz * MIN -> RF_MIN, MAX -> RF_MAX, ASSERT -> RF_ASSERT * fix 80-column brain damage in comments * * Revision 1.18 1995/11/30 16:27:48 wvcii * added copyright info * * Revision 1.17 1995/11/19 16:25:55 wvcii * SelectAlgorithm now creates an array, returned in desc->dagArray * return value is now int (1 = FAIL) * * Revision 1.16 1995/11/17 15:09:58 wvcii * fixed bug in SelectAlgorithm in which multiple graphs per stripe are required * * Revision 1.15 1995/11/07 17:12:42 wvcii * changed SelectAlgorithm as follows: * * dag creation funcs now create term nodes * dag selection funcs no longer return numHdrSucc, numTermAnt * there is now one dag hdr for each dag in a request, implying * that SelectAlgorithm now returns a linked list of dag hdrs * */#include "rf_archs.h"#include "rf_types.h"#include "rf_raid.h"#include "rf_dag.h"#include "rf_dagutils.h"#include "rf_dagfuncs.h"#include "rf_general.h"#include "rf_desc.h"#include "rf_map.h"/****************************************************************************** * * Create and Initialiaze a dag header and termination node * *****************************************************************************/static int InitHdrNode(hdr, raidPtr, memChunkEnable) RF_DagHeader_t **hdr; RF_Raid_t *raidPtr; int memChunkEnable;{ /* create and initialize dag hdr */ *hdr = rf_AllocDAGHeader(); rf_MakeAllocList((*hdr)->allocList); if ((*hdr)->allocList == NULL) { rf_FreeDAGHeader(*hdr); return(ENOMEM); } (*hdr)->status = rf_enable; (*hdr)->numSuccedents = 0; (*hdr)->raidPtr = raidPtr; (*hdr)->next = NULL; return(0);}/****************************************************************************** * * Transfer allocation list and mem chunks from one dag to another * *****************************************************************************/static void TransferDagMemory(daga, dagb) RF_DagHeader_t *daga; RF_DagHeader_t *dagb;{ RF_AccessStripeMapHeader_t *end; RF_AllocListElem_t *p; int i, memChunksXfrd = 0, xtraChunksXfrd = 0; /* transfer allocList from dagb to daga */ for (p = dagb->allocList; p ; p = p->next) { for (i = 0; i < p->numPointers; i++) { rf_AddToAllocList(daga->allocList, p->pointers[i], p->sizes[i]); p->pointers[i] = NULL; p->sizes[i] = 0; } p->numPointers = 0; } /* transfer chunks from dagb to daga */ while ((memChunksXfrd + xtraChunksXfrd < dagb->chunkIndex + dagb->xtraChunkIndex) && (daga->chunkIndex < RF_MAXCHUNKS)) { /* stuff chunks into daga's memChunk array */ if (memChunksXfrd < dagb->chunkIndex) { daga->memChunk[daga->chunkIndex++] = dagb->memChunk[memChunksXfrd]; dagb->memChunk[memChunksXfrd++] = NULL; } else { daga->memChunk[daga->xtraChunkIndex++] = dagb->xtraMemChunk[xtraChunksXfrd]; dagb->xtraMemChunk[xtraChunksXfrd++] = NULL; } } /* use escape hatch to hold excess chunks */ while (memChunksXfrd + xtraChunksXfrd < dagb->chunkIndex + dagb->xtraChunkIndex) { if (memChunksXfrd < dagb->chunkIndex) { daga->xtraMemChunk[daga->xtraChunkIndex++] = dagb->memChunk[memChunksXfrd]; dagb->memChunk[memChunksXfrd++] = NULL; } else { daga->xtraMemChunk[daga->xtraChunkIndex++] = dagb->xtraMemChunk[xtraChunksXfrd]; dagb->xtraMemChunk[xtraChunksXfrd++] = NULL; } } RF_ASSERT((memChunksXfrd == dagb->chunkIndex) && (xtraChunksXfrd == dagb->xtraChunkIndex)); RF_ASSERT(daga->chunkIndex <= RF_MAXCHUNKS); RF_ASSERT(daga->xtraChunkIndex <= daga->xtraChunkCnt); dagb->chunkIndex = 0; dagb->xtraChunkIndex = 0; /* transfer asmList from dagb to daga */ if (dagb->asmList) { if (daga->asmList) { end = daga->asmList; while (end->next) end = end->next; end->next = dagb->asmList; } else daga->asmList = dagb->asmList; dagb->asmList = NULL; }}/***************************************************************************************** * * Ensure that all node->dagHdr fields in a dag are consistent * * IMPORTANT: This routine recursively searches all succedents of the node. If a * succedent is encountered whose dagHdr ptr does not require adjusting, that node's * succedents WILL NOT BE EXAMINED. * ****************************************************************************************/static void UpdateNodeHdrPtr(hdr, node) RF_DagHeader_t *hdr; RF_DagNode_t *node;{ int i; RF_ASSERT(hdr != NULL && node != NULL); for (i = 0; i < node->numSuccedents; i++) if (node->succedents[i]->dagHdr != hdr) UpdateNodeHdrPtr(hdr, node->succedents[i]); node->dagHdr = hdr;}/****************************************************************************** * * Create a DAG to do a read or write operation. * * create an array of dagLists, one list per parity stripe. * return the lists in the array desc->dagArray. * * Normally, each list contains one dag for the entire stripe. In some * tricky cases, we break this into multiple dags, either one per stripe * unit or one per block (sector). When this occurs, these dags are returned * as a linked list (dagList) which is executed sequentially (to preserve * atomic parity updates in the stripe). * * dags which operate on independent parity goups (stripes) are returned in * independent dagLists (distinct elements in desc->dagArray) and may be * executed concurrently. * * Finally, if the SelectionFunc fails to create a dag for a block, we punt * and return 1. * * The above process is performed in two phases: * 1) create an array(s) of creation functions (eg stripeFuncs) * 2) create dags and concatenate/merge to form the final dag. * * Because dag's are basic blocks (single entry, single exit, unconditional * control flow, we can add the following optimizations (future work): * first-pass optimizer to allow max concurrency (need all data dependencies) * second-pass optimizer to eliminate common subexpressions (need true * data dependencies) * third-pass optimizer to eliminate dead code (need true data dependencies) *****************************************************************************/#define MAXNSTRIPES 50int rf_SelectAlgorithm(desc, flags) RF_RaidAccessDesc_t *desc; RF_RaidAccessFlags_t flags;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -