diff mbox series

[v1,1/2] drm/selftests/mm: Switch to bitmap_zalloc()

Message ID 20190304090321.47638-1-andriy.shevchenko@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series [v1,1/2] drm/selftests/mm: Switch to bitmap_zalloc() | expand

Commit Message

Andy Shevchenko March 4, 2019, 9:03 a.m. UTC
Switch to bitmap_zalloc() to show clearly what we are allocating.
Besides that it returns pointer of bitmap type instead of opaque void *.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpu/drm/selftests/test-drm_mm.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

Comments

kernel test robot March 4, 2019, 11:03 a.m. UTC | #1
Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on drm-intel/for-linux-next]
[also build test ERROR on v5.0 next-20190301]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Andy-Shevchenko/drm-selftests-mm-Switch-to-bitmap_zalloc/20190304-183335
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: nds32-allyesconfig (attached as .config)
compiler: nds32le-linux-gcc (GCC) 6.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=6.4.0 make.cross ARCH=nds32 

All error/warnings (new ones prefixed by >>):

   drivers/gpu/drm/selftests/test-drm_mm.c: In function 'igt_bottomup':
>> drivers/gpu/drm/selftests/test-drm_mm.c:1747:11: error: implicit declaration of function 'bitmap_zcalloc' [-Werror=implicit-function-declaration]
     bitmap = bitmap_zcalloc(count, GFP_KERNEL);
              ^~~~~~~~~~~~~~
>> drivers/gpu/drm/selftests/test-drm_mm.c:1747:9: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
     bitmap = bitmap_zcalloc(count, GFP_KERNEL);
            ^
   cc1: some warnings being treated as errors

vim +/bitmap_zcalloc +1747 drivers/gpu/drm/selftests/test-drm_mm.c

  1725	
  1726	static int igt_bottomup(void *ignored)
  1727	{
  1728		const struct insert_mode *bottomup = &insert_modes[BOTTOMUP];
  1729		DRM_RND_STATE(prng, random_seed);
  1730		const unsigned int count = 8192;
  1731		unsigned int size;
  1732		unsigned long *bitmap;
  1733		struct drm_mm mm;
  1734		struct drm_mm_node *nodes, *node, *next;
  1735		unsigned int *order, n, m, o = 0;
  1736		int ret;
  1737	
  1738		/* Like igt_topdown, but instead of searching for the last hole,
  1739		 * we search for the first.
  1740		 */
  1741	
  1742		ret = -ENOMEM;
  1743		nodes = vzalloc(array_size(count, sizeof(*nodes)));
  1744		if (!nodes)
  1745			goto err;
  1746	
> 1747		bitmap = bitmap_zcalloc(count, GFP_KERNEL);
  1748		if (!bitmap)
  1749			goto err_nodes;
  1750	
  1751		order = drm_random_order(count, &prng);
  1752		if (!order)
  1753			goto err_bitmap;
  1754	
  1755		ret = -EINVAL;
  1756		for (size = 1; size <= 64; size <<= 1) {
  1757			drm_mm_init(&mm, 0, size*count);
  1758			for (n = 0; n < count; n++) {
  1759				if (!expect_insert(&mm, &nodes[n],
  1760						   size, 0, n,
  1761						   bottomup)) {
  1762					pr_err("bottomup insert failed, size %u step %d\n", size, n);
  1763					goto out;
  1764				}
  1765	
  1766				if (!assert_one_hole(&mm, size*(n + 1), size*count))
  1767					goto out;
  1768			}
  1769	
  1770			if (!assert_continuous(&mm, size))
  1771				goto out;
  1772	
  1773			drm_random_reorder(order, count, &prng);
  1774			for_each_prime_number_from(n, 1, min(count, max_prime)) {
  1775				for (m = 0; m < n; m++) {
  1776					node = &nodes[order[(o + m) % count]];
  1777					drm_mm_remove_node(node);
  1778					__set_bit(node_index(node), bitmap);
  1779				}
  1780	
  1781				for (m = 0; m < n; m++) {
  1782					unsigned int first;
  1783	
  1784					node = &nodes[order[(o + m) % count]];
  1785					if (!expect_insert(&mm, node,
  1786							   size, 0, 0,
  1787							   bottomup)) {
  1788						pr_err("insert failed, step %d/%d\n", m, n);
  1789						goto out;
  1790					}
  1791	
  1792					first = find_first_bit(bitmap, count);
  1793					if (node_index(node) != first) {
  1794						pr_err("node %d/%d not inserted into bottom hole, expected %d, found %d\n",
  1795						       m, n, first, node_index(node));
  1796						goto out;
  1797					}
  1798					__clear_bit(first, bitmap);
  1799				}
  1800	
  1801				DRM_MM_BUG_ON(find_first_bit(bitmap, count) != count);
  1802	
  1803				o += n;
  1804			}
  1805	
  1806			drm_mm_for_each_node_safe(node, next, &mm)
  1807				drm_mm_remove_node(node);
  1808			DRM_MM_BUG_ON(!drm_mm_clean(&mm));
  1809			cond_resched();
  1810		}
  1811	
  1812		ret = 0;
  1813	out:
  1814		drm_mm_for_each_node_safe(node, next, &mm)
  1815			drm_mm_remove_node(node);
  1816		drm_mm_takedown(&mm);
  1817		kfree(order);
  1818	err_bitmap:
  1819		bitmap_free(bitmap);
  1820	err_nodes:
  1821		vfree(nodes);
  1822	err:
  1823		return ret;
  1824	}
  1825	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
