mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: George Spelvin <lkml@sdf.org>
To: andy.shevchenko@gmail.com, kbusch@kernel.org, lkml@sdf.org
Cc: akpm@linux-foundation.org, andriy.shevchenko@linux.intel.com,
	keescook@chromium.org, linux-kernel@vger.kernel.org,
	linux@rasmusvillemoes.dk, mchehab+samsung@kernel.org,
	samitolvanen@google.com, st5pub@yandex.ru
Subject: Re: [PATCH] lib/list_sort: fix function type mismatches
Date: Sat, 11 Jan 2020 23:22:51 GMT	[thread overview]
Message-ID: <202001112322.00BNMp7Q002616@sdf.org> (raw)
In-Reply-To: <202001111144.00BBiXEq002960@sdf.org>

(Resend with corrected e-mail address and more thoughts.)

On Sat, 11 Jan 2020 at 12:35, Andy Shevchenko <andy.shevchenko@gmail.com> wrote:
> Hint: When you post Message-Id you may prefix them with
> https://lore.kernel.org/r/ which makes search a bit more convenient
> and faster.

I just learned that https://marc.info/?i= also works, so
https://lore.kernel.org/r/20191007135656.37734-1-andriy.shevchenko@linux.intel.com
https://marc.info/?i=20191007135656.37734-1-andriy.shevchenko@linux.intel.com

https://lore.kernel.org/r/20190416154522.65aaa348161fc581181b56d9@linux-foundation.org
https://marc.info/?i=20190416154522.65aaa348161fc581181b56d9@linux-foundation.org

> For the record, I have just checked users of list_sort() in regard to
> constify of priv parameter and only ACPI HMAT is using it as not
> const. UBIFS and XFS do not change the data (if I didn't miss
> anything).

Yes, that initiator_cmp() at drivers/acpi/hmat/hmat.c:526 is... interesting.

Basically, it wants to fill in a bitmap of all of the processor_pxm
identifiers, so it avoids having a separate list traversal by
setting bits in the compare function (which is guaranteed to visit
each list element at least once).

It ends up setting each bit 2*log2(n) times (since there are an
average of log2(n) compares per element and each compare sets two
bits), but it makes the code smaller.  And although it make the
aggressive performance optimizer in me cringe, I have to agree this
is not performance-critical code and so it's a reasonable thing to do.

I do note, however, that the list_sort is almost immediately followed
by a list_for_each_entry() loop and maybe the bitmap computation
could be folded in there.  Basically start the loop with:

	unsigned int pxm = -1u;	/* Invalid sentinel value */
	list_for_each_entry(initiator, &initiators, node) {
		u32 value;

		if (initiator->processor_pxm != pxm) {
			pxm = initiator->processor_pxm;
			set_bit(pxm, p_nodes);
		} else if (!test_bit(pxm, p_nodes)) {
			continue;
		}

... but oh, whoops, that won't work.  The "almost immediately"
glosses over a second loop, so there are multiple passes over the
initiators list, while we want the bitmap set up only once.

What we should probably do is just cast away the const in the cmp
function.  That's a strange thing to do, which is appropriate because
the code is doing something strange.

It might be too subtle, but given the semantics guaranteed by list_sort,
it would suffice to set only the bit corresponding to the *second*
argument to cmp(), plus the bit corresponding to the first element
of the input (not yet sorted) list.

Cc: to Keith Busch <kbusch@kernel.org>, who wrote that code.
Keith, is there a better way we could avoid the non-const priv
parameter, just for the sake of code cleanliness in <list_sort.h>?

      reply	other threads:[~2020-01-11 23:22 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-10 22:56 Sami Tolvanen
2020-01-11  8:30 ` George Spelvin
2020-01-11 10:35   ` Andy Shevchenko
2020-01-11 10:55     ` Andy Shevchenko
2020-01-11 11:44     ` George Spelvin
2020-01-11 23:22       ` George Spelvin [this message]

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=202001112322.00BNMp7Q002616@sdf.org \
    --to=lkml@sdf.org \
    --cc=akpm@linux-foundation.org \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=kbusch@kernel.org \
    --cc=keescook@chromium.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=mchehab+samsung@kernel.org \
    --cc=samitolvanen@google.com \
    --cc=st5pub@yandex.ru \
    /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

all inboxes | Powered by JetHome®