2014-06-03 21:18:09 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2014 Travis Geiselbrecht
|
|
|
|
|
*
|
2019-07-05 17:22:23 -07:00
|
|
|
* Use of this source code is governed by a MIT-style
|
|
|
|
|
* license that can be found in the LICENSE file or at
|
|
|
|
|
* https://opensource.org/licenses/MIT
|
2014-06-03 21:18:09 -07:00
|
|
|
*/
|
|
|
|
|
#if ARM_WITH_CACHE
|
|
|
|
|
|
2015-09-08 18:24:37 -07:00
|
|
|
#include <stdbool.h>
|
2014-06-03 21:18:09 -07:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <arch.h>
|
|
|
|
|
#include <arch/ops.h>
|
2019-07-13 16:56:33 -07:00
|
|
|
#include <lk/console_cmd.h>
|
2014-06-03 21:18:09 -07:00
|
|
|
#include <platform.h>
|
|
|
|
|
|
2019-06-19 20:54:28 -07:00
|
|
|
static void bench_cache(size_t bufsize, uint8_t *buf) {
|
2014-06-03 21:18:09 -07:00
|
|
|
lk_bigtime_t t;
|
2015-09-08 18:24:37 -07:00
|
|
|
bool do_free;
|
|
|
|
|
|
2015-09-10 12:11:34 -07:00
|
|
|
if (buf == 0) {
|
2015-09-08 18:24:37 -07:00
|
|
|
buf = memalign(PAGE_SIZE, bufsize);
|
|
|
|
|
do_free = true;
|
2015-09-10 12:11:34 -07:00
|
|
|
} else {
|
2015-09-08 18:24:37 -07:00
|
|
|
do_free = false;
|
|
|
|
|
}
|
2014-06-03 21:18:09 -07:00
|
|
|
|
2014-10-19 01:02:43 -07:00
|
|
|
printf("buf %p, size %zu\n", buf, bufsize);
|
2014-06-03 21:18:09 -07:00
|
|
|
|
2014-10-19 01:02:43 -07:00
|
|
|
if (!buf)
|
|
|
|
|
return;
|
2014-06-03 21:18:09 -07:00
|
|
|
|
|
|
|
|
t = current_time_hires();
|
2014-10-19 01:02:43 -07:00
|
|
|
arch_clean_cache_range((addr_t)buf, bufsize);
|
2014-06-03 21:18:09 -07:00
|
|
|
t = current_time_hires() - t;
|
|
|
|
|
|
2014-10-19 01:02:43 -07:00
|
|
|
printf("took %llu usecs to clean %d bytes (cold)\n", t, bufsize);
|
2014-06-03 21:18:09 -07:00
|
|
|
|
2014-10-19 01:02:43 -07:00
|
|
|
memset(buf, 0x99, bufsize);
|
2014-06-03 21:18:09 -07:00
|
|
|
|
|
|
|
|
t = current_time_hires();
|
2014-10-19 01:02:43 -07:00
|
|
|
arch_clean_cache_range((addr_t)buf, bufsize);
|
2014-06-03 21:18:09 -07:00
|
|
|
t = current_time_hires() - t;
|
|
|
|
|
|
2015-09-08 18:24:37 -07:00
|
|
|
if (do_free)
|
|
|
|
|
free(buf);
|
2014-06-03 21:18:09 -07:00
|
|
|
|
2015-09-08 18:24:37 -07:00
|
|
|
printf("took %llu usecs to clean %d bytes (hot)\n", t, bufsize);
|
2014-10-19 01:02:43 -07:00
|
|
|
}
|
|
|
|
|
|
2019-06-19 20:54:28 -07:00
|
|
|
static int cache_tests(int argc, const cmd_args *argv) {
|
2016-02-14 12:24:01 -08:00
|
|
|
uint8_t *buf;
|
2015-09-10 12:11:34 -07:00
|
|
|
buf = (uint8_t *)((argc > 1) ? argv[1].u : 0UL);
|
|
|
|
|
|
2014-10-19 01:02:43 -07:00
|
|
|
printf("testing cache\n");
|
|
|
|
|
|
2015-09-08 18:24:37 -07:00
|
|
|
bench_cache(2*1024, buf);
|
|
|
|
|
bench_cache(64*1024, buf);
|
|
|
|
|
bench_cache(256*1024, buf);
|
|
|
|
|
bench_cache(1*1024*1024, buf);
|
|
|
|
|
bench_cache(8*1024*1024, buf);
|
2014-06-03 21:18:09 -07:00
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
STATIC_COMMAND_START
|
2014-10-23 14:35:57 -07:00
|
|
|
STATIC_COMMAND("cache_tests", "test/bench the cpu cache", &cache_tests)
|
2014-06-03 21:18:09 -07:00
|
|
|
STATIC_COMMAND_END(cache_tests);
|
|
|
|
|
|
|
|
|
|
#endif
|