Skip to contentSkip to conversation

i915: Move list_count() to list.h for broader use

PATCH Superseded Andy Shevchenko 3 participants 8 messages Nov 23, 2022

Subsystems (5)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/4 i915: Move list_count() to list.h for broader use

Some of the existing users, and definitely will be new ones, want to count existing nodes in the list. Provide a generic API for that by moving code from i915 to list.h.

---
v4: fixed prototype when converting to static inline
v3: added tag (Jani), changed to be static inline (Mike)
v2: dropped the duplicate code in i915 (LKP)

 drivers/gpu/drm/i915/gt/intel_engine_cs.c | 13 +------------
 include/linux/list.h                      | 15 +++++++++++++++
 2 files changed, 16 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine_cs.c +1 -12
index c33e0d72d670..b96c8217743c 100644
@@ -2094,17 +2094,6 @@ static void print_request_ring(struct drm_printer *m, struct i915_request *rq)
 	}
 }
 
-static unsigned long list_count(struct list_head *list)
-{
-	struct list_head *pos;
-	unsigned long count = 0;
-
-	list_for_each(pos, list)
-		count++;
-
-	return count;
-}
-
 static unsigned long read_ul(void *p, size_t x)
 {
 	return *(unsigned long *)(p + x);
@@ -2279,7 +2268,7 @@ void intel_engine_dump(struct intel_engine_cs *engine,
 	spin_lock_irqsave(&engine->sched_engine->lock, flags);
 	engine_dump_active_requests(engine, m);
 
-	drm_printf(m, "\tOn hold?: %lu\n",
+	drm_printf(m, "\tOn hold?: %zu\n",
 		   list_count(&engine->sched_engine->hold));
 	spin_unlock_irqrestore(&engine->sched_engine->lock, flags);
 
include/linux/list.h +15 -0
index 61762054b4be..632a298c7018 100644
@@ -655,6 +655,21 @@ static inline void list_splice_tail_init(struct list_head *list,
 	     !list_is_head(pos, (head)); \
 	     pos = n, n = pos->prev)
 
+/**
+ * list_count - count nodes in the list
+ * @head:	the head for your list.
+ */
+static inline size_t list_count(struct list_head *head)
+{
+	struct list_head *pos;
+	size_t count = 0;
+
+	list_for_each(pos, head)
+		count++;
+
+	return count;
+}
+
 /**
  * list_entry_is_head - test if the entry points to the head of the list
  * @pos:	the type * to cursor
Signature · 1 line
2.35.1
#1 lore raw

PATCH v4 2/4 usb: gadget: hid: Convert to use list_count()

The list API now provides the list_count() to help with counting existing nodes in the list. Utilise it.

---
v4: no change
v3: fixed typo in the commit message (Fabio)
v2: no change

 drivers/usb/gadget/legacy/hid.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/usb/gadget/legacy/hid.c +2 -5
index 1187ee4f316a..6196c3456e0b 100644
@@ -133,14 +133,11 @@ static struct usb_configuration config_driver = {
 static int hid_bind(struct usb_composite_dev *cdev)
 {
 	struct usb_gadget *gadget = cdev->gadget;
-	struct list_head *tmp;
 	struct hidg_func_node *n = NULL, *m, *iter_n;
 	struct f_hid_opts *hid_opts;
-	int status, funcs = 0;
-
-	list_for_each(tmp, &hidg_func_list)
-		funcs++;
+	int status, funcs;
 
+	funcs = list_count(&hidg_func_list);
 	if (!funcs)
 		return -ENODEV;
 
Signature · 1 line
2.35.1
#2 lore raw

PATCH v4 3/4 usb: gadget: udc: bcm63xx: Convert to use list_count()

In reply to Andy Shevchenko

The list API now provides the list_count() to help with counting existing nodes in the list. Utilise it.

---
v4: no change
v3: no change
v2: no change

 drivers/usb/gadget/udc/bcm63xx_udc.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/usb/gadget/udc/bcm63xx_udc.c +3 -8
index 2cdb07905bde..0762e49e85f8 100644
@@ -2172,7 +2172,6 @@ static int bcm63xx_iudma_dbg_show(struct seq_file *s, void *p)
 
 	for (ch_idx = 0; ch_idx < BCM63XX_NUM_IUDMA; ch_idx++) {
 		struct iudma_ch *iudma = &udc->iudma[ch_idx];
-		struct list_head *pos;
 
 		seq_printf(s, "IUDMA channel %d -- ", ch_idx);
 		switch (iudma_defaults[ch_idx].ep_type) {
@@ -2205,14 +2204,10 @@ static int bcm63xx_iudma_dbg_show(struct seq_file *s, void *p)
 		seq_printf(s, "  desc: %d/%d used", iudma->n_bds_used,
 			   iudma->n_bds);
 
-		if (iudma->bep) {
-			i = 0;
-			list_for_each(pos, &iudma->bep->queue)
-				i++;
-			seq_printf(s, "; %d queued\n", i);
-		} else {
+		if (iudma->bep)
+			seq_printf(s, "; %zu queued\n", list_count(&iudma->bep->queue));
+		else
 			seq_printf(s, "\n");
-		}
 
 		for (i = 0; i < iudma->n_bds; i++) {
 			struct bcm_enet_desc *d = &iudma->bd_ring[i];
Signature · 1 line
2.35.1
#3 lore raw

PATCH v4 4/4 xhci: Convert to use list_count()

In reply to Andy Shevchenko

The list API now provides the list_count() to help with counting existing nodes in the list. Utilise it.

---
v4: added tag (Mathias)
v3: no change
v2: no change

 drivers/usb/host/xhci-ring.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/usb/host/xhci-ring.c +2 -5
index ad81e9a508b1..817c31e3b0c8 100644
@@ -2532,7 +2532,6 @@ static int handle_tx_event(struct xhci_hcd *xhci,
 	union xhci_trb *ep_trb;
 	int status = -EINPROGRESS;
 	struct xhci_ep_ctx *ep_ctx;
-	struct list_head *tmp;
 	u32 trb_comp_code;
 	int td_num = 0;
 	bool handling_skipped_tds = false;
@@ -2580,10 +2579,8 @@ static int handle_tx_event(struct xhci_hcd *xhci,
 	}
 
 	/* Count current td numbers if ep->skip is set */
-	if (ep->skip) {
-		list_for_each(tmp, &ep_ring->td_list)
-			td_num++;
-	}
+	if (ep->skip)
+		td_num += list_count(&ep_ring->td_list);
 
 	/* Look for common error cases */
 	switch (trb_comp_code) {
Signature · 1 line
2.35.1
Reviewed-by on v4 1/4
#4 lore raw
In reply to Andy Shevchenko
Quoted 6 lines · Andy Shevchenko

Some of the existing users, and definitely will be new ones, want to count existing nodes in the list. Provide a generic API for that by moving code from i915 to list.h.

thanks
Lucas De Marchi

Quoted 68 lines

---
v4: fixed prototype when converting to static inline
v3: added tag (Jani), changed to be static inline (Mike)
v2: dropped the duplicate code in i915 (LKP) drivers/gpu/drm/i915/gt/intel_engine_cs.c | 13 +------------
include/linux/list.h | 15 +++++++++++++++

2 files changed, 16 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine_cs.c +1 -12
index c33e0d72d670..b96c8217743c 100644
@@ -2094,17 +2094,6 @@ static void print_request_ring(struct drm_printer *m, struct i915_request *rq)
 	}
 }
 
-static unsigned long list_count(struct list_head *list)
-{
-	struct list_head *pos;
-	unsigned long count = 0;
-
-	list_for_each(pos, list)
-		count++;
-
-	return count;
-}
-
 static unsigned long read_ul(void *p, size_t x)
 {
 	return *(unsigned long *)(p + x);
@@ -2279,7 +2268,7 @@ void intel_engine_dump(struct intel_engine_cs *engine,
 	spin_lock_irqsave(&engine->sched_engine->lock, flags);
 	engine_dump_active_requests(engine, m);
 
-	drm_printf(m, "\tOn hold?: %lu\n",
+	drm_printf(m, "\tOn hold?: %zu\n",
 		   list_count(&engine->sched_engine->hold));
 	spin_unlock_irqrestore(&engine->sched_engine->lock, flags);
 
include/linux/list.h +15 -0
index 61762054b4be..632a298c7018 100644
@@ -655,6 +655,21 @@ static inline void list_splice_tail_init(struct list_head *list,
 	     !list_is_head(pos, (head)); \
 	     pos = n, n = pos->prev)
 
+/**
+ * list_count - count nodes in the list
+ * @head:	the head for your list.
+ */
+static inline size_t list_count(struct list_head *head)
+{
+	struct list_head *pos;
+	size_t count = 0;
+
+	list_for_each(pos, head)
+		count++;
+
+	return count;
+}
+
 /**
 * list_entry_is_head - test if the entry points to the head of the list
 * @pos:	the type * to cursor
Signature · 1 line
2.35.1
#5 lore raw

[Intel-gfx] ✗ Fi.CI.DOCS: warning for series starting with [v4,1/4] i915: Move list_count() to list.h for broader use

In reply to Andy Shevchenko
== Series Details ==

== Series Details ==

Series: series starting with [v4,1/4] i915: Move list_count() to list.h for broader use
URL : https://patchwork.freedesktop.org/series/111259/
State : warning

== Summary ==

Error: make htmldocs had i915 warnings
./drivers/gpu/drm/i915/gt/intel_gt_mcr.c:739: warning: expecting prototype for intel_gt_mcr_wait_for_reg_fw(). Prototype was for intel_gt_mcr_wait_for_reg() instead ./drivers/gpu/drm/i915/gt/intel_gt_mcr.c:739: warning: expecting prototype for intel_gt_mcr_wait_for_reg_fw(). Prototype was for intel_gt_mcr_wait_for_reg() instead

#6 lore raw

[Intel-gfx] ✗ Fi.CI.SPARSE: warning for series starting with [v4,1/4] i915: Move list_count() to list.h for broader use

In reply to Andy Shevchenko
== Series Details ==

== Series Details ==

Series: series starting with [v4,1/4] i915: Move list_count() to list.h for broader use
URL : https://patchwork.freedesktop.org/series/111259/
State : warning

== Summary ==

Error: dim sparse failed
Sparse version: v0.6.2
Fast mode used, each commit won't be checked separately.

#7 lore raw

[Intel-gfx] ✓ Fi.CI.BAT: success for series starting with [v4,1/4] i915: Move list_count() to list.h for broader use

In reply to Andy Shevchenko
== Series Details ==

== Series Details ==

Series: series starting with [v4,1/4] i915: Move list_count() to list.h for broader use
URL : https://patchwork.freedesktop.org/series/111259/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_12423 -> Patchwork_111259v1
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111259v1/index.html

Participating hosts (37 -> 37)
------------------------------

Additional (2): fi-cfl-8109u fi-apl-guc
Missing (2): fi-ctg-p8600 fi-ilk-m540

Known issues
------------

Here are the changes found in Patchwork_111259v1 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@core_hotunplug@unbind-rebind:
- fi-apl-guc: NOTRUN -> [INCOMPLETE][1] ([i915#7073])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111259v1/fi-apl-guc/igt@[email protected]

* igt@gem_huc_copy@huc-copy:
- fi-cfl-8109u: NOTRUN -> [SKIP][2] ([fdo#109271] / [i915#2190])
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111259v1/fi-cfl-8109u/igt@[email protected]

* igt@gem_lmem_swapping@verify-random:
- fi-cfl-8109u: NOTRUN -> [SKIP][3] ([fdo#109271] / [i915#4613]) +3 similar issues
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111259v1/fi-cfl-8109u/igt@[email protected]

* igt@i915_selftest@live@gt_heartbeat:
- fi-glk-j4005: [PASS][4] -> [DMESG-FAIL][5] ([i915#5334])
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12423/fi-glk-j4005/igt@i915_selftest@live@gt_heartbeat.html
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111259v1/fi-glk-j4005/igt@i915_selftest@live@gt_heartbeat.html

* igt@kms_chamelium@dp-crc-fast:
- fi-cfl-8109u: NOTRUN -> [SKIP][6] ([fdo#109271] / [fdo#111827]) +8 similar issues
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111259v1/fi-cfl-8109u/igt@[email protected]

* igt@kms_chamelium@hdmi-crc-fast:
- fi-apl-guc: NOTRUN -> [SKIP][7] ([fdo#109271] / [fdo#111827]) +7 similar issues
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111259v1/fi-apl-guc/igt@[email protected]

* igt@kms_force_connector_basic@force-connector-state:
- fi-apl-guc: NOTRUN -> [SKIP][8] ([fdo#109271]) +12 similar issues
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111259v1/fi-apl-guc/igt@[email protected]

* igt@prime_vgem@basic-userptr:
- fi-cfl-8109u: NOTRUN -> [SKIP][9] ([fdo#109271]) +9 similar issues
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111259v1/fi-cfl-8109u/igt@[email protected]

#### Possible fixes ####

* igt@i915_selftest@live@migrate:
- {bat-dg2-11}: [DMESG-WARN][10] ([i915#7359]) -> [PASS][11]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12423/bat-dg2-11/igt@i915_selftest@[email protected]
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111259v1/bat-dg2-11/igt@i915_selftest@[email protected]
- {bat-adlp-6}: [INCOMPLETE][12] ([i915#7348]) -> [PASS][13]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12423/bat-adlp-6/igt@i915_selftest@[email protected]
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111259v1/bat-adlp-6/igt@i915_selftest@[email protected]

* igt@i915_selftest@live@reset:
- {bat-rpls-1}: [DMESG-FAIL][14] ([i915#4983]) -> [PASS][15]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12423/bat-rpls-1/igt@i915_selftest@[email protected]
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111259v1/bat-rpls-1/igt@i915_selftest@[email protected]

* igt@i915_selftest@live@slpc:
- {bat-adln-1}: [DMESG-FAIL][16] ([i915#6997]) -> [PASS][17]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12423/bat-adln-1/igt@i915_selftest@[email protected]
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111259v1/bat-adln-1/igt@i915_selftest@[email protected]

#### Warnings ####

* igt@i915_suspend@basic-s3-without-i915:
- fi-rkl-11600: [FAIL][18] ([fdo#103375]) -> [INCOMPLETE][19] ([i915#4817])
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12423/fi-rkl-11600/igt@[email protected]
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111259v1/fi-rkl-11600/igt@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[fdo#103375]: https://bugs.freedesktop.org/show_bug.cgi?id=103375
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#111827]: https://bugs.freedesktop.org/show_bug.cgi?id=111827
[i915#1845]: https://gitlab.freedesktop.org/drm/intel/issues/1845
[i915#2190]: https://gitlab.freedesktop.org/drm/intel/issues/2190
[i915#4613]: https://gitlab.freedesktop.org/drm/intel/issues/4613
[i915#4817]: https://gitlab.freedesktop.org/drm/intel/issues/4817
[i915#4983]: https://gitlab.freedesktop.org/drm/intel/issues/4983
[i915#5334]: https://gitlab.freedesktop.org/drm/intel/issues/5334
[i915#6367]: https://gitlab.freedesktop.org/drm/intel/issues/6367
[i915#6997]: https://gitlab.freedesktop.org/drm/intel/issues/6997
[i915#7073]: https://gitlab.freedesktop.org/drm/intel/issues/7073
[i915#7348]: https://gitlab.freedesktop.org/drm/intel/issues/7348
[i915#7359]: https://gitlab.freedesktop.org/drm/intel/issues/7359

Build changes
-------------

* Linux: CI_DRM_12423 -> Patchwork_111259v1

CI-20190529: 20190529
CI_DRM_12423: 1faa699c29da496684f8067db4859f352421ce71 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_7072: 69ba7163475925cdc69aebbdfa0e87453ae165c7 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
Patchwork_111259v1: 1faa699c29da496684f8067db4859f352421ce71 @ git://anongit.freedesktop.org/gfx-ci/linux

### Linux commits

be6d33c4bf69 xhci: Convert to use list_count() 9db9c0963e4a usb: gadget: udc: bcm63xx: Convert to use list_count() d3a42bc3ca66 usb: gadget: hid: Convert to use list_count() ae468200324c i915: Move list_count() to list.h for broader use

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_111259v1/index.html