All of lore.kernel.org
 help / color / mirror / Atom feed
From: Davidlohr Bueso <dave@stgolabs.net>
To: Dan Williams <dan.j.williams@intel.com>
Cc: vishal.l.verma@intel.com, alison.schofield@intel.com,
	nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org,
	a.manzanares@samsung.com
Subject: Re: [PATCH 5/11] cxl/lib: Maintain decoders in id order
Date: Wed, 13 Jul 2022 12:45:02 -0700	[thread overview]
Message-ID: <20220713194502.5hxf5jxpwzvsukx7@offworld> (raw)
In-Reply-To: <165765287277.435671.14320322485572083484.stgit@dwillia2-xfh>

On Tue, 12 Jul 2022, Dan Williams wrote:

>Given that decoder instance order is fundamental to the DPA translation
>sequence for endpoint decoders, enforce that cxl_decoder_for_each() returns
>decoders in instance order. Otherwise, they show up in readddir() order
>which is not predictable.
>
>Add a list_add_sorted() to generically handle inserting into a sorted list.

With the already available list_add_before ccan code nit already pointed out
by Ira.

Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>

>
>Signed-off-by: Dan Williams <dan.j.williams@intel.com>
>---
> cxl/lib/libcxl.c |    8 ++++++-
> util/list.h      |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 68 insertions(+), 1 deletion(-)
>
>diff --git a/cxl/lib/libcxl.c b/cxl/lib/libcxl.c
>index f36edcfc735a..e4c5d3819e88 100644
>--- a/cxl/lib/libcxl.c
>+++ b/cxl/lib/libcxl.c
>@@ -19,6 +19,7 @@
> #include <ccan/short_types/short_types.h>
>
> #include <util/log.h>
>+#include <util/list.h>
> #include <util/size.h>
> #include <util/sysfs.h>
> #include <util/bitmap.h>
>@@ -908,6 +909,11 @@ cxl_endpoint_get_memdev(struct cxl_endpoint *endpoint)
> 	return NULL;
> }
>
>+static int decoder_id_cmp(struct cxl_decoder *d1, struct cxl_decoder *d2)
>+{
>+	return d1->id - d2->id;
>+}
>+
> static void *add_cxl_decoder(void *parent, int id, const char *cxldecoder_base)
> {
> 	const char *devname = devpath_to_devname(cxldecoder_base);
>@@ -1049,7 +1055,7 @@ static void *add_cxl_decoder(void *parent, int id, const char *cxldecoder_base)
> 			return decoder_dup;
> 		}
>
>-	list_add(&port->decoders, &decoder->list);
>+	list_add_sorted(&port->decoders, decoder, list, decoder_id_cmp);
>
> 	free(path);
> 	return decoder;
>diff --git a/util/list.h b/util/list.h
>index 1ea9c59b9f0c..c6584e3ec725 100644
>--- a/util/list.h
>+++ b/util/list.h
>@@ -37,4 +37,65 @@ static inline void list_add_after_(struct list_head *h,
> 	(void)list_debug(h, abortstr);
> }
>
>+/**
>+ * list_add_before - add an entry before the given node in the linked list.
>+ * @h: the list_head to add the node to
>+ * @l: the list_node before which to add to
>+ * @n: the list_node to add to the list.
>+ *
>+ * The list_node does not need to be initialized; it will be overwritten.
>+ * Example:
>+ *	struct child *child = malloc(sizeof(*child));
>+ *
>+ *	child->name = "geoffrey";
>+ *	list_add_before(&parent->children, &child1->list, &child->list);
>+ *	parent->num_children++;
>+ */
>+#define list_add_before(h, l, n) list_add_before_(h, l, n, LIST_LOC)
>+static inline void list_add_before_(struct list_head *h, struct list_node *l,
>+				    struct list_node *n, const char *abortstr)
>+{
>+	if (l->prev == &h->n) {
>+		/* l is the first element, this becomes a list_add */
>+		list_add(h, n);
>+		return;
>+	}
>+
>+	n->next = l;
>+	n->prev = l->prev;
>+	l->prev->next = n;
>+	l->prev = n;
>+}
>+
>+#define list_add_sorted(head, n, node, cmp)                                    \
>+	do {                                                                   \
>+		struct list_head *__head = (head);                             \
>+		typeof(n) __iter, __next;                                      \
>+		typeof(n) __new = (n);                                         \
>+                                                                               \
>+		if (list_empty(__head)) {                                      \
>+			list_add(__head, &__new->node);                        \
>+			break;                                                 \
>+		}                                                              \
>+                                                                               \
>+		list_for_each (__head, __iter, node) {                         \
>+			if (cmp(__new, __iter) < 0) {                          \
>+				list_add_before(__head, &__iter->node,         \
>+						&__new->node);                 \
>+				break;                                         \
>+			}                                                      \
>+			__next = list_next(__head, __iter, node);              \
>+			if (!__next) {                                         \
>+				list_add_after(__head, &__iter->node,          \
>+					       &__new->node);                  \
>+				break;                                         \
>+			}                                                      \
>+			if (cmp(__new, __next) < 0) {                          \
>+				list_add_before(__head, &__next->node,         \
>+						&__new->node);                 \
>+				break;                                         \
>+			}                                                      \
>+		}                                                              \
>+	} while (0)
>+
> #endif /* _NDCTL_LIST_H_ */
>

  parent reply	other threads:[~2022-07-13 23:11 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-12 19:07 [ndctl PATCH 00/11] cxl: Region provisioning foundation Dan Williams
2022-07-12 19:07 ` [ndctl PATCH 01/11] cxl/list: Reformat option list Dan Williams
2022-07-13 19:04   ` [PATCH 1/11] " Davidlohr Bueso
2022-07-12 19:07 ` [ndctl PATCH 02/11] cxl/list: Emit endpoint decoders filtered by memdev Dan Williams
2022-07-12 19:07 ` [ndctl PATCH 03/11] cxl/list: Hide 0s in disabled decoder listings Dan Williams
2022-07-13 19:16   ` [PATCH 3/11] " Davidlohr Bueso
2022-07-12 19:07 ` [ndctl PATCH 04/11] cxl/list: Add DPA span to endpoint " Dan Williams
2022-07-12 19:07 ` [ndctl PATCH 05/11] cxl/lib: Maintain decoders in id order Dan Williams
2022-07-13 14:44   ` Ira Weiny
2022-07-13 16:23     ` Dan Williams
2022-07-13 19:45   ` Davidlohr Bueso [this message]
2022-07-13 23:14     ` [PATCH 5/11] " Dan Williams
2022-07-12 19:07 ` [ndctl PATCH 06/11] cxl/memdev: Fix json for multi-device partitioning Dan Williams
2022-07-12 19:08 ` [ndctl PATCH 07/11] cxl/list: Emit 'mode' for endpoint decoder objects Dan Williams
2022-07-12 19:08 ` [ndctl PATCH 08/11] cxl/set-partition: Accept 'ram' as an alias for 'volatile' Dan Williams
2022-07-13 19:06   ` [PATCH 8/11] " Davidlohr Bueso
2022-07-12 19:08 ` [ndctl PATCH 09/11] cxl/memdev: Add {reserve,free}-dpa commands Dan Williams
2022-07-13  8:04   ` Verma, Vishal L
2022-07-13 15:22     ` Dan Williams
2022-07-13 15:44       ` Verma, Vishal L
2022-07-13 16:55         ` Dan Williams
2022-07-12 19:08 ` [ndctl PATCH 10/11] cxl/test: Update CXL memory parameters Dan Williams
2022-07-12 19:08 ` [ndctl PATCH 11/11] cxl/test: Checkout region setup/teardown Dan Williams
2022-07-13  7:47   ` Verma, Vishal L
2022-07-13 14:47     ` Dan Williams
2022-07-13 15:15       ` Verma, Vishal L
2022-07-13 16:53         ` Dan Williams

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=20220713194502.5hxf5jxpwzvsukx7@offworld \
    --to=dave@stgolabs.net \
    --cc=a.manzanares@samsung.com \
    --cc=alison.schofield@intel.com \
    --cc=dan.j.williams@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    --cc=vishal.l.verma@intel.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.