Skip to contentSkip to conversation

drm/mst: Fix up u64 division

PATCH In review Sean Paul 3 participants 6 messages Nov 6, 2019 – Nov 8, 2019

Subsystems (2)
lore
Share & tools
lore

Sean Paul

author
#0 lore raw

PATCH 1/1 drm/mst: Fix up u64 division

From: Sean Paul <[email protected]>

Use do_div to divide rem_nsec instead of /.

Fixes 12a280c72868 ("drm/dp_mst: Add topology ref history tracking for debugging")
Cc Juston Li <[email protected]>
Cc Imre Deak <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Harry Wentland <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sean Paul <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_dp_mst_topology.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_dp_mst_topology.c +2 -2
index 11adc4b6ccfe..d2da5f113f16 100644
@@ -1512,10 +1512,10 @@ __dump_topology_ref_history(struct drm_dp_mst_topology_ref_history *history,
 		nr_entries = stack_depot_fetch(entry->backtrace, &entries);
 		stack_trace_snprint(buf, PAGE_SIZE, entries, nr_entries, 4);
 
-		drm_printf(&p, "  %d %ss (last at %5llu.%06llu):\n%s",
+		drm_printf(&p, "  %d %ss (last at %5llu.%06u):\n%s",
 			   entry->count,
 			   topology_ref_type_to_str(entry->type),
-			   ts_nsec, rem_nsec / 1000, buf);
+			   ts_nsec, do_div(rem_nsec, 1000), buf);
 	}
 
 	/* Now free the history, since this is the only time we expose it */
Signature · 6 lines
Sean Paul, Software Engineer, Google / Chromium OS

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw
Quoted 27 lines · Sean Paul

From: Sean Paul <[email protected]>

Use do_div to divide rem_nsec instead of /.

Fixes 12a280c72868 ("drm/dp_mst: Add topology ref history tracking for debugging")
Cc Juston Li <[email protected]>
Cc Imre Deak <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Harry Wentland <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sean Paul <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_dp_mst_topology.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_dp_mst_topology.c +0 -0
index 11adc4b6ccfe..d2da5f113f16 100644

