On Sun, 17 Aug 2025 10:55:14 +0300 Mohammad Gomaa <midomaxgo...@gmail.com> wrote:
> Hello, > > This patch adds tracepoints to i2c-core-base to aid with debugging I2C > probing failrues. > > The motivation for this comes from my work in Google Summer of Code (GSoC) > 2025: > "ChromeOS Platform Input Device Quality Monitoring" > https://summerofcode.withgoogle.com/programs/2025/projects/uCdIgK7K > > This is my first submission to the Linux kernel, so any feedback is welcome. Welcome Mohammad! > driver = to_i2c_driver(dev->driver); > I'll let those that own this code discuss the merits of this, and if there's a better way to achieve this. But I'll comment only on the tracing aspect of this change. > + has_id_table = driver->id_table; > + has_acpi_match = acpi_driver_match_device(dev, dev->driver); > + has_of_match = i2c_of_match_device(dev->driver->of_match_table, client); > + > + if (!has_id_table) > + trace_i2c_device_probe_debug(dev, > I2C_TRACE_REASON_NO_I2C_ID_TABLE); > + if (!has_acpi_match) > + trace_i2c_device_probe_debug(dev, > I2C_TRACE_REASON_ACPI_ID_MISMATCH); > + if (!has_of_match) > + trace_i2c_device_probe_debug(dev, > I2C_TRACE_REASON_OF_ID_MISMATCH); The above adds if statements into the running code when tracing is disabled and this causes pressure on the branch prediction and should be avoided. To avoid this, you could use the trace_<tracepoint>_enabled() helper: if (trace_i2c_device_probe_debug_enabled()) { has_id_table = driver->id_table; has_acpi_match = acpi_driver_match_device(dev, dev->driver); has_of_match = i2c_of_match_device(dev->driver->of_match_table, client); if (!has_id_table) trace_i2c_device_probe_debug(dev, I2C_TRACE_REASON_NO_I2C_ID_TABLE); if (!has_acpi_match) trace_i2c_device_probe_debug(dev, I2C_TRACE_REASON_ACPI_ID_MISMATCH); if (!has_of_match) trace_i2c_device_probe_debug(dev, I2C_TRACE_REASON_OF_ID_MISMATCH); } But I suspect there's a better way to record this information. I just wanted to inform you on the trace_<tracepoint>_enabled() logic. What it does is to add a static branch (jump label) where there's no "if" statement. It's either a nop that skips this code altogether, or it's a jmp to the code that will do the logic as well as the tracing and then jump back to where it left off. It's much more efficient to use this and it doesn't add anything to the branch prediction cache. -- Steve