Skip to content

Commit 673f5d8

Browse files
committed
pingpong: Use perfdata
Signed-off-by: msdx321 <[email protected]>
1 parent 2147dfa commit 673f5d8

1 file changed

Lines changed: 35 additions & 10 deletions

File tree

  • src/components/implementation/tests/unit_pingpong

src/components/implementation/tests/unit_pingpong/ping.c

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
#include <cos_kernel_api.h>
22
#include <cos_types.h>
3+
#include <perfdata.h>
34
#include <pong.h>
45
#include <ps.h>
56

6-
#define ITER 1024
7+
#define ITER 10 * 1000
8+
#define PRINT_ALL
79

810
volatile ps_tsc_t fast_path, all_args;
911

12+
struct perfdata perf1, perf2;
13+
ps_tsc_t result1[ITER] = {0, };
14+
ps_tsc_t result2[ITER] = {0, };
15+
1016
void
1117
cos_init(void)
1218
{
@@ -23,6 +29,7 @@ cos_init(void)
2329

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

32+
2633
pong_call();
2734
ret = pong_ret();
2835
assert(ret == 42);
@@ -48,29 +55,47 @@ cos_init(void)
4855
tid = pong_ids(&us, &them);
4956
assert(cos_thdid() == tid && us != them && us == cos_compid());
5057

51-
begin = ps_tsc();
58+
perfdata_init(&perf1, "Ping-pong - fast_path", result1, ITER);
59+
5260
for (i = 0; i < ITER; i++) {
61+
begin = ps_tsc();
5362
pong_call();
63+
end = ps_tsc();
64+
65+
perfdata_add(&perf1, end - begin);
5466
}
55-
end = ps_tsc();
56-
fast_path = (end - begin)/ITER;
5767

58-
begin = ps_tsc();
68+
69+
perfdata_init(&perf2, "Ping-pong - three_return", result2, ITER);
70+
5971
for (i = 0; i < ITER; i++) {
72+
begin = ps_tsc();
6073
pong_argsrets(0, 0, 0, 0, &r0, &r1);
74+
end = ps_tsc();
75+
76+
perfdata_add(&perf2, end - begin);
6177
}
62-
end = ps_tsc();
63-
all_args = (end - begin)/ITER;
78+
6479

6580
return;
6681
}
6782

6883
int
6984
main(void)
7085
{
71-
printc("Ping component %ld: main execution\n", cos_compid());
72-
printc("Fast-path invocation: %llu cycles\n", fast_path);
73-
printc("Three return value invocation: %llu cycles\n", all_args);
86+
#ifdef PRINT_ALL
87+
perfdata_raw(&perf1);
88+
#endif
89+
perfdata_calc(&perf1);
90+
perfdata_print(&perf1);
91+
92+
#ifdef PRINT_ALL
93+
perfdata_raw(&perf2);
94+
#endif
95+
perfdata_calc(&perf2);
96+
perfdata_print(&perf2);
97+
98+
while(1);
7499

75100
return 0;
76101
}

0 commit comments

Comments
 (0)