From: DJ Delorie <dj@redhat.com>
To: "Carlos O'Donell" <carlos@redhat.com>
Cc: libc-alpha@sourceware.org
Subject: Re: [PATCH 2/4] <nss_action.h>: New abstraction for combining NSS modules and NSS actions
Date: Wed, 01 Jul 2020 17:27:16 -0400 [thread overview]
Message-ID: <xnmu4jsz7v.fsf@greed.delorie.com> (raw)
In-Reply-To: <3133c91b-52bf-e45d-cd39-72e923cea450@redhat.com> (carlos@redhat.com)
"Carlos O'Donell" <carlos@redhat.com> writes:
>> + /* The next element of the list.x */
>
> s/.x/./g
Done.
> Suggest:
>
> /* Lock covers the nss_actions list. */
Changed.
>> +/* Returns true if the actions are equal (same module, same actions
>> + aray). */
>
> s/aray/array/g
Changed.
>> +
>> +/* Returns true if the COUNT actions at A and B are equal (according
>> + to actions_equal above). */
>
> Suggest:
>
> /* Returns true if COUNT actions at A and B are equal (according
> to actions_equal above). Caller must ensure that A and B have
> at least COUNT actions. */
Went with:
/* Returns true if COUNT actions at A and B are equal (according to
actions_equal above). Caller must ensure that either A or B have at
least COUNT actions. */
Like strcmp, a NULL entry will end the search early but safely (as a
mismatch). The only case that causes problems is if both A and B are
equal, but both shorter than COUNT - then we iterate past the NULL
terminator record.
>> +/* Index in actions. */
>
> Suggest:
>
> /* Value to add to first nss_status value to get zero. */
> #define NSS_STATUS_BIAS 2
> /* Number of bits per lookup action. */
> #define NSS_BPL 2
> #define NSS_BPL_MASK ((1 << NSS_BPL) - 1)
>
> /* Index in actions of an NSS status.
> Note that in nss/nss.h the status starts at -2, and
> we shift that up to zero by adding 2. Thus for example
> NSS_STATUS_TRYAGAIN, which is -2, would index into the
> 0th bit place as expected. */
Changed.
>> +static inline int
>> +nss_actions_bits_index (enum nss_status status)
>> +{
>> + return 2 * (2 + status);
>
> Suggest:
>
> return NSS_BPL * (NSS_STATUS_BIAS + status);
Changed.
>> +nss_action_get (const struct nss_action *action, enum nss_status status)
>> +{
>> + return (action->action_bits >> nss_actions_bits_index (status)) & 3;
>
> Suggest:
>
> return (action->action_bits >> nss_actions_bits_index (status)) & NSS_BPL_MASK;
Changed.
>> + int offset = nss_actions_bits_index (status);
>> + unsigned int mask = 3 << offset;
>
> Use NSS_BPL_MASK and then "mask" makes sense.
Changed.
>> + unsigned int bits = actions;
>> + /* Produces 0b00 .. 00 AA AA AA AA AA. */
>> + action->action_bits = bits * 0x155;
>
> This needs to be rewritten to be expressed as a function of all the
> nss_status entries. That is to say you need to call nss_action_set
> for all status and actions. I dislike the above magic. It should be
> immediately readable and understandable that we set all the entries.
I went with this:
unsigned int bits = actions & NSS_BPL_MASK;
action->action_bits = ( bits
| (bits << (NSS_BPL * 1))
| (bits << (NSS_BPL * 2))
| (bits << (NSS_BPL * 3))
| (bits << (NSS_BPL * 4))
);
Sadly, GCC does not optimize this to a single multiplication, but at
least it's only called when parsing a new /etc/nsswitch.conf so
performance here isn't critical.
next prev parent reply other threads:[~2020-07-01 21:27 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-25 4:05 DJ Delorie
2020-07-01 19:08 ` Carlos O'Donell
2020-07-01 21:27 ` DJ Delorie [this message]
2020-07-03 12:57 ` Carlos O'Donell
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=xnmu4jsz7v.fsf@greed.delorie.com \
--to=dj@redhat.com \
--cc=carlos@redhat.com \
--cc=libc-alpha@sourceware.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).