mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Dave Airlie <airlied@linux.ie>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	linux-kernel@vger.kernel.org, dri-devel@lists.sf.net
Subject: Re: [git pull] drm patches for 2.6.27-rc1
Date: Fri, 17 Oct 2008 15:43:02 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LFD.2.00.0810171510170.3438@nehalem.linux-foundation.org> (raw)
In-Reply-To: <alpine.DEB.0.82.0810172227490.14817@skynet.skynet.ie>



On Fri, 17 Oct 2008, Dave Airlie wrote:
> 
> Please pull the 'drm-next' branch from
> ssh://master.kernel.org/pub/scm/linux/kernel/git/airlied/drm-2.6.git drm-next

Grr.

This whole merge series has been full of people sending me UNTESTED CRAP.

So what's the excuse _this_ time for adding all these stupid warnings to 
my build log? Did nobody test this?

  drivers/gpu/drm/drm_proc.c: In function ‘drm_gem_one_name_info’:
  drivers/gpu/drm/drm_proc.c:525: warning: format ‘%d’ expects type ‘int’, but argument 3 has type ‘size_t’
  drivers/gpu/drm/drm_proc.c:533: warning: format ‘%9d’ expects type ‘int’, but argument 4 has type ‘size_t’
  drivers/gpu/drm/i915/i915_gem.c: In function ‘i915_gem_gtt_pwrite’:
  drivers/gpu/drm/i915/i915_gem.c:184: warning: unused variable ‘vaddr_atomic’

and I wonder how many other warnings got added that I never even noticed 
because I don't build them?

And yes, it's not just warnings. One of thse is horribly bad code:

	nid->len += sprintf(&nid->buf[nid->len],
                            "%6d%9d%8d%9d\n",
                            obj->name, obj->size,
                            atomic_read(&obj->handlecount.refcount),
                            atomic_read(&obj->refcount.refcount));

where it's just wrong to use the field width as a separator. Because if 
the counts are big enough, the separator suddenly goes away!

So that format string should be

	"%6d %8zd %7d %8d\n"

instead. Which  gives the same output when you don't overflow, and doesn't 
have the overflow bug when you do.

As to that "vaddr_atomic" thing, the warning would have been avoided if 
you had just cleanly split up the optimistic fast case.

IOW, write cleaner code, and the warning just goes away on its own. 
Something like the appended. UNTESTED!

Hmm?

I really wish people were more careful, and took more pride in trying to 
write readable code, with small modular functions instead. And move those 
variables down to the block they are needed in.

Anyway, I pulled the thing, but _please_ test this cleanup and send it 
back to me if it passes your testing. Ok? 

			Linus

---
 drivers/gpu/drm/drm_proc.c      |    4 +-
 drivers/gpu/drm/i915/i915_gem.c |   59 +++++++++++++++++++++++---------------
 2 files changed, 38 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/drm_proc.c b/drivers/gpu/drm/drm_proc.c
index d490db4..ae73b7f 100644
--- a/drivers/gpu/drm/drm_proc.c
+++ b/drivers/gpu/drm/drm_proc.c
@@ -522,12 +522,12 @@ static int drm_gem_one_name_info(int id, void *ptr, void *data)
 	struct drm_gem_object *obj = ptr;
 	struct drm_gem_name_info_data   *nid = data;
 
-	DRM_INFO("name %d size %d\n", obj->name, obj->size);
+	DRM_INFO("name %d size %zd\n", obj->name, obj->size);
 	if (nid->eof)
 		return 0;
 
 	nid->len += sprintf(&nid->buf[nid->len],
-			    "%6d%9d%8d%9d\n",
+			    "%6d %8zd %7d %8d\n",
 			    obj->name, obj->size,
 			    atomic_read(&obj->handlecount.refcount),
 			    atomic_read(&obj->refcount.refcount));
diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 9ac73dd..b8c8b2e 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -171,6 +171,36 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data,
 	return 0;
 }
 
