Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
libvirt
提交
223521bd
L
libvirt
项目概览
openeuler
/
libvirt
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
L
libvirt
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
223521bd
编写于
10月 18, 2013
作者:
P
Peter Krempa
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
numa: Add wrapper of numa_node_to_cpus and use it
上级
f162a229
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
117 addition
and
38 deletion
+117
-38
src/nodeinfo.c
src/nodeinfo.c
+24
-38
src/util/virnuma.c
src/util/virnuma.c
+91
-0
src/util/virnuma.h
src/util/virnuma.h
+2
-0
未找到文件。
src/nodeinfo.c
浏览文件 @
223521bd
...
...
@@ -1535,11 +1535,6 @@ nodeGetFreeMemoryFake(void)
}
#if WITH_NUMACTL
# define n_bits(var) (8 * sizeof(var))
# define MASK_CPU_ISSET(mask, cpu) \
(((mask)[((cpu) / n_bits(*(mask)))] >> ((cpu) % n_bits(*(mask)))) & 1)
static
virBitmapPtr
virNodeGetSiblingsList
(
const
char
*
dir
,
int
cpu_id
)
{
...
...
@@ -1592,14 +1587,12 @@ int
nodeCapsInitNUMA
(
virCapsPtr
caps
)
{
int
n
;
unsigned
long
*
mask
=
NULL
;
unsigned
long
*
allonesmask
=
NULL
;
unsigned
long
long
memory
;
virCapsHostNUMACellCPUPtr
cpus
=
NULL
;
virBitmapPtr
cpumap
=
NULL
;
int
ret
=
-
1
;
int
max_n_cpus
=
virNumaGetMaxCPUs
();
int
mask_n_bytes
=
max_n_cpus
/
8
;
int
ncpus
=
0
;
int
cpu
;
bool
topology_failed
=
false
;
int
max_node
;
...
...
@@ -1609,49 +1602,41 @@ nodeCapsInitNUMA(virCapsPtr caps)
if
((
max_node
=
virNumaGetMaxNode
())
<
0
)
goto
cleanup
;
if
(
VIR_ALLOC_N
(
mask
,
mask_n_bytes
/
sizeof
(
*
mask
))
<
0
)
goto
cleanup
;
if
(
VIR_ALLOC_N
(
allonesmask
,
mask_n_bytes
/
sizeof
(
*
mask
))
<
0
)
goto
cleanup
;
memset
(
allonesmask
,
0xff
,
mask_n_bytes
);
for
(
n
=
0
;
n
<=
max_node
;
n
++
)
{
size_t
i
;
/* The first time this returns -1, ENOENT if node doesn't exist... */
if
(
numa_node_to_cpus
(
n
,
mask
,
mask_n_bytes
)
<
0
)
{
VIR_WARN
(
"NUMA topology for cell %d of %d not available, ignoring"
,
n
,
max_node
+
1
);
continue
;
}
/* second, third... times it returns an all-1's mask */
if
(
memcmp
(
mask
,
allonesmask
,
mask_n_bytes
)
==
0
)
{
VIR_DEBUG
(
"NUMA topology for cell %d of %d is all ones, ignoring"
,
n
,
max_node
+
1
);
continue
;
}
/* Detect the amount of memory in the numa cell in KiB */
virNumaGetNodeMemory
(
n
,
&
memory
,
NULL
);
memory
>>=
10
;
if
((
ncpus
=
virNumaGetNodeCPUs
(
n
,
&
cpumap
))
<
0
)
{
if
(
ncpus
==
-
2
)
continue
;
for
(
ncpus
=
0
,
i
=
0
;
i
<
max_n_cpus
;
i
++
)
if
(
MASK_CPU_ISSET
(
mask
,
i
))
ncpus
++
;
goto
cleanup
;
}
if
(
VIR_ALLOC_N
(
cpus
,
ncpus
)
<
0
)
goto
cleanup
;
cpu
=
0
;
for
(
ncpus
=
0
,
i
=
0
;
i
<
max_n_cpus
;
i
++
)
{
if
(
MASK_CPU_ISSET
(
mask
,
i
))
{
if
(
virNodeCapsFillCPUInfo
(
i
,
cpus
+
ncpus
++
)
<
0
)
{
for
(
i
=
0
;
i
<
virBitmapSize
(
cpumap
);
i
++
)
{
bool
cpustate
;
if
(
virBitmapGetBit
(
cpumap
,
i
,
&
cpustate
)
<
0
)
continue
;
if
(
cpustate
)
{
if
(
virNodeCapsFillCPUInfo
(
i
,
cpus
+
cpu
++
)
<
0
)
{
topology_failed
=
true
;
virResetLastError
();
}
}
}
/* Detect the amount of memory in the numa cell in KiB */
virNumaGetNodeMemory
(
n
,
&
memory
,
NULL
);
memory
>>=
10
;
if
(
virCapabilitiesAddHostNUMACell
(
caps
,
n
,
ncpus
,
memory
,
cpus
)
<
0
)
goto
cleanup
;
cpus
=
NULL
;
}
ret
=
0
;
...
...
@@ -1660,11 +1645,12 @@ cleanup:
if
(
topology_failed
||
ret
<
0
)
virCapabilitiesClearHostNUMACellCPUTopology
(
cpus
,
ncpus
);
virBitmapFree
(
cpumap
);
VIR_FREE
(
cpus
);
if
(
ret
<
0
)
VIR_FREE
(
cpus
);
VIR_FREE
(
mask
);
VIR_FREE
(
allonesmask
);
return
ret
;
}
...
...
src/util/virnuma.c
浏览文件 @
223521bd
...
...
@@ -38,6 +38,8 @@
#include "vircommand.h"
#include "virerror.h"
#include "virlog.h"
#include "viralloc.h"
#include "virbitmap.h"
#define VIR_FROM_THIS VIR_FROM_NONE
...
...
@@ -249,6 +251,83 @@ virNumaGetNodeMemory(int node,
return
0
;
}
/**
* virNumaGetNodeCPUs:
* @node: identifier of the requested NUMA node
* @cpus: returns a bitmap of CPUs in @node
*
* Returns count of CPUs in the selected node and sets the map of the cpus to
* @cpus. On error if the @node doesn't exist in the system this function
* returns -2 and sets @cpus to NULL. On other errors -1 is returned, @cpus
* is set to NULL and an error is reported.
*/
# define n_bits(var) (8 * sizeof(var))
# define MASK_CPU_ISSET(mask, cpu) \
(((mask)[((cpu) / n_bits(*(mask)))] >> ((cpu) % n_bits(*(mask)))) & 1)
int
virNumaGetNodeCPUs
(
int
node
,
virBitmapPtr
*
cpus
)
{
unsigned
long
*
mask
=
NULL
;
unsigned
long
*
allonesmask
=
NULL
;
virBitmapPtr
cpumap
=
NULL
;
int
ncpus
=
0
;
int
max_n_cpus
=
virNumaGetMaxCPUs
();
int
mask_n_bytes
=
max_n_cpus
/
8
;
size_t
i
;
int
ret
=
-
1
;
*
cpus
=
NULL
;
if
(
VIR_ALLOC_N
(
mask
,
mask_n_bytes
/
sizeof
(
*
mask
))
<
0
)
goto
cleanup
;
if
(
VIR_ALLOC_N
(
allonesmask
,
mask_n_bytes
/
sizeof
(
*
mask
))
<
0
)
goto
cleanup
;
memset
(
allonesmask
,
0xff
,
mask_n_bytes
);
/* The first time this returns -1, ENOENT if node doesn't exist... */
if
(
numa_node_to_cpus
(
node
,
mask
,
mask_n_bytes
)
<
0
)
{
VIR_WARN
(
"NUMA topology for cell %d is not available, ignoring"
,
node
);
ret
=
-
2
;
goto
cleanup
;
}
/* second, third... times it returns an all-1's mask */
if
(
memcmp
(
mask
,
allonesmask
,
mask_n_bytes
)
==
0
)
{
VIR_DEBUG
(
"NUMA topology for cell %d is invalid, ignoring"
,
node
);
ret
=
-
2
;
goto
cleanup
;
}
if
(
!
(
cpumap
=
virBitmapNew
(
max_n_cpus
)))
goto
cleanup
;
for
(
i
=
0
;
i
<
max_n_cpus
;
i
++
)
{
if
(
MASK_CPU_ISSET
(
mask
,
i
))
{
ignore_value
(
virBitmapSetBit
(
cpumap
,
i
));
ncpus
++
;
}
}
*
cpus
=
cpumap
;
cpumap
=
NULL
;
ret
=
ncpus
;
cleanup:
VIR_FREE
(
mask
);
VIR_FREE
(
allonesmask
);
VIR_FREE
(
cpumap
);
return
ret
;
}
# undef MASK_CPU_ISSET
# undef n_bits
#else
int
virNumaSetupMemoryPolicy
(
virNumaTuneDef
numatune
,
...
...
@@ -295,6 +374,18 @@ virNumaGetNodeMemory(int node ATTRIBUTE_UNUSED,
VIR_DEBUG
(
"NUMA isn't available on this host"
);
return
-
1
;
}
int
virNumaGetNodeCPUs
(
int
node
ATTRIBUTE_UNUSED
,
virBitmapPtr
*
cpus
)
{
*
cpus
=
NULL
;
virReportError
(
VIR_ERR_INTERNAL_ERROR
,
"%s"
,
_
(
"NUMA isn't available on this host"
));
return
-
1
;
}
#endif
...
...
src/util/virnuma.h
浏览文件 @
223521bd
...
...
@@ -64,4 +64,6 @@ int virNumaGetNodeMemory(int node,
unsigned
int
virNumaGetMaxCPUs
(
void
);
int
virNumaGetNodeCPUs
(
int
node
,
virBitmapPtr
*
cpus
);
#endif
/* __VIR_NUMA_H__ */
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录