Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mt-helloworld example #1428

Merged
merged 1 commit into from
Apr 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ include libgloss.mk

PROGRAMS = pwm blkdev accum charcount nic-loopback big-blkdev pingd \
streaming-passthrough streaming-fir nvdla spiflashread spiflashwrite fft gcd \
hello
hello mt-hello

spiflash.img: spiflash.py
python3 $<
Expand Down
1 change: 1 addition & 0 deletions tests/encoding.h
6 changes: 5 additions & 1 deletion tests/hello.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include <stdio.h>
#include "encoding.h"
#include "marchid.h"

int main(void) {
printf("Hello world\n");
uint64_t marchid = read_csr(marchid);
const char* march = get_march(marchid);
printf("Hello world from core 0, a %s\n", march);
return 0;
}
17 changes: 17 additions & 0 deletions tests/marchid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef MARCHID_H
#define MARCHID_H

const char* get_march(size_t marchid) {
switch (marchid) {
case 1:
return "rocket";
case 2:
return "sonicboom";
case 5:
return "spike";
default:
return "unknown";
}
}

#endif
48 changes: 48 additions & 0 deletions tests/mt-hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include "encoding.h"
#include <stdio.h>
#include "marchid.h"

// EDIT THIS
static size_t n_cores = 4;

static void __attribute__((noinline)) barrier()
{
static volatile int sense;
static volatile int count;
static __thread int threadsense;

__sync_synchronize();

threadsense = !threadsense;
if (__sync_fetch_and_add(&count, 1) == n_cores-1)
{
count = 0;
sense = threadsense;
}
else while(sense != threadsense)
;

__sync_synchronize();
}

void __main(void) {
size_t mhartid = read_csr(mhartid);

if (mhartid >= n_cores) while (1);

const char* march = get_march(read_csr(marchid));
for (size_t i = 0; i < n_cores; i++) {
if (mhartid == i) {
printf("Hello world from core %lu, a %s\n", mhartid, march);
}
barrier();
}

// Spin if not core 0
if (mhartid > 0) while (1);
}

int main(void) {
__main();
return 0;
}