2020-12-05 13:08:24 +01:00
|
|
|
#include "stdafx.h"
|
2016-03-21 20:42:14 +01:00
|
|
|
#include "Emu/Cell/PPUModule.h"
|
2019-09-08 17:36:10 +02:00
|
|
|
#include "Emu/IdManager.h"
|
2015-07-24 18:31:16 +02:00
|
|
|
|
|
|
|
|
#include "sceNp.h"
|
2015-07-26 11:15:15 +02:00
|
|
|
#include "sceNpUtil.h"
|
2015-07-24 18:31:16 +02:00
|
|
|
|
2018-08-25 14:39:00 +02:00
|
|
|
LOG_CHANNEL(sceNpUtil);
|
2015-07-24 18:31:16 +02:00
|
|
|
|
2022-05-30 22:24:25 +02:00
|
|
|
struct bandwidth_test
|
|
|
|
|
{
|
|
|
|
|
atomic_t<u32> status = SCE_NP_UTIL_BANDWIDTH_TEST_STATUS_NONE;
|
|
|
|
|
atomic_t<bool> abort = false;
|
|
|
|
|
atomic_t<bool> shutdown = false;
|
|
|
|
|
atomic_t<bool> finished = false;
|
|
|
|
|
SceNpUtilBandwidthTestResult test_result{};
|
|
|
|
|
|
|
|
|
|
static constexpr auto thread_name = "HLE SceNpBandwidthTest"sv;
|
|
|
|
|
|
|
|
|
|
void operator()()
|
|
|
|
|
{
|
|
|
|
|
status = SCE_NP_UTIL_BANDWIDTH_TEST_STATUS_RUNNING;
|
|
|
|
|
u32 fake_sleep_count = 0;
|
|
|
|
|
|
|
|
|
|
while (thread_ctrl::state() != thread_state::aborting)
|
|
|
|
|
{
|
|
|
|
|
if (abort || shutdown)
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: run proper bandwidth test, probably with cellHttp
|
|
|
|
|
|
|
|
|
|
thread_ctrl::wait_for(1000); // wait 1ms
|
|
|
|
|
|
|
|
|
|
if (fake_sleep_count++ > 100) // end fake bandwidth test after 100 ms
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-12 04:05:05 +01:00
|
|
|
test_result.upload_bps = 100'000'000.0;
|
|
|
|
|
test_result.download_bps = 100'000'000.0;
|
2022-05-30 22:24:25 +02:00
|
|
|
test_result.result = CELL_OK;
|
|
|
|
|
status = SCE_NP_UTIL_BANDWIDTH_TEST_STATUS_FINISHED;
|
|
|
|
|
finished = true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct sce_np_util_manager
|
|
|
|
|
{
|
|
|
|
|
shared_mutex mtx{};
|
|
|
|
|
std::unique_ptr<named_thread<bandwidth_test>> bandwidth_test_thread;
|
|
|
|
|
|
|
|
|
|
~sce_np_util_manager()
|
|
|
|
|
{
|
|
|
|
|
join_thread();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void join_thread()
|
|
|
|
|
{
|
|
|
|
|
if (bandwidth_test_thread)
|
|
|
|
|
{
|
|
|
|
|
auto& thread = *bandwidth_test_thread;
|
|
|
|
|
thread = thread_state::aborting;
|
|
|
|
|
thread();
|
|
|
|
|
bandwidth_test_thread.reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-09-13 15:08:55 +02:00
|
|
|
error_code sceNpUtilBandwidthTestInitStart([[maybe_unused]] ppu_thread& ppu, u32 prio, u32 stack)
|
2015-07-24 18:31:16 +02:00
|
|
|
{
|
2019-09-08 17:36:10 +02:00
|
|
|
sceNpUtil.todo("sceNpUtilBandwidthTestInitStart(prio=%d, stack=%d)", prio, stack);
|
|
|
|
|
|
2021-03-02 12:59:19 +01:00
|
|
|
auto& util_manager = g_fxo->get<sce_np_util_manager>();
|
2022-05-30 22:24:25 +02:00
|
|
|
std::lock_guard lock(util_manager.mtx);
|
2019-09-08 17:36:10 +02:00
|
|
|
|
2022-05-30 22:24:25 +02:00
|
|
|
if (util_manager.bandwidth_test_thread)
|
2019-09-08 17:36:10 +02:00
|
|
|
{
|
|
|
|
|
return SCE_NP_ERROR_ALREADY_INITIALIZED;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-30 22:24:25 +02:00
|
|
|
util_manager.bandwidth_test_thread = std::make_unique<named_thread<bandwidth_test>>();
|
2019-09-08 17:36:10 +02:00
|
|
|
|
2015-07-24 18:31:16 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-08 17:36:10 +02:00
|
|
|
error_code sceNpUtilBandwidthTestGetStatus()
|
2015-07-24 18:31:16 +02:00
|
|
|
{
|
2022-05-30 22:24:25 +02:00
|
|
|
sceNpUtil.notice("sceNpUtilBandwidthTestGetStatus()");
|
2019-09-08 17:36:10 +02:00
|
|
|
|
2022-05-30 22:24:25 +02:00
|
|
|
auto& util_manager = g_fxo->get<sce_np_util_manager>();
|
|
|
|
|
std::lock_guard lock(util_manager.mtx);
|
|
|
|
|
|
|
|
|
|
if (!util_manager.bandwidth_test_thread)
|
2019-09-08 17:36:10 +02:00
|
|
|
{
|
|
|
|
|
return SCE_NP_ERROR_NOT_INITIALIZED;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-30 22:24:25 +02:00
|
|
|
return not_an_error(util_manager.bandwidth_test_thread->status);
|
2015-07-24 18:31:16 +02:00
|
|
|
}
|
|
|
|
|
|
2022-09-13 15:08:55 +02:00
|
|
|
error_code sceNpUtilBandwidthTestShutdown([[maybe_unused]] ppu_thread& ppu, vm::ptr<SceNpUtilBandwidthTestResult> result)
|
2015-07-24 18:31:16 +02:00
|
|
|
{
|
2022-05-30 22:24:25 +02:00
|
|
|
sceNpUtil.warning("sceNpUtilBandwidthTestShutdown(result=*0x%x)", result);
|
2019-09-08 17:36:10 +02:00
|
|
|
|
2021-03-02 12:59:19 +01:00
|
|
|
auto& util_manager = g_fxo->get<sce_np_util_manager>();
|
2022-05-30 22:24:25 +02:00
|
|
|
std::lock_guard lock(util_manager.mtx);
|
2019-09-08 17:36:10 +02:00
|
|
|
|
2022-05-30 22:24:25 +02:00
|
|
|
if (!util_manager.bandwidth_test_thread)
|
2019-09-08 17:36:10 +02:00
|
|
|
{
|
|
|
|
|
return SCE_NP_ERROR_NOT_INITIALIZED;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-30 22:24:25 +02:00
|
|
|
util_manager.bandwidth_test_thread->shutdown = true;
|
|
|
|
|
|
|
|
|
|
while (!util_manager.bandwidth_test_thread->finished)
|
|
|
|
|
{
|
|
|
|
|
thread_ctrl::wait_for(1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result) // TODO: what happens when this is null ?
|
|
|
|
|
{
|
|
|
|
|
*result = util_manager.bandwidth_test_thread->test_result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
util_manager.join_thread();
|
2019-09-08 17:36:10 +02:00
|
|
|
|
2015-07-24 18:31:16 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-08 17:36:10 +02:00
|
|
|
error_code sceNpUtilBandwidthTestAbort()
|
2015-07-24 18:31:16 +02:00
|
|
|
{
|
2019-09-08 17:36:10 +02:00
|
|
|
sceNpUtil.todo("sceNpUtilBandwidthTestAbort()");
|
|
|
|
|
|
2022-05-30 22:24:25 +02:00
|
|
|
auto& util_manager = g_fxo->get<sce_np_util_manager>();
|
|
|
|
|
std::lock_guard lock(util_manager.mtx);
|
|
|
|
|
|
|
|
|
|
if (!util_manager.bandwidth_test_thread)
|
2019-09-08 17:36:10 +02:00
|
|
|
{
|
|
|
|
|
return SCE_NP_ERROR_NOT_INITIALIZED;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-30 22:24:25 +02:00
|
|
|
// TODO: cellHttpTransactionAbortConnection();
|
|
|
|
|
|
|
|
|
|
util_manager.bandwidth_test_thread->abort = true;
|
|
|
|
|
|
2015-07-24 18:31:16 +02:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-21 20:42:14 +01:00
|
|
|
DECLARE(ppu_module_manager::sceNpUtil)("sceNpUtil", []()
|
2025-04-05 21:50:45 +02:00
|
|
|
{
|
|
|
|
|
REG_FUNC(sceNpUtil, sceNpUtilBandwidthTestInitStart);
|
|
|
|
|
REG_FUNC(sceNpUtil, sceNpUtilBandwidthTestShutdown);
|
|
|
|
|
REG_FUNC(sceNpUtil, sceNpUtilBandwidthTestGetStatus);
|
|
|
|
|
REG_FUNC(sceNpUtil, sceNpUtilBandwidthTestAbort);
|
|
|
|
|
});
|