fix: Optimize quickstart node implementation
Adjust QuickstartListen parameters: 1.delete monitored process pid 2.add timeout waiting Close #I3R8O8 Change-Id: I89c8626c80b8d6fdaea7cd46029dd9a34b555d37
This commit is contained in:
parent
6012acb509
commit
4abd2e0247
|
@ -49,21 +49,19 @@ typedef enum {
|
|||
} QuickstartStage;
|
||||
|
||||
typedef enum {
|
||||
QS_UNREGISTER = QS_STAGE_LIMIT, /* quickstart dev unregister */
|
||||
QS_NOTIFY, /* quickstart notify */
|
||||
QS_LISTEN, /* quickstart listen */
|
||||
QS_NOTIFY = QS_STAGE_LIMIT, /* quickstart notify */
|
||||
QS_LISTEN, /* quickstart listen */
|
||||
QS_CTL_LIMIT
|
||||
} QuickstartConctrl;
|
||||
|
||||
typedef struct {
|
||||
unsigned int pid;
|
||||
unsigned int events;
|
||||
} QuickstartMask;
|
||||
unsigned int wait;
|
||||
} QuickstartListenArgs;
|
||||
|
||||
#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_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_NODE "/dev/quickstart"
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include "fcntl.h"
|
||||
#include "linux/kernel.h"
|
||||
#include "los_process_pri.h"
|
||||
|
||||
#include "fs/fs.h"
|
||||
|
||||
EVENT_CB_S g_qsEvent;
|
||||
static SysteminitHook g_systemInitFunc[QS_STAGE_CNT] = {0};
|
||||
|
@ -51,10 +51,7 @@ static int QuickstartClose(struct file *filep)
|
|||
|
||||
static int QuickstartNotify(unsigned int events)
|
||||
{
|
||||
unsigned int pid = LOS_GetCurrProcessID();
|
||||
/* 16:low 16 bits for eventMask, high 16 bits for pid */
|
||||
unsigned int notifyEvent = (pid << 16) | events;
|
||||
int ret = LOS_EventWrite((PEVENT_CB_S)&g_qsEvent, notifyEvent);
|
||||
int ret = LOS_EventWrite((PEVENT_CB_S)&g_qsEvent, events);
|
||||
if (ret != 0) {
|
||||
PRINT_ERR("%s,%d:0x%x\n", __FUNCTION__, __LINE__, ret);
|
||||
ret = -EINVAL;
|
||||
|
@ -62,17 +59,21 @@ static int QuickstartNotify(unsigned int events)
|
|||
return ret;
|
||||
}
|
||||
|
||||
#define WAITLIMIT 300000 /* 5min = 5*60*1000*1tick(1ms) */
|
||||
|
||||
static int QuickstartListen(unsigned long arg)
|
||||
{
|
||||
QuickstartMask listenMask;
|
||||
if (copy_from_user(&listenMask, (struct QuickstartMask __user *)arg, sizeof(QuickstartMask)) != LOS_OK) {
|
||||
PRINT_ERR("%s,%d\n", __FUNCTION__, __LINE__);
|
||||
QuickstartListenArgs args;
|
||||
if (copy_from_user(&args, (QuickstartListenArgs __user *)arg, sizeof(QuickstartListenArgs)) != LOS_OK) {
|
||||
PRINT_ERR("%s,%d,failed!\n", __FUNCTION__, __LINE__);
|
||||
return -EINVAL;
|
||||
}
|
||||
/* 16:low 16 bits for eventMask, high 16 bits for pid */
|
||||
unsigned int mask = (listenMask.pid << 16) | listenMask.events;
|
||||
int ret = LOS_EventRead((PEVENT_CB_S)&g_qsEvent, mask, LOS_WAITMODE_AND | LOS_WAITMODE_CLR, LOS_WAIT_FOREVER);
|
||||
if (ret != mask) {
|
||||
if (args.wait > WAITLIMIT) {
|
||||
args.wait = WAITLIMIT;
|
||||
PRINT_ERR("%s wait arg is too longer, set to WAITLIMIT!\n", __FUNCTION__);
|
||||
}
|
||||
int ret = LOS_EventRead((PEVENT_CB_S)&g_qsEvent, args.events, LOS_WAITMODE_AND | LOS_WAITMODE_CLR, args.wait);
|
||||
if (ret != args.events && ret != 0) { /* 0: nowait is normal case */
|
||||
PRINT_ERR("%s,%d:0x%x\n", __FUNCTION__, __LINE__, ret);
|
||||
ret = -EINVAL;
|
||||
}
|
||||
|
@ -97,8 +98,9 @@ static int QuickstartStageWorking(unsigned int level)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int QuickstartDevUnregister(void)
|
||||
static int QuickstartDevUnlink(struct Vnode *node)
|
||||
{
|
||||
(void)node;
|
||||
return unregister_driver(QUICKSTART_NODE);
|
||||
}
|
||||
|
||||
|
@ -114,9 +116,6 @@ static ssize_t QuickstartIoctl(struct file *filep, int cmd, unsigned long arg)
|
|||
return -EACCES;
|
||||
}
|
||||
switch (cmd) {
|
||||
case QUICKSTART_UNREGISTER:
|
||||
ret = QuickstartDevUnregister();
|
||||
break;
|
||||
case QUICKSTART_LISTEN:
|
||||
ret = QuickstartListen(arg);
|
||||
break;
|
||||
|
@ -128,17 +127,10 @@ static ssize_t QuickstartIoctl(struct file *filep, int cmd, unsigned long arg)
|
|||
}
|
||||
|
||||
static const struct file_operations_vfs g_quickstartDevOps = {
|
||||
QuickstartOpen, /* open */
|
||||
QuickstartClose, /* close */
|
||||
NULL, /* read */
|
||||
NULL, /* write */
|
||||
NULL, /* seek */
|
||||
QuickstartIoctl, /* ioctl */
|
||||
NULL, /* mmap */
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
NULL, /* poll */
|
||||
#endif
|
||||
NULL, /* unlink */
|
||||
.open = QuickstartOpen, /* open */
|
||||
.close = QuickstartClose, /* close */
|
||||
.ioctl = QuickstartIoctl, /* ioctl */
|
||||
.unlink = QuickstartDevUnlink, /* unlink */
|
||||
};
|
||||
|
||||
int QuickstartDevRegister(void)
|
||||
|
|
Loading…
Reference in New Issue