Page MenuHomeFreeBSD

arm64 pmap: Simplify logic around pv_chunk sizes.
ClosedPublic

Authored by jhb on Aug 16 2022, 5:15 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Nov 2, 12:20 AM
Unknown Object (File)
Thu, Oct 24, 2:51 AM
Unknown Object (File)
Sun, Oct 20, 10:22 AM
Unknown Object (File)
Oct 3 2024, 7:11 PM
Unknown Object (File)
Oct 2 2024, 7:48 PM
Unknown Object (File)
Sep 20 2024, 8:37 PM
Unknown Object (File)
Sep 17 2024, 4:02 AM
Unknown Object (File)
Sep 7 2024, 6:35 PM
Subscribers

Details

Summary
  • Define PC_FREEL and _NPCM in terms of _NPCPV rather than via magic numbers.
  • Remove assertions about _NPC* values from pmap.c. This is less relevant now that PC_FREEL and _NPCM are derived from _NPCPV.
  • Add a helper inline function pc_is_full() which uses a loop to check if pc_map is all zeroes. Use this to replace three places that check for a full mask assuming there are only 3 entries in pc_map.

Sponsored by: DARPA

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

jhb requested review of this revision.Aug 16 2022, 5:15 PM
sys/arm64/arm64/pmap.c
2463

I think this also makes it a bit more obvious how the value is derived compared to the previous versions. Possibly we could even define _NPCM as howmany(_NPCPV, 64) which would be in a similar vein.

In CheriBSD purecap kernels have different values for _NPCPV so we end up with 4 values here otherwise.

2487

This unrolls to a series of cbnz

markj added inline comments.
sys/arm64/arm64/pmap.c
2786

Hmm, I think this test could be implemented more efficiently:

if (field == _NPCM - 1 && pc->pc_map[_NPCM - 1] == 0)

That is, take advantage of the fact that we've already scanned the bitmap looking for a set bit.

This diff seems fine as-is though, I can write a follow-up patch.

2974

I think a similar optimization can be applied here.

This revision is now accepted and ready to land.Aug 16 2022, 6:10 PM
sys/arm64/arm64/pmap.c
2463

+1 for defining _NPCM in terms of _NPCPV.

sys/arm64/arm64/pmap.c
2974

Oops, no, not in this case.

sys/arm64/arm64/pmap.c
2786

I agree that's a useful optimization and that it should be a separate followup.

This revision now requires review to proceed.Aug 17 2022, 12:41 AM
jhb marked an inline comment as done.Aug 17 2022, 12:45 AM
jhb added inline comments.
sys/arm64/arm64/pmap.c
2473

After my other followup commit to reimplement PC_IS_FREE, the definition of pc_freemask is the only place that needs #if's now. It's a bit messier in CheriBSD and it might be nice to just initialize it during pmap_bootstrap() or the like with a simple loop.

Here's what it is in CheriBSD:

static const uint64_t pc_freemask[] = { PC_FREEN,
#if _NPCM > 2
    PC_FREEN,
#endif
#if _NPCM > 3
    PC_FREEN, PC_FREEN, PC_FREEN,
#endif
#if _NPCM > 6
    PC_FREEN, PC_FREEN, PC_FREEN, PC_FREEN, PC_FREEN,
#endif
    PC_FREEL
};
This revision is now accepted and ready to land.Aug 17 2022, 1:34 PM