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

Last change on this file since 21 was 18, checked in by max@…, 7 years ago

cosmetic, and a few typos

File size: 6.1 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 embedded 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 up to (CONFIG_PPM_PAGE_SIZE / CONFIG_CACHE_LINE_SIZE) blocks.
67 * This kcm page descriptor is stored in the first slot of the page.
68 ***************************************************************************************/
69
70typedef struct kcm_page_s
71{
72        BITMAP          ( bitmap , CONFIG_KCM_BLOCKS_MAX );
73        uint8_t       * base;                  /*! pointer on first block in page          */
74        kcm_t         * kcm;                   /*! owner KCM allocator                     */
75        list_entry_t    list;                  /*! [active / busy / free] list member      */
76        page_t        * page;                  /*! pointer on the physical page descriptor */
77        uint8_t         refcount;              /*! number of allocated blocks              */
78        uint8_t         busy;                  /*! page busy if non zero                   */
79        uint8_t         active;                /*! page active if non zero                 */
80        uint8_t         unused;                /*!                                         */
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 ***************************************************************************************/
90void 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 * @ return pointer on allocated block if success / return NULL if failure
106 ***************************************************************************************/
107void * kcm_alloc( kcm_t * kcm );
108
109/****************************************************************************************
110 * This function releases a previouly allocated block containing one object.
111 ****************************************************************************************
112 * @ ptr   : local pointer on the allocated buffer.
113 ***************************************************************************************/
114void  kcm_free( void * ptr );
115
116/****************************************************************************************
117 * This function prints KCM allocator state (for debug only).
118 ****************************************************************************************
119 * @ kcm   : local pointer on the selected KCM allocator.
120 ***************************************************************************************/
121void kcm_print( kcm_t * kcm );
122
123
124
125#endif  /* _KCM_H_ */
Note: See TracBrowser for help on using the repository browser.