Beispiel #1
0
void sys_exit(int code)
{
  if (current.t0)
    printk("%ld cycles\n", rdcycle() - current.t0);
  dump_uarch_counters();
  shutdown(code);
}
Beispiel #2
0
long sys_time(long* loc)
{
  uintptr_t t = rdcycle() / CLOCK_FREQ;
  if (loc)
    *loc = t;
  return t;
}
Beispiel #3
0
void sys_exit(int code)
{
  if (current.t0)
    printk("%ld cycles\n", rdcycle() - current.t0);

  if (uarch_counters_enabled) {
    size_t i = 0;
    #define READ_CTR_FINI(name) do { \
      while (i >= NUM_COUNTERS) ; \
      long csr = read_csr(name); \
      csr -= uarch_counters[i]; uarch_counter_names[i] = #name; \
      uarch_counters[i++] = csr; \
    } while (0)
    READ_CTR_FINI(cycle);   READ_CTR_FINI(instret);
    READ_CTR_FINI(uarch0);  READ_CTR_FINI(uarch1);  READ_CTR_FINI(uarch2);
    READ_CTR_FINI(uarch3);  READ_CTR_FINI(uarch4);  READ_CTR_FINI(uarch5);
    READ_CTR_FINI(uarch6);  READ_CTR_FINI(uarch7);  READ_CTR_FINI(uarch8);
    READ_CTR_FINI(uarch9);  READ_CTR_FINI(uarch10); READ_CTR_FINI(uarch11);
    READ_CTR_FINI(uarch12); READ_CTR_FINI(uarch13); READ_CTR_FINI(uarch14);
    READ_CTR_FINI(uarch15);
    #undef READ_CTR_FINI

    for (int i = 0; i < NUM_COUNTERS; i++) {
      if (uarch_counters[i]) {
        printk("%s = %ld\n", uarch_counter_names[i], uarch_counters[i]);
      }
    }
  }

  frontend_syscall(SYS_exit, code, 0, 0, 0, 0);
  clear_csr(status, SR_EI);
  while (1);
}
Beispiel #4
0
int sys_gettimeofday(long* loc)
{
  uintptr_t t = rdcycle();
  loc[0] = t / CLOCK_FREQ;
  loc[1] = (t % CLOCK_FREQ) / (CLOCK_FREQ / 1000000);
  
  return 0;
}
Beispiel #5
0
long sys_time(void* loc)
{
  uintptr_t t = rdcycle() / CLOCK_FREQ;
  if (loc)
  {
    populate_mapping(loc, long_bytes, PROT_WRITE);
    put_long(loc, 0, t);
  }
  return t;
}
Beispiel #6
0
int sys_times(long* loc)
{
  uintptr_t t = rdcycle();
  kassert(CLOCK_FREQ % 1000000 == 0);
  loc[0] = t / (CLOCK_FREQ / 1000000);
  loc[1] = 0;
  loc[2] = 0;
  loc[3] = 0;
  
  return 0;
}
Beispiel #7
0
void thread_entry(int cid, int nc)
{
  const int R = 8;
  int m, n, p;
  uint64_t s = 0xdeadbeefU;
  
  if (have_vec) {
    m = HCBM;
    n = HCBN;
    p = HCBK;
  } else {
    m = CBM;
    n = CBN;
    p = CBK;
  }

  t a[m*p];
  t b[p*n];
  t c[m*n];

  for (size_t i = 0; i < m; i++)
    for (size_t j = 0; j < p; j++)
      a[i*p+j] = (t)(s = lfsr(s));
  for (size_t i = 0; i < p; i++)
    for (size_t j = 0; j < n; j++)
      b[i*n+j] = (t)(s = lfsr(s));
  memset(c, 0, m*n*sizeof(c[0]));

  size_t instret, cycles;
  if (have_vec) {
    for (int i = 0; i < R; i++)
    {
      instret = -rdinstret();
      cycles = -rdcycle();
      mm_rb_hwacha(m, n, p, a, p, b, n, c, n);
      instret += rdinstret();
      cycles += rdcycle();
    }
  } else {
    for (int i = 0; i < R; i++)
    {
      instret = -rdinstret();
      cycles = -rdcycle();
      mm(m, n, p, a, p, b, n, c, n);
      instret += rdinstret();
      cycles += rdcycle();
    }
  }

  asm volatile("fence");

  printf("C%d: reg block %dx%dx%d, cache block %dx%dx%d\n",
         cid, RBM, RBN, RBK, CBM, CBN, CBK);
  printf("C%d: %d instructions\n", cid, (int)(instret));
  printf("C%d: %d cycles\n", cid, (int)(cycles));
  printf("C%d: %d flops\n", cid, 2*m*n*p);
  printf("C%d: %d Mflops @ 1 GHz\n", cid, 2000*m*n*p/(cycles));

#if 1
  for (size_t i = 0; i < m; i++)
  {
    for (size_t j = 0; j < n; j++)
    {
      t s = 0;
      for (size_t k = 0; k < p; k++)
        s += a[i*p+k] * b[k*n+j];
      s *= R;
      if (fabs(c[i*n+j]-s) > fabs(1e-6*s))
      {
        printf("C%d: c[%lu][%lu] %f != %f\n", cid, i, j, c[i*n+j], s);
        exit(1);
      }
    }
  }
#endif

  barrier(nc);
  exit(0);
}
Beispiel #8
0
//function 1: outputs what time to wake up if you know your bed time.
int when_to_wake_up() {

	int hr = 0;
	int mins = 0;

	//Ask the initial question, and take two answers using scanf()
	printf("\nWhat time will you go to bed?\nInput the time in 24hr format (e.g. 23:30)\n\n");
		scanf("%d:%d", &hr, &mins);

	//assigning pointers
	int *ptr3 = &hr;
	int *ptr4 = &mins;

		//if input is above 24hr and 60mins, send an error
		if (*ptr3 > 24 || *ptr4 > 60){
			printf("Invalid input: Please type down the correct hour and minutes.\n");
		}

		else {
			//90mins = 1 sleepy cycle. must add 5-6 sleep cycles
			*ptr4 = rdcycle(*ptr4);

			//For each instance where minute is greater than 60: take away 60 and run following.
			for ( ; *ptr4 >= 60 ; *ptr4-=60 ){
				*ptr3 = *ptr3 + 1;
                if (*ptr3 > 24){  *ptr3 = 01;}
			}

	printf( "Wake up at one of the following times:\n %02d:%02d\n", *ptr3, *ptr4);
	//second cycle
    int *ptr5 = &hr;
    int *ptr6 = &mins;

    *ptr6 = mrdcycle(*ptr6);

    *ptr6 = thcycle(*ptr6);

        for ( ; *ptr6 >= 60 ; *ptr6-=60 ){
			*ptr5 = *ptr5 + 1;
                if (*ptr5 > 24){  *ptr5 = 01;}
        }

	printf(" %02d:%02d\n", *ptr5, *ptr6);
	//third cycle
    int *ptr7 = &hr;
    int *ptr8 = &mins;

    *ptr6 = mthcycle(*ptr8);

    *ptr6 = ghcycle(*ptr8);

        for ( ; *ptr8 >= 60 ; *ptr8-=60 ){
			*ptr5 = *ptr7 + 1;
                if (*ptr7 > 24){  *ptr7 = 01;}
        }

	printf(" %02d:%02d\n", *ptr7, *ptr8);
		}

	printf("\nPress any key to exit...");
Pause();
return 1;
}
Beispiel #9
0
long sys_time(void* loc)
{
  uintptr_t t = rdcycle() / CLOCK_FREQ;
  if (loc)
  {
    populate_mapping(loc, long_bytes, PROT_WRITE);
    put_long(loc, 0, t);
  }
  return t;
}