kernel test robot March 4, 2019, 11:13 a.m. UTC | #2
Hi Andy,

I love your patch! Yet something to improve:

[auto build test ERROR on drm-intel/for-linux-next]
[also build test ERROR on v5.0 next-20190301]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/Andy-Shevchenko/drm-selftests-mm-Switch-to-bitmap_zalloc/20190304-183335
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: xtensa-allyesconfig (attached as .config)
compiler: xtensa-linux-gcc (GCC) 8.2.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=8.2.0 make.cross ARCH=xtensa 

All error/warnings (new ones prefixed by >>):

   drivers/gpu//drm/selftests/test-drm_mm.c: In function 'igt_bottomup':
>> drivers/gpu//drm/selftests/test-drm_mm.c:1747:11: error: implicit declaration of function 'bitmap_zcalloc'; did you mean 'bitmap_zalloc'? [-Werror=implicit-function-declaration]
     bitmap = bitmap_zcalloc(count, GFP_KERNEL);
              ^~~~~~~~~~~~~~
              bitmap_zalloc
>> drivers/gpu//drm/selftests/test-drm_mm.c:1747:9: warning: assignment to 'long unsigned int *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
     bitmap = bitmap_zcalloc(count, GFP_KERNEL);
            ^
   cc1: some warnings being treated as errors