+/*
+ * Try to write quickly with an atomic kmap. Return true on success.
+ *
+ * If this fails (which includes a partial write), we'll redo the whole
+ * thing with the slow version.
+ *
+ * This is a workaround for the low performance of iounmap (approximate
+ * 10% cpu cost on normal 3D workloads).  kmap_atomic on HIGHMEM kernels
+ * happens to let us map card memory without taking IPIs.  When the vmap
+ * rework lands we should be able to dump this hack.
+ */
+static inline int fast_user_write(unsigned long pfn, char __user *user_data, int l)
+{
+#ifdef CONFIG_HIGHMEM
+	unsigned long unwritten;
+	char *vaddr_atomic;
+
+	vaddr_atomic = kmap_atomic_pfn(pfn, KM_USER0);
+#if WATCH_PWRITE
+	DRM_INFO("pwrite i %d o %d l %d pfn %ld vaddr %p\n",
+		 i, o, l, pfn, vaddr_atomic);
+#endif
+	unwritten = __copy_from_user_inatomic_nocache(vaddr_atomic + o, user_data, l);
+	kunmap_atomic(vaddr_atomic, KM_USER0);
+	return !unwritten;
+#else
+	return 1;
+#endif
+}
+
 static int
 i915_gem_gtt_pwrite(struct drm_device *dev, struct drm_gem_object *obj,
 		    struct drm_i915_gem_pwrite *args,
@@ -180,12 +210,7 @@ i915_gem_gtt_pwrite(struct drm_device *dev, struct drm_gem_object *obj,
 	ssize_t remain;
 	loff_t offset;
 	char __user *user_data;
-	char __iomem *vaddr;
-	char *vaddr_atomic;
-	int i, o, l;
 	int ret = 0;
-	unsigned long pfn;
-	unsigned long unwritten;
 
 	user_data = (char __user *) (uintptr_t) args->data_ptr;
 	remain = args->size;
@@ -209,6 +234,9 @@ i915_gem_gtt_pwrite(struct drm_device *dev, struct drm_gem_object *obj,
 	obj_priv->dirty = 1;
 
 	while (remain > 0) {
+		unsigned long pfn;
+		int i, o, l;
+
 		/* Operation in this page
 		 *
 		 * i = page number
@@ -223,25 +251,10 @@ i915_gem_gtt_pwrite(struct drm_device *dev, struct drm_gem_object *obj,
 
 		pfn = (dev->agp->base >> PAGE_SHIFT) + i;
 
-#ifdef CONFIG_HIGHMEM
-		/* This is a workaround for the low performance of iounmap
-		 * (approximate 10% cpu cost on normal 3D workloads).
-		 * kmap_atomic on HIGHMEM kernels happens to let us map card
-		 * memory without taking IPIs.  When the vmap rework lands
-		 * we should be able to dump this hack.
-		 */
-		vaddr_atomic = kmap_atomic_pfn(pfn, KM_USER0);
-#if WATCH_PWRITE
-		DRM_INFO("pwrite i %d o %d l %d pfn %ld vaddr %p\n",
-			 i, o, l, pfn, vaddr_atomic);
-#endif
-		unwritten = __copy_from_user_inatomic_nocache(vaddr_atomic + o,
-							      user_data, l);
-		kunmap_atomic(vaddr_atomic, KM_USER0);
+		if (!fast_user_write(pfn, user_data, l)) {
+			unsigned long unwritten;
+			char __iomem *vaddr;
 
-		if (unwritten)
-#endif /* CONFIG_HIGHMEM */
-		{
 			vaddr = ioremap_wc(pfn << PAGE_SHIFT, PAGE_SIZE);
 #if WATCH_PWRITE
 			DRM_INFO("pwrite slow i %d o %d l %d "

  reply	other threads:[~2008-10-17 22:43 UTC|newest]

Thread overview: 75+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-17 21:29 Dave Airlie
2008-10-17 22:43 ` Linus Torvalds [this message]
2008-10-18  2:10   ` Eric Anholt
2008-10-18  2:47     ` Linus Torvalds
2008-10-18  3:49       ` Keith Packard
2008-10-18  6:44         ` Corbin Simpson
2008-10-18  7:49       ` Eric Anholt
2008-10-19 17:52         ` Peter Zijlstra
2008-10-20  4:17           ` Steven J Newbury
2008-10-20 16:31         ` Linus Torvalds
2008-10-20 20:04     ` Jesse Barnes
2008-10-18  9:11   ` Dave Airlie
2008-10-18  1:37 ` Nick Piggin
2008-10-18 19:11   ` Keith Packard
2008-10-18 19:31     ` Linus Torvalds
2008-10-18 20:07       ` Thomas Hellström
2008-10-18 20:20       ` Keith Packard
2008-10-18 20:37       ` Ingo Molnar
2008-10-18 21:51         ` Keith Packard
2008-10-18 22:32           ` Ingo Molnar
2008-10-18 22:47             ` Jon Smirl
2008-10-18 22:53               ` Linus Torvalds
2008-10-19  0:38             ` Keith Packard
2008-10-19  1:06               ` Arjan van de Ven
2008-10-19  1:15                 ` Keith Packard
2008-10-20 10:01               ` Ingo Molnar
2008-10-19  4:14             ` Keith Packard
2008-10-19  6:41               ` Keith Packard
2008-10-19 17:53                 ` io resources and cached mappings (was: [git pull] drm patches for 2.6.27-rc1) Ingo Molnar
2008-10-19 18:00                   ` Arjan van de Ven
2008-10-19 19:07                   ` Eric Anholt
2008-10-20 11:55                     ` Ingo Molnar
2008-10-20 12:20                       ` Ingo Molnar
2008-10-19 21:04                   ` Keith Packard
2008-10-20 11:58                     ` Ingo Molnar
2008-10-20 15:49                       ` Keith Packard
2008-10-22  9:36                         ` Ingo Molnar
2008-10-23  7:14                           ` Keith Packard
2008-10-23  7:14                             ` [PATCH] Add io-mapping functions to dynamically map large device apertures Keith Packard
2008-10-23  7:14                               ` [PATCH] [drm/i915] Use io-mapping interfaces instead of a variety of mapping kludges Keith Packard
2008-10-24  4:49                               ` [PATCH] Add io-mapping functions to dynamically map large device apertures Randy Dunlap
2008-10-24  6:26                                 ` Keith Packard
2008-10-23  8:05                             ` io resources and cached mappings (was: [git pull] drm patches for 2.6.27-rc1) Ingo Molnar
2008-10-23 15:39                               ` Keith Packard
2008-11-03  7:00                                 ` Dave Airlie
2008-11-03 10:48                                   ` Ingo Molnar
2008-11-03 16:36                                   ` Linus Torvalds
2008-11-03 16:53                                     ` Ingo Molnar
2008-11-03 17:29                                       ` [git pull] IO mappings, #2 Ingo Molnar
2008-11-04 22:36                                         ` Jonathan Corbet
2008-11-05  9:01                                           ` Ingo Molnar
2008-10-23 20:22                           ` Adding kmap_atomic_prot_pfn (was: [git pull] drm patches for 2.6.27-rc1) Keith Packard
2008-10-23 20:38                             ` Andrew Morton
2008-10-23 21:03                               ` Keith Packard
2008-10-23 21:24                               ` Linus Torvalds
2008-10-24  1:50                                 ` Keith Packard
2008-10-24  2:48                                   ` Linus Torvalds
2008-10-24  3:24                                     ` Benjamin Herrenschmidt
2008-10-24  5:37                                       ` Keith Packard
2008-10-24 14:53                                         ` Linus Torvalds
2008-10-24 15:45                                           ` Keith Packard
2008-10-24  4:29                                     ` Keith Packard
2008-10-24  6:22                                     ` Keith Packard
2008-10-24  7:33                                       ` Adding kmap_atomic_prot_pfn Thomas Hellström
2008-10-24  8:38                                         ` Ingo Molnar
2008-10-24  9:19                                           ` Thomas Hellström
2008-10-24  9:32                                             ` Ingo Molnar
2008-10-24 11:04                                               ` Thomas Hellström
2008-10-24 15:48                                         ` Keith Packard
2008-10-24 10:18                                           ` Thomas Hellström
2008-10-24  9:14                                     ` Adding kmap_atomic_prot_pfn (was: [git pull] drm patches for 2.6.27-rc1) Ingo Molnar
2008-10-24  3:21                                 ` Benjamin Herrenschmidt
2008-10-20 10:10                   ` io resources and cached mappings " Ingo Molnar
2008-10-19  4:28             ` [git pull] drm patches for 2.6.27-rc1 Yinghai Lu
2008-10-19  3:14       ` Nick Piggin

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=alpine.LFD.2.00.0810171510170.3438@nehalem.linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=airlied@linux.ie \
    --cc=akpm@linux-foundation.org \
    --cc=dri-devel@lists.sf.net \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®