First of all, I agree that technical discussions should not devolve into
personal, political, ageist, experienceist etc. off-topics and overt or
concealed insults. We are all adults here, I suppose - let's behave like
that. Non-adults are welcome to learn if needed, or present the finer sides
of their personality too ;)

Surely, the discussions are here to share opinions and knowledge, perhaps
to teach and learn too, but this can all be done in a civilized manner.
Even by semi-asocial geeks posting from a bat-cave, those like myself at
times. Soft skills are learnable like most others ;P

> In particular, I would recommend an explicit per-driver option to disable
the use of stale cached data. In that mode, the information must be fresh;
if fresh data cannot be obtained, the driver must clearly report that
failure instead of presenting an old value as a current measurement. I mean
disabling the use of stale values, not disabling the indication of their
age or the reporting of a communication failure.

As noted earlier, this is neigh impossible. Setting aside how frequently
the device itself learns of its internal state in digital form (upon
protocol request or cached in the controller so literally same data is
returned by polling that device within some timeframe), we have one program
on the computer side getting that data (age=0 if you like) and another loop
consuming and acting on it - whether in same program (mono driver/app) or
another program or even computer (NUT driver/server/client).

Maybe if your mono-app polls the device and immediately acts upon each
reading it sensed, you could assume age=0 as a required constraint. Even if
in one program you read and parse all there is first, deduce data and
actions later (e.g. estimate runtime from fresh readings charge, load, time
on-battery etc.), by the time you act the age is already not zero-ish. With
more data-relaying components and devices in play, more so.

So we can just hope to track how much above zero that age is - microseconds
or minutes, and how much is acceptable (as noted in the thread, driver
might announce that).

As also noted, with protocols that do not surely update the whole device
data snapshot simultaneously and atomically, you can well see vastly
different ages for various readings. You can also consider different max
ages as problematic, to the point of only reading some once in a driver's
uptime or very rarely (status vs. battery installation date).

>   I would like drivers to be able to report "unavailable" for a value,
and drivers should manage timeouts (that they understand because it's
device behavior) and report them as unavailable.

>  If the driver stops communicating, upsd should set everything
to unavailable.

At least the second point should be here already, unless development of
past months disrupted it again: when drivers detect they should reconnect,
they should declare datastale first and also update the driver state to
"reconnecting". There was certainly a PR for that in the recent year or so;
maybe developer docs were not updated to require that for new change sets -
should check on that bit.

Looking at `drivers/dstate.c` I see `vdstate_setinfo()` posting SETINFO on
the driver-server socket/pipe for each single written entry, so `upsd` can
update its cached view (and its per-entry timestamp) as soon as each
NUT-named data point is parsed and saved by the driver internally. The
counterpart can be seen in `server/sstate.{c,h}` and in `common/state.c`
for foundations of both.

* "`upsd` can" means it is able to do so, as soon as its file descriptor
walking loop gets that line, although many events along the way may delay
this.

Note that clocks between computers are never in precise sync, and may be
not monotonous in one computer either. (There are recent PRs to employ
system-provided monotonous clock readings where available.) So `upsd` is
IMHO a good point as the cacher and provider of data points to be an
authority about their age, at least in its view. It also does track already
when the UPS driver last talked on the bus, see MAXAGE setting.

Ages seen in drivers dstate, or in long-running clients that regularly grab
snapshots over networked protocol may differ.

There is certainly some code to walk those state trees for "data older than
X", but I can't say OTOH where it is used already and what usages might get
added due to e.g. this discussion.

Hope this helps,
Jim Klimov

PS: No AI here, fingers hurt after typing this on painted keyboard shim of
a phone for an hour while commuting.


On Mon, Nov 16, 2026, 13:55 Greg Troxel via Nut-upsdev <
[email protected]> wrote:

> Edgar Fuß via Nut-upsdev <[email protected]> writes:
>
> > Isn't the most interesting information not how old some data is, but how
> long it's overdue (taking into account the peculiarities of this specific
> hardware)?
>
> Agreed.  There are multiple ways for measurements to flow from the UPS
> unit to upsd, and as a user of upsd (via upsc or the protocol) I would
> like not to care about those details.
>
> > OTOH, my feeling is that most of this how-long-is-that-data-stale
> > logic belongs into upsd, not into each individual driver. (And
> > deciding whether a certain data being stale for a certain time is a
> > problem belongs into the application: I can live with not knowing when
> > it will be time to replace the battery for much longer than with not
> > knowing whether I'm on battery.)
>
> To me the key point is that when a driver makes a report, that report
> should only include information which is "not stale", with some
> acceptable fuzz for values that are read less frequently.  And then upsd
> should convey "how long since the last (non-stale) report".  I see this
> as pretty straightforward conceptually.
>
> > So, what about the driver, at initialization time, telling upsd, for
> each value, what the expected update interval is (with upsd chosing a
> default for the majority of them) and having upsd deal with the rest?
> > Of course, there should be an additional method for the driver to tell
> upsd that reading a value failed by providing an "undefined" value.
>
> I always lean to the simplest reasonable approach.  Here,
>
>   I would like drivers to be able to report "unavailable" for a value,
>   and drivers should manage timeouts (that they understand because it's
>   device behavior) and report them as unavailable.
>
>   If the driver stops communicating, upsd should set everything to
>   unavailable.  Timeout here could be 5s by spec, and drivers that are
>   up and functioning and have no news can just keepalive to avoid this
>   timeout.   This would matter only for a driver crash.
>
> which is mostly what you said, but not pushing timeouts to upsd.
>
>
> Separately, I would suggest that with a driver reading from a UPS unit,
> things are either
>
>   ok, where all  values can be read routinely
>
>   not ok, where some values that should work give errors
>
> and we should not agonize over shades of grey of not ok, and let drivers
> decide which side of the boundary they are on.  To me the things that
> really matter and the timescales I care about them are
>
>   input voltage - ok or bad: immediate
>   online or on battery: a few seconds
>   battery voltage or remaining runtime: 30s
>
>   output VA: nice to have a few seconds, every minute is acceptable
>
>   battery needs replacement: 1h
>
>
> _______________________________________________
> Nut-upsdev mailing list
> [email protected]
> https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsdev
>
_______________________________________________
Nut-upsdev mailing list
[email protected]
https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsdev

Reply via email to