Home | History | Annotate | Line # | Download | only in raidframe
rf_diskqueue.h revision 1.1
      1  1.1  oster /*	$NetBSD: rf_diskqueue.h,v 1.1 1998/11/13 04:20:29 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  * :
     39  1.1  oster  *
     40  1.1  oster  * Log: rf_diskqueue.h,v
     41  1.1  oster  * Revision 1.31  1996/08/07 21:08:49  jimz
     42  1.1  oster  * b_proc -> kb_proc (IRIX complained)
     43  1.1  oster  *
     44  1.1  oster  * Revision 1.30  1996/06/18  20:53:11  jimz
     45  1.1  oster  * fix up disk queueing (remove configure routine,
     46  1.1  oster  * add shutdown list arg to create routines)
     47  1.1  oster  *
     48  1.1  oster  * Revision 1.29  1996/06/13  20:38:19  jimz
     49  1.1  oster  * fix queue type in DiskQueueData
     50  1.1  oster  *
     51  1.1  oster  * Revision 1.28  1996/06/10  11:55:47  jimz
     52  1.1  oster  * Straightened out some per-array/not-per-array distinctions, fixed
     53  1.1  oster  * a couple bugs related to confusion. Added shutdown lists. Removed
     54  1.1  oster  * layout shutdown function (now subsumed by shutdown lists).
     55  1.1  oster  *
     56  1.1  oster  * Revision 1.27  1996/06/07  22:26:27  jimz
     57  1.1  oster  * type-ify which_ru (RF_ReconUnitNum_t)
     58  1.1  oster  *
     59  1.1  oster  * Revision 1.26  1996/06/07  21:33:04  jimz
     60  1.1  oster  * begin using consistent types for sector numbers,
     61  1.1  oster  * stripe numbers, row+col numbers, recon unit numbers
     62  1.1  oster  *
     63  1.1  oster  * Revision 1.25  1996/06/06  17:29:12  jimz
     64  1.1  oster  * track arm position of last I/O dequeued
     65  1.1  oster  *
     66  1.1  oster  * Revision 1.24  1996/06/05  18:06:02  jimz
     67  1.1  oster  * Major code cleanup. The Great Renaming is now done.
     68  1.1  oster  * Better modularity. Better typing. Fixed a bunch of
     69  1.1  oster  * synchronization bugs. Made a lot of global stuff
     70  1.1  oster  * per-desc or per-array. Removed dead code.
     71  1.1  oster  *
     72  1.1  oster  * Revision 1.23  1996/06/02  17:31:48  jimz
     73  1.1  oster  * Moved a lot of global stuff into array structure, where it belongs.
     74  1.1  oster  * Fixed up paritylogging, pss modules in this manner. Some general
     75  1.1  oster  * code cleanup. Removed lots of dead code, some dead files.
     76  1.1  oster  *
     77  1.1  oster  * Revision 1.22  1996/05/30  23:22:16  jimz
     78  1.1  oster  * bugfixes of serialization, timing problems
     79  1.1  oster  * more cleanup
     80  1.1  oster  *
     81  1.1  oster  * Revision 1.21  1996/05/30  11:29:41  jimz
     82  1.1  oster  * Numerous bug fixes. Stripe lock release code disagreed with the taking code
     83  1.1  oster  * about when stripes should be locked (I made it consistent: no parity, no lock)
     84  1.1  oster  * There was a lot of extra serialization of I/Os which I've removed- a lot of
     85  1.1  oster  * it was to calculate values for the cache code, which is no longer with us.
     86  1.1  oster  * More types, function, macro cleanup. Added code to properly quiesce the array
     87  1.1  oster  * on shutdown. Made a lot of stuff array-specific which was (bogusly) general
     88  1.1  oster  * before. Fixed memory allocation, freeing bugs.
     89  1.1  oster  *
     90  1.1  oster  * Revision 1.20  1996/05/24  22:17:04  jimz
     91  1.1  oster  * continue code + namespace cleanup
     92  1.1  oster  * typed a bunch of flags
     93  1.1  oster  *
     94  1.1  oster  * Revision 1.19  1996/05/24  01:59:45  jimz
     95  1.1  oster  * another checkpoint in code cleanup for release
     96  1.1  oster  * time to sync kernel tree
     97  1.1  oster  *
     98  1.1  oster  * Revision 1.18  1996/05/23  21:46:35  jimz
     99  1.1  oster  * checkpoint in code cleanup (release prep)
    100  1.1  oster  * lots of types, function names have been fixed
    101  1.1  oster  *
    102  1.1  oster  * Revision 1.17  1996/05/23  00:33:23  jimz
    103  1.1  oster  * code cleanup: move all debug decls to rf_options.c, all extern
    104  1.1  oster  * debug decls to rf_options.h, all debug vars preceded by rf_
    105  1.1  oster  *
    106  1.1  oster  * Revision 1.16  1996/05/18  19:51:34  jimz
    107  1.1  oster  * major code cleanup- fix syntax, make some types consistent,
    108  1.1  oster  * add prototypes, clean out dead code, et cetera
    109  1.1  oster  *
    110  1.1  oster  * Revision 1.15  1996/05/10  19:39:31  jimz
    111  1.1  oster  * add prev pointer to DiskQueueData
    112  1.1  oster  *
    113  1.1  oster  * Revision 1.14  1996/05/10  16:24:04  jimz
    114  1.1  oster  * mark old defines as deprecated, add RF_ defines
    115  1.1  oster  *
    116  1.1  oster  * Revision 1.13  1995/12/01  15:59:04  root
    117  1.1  oster  * added copyright info
    118  1.1  oster  *
    119  1.1  oster  * Revision 1.12  1995/11/07  16:26:44  wvcii
    120  1.1  oster  * added Peek() function to diskqueuesw
    121  1.1  oster  *
    122  1.1  oster  * Revision 1.11  1995/10/05  02:33:15  jimz
    123  1.1  oster  * made queue lens longs (less instructions to read :-)
    124  1.1  oster  *
    125  1.1  oster  * Revision 1.10  1995/10/04  07:07:07  wvcii
    126  1.1  oster  * queue->numOutstanding now valid for user & sim
    127  1.1  oster  * user tested & verified, sim untested
    128  1.1  oster  *
    129  1.1  oster  * Revision 1.9  1995/09/12  00:21:37  wvcii
    130  1.1  oster  * added support for tracing disk queue time
    131  1.1  oster  *
    132  1.1  oster  * Revision 1.8  95/04/24  13:25:51  holland
    133  1.1  oster  * rewrite to move disk queues, recon, & atomic RMW to kernel
    134  1.1  oster  *
    135  1.1  oster  * Revision 1.6.10.2  1995/04/03  20:13:56  holland
    136  1.1  oster  * added numOutstanding and maxOutstanding to support moving
    137  1.1  oster  * disk queues into kernel code
    138  1.1  oster  *
    139  1.1  oster  * Revision 1.6.10.1  1995/04/03  20:03:56  holland
    140  1.1  oster  * initial checkin on branch
    141  1.1  oster  *
    142  1.1  oster  * Revision 1.6  1995/03/03  18:34:33  rachad
    143  1.1  oster  * Simulator mechanism added
    144  1.1  oster  *
    145  1.1  oster  * Revision 1.5  1995/03/01  20:25:48  holland
    146  1.1  oster  * kernelization changes
    147  1.1  oster  *
    148  1.1  oster  * Revision 1.4  1995/02/03  22:31:36  holland
    149  1.1  oster  * many changes related to kernelization
    150  1.1  oster  *
    151  1.1  oster  * Revision 1.3  1995/02/01  14:25:19  holland
    152  1.1  oster  * began changes for kernelization:
    153  1.1  oster  *      changed all instances of mutex_t and cond_t to DECLARE macros
    154  1.1  oster  *      converted configuration code to use config structure
    155  1.1  oster  *
    156  1.1  oster  * Revision 1.2  1994/11/29  20:36:02  danner
    157  1.1  oster  * Added symbolic constants for io_type (e.g,IO_TYPE_READ)
    158  1.1  oster  * and support for READ_OP_WRITE
    159  1.1  oster  *
    160  1.1  oster  */
    161  1.1  oster 
    162  1.1  oster 
    163  1.1  oster #ifndef _RF__RF_DISKQUEUE_H_
    164  1.1  oster #define _RF__RF_DISKQUEUE_H_
    165  1.1  oster 
    166  1.1  oster #include "rf_threadstuff.h"
    167  1.1  oster #include "rf_acctrace.h"
    168  1.1  oster #include "rf_alloclist.h"
    169  1.1  oster #include "rf_types.h"
    170  1.1  oster #include "rf_etimer.h"
    171  1.1  oster 
    172  1.1  oster 
    173  1.1  oster #if defined(__NetBSD__) && defined(_KERNEL)
    174  1.1  oster #include "rf_netbsd.h"
    175  1.1  oster #endif
    176  1.1  oster 
    177  1.1  oster 
    178  1.1  oster #define RF_IO_NORMAL_PRIORITY 1
    179  1.1  oster #define RF_IO_LOW_PRIORITY    0
    180  1.1  oster 
    181  1.1  oster /* the data held by a disk queue entry */
    182  1.1  oster struct RF_DiskQueueData_s {
    183  1.1  oster   RF_SectorNum_t           sectorOffset;   /* sector offset into the disk */
    184  1.1  oster   RF_SectorCount_t         numSector;      /* number of sectors to read/write */
    185  1.1  oster   RF_IoType_t              type;           /* read/write/nop */
    186  1.1  oster   caddr_t                  buf;            /* buffer pointer */
    187  1.1  oster   RF_StripeNum_t           parityStripeID; /* the RAID parity stripe ID this access is for */
    188  1.1  oster   RF_ReconUnitNum_t        which_ru;       /* which RU within this parity stripe */
    189  1.1  oster   int                      priority;       /* the priority of this request */
    190  1.1  oster   int                    (*CompleteFunc)(void *,int);/* function to be called upon completion */
    191  1.1  oster   int                    (*AuxFunc)(void *,...); /* function called upon completion of the first I/O of a Read_Op_Write pair*/
    192  1.1  oster   void                    *argument;       /* argument to be passed to CompleteFunc */
    193  1.1  oster #ifdef SIMULATE
    194  1.1  oster   RF_Owner_t               owner;          /* which task is responsible for this request */
    195  1.1  oster #endif /* SIMULATE */
    196  1.1  oster   void                    *raidPtr;        /* needed for simulation */
    197  1.1  oster   RF_AccTraceEntry_t      *tracerec;       /* perf mon only */
    198  1.1  oster   RF_Etimer_t              qtime;          /* perf mon only - time request is in queue */
    199  1.1  oster   long                     entryTime;
    200  1.1  oster   RF_DiskQueueData_t      *next;
    201  1.1  oster   RF_DiskQueueData_t      *prev;
    202  1.1  oster   caddr_t                  buf2;   /* for read-op-write */
    203  1.1  oster   dev_t                    dev;    /* the device number for in-kernel version */
    204  1.1  oster   RF_DiskQueue_t          *queue;  /* the disk queue to which this req is targeted */
    205  1.1  oster   RF_DiskQueueDataFlags_t  flags;  /* flags controlling operation */
    206  1.1  oster 
    207  1.1  oster #ifdef KERNEL
    208  1.1  oster   struct proc             *b_proc;  /* the b_proc from the original bp passed into the driver for this I/O */
    209  1.1  oster   struct buf              *bp;      /* a bp to use to get this I/O done */
    210  1.1  oster #endif /* KERNEL */
    211  1.1  oster };
    212  1.1  oster 
    213  1.1  oster #define RF_LOCK_DISK_QUEUE   0x01
    214  1.1  oster #define RF_UNLOCK_DISK_QUEUE 0x02
    215  1.1  oster 
    216  1.1  oster /* note: "Create" returns type-specific queue header pointer cast to (void *) */
    217  1.1  oster struct RF_DiskQueueSW_s {
    218  1.1  oster   RF_DiskQueueType_t     queueType;
    219  1.1  oster   void                *(*Create)(RF_SectorCount_t, RF_AllocListElem_t *, RF_ShutdownList_t **);    /* creation routine -- one call per queue in system */
    220  1.1  oster   void                 (*Enqueue)(void *,RF_DiskQueueData_t * ,int);   /* enqueue routine */
    221  1.1  oster   RF_DiskQueueData_t  *(*Dequeue)(void *);   /* dequeue routine */
    222  1.1  oster   RF_DiskQueueData_t  *(*Peek)(void *);      /* peek at head of queue */
    223  1.1  oster 
    224  1.1  oster   /* the rest are optional:  they improve performance, but the driver will deal with it if they don't exist */
    225  1.1  oster   int                  (*Promote)(void *, RF_StripeNum_t, RF_ReconUnitNum_t);   /* promotes priority of tagged accesses */
    226  1.1  oster };
    227  1.1  oster 
    228  1.1  oster struct RF_DiskQueue_s {
    229  1.1  oster   RF_DiskQueueSW_t    *qPtr;             /* access point to queue functions */
    230  1.1  oster   void                *qHdr;             /* queue header, of whatever type */
    231  1.1  oster   RF_DECLARE_MUTEX(mutex)                /* mutex locking data structures */
    232  1.1  oster   RF_DECLARE_COND(cond)                  /* condition variable for synchronization */
    233  1.1  oster   long                 numOutstanding;   /* number of I/Os currently outstanding on disk */
    234  1.1  oster   long                 maxOutstanding;   /* max # of I/Os that can be outstanding on a disk (in-kernel only) */
    235  1.1  oster   int                  curPriority;      /* the priority of accs all that are currently outstanding */
    236  1.1  oster   long                 queueLength;      /* number of requests in queue */
    237  1.1  oster   RF_DiskQueueData_t  *nextLockingOp;    /* a locking op that has arrived at the head of the queue & is waiting for drainage */
    238  1.1  oster   RF_DiskQueueData_t  *unlockingOp;      /* used at user level to communicate unlocking op b/w user (or dag exec) & disk threads */
    239  1.1  oster   int                  numWaiting;       /* number of threads waiting on this variable.  user-level only */
    240  1.1  oster   RF_DiskQueueFlags_t  flags;            /* terminate, locked */
    241  1.1  oster   RF_Raid_t           *raidPtr;          /* associated array */
    242  1.1  oster   dev_t                dev;              /* device number for kernel version */
    243  1.1  oster   RF_SectorNum_t       last_deq_sector;  /* last sector number dequeued or dispatched */
    244  1.1  oster   int                  row, col;         /* debug only */
    245  1.1  oster #if defined(__NetBSD__) && defined(_KERNEL)
    246  1.1  oster   struct raidcinfo *rf_cinfo;      /* disks component info.. */
    247  1.1  oster #endif
    248  1.1  oster };
    249  1.1  oster 
    250  1.1  oster #define RF_DQ_LOCKED  0x02  /* no new accs allowed until queue is explicitly unlocked */
    251  1.1  oster 
    252  1.1  oster /* macros setting & returning information about queues and requests */
    253  1.1  oster #define RF_QUEUE_LOCKED(_q)                 ((_q)->flags & RF_DQ_LOCKED)
    254  1.1  oster #define RF_QUEUE_EMPTY(_q)                  (((_q)->numOutstanding == 0) && ((_q)->nextLockingOp == NULL) && !RF_QUEUE_LOCKED(_q))
    255  1.1  oster #define RF_QUEUE_FULL(_q)                   ((_q)->numOutstanding == (_q)->maxOutstanding)
    256  1.1  oster 
    257  1.1  oster #define RF_LOCK_QUEUE(_q)                   (_q)->flags |= RF_DQ_LOCKED
    258  1.1  oster #define RF_UNLOCK_QUEUE(_q)                 (_q)->flags &= ~RF_DQ_LOCKED
    259  1.1  oster 
    260  1.1  oster #define RF_LOCK_QUEUE_MUTEX(_q_,_wh_)   RF_LOCK_MUTEX((_q_)->mutex)
    261  1.1  oster #define RF_UNLOCK_QUEUE_MUTEX(_q_,_wh_) RF_UNLOCK_MUTEX((_q_)->mutex)
    262  1.1  oster 
    263  1.1  oster #define RF_LOCKING_REQ(_r)                  ((_r)->flags & RF_LOCK_DISK_QUEUE)
    264  1.1  oster #define RF_UNLOCKING_REQ(_r)                ((_r)->flags & RF_UNLOCK_DISK_QUEUE)
    265  1.1  oster 
    266  1.1  oster /* whether it is ok to dispatch a regular request */
    267  1.1  oster #define RF_OK_TO_DISPATCH(_q_,_r_) \
    268  1.1  oster   (RF_QUEUE_EMPTY(_q_) || \
    269  1.1  oster     (!RF_QUEUE_FULL(_q_) && ((_r_)->priority >= (_q_)->curPriority)))
    270  1.1  oster 
    271  1.1  oster int rf_ConfigureDiskQueueSystem(RF_ShutdownList_t **listp);
    272  1.1  oster 
    273  1.1  oster void rf_TerminateDiskQueues(RF_Raid_t *raidPtr);
    274  1.1  oster 
    275  1.1  oster int rf_ConfigureDiskQueues(RF_ShutdownList_t **listp, RF_Raid_t *raidPtr,
    276  1.1  oster 	RF_Config_t *cfgPtr);
    277  1.1  oster 
    278  1.1  oster void rf_DiskIOEnqueue(RF_DiskQueue_t *queue, RF_DiskQueueData_t *req, int pri);
    279  1.1  oster 
    280  1.1  oster #if !defined(KERNEL) && !defined(SIMULATE)
    281  1.1  oster void rf_BroadcastOnQueue(RF_DiskQueue_t *queue);
    282  1.1  oster #endif /* !KERNEL && !SIMULATE */
    283  1.1  oster 
    284  1.1  oster #ifndef KERNEL
    285  1.1  oster RF_DiskQueueData_t *rf_DiskIODequeue(RF_DiskQueue_t *queue);
    286  1.1  oster #else /* !KERNEL */
    287  1.1  oster void rf_DiskIOComplete(RF_DiskQueue_t *queue, RF_DiskQueueData_t *req, int status);
    288  1.1  oster #endif /* !KERNEL */
    289  1.1  oster 
    290  1.1  oster int rf_DiskIOPromote(RF_DiskQueue_t *queue, RF_StripeNum_t parityStripeID,
    291  1.1  oster 	RF_ReconUnitNum_t which_ru);
    292  1.1  oster 
    293  1.1  oster RF_DiskQueueData_t *rf_CreateDiskQueueData(RF_IoType_t typ,
    294  1.1  oster 	RF_SectorNum_t ssect, RF_SectorCount_t nsect, caddr_t buf,
    295  1.1  oster 	RF_StripeNum_t parityStripeID, RF_ReconUnitNum_t which_ru,
    296  1.1  oster         int (*wakeF)(void *, int),
    297  1.1  oster 	void *arg, RF_DiskQueueData_t *next, RF_AccTraceEntry_t *tracerec,
    298  1.1  oster 	void *raidPtr, RF_DiskQueueDataFlags_t flags, void *kb_proc);
    299  1.1  oster 
    300  1.1  oster RF_DiskQueueData_t *rf_CreateDiskQueueDataFull(RF_IoType_t typ,
    301  1.1  oster 	RF_SectorNum_t ssect, RF_SectorCount_t nsect, caddr_t buf,
    302  1.1  oster 	RF_StripeNum_t parityStripeID, RF_ReconUnitNum_t which_ru,
    303  1.1  oster         int (*wakeF)(void *, int),
    304  1.1  oster 	void *arg, RF_DiskQueueData_t *next, RF_AccTraceEntry_t *tracerec,
    305  1.1  oster 	int priority, int (*AuxFunc)(void *,...), caddr_t buf2,
    306  1.1  oster 	void *raidPtr, RF_DiskQueueDataFlags_t flags, void *kb_proc);
    307  1.1  oster 
    308  1.1  oster void rf_FreeDiskQueueData(RF_DiskQueueData_t *p);
    309  1.1  oster 
    310  1.1  oster #endif /* !_RF__RF_DISKQUEUE_H_ */
    311