tune usb irq (dwc3) based on usb function

This among other things greatly increases tethering performance.

Bug: 185092876
Test: TreeHugger, built and booted on an oriole, enabled tethering
Signed-off-by: Maciej Żenczykowski <maze@google.com>
Change-Id: Ic9f0b4bef05250bb38c91dc1e046366098d98dc0
diff --git a/conf/init.gs101.usb.rc b/conf/init.gs101.usb.rc
index b8ffc0a..d0f19a3 100644
--- a/conf/init.gs101.usb.rc
+++ b/conf/init.gs101.usb.rc
@@ -85,6 +85,12 @@
 on property:persist.vendor.usb.usbradio.config=*
    start usbd
 
+on property:vendor.usb.dwc3_irq=medium
+   exec /vendor/bin/hw/set_usb_irq.sh medium
+
+on property:vendor.usb.dwc3_irq=big
+   exec /vendor/bin/hw/set_usb_irq.sh big
+
 on charger
     mkdir /config/usb_gadget/g1
     mkdir /config/usb_gadget/g1/strings/0x409
diff --git a/device.mk b/device.mk
index 9c6d1da..5a523c8 100644
--- a/device.mk
+++ b/device.mk
@@ -261,6 +261,7 @@
 # Shell scripts
 PRODUCT_COPY_FILES += \
 	device/google/gs101/init.insmod.sh:$(TARGET_COPY_OUT_VENDOR)/bin/init.insmod.sh \
+	device/google/gs101/set_usb_irq.sh:$(TARGET_COPY_OUT_VENDOR)/bin/hw/set_usb_irq.sh \
 
 # insmod files
 PRODUCT_COPY_FILES += \
diff --git a/set_usb_irq.sh b/set_usb_irq.sh
new file mode 100755
index 0000000..29d3781
--- /dev/null
+++ b/set_usb_irq.sh
@@ -0,0 +1,16 @@
+#!/vendor/bin/sh
+
+# Switch into /proc/irq/$IRQ for the dwc3 usb controller
+cd /proc/irq/*/dwc3/.. || exit 7
+
+# Move the USB Controller (DWC3) interrupt as requested
+# Modem and DIT are on 0/2/5 depending on throughput, so avoid those.
+# 0-3 small, 4-5 medium, 6-7 big
+case "$1" in
+  medium) core=4;;
+  big) core=6;;
+  *) core=0;;
+esac
+
+# This can sometimes fail due to smp_affinity_list no longer existing...
+echo "${core}" > smp_affinity_list
diff --git a/usb/UsbGadget.cpp b/usb/UsbGadget.cpp
index b153e20..909fb48 100644
--- a/usb/UsbGadget.cpp
+++ b/usb/UsbGadget.cpp
@@ -367,6 +367,12 @@
         goto error;
     }
 
+    if (functions & GadgetFunction::NCM) {
+        SetProperty("vendor.usb.dwc3_irq", "big");
+    } else {
+        SetProperty("vendor.usb.dwc3_irq", "medium");
+    }
+
     ALOGI("Usb Gadget setcurrent functions called successfully");
     return Void();