core: barrier service thread shutdown

master
Liam 2022-10-23 05:45:45 +07:00
parent 0860fffd78
commit 2d90a927c9
6 changed files with 26 additions and 7 deletions

@ -384,6 +384,7 @@ struct System::Impl {
kernel.ShutdownCores(); kernel.ShutdownCores();
cpu_manager.Shutdown(); cpu_manager.Shutdown();
debugger.reset(); debugger.reset();
services->KillNVNFlinger();
kernel.CloseServices(); kernel.CloseServices();
services.reset(); services.reset();
service_manager.reset(); service_manager.reset();

@ -48,8 +48,8 @@ namespace Kernel {
struct KernelCore::Impl { struct KernelCore::Impl {
explicit Impl(Core::System& system_, KernelCore& kernel_) explicit Impl(Core::System& system_, KernelCore& kernel_)
: time_manager{system_}, : time_manager{system_}, service_threads_manager{1, "ServiceThreadsManager"},
service_threads_manager{1, "ServiceThreadsManager"}, system{system_} {} service_thread_barrier{2}, system{system_} {}
void SetMulticore(bool is_multi) { void SetMulticore(bool is_multi) {
is_multicore = is_multi; is_multicore = is_multi;
@ -737,7 +737,12 @@ struct KernelCore::Impl {
} }
void ClearServiceThreads() { void ClearServiceThreads() {
service_threads_manager.QueueWork([this]() { service_threads.clear(); }); service_threads_manager.QueueWork([this] {
service_threads.clear();
default_service_thread.reset();
service_thread_barrier.Sync();
});
service_thread_barrier.Sync();
} }
std::mutex server_objects_lock; std::mutex server_objects_lock;
@ -802,6 +807,7 @@ struct KernelCore::Impl {
std::unordered_set<std::shared_ptr<ServiceThread>> service_threads; std::unordered_set<std::shared_ptr<ServiceThread>> service_threads;
std::weak_ptr<ServiceThread> default_service_thread; std::weak_ptr<ServiceThread> default_service_thread;
Common::ThreadWorker service_threads_manager; Common::ThreadWorker service_threads_manager;
Common::Barrier service_thread_barrier;
std::array<KThread*, Core::Hardware::NUM_CPU_CORES> shutdown_threads; std::array<KThread*, Core::Hardware::NUM_CPU_CORES> shutdown_threads;
std::array<std::unique_ptr<Kernel::KScheduler>, Core::Hardware::NUM_CPU_CORES> schedulers{}; std::array<std::unique_ptr<Kernel::KScheduler>, Core::Hardware::NUM_CPU_CORES> schedulers{};

@ -102,15 +102,19 @@ NVFlinger::~NVFlinger() {
system.CoreTiming().UnscheduleEvent(single_composition_event, {}); system.CoreTiming().UnscheduleEvent(single_composition_event, {});
} }
ShutdownLayers();
if (nvdrv) {
nvdrv->Close(disp_fd);
}
}
void NVFlinger::ShutdownLayers() {
for (auto& display : displays) { for (auto& display : displays) {
for (size_t layer = 0; layer < display.GetNumLayers(); ++layer) { for (size_t layer = 0; layer < display.GetNumLayers(); ++layer) {
display.GetLayer(layer).Core().NotifyShutdown(); display.GetLayer(layer).Core().NotifyShutdown();
} }
} }
if (nvdrv) {
nvdrv->Close(disp_fd);
}
} }
void NVFlinger::SetNVDrvInstance(std::shared_ptr<Nvidia::Module> instance) { void NVFlinger::SetNVDrvInstance(std::shared_ptr<Nvidia::Module> instance) {

@ -48,6 +48,8 @@ public:
explicit NVFlinger(Core::System& system_, HosBinderDriverServer& hos_binder_driver_server_); explicit NVFlinger(Core::System& system_, HosBinderDriverServer& hos_binder_driver_server_);
~NVFlinger(); ~NVFlinger();
void ShutdownLayers();
/// Sets the NVDrv module instance to use to send buffers to the GPU. /// Sets the NVDrv module instance to use to send buffers to the GPU.
void SetNVDrvInstance(std::shared_ptr<Nvidia::Module> instance); void SetNVDrvInstance(std::shared_ptr<Nvidia::Module> instance);

@ -303,4 +303,8 @@ Services::Services(std::shared_ptr<SM::ServiceManager>& sm, Core::System& system
Services::~Services() = default; Services::~Services() = default;
void Services::KillNVNFlinger() {
nv_flinger->ShutdownLayers();
}
} // namespace Service } // namespace Service

@ -238,6 +238,8 @@ public:
explicit Services(std::shared_ptr<SM::ServiceManager>& sm, Core::System& system); explicit Services(std::shared_ptr<SM::ServiceManager>& sm, Core::System& system);
~Services(); ~Services();
void KillNVNFlinger();
private: private:
std::unique_ptr<NVFlinger::HosBinderDriverServer> hos_binder_driver_server; std::unique_ptr<NVFlinger::HosBinderDriverServer> hos_binder_driver_server;
std::unique_ptr<NVFlinger::NVFlinger> nv_flinger; std::unique_ptr<NVFlinger::NVFlinger> nv_flinger;