int sys_times(void* restrict loc)
{
  populate_mapping(loc, 4*long_bytes, PROT_WRITE);

  uintptr_t t = rdcycle();
  kassert(CLOCK_FREQ % 1000000 == 0);
  put_long(loc, 0, t / (CLOCK_FREQ / 1000000));
  put_long(loc, 1, 0);
  put_long(loc, 2, 0);
  put_long(loc, 3, 0);
  
  return 0;
}

int sys_gettimeofday(long* loc)
{
  populate_mapping(loc, 2*long_bytes, PROT_WRITE);

  uintptr_t t = rdcycle();
  put_long(loc, 0, t/CLOCK_FREQ);
Beispiel #10
0
static void run_loaded_program(size_t argc, char** argv, uintptr_t kstack_top)
{
  // copy phdrs to user stack
  size_t stack_top = current.stack_top - current.phdr_size;
  memcpy((void*)stack_top, (void*)current.phdr, current.phdr_size);
  current.phdr = stack_top;

  // copy argv to user stack
  for (size_t i = 0; i < argc; i++) {
    size_t len = strlen((char*)(uintptr_t)argv[i])+1;
    stack_top -= len;
    memcpy((void*)stack_top, (void*)(uintptr_t)argv[i], len);
    argv[i] = (void*)stack_top;
  }

  // copy envp to user stack
  const char* envp[] = {
    // environment goes here
  };
  size_t envc = sizeof(envp) / sizeof(envp[0]);
  for (size_t i = 0; i < envc; i++) {
    size_t len = strlen(envp[i]) + 1;
    stack_top -= len;
    memcpy((void*)stack_top, envp[i], len);
    envp[i] = (void*)stack_top;
  }

  // align stack
  stack_top &= -sizeof(void*);

  struct {
    long key;
    long value;
  } aux[] = {
    {AT_ENTRY, current.entry},
    {AT_PHNUM, current.phnum},
    {AT_PHENT, current.phent},
    {AT_PHDR, current.phdr},
    {AT_PAGESZ, RISCV_PGSIZE},
    {AT_SECURE, 0},
    {AT_RANDOM, stack_top},
    {AT_NULL, 0}
  };

  // place argc, argv, envp, auxp on stack
  #define PUSH_ARG(type, value) do { \
    *((type*)sp) = (type)value; \
    sp += sizeof(type); \
  } while (0)

  #define STACK_INIT(type) do { \
    unsigned naux = sizeof(aux)/sizeof(aux[0]); \
    stack_top -= (1 + argc + 1 + envc + 1 + 2*naux) * sizeof(type); \
    stack_top &= -16; \
    long sp = stack_top; \
    PUSH_ARG(type, argc); \
    for (unsigned i = 0; i < argc; i++) \
      PUSH_ARG(type, argv[i]); \
    PUSH_ARG(type, 0); /* argv[argc] = NULL */ \
    for (unsigned i = 0; i < envc; i++) \
      PUSH_ARG(type, envp[i]); \
    PUSH_ARG(type, 0); /* envp[envc] = NULL */ \
    for (unsigned i = 0; i < naux; i++) { \
      PUSH_ARG(type, aux[i].key); \
      PUSH_ARG(type, aux[i].value); \
    } \
  } while (0)

  STACK_INIT(uintptr_t);

  if (current.cycle0) { // start timer if so requested
    current.time0 = rdtime();
    current.cycle0 = rdcycle();
    current.instret0 = rdinstret();
  }

  trapframe_t tf;
  init_tf(&tf, current.entry, stack_top);
  __clear_cache(0, 0);
  write_csr(sscratch, kstack_top);
  start_user(&tf);
}