lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aAadxhaapT_3-W-I@agluck-desk3>
Date: Mon, 21 Apr 2025 12:34:30 -0700
From: "Luck, Tony" <tony.luck@...el.com>
To: Reinette Chatre <reinette.chatre@...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

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.

-Tony

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