Re: [PATCH v13 12/32] x86,fs/resctrl: Support binary fixed point event counters

David Laight
2025-11-12T13:08:16Z

On Wed, 29 Oct 2025 09:20:55 -0700
Tony Luck <tony.luck@intel.com> wrote:

> resctrl assumes that all monitor events can be displayed as unsigned
> decimal integers.
>
> Hardware architecture counters may provide some telemetry events with
> greater precision where the event is not a simple count, but is a
> measurement of some sort (e.g. Joules for energy consumed).
>
> Add a new argument to resctrl_enable_mon_event() for architecture code
> to inform the file system that the value for a counter is a fixed-point
> value with a specific number of binary places.
> Only allow architecture to use floating point format on events that the
> file system has marked with mon_evt::is_floating_point.
>
> Display fixed point values with values rounded to an appropriate number
> of decimal places for the precision of the number of binary places
> provided. Add one extra decimal place for every three additional binary
> places, except for low precision binary values where exact representation
> is possible:
>
> 1 binary place is 0.0 or 0.5 => 1 decimal place
> 2 binary places is 0.0, 0.25, 0.5, 0.75 => 2 decimal places
> 3 binary places is 0.0, 0.125, etc. => 3 decimal places
>
> Signed-off-by: Tony Luck <tony.luck@intel.com>
> Reviewed-by: Reinette Chatre <reinette.chatre@intel.com>
> ---
> include/linux/resctrl.h | 3 +-
> fs/resctrl/internal.h | 8 +++
> arch/x86/kernel/cpu/resctrl/core.c | 6 +--
> fs/resctrl/ctrlmondata.c | 84 ++++++++++++++++++++++++++++++
> fs/resctrl/monitor.c | 10 +++-
> 5 files changed, 105 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/resctrl.h b/include/linux/resctrl.h
> index 702205505dc9..a7e5a546152d 100644
> --- a/include/linux/resctrl.h
> +++ b/include/linux/resctrl.h
> @@ -409,7 +409,8 @@ u32 resctrl_arch_get_num_closid(struct rdt_resource *r);
> u32 resctrl_arch_system_num_rmid_idx(void);
> int resctrl_arch_update_domains(struct rdt_resource *r, u32 closid);
>
> -void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu);
> +void resctrl_enable_mon_event(enum resctrl_event_id eventid, bool any_cpu,
> + unsigned int binary_bits);
>
> bool resctrl_is_mon_event_enabled(enum resctrl_event_id eventid);
>
> diff --git a/fs/resctrl/internal.h b/fs/resctrl/internal.h
> index 40b76eaa33d0..f5189b6771a0 100644
> --- a/fs/resctrl/internal.h
> +++ b/fs/resctrl/internal.h
> @@ -62,6 +62,9 @@ static inline struct rdt_fs_context *rdt_fc2context(struct fs_context *fc)
> * Only valid if @evtid is an MBM event.
> * @configurable: true if the event is configurable
> * @any_cpu: true if the event can be read from any CPU
> + * @is_floating_point: event values are displayed in floating point format
> + * @binary_bits: number of fixed-point binary bits from architecture,
> + * only valid if @is_floating_point is true
> * @enabled: true if the event is enabled
> */
> struct mon_evt {
> @@ -71,6 +74,8 @@ struct mon_evt {
> u32 evt_cfg;
> bool configurable;
> bool any_cpu;
> + bool is_floating_point;
> + unsigned int binary_bits;
> bool enabled;
> };

Nit: You've added 4 bytes of padding.

David