From: Daniel Vetter <daniel.vetter@ffwll.ch>
To: intel-gfx@lists.freedesktop.org
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>, dri-devel@lists.freedesktop.org
Subject: [PATCH 6/9] drm_mm: extract check_free_mm_node
Date: Tue, 18 May 2010 23:11:48 +0200 [thread overview]
Message-ID: <1274217111-3882-7-git-send-email-daniel.vetter@ffwll.ch> (raw)
In-Reply-To: <1274217111-3882-1-git-send-email-daniel.vetter@ffwll.ch>
There are already two copies of this logic. And the new scanning
stuff will add some more. So extract it into a small helper
function.
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
drivers/gpu/drm/drm_mm.c | 71 ++++++++++++++++++++++------------------------
1 files changed, 34 insertions(+), 37 deletions(-)
diff --git a/drivers/gpu/drm/drm_mm.c b/drivers/gpu/drm/drm_mm.c
index d2267ff..fd86a6c 100644
--- a/drivers/gpu/drm/drm_mm.c
+++ b/drivers/gpu/drm/drm_mm.c
@@ -283,6 +283,27 @@ void drm_mm_put_block(struct drm_mm_node *cur)
EXPORT_SYMBOL(drm_mm_put_block);
+static int check_free_mm_node(struct drm_mm_node *entry, unsigned long size,
+ unsigned alignment)
+{
+ unsigned wasted = 0;
+
+ if (entry->size < size)
+ return 0;
+
+ if (alignment) {
+ register unsigned tmp = entry->start % alignment;
+ if (tmp)
+ wasted = alignment - tmp;
+ }
+
+ if (entry->size >= size + wasted) {
+ return 1;
+ }
+
+ return 0;
+}
+
struct drm_mm_node *drm_mm_search_free(const struct drm_mm *mm,
unsigned long size,
unsigned alignment, int best_match)
@@ -290,30 +311,20 @@ struct drm_mm_node *drm_mm_search_free(const struct drm_mm *mm,
struct drm_mm_node *entry;
struct drm_mm_node *best;
unsigned long best_size;
- unsigned wasted;
best = NULL;
best_size = ~0UL;
list_for_each_entry(entry, &mm->free_stack, free_stack) {
- wasted = 0;
-
- if (entry->size < size)
+ if (!check_free_mm_node(entry, size, alignment))
continue;
- if (alignment) {
- register unsigned tmp = entry->start % alignment;
- if (tmp)
- wasted += alignment - tmp;
- }
+ if (!best_match)
+ return entry;
- if (entry->size >= size + wasted) {
- if (!best_match)
- return entry;
- if (entry->size < best_size) {
- best = entry;
- best_size = entry->size;
- }
+ if (entry->size < best_size) {
+ best = entry;
+ best_size = entry->size;
}
}
@@ -331,37 +342,23 @@ struct drm_mm_node *drm_mm_search_free_in_range(const struct drm_mm *mm,
struct drm_mm_node *entry;
struct drm_mm_node *best;
unsigned long best_size;
- unsigned wasted;
best = NULL;
best_size = ~0UL;
list_for_each_entry(entry, &mm->free_stack, free_stack) {
- wasted = 0;
-
- if (entry->size < size)
+ if (entry->start > end || (entry->start+entry->size) < start)
continue;
- if (entry->start > end || (entry->start+entry->size) < start)
+ if (!check_free_mm_node(entry, size, alignment))
continue;
- if (entry->start < start)
- wasted += start - entry->start;
+ if (!best_match)
+ return entry;
- if (alignment) {
- register unsigned tmp = (entry->start + wasted) % alignment;
- if (tmp)
- wasted += alignment - tmp;
- }
-
- if (entry->size >= size + wasted &&
- (entry->start + wasted + size) <= end) {
- if (!best_match)
- return entry;
- if (entry->size < best_size) {
- best = entry;
- best_size = entry->size;
- }
+ if (entry->size < best_size) {
+ best = entry;
+ best_size = entry->size;
}
}
--
1.7.1
next prev parent reply other threads:[~2010-05-18 21:11 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-05-18 21:11 [PATCH 0/9] [RFC] fair-lru eviction Daniel Vetter
2010-05-18 21:11 ` [PATCH 1/9] list.h: add list_for_each_entry_safe_from_reverse Daniel Vetter
2010-05-18 21:11 ` [PATCH 2/9] drm: use list_for_each_entry in drm_mm.c Daniel Vetter
2010-05-18 21:11 ` [PATCH 3/9] drm: kill drm_mm_node->private Daniel Vetter
2010-05-19 9:25 ` Jerome Glisse
2010-05-19 17:03 ` Daniel Vetter
2010-05-19 22:04 ` Jerome Glisse
2010-05-18 21:11 ` [PATCH 4/9] drm: kill dead code in drm_mm.c Daniel Vetter
2010-05-18 21:11 ` [PATCH 5/9] drm: sane naming for drm_mm.c Daniel Vetter
2010-05-18 21:11 ` Daniel Vetter [this message]
2010-05-18 21:11 ` [PATCH 7/9] drm: implement helper functions for scanning lru list Daniel Vetter
2010-05-18 21:11 ` [PATCH 8/9] drm/i915: prepare for fair lru eviction Daniel Vetter
2010-05-18 21:11 ` [PATCH 9/9] drm/i915: implement " Daniel Vetter
2010-05-19 3:05 ` [PATCH 0/9] [RFC] fair-lru eviction Eric Anholt
2010-05-19 8:06 ` Chris Wilson
2010-05-19 16:57 ` Daniel Vetter
2010-05-19 17:09 ` Chris Wilson
2010-05-19 19:51 ` Thomas Hellström
2010-05-19 20:13 ` Daniel Vetter
2010-05-19 21:08 ` Thomas Hellstrom
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=1274217111-3882-7-git-send-email-daniel.vetter@ffwll.ch \
--to=daniel.vetter@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).