Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lfmiao0
rt-thread
提交
163772fb
R
rt-thread
项目概览
lfmiao0
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
163772fb
编写于
3月 20, 2019
作者:
lymzzyh
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix slab at 64bits CPU
上级
c9d88a8e
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
21 addition
and
21 deletion
+21
-21
src/slab.c
src/slab.c
+21
-21
未找到文件。
src/slab.c
浏览文件 @
163772fb
...
@@ -217,9 +217,9 @@ struct memusage
...
@@ -217,9 +217,9 @@ struct memusage
};
};
static
struct
memusage
*
memusage
=
RT_NULL
;
static
struct
memusage
*
memusage
=
RT_NULL
;
#define btokup(addr) \
#define btokup(addr) \
(&memusage[((rt_u
int32
_t)(addr) - heap_start) >> RT_MM_PAGE_BITS])
(&memusage[((rt_u
base
_t)(addr) - heap_start) >> RT_MM_PAGE_BITS])
static
rt_u
int32
_t
heap_start
,
heap_end
;
static
rt_u
base
_t
heap_start
,
heap_end
;
/* page allocator */
/* page allocator */
struct
rt_page_head
struct
rt_page_head
...
@@ -275,7 +275,7 @@ void rt_page_free(void *addr, rt_size_t npages)
...
@@ -275,7 +275,7 @@ void rt_page_free(void *addr, rt_size_t npages)
struct
rt_page_head
**
prev
;
struct
rt_page_head
**
prev
;
RT_ASSERT
(
addr
!=
RT_NULL
);
RT_ASSERT
(
addr
!=
RT_NULL
);
RT_ASSERT
((
rt_u
int32
_t
)
addr
%
RT_MM_PAGE_SIZE
==
0
);
RT_ASSERT
((
rt_u
base
_t
)
addr
%
RT_MM_PAGE_SIZE
==
0
);
RT_ASSERT
(
npages
!=
0
);
RT_ASSERT
(
npages
!=
0
);
n
=
(
struct
rt_page_head
*
)
addr
;
n
=
(
struct
rt_page_head
*
)
addr
;
...
@@ -348,13 +348,13 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
...
@@ -348,13 +348,13 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
RT_DEBUG_NOT_IN_INTERRUPT
;
RT_DEBUG_NOT_IN_INTERRUPT
;
/* align begin and end addr to page */
/* align begin and end addr to page */
heap_start
=
RT_ALIGN
((
rt_u
int32
_t
)
begin_addr
,
RT_MM_PAGE_SIZE
);
heap_start
=
RT_ALIGN
((
rt_u
base
_t
)
begin_addr
,
RT_MM_PAGE_SIZE
);
heap_end
=
RT_ALIGN_DOWN
((
rt_u
int32
_t
)
end_addr
,
RT_MM_PAGE_SIZE
);
heap_end
=
RT_ALIGN_DOWN
((
rt_u
base
_t
)
end_addr
,
RT_MM_PAGE_SIZE
);
if
(
heap_start
>=
heap_end
)
if
(
heap_start
>=
heap_end
)
{
{
rt_kprintf
(
"rt_system_heap_init, wrong address[0x%x - 0x%x]
\n
"
,
rt_kprintf
(
"rt_system_heap_init, wrong address[0x%x - 0x%x]
\n
"
,
(
rt_u
int32_t
)
begin_addr
,
(
rt_uint32
_t
)
end_addr
);
(
rt_u
base_t
)
begin_addr
,
(
rt_ubase
_t
)
end_addr
);
return
;
return
;
}
}
...
@@ -391,7 +391,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
...
@@ -391,7 +391,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
memusage
=
rt_page_alloc
(
limsize
/
RT_MM_PAGE_SIZE
);
memusage
=
rt_page_alloc
(
limsize
/
RT_MM_PAGE_SIZE
);
RT_DEBUG_LOG
(
RT_DEBUG_SLAB
,
(
"memusage 0x%x, size 0x%x
\n
"
,
RT_DEBUG_LOG
(
RT_DEBUG_SLAB
,
(
"memusage 0x%x, size 0x%x
\n
"
,
(
rt_u
int32
_t
)
memusage
,
limsize
));
(
rt_u
base
_t
)
memusage
,
limsize
));
}
}
/*
/*
...
@@ -401,7 +401,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
...
@@ -401,7 +401,7 @@ void rt_system_heap_init(void *begin_addr, void *end_addr)
rt_inline
int
zoneindex
(
rt_size_t
*
bytes
)
rt_inline
int
zoneindex
(
rt_size_t
*
bytes
)
{
{
/* unsigned for shift opt */
/* unsigned for shift opt */
rt_u
int32_t
n
=
(
rt_uint32
_t
)(
*
bytes
);
rt_u
base_t
n
=
(
rt_ubase
_t
)(
*
bytes
);
if
(
n
<
128
)
if
(
n
<
128
)
{
{
...
@@ -507,7 +507,7 @@ void *rt_malloc(rt_size_t size)
...
@@ -507,7 +507,7 @@ void *rt_malloc(rt_size_t size)
(
"malloc a large memory 0x%x, page cnt %d, kup %d
\n
"
,
(
"malloc a large memory 0x%x, page cnt %d, kup %d
\n
"
,
size
,
size
,
size
>>
RT_MM_PAGE_BITS
,
size
>>
RT_MM_PAGE_BITS
,
((
rt_u
int32
_t
)
chunk
-
heap_start
)
>>
RT_MM_PAGE_BITS
));
((
rt_u
base
_t
)
chunk
-
heap_start
)
>>
RT_MM_PAGE_BITS
));
/* lock heap */
/* lock heap */
rt_sem_take
(
&
heap_sem
,
RT_WAITING_FOREVER
);
rt_sem_take
(
&
heap_sem
,
RT_WAITING_FOREVER
);
...
@@ -610,7 +610,7 @@ void *rt_malloc(rt_size_t size)
...
@@ -610,7 +610,7 @@ void *rt_malloc(rt_size_t size)
rt_sem_take
(
&
heap_sem
,
RT_WAITING_FOREVER
);
rt_sem_take
(
&
heap_sem
,
RT_WAITING_FOREVER
);
RT_DEBUG_LOG
(
RT_DEBUG_SLAB
,
(
"alloc a new zone: 0x%x
\n
"
,
RT_DEBUG_LOG
(
RT_DEBUG_SLAB
,
(
"alloc a new zone: 0x%x
\n
"
,
(
rt_u
int32
_t
)
z
));
(
rt_u
base
_t
)
z
));
/* set message usage */
/* set message usage */
for
(
off
=
0
,
kup
=
btokup
(
z
);
off
<
zone_page_cnt
;
off
++
)
for
(
off
=
0
,
kup
=
btokup
(
z
);
off
<
zone_page_cnt
;
off
++
)
...
@@ -694,7 +694,7 @@ void *rt_realloc(void *ptr, rt_size_t size)
...
@@ -694,7 +694,7 @@ void *rt_realloc(void *ptr, rt_size_t size)
* Get the original allocation's zone. If the new request winds up
* Get the original allocation's zone. If the new request winds up
* using the same chunk size we do not have to do anything.
* using the same chunk size we do not have to do anything.
*/
*/
kup
=
btokup
((
rt_u
int32
_t
)
ptr
&
~
RT_MM_PAGE_MASK
);
kup
=
btokup
((
rt_u
base
_t
)
ptr
&
~
RT_MM_PAGE_MASK
);
if
(
kup
->
type
==
PAGE_TYPE_LARGE
)
if
(
kup
->
type
==
PAGE_TYPE_LARGE
)
{
{
rt_size_t
osize
;
rt_size_t
osize
;
...
@@ -709,7 +709,7 @@ void *rt_realloc(void *ptr, rt_size_t size)
...
@@ -709,7 +709,7 @@ void *rt_realloc(void *ptr, rt_size_t size)
}
}
else
if
(
kup
->
type
==
PAGE_TYPE_SMALL
)
else
if
(
kup
->
type
==
PAGE_TYPE_SMALL
)
{
{
z
=
(
slab_zone
*
)(((
rt_u
int32
_t
)
ptr
&
~
RT_MM_PAGE_MASK
)
-
z
=
(
slab_zone
*
)(((
rt_u
base
_t
)
ptr
&
~
RT_MM_PAGE_MASK
)
-
kup
->
size
*
RT_MM_PAGE_SIZE
);
kup
->
size
*
RT_MM_PAGE_SIZE
);
RT_ASSERT
(
z
->
z_magic
==
ZALLOC_SLAB_MAGIC
);
RT_ASSERT
(
z
->
z_magic
==
ZALLOC_SLAB_MAGIC
);
...
@@ -783,20 +783,20 @@ void rt_free(void *ptr)
...
@@ -783,20 +783,20 @@ void rt_free(void *ptr)
/* get memory usage */
/* get memory usage */
#if RT_DEBUG_SLAB
#if RT_DEBUG_SLAB
{
{
rt_u
int32_t
addr
=
((
rt_uint32
_t
)
ptr
&
~
RT_MM_PAGE_MASK
);
rt_u
base_t
addr
=
((
rt_ubase
_t
)
ptr
&
~
RT_MM_PAGE_MASK
);
RT_DEBUG_LOG
(
RT_DEBUG_SLAB
,
RT_DEBUG_LOG
(
RT_DEBUG_SLAB
,
(
"free a memory 0x%x and align to 0x%x, kup index %d
\n
"
,
(
"free a memory 0x%x and align to 0x%x, kup index %d
\n
"
,
(
rt_u
int32
_t
)
ptr
,
(
rt_u
base
_t
)
ptr
,
(
rt_u
int32
_t
)
addr
,
(
rt_u
base
_t
)
addr
,
((
rt_u
int32
_t
)(
addr
)
-
heap_start
)
>>
RT_MM_PAGE_BITS
));
((
rt_u
base
_t
)(
addr
)
-
heap_start
)
>>
RT_MM_PAGE_BITS
));
}
}
#endif
#endif
kup
=
btokup
((
rt_u
int32
_t
)
ptr
&
~
RT_MM_PAGE_MASK
);
kup
=
btokup
((
rt_u
base
_t
)
ptr
&
~
RT_MM_PAGE_MASK
);
/* release large allocation */
/* release large allocation */
if
(
kup
->
type
==
PAGE_TYPE_LARGE
)
if
(
kup
->
type
==
PAGE_TYPE_LARGE
)
{
{
rt_u
int32
_t
size
;
rt_u
base
_t
size
;
/* lock heap */
/* lock heap */
rt_sem_take
(
&
heap_sem
,
RT_WAITING_FOREVER
);
rt_sem_take
(
&
heap_sem
,
RT_WAITING_FOREVER
);
...
@@ -811,7 +811,7 @@ void rt_free(void *ptr)
...
@@ -811,7 +811,7 @@ void rt_free(void *ptr)
RT_DEBUG_LOG
(
RT_DEBUG_SLAB
,
RT_DEBUG_LOG
(
RT_DEBUG_SLAB
,
(
"free large memory block 0x%x, page count %d
\n
"
,
(
"free large memory block 0x%x, page count %d
\n
"
,
(
rt_u
int32
_t
)
ptr
,
size
));
(
rt_u
base
_t
)
ptr
,
size
));
/* free this page */
/* free this page */
rt_page_free
(
ptr
,
size
);
rt_page_free
(
ptr
,
size
);
...
@@ -823,7 +823,7 @@ void rt_free(void *ptr)
...
@@ -823,7 +823,7 @@ void rt_free(void *ptr)
rt_sem_take
(
&
heap_sem
,
RT_WAITING_FOREVER
);
rt_sem_take
(
&
heap_sem
,
RT_WAITING_FOREVER
);
/* zone case. get out zone. */
/* zone case. get out zone. */
z
=
(
slab_zone
*
)(((
rt_u
int32
_t
)
ptr
&
~
RT_MM_PAGE_MASK
)
-
z
=
(
slab_zone
*
)(((
rt_u
base
_t
)
ptr
&
~
RT_MM_PAGE_MASK
)
-
kup
->
size
*
RT_MM_PAGE_SIZE
);
kup
->
size
*
RT_MM_PAGE_SIZE
);
RT_ASSERT
(
z
->
z_magic
==
ZALLOC_SLAB_MAGIC
);
RT_ASSERT
(
z
->
z_magic
==
ZALLOC_SLAB_MAGIC
);
...
@@ -857,7 +857,7 @@ void rt_free(void *ptr)
...
@@ -857,7 +857,7 @@ void rt_free(void *ptr)
slab_zone
**
pz
;
slab_zone
**
pz
;
RT_DEBUG_LOG
(
RT_DEBUG_SLAB
,
(
"free zone 0x%x
\n
"
,
RT_DEBUG_LOG
(
RT_DEBUG_SLAB
,
(
"free zone 0x%x
\n
"
,
(
rt_u
int32
_t
)
z
,
z
->
z_zoneindex
));
(
rt_u
base
_t
)
z
,
z
->
z_zoneindex
));
/* remove zone from zone array list */
/* remove zone from zone array list */
for
(
pz
=
&
zone_array
[
z
->
z_zoneindex
];
z
!=
*
pz
;
pz
=
&
(
*
pz
)
->
z_next
)
for
(
pz
=
&
zone_array
[
z
->
z_zoneindex
];
z
!=
*
pz
;
pz
=
&
(
*
pz
)
->
z_next
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录