From: Edmond Chung Date: Wed, 18 Aug 2021 20:37:04 +0000 (-0700) Subject: rebalance_interrupts: Change affinity ownership to system X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=3b62eb18a74ed50500d5878c960585fd99e432f5;p=GitHub%2FLineageOS%2Fandroid_hardware_samsung.git rebalance_interrupts: Change affinity ownership to system Bug: 196058977 Test: Check affinity file ownerships Change-Id: I4e63d9e6574e4730c452de4e18ae4b60b4ef8c64 --- diff --git a/rebalance_interrupts/rebalance_interrupts.cpp b/rebalance_interrupts/rebalance_interrupts.cpp index b0d2f69..77a0bfb 100644 --- a/rebalance_interrupts/rebalance_interrupts.cpp +++ b/rebalance_interrupts/rebalance_interrupts.cpp @@ -224,6 +224,33 @@ bool RebalanceIrqs(const list>>& action_to_irqs) { return true; } +void ChownIrqAffinity() { + std::unique_ptr irq_dir(opendir(PROC_IRQDIR), closedir); + if (!irq_dir) { + PLOG(ERROR) << "opening dir " PROC_IRQDIR; + return; + } + + struct dirent *entry; + while ((entry = readdir(irq_dir.get()))) { + // If the directory entry isn't a parsable number, skip it. + // . and .. get skipped here. + unsigned throwaway; + if (!ParseUint(entry->d_name, &throwaway)) + continue; + + string affinity_path(PROC_IRQDIR "/"); + affinity_path += entry->d_name; + affinity_path += "/smp_affinity"; + chown(affinity_path.c_str(), 1000, 1000); + + string affinity_list_path(PROC_IRQDIR "/"); + affinity_list_path += entry->d_name; + affinity_list_path += "/smp_affinity_list"; + chown(affinity_list_path.c_str(), 1000, 1000); + } +} + int main(int /* argc */, char* /* argv */[]) { map> irq_mapping; list>> action_to_irqs; @@ -238,6 +265,10 @@ int main(int /* argc */, char* /* argv */[]) { return 1; } + // Change ownership of smp_affinity and smp_affinity_list handles + // from root to system. + ChownIrqAffinity(); + // Some IRQs are already assigned to a subset of cores, usually for // good reason (like some drivers have an IRQ per core, for per-core // queues.) Find the set of IRQs that haven't been mapped to specific