Skip to content

Commit

Permalink
Replace process local WCET with global WCET
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrik Karlsson committed Oct 11, 2023
1 parent 7878104 commit 55a0d93
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 17 deletions.
1 change: 1 addition & 0 deletions common/inc/s3k/syscall.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ typedef enum {
uint64_t s3k_get_pid(void);
uint64_t s3k_get_time(void);
uint64_t s3k_get_timeout(void);
uint64_t s3k_get_wcet(bool reset);
uint64_t s3k_reg_read(s3k_reg_t reg);
uint64_t s3k_reg_write(s3k_reg_t reg, uint64_t val);
void s3k_sync();
Expand Down
1 change: 0 additions & 1 deletion common/inc/s3k/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ typedef enum {
S3K_REG_ECAUSE,
S3K_REG_EVAL,
S3K_REG_SERVTIME,
S3K_REG_WCET,
/* Special value for number of registers */
S3K_REG_CNT,
} s3k_reg_t;
Expand Down
6 changes: 6 additions & 0 deletions common/src/s3k/s3k.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,12 @@ uint64_t s3k_get_timeout(void)
return do_ecall(S3K_SYS_GET_INFO, args).val;
}

uint64_t s3k_get_wcet(bool reset)
{
sys_args_t args = {.get_info = {reset ? 4 : 3}};
return do_ecall(S3K_SYS_GET_INFO, args).val;
}

uint64_t s3k_reg_read(s3k_reg_t reg)
{
sys_args_t args = {.reg = {reg}};
Expand Down
2 changes: 2 additions & 0 deletions kernel/inc/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include <stdint.h>

void kernel_init(void);
uint64_t kernel_wcet(void);
void kernel_wcet_reset(void);

bool kernel_lock(proc_t *p);
void kernel_unlock(proc_t *p);
Expand Down
19 changes: 9 additions & 10 deletions kernel/inc/offsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@
#define PROC_ECAUSE _OFFSET(36)
#define PROC_EVAL _OFFSET(37)
#define PROC_SERVTIME _OFFSET(38)
#define PROC_WCET _OFFSET(39)
#define PROC_PMPCFG0 _OFFSET(40)
#define PROC_PMPADDR0 _OFFSET(41)
#define PROC_PMPADDR1 _OFFSET(42)
#define PROC_PMPADDR2 _OFFSET(43)
#define PROC_PMPADDR3 _OFFSET(44)
#define PROC_PMPADDR4 _OFFSET(45)
#define PROC_PMPADDR5 _OFFSET(46)
#define PROC_PMPADDR6 _OFFSET(47)
#define PROC_PMPADDR7 _OFFSET(48)
#define PROC_PMPCFG0 _OFFSET(39)
#define PROC_PMPADDR0 _OFFSET(40)
#define PROC_PMPADDR1 _OFFSET(41)
#define PROC_PMPADDR2 _OFFSET(42)
#define PROC_PMPADDR3 _OFFSET(43)
#define PROC_PMPADDR4 _OFFSET(44)
#define PROC_PMPADDR5 _OFFSET(45)
#define PROC_PMPADDR6 _OFFSET(46)
#define PROC_PMPADDR7 _OFFSET(47)
1 change: 0 additions & 1 deletion kernel/inc/proc.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ typedef enum {
REG_ECAUSE,
REG_EVAL,
REG_SERVTIME,
REG_WCET,
/* Special value for number of registers */
REG_CNT,
} reg_t;
Expand Down
14 changes: 12 additions & 2 deletions kernel/src/kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "sched.h"

static mcslock_t lock;
static uint64_t wcet;

void kernel_init(void)
{
Expand All @@ -20,6 +21,16 @@ void kernel_init(void)
uart_puts("kernel initialized");
}

uint64_t kernel_wcet(void)
{
return wcet;
}

void kernel_wcet_reset(void)
{
wcet = 0;
}

bool kernel_lock(proc_t *p)
{
kernel_hook_sys_exit(p);
Expand All @@ -44,7 +55,6 @@ void kernel_hook_sys_exit(proc_t *p)
{
#ifdef INSTRUMENT
uint64_t cycles = csrr_mcycle();
if (p->regs[REG_WCET] < cycles)
p->regs[REG_WCET] = cycles;
__asm__ volatile("amomax.d x0,%0,(%1)" ::"r"(cycles), "r"(&wcet));
#endif
}
7 changes: 7 additions & 0 deletions kernel/src/syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,13 @@ err_t sys_get_info(proc_t *p, const sys_args_t *args, uint64_t *ret)
case 2:
*ret = timer_get(csrr_mhartid());
break;
case 3:
*ret = kernel_wcet();
break;
case 4:
*ret = kernel_wcet();
kernel_wcet_reset();
break;
default:
*ret = 0;
}
Expand Down
3 changes: 0 additions & 3 deletions kernel/src/trap.S
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,6 @@ trap_resume:
ld t0,PROC_PC(a0)
csrw mepc,t0

ld t0,PROC_WCET(a0)
csrw mhpmcounter3,t0

ld ra,PROC_RA(a0)
ld sp,PROC_SP(a0)
ld gp,PROC_GP(a0)
Expand Down

0 comments on commit 55a0d93

Please sign in to comment.