添加CPU性能指令

This commit is contained in:
gb 2024-01-29 14:47:35 +08:00
parent 6104c9dcdd
commit 2f9cf45ec3
2 changed files with 28 additions and 12 deletions

View File

@ -31,11 +31,14 @@ static void *(*old_malloc_hook)(size_t, const void *) = nullptr;
static void (*old_free_hook)(void *ptr, const void *caller) = nullptr;
static FILE* g_mem_file = nullptr;
static uint64_t total_size = 0;
static bool record_ = false;
static void * my_malloc_hook(size_t size, const void *caller)
{
void *result;
/* Restore all old hooks */
__malloc_hook = old_malloc_hook;
if(__malloc_hook == my_malloc_hook)
__malloc_hook = nullptr;
/* Call recursively */
result = malloc(size);
/* Save underlying hooks */
@ -50,12 +53,15 @@ static void * my_malloc_hook(size_t size, const void *caller)
else
printf("+%p from %p (size = %u)\n", result, caller, size);
/* Restore our own hooks */
if(record_)
__malloc_hook = my_malloc_hook;
return result;
}
static void my_free_hook(void *ptr, const void *caller)
{
__free_hook = old_free_hook;
if(__free_hook == my_free_hook)
__free_hook = nullptr;
if(ptr)
free(ptr);
if(g_mem_file)
@ -67,9 +73,10 @@ static void my_free_hook(void *ptr, const void *caller)
else
printf("-%p from %p\n", ptr, caller);
old_free_hook = __free_hook;
if(record_)
__free_hook = my_free_hook;
}
static void record_malloc(bool enable)
void record_malloc(bool enable)
{
if(enable)
{
@ -80,6 +87,7 @@ static void record_malloc(bool enable)
std::string log(utils::format_current_time() + "\n");
fwrite(log.c_str(), 1, log.length(), g_mem_file);
record_ = true;
old_free_hook = __free_hook;
__free_hook = my_free_hook;
@ -88,21 +96,25 @@ static void record_malloc(bool enable)
}
else // if(old_malloc_hook)
{
printf("cancel log malloc.\n");
record_ = false;
// __malloc_hook = old_malloc_hook;
// old_malloc_hook = nullptr;
// __free_hook = old_free_hook;
// old_free_hook = nullptr;
if(g_mem_file)
{
std::string log(utils::format_current_time() + "\n");
fwrite(log.c_str(), 1, log.length(), g_mem_file);
// std::string log(utils::format_current_time() + "\n");
// fwrite(log.c_str(), 1, log.length(), g_mem_file);
fclose(g_mem_file);
}
g_mem_file = nullptr;
__malloc_hook = old_malloc_hook;
old_malloc_hook = nullptr;
__free_hook = old_free_hook;
old_free_hook = nullptr;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
async_scanner::async_scanner() : usb_(nullptr), cfg_mgr_(nullptr), scan_id_(0)
@ -144,6 +156,7 @@ async_scanner::async_scanner() : usb_(nullptr), cfg_mgr_(nullptr), scan_id_(0)
{
cis_->close();
utils::print_memory_usage("Memory usage when finished scanning", false);
system("sudo cpufreq-set -g ondemand");
}
usb_->write_bulk(img);
@ -563,7 +576,10 @@ dyn_mem_ptr async_scanner::handle_scan_start(LPPACK_BASE pack, uint32_t* used, p
if(scan_err_)
{
cis_->stop_scan();
cis_->close();
}
else
system("echo performance > /sys/devices/system/cpu/cpu5/cpufreq/scaling_governor");
BASE_PACKET_REPLY(*((LPPACK_BASE)reply->ptr()), pack->cmd + 1, pack->pack_id, scan_err_);
((LPPACK_BASE)reply->ptr())->payload_len = config.length() + 2;
strcpy(((LPPACK_BASE)reply->ptr())->payload, config.c_str());

View File

@ -60,8 +60,8 @@ add_packagedirs("sdk")
add_defines("BUILD_AS_DEVICE")
add_defines("VER_MAIN=2")
add_defines("VER_FAMILY=200")
add_defines("VER_DATE=20240127")
add_defines("VER_BUILD=27")
add_defines("VER_DATE=20240129")
add_defines("VER_BUILD=8")
target("conf")
set_kind("phony")