Thread (28 messages) 28 messages, 4 authors, 2021-06-09

Re: [PATCH v2 8/8] perf record: Directly bail out for compat case

From: Leo Yan <hidden>
Date: 2021-06-02 12:40:13
Also in: linux-arm-kernel, lkml

Hi Adrain,

On Wed, Jun 02, 2021 at 02:18:47PM +0300, Adrian Hunter wrote:
On 2/06/21 1:30 pm, Leo Yan wrote:
quoted
Since the 64-bit atomicity is not promised in 32-bit perf, directly
report the error and bail out for this case.

Now only applies on x86_64 and Arm64 platforms.

Suggested-by: Adrian Hunter <adrian.hunter@intel.com>
Maybe we can do better for the compat case.

We can assume the upper 32-bits change very seldom,
and always increase. So for the 'read' case:

	u64 first, second, last;
	u64 mask = (u64)((u32)-1) << 32;

	do {
		first = READ_ONCE(pc->aux_head);
		rmb();
		second = READ_ONCE(pc->aux_head);
		rmb();
		last = READ_ONCE(pc->aux_head);
	} while ((first & mask) != (last & mask));
	return second;

For the write case, we can cause a fatal error only if the new
tail has non-zero upper 32-bits.  That gives up to 4GiB of data
before aborting:

	if (tail & mask)
		return -1;
	smp_mb();
	WRITE_ONCE(pc->aux_tail, tail);
Seems to me, it's pointless to only support aux_head for 64-bit and
support aux_tail for 32-bit.  I understand this can be helpful for the
snapshot mode which only uses aux_head, but it still fails to support
the normal case for AUX ring buffer using 64-bit head/tail.

Thanks,
Leo
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help