xref: /aoo41x/main/sal/rtl/source/alloc_cache.h (revision 514f4c20)
1*514f4c20SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*514f4c20SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*514f4c20SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*514f4c20SAndrew Rist  * distributed with this work for additional information
6*514f4c20SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*514f4c20SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*514f4c20SAndrew Rist  * "License"); you may not use this file except in compliance
9*514f4c20SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*514f4c20SAndrew Rist  *
11*514f4c20SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*514f4c20SAndrew Rist  *
13*514f4c20SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*514f4c20SAndrew Rist  * software distributed under the License is distributed on an
15*514f4c20SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*514f4c20SAndrew Rist  * KIND, either express or implied.  See the License for the
17*514f4c20SAndrew Rist  * specific language governing permissions and limitations
18*514f4c20SAndrew Rist  * under the License.
19*514f4c20SAndrew Rist  *
20*514f4c20SAndrew Rist  *************************************************************/
21*514f4c20SAndrew Rist 
22*514f4c20SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef INCLUDED_RTL_ALLOC_CACHE_H
25cdf0e10cSrcweir #define INCLUDED_RTL_ALLOC_CACHE_H
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "sal/types.h"
28cdf0e10cSrcweir #include "rtl/alloc.h"
29cdf0e10cSrcweir #include "alloc_impl.h"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #ifdef __cplusplus
32cdf0e10cSrcweir extern "C" {
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir 
35cdf0e10cSrcweir /** rtl_cache_stat_type
36cdf0e10cSrcweir  *  @internal
37cdf0e10cSrcweir  */
38cdf0e10cSrcweir typedef struct rtl_cache_stat_st rtl_cache_stat_type;
39cdf0e10cSrcweir struct rtl_cache_stat_st
40cdf0e10cSrcweir {
41cdf0e10cSrcweir 	sal_uInt64 m_alloc;
42cdf0e10cSrcweir 	sal_uInt64 m_free;
43cdf0e10cSrcweir 
44cdf0e10cSrcweir 	sal_Size   m_mem_total;
45cdf0e10cSrcweir 	sal_Size   m_mem_alloc;
46cdf0e10cSrcweir };
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 
49cdf0e10cSrcweir /** rtl_cache_bufctl_type
50cdf0e10cSrcweir  *  @internal
51cdf0e10cSrcweir  */
52cdf0e10cSrcweir typedef struct rtl_cache_bufctl_st rtl_cache_bufctl_type;
53cdf0e10cSrcweir struct rtl_cache_bufctl_st
54cdf0e10cSrcweir {
55cdf0e10cSrcweir 	rtl_cache_bufctl_type * m_next; /* linkage */
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 	sal_uIntPtr             m_addr; /* buffer address  */
58cdf0e10cSrcweir 	sal_uIntPtr             m_slab; /* parent slab address */
59cdf0e10cSrcweir };
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 
62cdf0e10cSrcweir /** rtl_cache_slab_type
63cdf0e10cSrcweir  *  @internal
64cdf0e10cSrcweir  */
65cdf0e10cSrcweir typedef struct rtl_cache_slab_st rtl_cache_slab_type;
66cdf0e10cSrcweir struct rtl_cache_slab_st
67cdf0e10cSrcweir {
68cdf0e10cSrcweir 	rtl_cache_slab_type *   m_slab_next; /* slab linkage */
69cdf0e10cSrcweir 	rtl_cache_slab_type *   m_slab_prev; /* slab linkage */
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	sal_Size                m_ntypes;    /* number of buffers used */
72cdf0e10cSrcweir 	sal_uIntPtr             m_data;      /* buffer start addr */
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	sal_uIntPtr             m_bp;        /* free buffer linkage 'base pointer'  */
75cdf0e10cSrcweir 	rtl_cache_bufctl_type * m_sp;        /* free buffer linkage 'stack pointer' */
76cdf0e10cSrcweir };
77cdf0e10cSrcweir 
78cdf0e10cSrcweir 
79cdf0e10cSrcweir /** rtl_cache_magazine_type
80cdf0e10cSrcweir  *  @internal
81cdf0e10cSrcweir  */
82cdf0e10cSrcweir #define RTL_CACHE_MAGAZINE_SIZE 61
83cdf0e10cSrcweir 
84cdf0e10cSrcweir typedef struct rtl_cache_magazine_st rtl_cache_magazine_type;
85cdf0e10cSrcweir struct rtl_cache_magazine_st
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	rtl_cache_magazine_type * m_mag_next; /* depot linkage */
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 	sal_Size                  m_mag_size;
90cdf0e10cSrcweir 	sal_Size                  m_mag_used;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	void *                    m_objects[RTL_CACHE_MAGAZINE_SIZE];
93cdf0e10cSrcweir };
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 
96cdf0e10cSrcweir /** rtl_cache_depot_type
97cdf0e10cSrcweir  *  @internal
98cdf0e10cSrcweir  */
99cdf0e10cSrcweir typedef struct rtl_cache_depot_st rtl_cache_depot_type;
100cdf0e10cSrcweir struct rtl_cache_depot_st
101cdf0e10cSrcweir {
102cdf0e10cSrcweir 	/* magazine list */
103cdf0e10cSrcweir 	rtl_cache_magazine_type * m_mag_next;  /* linkage */
104cdf0e10cSrcweir 	sal_Size                  m_mag_count; /* count */
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	/* working set parameters */
107cdf0e10cSrcweir 	sal_Size                  m_curr_min;
108cdf0e10cSrcweir 	sal_Size                  m_prev_min;
109cdf0e10cSrcweir };
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 
112cdf0e10cSrcweir /** rtl_cache_type
113cdf0e10cSrcweir  *  @internal
114cdf0e10cSrcweir  */
115cdf0e10cSrcweir #define RTL_CACHE_HASH_SIZE        8
116cdf0e10cSrcweir 
117cdf0e10cSrcweir #define RTL_CACHE_FEATURE_HASH        1
118cdf0e10cSrcweir #define RTL_CACHE_FEATURE_BULKDESTROY 2
119cdf0e10cSrcweir #define RTL_CACHE_FEATURE_RESCALE     4 /* within hash rescale operation */
120cdf0e10cSrcweir 
121cdf0e10cSrcweir struct rtl_cache_st
122cdf0e10cSrcweir {
123cdf0e10cSrcweir 	/* linkage */
124cdf0e10cSrcweir 	rtl_cache_type *          m_cache_next;
125cdf0e10cSrcweir 	rtl_cache_type *          m_cache_prev;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 	/* properties */
128cdf0e10cSrcweir 	char                      m_name[RTL_CACHE_NAME_LENGTH + 1];
129cdf0e10cSrcweir 	long                      m_features;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 	sal_Size                  m_type_size;   /* const */
132cdf0e10cSrcweir 	sal_Size                  m_type_align;  /* const */
133cdf0e10cSrcweir 	sal_Size                  m_type_shift;  /* log2(m_type_size); const */
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	int  (SAL_CALL * m_constructor)(void * obj, void * userarg); /* const */
136cdf0e10cSrcweir 	void (SAL_CALL * m_destructor) (void * obj, void * userarg); /* const */
137cdf0e10cSrcweir 	void (SAL_CALL * m_reclaim)    (void * userarg);             /* const */
138cdf0e10cSrcweir 	void *                    m_userarg;
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	/* slab layer */
141cdf0e10cSrcweir 	rtl_memory_lock_type      m_slab_lock;
142cdf0e10cSrcweir 	rtl_cache_stat_type       m_slab_stats;
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	rtl_arena_type *          m_source;     /* slab supplier; const */
145cdf0e10cSrcweir 	sal_Size                  m_slab_size;  /* const */
146cdf0e10cSrcweir 	sal_Size                  m_ntypes;     /* number of buffers per slab; const */
147cdf0e10cSrcweir 	sal_Size                  m_ncolor;     /* next slab color */
148cdf0e10cSrcweir 	sal_Size                  m_ncolor_max; /* max. slab color */
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 	rtl_cache_slab_type       m_free_head;
151cdf0e10cSrcweir 	rtl_cache_slab_type       m_used_head;
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 	rtl_cache_bufctl_type **  m_hash_table;
154cdf0e10cSrcweir 	rtl_cache_bufctl_type *   m_hash_table_0[RTL_CACHE_HASH_SIZE];
155cdf0e10cSrcweir 	sal_Size                  m_hash_size;  /* m_hash_mask + 1   */
156cdf0e10cSrcweir 	sal_Size                  m_hash_shift; /* log2(m_hash_size) */
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 	/* depot layer */
159cdf0e10cSrcweir 	rtl_memory_lock_type      m_depot_lock;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	rtl_cache_depot_type      m_depot_empty;
162cdf0e10cSrcweir 	rtl_cache_depot_type      m_depot_full;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 	rtl_cache_type *          m_magazine_cache; /* magazine supplier; const */
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 	/* cpu layer */
167cdf0e10cSrcweir 	rtl_cache_magazine_type * m_cpu_curr;
168cdf0e10cSrcweir 	rtl_cache_magazine_type * m_cpu_prev;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 	rtl_cache_stat_type       m_cpu_stats;
171cdf0e10cSrcweir };
172cdf0e10cSrcweir 
173cdf0e10cSrcweir 
174cdf0e10cSrcweir #ifdef __cplusplus
175cdf0e10cSrcweir }
176cdf0e10cSrcweir #endif
177cdf0e10cSrcweir 
178cdf0e10cSrcweir #endif /* INCLUDED_RTL_ALLOC_CACHE_H */
179