Skip to content

Commit

Permalink
patina_bench: Misc tweaks
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 673f5d8 commit 8699961
Show file tree
Hide file tree
Showing 12 changed files with 233 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,47 @@

/* lo and hi is actually running at the same prio */
#define ITERATION 10000
/* #define PRINT_ALL */
#define PRINT_ALL

thdid_t yield_hi = 0, yield_lo = 0;

volatile cycles_t start;
volatile cycles_t end;
volatile int count;

struct perfdata perf;
cycles_t result[ITERATION] = {0, };

/***
* We're measuring 2-way context switch time.
* We're measuring one-way context switch time.
*/
void
yield_hi_thd(void *d)
{
/* Never stops running; low priority controls how many iters to run. */
while (1) {
cycles_t end;

while (count < ITERATION) {
debug("h1,");

start = time_now();
sched_thd_yield_to(yield_lo);
end = time_now();

debug("h2,");

perfdata_add(&perf, end - start);

count++;
}

while (1) ;
}

void
yield_lo_thd(void *d)
{
int i;
int first = 0;
cycles_t end;

for (i = 0; i < ITERATION + 1; i++) {
while (count < ITERATION) {
debug("l1,");

start = time_now();
Expand All @@ -55,16 +66,16 @@ yield_lo_thd(void *d)

debug("l2,");

if (first == 0) first = 1;
else perfdata_add(&perf, end - start);
perfdata_add(&perf, end - start);

count++;
}

perfdata_calc(&perf);
#ifdef PRINT_ALL
perfdata_all(&perf);
#else
perfdata_print(&perf);
perfdata_raw(&perf);
#endif
perfdata_calc(&perf);
perfdata_print(&perf);

while (1) ;
}
Expand All @@ -77,6 +88,8 @@ test_yield(void)
SCHED_PARAM_CONS(SCHEDP_PRIO, 6)
};

count = 0;

perfdata_init(&perf, "Context switch time", result, ITERATION);

printc("Create threads:\n");
Expand Down
37 changes: 25 additions & 12 deletions src/components/implementation/tests/bench_sl_yield/bench_sl_yield.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

/* lo and hi is actually running at the same prio */
#define ITERATION 10000
/* #define PRINT_ALL */
#define PRINT_ALL

/* Ensure this is the same as what is in sl_mod_fprr.c */
#define SL_FPRR_NPRIOS 32
Expand All @@ -32,29 +32,40 @@ struct sl_thd *testing_thread;
thdid_t thdid1, thdid2;

volatile cycles_t start;
volatile cycles_t end;
volatile int count;

struct perfdata perf;
cycles_t result[ITERATION] = {0, };

static void
thd1_fn()
{
/* Never stops running; low priority controls how many iters to run. */
while (1) {
cycles_t end;

while (count < ITERATION) {
debug("h1,");

start = time_now();
sl_thd_yield(thdid2);
end = time_now();

debug("h2,");

perfdata_add(&perf, end - start);

count++;
}

while (1);
}

static void
thd2_fn()
{
int i;
int first = 0;
cycles_t end;

for (i = 0; i < ITERATION + 1; i++) {
while (count < ITERATION) {
debug("l1,");

start = time_now();
Expand All @@ -63,16 +74,16 @@ thd2_fn()

debug("l2,");

if (first == 0) first = 1;
else perfdata_add(&perf, end - start);
perfdata_add(&perf, end - start);

count++;
}

perfdata_calc(&perf);
#ifdef PRINT_ALL
perfdata_all(&perf);
#else
perfdata_print(&perf);
perfdata_raw(&perf);
#endif
perfdata_calc(&perf);
perfdata_print(&perf);

while (1) ;
}
Expand Down Expand Up @@ -104,6 +115,8 @@ cos_init(void)
struct cos_defcompinfo *defci = cos_defcompinfo_curr_get();
struct cos_compinfo *ci = cos_compinfo_get(defci);

count = 0;

PRINTC("Thread switch benchmark for the scheduling library (sl)\n");
cos_meminfo_init(&(ci->mi), BOOT_MEM_KM_BASE, COS_MEM_KERN_PA_SZ, BOOT_CAPTBL_SELF_UNTYPED_PT);
cos_defcompinfo_init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@
#include <patina.h>
#include <perfdata.h>

#define COLD_CACHE
#ifdef COLD_CACHE
#define cache_flush() __cache_flush()
#define COLD_OFFSET 1
#define COLD_INDEX 0
#else
#define cache_flush()
#define COLD_OFFSET 0
#define COLD_INDEX -1
#endif

#define CACHE_SIZE 512 * 1024
#define CACHE_LINE_SIZE 32

#undef PATINA_CHAN_TRACE_DEBUG
#ifdef PATINA_CHAN_TRACE_DEBUG
#define debug(format, ...) printc(format, ##__VA_ARGS__)
Expand All @@ -18,11 +32,14 @@
#endif

/* One low-priority thread and one high-priority thread contends on the lock */
#ifdef COLD_CACHE
#define ITERATION 10 * 10
#else
#define ITERATION 10 * 1000
#define PRINT_ALL
#endif
#undef PRINT_ALL

/* Two options are available: Sender at low/high prio, data words 4 */
#undef READER_HIGH
#define DATA_WORDS 2

thdid_t chan_reader = 0, chan_writer = 0;
Expand Down Expand Up @@ -60,6 +77,20 @@ patina_chan_r_t rid2;
patina_chan_s_t sid;
patina_chan_s_t sid2;

volatile char pool[CACHE_SIZE * 4] = {
0,
};

void
__cache_flush()
{
int agg = 1;
for (int i = 0; i < CACHE_SIZE * 4; i += CACHE_LINE_SIZE) {
pool[i] += agg;
agg = pool[i];
}
}

/***
* The two threads reciprocally sends and receives.
*/
Expand All @@ -84,10 +115,10 @@ void
chan_writer_thd(void *d)
{
int i;
int first = 0;

for (int i = 0; i < ITERATION + 1; i++) {
for (int i = 0; i < ITERATION + COLD_OFFSET; i++) {
debug("w1,");
cache_flush();
ts1[0] = time_now();
debug("ts1: %d,", ts1[0]);
debug("w2,");
Expand All @@ -99,35 +130,25 @@ chan_writer_thd(void *d)
ts3[0] = time_now();
debug("w5,");

if (first == 0)
first = 1;
else {
if (ts2[0] > ts1[0] && ts3[0] > ts2[0]) {
perfdata_add(&perf1, ts2[0] - ts1[0]);
perfdata_add(&perf2, ts3[0] - ts2[0]);
perfdata_add(&perf3, ts3[0] - ts1[0]);
}
if (ts2[0] > ts1[0] && ts3[0] > ts2[0] && i != COLD_INDEX) {
perfdata_add(&perf1, ts2[0] - ts1[0]);
perfdata_add(&perf2, ts3[0] - ts2[0]);
perfdata_add(&perf3, ts3[0] - ts1[0]);
}
}

#ifdef PRINT_ALL
perfdata_raw(&perf1);
perfdata_raw(&perf2);
perfdata_raw(&perf3);
#endif
perfdata_calc(&perf1);
perfdata_calc(&perf2);
perfdata_calc(&perf3);
#ifdef PRINT_ALL
#ifdef READER_HIGH
perfdata_all(&perf1);
#else
perfdata_all(&perf2);
#endif
perfdata_all(&perf3);
#else
#ifdef READER_HIGH

perfdata_print(&perf1);
#else
perfdata_print(&perf2);
#endif
perfdata_print(&perf3);
#endif

while (1)
;
Expand All @@ -137,18 +158,13 @@ void
test_chan(void)
{
int i;
int first = 0;
cycles_t begin, end;

#ifdef READER_HIGH
sched_param_t sps[] = {SCHED_PARAM_CONS(SCHEDP_PRIO, 4), SCHED_PARAM_CONS(SCHEDP_PRIO, 6)};
#else
sched_param_t sps[] = {SCHED_PARAM_CONS(SCHEDP_PRIO, 6), SCHED_PARAM_CONS(SCHEDP_PRIO, 4)};
#endif

/* Uncontended lock taking/releasing */
perfdata_init(&perf1, "Uncontended channel - selfloop", result1, ITERATION);
for (i = 0; i < ITERATION + 1; i++) {
for (i = 0; i < ITERATION; i++) {
begin = time_now();

debug("send\n");
Expand All @@ -157,17 +173,13 @@ test_chan(void)
patina_channel_recv(rid, tmp, 1, 0);

end = time_now();
if (first == 0)
first = 1;
else
perfdata_add(&perf1, end - begin);
perfdata_add(&perf1, end - begin);
}
perfdata_calc(&perf1);
#ifdef PRINT_ALL
perfdata_all(&perf1);
#else
perfdata_print(&perf1);
perfdata_raw(&perf1);
#endif
perfdata_calc(&perf1);
perfdata_print(&perf1);

perfdata_init(&perf1, "Contended channel - reader high use this", result1, ITERATION);
perfdata_init(&perf2, "Contended channel - writer high use this", result2, ITERATION);
Expand All @@ -176,11 +188,11 @@ test_chan(void)
printc("Create threads:\n");

chan_reader = sched_thd_create(chan_reader_thd, NULL);
printc("\tcreating reader thread %d at prio %d\n", chan_reader, sps[0]);
printc("\tcreating reader thread %d at prio %d\n", chan_reader, sps[1]);
sched_thd_param_set(chan_reader, sps[0]);

chan_writer = sched_thd_create(chan_writer_thd, NULL);
printc("\tcreating writer thread %d at prio %d\n", chan_writer, sps[1]);
printc("\tcreating writer thread %d at prio %d\n", chan_writer, sps[0]);
sched_thd_param_set(chan_writer, sps[1]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,13 @@ patina_chan_r_t rid;
patina_event_t evt;

/* Keep these settings below consistent with the sender side */
#undef READER_HIGH
#define USE_EVTMGR
#undef USE_EVTMGR

#define TEST_CHAN_ITEM_SZ sizeof(u32_t)
#define TEST_CHAN_NSLOTS 2
#define TEST_CHAN_SEND_ID 3
#define TEST_CHAN_RECV_ID 4
/* We are the receiver, and we don't care about data gathering */
#ifdef READER_HIGH
#define TEST_CHAN_PRIO_SELF 4
#else
#define TEST_CHAN_PRIO_SELF 5
#endif

typedef unsigned int cycles_32_t;

Expand Down
Loading

0 comments on commit 8699961

Please sign in to comment.