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

Last change on this file since 663 was 657, checked in by alain, 5 years ago

Introduce remote_buf.c/.h & socket.c/.h files.
Update dev_nic.c/.h files.

File size: 7.7 KB
Line 
1/*
2 * kcm.h - Kernel Cache Manager definition.
3 *
4 * Authors    Alain Greiner (2016,2017,2018,2019)
5 *
6 * Copyright (c) UPMC Sorbonne Universites
7 *
8 * This file is part of ALMOS-MKH.
9 *
10 * ALMOS-MKH is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.0 of the License.
13 *
14 * ALMOS-MKH is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with ALMOS-MKH; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef _KCM_H_
25#define _KCM_H_
26
27#include <list.h>
28#include <hal_kernel_types.h>
29#include <busylock.h>
30#include <page.h>
31#include <bits.h>
32#include <kmem.h>
33
34
35#define KCM_PAGE_FULL     0
36#define KCM_PAGE_EMPTY    1
37#define KCM_PAGE_ACTIVE   2
38
39/****************************************************************************************
40 * This structure defines a generic Kernel Cache Manager, that is a block allocator,
41 * for fixed size objects. It exists in each cluster a specific KCM allocator for
42 * the following block sizes: 64, 128, 256, 512, 1024, 2048 bytes.
43 * These six KCM allocators are initialized by the cluster_init() function.
44 *
45 * Each KCM cache is implemented as a set o 4 Kbytes pages. A kcm_page is split in slots,
46 * where each slot can contain one block. in each kcm_page, the first slot (that cannot
47 * be smaller than 64 bytes) contains the kcm page descriptor, defined below
48 *
49 * To allow any thread running in any cluster to directly access the KCM of any cluster,
50 * ALMOS-MKH defines two sets of access functions, for local or remote access.
51 ***************************************************************************************/
52
53typedef struct kcm_s
54{
55        remote_busylock_t    lock;             /*! protect KCM allocator                   */
56
57        list_entry_t         full_root;        /*! root of full pages list                 */
58        list_entry_t         active_root;      /*! root of active pages list               */
59
60        uint32_t             full_pages_nr;    /*! number of busy pages                    */
61        uint32_t             active_pages_nr;  /*! number of active pages                  */
62
63        uint32_t             order;            /*! ln( block_size )                        */
64        uint32_t             max_blocks;       /*! max number of blocks per page           */
65}
66kcm_t;
67
68
69/****************************************************************************************
70 * This structure defines a KCM-page descriptor.
71 * A KCM-page contains at most (CONFIG_PPM_PAGE_SIZE / CONFIG_KCM_SLOT_SIZE) slots,
72 * and each slot contains one block. The kcm page descriptor is stored in first slot.
73 * The current allocation status is defined by the 64 bits "status" bit vector: each
74 * non zero bit defines an allocated block / "counts is the number of allocated blocks.
75 * Each kcm_page is registered in one of the two following page_list:
76 * - full   : when count == max
77 * - active : count < max
78 ***************************************************************************************/
79
80typedef struct kcm_page_s
81{
82        uint64_t            status;            /*! bit vector: non-zero == allocated       */
83        uint32_t            count;             /*! number of allocated blocks in page      */
84        list_entry_t        list;              /*! [active / busy / free] list member      */
85        kcm_t             * kcm;               /*! pointer on kcm allocator                */
86        page_t            * page;              /*! pointer on the physical page descriptor */
87}
88kcm_page_t;
89
90/****************************************************************************************
91 * This function must be called by a local thread.
92 * It initializes a Kernel Cache Manager, depending on block size.
93 ****************************************************************************************
94 * @ kcm      : pointer on KCM to be initialized.
95 * @ order    : ln(block_size).
96 ***************************************************************************************/
97void kcm_init( kcm_t    * kcm,
98               uint32_t   order );
99
100/****************************************************************************************
101 * This function must be called by a local thread.
102 * It releases all memory allocated to a Kernel Cache Manager.
103 ****************************************************************************************
104 * @ kcm      : pointer on KCM manager to destroy.
105 ***************************************************************************************/
106void kcm_destroy( kcm_t  * kcm );
107
108/****************************************************************************************
109 * This function must be called by a local thread.
110 * It allocates one block from the local Kernel Cache Manager.
111 ****************************************************************************************
112 * @ order     :  ln( block-size ) == KCM allocator identifier.
113 * @ return pointer on allocated block if success / return NULL if failure
114 ***************************************************************************************/
115void * kcm_alloc( uint32_t order );
116
117/****************************************************************************************
118 * This function must be called by a local thread.
119 * It releases a previouly allocated block to the local Kernel Cache Manager.
120 ****************************************************************************************
121 * @ block_ptr   : local pointer on the released block.
122 ***************************************************************************************/
123void kcm_free( void    * block_ptr );
124
125
126
127
128/****************************************************************************************
129 * This function can be called by any thread running in any cluster.
130 * It allocates one fixed size block from a remote Kernel Cache Manager.
131 ****************************************************************************************
132 * @ kcm_cxy   : remote KCM cluster identifier.
133 * @ order     :  ln( block-size ) == KCM allocator identifier.
134 * @ return a local pointer on allocated block if success / return NULL if failure
135 ***************************************************************************************/
136void * kcm_remote_alloc( cxy_t    kcm_cxy,
137                         uint32_t order );
138
139/****************************************************************************************
140 * This function can be called by any thread running in any cluster.
141 * It releases a previouly allocated block to a remote Kernel Cache Manager.
142 ****************************************************************************************
143 * @ kcm_cxy     : remote KCM cluster identifier.
144 * @ block_ptr   : local pointer on the released buffer in remote cluster.
145 ***************************************************************************************/
146void kcm_remote_free( cxy_t     kcm_cxy,
147                      void    * block_ptr );
148
149/****************************************************************************************
150 * This debug function can be called by any thread running in any cluster.
151 * It diplays on TXT0 the current state of a local KCM allocator.
152 ****************************************************************************************
153 * @ kcm_cxy : remote KCM cluster identifier.
154 * @ kcm_ptr : local pointer on remote KCM.
155 ***************************************************************************************/
156void kcm_remote_display( cxy_t   kcm_cxy,
157                         kcm_t * kcm_ptr );
158
159#endif  /* _KCM_H_ */
Note: See TracBrowser for help on using the repository browser.