rf_fifo.c revision 1.9 1 /* $NetBSD: rf_fifo.c,v 1.9 2003/12/29 03:33:48 oster Exp $ */
2 /*
3 * Copyright (c) 1995 Carnegie-Mellon University.
4 * All rights reserved.
5 *
6 * Author: Mark Holland
7 *
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.
13 *
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.
17 *
18 * Carnegie Mellon requests users of this software to return to
19 *
20 * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
24 *
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
27 */
28
29 /***************************************************
30 *
31 * rf_fifo.c -- prioritized fifo queue code.
32 * There are only two priority levels: hi and lo.
33 *
34 * Aug 4, 1994, adapted from raidSim version (MCH)
35 *
36 ***************************************************/
37
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: rf_fifo.c,v 1.9 2003/12/29 03:33:48 oster Exp $");
40
41 #include <dev/raidframe/raidframevar.h>
42
43 #include "rf_alloclist.h"
44 #include "rf_stripelocks.h"
45 #include "rf_layout.h"
46 #include "rf_diskqueue.h"
47 #include "rf_fifo.h"
48 #include "rf_debugMem.h"
49 #include "rf_general.h"
50 #include "rf_options.h"
51 #include "rf_raid.h"
52
53 /* just malloc a header, zero it (via calloc), and return it */
54 /*ARGSUSED*/
55 void *
56 rf_FifoCreate(sectPerDisk, clList, listp)
57 RF_SectorCount_t sectPerDisk;
58 RF_AllocListElem_t *clList;
59 RF_ShutdownList_t **listp;
60 {
61 RF_FifoHeader_t *q;
62
63 RF_MallocAndAdd(q, sizeof(RF_FifoHeader_t),
64 (RF_FifoHeader_t *), clList);
65 q->hq_count = q->lq_count = 0;
66 return ((void *) q);
67 }
68
69 void
70 rf_FifoEnqueue(q_in, elem, priority)
71 void *q_in;
72 RF_DiskQueueData_t *elem;
73 int priority;
74 {
75 RF_FifoHeader_t *q = (RF_FifoHeader_t *) q_in;
76
77 RF_ASSERT(priority == RF_IO_NORMAL_PRIORITY || priority == RF_IO_LOW_PRIORITY);
78
79 elem->next = NULL;
80 if (priority == RF_IO_NORMAL_PRIORITY) {
81 if (!q->hq_tail) {
82 RF_ASSERT(q->hq_count == 0 && q->hq_head == NULL);
83 q->hq_head = q->hq_tail = elem;
84 } else {
85 RF_ASSERT(q->hq_count != 0 && q->hq_head != NULL);
86 q->hq_tail->next = elem;
87 q->hq_tail = elem;
88 }
89 q->hq_count++;
90 } else {
91 RF_ASSERT(elem->next == NULL);
92 #if RF_DEBUG_QUEUE
93 if (rf_fifoDebug) {
94 printf("raid%d: fifo: ENQ lopri\n",
95 elem->raidPtr->raidid);
96 }
97 #endif
98 if (!q->lq_tail) {
99 RF_ASSERT(q->lq_count == 0 && q->lq_head == NULL);
100 q->lq_head = q->lq_tail = elem;
101 } else {
102 RF_ASSERT(q->lq_count != 0 && q->lq_head != NULL);
103 q->lq_tail->next = elem;
104 q->lq_tail = elem;
105 }
106 q->lq_count++;
107 }
108 if ((q->hq_count + q->lq_count) != elem->queue->queueLength) {
109 printf("Queue lengths differ!: %d %d %d\n",
110 q->hq_count, q->lq_count, (int) elem->queue->queueLength);
111 printf("%d %d %d %d\n",
112 (int) elem->queue->numOutstanding,
113 (int) elem->queue->maxOutstanding,
114 (int) elem->queue->row,
115 (int) elem->queue->col);
116 }
117 RF_ASSERT((q->hq_count + q->lq_count) == elem->queue->queueLength);
118 }
119
120 RF_DiskQueueData_t *
121 rf_FifoDequeue(q_in)
122 void *q_in;
123 {
124 RF_FifoHeader_t *q = (RF_FifoHeader_t *) q_in;
125 RF_DiskQueueData_t *nd;
126
127 RF_ASSERT(q);
128 if (q->hq_head) {
129 RF_ASSERT(q->hq_count != 0 && q->hq_tail != NULL);
130 nd = q->hq_head;
131 q->hq_head = q->hq_head->next;
132 if (!q->hq_head)
133 q->hq_tail = NULL;
134 nd->next = NULL;
135 q->hq_count--;
136 } else
137 if (q->lq_head) {
138 RF_ASSERT(q->lq_count != 0 && q->lq_tail != NULL);
139 nd = q->lq_head;
140 q->lq_head = q->lq_head->next;
141 if (!q->lq_head)
142 q->lq_tail = NULL;
143 nd->next = NULL;
144 q->lq_count--;
145 #if RF_DEBUG_QUEUE
146 if (rf_fifoDebug) {
147 printf("raid%d: fifo: DEQ lopri %lx\n",
148 nd->raidPtr->raidid, (long) nd);
149 }
150 #endif
151 } else {
152 RF_ASSERT(q->hq_count == 0 && q->lq_count == 0 && q->hq_tail == NULL && q->lq_tail == NULL);
153 nd = NULL;
154 }
155 return (nd);
156 }
157
158 /* Return ptr to item at head of queue. Used to examine request
159 * info without actually dequeueing the request.
160 */
161 RF_DiskQueueData_t *
162 rf_FifoPeek(void *q_in)
163 {
164 RF_DiskQueueData_t *headElement = NULL;
165 RF_FifoHeader_t *q = (RF_FifoHeader_t *) q_in;
166
167 RF_ASSERT(q);
168 if (q->hq_head)
169 headElement = q->hq_head;
170 else
171 if (q->lq_head)
172 headElement = q->lq_head;
173 return (headElement);
174 }
175 /* We sometimes need to promote a low priority access to a regular priority access.
176 * Currently, this is only used when the user wants to write a stripe which is currently
177 * under reconstruction.
178 * This routine will promote all accesses tagged with the indicated parityStripeID from
179 * the low priority queue to the end of the normal priority queue.
180 * We assume the queue is locked upon entry.
181 */
182 int
183 rf_FifoPromote(q_in, parityStripeID, which_ru)
184 void *q_in;
185 RF_StripeNum_t parityStripeID;
186 RF_ReconUnitNum_t which_ru;
187 {
188 RF_FifoHeader_t *q = (RF_FifoHeader_t *) q_in;
189 RF_DiskQueueData_t *lp = q->lq_head, *pt = NULL; /* lp = lo-pri queue
190 * pointer, pt = trailer */
191 int retval = 0;
192
193 while (lp) {
194
195 /* search for the indicated parity stripe in the low-pri queue */
196 if (lp->parityStripeID == parityStripeID && lp->which_ru == which_ru) {
197 /* printf("FifoPromote: promoting access for psid
198 * %ld\n",parityStripeID); */
199 if (pt)
200 pt->next = lp->next; /* delete an entry other
201 * than the first */
202 else
203 q->lq_head = lp->next; /* delete the head entry */
204
205 if (!q->lq_head)
206 q->lq_tail = NULL; /* we deleted the only
207 * entry */
208 else
209 if (lp == q->lq_tail)
210 q->lq_tail = pt; /* we deleted the tail
211 * entry */
212
213 lp->next = NULL;
214 q->lq_count--;
215
216 if (q->hq_tail) {
217 q->hq_tail->next = lp;
218 q->hq_tail = lp;
219 }
220 /* append to hi-priority queue */
221 else {
222 q->hq_head = q->hq_tail = lp;
223 }
224 q->hq_count++;
225
226 /* UpdateShortestSeekFinishTimeForced(lp->requestPtr,
227 * lp->diskState); *//* deal with this later, if ever */
228
229 lp = (pt) ? pt->next : q->lq_head; /* reset low-pri pointer
230 * and continue */
231 retval++;
232
233 } else {
234 pt = lp;
235 lp = lp->next;
236 }
237 }
238
239 /* sanity check. delete this if you ever put more than one entry in
240 * the low-pri queue */
241 RF_ASSERT(retval == 0 || retval == 1);
242 return (retval);
243 }
244