22#if defined(XWMM_BMA_LOG)
23# define xwmm_bmalogf(lv, fmt, ...) xwlogf(lv, "BMA", fmt, ##__VA_ARGS__)
25# define xwmm_bmalogf(lv, fmt, ...)
73 if (size != (num * blksize)) {
75 xwmm_bmalogf(ERR,
"Size of memory(0x%lX, 0x%lX) is error!\n",
88 "memory:(0x%lX,0x%lX),orderlists:0x%lX,bcbs:0x%lX,"
89 "blocksize:0x%lX, blockorder:0x%lX\n",
93 for (i = 0; i < num; i++) {
98 for (i = 0; i <= blkodr; i++) {
123 if (ofs == (idx * bma->
blksize)) {
124 bcb = &bma->
bcbs[idx];
164 return &bma->
bcbs[seq];
186 "[OL:0x%lX][+] bcb(idx:0x%lX,odr:0x%X),mem(0x%lX)\n",
220 "[OL:0x%lX][-] bcb(idx:0x%lX,odr:0x%X),mem(0x%lX)\n",
226 if (odr != bcb->
order) {
257 "[OL:0x%lX][C] bcb(idx:0x%lX,odr:0x%X)\n",
287 while (blk_odr > target_odr) {
290 blk_ofs = 1U << blk_odr;
291 buddy = &bma->
bcbs[blk_idx + blk_ofs];
299 "[ALLOC][D] bcb(idx:0x%lX,odr:0x%X),"
300 "buddy(idx:0x%lX,odr:0x%X)\n",
339 "[ALLOC] bcb(idx:0x%lX,odr:0x%X)\n",
366 target_odr = curr_odr + (
xwsq_t)1;
367 while (target_odr <= bma->blkodr) {
370 "[FREE][M] bcb(idx:0x%lX,odr:0x%X),"
371 "buddy(idx:0x%lX,odr:0x%X)\n",
395 curr_odr = target_odr;
411 if ((((
xwptr_t)mem < bma->zone.origin) ||
422 "[FREE] mem:0x%lX,bcb(idx:0x%lX,odr:0x%X)\n",
static struct xwmm_bma_bcb * xwmm_bma_mem_to_bcb(struct xwmm_bma *bma, void *mem)
从内存块首地址获得其控制块的指针
static void xwmm_bma_combine(struct xwmm_bma *bma, struct xwmm_bma_bcb *bcb)
合并内存块
static void xwmm_bma_orderlist_add(struct xwmm_bma *bma, struct xwmm_bma_orderlist *ol, xwu8_t odr, struct xwmm_bma_bcb *bcb)
将一块内存加入到阶链表
static struct xwmm_bma_bcb * xwmm_bma_orderlist_choose(struct xwmm_bma *bma, struct xwmm_bma_orderlist *ol)
从阶链表中选择一块内存,并返回其块控制块
#define xwmm_bmalogf(lv, fmt,...)
static struct xwmm_bma_bcb * xwmm_bma_find_buddy(struct xwmm_bma *bma, struct xwmm_bma_bcb *bcb)
寻找内存块的伙伴
static void * xwmm_bma_bcb_to_mem(struct xwmm_bma *bma, struct xwmm_bma_bcb *bcb)
从内存块的控制块指针获得内存块的首地址
static xwer_t xwmm_bma_orderlist_remove(struct xwmm_bma *bma, struct xwmm_bma_orderlist *ol, xwu8_t odr, struct xwmm_bma_bcb *bcb)
从阶链表中删除一块内存
static void xwmm_bma_divide_block(struct xwmm_bma *bma, struct xwmm_bma_bcb *bcb, xwsq_t target_odr, struct xwmm_bma_orderlist *curr_ol)
将大内存块分割成小块
#define XWMM_BMA_ORDER_MASK
xwer_t xwmm_bma_init(struct xwmm_bma *bma, const char *name, xwptr_t origin, xwsz_t size, xwsz_t blksize, xwsz_t blkodr)
XWMM API:初始化伙伴算法内存块分配器
xwer_t xwmm_bma_free(struct xwmm_bma *bma, void *mem)
XWMM API:释放内存块
#define XWMM_BMA_COMBINED
xwer_t xwmm_bma_alloc(struct xwmm_bma *bma, xwsq_t order, void **membuf)
XWMM API:申请一块连续的内存
static void xwlib_bclst_init_head(struct xwlib_bclst_node *h)
初始化一个链表头。
static void xwlib_bclst_init_node(struct xwlib_bclst_node *n)
初始化一个链表节点。
static bool xwlib_bclst_tst_empty(const struct xwlib_bclst_node *h)
测试链表是否为空。
static void xwlib_bclst_add_head(struct xwlib_bclst_node *head, struct xwlib_bclst_node *newn)
将一个节点加入链表头部(链表头的后面)
static void xwlib_bclst_del_init(struct xwlib_bclst_node *node)
删除一个节点,并重新初始化它
#define ENOENT
No such file or directory
#define EINVAL
Invalid argument
#define EFAULT
Bad address
#define ESRCH
No such process
#define ENOMEM
Not enough space
#define ERANGE
Result too large
static __xwcc_inline void *__xwcc_must_check err_ptr(xwer_t err)
将错误码转换为指针
static __xwcc_inline bool __xwcc_must_check is_err(const void *ptr)
测试指针的值是否为错误码
static __xwcc_inline xwer_t __xwcc_must_check ptr_err(const void *ptr)
将指针的值转换为错误码
static void xwos_splk_unlock_cpuirqrs(struct xwos_splk *spl, xwreg_t cpuirq)
XWOS API:解锁自旋锁,并恢复本地CPU的中断标志
static void xwos_splk_init(struct xwos_splk *spl)
XWOS API:初始化自旋锁
static void xwos_splk_lock_cpuirqsv(struct xwos_splk *spl, xwreg_t *cpuirq)
XWOS API:上锁自旋锁,保存本地CPU的中断标志并关闭
#define XWOS_VALIDATE(exp, errstr,...)
检查函数参数是否有效
struct xwlib_bclst_node * next
struct xwlib_bclst_node head
struct xwmm_bma_orderlist * orderlists
struct xwmm_bma_bcb * bcbs