-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
967 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# | ||
# Makefile for Phoenix-RTOS librhcommon | ||
# | ||
# Copyright 2024 Phoenix Systems | ||
# | ||
|
||
NAME := librhcommon | ||
LOCAL_HEADERS := rhcommon.h | ||
LOCAL_SRCS := common.c | ||
|
||
include $(static-lib.mk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Phoenix-RTOS | ||
* | ||
* Rhealstone benchmark | ||
* | ||
* Common functions | ||
* | ||
* Copyright 2024 Phoenix Systems | ||
* Author: Lukasz Leczkowski | ||
* | ||
* This file is part of Phoenix-RTOS. | ||
* | ||
* %LICENSE% | ||
*/ | ||
|
||
#include "rhcommon.h" | ||
|
||
#include <stdatomic.h> | ||
#include <stdio.h> | ||
#include <sys/threads.h> | ||
#include <unistd.h> | ||
|
||
|
||
uint64_t printResult(uint64_t start, uint64_t end, int loops, uint64_t loopOverhead, uint64_t singleOverhead) | ||
{ | ||
uint64_t elapsed = end - start - loopOverhead; | ||
float time = ((float)elapsed / (float)loops) - (float)singleOverhead; | ||
printf("Result: %.1f cycles\n", time); | ||
|
||
return elapsed; | ||
} | ||
|
||
|
||
static void emptyThread(void *arg) | ||
{ | ||
endthread(); | ||
} | ||
|
||
|
||
uint64_t threadJoinOverhead(void) | ||
{ | ||
uint64_t start, end; | ||
int tid; | ||
char stack[512]; | ||
if (beginthreadex(emptyThread, 0, stack, sizeof(stack), NULL, &tid) < 0) { | ||
perror("beginthreadex"); | ||
return 0; | ||
} | ||
|
||
usleep(100000); | ||
|
||
start = getCntr(); | ||
threadJoin(tid, 0); | ||
end = getCntr(); | ||
|
||
return end - start; | ||
} | ||
|
||
|
||
uint64_t mutexLockOverhead(handle_t mutex) | ||
{ | ||
const int loops = 100; | ||
uint64_t start, end, total = 0; | ||
|
||
for (int i = 0; i < loops; i++) { | ||
start = getCntr(); | ||
mutexLock(mutex); | ||
end = getCntr(); | ||
mutexUnlock(mutex); | ||
total += end - start; | ||
} | ||
|
||
return total / loops; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Phoenix-RTOS | ||
* | ||
* Rhealstone benchmark | ||
* | ||
* Common functions | ||
* | ||
* Copyright 2024 Phoenix Systems | ||
* Author: Lukasz Leczkowski | ||
* | ||
* This file is part of Phoenix-RTOS. | ||
* | ||
* %LICENSE% | ||
*/ | ||
|
||
#ifndef _RHCOMMON_H_ | ||
#define _RHCOMMON_H_ | ||
|
||
|
||
#include <stdio.h> | ||
#include <sys/threads.h> | ||
|
||
|
||
#define BENCH_NAME(name) \ | ||
do { \ | ||
printf("Rhealstone benchmark suite\n%s\n", name); \ | ||
} while (0) | ||
|
||
uint64_t printResult(uint64_t start, uint64_t end, int loops, uint64_t loopOverhead, uint64_t singleOverhead); | ||
|
||
|
||
static inline uint64_t getCntr(void) | ||
{ | ||
uint32_t asr22, asr23; | ||
uint64_t cntr; | ||
__asm__ volatile( | ||
"rd %%asr22, %0\n\t" | ||
"rd %%asr23, %1\n\t" | ||
: "=r"(asr22), "=r"(asr23) :); | ||
|
||
cntr = ((uint64_t)(asr22 & 0xffffffu) << 32) | asr23; | ||
|
||
return cntr; | ||
} | ||
|
||
|
||
uint64_t threadJoinOverhead(void); | ||
|
||
|
||
uint64_t mutexLockOverhead(handle_t mutex); | ||
|
||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# | ||
# Makefile for user application | ||
# | ||
# Copyright 2024 Phoenix Systems | ||
# | ||
|
||
NAME := rh-deadlock-break | ||
LOCAL_SRCS := main.c | ||
DEP_LIBS := librhcommon | ||
|
||
include $(binary.mk) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
/* | ||
* Phoenix-RTOS | ||
* | ||
* Rhealstone benchmark | ||
* | ||
* Task switch | ||
* | ||
* Copyright 2024 Phoenix Systems | ||
* Author: Lukasz Leczkowski | ||
* | ||
* This file is part of Phoenix-RTOS. | ||
* | ||
* %LICENSE% | ||
*/ | ||
|
||
#include <stdatomic.h> | ||
#include <stdbool.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <sys/time.h> | ||
#include <sys/threads.h> | ||
|
||
#include <board_config.h> | ||
#include <rhcommon.h> | ||
|
||
|
||
#define BENCHMARKS 10000 | ||
|
||
bool deadBrk; | ||
volatile bool done = false; | ||
handle_t mutex; | ||
|
||
unsigned char stack[3][4096]; | ||
int maxLoops = BENCHMARKS; | ||
int tid1, tid2, tid3; | ||
|
||
atomic_bool t3_started = false; | ||
|
||
uint64_t totalNoDeadBrk = 0; | ||
uint64_t totalDeadBrk = 0; | ||
|
||
/* High priority task */ | ||
void task3(void *arg) | ||
{ | ||
t3_started = true; | ||
uint64_t time = getCntr(); | ||
if (deadBrk) { | ||
mutexLock(mutex); | ||
} | ||
|
||
if (deadBrk) { | ||
mutexUnlock(mutex); | ||
time = getCntr() - time; | ||
totalDeadBrk += time; | ||
} | ||
else { | ||
time = getCntr() - time; | ||
totalNoDeadBrk += time; | ||
} | ||
done = true; | ||
endthread(); | ||
} | ||
|
||
|
||
/* Medium priority task */ | ||
void task2(void *arg) | ||
{ | ||
if (beginthreadex(task3, 1, stack[2], sizeof(stack[2]), NULL, &tid3)) { | ||
perror("beginthreadex"); | ||
endthread(); | ||
} | ||
|
||
while (!done) { | ||
__asm__ volatile("nop"); | ||
} | ||
|
||
threadJoin(tid3, 0); | ||
|
||
endthread(); | ||
} | ||
|
||
/* Low priority task */ | ||
void task1(void *arg) | ||
{ | ||
if (deadBrk) { | ||
mutexLock(mutex); | ||
} | ||
|
||
if (beginthreadex(task2, 2, stack[1], sizeof(stack[1]), NULL, &tid2)) { | ||
perror("beginthreadex"); | ||
endthread(); | ||
} | ||
|
||
while (!t3_started) { | ||
usleep(0); | ||
} | ||
|
||
if (deadBrk) { | ||
mutexUnlock(mutex); | ||
} | ||
|
||
threadJoin(tid2, 0); | ||
t3_started = false; | ||
endthread(); | ||
} | ||
|
||
|
||
int doTest(void) | ||
{ | ||
if (beginthreadex(task1, 3, stack[0], sizeof(stack[0]), NULL, &tid1)) { | ||
perror("beginthreadex"); | ||
return -1; | ||
} | ||
|
||
priority(4); | ||
|
||
usleep(0); | ||
|
||
threadJoin(tid1, 0); | ||
|
||
priority(0); | ||
|
||
return 0; | ||
} | ||
|
||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
BENCH_NAME("Deadlock Break"); | ||
|
||
if (argc > 1) { | ||
maxLoops = atoi(argv[1]); | ||
} | ||
|
||
priority(0); | ||
|
||
mutexCreate(&mutex); | ||
|
||
uint64_t mutexOverhead = mutexLockOverhead(mutex); | ||
uint64_t joinOverhead = threadJoinOverhead(); | ||
|
||
deadBrk = false; | ||
|
||
|
||
for (int i = 0; i < maxLoops; i++) { | ||
if (doTest() < 0) { | ||
return -1; | ||
} | ||
} | ||
|
||
printf("No deadlock: \n"); | ||
printResult(0, totalNoDeadBrk, 1, joinOverhead, 0); | ||
|
||
deadBrk = true; | ||
|
||
for (int i = 0; i < maxLoops; i++) { | ||
if (doTest() < 0) { | ||
return -1; | ||
} | ||
} | ||
|
||
printf("Deadlocks: full time\n"); | ||
printResult(0, totalDeadBrk, 1, joinOverhead, 0); | ||
|
||
printf("Deadlocks: per resolution\n"); | ||
printResult(0, totalDeadBrk, maxLoops, totalNoDeadBrk, mutexOverhead); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# | ||
# Makefile for user application | ||
# | ||
# Copyright 2024 Phoenix Systems | ||
# | ||
|
||
NAME := rh-irq-latency | ||
LOCAL_SRCS := main.c | ||
DEP_LIBS := librhcommon | ||
|
||
include $(binary.mk) |
Oops, something went wrong.