1999-03-15 00:53:31 +03:00
|
|
|
/* $NetBSD: rf_revent.c,v 1.4 1999/03/14 21:53:31 oster Exp $ */
|
1998-11-13 07:20:26 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1995 Carnegie-Mellon University.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Author:
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify and distribute this software and
|
|
|
|
* its documentation is hereby granted, provided that both the copyright
|
|
|
|
* notice and this permission notice appear in all copies of the
|
|
|
|
* software, derivative works or modified versions, and any portions
|
|
|
|
* thereof, and that both notices appear in supporting documentation.
|
|
|
|
*
|
|
|
|
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
|
|
|
|
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
|
|
|
|
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
|
|
|
|
*
|
|
|
|
* Carnegie Mellon requests users of this software to return to
|
|
|
|
*
|
|
|
|
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
|
|
|
|
* School of Computer Science
|
|
|
|
* Carnegie Mellon University
|
|
|
|
* Pittsburgh PA 15213-3890
|
|
|
|
*
|
|
|
|
* any improvements or extensions that they make and grant Carnegie the
|
|
|
|
* rights to redistribute these changes.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* revent.c -- reconstruction event handling code
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/errno.h>
|
|
|
|
|
|
|
|
#include "rf_raid.h"
|
|
|
|
#include "rf_revent.h"
|
|
|
|
#include "rf_etimer.h"
|
|
|
|
#include "rf_general.h"
|
|
|
|
#include "rf_freelist.h"
|
|
|
|
#include "rf_desc.h"
|
|
|
|
#include "rf_shutdown.h"
|
|
|
|
|
|
|
|
static RF_FreeList_t *rf_revent_freelist;
|
|
|
|
#define RF_MAX_FREE_REVENT 128
|
|
|
|
#define RF_REVENT_INC 8
|
|
|
|
#define RF_REVENT_INITIAL 8
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <sys/proc.h>
|
|
|
|
|
|
|
|
extern int hz;
|
|
|
|
|
1999-03-15 00:53:31 +03:00
|
|
|
#define DO_WAIT(_rc) tsleep(&(_rc)->eventQueue, PRIBIO, "raidframe eventq", 0)
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
#define DO_SIGNAL(_rc) wakeup(&(_rc)->eventQueue)
|
|
|
|
|
|
|
|
|
|
|
|
static void rf_ShutdownReconEvent(void *);
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
static RF_ReconEvent_t *
|
|
|
|
GetReconEventDesc(RF_RowCol_t row, RF_RowCol_t col,
|
|
|
|
void *arg, RF_Revent_t type);
|
|
|
|
RF_ReconEvent_t *
|
|
|
|
rf_GetNextReconEvent(RF_RaidReconDesc_t *,
|
|
|
|
RF_RowCol_t, void (*continueFunc) (void *),
|
|
|
|
void *);
|
1998-11-13 07:20:26 +03:00
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
static void rf_ShutdownReconEvent(ignored)
|
|
|
|
void *ignored;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_FREELIST_DESTROY(rf_revent_freelist, next, (RF_ReconEvent_t *));
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
int
|
|
|
|
rf_ConfigureReconEvent(listp)
|
|
|
|
RF_ShutdownList_t **listp;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
RF_FREELIST_CREATE(rf_revent_freelist, RF_MAX_FREE_REVENT,
|
|
|
|
RF_REVENT_INC, sizeof(RF_ReconEvent_t));
|
|
|
|
if (rf_revent_freelist == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
rc = rf_ShutdownCreate(listp, rf_ShutdownReconEvent, NULL);
|
|
|
|
if (rc) {
|
|
|
|
RF_ERRORMSG3("Unable to add to shutdown list file %s line %d rc=%d\n", __FILE__,
|
|
|
|
__LINE__, rc);
|
|
|
|
rf_ShutdownReconEvent(NULL);
|
|
|
|
return (rc);
|
|
|
|
}
|
|
|
|
RF_FREELIST_PRIME(rf_revent_freelist, RF_REVENT_INITIAL, next,
|
|
|
|
(RF_ReconEvent_t *));
|
|
|
|
return (0);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
/* returns the next reconstruction event, blocking the calling thread until
|
|
|
|
* one becomes available
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* will now return null if it is blocked or will return an event if it is not */
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_ReconEvent_t *
|
|
|
|
rf_GetNextReconEvent(reconDesc, row, continueFunc, continueArg)
|
|
|
|
RF_RaidReconDesc_t *reconDesc;
|
|
|
|
RF_RowCol_t row;
|
|
|
|
void (*continueFunc) (void *);
|
|
|
|
void *continueArg;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_Raid_t *raidPtr = reconDesc->raidPtr;
|
|
|
|
RF_ReconCtrl_t *rctrl = raidPtr->reconControl[row];
|
|
|
|
RF_ReconEvent_t *event;
|
|
|
|
|
|
|
|
RF_ASSERT(row >= 0 && row <= raidPtr->numRow);
|
|
|
|
RF_LOCK_MUTEX(rctrl->eq_mutex);
|
|
|
|
RF_ASSERT((rctrl->eventQueue == NULL) == (rctrl->eq_count == 0)); /* q null and count==0
|
|
|
|
* must be equivalent
|
|
|
|
* conditions */
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
rctrl->continueFunc = continueFunc;
|
|
|
|
rctrl->continueArg = continueArg;
|
1998-11-13 07:20:26 +03:00
|
|
|
|
|
|
|
|
|
|
|
/* mpsleep timeout value: secs = timo_val/hz. 'ticks' here is defined as cycle-counter ticks, not softclock ticks */
|
1999-02-05 03:06:06 +03:00
|
|
|
#define MAX_RECON_EXEC_TICKS 15000000 /* 150 Mhz => this many ticks in 100
|
|
|
|
* ms */
|
1998-11-13 07:20:26 +03:00
|
|
|
#define RECON_DELAY_MS 25
|
|
|
|
#define RECON_TIMO ((RECON_DELAY_MS * hz) / 1000)
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
/* we are not pre-emptible in the kernel, but we don't want to run
|
|
|
|
* forever. If we run w/o blocking for more than MAX_RECON_EXEC_TICKS
|
|
|
|
* ticks of the cycle counter, delay for RECON_DELAY before
|
|
|
|
* continuing. this may murder us with context switches, so we may
|
|
|
|
* need to increase both the MAX...TICKS and the RECON_DELAY_MS. */
|
|
|
|
if (reconDesc->reconExecTimerRunning) {
|
|
|
|
int status;
|
|
|
|
|
|
|
|
RF_ETIMER_STOP(reconDesc->recon_exec_timer);
|
|
|
|
RF_ETIMER_EVAL(reconDesc->recon_exec_timer);
|
|
|
|
reconDesc->reconExecTicks += RF_ETIMER_VAL_TICKS(reconDesc->recon_exec_timer);
|
|
|
|
if (reconDesc->reconExecTicks > reconDesc->maxReconExecTicks)
|
|
|
|
reconDesc->maxReconExecTicks = reconDesc->reconExecTicks;
|
|
|
|
if (reconDesc->reconExecTicks >= MAX_RECON_EXEC_TICKS) {
|
|
|
|
/* we've been running too long. delay for
|
|
|
|
* RECON_DELAY_MS */
|
1998-11-13 07:20:26 +03:00
|
|
|
#if RF_RECON_STATS > 0
|
1999-02-05 03:06:06 +03:00
|
|
|
reconDesc->numReconExecDelays++;
|
|
|
|
#endif /* RF_RECON_STATS > 0 */
|
1999-03-15 00:53:31 +03:00
|
|
|
status = tsleep(&reconDesc->reconExecTicks, PRIBIO, "recon delay", RECON_TIMO);
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_ASSERT(status == EWOULDBLOCK);
|
|
|
|
reconDesc->reconExecTicks = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (!rctrl->eventQueue) {
|
1998-11-13 07:20:26 +03:00
|
|
|
#if RF_RECON_STATS > 0
|
1999-02-05 03:06:06 +03:00
|
|
|
reconDesc->numReconEventWaits++;
|
|
|
|
#endif /* RF_RECON_STATS > 0 */
|
|
|
|
DO_WAIT(rctrl);
|
|
|
|
reconDesc->reconExecTicks = 0; /* we've just waited */
|
|
|
|
}
|
|
|
|
|
|
|
|
reconDesc->reconExecTimerRunning = 1;
|
|
|
|
RF_ETIMER_START(reconDesc->recon_exec_timer);
|
|
|
|
|
|
|
|
event = rctrl->eventQueue;
|
|
|
|
rctrl->eventQueue = event->next;
|
|
|
|
event->next = NULL;
|
|
|
|
rctrl->eq_count--;
|
|
|
|
RF_ASSERT((rctrl->eventQueue == NULL) == (rctrl->eq_count == 0)); /* q null and count==0
|
|
|
|
* must be equivalent
|
|
|
|
* conditions */
|
|
|
|
RF_UNLOCK_MUTEX(rctrl->eq_mutex);
|
|
|
|
return (event);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
/* enqueues a reconstruction event on the indicated queue */
|
1999-02-05 03:06:06 +03:00
|
|
|
void
|
|
|
|
rf_CauseReconEvent(raidPtr, row, col, arg, type)
|
|
|
|
RF_Raid_t *raidPtr;
|
|
|
|
RF_RowCol_t row;
|
|
|
|
RF_RowCol_t col;
|
|
|
|
void *arg;
|
|
|
|
RF_Revent_t type;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_ReconCtrl_t *rctrl = raidPtr->reconControl[row];
|
|
|
|
RF_ReconEvent_t *event = GetReconEventDesc(row, col, arg, type);
|
|
|
|
|
|
|
|
if (type == RF_REVENT_BUFCLEAR) {
|
|
|
|
RF_ASSERT(col != rctrl->fcol);
|
|
|
|
}
|
|
|
|
RF_ASSERT(row >= 0 && row <= raidPtr->numRow && col >= 0 && col <= raidPtr->numCol);
|
|
|
|
RF_LOCK_MUTEX(rctrl->eq_mutex);
|
|
|
|
RF_ASSERT((rctrl->eventQueue == NULL) == (rctrl->eq_count == 0)); /* q null and count==0
|
|
|
|
* must be equivalent
|
|
|
|
* conditions */
|
|
|
|
event->next = rctrl->eventQueue;
|
|
|
|
rctrl->eventQueue = event;
|
|
|
|
rctrl->eq_count++;
|
|
|
|
RF_UNLOCK_MUTEX(rctrl->eq_mutex);
|
|
|
|
|
|
|
|
DO_SIGNAL(rctrl);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
/* allocates and initializes a recon event descriptor */
|
1999-02-05 03:06:06 +03:00
|
|
|
static RF_ReconEvent_t *
|
|
|
|
GetReconEventDesc(row, col, arg, type)
|
|
|
|
RF_RowCol_t row;
|
|
|
|
RF_RowCol_t col;
|
|
|
|
void *arg;
|
|
|
|
RF_Revent_t type;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
|
|
|
RF_ReconEvent_t *t;
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_FREELIST_GET(rf_revent_freelist, t, next, (RF_ReconEvent_t *));
|
1998-11-13 07:20:26 +03:00
|
|
|
if (t == NULL)
|
1999-02-05 03:06:06 +03:00
|
|
|
return (NULL);
|
1998-11-13 07:20:26 +03:00
|
|
|
t->col = col;
|
|
|
|
t->arg = arg;
|
|
|
|
t->type = type;
|
1999-02-05 03:06:06 +03:00
|
|
|
return (t);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|
|
|
|
|
1999-02-05 03:06:06 +03:00
|
|
|
void
|
|
|
|
rf_FreeReconEventDesc(event)
|
|
|
|
RF_ReconEvent_t *event;
|
1998-11-13 07:20:26 +03:00
|
|
|
{
|
1999-02-05 03:06:06 +03:00
|
|
|
RF_FREELIST_FREE(rf_revent_freelist, event, next);
|
1998-11-13 07:20:26 +03:00
|
|
|
}
|