aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Cunningham <cc@localhost>2022-03-28 00:59:23 -0700
committerChristian Cunningham <cc@localhost>2022-03-28 00:59:23 -0700
commit3e7833e4017c52ca54e6c8311d1aeb793796986c (patch)
treea9853e0322850d171edf12c99a06d15d1ce5a76d
parent973a9ef0e1d86bd018e7478547e7e81783d9a5b3 (diff)
Testing with Cycle Counter
-rw-r--r--kernel/sys/core.c4
-rw-r--r--usr/main.c19
-rw-r--r--usr/test.c191
3 files changed, 204 insertions, 10 deletions
diff --git a/kernel/sys/core.c b/kernel/sys/core.c
index c06ed4b..551d741 100644
--- a/kernel/sys/core.c
+++ b/kernel/sys/core.c
@@ -40,6 +40,6 @@ void sysinit(void)
// Start Scheduler
init_scheduler();
- add_thread(test_entry, 0, 2);
- //add_thread(main, 0, 0);
+ //add_thread(test_entry, 0, 2);
+ add_thread(main, 0, 0);
}
diff --git a/usr/main.c b/usr/main.c
index 415d6c9..b6e540d 100644
--- a/usr/main.c
+++ b/usr/main.c
@@ -49,14 +49,17 @@ void gptest(void)
draw_string(0, 31, start);
}
+void test_super(void);
+
void main(void)
{
- subscribe_irq(UART_IRQ, handle_data, &UART_INFO);
- subscribe_irq(SYS_TIMER_0_IRQ, loopt, &stime_0);
- subscribe_irq(SYS_TIMER_1_IRQ, loopt, &stime_1);
- subscribe_irq(SYS_TIMER_2_IRQ, loopt, &stime_2);
- subscribe_irq(SYS_TIMER_3_IRQ, loopt, &stime_3);
- subscribe_irq(GPIO_BANK_1_IRQ, gptest, &gpinfo);
- add_thread(loop, 0, 8);
- add_thread(consumer, 0, 3);
+ //subscribe_irq(UART_IRQ, handle_data, &UART_INFO);
+ //subscribe_irq(SYS_TIMER_0_IRQ, loopt, &stime_0);
+ //subscribe_irq(SYS_TIMER_1_IRQ, loopt, &stime_1);
+ //subscribe_irq(SYS_TIMER_2_IRQ, loopt, &stime_2);
+ //subscribe_irq(SYS_TIMER_3_IRQ, loopt, &stime_3);
+ //subscribe_irq(GPIO_BANK_1_IRQ, gptest, &gpinfo);
+ //add_thread(loop, 0, 8);
+ //add_thread(consumer, 0, 3);
+ add_thread(test_super, 0, 4);
}
diff --git a/usr/test.c b/usr/test.c
new file mode 100644
index 0000000..6210384
--- /dev/null
+++ b/usr/test.c
@@ -0,0 +1,191 @@
+#include <cpu.h>
+#include <graphics/lfb.h>
+#include <sys/schedule.h>
+#include <usr/string.h>
+#include <util/mutex.h>
+
+#define MAX_ITER 8192
+#define MULTIPLIER 1000000/900
+
+static unsigned long ti, tf;
+static unsigned long times[MAX_ITER];
+static unsigned long idx = 0;
+
+void test_results(unsigned long off)
+{
+ unsigned long mean=0, stdev=0, max=0;
+ for (unsigned long i = 0; i < MAX_ITER; i++) {
+ mean += times[i];
+ if (times[i] > max)
+ max = times[i];
+ }
+ mean /= MAX_ITER;
+ for (unsigned long i = 0; i < MAX_ITER; i++) {
+ unsigned long term = (times[i]-mean)*(times[i]-mean)/MAX_ITER;
+ stdev += term;
+ }
+ static char str[13];
+ char* start;
+ start = ulong_to_string(mean, str);
+ draw_string(off*13, 12, start);
+ start = ulong_to_string(stdev, str);
+ draw_string(off*13, 13, start);
+ start = ulong_to_string(max, str);
+ draw_string(off*13, 14, start);
+}
+
+void nopfxn(void) {}
+
+void trace_test(void)
+{
+ sys0_32(SYS_TIME_2, &ti);
+ sys0_32(SYS_TIME_2, &tf);
+ times[idx++] = (tf-ti)*MULTIPLIER;
+}
+
+void switch_test(void)
+{
+ sys0_32(SYS_TIME_2, &ti);
+ sys0(SYS_YIELD);
+ sys0_32(SYS_TIME_2, &tf);
+ times[idx++] = (tf-ti)*MULTIPLIER;
+}
+
+void add_low_test(void)
+{
+ sys0_32(SYS_TIME_2, &ti);
+ add_thread(nopfxn, 0, 6);
+ sys0_32(SYS_TIME_2, &tf);
+ times[idx++] = (tf-ti)*MULTIPLIER;
+}
+
+void add_high_test(void)
+{
+ sys0_32(SYS_TIME_2, &ti);
+ add_thread(nopfxn, 0, 1);
+ sys0_32(SYS_TIME_2, &tf);
+ times[idx++] = (tf-ti)*MULTIPLIER;
+}
+
+void mutex_create_test(void)
+{
+ struct Mutex* m;
+ sys0_32(SYS_TIME_2, &ti);
+ m = create_mutex(0);
+ sys0_32(SYS_TIME_2, &tf);
+ delete_mutex(m);
+ times[idx++] = (tf-ti)*MULTIPLIER;
+}
+
+void mutex_delete_test(void)
+{
+ struct Mutex* m = create_mutex(0);
+ sys0_32(SYS_TIME_2, &ti);
+ delete_mutex(m);
+ sys0_32(SYS_TIME_2, &tf);
+ times[idx++] = (tf-ti)*MULTIPLIER;
+}
+
+void mutex_lock_test(struct Mutex* m)
+{
+ sys0_32(SYS_TIME_2, &ti);
+ lock_mutex(m);
+ sys0_32(SYS_TIME_2, &tf);
+ unlock_mutex(m);
+ times[idx++] = (tf-ti)*MULTIPLIER;
+}
+
+void mutex_unlock_test(struct Mutex* m)
+{
+ lock_mutex(m);
+ sys0_32(SYS_TIME_2, &ti);
+ unlock_mutex(m);
+ sys0_32(SYS_TIME_2, &tf);
+ times[idx++] = (tf-ti)*MULTIPLIER;
+}
+
+void semaphore_p_test(unsigned long* sem)
+{
+ sys0_32(SYS_TIME_2, &ti);
+ sys1(SYS_SEMAPHORE_P, sem);
+ sys0_32(SYS_TIME_2, &tf);
+ times[idx++] = (tf-ti)*MULTIPLIER;
+}
+
+void semaphore_v_test(unsigned long* sem)
+{
+ sys0_32(SYS_TIME_2, &ti);
+ sys1(SYS_SEMAPHORE_V, sem);
+ sys0_32(SYS_TIME_2, &tf);
+ times[idx++] = (tf-ti)*MULTIPLIER;
+}
+
+void test_super(void)
+{
+ for (unsigned long i = 0; i < MAX_ITER; i++) {
+ add_thread(trace_test, 0, 2);
+ }
+ add_thread(test_results,(void*) 0, 0);idx = 0;
+
+ for (unsigned long i = 0; i < MAX_ITER; i++) {
+ add_thread(switch_test, 0, 2);
+ }
+ add_thread(test_results,(void*) 1, 0);idx = 0;
+
+ for (unsigned long i = 0; i < MAX_ITER; i++) {
+ add_thread(add_low_test, 0, 2);
+ }
+ add_thread(test_results,(void*) 2, 0);idx = 0;
+
+ for (unsigned long i = 0; i < MAX_ITER; i++) {
+ add_thread(add_high_test, 0, 2);
+ }
+ add_thread(test_results,(void*) 3, 0);idx = 0;
+
+ struct Mutex* m;
+ for (unsigned long i = 0; i < MAX_ITER; i++) {
+ add_thread(mutex_create_test, 0, 2);
+ }
+ add_thread(test_results,(void*) 4, 0);idx = 0;
+ for (unsigned long i = 0; i < MAX_ITER; i++) {
+ add_thread(mutex_delete_test, 0, 2);
+ }
+ add_thread(test_results,(void*) 5, 0);idx = 0;
+ for (unsigned long i = 0; i < MAX_ITER; i++) {
+ m = create_mutex(0);
+ lock_mutex(m);
+ add_thread(mutex_lock_test, 0, 2);
+ unlock_mutex(m);
+ delete_mutex(m);
+ }
+ add_thread(test_results,(void*) 6, 0);idx = 0;
+ for (unsigned long i = 0; i < MAX_ITER; i++) {
+ m = create_mutex(0);
+ add_thread(mutex_lock_test, 0, 2);
+ delete_mutex(m);
+ }
+ add_thread(test_results,(void*) 7, 0);idx = 0;
+ for (unsigned long i = 0; i < MAX_ITER; i++) {
+ m = create_mutex(0);
+ add_thread(mutex_unlock_test, 0, 2);
+ delete_mutex(m);
+ }
+ add_thread(test_results,(void*) 8, 0);idx = 0;
+
+ static unsigned long semp = 0;
+ for (unsigned long i = 0; i < MAX_ITER; i++) {
+ semp = 1;
+ add_thread(semaphore_p_test, &semp, 2);
+ }
+ add_thread(test_results,(void*) 9, 0);idx = 0;
+ for (unsigned long i = 0; i < MAX_ITER; i++) {
+ semp = 0;
+ add_thread(semaphore_v_test, &semp, 2);
+ }
+ add_thread(test_results,(void*) 10, 0);idx = 0;
+ for (unsigned long i = 0; i < MAX_ITER; i++) {
+ semp = 1;
+ add_thread(semaphore_v_test, &semp, 2);
+ }
+ add_thread(test_results,(void*) 11, 0);idx = 0;
+}