vim +1747 drivers/gpu//drm/selftests/test-drm_mm.c

  1725	
  1726	static int igt_bottomup(void *ignored)
  1727	{
  1728		const struct insert_mode *bottomup = &insert_modes[BOTTOMUP];
  1729		DRM_RND_STATE(prng, random_seed);
  1730		const unsigned int count = 8192;
  1731		unsigned int size;
  1732		unsigned long *bitmap;
  1733		struct drm_mm mm;
  1734		struct drm_mm_node *nodes, *node, *next;
  1735		unsigned int *order, n, m, o = 0;
  1736		int ret;
  1737	
  1738		/* Like igt_topdown, but instead of searching for the last hole,
  1739		 * we search for the first.
  1740		 */
  1741	
  1742		ret = -ENOMEM;
  1743		nodes = vzalloc(array_size(count, sizeof(*nodes)));
  1744		if (!nodes)
  1745			goto err;
  1746	
> 1747		bitmap = bitmap_zcalloc(count, GFP_KERNEL);
  1748		if (!bitmap)
  1749			goto err_nodes;
  1750	
  1751		order = drm_random_order(count, &prng);
  1752		if (!order)
  1753			goto err_bitmap;
  1754	
  1755		ret = -EINVAL;
  1756		for (size = 1; size <= 64; size <<= 1) {
  1757			drm_mm_init(&mm, 0, size*count);
  1758			for (n = 0; n < count; n++) {
  1759				if (!expect_insert(&mm, &nodes[n],
  1760						   size, 0, n,
  1761						   bottomup)) {
  1762					pr_err("bottomup insert failed, size %u step %d\n", size, n);
  1763					goto out;
  1764				}
  1765	
  1766				if (!assert_one_hole(&mm, size*(n + 1), size*count))
  1767					goto out;
  1768			}
  1769	
  1770			if (!assert_continuous(&mm, size))
  1771				goto out;
  1772	
  1773			drm_random_reorder(order, count, &prng);
  1774			for_each_prime_number_from(n, 1, min(count, max_prime)) {
  1775				for (m = 0; m < n; m++) {
  1776					node = &nodes[order[(o + m) % count]];
  1777					drm_mm_remove_node(node);
  1778					__set_bit(node_index(node), bitmap);
  1779				}
  1780	
  1781				for (m = 0; m < n; m++) {
  1782					unsigned int first;
  1783	
  1784					node = &nodes[order[(o + m) % count]];
  1785					if (!expect_insert(&mm, node,
  1786							   size, 0, 0,
  1787							   bottomup)) {
  1788						pr_err("insert failed, step %d/%d\n", m, n);
  1789						goto out;
  1790					}
  1791	
  1792					first = find_first_bit(bitmap, count);
  1793					if (node_index(node) != first) {
  1794						pr_err("node %d/%d not inserted into bottom hole, expected %d, found %d\n",
  1795						       m, n, first, node_index(node));
  1796						goto out;
  1797					}
  1798					__clear_bit(first, bitmap);
  1799				}
  1800	
  1801				DRM_MM_BUG_ON(find_first_bit(bitmap, count) != count);
  1802	
  1803				o += n;
  1804			}
  1805	
  1806			drm_mm_for_each_node_safe(node, next, &mm)
  1807				drm_mm_remove_node(node);
  1808			DRM_MM_BUG_ON(!drm_mm_clean(&mm));
  1809			cond_resched();
  1810		}
  1811	
  1812		ret = 0;
  1813	out:
  1814		drm_mm_for_each_node_safe(node, next, &mm)
  1815			drm_mm_remove_node(node);
  1816		drm_mm_takedown(&mm);
  1817		kfree(order);
  1818	err_bitmap:
  1819		bitmap_free(bitmap);
  1820	err_nodes:
  1821		vfree(nodes);
  1822	err:
  1823		return ret;
  1824	}
  1825	

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
Joonas Lahtinen March 5, 2019, 9:28 a.m. UTC | #3
I take it that both instances are supposed to call bitmap_zalloc?

If you can send a v2 that compiles, I can merge it after it passes the
CI.

Regards, Joonas

Quoting Andy Shevchenko (2019-03-04 11:03:20)
> Switch to bitmap_zalloc() to show clearly what we are allocating.
> Besides that it returns pointer of bitmap type instead of opaque void *.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/gpu/drm/selftests/test-drm_mm.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c
> index fbed2c90fd51..d1206aef26af 100644
> --- a/drivers/gpu/drm/selftests/test-drm_mm.c
> +++ b/drivers/gpu/drm/selftests/test-drm_mm.c
> @@ -1615,7 +1615,7 @@ static int igt_topdown(void *ignored)
>         DRM_RND_STATE(prng, random_seed);
>         const unsigned int count = 8192;
>         unsigned int size;
> -       unsigned long *bitmap = NULL;
> +       unsigned long *bitmap;
>         struct drm_mm mm;
>         struct drm_mm_node *nodes, *node, *next;
>         unsigned int *order, n, m, o = 0;
> @@ -1631,8 +1631,7 @@ static int igt_topdown(void *ignored)
>         if (!nodes)
>                 goto err;
>  
> -       bitmap = kcalloc(count / BITS_PER_LONG, sizeof(unsigned long),
> -                        GFP_KERNEL);
> +       bitmap = bitmap_zalloc(count, GFP_KERNEL);
>         if (!bitmap)
>                 goto err_nodes;
>  
> @@ -1717,7 +1716,7 @@ static int igt_topdown(void *ignored)
>         drm_mm_takedown(&mm);
>         kfree(order);
>  err_bitmap:
> -       kfree(bitmap);
> +       bitmap_free(bitmap);
>  err_nodes:
>         vfree(nodes);
>  err:
> @@ -1745,8 +1744,7 @@ static int igt_bottomup(void *ignored)
>         if (!nodes)
>                 goto err;
>  
> -       bitmap = kcalloc(count / BITS_PER_LONG, sizeof(unsigned long),
> -                        GFP_KERNEL);
> +       bitmap = bitmap_zcalloc(count, GFP_KERNEL);
>         if (!bitmap)
>                 goto err_nodes;
>  
> @@ -1818,7 +1816,7 @@ static int igt_bottomup(void *ignored)
>         drm_mm_takedown(&mm);
>         kfree(order);
>  err_bitmap:
> -       kfree(bitmap);
> +       bitmap_free(bitmap);
>  err_nodes:
>         vfree(nodes);
>  err:
> -- 
> 2.20.1
>
Andy Shevchenko March 5, 2019, 10:20 a.m. UTC | #4
On Tue, Mar 05, 2019 at 11:28:36AM +0200, Joonas Lahtinen wrote:
> I take it that both instances are supposed to call bitmap_zalloc?
> 
> If you can send a v2 that compiles, I can merge it after it passes the
> CI.

