fix:modify wait time 10ms

Feature or Bugfix:Bugfix
Binary Source: No

Signed-off-by: liveery <liangming712@huawei.com>
This commit is contained in:
liveery 2024-02-19 08:04:57 +00:00
parent 42c1b440b5
commit 63f671167b
5 changed files with 27 additions and 26 deletions

View File

@ -54,6 +54,11 @@ char *ReadFileToBuf(const char *configFile);
int GetProcCmdlineValue(const char *name, const char *buffer, char *value, int length);
char *ReadFileData(const char *fileName);
typedef struct INIT_TIMING_STAT {
struct timespec startTime;
struct timespec endTime;
} INIT_TIMING_STAT;
typedef struct NameValuePair {
const char *name;
const char *nameEnd;
@ -63,6 +68,7 @@ typedef struct NameValuePair {
int IterateNameValuePairs(const char *src, void (*iterator)(const NAME_VALUE_PAIR *nv, void *context), void *context);
int SplitString(char *srcPtr, const char *del, char **dstPtr, int maxNum);
long long InitDiffTime(INIT_TIMING_STAT *stat);
void WaitForFile(const char *source, unsigned int maxSecond);
size_t WriteAll(int fd, const char *buffer, size_t size);
char *GetRealPath(const char *source);

View File

@ -73,11 +73,6 @@ struct CmdTable {
void (*DoFuncion)(const struct CmdArgs *ctx);
};
typedef struct INIT_TIMING_STAT {
struct timespec startTime;
struct timespec endTime;
} INIT_TIMING_STAT;
typedef enum _initContextType {
INIT_CONTEXT_CHIPSET,
INIT_CONTEXT_MAIN,
@ -103,7 +98,6 @@ void ExecCmd(const struct CmdTable *cmd, const char *cmdContent);
int SetFileCryptPolicy(const char *dir);
void OpenHidebug(const char *name);
long long InitDiffTime(INIT_TIMING_STAT *stat);
void StopSubInit(pid_t pid);
int ExecuteCmdInSubInit(const ConfigContext *context, const char *name, const char *cmdContent);

View File

@ -737,17 +737,6 @@ int GetCmdLinesFromJson(const cJSON *root, CmdLines **cmdLines)
return 0;
}
long long InitDiffTime(INIT_TIMING_STAT *stat)
{
long long diff = (long long)((stat->endTime.tv_sec - stat->startTime.tv_sec) * 1000000); // 1000000 1000ms
if (stat->endTime.tv_nsec > stat->startTime.tv_nsec) {
diff += (stat->endTime.tv_nsec - stat->startTime.tv_nsec) / BASE_MS_UNIT;
} else {
diff -= (stat->startTime.tv_nsec - stat->endTime.tv_nsec) / BASE_MS_UNIT;
}
return diff;
}
void DoCmdByIndex(int index, const char *cmdContent, const ConfigContext *context)
{
if (cmdContent == NULL) {

View File

@ -108,7 +108,6 @@ int SystemTraversalParameter(const char *prefix, TraversalParamPtr traversalPara
workSpace = GetNextWorkSpace(workSpace);
}
while (workSpace != NULL) {
PARAM_LOGV("SystemTraversalParameter prefix %s in space %s", context.prefix, workSpace->fileName);
WorkSpace *next = GetNextWorkSpace(workSpace);
ParamTrieNode *root = NULL;
if (prefix != NULL && strlen(prefix) != 0) {

View File

@ -366,23 +366,36 @@ char **SplitStringExt(char *buffer, const char *del, int *returnCount, int maxIt
return items;
}
long long InitDiffTime(INIT_TIMING_STAT *stat)
{
long long diff = (long long)((stat->endTime.tv_sec - stat->startTime.tv_sec) * 1000000); // 1000000 1000ms
if (stat->endTime.tv_nsec > stat->startTime.tv_nsec) {
diff += (stat->endTime.tv_nsec - stat->startTime.tv_nsec) / BASE_MS_UNIT;
} else {
diff -= (stat->startTime.tv_nsec - stat->endTime.tv_nsec) / BASE_MS_UNIT;
}
return diff;
}
void WaitForFile(const char *source, unsigned int maxSecond)
{
INIT_ERROR_CHECK(maxSecond <= WAIT_MAX_SECOND, maxSecond = WAIT_MAX_SECOND,
"WaitForFile max time is %us", WAIT_MAX_SECOND);
struct stat sourceInfo = {0};
unsigned int waitTime = 500000;
/* 500ms interval, check maxSecond*2 times total */
unsigned int maxCount = maxSecond * 2;
unsigned int waitTime = 10 * BASE_MS_UNIT; // 10ms
long long maxDuration = maxSecond * BASE_MS_UNIT * BASE_MS_UNIT; // 5s
#ifdef STARTUP_INIT_TEST
maxCount = 0;
maxDuration = 0;
#endif
unsigned int count = 0;
while ((stat(source, &sourceInfo) < 0) && (errno == ENOENT) && (count < maxCount)) {
long long duration = 0;
INIT_TIMING_STAT cmdTimer;
(void)clock_gettime(CLOCK_MONOTONIC, &cmdTimer.startTime);
while ((stat(source, &sourceInfo) < 0) && (errno == ENOENT) && (duration < maxDuration)) {
usleep(waitTime);
count++;
(void)clock_gettime(CLOCK_MONOTONIC, &cmdTimer.endTime);
duration = InitDiffTime(&cmdTimer);
}
INIT_CHECK_ONLY_ELOG(count != maxCount, "wait for file:%s failed after %d second.", source, maxSecond);
INIT_CHECK_ONLY_ELOG(duration < maxDuration, "wait for file:%s failed after %d second.", source, maxSecond);
return;
}