Re: [PATCH v1 0/3] Introduce cros_ec power monitoring
From: Jonathan Cameron
Date: Sun Nov 22 2026 - 15:57:05 EST
On Fri, 20 Nov 2026 09:10:22 +0000
Daniel Balint <dbalint@xxxxxxxxxx> wrote:
> On Wed, 18 Nov 2026 22:00:33 +0000
> Jonathan Cameron <jic23@xxxxxxxxxx> wrote:
>
> > Do you need that coherent snapshot to get to userspace in one go?
> >
> > For accumulator channels the way they are normally done to sysfs
> > style reads is to snapshot on each read, update an internal store
> > of accumulation since enable then provide whichever one was requested.
> > That way no data is lost - but you don't get an aligned snapshot.
> > So it depends on what maths you are going to do with them, whether
> > it can be done in kernel and if not how much interchannel skid
> > matters.
> >
> > So tell us more on why you need that coherent snapshot to userspace.
>
> Sure, I can provide more context. Usecases are broad, but an example
> would be that we calculate per-rail drain contributions over short
> time windows for comparative analysis between device states (device state
> transitions like screen on/off trigger snapshot), or for debugging and
> power profiling purposes we correlate fine-grained ODPM data frames
> (~1s intervals) with other timestamped system diagnostics in our tracing
> tools (e.g. perform per-process-per-rail energy attribution), so math
> happens server side, and the relative energy deltas between channels
> within a frame are just as important to us as their absolute values.
> In general, data from a single channel makes sense in the context of
> other channels, there wouldn't be a client that requests only one
> channel.
>
> At higher userspace sampling frequencies, e.g. ~1s trigger intervals,
> which can happen in both abovementioned cases, interchannel skid becomes
> an issue if we read individually.
> Because the latching and data delivery (up to 64 MKBP events)
> roundtrip between EC and kernel takes non-trivial bus time that's in the
> ~10 ms range, latching per sysfs read across 64 files spreads channels
> across a hundreds of ms long interval, which would compromise coherency
> and render the data minimally useful. It would also make the EC
> unnecessarily busy with redundant work, so latching per channel read
> isn't really an option.
> But to Guenter's point, this could be solved by driver-side caching.
>
>
> On Wed, 18 Nov 2026 15:00:20 -0800
> Guenter Roeck <linux@xxxxxxxxxxxx> wrote:
>
> > You could accomplish that the same way many hwmon drivers are doing it:
> > Read all attributes in one go from the hardware, then cache it for a period
> > of time.
>
> I should have mentioned the importance of timekeeping earlier. As we're
> correlating the snapshots with other diagnostic time-series data,
> userspace needs to know when accumulators were latched as accurately as
> possible.
> In contrast to IIO, in hwmon:
> (1) There is no timestamp ABI to propagate latch times, so userspace has
> to rely on its own timestamp when initiating a read.
> (2) There is no trigger ABI to force a fresh latch on demand (e.g. on a
> device state transition), so a userspace timestamp only marks the
> start of a sysfs read sweep rather than the actual hardware latch.
>
> So, unless I missed something, with a timeout-based cache in hwmon, a
> reader has no visibility into whether it's hitting newly latched or
> cached data or when the cache was actually latched (skewing time-series
> alignment) or whether the cache has expired mid-sweep across 64 sysfs
> reads.
>
> We could probably tune a short enough cache timeout where time skew
> would be negligible and mid-sweep expiries would still be infrequent,
> then it's a trade-off between accuracy and more mid-sweep expirations
> (more EC roundtrips). It could work, although we still would do 64
> sysfs reads instead of 1 on each trigger.
> So I guess it's not a must to send the coherent snapshot in one go, and
> I cannot provide any data to claim that hwmon would be a suboptimal
> solution to IIO, but our technical judgement is that IIO's explicit
> trigger, latch timestamp and single buffer read is a cleaner fit for
> power monitoring via the ChromeOS EC.
This is all good information. Capture a short version of it in cover
letter for v2 and include a link back to here for anyone wanting
the full gory details!
Jonathan