From: "Darrick J. Wong" <djwong@kernel.org>
To: djwong@kernel.org, cem@kernel.org
Cc: cmaiolino@redhat.com, linux-xfs@vger.kernel.org, hch@infradead.org
Subject: [PATCH 2/5] xfs_db: improve number extraction in getbitval
Date: Mon, 15 Apr 2024 17:59:05 -0700 [thread overview]
Message-ID: <171322881835.210882.6715743182101731750.stgit@frogsfrogsfrogs> (raw)
In-Reply-To: <171322881805.210882.5445286603045179895.stgit@frogsfrogsfrogs>
From: Darrick J. Wong <djwong@kernel.org>
For some reason, getbitval insists upon collecting a u64 from a pointer
bit by bit if it's not aligned to a 16-byte boundary. If not, then it
resorts to scraping bits individually. I don't know of any platform
where we require 16-byte alignment for a 8-byte access, or why we'd care
now that we have things like get_unaligned_beXX.
Rework this function to detect either naturally aligned accesses and use
the regular beXX_to_cpu functions; or byte-aligned accesses and use the
get_unaligned_beXX functions. Only fall back to the bit scraping
algorithm for the really weird cases.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
db/bit.c | 37 ++++++++++++++++---------------------
1 file changed, 16 insertions(+), 21 deletions(-)
diff --git a/db/bit.c b/db/bit.c
index c9bfd2eb025f..1b9ca054f3b1 100644
--- a/db/bit.c
+++ b/db/bit.c
@@ -55,39 +55,34 @@ getbitval(
char *p;
int64_t rval;
int signext;
- int z1, z2, z3, z4;
ASSERT(nbits<=64);
p = (char *)obj + byteize(bitoff);
bit = bitoffs(bitoff);
signext = (flags & BVSIGNED) != 0;
- z4 = ((intptr_t)p & 0xf) == 0 && bit == 0;
- if (nbits == 64 && z4)
- return be64_to_cpu(*(__be64 *)p);
- z3 = ((intptr_t)p & 0x7) == 0 && bit == 0;
- if (nbits == 32 && z3) {
+
+ if (bit != 0)
+ goto scrape_bits;
+
+ switch (nbits) {
+ case 64:
+ return get_unaligned_be64(p);
+ case 32:
if (signext)
- return (__s32)be32_to_cpu(*(__be32 *)p);
- else
- return (__u32)be32_to_cpu(*(__be32 *)p);
- }
- z2 = ((intptr_t)p & 0x3) == 0 && bit == 0;
- if (nbits == 16 && z2) {
+ return (__s32)get_unaligned_be32(p);
+ return (__u32)get_unaligned_be32(p);
+ case 16:
if (signext)
- return (__s16)be16_to_cpu(*(__be16 *)p);
- else
- return (__u16)be16_to_cpu(*(__be16 *)p);
- }
- z1 = ((intptr_t)p & 0x1) == 0 && bit == 0;
- if (nbits == 8 && z1) {
+ return (__s16)get_unaligned_be16(p);
+ return (__u16)get_unaligned_be16(p);
+ case 8:
if (signext)
return *(__s8 *)p;
- else
- return *(__u8 *)p;
+ return *(__u8 *)p;
}
-
+scrape_bits:
for (i = 0, rval = 0LL; i < nbits; i++) {
if (getbit_l(p, bit + i)) {
/* If the last bit is on and we care about sign
next prev parent reply other threads:[~2024-04-16 0:59 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-16 0:51 [PATCHBOMB v3] xfsprogs: everything headed towards 6.9 Darrick J. Wong
2024-04-16 0:57 ` [PATCHSET 1/4] xfsprogs: bug fixes for 6.8 Darrick J. Wong
2024-04-16 0:58 ` [PATCH 1/5] xfs_repair: double-check with shortform attr verifiers Darrick J. Wong
2024-04-16 0:59 ` Darrick J. Wong [this message]
2024-04-16 4:53 ` [PATCH 2/5] xfs_db: improve number extraction in getbitval Christoph Hellwig
2024-04-16 0:59 ` [PATCH 3/5] xfs_scrub: fix threadcount estimates for phase 6 Darrick J. Wong
2024-04-16 4:53 ` Christoph Hellwig
2024-04-16 0:59 ` [PATCH 4/5] xfs_scrub: don't fail while reporting media scan errors Darrick J. Wong
2024-04-16 0:59 ` [PATCH 5/5] xfs_io: add linux madvise advice codes Darrick J. Wong
2024-04-17 7:34 ` [PATCHSET 1/4] xfsprogs: bug fixes for 6.8 Carlos Maiolino
2024-04-17 15:30 ` Darrick J. Wong
2024-04-16 0:58 ` [PATCHSET 2/4] libxfs: sync with 6.9 Darrick J. Wong
2024-04-16 1:00 ` [PATCH 088/111] libxfs: teach buftargs to maintain their own buffer hashtable Darrick J. Wong
2024-04-16 1:00 ` [PATCH 089/111] libxfs: add xfile support Darrick J. Wong
2024-04-16 1:00 ` [PATCH 090/111] libxfs: partition memfd files to avoid using too many fds Darrick J. Wong
2024-04-16 4:55 ` Christoph Hellwig
2024-04-16 15:49 ` Darrick J. Wong
2024-04-16 16:29 ` Christoph Hellwig
2024-04-16 16:57 ` Darrick J. Wong
2024-04-16 18:47 ` Christoph Hellwig
2024-04-16 18:55 ` Darrick J. Wong
2024-04-24 17:20 ` [PATCH v3.1 " Darrick J. Wong
2024-04-16 1:00 ` [PATCH 091/111] xfs: teach buftargs to maintain their own buffer hashtable Darrick J. Wong
2024-04-16 1:01 ` [PATCH 092/111] libxfs: support in-memory buffer cache targets Darrick J. Wong
2024-04-16 0:58 ` [PATCHSET v30.3 3/4] xfsprogs: bmap log intent cleanups Darrick J. Wong
2024-04-16 1:01 ` [PATCH 1/4] libxfs: remove kmem_alloc, kmem_zalloc, and kmem_free Darrick J. Wong
2024-04-16 4:55 ` Christoph Hellwig
2024-04-16 1:01 ` [PATCH 2/4] libxfs: add a bi_entry helper Darrick J. Wong
2024-04-16 4:55 ` Christoph Hellwig
2024-04-16 1:01 ` [PATCH 3/4] libxfs: reuse xfs_bmap_update_cancel_item Darrick J. Wong
2024-04-16 4:55 ` Christoph Hellwig
2024-04-16 1:02 ` [PATCH 4/4] libxfs: add a xattr_entry helper Darrick J. Wong
2024-04-16 4:56 ` Christoph Hellwig
2024-04-16 0:58 ` [PATCHSET v30.3 4/4] xfs_repair: minor fixes Darrick J. Wong
2024-04-16 1:02 ` [PATCH 1/1] xfs_repair: check num before bplist[num] Darrick J. Wong
2024-04-16 4:56 ` Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2024-04-17 21:16 [PATCHSET 06/11] xfsprogs: bug fixes for 6.8 Darrick J. Wong
2024-04-17 21:40 ` [PATCH 2/5] xfs_db: improve number extraction in getbitval Darrick J. Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=171322881835.210882.6715743182101731750.stgit@frogsfrogsfrogs \
--to=djwong@kernel.org \
--cc=cem@kernel.org \
--cc=cmaiolino@redhat.com \
--cc=hch@infradead.org \
--cc=linux-xfs@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).