drivers/gpu/drm/drm_dp_mst_topology.c __dump_topology_ref_history(struct drm_dp_mst_topology_ref_history *history, · line 1518

Quoted 9 lines
drivers/gpu/drm/drm_dp_mst_topology.c +2 -2
@@ -1512,10 +1512,10 @@ __dump_topology_ref_history(struct drm_dp_mst_topology_ref_history *history,
 		nr_entries = stack_depot_fetch(entry->backtrace, &entries);
 		stack_trace_snprint(buf, PAGE_SIZE, entries, nr_entries, 4);
 
-		drm_printf(&p, "  %d %ss (last at %5llu.%06llu):\n%s",
+		drm_printf(&p, "  %d %ss (last at %5llu.%06u):\n%s",
 			   entry->count,
 			   topology_ref_type_to_str(entry->type),
-			   ts_nsec, rem_nsec / 1000, buf);
+			   ts_nsec, do_div(rem_nsec, 1000), buf);

Or just change rem_nsec to u32 since that's what do_div() gives you.

Quoted 5 lines
drivers/gpu/drm/drm_dp_mst_topology.c +0 -0
 	}
 
 	/* Now free the history, since this is the only time we expose it */
Signature · 1 line
Sean Paul, Software Engineer, Google / Chromium OS
Signature · 6 lines
Ville Syrjälä
Intel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author
#2 lore raw

PATCH 1/1 drm/mst: Fix up u64 division

From: Sean Paul <[email protected]>

Change rem_nsec to u32 since that's what do_div returns, this avoids the u64 divide in the drm_print args.

Changes in v2:
- Instead of doing do_div in drm_print, make rem_nsec u32 (Ville)

Link to v1: https://patchwork.freedesktop.org/patch/msgid/[email protected]

Fixes 12a280c72868 ("drm/dp_mst: Add topology ref history tracking for debugging")
Cc Juston Li <[email protected]>
Cc Imre Deak <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Harry Wentland <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sean Paul <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
---
 drivers/gpu/drm/drm_dp_mst_topology.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_dp_mst_topology.c +2 -2
index 11adc4b6ccfe..ae5809a1f19a 100644
@@ -1507,12 +1507,12 @@ __dump_topology_ref_history(struct drm_dp_mst_topology_ref_history *history,
 		ulong *entries;
 		uint nr_entries;
 		u64 ts_nsec = entry->ts_nsec;
-		u64 rem_nsec = do_div(ts_nsec, 1000000000);
+		u32 rem_nsec = do_div(ts_nsec, 1000000000);
 
 		nr_entries = stack_depot_fetch(entry->backtrace, &entries);
 		stack_trace_snprint(buf, PAGE_SIZE, entries, nr_entries, 4);
 
-		drm_printf(&p, "  %d %ss (last at %5llu.%06llu):\n%s",
+		drm_printf(&p, "  %d %ss (last at %5llu.%06u):\n%s",
 			   entry->count,
 			   topology_ref_type_to_str(entry->type),
 			   ts_nsec, rem_nsec / 1000, buf);
Signature · 6 lines
Sean Paul, Software Engineer, Google / Chromium OS

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v1 1/1
#3 lore raw
Quoted 10 lines · Sean Paul

From: Sean Paul <[email protected]>

Change rem_nsec to u32 since that's what do_div returns, this avoids the u64 divide in the drm_print args.

Changes in v2:
- Instead of doing do_div in drm_print, make rem_nsec u32 (Ville)

Link to v1: https://patchwork.freedesktop.org/patch/msgid/[email protected]

Quoted 14 lines
Fixes 12a280c72868 ("drm/dp_mst: Add topology ref history tracking for debugging")
Cc Juston Li <[email protected]>
Cc Imre Deak <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Harry Wentland <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sean Paul <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>

lgtm

Quoted 25 lines
---
 drivers/gpu/drm/drm_dp_mst_topology.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_dp_mst_topology.c +2 -2
index 11adc4b6ccfe..ae5809a1f19a 100644
@@ -1507,12 +1507,12 @@ __dump_topology_ref_history(struct drm_dp_mst_topology_ref_history *history,
 		ulong *entries;
 		uint nr_entries;
 		u64 ts_nsec = entry->ts_nsec;
-		u64 rem_nsec = do_div(ts_nsec, 1000000000);
+		u32 rem_nsec = do_div(ts_nsec, 1000000000);
 
 		nr_entries = stack_depot_fetch(entry->backtrace, &entries);
 		stack_trace_snprint(buf, PAGE_SIZE, entries, nr_entries, 4);
 
-		drm_printf(&p, "  %d %ss (last at %5llu.%06llu):\n%s",
+		drm_printf(&p, "  %d %ss (last at %5llu.%06u):\n%s",
 			   entry->count,
 			   topology_ref_type_to_str(entry->type),
 			   ts_nsec, rem_nsec / 1000, buf);
Signature · 1 line
Sean Paul, Software Engineer, Google / Chromium OS
Signature · 6 lines
Ville Syrjälä
Intel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author
#4 lore raw
Quoted 26 lines · Ville Syrjälä
Quoted 10 lines · Sean Paul

From: Sean Paul <[email protected]>

Change rem_nsec to u32 since that's what do_div returns, this avoids the u64 divide in the drm_print args.

Changes in v2:
- Instead of doing do_div in drm_print, make rem_nsec u32 (Ville)

Link to v1: https://patchwork.freedesktop.org/patch/msgid/[email protected]

Quoted 14 lines
Fixes 12a280c72868 ("drm/dp_mst: Add topology ref history tracking for debugging")
Cc Juston Li <[email protected]>
Cc Imre Deak <[email protected]>
Cc Ville Syrjälä <[email protected]>
Cc Harry Wentland <[email protected]>
Cc Daniel Vetter <[email protected]>
Cc Sean Paul <[email protected]>
Cc Lyude Paul <[email protected]>
Cc Maarten Lankhorst <[email protected]>
Cc Maxime Ripard <[email protected]>
Cc David Airlie <[email protected]>
Cc Daniel Vetter <[email protected]>
Quoted 2 lines

lgtm

Thanks for the quick reviews, I've pushed this to drm-misc-next-fixes.

Sean

Quoted 30 lines
Quoted 26 lines
---
 drivers/gpu/drm/drm_dp_mst_topology.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_dp_mst_topology.c +2 -2
index 11adc4b6ccfe..ae5809a1f19a 100644
@@ -1507,12 +1507,12 @@ __dump_topology_ref_history(struct drm_dp_mst_topology_ref_history *history,
 		ulong *entries;
 		uint nr_entries;
 		u64 ts_nsec = entry->ts_nsec;
-		u64 rem_nsec = do_div(ts_nsec, 1000000000);
+		u32 rem_nsec = do_div(ts_nsec, 1000000000);
 
 		nr_entries = stack_depot_fetch(entry->backtrace, &entries);
 		stack_trace_snprint(buf, PAGE_SIZE, entries, nr_entries, 4);
 
-		drm_printf(&p, "  %d %ss (last at %5llu.%06llu):\n%s",
+		drm_printf(&p, "  %d %ss (last at %5llu.%06u):\n%s",
 			   entry->count,
 			   topology_ref_type_to_str(entry->type),
 			   ts_nsec, rem_nsec / 1000, buf);
Signature · 1 line
Sean Paul, Software Engineer, Google / Chromium OS
Signature · 2 lines
Ville Syrjälä
Intel
Signature · 5 lines
Sean Paul, Software Engineer, Google / Chromium OS
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw
In reply to Sean Paul
I love your patch! Perhaps something to improve:

Hi Sean,

I love your patch! Perhaps something to improve:

[auto build test WARNING on drm-intel/for-linux-next]
[also build test WARNING on next-20191108]
[cannot apply to v5.4-rc6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Sean-Paul/drm-mst-Fix-up-u64-division/20191109-040829
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: m68k-allmodconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 7.4.0

reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=m68k

If you fix the issue, kindly add following tag

All warnings (new ones prefixed by >>):

drivers/gpu/drm/drm_dp_mst_topology.c: In function '__topology_ref_save':
drivers/gpu/drm/drm_dp_mst_topology.c:1424:6: error: implicit declaration of function 'stack_trace_save'; did you mean 'stack_depot_save'? [-Werror=implicit-function-declaration]

     n = stack_trace_save(stack_entries, ARRAY_SIZE(stack_entries), 1);
         ^~~~~~~~~~~~~~~~
         stack_depot_save
   drivers/gpu/drm/drm_dp_mst_topology.c: In function '__dump_topology_ref_history':
   drivers/gpu/drm/drm_dp_mst_topology.c:1513:3: error: implicit declaration of function 'stack_trace_snprint'; did you mean 'acpi_trace_point'? [-Werror=implicit-function-declaration]
      stack_trace_snprint(buf, PAGE_SIZE, entries, nr_entries, 4);
      ^~~~~~~~~~~~~~~~~~~
      acpi_trace_point
>> drivers/gpu/drm/drm_dp_mst_topology.c:1515:46: warning: format '%u' expects argument of type 'unsigned int', but argument 6 has type 'long unsigned int' [-Wformat=]
      drm_printf(&p, "  %d %ss (last at %5llu.%06u):\n%s",
                                              ~~~^
                                              %06lu

cc1: some warnings being treated as errors

vim +1515 drivers/gpu/drm/drm_dp_mst_topology.c

1412
1413 static noinline void
1414 __topology_ref_save(struct drm_dp_mst_topology_mgr *mgr,
1415 struct drm_dp_mst_topology_ref_history *history,
1416 enum drm_dp_mst_topology_ref_type type)
1417 {
1418 struct drm_dp_mst_topology_ref_entry *entry = NULL;
1419 depot_stack_handle_t backtrace;
1420 ulong stack_entries[STACK_DEPTH];
1421 uint n;
1422 int i;
1423

> 1424		n = stack_trace_save(stack_entries, ARRAY_SIZE(stack_entries), 1);
  1425		backtrace = stack_depot_save(stack_entries, n, GFP_KERNEL);
  1426		if (!backtrace)
  1427			return;
  1428	
  1429		/* Try to find an existing entry for this backtrace */
  1430		for (i = 0; i < history->len; i++) {
  1431			if (history->entries[i].backtrace == backtrace) {
  1432				entry = &history->entries[i];
  1433				break;
  1434			}
  1435		}
  1436	
  1437		/* Otherwise add one */
  1438		if (!entry) {
  1439			struct drm_dp_mst_topology_ref_entry *new;
  1440			int new_len = history->len + 1;
  1441	
  1442			new = krealloc(history->entries, sizeof(*new) * new_len,
  1443				       GFP_KERNEL);
  1444			if (!new)
  1445				return;
  1446	
  1447			entry = &new[history->len];
  1448			history->len = new_len;
  1449			history->entries = new;
  1450	
  1451			entry->backtrace = backtrace;
  1452			entry->type = type;
  1453			entry->count = 0;
  1454		}
  1455		entry->count++;
  1456		entry->ts_nsec = ktime_get_ns();
  1457	}
  1458	
  1459	static int
  1460	topology_ref_history_cmp(const void *a, const void *b)
  1461	{
  1462		const struct drm_dp_mst_topology_ref_entry *entry_a = a, *entry_b = b;
  1463	
  1464		if (entry_a->ts_nsec > entry_b->ts_nsec)
  1465			return 1;
  1466		else if (entry_a->ts_nsec < entry_b->ts_nsec)
  1467			return -1;
  1468		else
  1469			return 0;
  1470	}
  1471	
  1472	static inline const char *
  1473	topology_ref_type_to_str(enum drm_dp_mst_topology_ref_type type)
  1474	{
  1475		if (type == DRM_DP_MST_TOPOLOGY_REF_GET)
  1476			return "get";
  1477		else
  1478			return "put";
  1479	}
  1480	
  1481	static void
  1482	__dump_topology_ref_history(struct drm_dp_mst_topology_ref_history *history,
  1483				    void *ptr, const char *type_str)
  1484	{
  1485		struct drm_printer p = drm_debug_printer(DBG_PREFIX);
  1486		char *buf = kzalloc(PAGE_SIZE, GFP_KERNEL);
  1487		int i;
  1488	
  1489		if (!buf)
  1490			return;
  1491	
  1492		if (!history->len)
  1493			goto out;
  1494	
  1495		/* First, sort the list so that it goes from oldest to newest
  1496		 * reference entry
  1497		 */
  1498		sort(history->entries, history->len, sizeof(*history->entries),
  1499		     topology_ref_history_cmp, NULL);
  1500	
  1501		drm_printf(&p, "%s (%p) topology count reached 0, dumping history:\n",
  1502			   type_str, ptr);
  1503	
  1504		for (i = 0; i < history->len; i++) {
  1505			const struct drm_dp_mst_topology_ref_entry *entry =
  1506				&history->entries[i];
  1507			ulong *entries;
  1508			uint nr_entries;
  1509			u64 ts_nsec = entry->ts_nsec;
  1510			u64 rem_nsec = do_div(ts_nsec, 1000000000);
  1511	
  1512			nr_entries = stack_depot_fetch(entry->backtrace, &entries);
  1513			stack_trace_snprint(buf, PAGE_SIZE, entries, nr_entries, 4);
  1514	
> 1515			drm_printf(&p, "  %d %ss (last at %5llu.%06u):\n%s",
  1516				   entry->count,
  1517				   topology_ref_type_to_str(entry->type),
  1518				   ts_nsec, do_div(rem_nsec, 1000), buf);

1519 }
1520
1521 /* Now free the history, since this is the only time we expose it */
1522 kfree(history->entries);
1523 out:
1524 kfree(buf);
1525 }
1526

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation