Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm: kselftest for drm_mm and bottom-up allocation

Check that if we request bottom-up allocation from drm_mm_insert_node()
we receive the next available hole from the bottom.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/20170202114434.3060-2-chris@chris-wilson.co.uk

authored by

Chris Wilson and committed by
Daniel Vetter
bb18dfcc 4e64e553

+101
+1
drivers/gpu/drm/selftests/drm_mm_selftests.h
··· 17 17 selftest(align64, igt_align64) 18 18 selftest(evict, igt_evict) 19 19 selftest(evict_range, igt_evict_range) 20 + selftest(bottomup, igt_bottomup) 20 21 selftest(topdown, igt_topdown) 21 22 selftest(color, igt_color) 22 23 selftest(color_evict, igt_color_evict)
+100
drivers/gpu/drm/selftests/test-drm_mm.c
··· 1697 1697 return ret; 1698 1698 } 1699 1699 1700 + static int igt_bottomup(void *ignored) 1701 + { 1702 + const struct insert_mode *bottomup = &insert_modes[BOTTOMUP]; 1703 + DRM_RND_STATE(prng, random_seed); 1704 + const unsigned int count = 8192; 1705 + unsigned int size; 1706 + unsigned long *bitmap; 1707 + struct drm_mm mm; 1708 + struct drm_mm_node *nodes, *node, *next; 1709 + unsigned int *order, n, m, o = 0; 1710 + int ret; 1711 + 1712 + /* Like igt_topdown, but instead of searching for the last hole, 1713 + * we search for the first. 1714 + */ 1715 + 1716 + ret = -ENOMEM; 1717 + nodes = vzalloc(count * sizeof(*nodes)); 1718 + if (!nodes) 1719 + goto err; 1720 + 1721 + bitmap = kzalloc(count / BITS_PER_LONG * sizeof(unsigned long), 1722 + GFP_TEMPORARY); 1723 + if (!bitmap) 1724 + goto err_nodes; 1725 + 1726 + order = drm_random_order(count, &prng); 1727 + if (!order) 1728 + goto err_bitmap; 1729 + 1730 + ret = -EINVAL; 1731 + for (size = 1; size <= 64; size <<= 1) { 1732 + drm_mm_init(&mm, 0, size*count); 1733 + for (n = 0; n < count; n++) { 1734 + if (!expect_insert(&mm, &nodes[n], 1735 + size, 0, n, 1736 + bottomup)) { 1737 + pr_err("bottomup insert failed, size %u step %d\n", size, n); 1738 + goto out; 1739 + } 1740 + 1741 + if (!assert_one_hole(&mm, size*(n + 1), size*count)) 1742 + goto out; 1743 + } 1744 + 1745 + if (!assert_continuous(&mm, size)) 1746 + goto out; 1747 + 1748 + drm_random_reorder(order, count, &prng); 1749 + for_each_prime_number_from(n, 1, min(count, max_prime)) { 1750 + for (m = 0; m < n; m++) { 1751 + node = &nodes[order[(o + m) % count]]; 1752 + drm_mm_remove_node(node); 1753 + __set_bit(node_index(node), bitmap); 1754 + } 1755 + 1756 + for (m = 0; m < n; m++) { 1757 + unsigned int first; 1758 + 1759 + node = &nodes[order[(o + m) % count]]; 1760 + if (!expect_insert(&mm, node, 1761 + size, 0, 0, 1762 + bottomup)) { 1763 + pr_err("insert failed, step %d/%d\n", m, n); 1764 + goto out; 1765 + } 1766 + 1767 + first = find_first_bit(bitmap, count); 1768 + if (node_index(node) != first) { 1769 + pr_err("node %d/%d not inserted into bottom hole, expected %d, found %d\n", 1770 + m, n, first, node_index(node)); 1771 + goto out; 1772 + } 1773 + __clear_bit(first, bitmap); 1774 + } 1775 + 1776 + DRM_MM_BUG_ON(find_first_bit(bitmap, count) != count); 1777 + 1778 + o += n; 1779 + } 1780 + 1781 + drm_mm_for_each_node_safe(node, next, &mm) 1782 + drm_mm_remove_node(node); 1783 + DRM_MM_BUG_ON(!drm_mm_clean(&mm)); 1784 + } 1785 + 1786 + ret = 0; 1787 + out: 1788 + drm_mm_for_each_node_safe(node, next, &mm) 1789 + drm_mm_remove_node(node); 1790 + drm_mm_takedown(&mm); 1791 + kfree(order); 1792 + err_bitmap: 1793 + kfree(bitmap); 1794 + err_nodes: 1795 + vfree(nodes); 1796 + err: 1797 + return ret; 1798 + } 1799 + 1700 1800 static void separate_adjacent_colors(const struct drm_mm_node *node, 1701 1801 unsigned long color, 1702 1802 u64 *start,