Home | History | Annotate | Line # | Download | only in raidframe
rf_alloclist.c revision 1.19
      1  1.19    oster /*	$NetBSD: rf_alloclist.c,v 1.19 2004/03/05 02:53:55 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  * Alloclist.c -- code to manipulate allocation lists
     32   1.1    oster  *
     33   1.1    oster  * an allocation list is just a list of AllocListElem structures.  Each
     34   1.1    oster  * such structure contains a fixed-size array of pointers.  Calling
     35   1.1    oster  * FreeAList() causes each pointer to be freed.
     36   1.1    oster  *
     37   1.1    oster  ***************************************************************************/
     38   1.8    lukem 
     39   1.8    lukem #include <sys/cdefs.h>
     40  1.19    oster __KERNEL_RCSID(0, "$NetBSD: rf_alloclist.c,v 1.19 2004/03/05 02:53:55 oster Exp $");
     41   1.1    oster 
     42   1.6    oster #include <dev/raidframe/raidframevar.h>
     43   1.6    oster 
     44   1.7    oster #include "rf_options.h"
     45   1.1    oster #include "rf_threadstuff.h"
     46   1.1    oster #include "rf_alloclist.h"
     47   1.1    oster #include "rf_debugMem.h"
     48   1.1    oster #include "rf_etimer.h"
     49   1.1    oster #include "rf_general.h"
     50   1.1    oster #include "rf_shutdown.h"
     51   1.1    oster 
     52  1.17    oster #include <sys/pool.h>
     53   1.1    oster 
     54  1.17    oster static struct pool rf_alloclist_pool;
     55   1.1    oster #define RF_AL_FREELIST_MAX 256
     56  1.19    oster #define RF_AL_FREELIST_MIN 64
     57   1.1    oster 
     58   1.9    oster static void rf_ShutdownAllocList(void *);
     59   1.1    oster 
     60  1.15    oster static void rf_ShutdownAllocList(void *ignored)
     61   1.1    oster {
     62  1.17    oster 	pool_destroy(&rf_alloclist_pool);
     63   1.1    oster }
     64   1.1    oster 
     65   1.3    oster int
     66  1.15    oster rf_ConfigureAllocList(RF_ShutdownList_t **listp)
     67   1.1    oster {
     68   1.1    oster 
     69  1.17    oster 	pool_init(&rf_alloclist_pool, sizeof(RF_AllocListElem_t),
     70  1.17    oster 		  0, 0, 0, "rf_alloclist_pl", NULL);
     71  1.17    oster 	pool_sethiwat(&rf_alloclist_pool, RF_AL_FREELIST_MAX);
     72  1.19    oster 	pool_prime(&rf_alloclist_pool, RF_AL_FREELIST_MIN);
     73  1.19    oster 	pool_setlowat(&rf_alloclist_pool, RF_AL_FREELIST_MIN);
     74  1.19    oster 
     75  1.17    oster 
     76  1.18    oster 	rf_ShutdownCreate(listp, rf_ShutdownAllocList, NULL);
     77  1.17    oster 
     78   1.3    oster 	return (0);
     79   1.1    oster }
     80   1.1    oster 
     81   1.1    oster 
     82   1.1    oster /* we expect the lists to have at most one or two elements, so we're willing
     83   1.1    oster  * to search for the end.  If you ever observe the lists growing longer,
     84   1.1    oster  * increase POINTERS_PER_ALLOC_LIST_ELEMENT.
     85   1.1    oster  */
     86   1.3    oster void
     87  1.15    oster rf_real_AddToAllocList(RF_AllocListElem_t *l, void *p, int size)
     88   1.1    oster {
     89   1.3    oster 	RF_AllocListElem_t *newelem;
     90   1.1    oster 
     91   1.3    oster 	for (; l->next; l = l->next)
     92   1.3    oster 		RF_ASSERT(l->numPointers == RF_POINTERS_PER_ALLOC_LIST_ELEMENT);	/* find end of list */
     93   1.3    oster 
     94   1.3    oster 	RF_ASSERT(l->numPointers >= 0 && l->numPointers <= RF_POINTERS_PER_ALLOC_LIST_ELEMENT);
     95   1.3    oster 	if (l->numPointers == RF_POINTERS_PER_ALLOC_LIST_ELEMENT) {
     96  1.11    oster 		newelem = rf_real_MakeAllocList();
     97   1.3    oster 		l->next = newelem;
     98   1.3    oster 		l = newelem;
     99   1.3    oster 	}
    100   1.3    oster 	l->pointers[l->numPointers] = p;
    101   1.3    oster 	l->sizes[l->numPointers] = size;
    102   1.3    oster 	l->numPointers++;
    103   1.1    oster 
    104   1.1    oster }
    105   1.1    oster 
    106   1.3    oster void
    107  1.15    oster rf_FreeAllocList(RF_AllocListElem_t *l)
    108   1.1    oster {
    109   1.3    oster 	int     i;
    110   1.3    oster 	RF_AllocListElem_t *temp, *p;
    111   1.1    oster 
    112   1.3    oster 	for (p = l; p; p = p->next) {
    113  1.12    oster 		RF_ASSERT(p->numPointers >= 0 &&
    114  1.12    oster 			  p->numPointers <= RF_POINTERS_PER_ALLOC_LIST_ELEMENT);
    115   1.3    oster 		for (i = 0; i < p->numPointers; i++) {
    116   1.3    oster 			RF_ASSERT(p->pointers[i]);
    117   1.3    oster 			RF_Free(p->pointers[i], p->sizes[i]);
    118   1.3    oster 		}
    119   1.3    oster 	}
    120   1.3    oster 	while (l) {
    121   1.3    oster 		temp = l;
    122   1.3    oster 		l = l->next;
    123  1.17    oster 		pool_put(&rf_alloclist_pool, temp);
    124   1.3    oster 	}
    125   1.1    oster }
    126   1.1    oster 
    127   1.3    oster RF_AllocListElem_t *
    128  1.11    oster rf_real_MakeAllocList()
    129   1.1    oster {
    130   1.3    oster 	RF_AllocListElem_t *p;
    131   1.1    oster 
    132  1.17    oster 	p = pool_get(&rf_alloclist_pool, PR_WAITOK);
    133   1.5  thorpej 	memset((char *) p, 0, sizeof(RF_AllocListElem_t));
    134   1.3    oster 	return (p);
    135   1.1    oster }
    136