[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <79a0eea8-e08f-46c7-bfc2-135bcd90dd87@intel.com>
Date: Tue, 22 Apr 2025 11:20:08 -0700
From: Reinette Chatre <reinette.chatre@...el.com>
To: "Luck, Tony" <tony.luck@...el.com>
CC: Fenghua Yu <fenghuay@...dia.com>, Maciej Wieczor-Retman
<maciej.wieczor-retman@...el.com>, Peter Newman <peternewman@...gle.com>,
James Morse <james.morse@....com>, Babu Moger <babu.moger@....com>, "Drew
Fustini" <dfustini@...libre.com>, Dave Martin <Dave.Martin@....com>, "Anil
Keshavamurthy" <anil.s.keshavamurthy@...el.com>,
<linux-kernel@...r.kernel.org>, <patches@...ts.linux.dev>
Subject: Re: [PATCH v3 11/26] fs/resctrl: Add support for additional monitor
event display formats
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
Powered by blists - more mailing lists