tune usb irq (dwc3) in usb gadget hal am: ba3dc9b3da

Original change: https://googleplex-android-review.googlesource.com/c/device/google/gs101/+/17313948

Change-Id: I4891e7dcbb7ac57005a3eea484abb5b875c23ee3
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Ray Chi 2022-05-05 07:27:15 +00:00 committed by Automerger Merge Worker
commit 1de6118168
2 changed files with 65 additions and 3 deletions

View file

@ -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");

View file

@ -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);
};