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

Dave Martin
2025-11-11T17:34:54Z

Hi Tony,

On Mon, Nov 10, 2025 at 08:52:52AM -0800, Luck, Tony wrote:
> On Wed, Nov 05, 2025 at 02:42:18PM +0000, Dave Martin wrote:
> > > +static void print_event_value(struct seq_file *m, unsigned int binary_bits, u64 val)
> > > +{
> > > + unsigned long long frac;
> > > + char buf[10];
> >
> > In place of the magic number 10, how about
> > decplaces[MAX_BINARY_BITS] + 1 ?
> >
> > (I think the compiler should accept that as an initialiser if the array
> > is const.)
>
> The compiler (gcc 15.2.1) accepts without any warnings. But generates
> different code.
>
> sparse complains:
> fs/resctrl/ctrlmondata.c:640:45: warning: Variable length array is used.

Hmmm. Shame.

(Of course, this is only a warning. sparse may not know how to
determine that the resulting buffer is limited to a sane size, but
looking at the code makes it pretty obvious. Perhaps best avoided,
though.)

> I may change the hard coded constant to 21 (guaranteed to be big enough
> for a "long long" plus terminating NUL byte.)

I guess. We may be able to sidestep this, though (see my other reply
about getting rid of buf[] altogether.)

Cheers
---Dave