Skip to content

Day 21 - Cache Mechanism for hwmon Driver

Summary

Implemented a cache layer in the I2C hwmon driver to reduce unnecessary hardware access.


What I Did

  • Added cache fields:
  • temp_mc_cached
  • last_update
  • cache_interval_ms
  • Implemented update_if_needed()
  • Modified read path to use cached data
  • Added sysfs control: cache_interval

Key Insight

Previously:

read → always I2C

Now:

read → cache → (optional I2C)

Verification

Tested with different cache intervals:

  • 0 ms → always update
  • 200 ms → update every ~2 reads
  • 1000 ms → almost no updates

Observed expected behavior.


Reflection

This change is small in code, but significant in design.

It introduces:

  • time-based logic
  • state management
  • performance optimization

Conclusion

Driver evolved from:

  • functional → optimized
  • passive → decision-making