From: Peter Zijlstra <peterz@infradead.org>
To: Frederic Weisbecker <frederic@kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>, Ingo Molnar <mingo@kernel.org>
Subject: Re: [PATCH 4/4] locking/lockdep: Test all incompatible scenario at once in check_irq_usage()
Date: Tue, 9 Apr 2019 15:03:52 +0200 [thread overview]
Message-ID: <20190409130352.GV4038@hirez.programming.kicks-ass.net> (raw)
In-Reply-To: <20190402160244.32434-5-frederic@kernel.org>
On Tue, Apr 02, 2019 at 06:02:44PM +0200, Frederic Weisbecker wrote:
> @@ -1988,45 +1961,151 @@ static int exclusive_bit(int new_bit)
> return state | (dir ^ LOCK_USAGE_DIR_MASK);
> }
>
> +static unsigned long exclusive_dir_mask(unsigned long mask)
Would you mind terribly if I call that: invert_dir_mask() ?
> +{
> + unsigned long excl;
> +
> + /* Invert dir */
> + excl = (mask & LOCKF_ENABLED_IRQ_ALL) >> LOCK_USAGE_DIR_MASK;
> + excl |= (mask & LOCKF_USED_IN_IRQ_ALL) << LOCK_USAGE_DIR_MASK;
> +
> + return excl;
> +}
> +
> +static unsigned long exclusive_mask(unsigned long mask)
> +{
> + unsigned long excl = exclusive_dir_mask(mask);
> +
> + /* Strip read */
> + excl |= (excl & LOCKF_IRQ_READ) >> LOCK_USAGE_READ_MASK;
> + excl &= ~LOCKF_IRQ_READ;
> +
> + return excl;
> +}
And I might write a comment to go with those functions; they're too
clever by half. I'm sure I'll have forgotten how they work in a few
months time.
Very well done :-)
> +/*
> + * Find the first pair of bit match between an original
> + * usage mask and an exclusive usage mask.
> + */
> +static int find_exclusive_match(unsigned long mask,
> + unsigned long excl_mask,
> + enum lock_usage_bit *bit,
> + enum lock_usage_bit *excl_bit)
> +{
> + int fs, nr = 0;
> +
> + while ((fs = ffs(mask))) {
> + int excl;
> +
> + nr += fs;
> + excl = exclusive_bit(nr - 1);
> + if (excl_mask & lock_flag(excl)) {
> + *bit = nr - 1;
> + *excl_bit = excl;
> + return 0;
> + }
> + mask >>= fs - 1;
> + /*
> + * Prevent from shifts of sizeof(long) which can
> + * give unpredictable results.
> + */
> + mask >>= 1;
> + }
> + return -1;
Should we write that like:
for_each_set_bit(bit, &mask, LOCK_USED) {
int excl = exclusive_bit(bit);
if (excl_mask & lock_flag(excl)) {
*bitp = bit;
*excl_bitp = excl;
return 0;
}
}
return -1;
Or something along those lines?
> +}
> +
next prev parent reply other threads:[~2019-04-09 13:03 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-02 16:02 [PATCH 0/4] lockdep cleanups and optimizations Frederic Weisbecker
2019-04-02 16:02 ` [PATCH 1/4] locking/lockdep: Move valid_state() inside CONFIG_TRACE_IRQFLAGS && CONFIG_PROVE_LOCKING Frederic Weisbecker
2019-04-18 11:26 ` [tip:locking/core] " tip-bot for Frederic Weisbecker
2019-04-02 16:02 ` [PATCH 2/4] locking/lockdep: Map remaining magic numbers to lock usage mask names Frederic Weisbecker
2019-04-18 11:26 ` [tip:locking/core] " tip-bot for Frederic Weisbecker
2019-04-02 16:02 ` [PATCH 3/4] locking/lockdep: Use expanded masks on find_usage_*() functions Frederic Weisbecker
2019-04-18 11:27 ` [tip:locking/core] " tip-bot for Frederic Weisbecker
2019-04-02 16:02 ` [PATCH 4/4] locking/lockdep: Test all incompatible scenario at once in check_irq_usage() Frederic Weisbecker
2019-04-09 13:03 ` Peter Zijlstra [this message]
2019-04-10 2:28 ` Frederic Weisbecker
2019-04-11 10:46 ` Peter Zijlstra
2019-04-13 0:35 ` Frederic Weisbecker
2019-04-16 11:20 ` Peter Zijlstra
2019-04-16 15:21 ` Frederic Weisbecker
2019-04-13 6:38 ` Yuyang Du
2019-04-29 6:39 ` [tip:locking/core] locking/lockdep: Test all incompatible scenarios " tip-bot for Frederic Weisbecker
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=20190409130352.GV4038@hirez.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=frederic@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@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 NNTP newsgroup(s).