Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
a732ac5f
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
1 年多 前同步成功
通知
3
Star
37
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Startup Init Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a732ac5f
编写于
2月 15, 2022
作者:
X
xlei1030
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修复cpu核绑实现
Signed-off-by:
N
xlei1030
<
xionglei6@huawei.com
>
上级
93bec381
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
23 addition
and
69 deletion
+23
-69
services/init/include/fd_holder_service.h
services/init/include/fd_holder_service.h
+1
-1
services/init/include/init_service.h
services/init/include/init_service.h
+3
-6
services/init/init_common_service.c
services/init/init_common_service.c
+8
-25
services/init/init_service_manager.c
services/init/init_service_manager.c
+11
-31
services/init/main.c
services/init/main.c
+0
-6
未找到文件。
services/init/include/fd_holder_service.h
浏览文件 @
a732ac5f
...
...
@@ -19,6 +19,6 @@ extern "C" {
#endif
void
RegisterFdHoldWatcher
(
int
sock
);
#ifdef __cplusplus
extern
"C"
{
}
#endif
#endif // BASE_STARTUP_INITLITE_FD_HOLDER_SERVICE_H
services/init/include/init_service.h
浏览文件 @
a732ac5f
...
...
@@ -17,6 +17,8 @@
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
#include <sched.h>
#include <stdio.h>
#include "cJSON.h"
#include "init_cmds.h"
...
...
@@ -89,11 +91,6 @@ typedef enum {
END_RECV_READY
,
}
ServiceEndMode
;
typedef
struct
{
int
*
cpus
;
int
cpuNum
;
}
CpuArgs
;
typedef
struct
{
uid_t
uID
;
gid_t
*
gIDArray
;
...
...
@@ -148,7 +145,7 @@ typedef struct Service_ {
size_t
fdCount
;
TimerHandle
timer
;
ServiceJobs
serviceJobs
;
CpuArgs
cpuInfo
;
cpu_set_t
cpuSet
;
}
Service
;
int
ServiceStart
(
Service
*
service
);
...
...
services/init/init_common_service.c
浏览文件 @
a732ac5f
...
...
@@ -18,8 +18,6 @@
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <sched.h>
#include <stdio.h>
#ifdef __MUSL__
#include <stropts.h>
#endif
...
...
@@ -238,32 +236,17 @@ static void PublishHoldFds(Service *service)
static
int
BindCpuCore
(
Service
*
service
)
{
if
(
service
==
NULL
||
service
->
cpuInfo
.
cpuNum
<=
0
)
{
if
(
service
==
NULL
)
{
return
SERVICE_SUCCESS
;
}
long
cpuNum
=
sysconf
(
_SC_NPROCESSORS_CONF
);
INIT_ERROR_CHECK
(
service
->
cpuInfo
.
cpuNum
<=
cpuNum
,
return
SERVICE_FAILURE
,
"%s cpus cores exceeds total number of device cores"
,
service
->
name
);
int
index
=
0
;
cpu_set_t
setMask
;
CPU_ZERO
(
&
setMask
);
#ifndef __LITEOS__
int
pid
=
getpid
();
for
(
int
i
=
0
;
i
<
service
->
cpuInfo
.
cpuNum
;
i
++
)
{
index
=
(
int
)
service
->
cpuInfo
.
cpus
[
i
];
if
((
int
)
cpuNum
<=
index
)
{
INIT_LOGW
(
"%s core number %d of CPU cores does not exist"
,
service
->
name
,
index
);
continue
;
}
if
(
CPU_ISSET
(
index
,
&
setMask
))
{
continue
;
}
CPU_SET
(
index
,
&
setMask
);
}
if
(
sched_setaffinity
(
pid
,
sizeof
(
setMask
),
&
setMask
)
!=
0
)
{
INIT_LOGI
(
"%s set affinity between process(pid=%d) with CPU's core failed"
,
service
->
name
,
pid
);
}
else
{
INIT_LOGE
(
"%s set affinity between process(pid=%d) with CPU's core successfully"
,
service
->
name
,
pid
);
if
(
sched_setaffinity
(
pid
,
sizeof
(
service
->
cpuSet
),
&
service
->
cpuSet
)
!=
0
)
{
INIT_LOGE
(
"%s set affinity between process(pid=%d) with CPU's core failed"
,
service
->
name
,
pid
);
return
SERVICE_FAILURE
;
}
INIT_LOGI
(
"%s set affinity between process(pid=%d) with CPU's core successfully"
,
service
->
name
,
pid
);
#endif
return
SERVICE_SUCCESS
;
}
...
...
services/init/init_service_manager.c
浏览文件 @
a732ac5f
...
...
@@ -175,6 +175,7 @@ Service *AddService(const char *name)
node
->
data
.
service
=
service
;
service
->
name
=
node
->
name
;
service
->
status
=
SERVICE_IDLE
;
CPU_ZERO
(
&
service
->
cpuSet
);
g_serviceSpace
.
serviceCount
++
;
INIT_LOGV
(
"AddService %s"
,
node
->
name
);
return
service
;
...
...
@@ -203,11 +204,6 @@ void ReleaseService(Service *service)
FreeServiceArg
(
&
service
->
writePidArgs
);
FreeServiceArg
(
&
service
->
capsArgs
);
if
(
service
->
cpuInfo
.
cpus
!=
NULL
)
{
free
(
service
->
cpuInfo
.
cpus
);
service
->
cpuInfo
.
cpus
=
NULL
;
}
service
->
cpuInfo
.
cpuNum
=
0
;
if
(
service
->
servPerm
.
caps
!=
NULL
)
{
free
(
service
->
servPerm
.
caps
);
service
->
servPerm
.
caps
=
NULL
;
...
...
@@ -767,12 +763,7 @@ int GetCritical(const cJSON *curArrItem, Service *curServ, const char *attrName
return
SERVICE_SUCCESS
;
}
static
int
Comparefunc
(
const
void
*
before
,
const
void
*
after
)
{
return
(
*
(
int
*
)
before
-
*
(
int
*
)
after
);
}
static
int
GetCpuArgs
(
const
cJSON
*
argJson
,
const
char
*
name
,
CpuArgs
*
args
)
static
int
GetCpuArgs
(
const
cJSON
*
argJson
,
const
char
*
name
,
Service
*
service
)
{
INIT_ERROR_CHECK
(
argJson
!=
NULL
,
return
SERVICE_FAILURE
,
"Invalid argJson"
);
cJSON
*
obj
=
cJSON_GetObjectItem
(
argJson
,
name
);
...
...
@@ -781,31 +772,20 @@ static int GetCpuArgs(const cJSON *argJson, const char *name, CpuArgs *args)
int
ret
=
cJSON_IsArray
(
obj
);
INIT_ERROR_CHECK
(
ret
,
return
SERVICE_FAILURE
,
"Invalid type"
);
int
count
=
cJSON_GetArraySize
(
obj
);
int
tmpArray
[
count
];
int
cpus
=
-
1
;
int
cpuNumMax
=
sysconf
(
_SC_NPROCESSORS_CONF
);
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
cJSON
*
item
=
cJSON_GetArrayItem
(
obj
,
i
);
INIT_ERROR_CHECK
(
item
!=
NULL
,
return
SERVICE_FAILURE
,
"prase invalid"
);
tmpArray
[
i
]
=
(
int
)
cJSON_GetNumberValue
(
item
);
}
qsort
(
tmpArray
,
count
,
sizeof
(
int
),
Comparefunc
);
int
cpuCount
=
0
;
for
(
int
j
=
0
;
j
<
count
;
j
++
)
{
if
(
j
==
0
&&
tmpArray
[
0
]
==
0
)
{
tmpArray
[
cpuCount
++
]
=
0
;
cpus
=
(
int
)
cJSON_GetNumberValue
(
item
);
if
(
cpuNumMax
<=
cpus
)
{
INIT_LOGW
(
"%s core number %d of CPU cores does not exist"
,
service
->
name
,
cpus
);
continue
;
}
if
(
tmpArray
[
j
]
!=
tmpArray
[
j
-
1
])
{
tmpArray
[
cpuCount
++
]
=
tmpArray
[
j
];
}
}
args
->
cpus
=
(
int
*
)
malloc
(
cpuCount
*
sizeof
(
int
));
INIT_ERROR_CHECK
(
args
->
cpus
!=
NULL
,
return
SERVICE_FAILURE
,
"Failed to malloc for argv"
);
for
(
int
i
=
0
;
i
<
cpuCount
;
++
i
)
{
args
->
cpus
[
i
]
=
-
1
;
if
(
CPU_ISSET
(
cpus
,
&
service
->
cpuSet
))
{
continue
;
}
args
->
cpuNum
=
cpuCount
;
for
(
int
i
=
0
;
i
<
count
;
++
i
)
{
args
->
cpus
[
i
]
=
tmpArray
[
i
];
CPU_SET
(
cpus
,
&
service
->
cpuSet
);
}
return
SERVICE_SUCCESS
;
}
...
...
@@ -843,7 +823,7 @@ int ParseOneService(const cJSON *curItem, Service *service)
(
void
)
GetServiceArgs
(
curItem
,
"writepid"
,
MAX_WRITEPID_FILES
,
&
service
->
writePidArgs
);
(
void
)
GetServiceArgs
(
curItem
,
D_CAPS_STR_IN_CFG
,
MAX_WRITEPID_FILES
,
&
service
->
capsArgs
);
(
void
)
GetStringItem
(
curItem
,
APL_STR_IN_CFG
,
service
->
apl
,
MAX_APL_NAME
);
(
void
)
GetCpuArgs
(
curItem
,
CPU_CORE_STR_IN_CFG
,
&
service
->
cpuInfo
);
(
void
)
GetCpuArgs
(
curItem
,
CPU_CORE_STR_IN_CFG
,
service
);
ret
=
GetServiceCaps
(
curItem
,
service
);
INIT_ERROR_CHECK
(
ret
==
0
,
return
SERVICE_FAILURE
,
"Failed to get caps for service %s"
,
service
->
name
);
ret
=
GetDynamicService
(
curItem
,
service
);
...
...
services/init/main.c
浏览文件 @
a732ac5f
...
...
@@ -17,11 +17,6 @@
static
const
pid_t
INIT_PROCESS_PID
=
1
;
int
__attribute__
((
weak
))
AtlibInit
(
void
)
{
return
0
;
}
int
main
(
int
argc
,
char
*
const
argv
[])
{
int
isSecondStage
=
0
;
...
...
@@ -40,7 +35,6 @@ int main(int argc, char * const argv[])
LogInit
();
}
LogInit
();
(
void
)
AtlibInit
();
SystemInit
();
SystemExecuteRcs
();
SystemConfig
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录