diff options
author | Ray Chi <raychi@google.com> | 2022-03-01 21:57:03 +0800 |
---|---|---|
committer | Ray Chi <raychi@google.com> | 2022-05-04 09:39:42 +0800 |
commit | 49a9b9f3ddbf31bc7c84e23f06e7278c7366d4c6 (patch) | |
tree | 674664e6db02dec9c4f909d867067d93065f411d | |
parent | bc34b8944ff413233cfec0ec4b17e417547c9a8c (diff) | |
download | gs101-49a9b9f3ddbf31bc7c84e23f06e7278c7366d4c6.tar.gz |
tune usb irq (dwc3) in usb gadget hal
Since affinity permission is changed from root to system, original
permission change by script can't be used. Therefore, this patch
will move the functionality to usb gadget hal.
Bug: 220996010
Test: dwc3 irq could be located in medium/big cores after USB function switch
Change-Id: Id993db9fc303e85a9a6337a0e41b1dfd6fc9a86a
(cherry picked from commit f363704a92fd7611cf01c8b3bcaf6e8913255207)
-rw-r--r-- | usb/gadget/UsbGadget.cpp | 58 | ||||
-rw-r--r-- | usb/gadget/UsbGadget.h | 10 |
2 files changed, 65 insertions, 3 deletions
diff --git a/usb/gadget/UsbGadget.cpp b/usb/gadget/UsbGadget.cpp index 5c0021fe..361cefd7 100644 --- a/usb/gadget/UsbGadget.cpp +++ b/usb/gadget/UsbGadget.cpp @@ -33,13 +33,55 @@ namespace gadget { namespace V1_2 { namespace implementation { -UsbGadget::UsbGadget() { +UsbGadget::UsbGadget() : mGadgetIrqPath("") { if (access(OS_DESC_PATH, R_OK) != 0) { ALOGE("configfs setup not done yet"); abort(); } } +V1_0::Status UsbGadget::getUsbGadgetIrqPath() { + std::string irqs; + size_t read_pos = 0; + size_t found_pos = 0; + + if (!ReadFileToString(kProcInterruptsPath, &irqs)) { + ALOGE("cannot read all interrupts"); + return Status::ERROR; + } + + while (true) { + found_pos = irqs.find_first_of("\n", read_pos); + if (found_pos == std::string::npos) { + ALOGI("the string of all interrupts is unexpected"); + return Status::ERROR; + } + + std::string single_irq = irqs.substr(read_pos, found_pos - read_pos); + + if (single_irq.find("dwc3", 0) != std::string::npos) { + unsigned int dwc3_irq_number; + size_t dwc3_pos = single_irq.find_first_of(":"); + if (!ParseUint(single_irq.substr(0, dwc3_pos), &dwc3_irq_number)) { + ALOGI("unknown IRQ strings"); + return Status::ERROR; + } + + mGadgetIrqPath = kProcIrqPath + single_irq.substr(0, dwc3_pos) + kSmpAffinityList; + break; + } + + if (found_pos == irqs.npos) { + ALOGI("USB gadget doesn't start"); + return Status::ERROR; + } + + read_pos = found_pos + 1; + } + + return Status::SUCCESS; +} + void currentFunctionsAppliedCallback(bool functionsApplied, void *payload) { UsbGadget *gadget = (UsbGadget *)payload; gadget->mCurrentUsbFunctionsApplied = functionsApplied; @@ -346,6 +388,10 @@ Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions, mCurrentUsbFunctions = functions; mCurrentUsbFunctionsApplied = false; + // Get the gadget IRQ number before tearDownGadget() + if (mGadgetIrqPath.empty()) + getUsbGadgetIrqPath(); + // Unlink the gadget and stop the monitor if running. V1_0::Status status = tearDownGadget(); if (status != Status::SUCCESS) { @@ -378,9 +424,15 @@ Return<void> UsbGadget::setCurrentUsbFunctions(uint64_t functions, } if (functions & GadgetFunction::NCM) { - SetProperty("vendor.usb.dwc3_irq", "big"); + if (!mGadgetIrqPath.empty()) { + if (!WriteStringToFile(BIG_CORE, mGadgetIrqPath)) + ALOGI("Cannot move gadget IRQ to big core, path:%s", mGadgetIrqPath.c_str()); + } } else { - SetProperty("vendor.usb.dwc3_irq", "medium"); + if (!mGadgetIrqPath.empty()) { + if (!WriteStringToFile(MEDIUM_CORE, mGadgetIrqPath)) + ALOGI("Cannot move gadget IRQ to medium core, path:%s", mGadgetIrqPath.c_str()); + } } ALOGI("Usb Gadget setcurrent functions called successfully"); diff --git a/usb/gadget/UsbGadget.h b/usb/gadget/UsbGadget.h index 2669f8da..f89476d8 100644 --- a/usb/gadget/UsbGadget.h +++ b/usb/gadget/UsbGadget.h @@ -19,6 +19,7 @@ #include <android-base/file.h> #include <android-base/properties.h> #include <android-base/unique_fd.h> +#include <android-base/parseint.h> #include <android-base/strings.h> #include <android/hardware/usb/gadget/1.2/IUsbGadget.h> #include <android/hardware/usb/gadget/1.2/types.h> @@ -44,6 +45,7 @@ namespace implementation { using ::android::sp; using ::android::base::GetProperty; using ::android::base::SetProperty; +using ::android::base::ParseUint; using ::android::base::unique_fd; using ::android::base::ReadFileToString; using ::android::base::Trim; @@ -71,6 +73,9 @@ using ::android::hardware::usb::gadget::V1_2::GadgetFunction; using ::std::string; constexpr char kGadgetName[] = "11110000.dwc3"; +constexpr char kProcInterruptsPath[] = "/proc/interrupts"; +constexpr char kProcIrqPath[] = "/proc/irq/"; +constexpr char kSmpAffinityList[] = "/smp_affinity_list"; #ifndef UDC_PATH #define UDC_PATH "/sys/class/udc/11110000.dwc3/" #endif @@ -78,11 +83,15 @@ static MonitorFfs monitorFfs(kGadgetName); #define SPEED_PATH UDC_PATH "current_speed" +#define BIG_CORE "6" +#define MEDIUM_CORE "4" + struct UsbGadget : public IUsbGadget { UsbGadget(); // Makes sure that only one request is processed at a time. std::mutex mLockSetCurrentFunction; + std::string mGadgetIrqPath; uint64_t mCurrentUsbFunctions; bool mCurrentUsbFunctionsApplied; UsbSpeed mUsbSpeed; @@ -99,6 +108,7 @@ struct UsbGadget : public IUsbGadget { private: Status tearDownGadget(); + Status getUsbGadgetIrqPath(); Status setupFunctions(uint64_t functions, const sp<V1_0::IUsbGadgetCallback> &callback, uint64_t timeout); }; |