# HG changeset patch # User anatofuz # Date 1561177146 -32400 # Node ID 16f496e8b85784a6e572cd215e4684686c2205ab # Parent 7d90b5bc0f758e94236ac889f0b5e094b6df68bd implement ticks syscall diff -r 7d90b5bc0f75 -r 16f496e8b857 src/defs.h --- a/src/defs.h Fri Jun 21 15:38:09 2019 +0900 +++ b/src/defs.h Sat Jun 22 13:19:06 2019 +0900 @@ -168,7 +168,7 @@ extern struct spinlock tickslock; // trap.c -extern uint ticks; +extern volatile uint ticks; void trap_init(void); void dump_trapframe (struct trapframe *tf); diff -r 7d90b5bc0f75 -r 16f496e8b857 src/device/timer.c --- a/src/device/timer.c Fri Jun 21 15:38:09 2019 +0900 +++ b/src/device/timer.c Sat Jun 22 13:19:06 2019 +0900 @@ -26,7 +26,7 @@ void isr_timer (struct trapframe *tp, int irq_idx); struct spinlock tickslock; -uint ticks; +uint volatile ticks; // acknowledge the timer, write any value to TIMER_INTCLR should do static void ack_timer () diff -r 7d90b5bc0f75 -r 16f496e8b857 src/main.c --- a/src/main.c Fri Jun 21 15:38:09 2019 +0900 +++ b/src/main.c Sat Jun 22 13:19:06 2019 +0900 @@ -30,13 +30,14 @@ kpt_freerange (align_up(&end, PT_SZ), vectbl); kpt_freerange (vectbl + PT_SZ, P2V_WO(INIT_KERNMAP)); paging_init (INIT_KERNMAP, PHYSTOP); - + kmem_init (); kmem_init2(P2V(INIT_KERNMAP), P2V(PHYSTOP)); trap_init (); // vector table and stacks for models pic_init (P2V(VIC_BASE)); // interrupt controller uart_enable_rx (); // interrupt for uart + init_DWT(); consoleinit (); // console pinit (); // process (locks) diff -r 7d90b5bc0f75 -r 16f496e8b857 src/proc.c --- a/src/proc.c Fri Jun 21 15:38:09 2019 +0900 +++ b/src/proc.c Sat Jun 22 13:19:06 2019 +0900 @@ -582,3 +582,27 @@ { return proc->priority; } + +volatile unsigned int *DWT_CYCCNT; + +void init_DWT(){ + volatile unsigned int *DWT_CONTROL; + volatile unsigned int *DEMCR; + + DWT_CONTROL = (unsigned int*)0xE0001000; + DWT_CYCCNT = (unsigned int*)0xE0001004; + DEMCR = (unsigned int*)0xE000EDFC; + + // enable the use DWT + *DEMCR = *DEMCR | 0x01000000; + // Reset cycle counter + *DWT_CYCCNT = 0; + // enable cycle counter + *DWT_CONTROL = *DWT_CONTROL | 1; + +} + +int getdwt(){ + return ticks; + // return V2P(DWT_CYCCNT); +} diff -r 7d90b5bc0f75 -r 16f496e8b857 src/syscall.c --- a/src/syscall.c Fri Jun 21 15:38:09 2019 +0900 +++ b/src/syscall.c Sat Jun 22 13:19:06 2019 +0900 @@ -116,6 +116,7 @@ extern int sys_uptime(void); extern int sys_setpriority(void); extern int getpriority(void); +extern int getdwt(void); static int (*syscalls[])(void) = { [SYS_fork] sys_fork, [SYS_exit] sys_exit, @@ -140,6 +141,7 @@ [SYS_close] sys_close, [SYS_getpriority] getpriority, [SYS_setpriority] sys_setpriority, + [SYS_getdwt] getdwt, }; void syscall(void) diff -r 7d90b5bc0f75 -r 16f496e8b857 src/syscall.h --- a/src/syscall.h Fri Jun 21 15:38:09 2019 +0900 +++ b/src/syscall.h Sat Jun 22 13:19:06 2019 +0900 @@ -22,3 +22,4 @@ #define SYS_close 21 #define SYS_setpriority 22 #define SYS_getpriority 23 +#define SYS_getdwt 24 diff -r 7d90b5bc0f75 -r 16f496e8b857 src/usr/Makefile --- a/src/usr/Makefile Fri Jun 21 15:38:09 2019 +0900 +++ b/src/usr/Makefile Sat Jun 22 13:19:06 2019 +0900 @@ -24,7 +24,8 @@ _zombie\ _hello\ _forktest\ - + _dummy + # _check\ all: $(FS_IMAGE) diff -r 7d90b5bc0f75 -r 16f496e8b857 src/usr/dummy.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/usr/dummy.c Sat Jun 22 13:19:06 2019 +0900 @@ -0,0 +1,33 @@ +#include "types.h" +#include "stat.h" +#include "user.h" +#include "fs.h" + +int +main(int argc, char *argv[]) +{ + int i; + int n; + long load = 0x100; + int priority; + //char this_proc_name[512]; + priority = 5; + //strcpy(this_proc_name,"undef"); + + if(argc == 4){ + priority = atoi(argv[1]); + load = atoi(argv[2]); + n = atoi(argv[3]); + } + + setpriority(priority); + printf(1," %d : count = %d\n",n,getdwt()); + + for(i=0; i