changeset 13:16f496e8b857

implement ticks syscall
author anatofuz
date Sat, 22 Jun 2019 13:19:06 +0900
parents 7d90b5bc0f75
children 4f068be78ce7
files src/defs.h src/device/timer.c src/main.c src/proc.c src/syscall.c src/syscall.h src/usr/Makefile src/usr/dummy.c src/usr/user.h src/usr/usys.S src/vm.c
diffstat 11 files changed, 70 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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);
 
--- 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 ()
--- 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)
 
--- 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); 
+}
--- 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)
--- 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
--- 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)
--- /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<load; i++){
+       __asm__ __volatile__ ("");
+    }
+
+    // number of cycles stored in count variable
+    printf(1," %d : count = %d\n",n,getdwt());
+    exit();
+}
--- a/src/usr/user.h	Fri Jun 21 15:38:09 2019 +0900
+++ b/src/usr/user.h	Sat Jun 22 13:19:06 2019 +0900
@@ -24,6 +24,7 @@
 int uptime(void);
 int getpriority(void);
 int setpriority(int);
+int getdwt();
 // ulib.c
 int stat(char*, struct stat*);
 char* strcpy(char*, char*);
--- a/src/usr/usys.S	Fri Jun 21 15:38:09 2019 +0900
+++ b/src/usr/usys.S	Sat Jun 22 13:19:06 2019 +0900
@@ -35,4 +35,5 @@
 SYSCALL(sleep)
 SYSCALL(uptime)
 SYSCALL(getpriority)
-SYSCALL(setpriority)
\ No newline at end of file
+SYSCALL(setpriority)
+SYSCALL(getdwt)
--- a/src/vm.c	Fri Jun 21 15:38:09 2019 +0900
+++ b/src/vm.c	Sat Jun 22 13:19:06 2019 +0900
@@ -443,5 +443,6 @@
 void paging_init (uint phy_low, uint phy_hi)
 {
     mappages (P2V(&_kernel_pgtbl), P2V(phy_low), phy_hi - phy_low, phy_low, AP_KU);
+    mappages (P2V(&_kernel_pgtbl), (void*)0xE0000000, 0x10000, 0xE0000000, AP_KU);
     flush_tlb ();
 }