Home | History | Annotate | Line # | Download | only in raidframe
rf_diskqueue.h revision 1.6
      1  1.6  oster /*	$NetBSD: rf_diskqueue.h,v 1.6 2001/10/04 15:58:53 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: 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  * rf_diskqueue.h -- header file for disk queues
     32  1.1  oster  *
     33  1.1  oster  * see comments in rf_diskqueue.c
     34  1.1  oster  *
     35  1.1  oster  ****************************************************************************************/
     36  1.1  oster 
     37  1.1  oster 
     38  1.1  oster #ifndef _RF__RF_DISKQUEUE_H_
     39  1.1  oster #define _RF__RF_DISKQUEUE_H_
     40  1.1  oster 
     41  1.6  oster #include <dev/raidframe/raidframevar.h>
     42  1.6  oster 
     43  1.1  oster #include "rf_threadstuff.h"
     44  1.1  oster #include "rf_acctrace.h"
     45  1.1  oster #include "rf_alloclist.h"
     46  1.1  oster #include "rf_etimer.h"
     47  1.1  oster 
     48  1.1  oster 
     49  1.1  oster #include "rf_netbsd.h"
     50  1.1  oster 
     51  1.1  oster 
     52  1.1  oster #define RF_IO_NORMAL_PRIORITY 1
     53  1.1  oster #define RF_IO_LOW_PRIORITY    0
     54  1.1  oster 
     55  1.1  oster /* the data held by a disk queue entry */
     56  1.1  oster struct RF_DiskQueueData_s {
     57  1.3  oster 	RF_SectorNum_t sectorOffset;	/* sector offset into the disk */
     58  1.3  oster 	RF_SectorCount_t numSector;	/* number of sectors to read/write */
     59  1.3  oster 	RF_IoType_t type;	/* read/write/nop */
     60  1.3  oster 	caddr_t buf;		/* buffer pointer */
     61  1.3  oster 	RF_StripeNum_t parityStripeID;	/* the RAID parity stripe ID this
     62  1.3  oster 					 * access is for */
     63  1.3  oster 	RF_ReconUnitNum_t which_ru;	/* which RU within this parity stripe */
     64  1.3  oster 	int     priority;	/* the priority of this request */
     65  1.3  oster 	int     (*CompleteFunc) (void *, int);	/* function to be called upon
     66  1.3  oster 						 * completion */
     67  1.3  oster 	int     (*AuxFunc) (void *,...);	/* function called upon
     68  1.3  oster 						 * completion of the first I/O
     69  1.3  oster 						 * of a Read_Op_Write pair */
     70  1.3  oster 	void   *argument;	/* argument to be passed to CompleteFunc */
     71  1.4  oster 	RF_Raid_t *raidPtr;	/* needed for simulation */
     72  1.3  oster 	RF_AccTraceEntry_t *tracerec;	/* perf mon only */
     73  1.3  oster 	RF_Etimer_t qtime;	/* perf mon only - time request is in queue */
     74  1.3  oster 	long    entryTime;
     75  1.3  oster 	RF_DiskQueueData_t *next;
     76  1.3  oster 	RF_DiskQueueData_t *prev;
     77  1.3  oster 	caddr_t buf2;		/* for read-op-write */
     78  1.3  oster 	dev_t   dev;		/* the device number for in-kernel version */
     79  1.3  oster 	RF_DiskQueue_t *queue;	/* the disk queue to which this req is
     80  1.3  oster 				 * targeted */
     81  1.3  oster 	RF_DiskQueueDataFlags_t flags;	/* flags controlling operation */
     82  1.3  oster 
     83  1.3  oster 	struct proc *b_proc;	/* the b_proc from the original bp passed into
     84  1.3  oster 				 * the driver for this I/O */
     85  1.3  oster 	struct buf *bp;		/* a bp to use to get this I/O done */
     86  1.1  oster };
     87  1.1  oster #define RF_LOCK_DISK_QUEUE   0x01
     88  1.1  oster #define RF_UNLOCK_DISK_QUEUE 0x02
     89  1.1  oster 
     90  1.1  oster /* note: "Create" returns type-specific queue header pointer cast to (void *) */
     91  1.1  oster struct RF_DiskQueueSW_s {
     92  1.3  oster 	RF_DiskQueueType_t queueType;
     93  1.3  oster 	void   *(*Create) (RF_SectorCount_t, RF_AllocListElem_t *, RF_ShutdownList_t **);	/* creation routine --
     94  1.3  oster 												 * one call per queue in
     95  1.3  oster 												 * system */
     96  1.3  oster 	void    (*Enqueue) (void *, RF_DiskQueueData_t *, int);	/* enqueue routine */
     97  1.3  oster 	RF_DiskQueueData_t *(*Dequeue) (void *);	/* dequeue routine */
     98  1.3  oster 	RF_DiskQueueData_t *(*Peek) (void *);	/* peek at head of queue */
     99  1.3  oster 
    100  1.3  oster 	/* the rest are optional:  they improve performance, but the driver
    101  1.3  oster 	 * will deal with it if they don't exist */
    102  1.3  oster 	int     (*Promote) (void *, RF_StripeNum_t, RF_ReconUnitNum_t);	/* promotes priority of
    103  1.3  oster 									 * tagged accesses */
    104  1.1  oster };
    105  1.1  oster 
    106  1.1  oster struct RF_DiskQueue_s {
    107  1.3  oster 	RF_DiskQueueSW_t *qPtr;	/* access point to queue functions */
    108  1.3  oster 	void   *qHdr;		/* queue header, of whatever type */
    109  1.3  oster 	        RF_DECLARE_MUTEX(mutex)	/* mutex locking data structures */
    110  1.3  oster 	        RF_DECLARE_COND(cond)	/* condition variable for
    111  1.3  oster 					 * synchronization */
    112  1.3  oster 	long    numOutstanding;	/* number of I/Os currently outstanding on
    113  1.3  oster 				 * disk */
    114  1.3  oster 	long    maxOutstanding;	/* max # of I/Os that can be outstanding on a
    115  1.3  oster 				 * disk (in-kernel only) */
    116  1.3  oster 	int     curPriority;	/* the priority of accs all that are currently
    117  1.3  oster 				 * outstanding */
    118  1.3  oster 	long    queueLength;	/* number of requests in queue */
    119  1.3  oster 	RF_DiskQueueData_t *nextLockingOp;	/* a locking op that has
    120  1.3  oster 						 * arrived at the head of the
    121  1.3  oster 						 * queue & is waiting for
    122  1.3  oster 						 * drainage */
    123  1.3  oster 	RF_DiskQueueData_t *unlockingOp;	/* used at user level to
    124  1.3  oster 						 * communicate unlocking op
    125  1.3  oster 						 * b/w user (or dag exec) &
    126  1.3  oster 						 * disk threads */
    127  1.3  oster 	int     numWaiting;	/* number of threads waiting on this variable.
    128  1.3  oster 				 * user-level only */
    129  1.3  oster 	RF_DiskQueueFlags_t flags;	/* terminate, locked */
    130  1.3  oster 	RF_Raid_t *raidPtr;	/* associated array */
    131  1.3  oster 	dev_t   dev;		/* device number for kernel version */
    132  1.3  oster 	RF_SectorNum_t last_deq_sector;	/* last sector number dequeued or
    133  1.3  oster 					 * dispatched */
    134  1.3  oster 	int     row, col;	/* debug only */
    135  1.3  oster 	struct raidcinfo *rf_cinfo;	/* disks component info.. */
    136  1.1  oster };
    137  1.3  oster #define RF_DQ_LOCKED  0x02	/* no new accs allowed until queue is
    138  1.3  oster 				 * explicitly unlocked */
    139  1.1  oster 
    140  1.1  oster /* macros setting & returning information about queues and requests */
    141  1.1  oster #define RF_QUEUE_LOCKED(_q)                 ((_q)->flags & RF_DQ_LOCKED)
    142  1.1  oster #define RF_QUEUE_EMPTY(_q)                  (((_q)->numOutstanding == 0) && ((_q)->nextLockingOp == NULL) && !RF_QUEUE_LOCKED(_q))
    143  1.1  oster #define RF_QUEUE_FULL(_q)                   ((_q)->numOutstanding == (_q)->maxOutstanding)
    144  1.1  oster 
    145  1.1  oster #define RF_LOCK_QUEUE(_q)                   (_q)->flags |= RF_DQ_LOCKED
    146  1.1  oster #define RF_UNLOCK_QUEUE(_q)                 (_q)->flags &= ~RF_DQ_LOCKED
    147  1.1  oster 
    148  1.1  oster #define RF_LOCK_QUEUE_MUTEX(_q_,_wh_)   RF_LOCK_MUTEX((_q_)->mutex)
    149  1.1  oster #define RF_UNLOCK_QUEUE_MUTEX(_q_,_wh_) RF_UNLOCK_MUTEX((_q_)->mutex)
    150  1.1  oster 
    151  1.1  oster #define RF_LOCKING_REQ(_r)                  ((_r)->flags & RF_LOCK_DISK_QUEUE)
    152  1.1  oster #define RF_UNLOCKING_REQ(_r)                ((_r)->flags & RF_UNLOCK_DISK_QUEUE)
    153  1.1  oster 
    154  1.1  oster /* whether it is ok to dispatch a regular request */
    155  1.1  oster #define RF_OK_TO_DISPATCH(_q_,_r_) \
    156  1.1  oster   (RF_QUEUE_EMPTY(_q_) || \
    157  1.1  oster     (!RF_QUEUE_FULL(_q_) && ((_r_)->priority >= (_q_)->curPriority)))
    158  1.1  oster 
    159  1.3  oster int     rf_ConfigureDiskQueueSystem(RF_ShutdownList_t ** listp);
    160  1.1  oster 
    161  1.3  oster void    rf_TerminateDiskQueues(RF_Raid_t * raidPtr);
    162  1.1  oster 
    163  1.3  oster int
    164  1.3  oster rf_ConfigureDiskQueues(RF_ShutdownList_t ** listp, RF_Raid_t * raidPtr,
    165  1.3  oster     RF_Config_t * cfgPtr);
    166  1.1  oster 
    167  1.3  oster void    rf_DiskIOEnqueue(RF_DiskQueue_t * queue, RF_DiskQueueData_t * req, int pri);
    168  1.1  oster 
    169  1.2  oster 
    170  1.3  oster void    rf_DiskIOComplete(RF_DiskQueue_t * queue, RF_DiskQueueData_t * req, int status);
    171  1.1  oster 
    172  1.3  oster int
    173  1.3  oster rf_DiskIOPromote(RF_DiskQueue_t * queue, RF_StripeNum_t parityStripeID,
    174  1.3  oster     RF_ReconUnitNum_t which_ru);
    175  1.1  oster 
    176  1.3  oster RF_DiskQueueData_t *
    177  1.5  oster rf_CreateDiskQueueData(RF_IoType_t typ, RF_SectorNum_t ssect,
    178  1.5  oster 		       RF_SectorCount_t nsect, caddr_t buf,
    179  1.5  oster 		       RF_StripeNum_t parityStripeID,
    180  1.5  oster 		       RF_ReconUnitNum_t which_ru,
    181  1.5  oster 		       int (*wakeF) (void *, int),
    182  1.5  oster 		       void *arg, RF_DiskQueueData_t * next,
    183  1.5  oster 		       RF_AccTraceEntry_t * tracerec,
    184  1.5  oster 		       void *raidPtr, RF_DiskQueueDataFlags_t flags,
    185  1.5  oster 		       void *kb_proc);
    186  1.1  oster 
    187  1.5  oster RF_DiskQueueData_t *
    188  1.5  oster rf_CreateDiskQueueDataFull(RF_IoType_t typ, RF_SectorNum_t ssect,
    189  1.5  oster 			   RF_SectorCount_t nsect, caddr_t buf,
    190  1.5  oster 			   RF_StripeNum_t parityStripeID,
    191  1.5  oster 			   RF_ReconUnitNum_t which_ru,
    192  1.5  oster 			   int (*wakeF) (void *, int),
    193  1.5  oster 			   void *arg, RF_DiskQueueData_t * next,
    194  1.5  oster 			   RF_AccTraceEntry_t * tracerec,
    195  1.5  oster 			   int priority, int (*AuxFunc) (void *,...),
    196  1.5  oster 			   caddr_t buf2, void *raidPtr,
    197  1.5  oster 			   RF_DiskQueueDataFlags_t flags, void *kb_proc);
    198  1.5  oster 
    199  1.5  oster void
    200  1.5  oster rf_FreeDiskQueueData(RF_DiskQueueData_t * p);
    201  1.5  oster 
    202  1.5  oster int
    203  1.5  oster rf_ConfigureDiskQueue(RF_Raid_t *, RF_DiskQueue_t *, RF_RowCol_t,
    204  1.5  oster 		      RF_RowCol_t, RF_DiskQueueSW_t *,
    205  1.5  oster 		      RF_SectorCount_t, dev_t, int,
    206  1.5  oster 		      RF_ShutdownList_t **,
    207  1.5  oster 		      RF_AllocListElem_t *);
    208  1.1  oster 
    209  1.3  oster #endif				/* !_RF__RF_DISKQUEUE_H_ */
    210