Skip to content

Commit

Permalink
pingpong: Use perfdata
Browse files Browse the repository at this point in the history
Signed-off-by: msdx321 <[email protected]>
  • Loading branch information
msdx321 committed Feb 8, 2021
1 parent 2147dfa commit 673f5d8
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions src/components/implementation/tests/unit_pingpong/ping.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#include <cos_kernel_api.h>
#include <cos_types.h>
#include <perfdata.h>
#include <pong.h>
#include <ps.h>

#define ITER 1024
#define ITER 10 * 1000
#define PRINT_ALL

volatile ps_tsc_t fast_path, all_args;

struct perfdata perf1, perf2;
ps_tsc_t result1[ITER] = {0, };
ps_tsc_t result2[ITER] = {0, };

void
cos_init(void)
{
Expand All @@ -23,6 +29,7 @@ cos_init(void)

printc("Ping component %ld: cos_init execution\n", cos_compid());


pong_call();
ret = pong_ret();
assert(ret == 42);
Expand All @@ -48,29 +55,47 @@ cos_init(void)
tid = pong_ids(&us, &them);
assert(cos_thdid() == tid && us != them && us == cos_compid());

begin = ps_tsc();
perfdata_init(&perf1, "Ping-pong - fast_path", result1, ITER);

for (i = 0; i < ITER; i++) {
begin = ps_tsc();
pong_call();
end = ps_tsc();

perfdata_add(&perf1, end - begin);
}
end = ps_tsc();
fast_path = (end - begin)/ITER;

begin = ps_tsc();

perfdata_init(&perf2, "Ping-pong - three_return", result2, ITER);

for (i = 0; i < ITER; i++) {
begin = ps_tsc();
pong_argsrets(0, 0, 0, 0, &r0, &r1);
end = ps_tsc();

perfdata_add(&perf2, end - begin);
}
end = ps_tsc();
all_args = (end - begin)/ITER;


return;
}

int
main(void)
{
printc("Ping component %ld: main execution\n", cos_compid());
printc("Fast-path invocation: %llu cycles\n", fast_path);
printc("Three return value invocation: %llu cycles\n", all_args);
#ifdef PRINT_ALL
perfdata_raw(&perf1);
#endif
perfdata_calc(&perf1);
perfdata_print(&perf1);

#ifdef PRINT_ALL
perfdata_raw(&perf2);
#endif
perfdata_calc(&perf2);
perfdata_print(&perf2);

while(1);

return 0;
}

0 comments on commit 673f5d8

Please sign in to comment.