1 /* $NetBSD: rf_fifo.c,v 1.14 2006/10/12 01:31:51 christos Exp $ */
3 * Copyright (c) 1995 Carnegie-Mellon University.
8 * Permission to use, copy, modify and distribute this software and
9 * its documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
16 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 * Carnegie Mellon requests users of this software to return to
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
29 /***************************************************
31 * rf_fifo.c -- prioritized fifo queue code.
32 * There are only two priority levels: hi and lo.
34 * Aug 4, 1994, adapted from raidSim version (MCH)
36 ***************************************************/
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: rf_fifo.c,v 1.14 2006/10/12 01:31:51 christos Exp $");
41 #include <dev/raidframe/raidframevar.h>
43 #include "rf_alloclist.h"
44 #include "rf_stripelocks.h"
45 #include "rf_layout.h"
46 #include "rf_diskqueue.h"
48 #include "rf_debugMem.h"
49 #include "rf_general.h"
50 #include "rf_options.h"
53 /* just malloc a header, zero it (via calloc), and return it */
56 rf_FifoCreate(RF_SectorCount_t sectPerDisk
, RF_AllocListElem_t
*clList
,
57 RF_ShutdownList_t
**listp
)
61 RF_MallocAndAdd(q
, sizeof(RF_FifoHeader_t
),
62 (RF_FifoHeader_t
*), clList
);
63 q
->hq_count
= q
->lq_count
= 0;
68 rf_FifoEnqueue(void *q_in
, RF_DiskQueueData_t
*elem
, int priority
)
70 RF_FifoHeader_t
*q
= (RF_FifoHeader_t
*) q_in
;
72 RF_ASSERT(priority
== RF_IO_NORMAL_PRIORITY
|| priority
== RF_IO_LOW_PRIORITY
);
75 if (priority
== RF_IO_NORMAL_PRIORITY
) {
77 RF_ASSERT(q
->hq_count
== 0 && q
->hq_head
== NULL
);
78 q
->hq_head
= q
->hq_tail
= elem
;
80 RF_ASSERT(q
->hq_count
!= 0 && q
->hq_head
!= NULL
);
81 q
->hq_tail
->next
= elem
;
86 RF_ASSERT(elem
->next
== NULL
);
89 printf("raid%d: fifo: ENQ lopri\n",
90 elem
->raidPtr
->raidid
);
94 RF_ASSERT(q
->lq_count
== 0 && q
->lq_head
== NULL
);
95 q
->lq_head
= q
->lq_tail
= elem
;
97 RF_ASSERT(q
->lq_count
!= 0 && q
->lq_head
!= NULL
);
98 q
->lq_tail
->next
= elem
;
103 if ((q
->hq_count
+ q
->lq_count
) != elem
->queue
->queueLength
) {
104 printf("Queue lengths differ!: %d %d %d\n",
105 q
->hq_count
, q
->lq_count
, (int) elem
->queue
->queueLength
);
107 (int) elem
->queue
->numOutstanding
,
108 (int) elem
->queue
->maxOutstanding
,
109 (int) elem
->queue
->col
);
111 RF_ASSERT((q
->hq_count
+ q
->lq_count
) == elem
->queue
->queueLength
);
115 rf_FifoDequeue(void *q_in
)
117 RF_FifoHeader_t
*q
= (RF_FifoHeader_t
*) q_in
;
118 RF_DiskQueueData_t
*nd
;
122 RF_ASSERT(q
->hq_count
!= 0 && q
->hq_tail
!= NULL
);
124 q
->hq_head
= q
->hq_head
->next
;
131 RF_ASSERT(q
->lq_count
!= 0 && q
->lq_tail
!= NULL
);
133 q
->lq_head
= q
->lq_head
->next
;
140 printf("raid%d: fifo: DEQ lopri %lx\n",
141 nd
->raidPtr
->raidid
, (long) nd
);
145 RF_ASSERT(q
->hq_count
== 0 && q
->lq_count
== 0 && q
->hq_tail
== NULL
&& q
->lq_tail
== NULL
);
151 /* Return ptr to item at head of queue. Used to examine request
152 * info without actually dequeueing the request.
155 rf_FifoPeek(void *q_in
)
157 RF_DiskQueueData_t
*headElement
= NULL
;
158 RF_FifoHeader_t
*q
= (RF_FifoHeader_t
*) q_in
;
162 headElement
= q
->hq_head
;
165 headElement
= q
->lq_head
;
166 return (headElement
);
168 /* We sometimes need to promote a low priority access to a regular priority access.
169 * Currently, this is only used when the user wants to write a stripe which is currently
170 * under reconstruction.
171 * This routine will promote all accesses tagged with the indicated parityStripeID from
172 * the low priority queue to the end of the normal priority queue.
173 * We assume the queue is locked upon entry.
176 rf_FifoPromote(void *q_in
, RF_StripeNum_t parityStripeID
,
177 RF_ReconUnitNum_t which_ru
)
179 RF_FifoHeader_t
*q
= (RF_FifoHeader_t
*) q_in
;
180 RF_DiskQueueData_t
*lp
= q
->lq_head
, *pt
= NULL
; /* lp = lo-pri queue
181 * pointer, pt = trailer */
186 /* search for the indicated parity stripe in the low-pri queue */
187 if (lp
->parityStripeID
== parityStripeID
&& lp
->which_ru
== which_ru
) {
188 /* printf("FifoPromote: promoting access for psid
189 * %ld\n",parityStripeID); */
191 pt
->next
= lp
->next
; /* delete an entry other
194 q
->lq_head
= lp
->next
; /* delete the head entry */
197 q
->lq_tail
= NULL
; /* we deleted the only
200 if (lp
== q
->lq_tail
)
201 q
->lq_tail
= pt
; /* we deleted the tail
208 q
->hq_tail
->next
= lp
;
211 /* append to hi-priority queue */
213 q
->hq_head
= q
->hq_tail
= lp
;
217 /* UpdateShortestSeekFinishTimeForced(lp->requestPtr,
218 * lp->diskState); *//* deal with this later, if ever */
220 lp
= (pt
) ? pt
->next
: q
->lq_head
; /* reset low-pri pointer
230 /* sanity check. delete this if you ever put more than one entry in
231 * the low-pri queue */
232 RF_ASSERT(retval
== 0 || retval
== 1);