🆕 clock()函数

This commit is contained in:
fslongjin
2022-07-12 13:20:01 +08:00
parent 7670031b11
commit da4867d662
9 changed files with 50 additions and 9 deletions

View File

@ -36,3 +36,10 @@ struct timespec
* @return int
*/
extern int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
/**
* @brief 获取当前的CPU时间
*
* @return uint64_t timer_jiffies
*/
extern uint64_t clock();

View File

@ -16,6 +16,7 @@
extern void system_call(void);
extern void syscall_int(void);
extern uint64_t sys_clock(struct pt_regs* regs);
/**
@ -770,5 +771,6 @@ system_call_t system_call_table[MAX_SYSTEM_CALL_NUM] =
[16] = sys_exit,
[17] = sys_mkdir,
[18] = sys_nanosleep,
[19 ... 254] = system_call_not_exists,
[19] = sys_clock,
[20 ... 254] = system_call_not_exists,
[255] = sys_ahci_end_req};

View File

@ -29,5 +29,6 @@
#define SYS_EXIT 16 // 进程退出
#define SYS_MKDIR 17 // 创建文件夹
#define SYS_NANOSLEEP 18 // 纳秒级休眠
#define SYS_CLOCK 19 // 获取当前cpu时间
#define SYS_AHCI_END_REQ 255 // AHCI DMA请求结束end_request的系统调用

View File

@ -42,7 +42,7 @@ void do_timer_softirq(void *data)
++cycle_count;
// 当前定时器达到阈值
if(cycle_count == TIMER_RUN_CYCLE_THRESHOLD)
if (cycle_count == TIMER_RUN_CYCLE_THRESHOLD)
break;
tmp = container_of(list_next(&timer_func_head.list), struct timer_func_list_t, list);
}
@ -106,3 +106,13 @@ void timer_func_del(struct timer_func_list_t *timer_func)
{
list_del(&timer_func->list);
}
uint64_t sys_clock(struct pt_regs *regs)
{
return timer_jiffies;
}
uint64_t clock()
{
return timer_jiffies;
}

View File

@ -61,3 +61,6 @@ void timer_func_add(struct timer_func_list_t *timer_func);
* @param timer_func
*/
void timer_func_del(struct timer_func_list_t *timer_func);
uint64_t clock();

View File

@ -432,7 +432,7 @@ int shell_cmd_exec(int argc, char **argv)
// printf("parent process wait for pid:[ %d ]\n", pid);
waitpid(pid, &retval, 0);
printf("parent process wait pid [ %d ], exit code=%d\n", pid, retval);
// printf("parent process wait pid [ %d ], exit code=%d\n", pid, retval);
free(argv);
}
}

View File

@ -30,3 +30,13 @@ int usleep(useconds_t usec)
return nanosleep(&ts, NULL);
}
/**
* @brief 获取系统当前cpu时间
*
* @return clock_t
*/
clock_t clock()
{
return (clock_t)syscall_invoke(SYS_CLOCK, 0,0,0,0,0,0,0,0);
}

View File

@ -36,3 +36,10 @@ struct timespec
* @return int
*/
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
/**
* @brief 获取系统当前cpu时间
*
* @return clock_t
*/
clock_t clock();

View File

@ -23,6 +23,7 @@
#define SYS_EXIT 16 // 进程退出
#define SYS_MKDIR 17 // 创建文件夹
#define SYS_NANOSLEEP 18 // 纳秒级休眠
#define SYS_CLOCK 19 // 获取当前cpu时间
/**
* @brief 用户态系统调用函数