v2 had been sent yesterday.
Chris Wilson March 5, 2019, 10:22 a.m. UTC | #5
Quoting Andy Shevchenko (2019-03-05 10:20:31)
> On Tue, Mar 05, 2019 at 11:28:36AM +0200, Joonas Lahtinen wrote:
> > I take it that both instances are supposed to call bitmap_zalloc?
> > 
> > If you can send a v2 that compiles, I can merge it after it passes the
> > CI.
> 
> v2 had been sent yesterday.
https://patchwork.freedesktop.org/series/57507/
-Chris
diff mbox series

Patch

diff --git a/drivers/gpu/drm/selftests/test-drm_mm.c b/drivers/gpu/drm/selftests/test-drm_mm.c
index fbed2c90fd51..d1206aef26af 100644
--- a/drivers/gpu/drm/selftests/test-drm_mm.c
+++ b/drivers/gpu/drm/selftests/test-drm_mm.c
@@ -1615,7 +1615,7 @@  static int igt_topdown(void *ignored)
 	DRM_RND_STATE(prng, random_seed);
 	const unsigned int count = 8192;
 	unsigned int size;
-	unsigned long *bitmap = NULL;
+	unsigned long *bitmap;
 	struct drm_mm mm;
 	struct drm_mm_node *nodes, *node, *next;
 	unsigned int *order, n, m, o = 0;
@@ -1631,8 +1631,7 @@  static int igt_topdown(void *ignored)
 	if (!nodes)
 		goto err;
 
-	bitmap = kcalloc(count / BITS_PER_LONG, sizeof(unsigned long),
-			 GFP_KERNEL);
+	bitmap = bitmap_zalloc(count, GFP_KERNEL);
 	if (!bitmap)
 		goto err_nodes;
 
@@ -1717,7 +1716,7 @@  static int igt_topdown(void *ignored)
 	drm_mm_takedown(&mm);
 	kfree(order);
 err_bitmap:
-	kfree(bitmap);
+	bitmap_free(bitmap);
 err_nodes:
 	vfree(nodes);
 err:
@@ -1745,8 +1744,7 @@  static int igt_bottomup(void *ignored)
 	if (!nodes)
 		goto err;
 
-	bitmap = kcalloc(count / BITS_PER_LONG, sizeof(unsigned long),
-			 GFP_KERNEL);
+	bitmap = bitmap_zcalloc(count, GFP_KERNEL);
 	if (!bitmap)
 		goto err_nodes;
 
@@ -1818,7 +1816,7 @@  static int igt_bottomup(void *ignored)
 	drm_mm_takedown(&mm);
 	kfree(order);
 err_bitmap:
-	kfree(bitmap);
+	bitmap_free(bitmap);
 err_nodes:
 	vfree(nodes);
 err: