source: trunk/kernel/mm/kcm.h @ 5

Last change on this file since 5 was 1, checked in by alain, 8 years ago

First import

File size: 6.0 KB
Line 
1/*
2 * kcm.h - Per-cluster Kernel Cache Manager Interface
3 *
4 * Authors  Ghassan Almaless (2008,2009,2010,2011,2012)
5 *          Alain Greiner    (2016)
6 *
7 * Copyright (c) UPMC Sorbonne Universites
8 *
9 * This file is part of ALMOS-MKH.
10 *
11 * ALMOS-MKH is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; version 2.0 of the License.
14 *
15 * ALMOS-MKH is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
22 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#ifndef _KCM_H_
26#define _KCM_H_
27
28#include <list.h>
29#include <hal_types.h>
30#include <spinlock.h>
31#include <page.h>
32#include <bits.h>
33#include <kmem.h>
34
35/****************************************************************************************
36 * This structure defines a generic Kernel Cache Manager, that is a block allocator,
37 * for fixed size objects. It exists a specific KCM allocator for each object type.
38 * The actual allocated block size is the smallest multiple of 64 bytes that can
39 * contain one single object.
40 * The various KCM allocators themselves are not statically allocated in the cluster
41 * manager, but are dynamically allocated when required, using the specific KCM
42 * allocator defined in the cluster manager, to allocate the other ones...
43 ***************************************************************************************/
44
45typedef struct kcm_s                     
46{
47        spinlock_t           lock;             /*! protect exclusive access to allocator   */
48        uint32_t             block_size;       /*! actual block size (bytes)               */
49        uint32_t             blocks_nr;        /*! number of blocks per page               */
50
51        list_entry_t         active_root;      /*! root of active pages list               */
52        list_entry_t         busy_root;        /*! root of busy pages list                 */
53        list_entry_t         free_root;        /*! root of free pages list                 */
54
55        uint32_t             free_pages_nr;    /*! number of free pages                    */
56        uint32_t             busy_pages_nr;    /*! number of busy pages                    */
57        uint32_t             active_pages_nr;  /*! number of active pages                  */
58
59    uint32_t             type;             /*! KCM type                                */
60} 
61kcm_t;
62
63
64/****************************************************************************************
65 * This structure defines a KCM-page descriptor.
66 * A KCM-page can contain several blocks.
67 * This descriptor is stored in the first block slot.
68 ***************************************************************************************/
69
70typedef struct kcm_page_s
71{
72        BITMAP          ( bitmap , 16 );       /*! at most 16 blocks in a page (1 if free) */
73        uint8_t       * blk_tbl;               /*! pointer on first free block in page     */
74        kcm_t         * kcm;                   /*! owner KCM allocator                     */
75        uint8_t         unused;                /*! first free block index in page          */
76        uint8_t         refcount;              /*! number of allocated blocks              */
77        uint8_t         busy;                  /*! page busy if non zero                   */
78        uint8_t         active;                /*! page active if non zero                 */
79        list_entry_t    list;                  /*! [active / busy / free] list member      */
80        page_t        * page;                  /*! pointer on the physical page descriptor */
81} 
82kcm_page_t;
83
84/****************************************************************************************
85 * This function initializes a generic Kernel Cache Manager.
86 ****************************************************************************************
87 * @ kcm      : pointer on KCM manager to initialize.
88 * @ type     : KCM allocator type.
89 ***************************************************************************************/
90error_t kcm_init( kcm_t       * kcm,
91                          uint32_t      type );
92
93/****************************************************************************************
94 * This function releases all memory allocated to a generic Kernel Cache Manager.
95 ****************************************************************************************
96 * @ kcm      : pointer on KCM manager to destroy.
97 ***************************************************************************************/
98void kcm_destroy( kcm_t       * kcm );
99
100/****************************************************************************************
101 * This function allocates one single object in a Kernel Cache Manager
102 * The object size must be smaller than one page size.
103 ****************************************************************************************
104 * @ kcm     :  pointer on the selected KCM allocator
105 ***************************************************************************************/
106void * kcm_alloc( kcm_t * kcm );
107
108/****************************************************************************************
109 * This function releases a previouly allocated block containing one object.
110 ****************************************************************************************
111 * @ ptr   : local pointer on the allocated buffer.
112 ***************************************************************************************/
113void  kcm_free( void * ptr );
114
115/****************************************************************************************
116 * This function prints KCM allocator state (for debug only).
117 ****************************************************************************************
118 * @ kcm   : local pointer on the selected KCM allocator.
119 ***************************************************************************************/
120void kcm_print( kcm_t * kcm );
121
122
123
124#endif  /* _KCM_H_ */
Note: See TracBrowser for help on using the repository browser.