-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathalloc_pool.c
More file actions
164 lines (133 loc) · 4.93 KB
/
alloc_pool.c
File metadata and controls
164 lines (133 loc) · 4.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* Copyright (C) 2019 ETH Zurich, University of Bologna
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "pulp.h"
#include <string.h>
#include <stdio.h>
#if defined(ARCHI_HAS_L1)
pos_alloc_t pos_alloc_l1[ARCHI_NB_CLUSTER];
#endif
#if defined(ARCHI_HAS_FC_TCDM)
pos_alloc_t pos_alloc_fc_tcdm;
#endif
#if defined(ARCHI_HAS_L2)
pos_alloc_t pos_alloc_l2[POS_NB_ALLOC_L2];
#endif
#ifdef CONFIG_ALLOC_L2_PWD_NB_BANKS
static uint32_t pos_alloc_account_0[CONFIG_ALLOC_L2_PWD_NB_BANKS];
static uint32_t pos_alloc_account_1[CONFIG_ALLOC_L2_PWD_NB_BANKS];
#endif
#if defined(ARCHI_HAS_FC_TCDM)
static inline pos_alloc_t *get_fc_alloc() { return &pos_alloc_fc_tcdm; }
#else
static inline pos_alloc_t *get_fc_alloc() { return &pos_alloc_l2[0]; }
#endif
void pos_allocs_init()
{
#if defined(ARCHI_HAS_L2)
#if defined(ARCHI_HAS_L2_MULTI)
//pos_trace(//pos_trace_INIT, "Initializing L2 private bank0 allocator (base: 0x%8x, size: 0x%8x)\n", (int)pos_l2_priv0_base(), pos_l2_priv0_size());
pos_alloc_init(&pos_alloc_l2[0], pos_l2_priv0_base(), pos_l2_priv0_size());
//pos_trace(//pos_trace_INIT, "Initializing L2 private bank1 allocator (base: 0x%8x, size: 0x%8x)\n", (int)pos_l2_priv1_base(), pos_l2_priv1_size());
pos_alloc_init(&pos_alloc_l2[1], pos_l2_priv1_base(), pos_l2_priv1_size());
//pos_trace(//pos_trace_INIT, "Initializing L2 shared banks allocator (base: 0x%8x, size: 0x%8x)\n", (int)pos_l2_shared_base(), pos_l2_shared_size());
pos_alloc_init(&pos_alloc_l2[2], pos_l2_shared_base(), pos_l2_shared_size());
#ifdef CONFIG_ALLOC_L2_PWD_NB_BANKS
pos_alloc_l2[2].track_pwd = 1;
pos_alloc_l2[2].pwd_count = pos_alloc_account_0;
pos_alloc_l2[2].ret_count = pos_alloc_account_0;
for (int i=0; i<CONFIG_ALLOC_L2_PWD_NB_BANKS; i++)
{
pos_alloc_l2[2].pwd_count[i] = 0;
pos_alloc_l2[2].ret_count[i] = 0;
}
pos_alloc_l2[2].bank_size_log2 = CONFIG_ALLOC_L2_PWD_BANK_SIZE_LOG2;
pos_alloc_l2[2].first_bank_addr = ARCHI_L2_SHARED_ADDR;
pos_alloc_account_free(&pos_alloc_l2[2], pos_l2_shared_base() - sizeof(pos_alloc_chunk_t), pos_l2_shared_size() + sizeof(pos_alloc_chunk_t));
#endif
#else
//pos_trace(//pos_trace_INIT, "Initializing L2 allocator (base: 0x%8x, size: 0x%8x)\n", (int)pos_l2_base(), pos_l2_size());
pos_alloc_init(&pos_alloc_l2[0], pos_l2_base(), pos_l2_size());
#endif
#endif
#if defined(ARCHI_HAS_FC_TCDM)
//pos_trace(//pos_trace_INIT, "Initializing FC TCDM allocator (base: 0x%8x, size: 0x%8x)\n", (int)pos_fc_tcdm_base(), pos_fc_tcdm_size());
pos_alloc_init(&pos_alloc_fc_tcdm, pos_fc_tcdm_base(), pos_fc_tcdm_size());
#endif
}
void *pos_alloc_user_data(int size)
{
#if defined(ARCHI_HAS_FC_TCDM)
return pos_alloc(&pos_alloc_fc_tcdm, size);
#elif defined(ARCHI_HAS_L2_MULTI)
// We try all the available L2 banks.
for (int i=0; i<3; i++) {
void *result = pos_alloc(&pos_alloc_l2[i], size);
if (result != NULL) return result;
}
// No available memory in any bank.
return NULL;
#else // i.e. we have a single l2 bank for data.
return pos_alloc(&pos_alloc_l2[0], size);
#endif
}
void pos_free_user_data(void *_chunk, int size)
{
#if defined(ARCHI_HAS_FC_TCDM)
pos_free(&pos_alloc_fc_tcdm, _chunk, size);
#elif defined(ARCHI_HAS_L2_MULTI)
// We deduce which l2 bank the chunk came from by looking at its address.
pos_alloc_t *allocator;
unsigned int base = (unsigned int) _chunk;
if (base < (unsigned int) pos_l2_priv0_base() + pos_l2_priv0_size()) allocator = &pos_alloc_l2[0];
else if (base < (unsigned int) pos_l2_priv1_base() + pos_l2_priv1_size()) allocator = &pos_alloc_l2[1];
else allocator = &pos_alloc_l2[2];
pos_free(allocator, _chunk, size);
#else
pos_free(&pos_alloc_l2[0]);
#endif
}
#if defined(ARCHI_HAS_L1)
void alloc_init_l1(int cid)
{
pos_alloc_init(&pos_alloc_l1[cid], pos_l1_base(cid), pos_l1_size(cid));
}
void *pi_l1_malloc(int cid, int size)
{
return pos_alloc(&pos_alloc_l1[cid], size);
}
void pi_l1_free(int cid, void *chunk, int size)
{
return pos_free(&pos_alloc_l1[cid], chunk, size);
}
#endif
void *pi_l2_malloc(int size)
{
return pos_alloc(&pos_alloc_l2[0], size);
}
void pi_l2_free(void *_chunk, int size)
{
return pos_free(&pos_alloc_l2[0], _chunk, size);
}
#if defined(ARCHI_HAS_FC_TCDM)
void *pi_fc_tcdm_malloc(int size)
{
return pos_alloc(&pos_alloc_fc_tcdm, size);
}
void pi_fc_tcdm_free(void *_chunk, int size)
{
return pos_free(&pos_alloc_fc_tcdm, _chunk, size);
}
#endif