MCPcopy Create free account
hub / github.com/F-Stack/f-stack / dpcpu_alloc

Function dpcpu_alloc

freebsd/kern/subr_pcpu.c:164–190  ·  view source on GitHub ↗

* First-fit extent based allocator for allocating space in the per-cpu * region reserved for modules. This is only intended for use by the * kernel linkers to place module linker sets. */

Source from the content-addressed store, hash-verified

162 * kernel linkers to place module linker sets.
163 */
164void *
165dpcpu_alloc(int size)
166{
167 struct dpcpu_free *df;
168 void *s;
169
170 s = NULL;
171 size = roundup2(size, sizeof(void *));
172 sx_xlock(&dpcpu_lock);
173 TAILQ_FOREACH(df, &dpcpu_head, df_link) {
174 if (df->df_len < size)
175 continue;
176 if (df->df_len == size) {
177 s = (void *)df->df_start;
178 TAILQ_REMOVE(&dpcpu_head, df, df_link);
179 free(df, M_PCPU);
180 break;
181 }
182 s = (void *)df->df_start;
183 df->df_len -= size;
184 df->df_start = df->df_start + size;
185 break;
186 }
187 sx_xunlock(&dpcpu_lock);
188
189 return (s);
190}
191
192/*
193 * Free dynamic per-cpu space at module unload time.

Callers 3

link_elf_link_preloadFunction · 0.85
link_elf_load_fileFunction · 0.85
parse_dpcpuFunction · 0.85

Calls 1

freeFunction · 0.70

Tested by

no test coverage detected