home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 8 / FreshFishVol8-CD2.bin / bbs / comm / amitcp-3.0ß2.lha / AmiTCP / src / amitcp / kern / uipc_mbuf.c < prev    next >
C/C++ Source or Header  |  1993-08-12  |  22KB  |  907 lines

  1. RCS_ID_C = "$Id: uipc_mbuf.c,v 1.18 1993/06/04 11:16:15 jraja Exp $";
  2. /*
  3.  * Copyright (c) 1993 AmiTCP/IP Group, <amitcp-group@hut.fi>
  4.  *                    Helsinki University of Technology, Finland.
  5.  *                    All rights reserved.
  6.  *
  7.  * Last modified: Fri Jun  4 00:36:45 1993 jraja
  8.  *
  9.  * HISTORY
  10.  * $Log: uipc_mbuf.c,v $
  11.  * Revision 1.18  1993/06/04  11:16:15  jraja
  12.  * Fixes for first public release.
  13.  *
  14.  * Revision 1.17  1993/05/29  20:57:23  jraja
  15.  * Added function mb_read_stats() to return mbuf type specific statistics.
  16.  *
  17.  * Revision 1.16  1993/05/16  15:20:25  ppessi
  18.  * Fixed bug with cluster allocation.
  19.  *
  20.  * Revision 1.16  1993/05/16  15:20:25  ppessi
  21.  * Fixed bug with cluster allocation.
  22.  *
  23.  * Revision 1.15  93/05/04  12:52:25  12:52:25  jraja (Jarno Tapio Rajahalme)
  24.  * Fixed default values of the configuration variables.
  25.  * 
  26.  * Revision 1.14  93/04/25  02:59:37  02:59:37  jraja (Jarno Tapio Rajahalme)
  27.  * Added some comments.
  28.  * 
  29.  * Revision 1.13  93/04/24  22:19:41  22:19:41  jraja (Jarno Tapio Rajahalme)
  30.  * Removed MBTYPES, moved configurable variables to a structure (mbconf),
  31.  * removed nmbufs and nmbclusters (already in mbstat), moved mbufmemsize to
  32.  * mbstat (as m_memused), added configuration notify function 
  33.  * mb_check_conf() to validate configurable variables,
  34.  * added checks for maximum memory usage,
  35.  * removed m_retryhdr(), since m_retry() is already called by MGETHDR,
  36.  * removed all USECLUSTERS (now using clusters always.
  37.  * 
  38.  * Revision 1.12  93/04/23  02:26:28  02:26:28  ppessi (Pekka Pessi)
  39.  * Added some configureable parameters
  40.  * 
  41.  * Revision 1.11  93/04/13  22:31:51  22:31:51  jraja (Jarno Tapio Rajahalme)
  42.  * Added #ifdef USECLUSTERS ... #endif to compile without.
  43.  * 
  44.  * Revision 1.10  93/04/06  15:16:04  15:16:04  jraja (Jarno Tapio Rajahalme)
  45.  * Changed spl function return value storage to spl_t,
  46.  * changed bcopys and bzeros to aligned and/or const when possible,
  47.  * added inclusion of conf.h to every .c file.
  48.  * 
  49.  * Revision 1.9  93/04/02  01:08:17  01:08:17  jraja (Jarno Tapio Rajahalme)
  50.  * Implemented clusters.
  51.  * Updated memory allocation.
  52.  * Added memHeader structure to keep account of allocated memory.
  53.  * 
  54.  * Revision 1.8  93/03/05  03:26:21  03:26:21  ppessi (Pekka Pessi)
  55.  * Compiles with SASC. Initial test version.
  56.  * 
  57.  * Revision 1.7  93/03/04  09:55:46  09:55:46  jraja (Jarno Tapio Rajahalme)
  58.  * Fixed includes.
  59.  * 
  60.  * Revision 1.6  93/03/03  19:59:29  19:59:29  jraja (Jarno Tapio Rajahalme)
  61.  * Added static initializers to globals.
  62.  * 
  63.  * Revision 1.5  93/03/03  19:20:43  19:20:43  jraja (Jarno Tapio Rajahalme)
  64.  * Moved some definitions from sys/mbuf.h to here.
  65.  * 
  66.  * Revision 1.4  93/02/24  12:55:20  12:55:20  jraja (Jarno Tapio Rajahalme)
  67.  * Changed init to remember if initialized.
  68.  * 
  69.  * Revision 1.3  93/01/06  19:24:53  19:24:53  jraja (Jarno Tapio Rajahalme)
  70.  * Ported this for AmigaOS. Added function mbdeinit(), which is used to free
  71.  * memory allocated by mbuf subsystem.
  72.  * Alse commented all memory cluster related stuff with #ifdef USECLUSTERS.
  73.  * 
  74.  * Revision 1.2  92/11/20  15:14:25  15:14:25  jraja (Jarno Tapio Rajahalme)
  75.  * Added #ifndef AMITCP's to make this compile.
  76.  * 
  77.  * Revision 1.1  92/11/19  12:07:15  12:07:15  jraja (Jarno Tapio Rajahalme)
  78.  * Initial revision
  79.  */
  80.  
  81. /* 
  82.  * Mach Operating System
  83.  * Copyright (c) 1992 Carnegie Mellon University
  84.  * All Rights Reserved.
  85.  * 
  86.  * Permission to use, copy, modify and distribute this software and its
  87.  * documentation is hereby granted, provided that both the copyright
  88.  * notice and this permission notice appear in all copies of the
  89.  * software, derivative works or modified versions, and any portions
  90.  * thereof, and that both notices appear in supporting documentation.
  91.  * 
  92.  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
  93.  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
  94.  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  95.  * 
  96.  * Carnegie Mellon requests users of this software to return to
  97.  * 
  98.  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
  99.  *  School of Computer Science
  100.  *  Carnegie Mellon University
  101.  *  Pittsburgh PA 15213-3890
  102.  * 
  103.  * any improvements or extensions that they make and grant Carnegie Mellon 
  104.  * the rights to redistribute these changes.
  105.  */
  106. /*
  107.  * HISTORY
  108.  * Log:    uipc_mbuf.c,v
  109.  * Revision 2.2  92/06/25  17:25:22  mrt
  110.  *     Preallocate mbufs in a chunk.
  111.  *     [92/06/24            rwd]
  112.  * 
  113.  * Revision 2.1  92/04/21  17:12:59  rwd
  114.  * BSDSS
  115.  * 
  116.  *
  117.  */
  118.  
  119. /*
  120.  * Copyright (c) 1982, 1986, 1988, 1991 Regents of the University of California.
  121.  * All rights reserved.
  122.  *
  123.  * Redistribution and use in source and binary forms, with or without
  124.  * modification, are permitted provided that the following conditions
  125.  * are met:
  126.  * 1. Redistributions of source code must retain the above copyright
  127.  *    notice, this list of conditions and the following disclaimer.
  128.  * 2. Redistributions in binary form must reproduce the above copyright
  129.  *    notice, this list of conditions and the following disclaimer in the
  130.  *    documentation and/or other materials provided with the distribution.
  131.  * 3. All advertising materials mentioning features or use of this software
  132.  *    must display the following acknowledgement:
  133.  *    This product includes software developed by the University of
  134.  *    California, Berkeley and its contributors.
  135.  * 4. Neither the name of the University nor the names of its contributors
  136.  *    may be used to endorse or promote products derived from this software
  137.  *    without specific prior written permission.
  138.  *
  139.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  140.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  141.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  142.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  143.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  144.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  145.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  146.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  147.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  148.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  149.  * SUCH DAMAGE.
  150.  *
  151.  *    @(#)uipc_mbuf.c    7.19 (Berkeley) 4/20/91
  152.  */
  153.  
  154. #include <conf.h>
  155.  
  156. #include <sys/param.h>
  157. #include <sys/malloc.h>
  158. #include <sys/mbuf.h>
  159. #include <sys/kernel.h>
  160. #include <sys/syslog.h>
  161. #include <sys/systm.h>
  162. #include <sys/domain.h>
  163. #include <sys/protosw.h>
  164. #include <sys/synch.h>
  165.  
  166. #include <kern/amiga_includes.h>
  167.  
  168. #include <dos/rdargs.h>
  169.  
  170. /*
  171.  * Configuration information.
  172.  */
  173. struct mbconf mbconf = {
  174.   2,                        /* # of mbuf chunks to allocate initially */
  175.   64,                /* # of mbufs to allocate at a time */
  176.   4,                /* # of clusters to allocate at a time */
  177.   256,                /* maximum memory to use (in kilobytes) */
  178.   2048                /* size of the mbuf cluster */
  179. };
  180.  
  181. /*
  182.  * List of free mbufs. Access to this list is protected by splimp()
  183.  */
  184. struct mbuf *mfree = NULL;
  185.  
  186. struct    mbstat mbstat = { 0 };
  187.  
  188. struct    mcluster *mclfree = NULL;
  189.  
  190. int    max_linkhdr = 0;        /* largest link-level header */
  191. int    max_protohdr = 0;        /* largest protocol header */
  192. int    max_hdr = 0;            /* largest link+protocol header */
  193. int    max_datalen = 0;        /* MHLEN - max_hdr */
  194.  
  195. /*
  196.  * Header structure that is placed at the start of every allocated memory 
  197.  * region to be freed on deinit. All memory alloctions are thus 
  198.  * sizeof(memHeader) larger and the data pointer is set past this header
  199.  * before used. These headers are linked together and the mbufmem pointer 
  200.  * holds the pointer to the start of the list.
  201.  */
  202. struct memHeader {
  203.   struct memHeader *next;
  204.   ULONG             size;
  205. };
  206.  
  207. static struct memHeader *mbufmem = NULL;
  208.  
  209. static BOOL initialized = FALSE;
  210.  
  211. LONG mb_read_stats(struct CSource *args, UBYTE **errstrp, struct CSource *res)
  212. {
  213.   int i, total = 0;
  214.   UBYTE *p = res->CS_Buffer;
  215.  
  216.   for(i = 0; i < MTCOUNT; i++) {
  217.     p += sprintf(p, "%ld ", mbstat.m_mtypes[i]);
  218.     total += mbstat.m_mtypes[i];
  219.   }
  220.   p += sprintf(p, "%ld", total);
  221.  
  222.   res->CS_CurChr =