⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rf_dagfuncs.c

📁 RAIDFrame是个非常好的磁盘阵列RAID仿真工具
💻 C
📖 第 1 页 / 共 3 页
字号:
  RF_Etimer_t timer;  int i, retcode;  RF_PhysDiskAddr_t *pda;  caddr_t undoBuf;  retcode = 0;  if (node->dagHdr->status == rf_enable) {    /* don't do the XOR if the input is the same as the output */    RF_ETIMER_START(timer);    for (i=0; i<node->numParams-1; i+=2) if (node->params[i+1].p != node->results[0]) {#if RF_BACKWARD > 0      /* This section mimics undo logging for backward error recovery experiments b       * allocating and initializing a buffer       * XXX 512 byte sector size is hard coded!       */      pda = node->params[i].p;      if (node->dagHdr->allocList == NULL)	rf_MakeAllocList(node->dagHdr->allocList);      RF_CallocAndAdd(undoBuf, 1, 512 * pda->numSector, (caddr_t), node->dagHdr->allocList);#endif /* RF_BACKWARD > 0 */      retcode = rf_XorIntoBuffer(raidPtr, (RF_PhysDiskAddr_t *) node->params[i].p,			      (char *)node->params[i+1].p, (char *) node->results[0], node->dagHdr->bp);    }    RF_ETIMER_STOP(timer); RF_ETIMER_EVAL(timer); tracerec->xor_us += RF_ETIMER_VAL_US(timer);  }  return(rf_GenericWakeupFunc(node, retcode));     /* call wake func explicitly since no I/O in this node */}/* xor the inputs into the result buffer, ignoring placement issues */int rf_SimpleXorFunc(node)  RF_DagNode_t  *node;{  RF_Raid_t *raidPtr = (RF_Raid_t *)node->params[node->numParams-1].p;  int i, retcode = 0;  RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec;  RF_Etimer_t timer;  RF_PhysDiskAddr_t *pda;  caddr_t undoBuf;  if (node->dagHdr->status == rf_enable) {    RF_ETIMER_START(timer);    /* don't do the XOR if the input is the same as the output */    for (i=0; i<node->numParams-1; i+=2) if (node->params[i+1].p != node->results[0]) {#if RF_BACKWARD > 0      /* This section mimics undo logging for backward error recovery experiments b       * allocating and initializing a buffer       * XXX 512 byte sector size is hard coded!       */      pda = node->params[i].p;      if (node->dagHdr->allocList == NULL)	rf_MakeAllocList(node->dagHdr->allocList);      RF_CallocAndAdd(undoBuf, 1, 512 * pda->numSector, (caddr_t), node->dagHdr->allocList);#endif /* RF_BACKWARD > 0 */      retcode = rf_bxor((char *)node->params[i+1].p, (char *) node->results[0], 		     rf_RaidAddressToByte(raidPtr, ((RF_PhysDiskAddr_t *)node->params[i].p)->numSector),		     (struct buf *) node->dagHdr->bp);    }    RF_ETIMER_STOP(timer); RF_ETIMER_EVAL(timer); tracerec->xor_us += RF_ETIMER_VAL_US(timer);  }  return(rf_GenericWakeupFunc(node, retcode));     /* call wake func explicitly since no I/O in this node */}/* this xor is used by the degraded-mode dag functions to recover lost data. * the second-to-last parameter is the PDA for the failed portion of the access. * the code here looks at this PDA and assumes that the xor target buffer is * equal in size to the number of sectors in the failed PDA.  It then uses * the other PDAs in the parameter list to determine where within the target * buffer the corresponding data should be xored. */int rf_RecoveryXorFunc(node)  RF_DagNode_t  *node;{  RF_Raid_t *raidPtr = (RF_Raid_t *)node->params[node->numParams-1].p;  RF_RaidLayout_t *layoutPtr = (RF_RaidLayout_t *) &raidPtr->Layout;  RF_PhysDiskAddr_t *failedPDA = (RF_PhysDiskAddr_t *)node->params[node->numParams-2].p;  int i, retcode = 0;  RF_PhysDiskAddr_t *pda;  int suoffset, failedSUOffset = rf_StripeUnitOffset(layoutPtr,failedPDA->startSector);  char *srcbuf, *destbuf;  RF_AccTraceEntry_t *tracerec = node->dagHdr->tracerec;  RF_Etimer_t timer;  caddr_t undoBuf;  if (node->dagHdr->status == rf_enable) {    RF_ETIMER_START(timer);    for (i=0; i<node->numParams-2; i+=2) if (node->params[i+1].p != node->results[0]) {      pda = (RF_PhysDiskAddr_t *)node->params[i].p;#if RF_BACKWARD > 0      /* This section mimics undo logging for backward error recovery experiments b       * allocating and initializing a buffer       * XXX 512 byte sector size is hard coded!       */      if (node->dagHdr->allocList == NULL)	rf_MakeAllocList(node->dagHdr->allocList);      RF_CallocAndAdd(undoBuf, 1, 512 * pda->numSector, (caddr_t), node->dagHdr->allocList);#endif /* RF_BACKWARD > 0 */      srcbuf = (char *)node->params[i+1].p;      suoffset = rf_StripeUnitOffset(layoutPtr, pda->startSector);      destbuf = ((char *) node->results[0]) + rf_RaidAddressToByte(raidPtr,suoffset-failedSUOffset);      retcode = rf_bxor(srcbuf, destbuf, rf_RaidAddressToByte(raidPtr, pda->numSector), node->dagHdr->bp);    }    RF_ETIMER_STOP(timer); RF_ETIMER_EVAL(timer); tracerec->xor_us += RF_ETIMER_VAL_US(timer);  }  return (rf_GenericWakeupFunc(node, retcode));}/***************************************************************************************** * The next three functions are utilities used by the above xor-execution functions. ****************************************************************************************//* * this is just a glorified buffer xor.  targbuf points to a buffer that is one full stripe unit * in size.  srcbuf points to a buffer that may be less than 1 SU, but never more.  When the * access described by pda is one SU in size (which by implication means it's SU-aligned), * all that happens is (targbuf) <- (srcbuf ^ targbuf).  When the access is less than one * SU in size the XOR occurs on only the portion of targbuf identified in the pda. */int rf_XorIntoBuffer(raidPtr, pda, srcbuf, targbuf, bp)  RF_Raid_t          *raidPtr;  RF_PhysDiskAddr_t  *pda;  char               *srcbuf;  char               *targbuf;  void               *bp;{  char *targptr;  int sectPerSU = raidPtr->Layout.sectorsPerStripeUnit;  int SUOffset = pda->startSector % sectPerSU;  int length, retcode = 0;  RF_ASSERT(pda->numSector <= sectPerSU);    targptr = targbuf + rf_RaidAddressToByte(raidPtr, SUOffset);  length  = rf_RaidAddressToByte(raidPtr, pda->numSector);  retcode = rf_bxor(srcbuf, targptr, length, bp);  return(retcode);}/* it really should be the case that the buffer pointers (returned by malloc) * are aligned to the natural word size of the machine, so this is the only * case we optimize for.  The length should always be a multiple of the sector * size, so there should be no problem with leftover bytes at the end. */int rf_bxor(src, dest, len, bp)  char  *src;  char  *dest;  int    len;  void  *bp;{  unsigned mask = sizeof(long) -1, retcode = 0;    if ( !(((unsigned long) src) & mask) && !(((unsigned long) dest) & mask) && !(len&mask) ) {    retcode = rf_longword_bxor((unsigned long *) src, (unsigned long *) dest, len>>RF_LONGSHIFT, bp);  } else {    RF_ASSERT(0);  }  return(retcode);}/* map a user buffer into kernel space, if necessary */#ifdef KERNEL#define REMAP_VA(_bp,x,y) (y) = (unsigned long *) ((IS_SYS_VA(x)) ? (unsigned long *)(x) : (unsigned long *) rf_MapToKernelSpace((struct buf *) (_bp), (caddr_t)(x)))#else /* KERNEL */#define REMAP_VA(_bp,x,y) (y) = (x)#endif /* KERNEL *//* When XORing in kernel mode, we need to map each user page to kernel space before we can access it. * We don't want to assume anything about which input buffers are in kernel/user * space, nor about their alignment, so in each loop we compute the maximum number * of bytes that we can xor without crossing any page boundaries, and do only this many * bytes before the next remap. */int rf_longword_bxor(src, dest, len, bp)  register unsigned long  *src;  register unsigned long  *dest;  int                      len; /* longwords */  void                    *bp;{  register unsigned long *end = src+len;  register unsigned long d0, d1, d2, d3, s0, s1, s2, s3;   /* temps */  register unsigned long *pg_src, *pg_dest;                /* per-page source/dest pointers */  int longs_this_time;                                     /* # longwords to xor in the current iteration */  REMAP_VA(bp, src, pg_src);  REMAP_VA(bp, dest, pg_dest);  if (!pg_src || !pg_dest) return(EFAULT);    while (len >= 4 ) {    longs_this_time = RF_MIN(len, RF_MIN(RF_BLIP(pg_src), RF_BLIP(pg_dest)) >> RF_LONGSHIFT);  /* note len in longwords */    src += longs_this_time; dest+= longs_this_time; len -= longs_this_time;    while (longs_this_time >= 4) {      d0 = pg_dest[0];      d1 = pg_dest[1];      d2 = pg_dest[2];      d3 = pg_dest[3];      s0 = pg_src[0];      s1 = pg_src[1];      s2 = pg_src[2];      s3 = pg_src[3];      pg_dest[0] = d0 ^ s0;      pg_dest[1] = d1 ^ s1;      pg_dest[2] = d2 ^ s2;      pg_dest[3] = d3 ^ s3;      pg_src += 4;      pg_dest += 4;      longs_this_time -= 4;    }    while (longs_this_time > 0) {   /* cannot cross any page boundaries here */      *pg_dest++ ^= *pg_src++;      longs_this_time--;    }        /* either we're done, or we've reached a page boundary on one (or possibly both) of the pointers */    if (len) {      if (RF_PAGE_ALIGNED(src))  REMAP_VA(bp, src, pg_src);      if (RF_PAGE_ALIGNED(dest)) REMAP_VA(bp, dest, pg_dest);      if (!pg_src || !pg_dest) return(EFAULT);    }  }  while (src < end) {    *pg_dest++ ^=  *pg_src++;    src++; dest++; len--;    if (RF_PAGE_ALIGNED(src)) REMAP_VA(bp, src, pg_src);    if (RF_PAGE_ALIGNED(dest)) REMAP_VA(bp, dest, pg_dest);  }  RF_ASSERT(len == 0);  return(0);}/*   dst = a ^ b ^ c;   a may equal dst   see comment above longword_bxor*/int rf_longword_bxor3(dst,a,b,c,len, bp)  register unsigned long  *dst;  register unsigned long  *a;  register unsigned long  *b;  register unsigned long  *c;  int                      len; /* length in longwords */  void                    *bp;{  unsigned long a0,a1,a2,a3, b0,b1,b2,b3;  register unsigned long *pg_a, *pg_b, *pg_c, *pg_dst;    /* per-page source/dest pointers */  int longs_this_time;                                     /* # longs to xor in the current iteration */  char dst_is_a = 0;  REMAP_VA(bp, a, pg_a);  REMAP_VA(bp, b, pg_b);  REMAP_VA(bp, c, pg_c);  if (a == dst) {pg_dst = pg_a; dst_is_a = 1;} else { REMAP_VA(bp, dst, pg_dst); }    /* align dest to cache line.  Can't cross a pg boundary on dst here. */  while ((((unsigned long) pg_dst) & 0x1f)) {    *pg_dst++ = *pg_a++ ^ *pg_b++ ^ *pg_c++;    dst++; a++; b++; c++;    if (RF_PAGE_ALIGNED(a)) {REMAP_VA(bp, a, pg_a); if (!pg_a) return(EFAULT);}    if (RF_PAGE_ALIGNED(b)) {REMAP_VA(bp, a, pg_b); if (!pg_b) return(EFAULT);}    if (RF_PAGE_ALIGNED(c)) {REMAP_VA(bp, a, pg_c); if (!pg_c) return(EFAULT);}    len--;  }    while (len > 4 ) {    longs_this_time = RF_MIN(len, RF_MIN(RF_BLIP(a), RF_MIN(RF_BLIP(b), RF_MIN(RF_BLIP(c), RF_BLIP(dst)))) >> RF_LONGSHIFT);    a+= longs_this_time; b+= longs_this_time; c+= longs_this_time; dst+=longs_this_time; len-=longs_this_time;    while (longs_this_time >= 4) {      a0 = pg_a[0]; longs_this_time -= 4;            a1 = pg_a[1];      a2 = pg_a[2];            a3 = pg_a[3];  pg_a += 4;            b0 = pg_b[0];      b1 = pg_b[1];            b2 = pg_b[2];      b3 = pg_b[3];      /* start dual issue */      a0 ^= b0; b0 =  pg_c[0];            pg_b += 4;  a1 ^= b1;            a2 ^= b2; a3 ^= b3;            b1 =  pg_c[1]; a0 ^= b0;            b2 =  pg_c[2]; a1 ^= b1;            b3 =  pg_c[3]; a2 ^= b2;            pg_dst[0] = a0; a3 ^= b3;      pg_dst[1] = a1; pg_c += 4;      pg_dst[2] = a2;      pg_dst[3] = a3; pg_dst += 4;    }    while (longs_this_time > 0) {   /* cannot cross any page boundaries here */      *pg_dst++ = *pg_a++ ^ *pg_b++ ^ *pg_c++;      longs_this_time--;    }        if (len) {      if (RF_PAGE_ALIGNED(a)) {REMAP_VA(bp, a, pg_a); if (!pg_a) return(EFAULT); if (dst_is_a) pg_dst = pg_a;}      if (RF_PAGE_ALIGNED(b)) {REMAP_VA(bp, b, pg_b); if (!pg_b) return(EFAULT);}      if (RF_PAGE_ALIGNED(c)) {REMAP_VA(bp, c, pg_c); if (!pg_c) return(EFAULT);}      if (!dst_is_a) if (RF_PAGE_ALIGNED(dst)) {REMAP_VA(bp, dst, pg_dst); if (!pg_dst) return(EFAULT);}    }  }  while (len) {    *pg_dst++ = *pg_a++ ^ *pg_b++ ^ *pg_c++;    dst++; a++; b++; c++;    if (RF_PAGE_ALIGNED(a)) {REMAP_VA(bp, a, pg_a); if (!pg_a) return(EFAULT); if (dst_is_a) pg_dst = pg_a;}    if (RF_PAGE_ALIGNED(b)) {REMAP_VA(bp, b, pg_b); if (!pg_b) return(EFAULT);}    if (RF_PAGE_ALIGNED(c)) {REMAP_VA(bp, c, pg_c); if (!pg_c) return(EFAULT);}    if (!dst_is_a) if (RF_PAGE_ALIGNED(dst)) {REMAP_VA(bp, dst, pg_dst); if (!pg_dst) return(EFAULT);}    len--;  }  return(0);}int rf_bxor3(dst,a,b,c,len, bp)  register unsigned char  *dst;  register unsigned char  *a;  register unsigned char  *b;  register unsigned char  *c;  unsigned long            len;  void                    *bp;{	RF_ASSERT(((RF_UL(dst)|RF_UL(a)|RF_UL(b)|RF_UL(c)|len) & 0x7) == 0);	return(rf_longword_bxor3((unsigned long *)dst, (unsigned long *)a,		(unsigned long *)b, (unsigned long *)c, len>>RF_LONGSHIFT, bp));}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -