Re: [PATCH v3 11/26] fs/resctrl: Add support for additional monitor event display formats

Reinette Chatre
2025-04-22T18:20:16Z

Hi Tony,

On 4/21/25 12:34 PM, Luck, Tony wrote:
> On Fri, Apr 18, 2025 at 04:02:08PM -0700, Reinette Chatre wrote:
>>> + case EVT_TYPE_U46_18:
>>> + frac = val & FRAC_MASK;
>>> + frac = frac * 1000000;
>>> + frac += 1ul << (NUM_FRAC_BITS - 1);
>>
>> Could you please help me understand why above line is needed? Seems like
>> shift below will just undo it?
>>
>>> + frac >>= NUM_FRAC_BITS;
>>> + seq_printf(m, "%llu.%06llu\n", val >> NUM_FRAC_BITS, frac);
>>> + break;
>>> + }
>
> The extra addtion is to round the value to nearest decimal supported
> value.
>
> E.g. take the case where val == 1 This is a 1 in the 18th binary
> place, so the precise decimal representation is:
>
> 1 / 2^18 = 0.000003814697265625
>
> rounding to six decimal places should give: 0.000004
>
> If you run the above code without the small addition you get:
>
> frac = val & FRAC_MASK; // frac == 1
> frac = frac * 1000000; // frac == 1000000
> frac >>= NUM_FRAC_BITS; // frac == 3
>
> So the output with be the truncated, not rounded, 0.000003
>
> The addition will have a "carry bit" in to the upper bits.
> That isn't lost when shifting right. The value added is
> as if there was a "1" in the 19th binary place.
>
Thank you very much.

Reinette