From 1423f40a96e9a4246f5a86488980f2c9bcf052e8 Mon Sep 17 00:00:00 2001 From: Lephe Date: Sun, 26 Mar 2023 20:40:08 +0200 Subject: [PATCH] usb: disable USB_LOG_TR() when no log is configured For some reason this has a *massive* impact on read performance, like 78 ms -> 20 ms on a full-screen read (177 kB) on the CG-50. --- include/gint/usb.h | 4 ++++ src/usb/pipes.c | 3 +++ src/usb/usb.c | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/include/gint/usb.h b/include/gint/usb.h index bb879fb..55c230d 100644 --- a/include/gint/usb.h +++ b/include/gint/usb.h @@ -391,6 +391,8 @@ void usb_read_cancel(int pipe); /* usb_set_log(): Set the logging function for the USB driver */ void usb_set_log(void (*logger)(char const *format, va_list args)); +/* usb_get_log(): Get the logging function */ +void (*usb_get_log(void))(char const *format, va_list args); /* usb_log(): Send a message to the USB log */ void usb_log(char const *format, ...); @@ -398,6 +400,8 @@ void usb_log(char const *format, ...); The function is called atomically, thus cannot be interrupted, therefore it is safe to call usb_trace() in interrupt handlers. */ void usb_set_trace(void (*tracer)(char const *message)); +/* usb_get_trace(): Get the tracing function */ +void (*usb_get_trace(void))(char const *message); /* usb_trace(): Trace the current state of the driver */ void usb_trace(char const *message); diff --git a/src/usb/pipes.c b/src/usb/pipes.c index 316f664..99ce8d3 100644 --- a/src/usb/pipes.c +++ b/src/usb/pipes.c @@ -529,6 +529,9 @@ void usb_pipe_write_bemp(int pipe) #ifdef GINT_USB_DEBUG static void USB_LOG_TR(char const *p, asyncio_op_t *t, char const *fmt, ...) { + if(!usb_get_log()) + return; + int E = USB.INTENB0.BRDYE; USB.INTENB0.BRDYE = 0; diff --git a/src/usb/usb.c b/src/usb/usb.c index 3f608a8..14adb76 100644 --- a/src/usb/usb.c +++ b/src/usb/usb.c @@ -40,6 +40,11 @@ void usb_set_log(void (*logger)(char const *format, va_list args)) usb_logger = logger; } +void (*usb_get_log(void))(char const *format, va_list args) +{ + return usb_logger; +} + void usb_log(char const *format, ...) { if(!usb_logger) return; @@ -54,6 +59,11 @@ void usb_set_trace(void (*tracer)(char const *message)) usb_tracer = tracer; } +void (*usb_get_trace(void))(char const *message) +{ + return usb_tracer; +} + void usb_trace(char const *message) { if(usb_tracer) {