* 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. */
| 162 | * kernel linkers to place module linker sets. |
| 163 | */ |
| 164 | void * |
| 165 | dpcpu_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. |
no test coverage detected