提交 b43f461a 编写于 作者: O openharmony_ci 提交者: Gitee

!29 优化startup_init_lite同步机制,在init主流程中添加job进行分阶段启动。

Merge pull request !29 from boxi/master
...@@ -13,24 +13,26 @@ ...@@ -13,24 +13,26 @@
import("//build/lite/config/component/lite_component.gni") import("//build/lite/config/component/lite_component.gni")
lite_component("initstage") { lite_component("initsync") {
features = [ "//base/startup/init_lite/initstage:libinitstage_shared" ] features = [ "//base/startup/init_lite/initsync:libinitsync_shared" ]
} }
shared_library("libinitstage_shared") { shared_library("libinitsync_shared") {
sources = [ "src/init_stage.c" ] sources = [ "src/init_sync.c" ]
cflags = [ "-Wall" ] cflags = [ "-Wall" ]
include_dirs = [ include_dirs = [
"//base/startup/init_lite/initstage/include", "//base/startup/init_lite/initsync/include",
"//base/startup/init_lite/interfaces/kits",
] ]
public_deps = [ "//third_party/bounds_checking_function:libsec_shared" ] public_deps = [ "//third_party/bounds_checking_function:libsec_shared" ]
} }
static_library("libinitstage_static") { static_library("libinitsync_static") {
sources = [ "src/init_stage.c" ] sources = [ "src/init_sync.c" ]
cflags = [ "-Wall" ] cflags = [ "-Wall" ]
include_dirs = [ include_dirs = [
"//base/startup/init_lite/initstage/include", "//base/startup/init_lite/initsync/include",
"//base/startup/init_lite/interfaces/kits",
] ]
public_deps = [ "//third_party/bounds_checking_function:libsec_static" ] public_deps = [ "//third_party/bounds_checking_function:libsec_static" ]
} }
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#ifndef BASE_STARTUP_INITLITE_STAGE_H #ifndef BASE_STARTUP_INITLITE_STAGE_H
#define BASE_STARTUP_INITLITE_STAGE_H #define BASE_STARTUP_INITLITE_STAGE_H
#include "init_sync.h"
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <unistd.h> #include <unistd.h>
...@@ -33,21 +34,19 @@ typedef enum { ...@@ -33,21 +34,19 @@ typedef enum {
} QuickstartStage; } QuickstartStage;
typedef enum { typedef enum {
QS_UNREGISTER = QS_STAGE_LIMIT, /* quickstart dev unregister */ QS_NOTIFY = QS_STAGE_LIMIT, /* quickstart notify */
QS_NOTIFY, /* quickstart notify */ QS_LISTEN, /* quickstart listen */
QS_LISTEN, /* quickstart listen */
QS_CTL_LIMIT QS_CTL_LIMIT
} QuickstartConctrl; } QuickstartConctrl;
typedef struct { typedef struct {
unsigned int pid;
unsigned int events; unsigned int events;
} QuickstartMask; unsigned int wait;
} QuickstartListenArgs;
#define QUICKSTART_IOC_MAGIC 'T' #define QUICKSTART_IOC_MAGIC 'T'
#define QUICKSTART_UNREGISTER _IO(QUICKSTART_IOC_MAGIC, QS_UNREGISTER)
#define QUICKSTART_NOTIFY _IO(QUICKSTART_IOC_MAGIC, QS_NOTIFY) #define QUICKSTART_NOTIFY _IO(QUICKSTART_IOC_MAGIC, QS_NOTIFY)
#define QUICKSTART_LISTEN _IOR(QUICKSTART_IOC_MAGIC, QS_LISTEN, QuickstartMask) #define QUICKSTART_LISTEN _IOR(QUICKSTART_IOC_MAGIC, QS_LISTEN, QuickstartListenArgs)
#define QUICKSTART_STAGE(x) _IO(QUICKSTART_IOC_MAGIC, (x)) #define QUICKSTART_STAGE(x) _IO(QUICKSTART_IOC_MAGIC, (x))
#define QUICKSTART_NODE "/dev/quickstart" #define QUICKSTART_NODE "/dev/quickstart"
...@@ -67,9 +66,8 @@ typedef struct { ...@@ -67,9 +66,8 @@ typedef struct {
* Listen the events of a specific pid process by Init process. * Listen the events of a specific pid process by Init process.
* Only be called by Init process. * Only be called by Init process.
* eventMask: There needs to be a consensus between the listener and the notifier. * eventMask: There needs to be a consensus between the listener and the notifier.
*/ */
extern int InitListen(pid_t pid, unsigned short eventMask); extern int InitListen(unsigned long eventMask, unsigned int wait);
/* /*
* Trigger the SystemInit stage. * Trigger the SystemInit stage.
...@@ -83,6 +81,11 @@ extern int SystemInitStage(QuickstartStage stage); ...@@ -83,6 +81,11 @@ extern int SystemInitStage(QuickstartStage stage);
*/ */
extern int InitStageFinished(void); extern int InitStageFinished(void);
/*
* Listen event and trigger the SystemInit stage.
* Only be called by Init process.
*/
extern void TriggerStage(unsigned int event, unsigned int wait, QuickstartStage stagelevel);
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
} }
......
...@@ -30,24 +30,24 @@ static int SendCmd(int cmd, unsigned long arg) ...@@ -30,24 +30,24 @@ static int SendCmd(int cmd, unsigned long arg)
if (fd != -1) { if (fd != -1) {
int ret = ioctl(fd, cmd, arg); int ret = ioctl(fd, cmd, arg);
if (ret == -1) { if (ret == -1) {
printf("[%s][%d]Err: %s!\n", __FUNCTION__, __LINE__, strerror(errno)); printf("[ERR][%s,%d] %s!\n", __FUNCTION__, __LINE__, strerror(errno));
} }
close(fd); close(fd);
return ret; return ret;
} }
printf("[%s][%d]Err: %s!\n", __FUNCTION__, __LINE__, strerror(errno)); printf("[ERR][%s,%d] %s!\n", __FUNCTION__, __LINE__, strerror(errno));
return fd; return fd;
} }
int InitListen(pid_t pid, unsigned short eventMask) int InitListen(unsigned long eventMask, unsigned int wait)
{ {
QuickstartMask listenMask; QuickstartListenArgs args;
listenMask.pid = pid; args.wait = wait;
listenMask.events = eventMask; args.events = eventMask;
return SendCmd(QUICKSTART_LISTEN, (unsigned long)&listenMask); return SendCmd(QUICKSTART_LISTEN, (unsigned long)&args);
} }
int NotifyInit(unsigned short event) int NotifyInit(unsigned long event)
{ {
return SendCmd(QUICKSTART_NOTIFY, event); return SendCmd(QUICKSTART_NOTIFY, event);
} }
...@@ -55,13 +55,21 @@ int NotifyInit(unsigned short event) ...@@ -55,13 +55,21 @@ int NotifyInit(unsigned short event)
int SystemInitStage(QuickstartStage stage) int SystemInitStage(QuickstartStage stage)
{ {
if (stage >= QS_STAGE_LIMIT || stage < QS_STAGE1) { if (stage >= QS_STAGE_LIMIT || stage < QS_STAGE1) {
printf("[%s][%d]Err: the stage(%d) is Not expected!!\n", __FUNCTION__, __LINE__, stage); printf("[ERR][%s,%d] the stage(%d) is not expected!\n", __FUNCTION__, __LINE__, stage);
return -1; return -1;
} }
return SendCmd(QUICKSTART_STAGE(stage), 0); return SendCmd(QUICKSTART_STAGE(stage), 0);
} }
void TriggerStage(unsigned int event, unsigned int wait, QuickstartStage stagelevel)
{
int ret = InitListen(event, wait);
if (ret != 0) {
SystemInitStage(stagelevel);
}
}
int InitStageFinished(void) int InitStageFinished(void)
{ {
return SendCmd(QUICKSTART_UNREGISTER, 0); return unlink(QUICKSTART_NODE);
} }
...@@ -22,12 +22,23 @@ extern "C" { ...@@ -22,12 +22,23 @@ extern "C" {
#endif #endif
#endif #endif
#define EVENT1 0xf
#define EVENT1_WAITTIME 10000 // 10s = 10*1000 * 1 tick(1ms)
#define EVENT2 0xf0
/* Define EVENT2_WAITTIME 0 means QS_STAGE2 is no used */
#define EVENT2_WAITTIME 0
#define EVENT3 0xf00
/* Define EVENT3_WAITTIME 0 means QS_STAGE3 is no used */
#define EVENT3_WAITTIME 0
/* /*
* Notify the event to Init process. * Notify the event to Init process.
* All processes can call. Usually called by the listened process. * All processes can call. Usually called by the listened process.
* event: There needs to be a consensus between the listener(init process) and the notifier. * event: There needs to be a consensus between the listener(init process) and the notifier.
*/ */
extern int NotifyInit(unsigned short event); extern int NotifyInit(unsigned long event);
#ifdef __cplusplus #ifdef __cplusplus
#if __cplusplus #if __cplusplus
......
...@@ -40,12 +40,18 @@ if (defined(ohos_lite)) { ...@@ -40,12 +40,18 @@ if (defined(ohos_lite)) {
deps = [ deps = [
"//base/startup/syspara_lite/frameworks/parameter:parameter", "//base/startup/syspara_lite/frameworks/parameter:parameter",
"//base/startup/init_lite/initsync:initsync",
"//build/lite/config/component/cJSON:cjson_shared", "//build/lite/config/component/cJSON:cjson_shared",
"//third_party/bounds_checking_function:libsec_shared", "//third_party/bounds_checking_function:libsec_shared",
] ]
ldflags = [] ldflags = []
if (ohos_kernel_type == "liteos_a") { if (ohos_kernel_type == "liteos_a") {
include_dirs += [ "//kernel/liteos_a/syscall" ] include_dirs += [
"//kernel/liteos_a/syscall",
"//base/startup/init_lite/interfaces/kits",
"//base/startup/init_lite/initsync/include",
]
deps += [ "//base/startup/init_lite/initsync:initsync" ]
} }
if (ohos_kernel_type == "linux") { if (ohos_kernel_type == "linux") {
defines += [ "NEED_EXEC_RCS_LINUX" ] defines += [ "NEED_EXEC_RCS_LINUX" ]
......
...@@ -27,7 +27,9 @@ ...@@ -27,7 +27,9 @@
#include "init_perms.h" #include "init_perms.h"
#include "init_service_manager.h" #include "init_service_manager.h"
#include "securec.h" #include "securec.h"
#ifndef __LINUX__
#include "init_stage.h"
#endif
static const long MAX_JSON_FILE_LEN = 102400; // max init.cfg size 100KB static const long MAX_JSON_FILE_LEN = 102400; // max init.cfg size 100KB
static const int MAX_PATH_ARGS_CNT = 20; // max path and args count static const int MAX_PATH_ARGS_CNT = 20; // max path and args count
...@@ -350,8 +352,21 @@ void InitReadCfg() ...@@ -350,8 +352,21 @@ void InitReadCfg()
// do jobs // do jobs
DoJob("pre-init"); DoJob("pre-init");
#ifndef __LINUX__
TriggerStage(EVENT1, EVENT1_WAITTIME, QS_STAGE1);
#endif
DoJob("init"); DoJob("init");
#ifndef __LINUX__
TriggerStage(EVENT2, EVENT2_WAITTIME, QS_STAGE2);
#endif
DoJob("post-init"); DoJob("post-init");
#ifndef __LINUX__
TriggerStage(EVENT3, EVENT3_WAITTIME, QS_STAGE3);
InitStageFinished();
#endif
ReleaseAllJobs(); ReleaseAllJobs();
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册