xf86-video-intel: src/sna/kgem.c

Chris Wilson ickle at kemper.freedesktop.org
Wed Jul 17 02:31:01 PDT 2013


 src/sna/kgem.c |   37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

New commits:
commit 7f76a2bf319f59d463a1f96974b03d7c651847dd
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date:   Wed Jul 17 10:22:17 2013 +0100

    sna: Fall back to /proc/cpuinfo parsing if cpuid cache size probe fails
    
    Older hardware does not support cache size probing via cpuid4, so we
    need to implement the older algorithm which requires a table based
    lookup. (And in hindsight, why I thought cache probing via cpuid to be
    quite hairy.) For the moment, just use the value found in /proc/cpuinfo.
    
    Reported-by: Oscar Dario Trujillo Tejada <oscardt19 at gmail.com>
    Reported-by: Ferry Toth <ftoth at telfort.nl>
    Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>

diff --git a/src/sna/kgem.c b/src/sna/kgem.c
index 605e049..0054cdf 100644
--- a/src/sna/kgem.c
+++ b/src/sna/kgem.c
@@ -698,7 +698,7 @@ total_ram_size(void)
 }
 
 static unsigned
-cpu_cache_size(void)
+cpu_cache_size__cpuid4(void)
 {
 	/* Deterministic Cache Parmaeters (Function 04h)":
 	 *    When EAX is initialized to a value of 4, the CPUID instruction
@@ -740,6 +740,39 @@ cpu_cache_size(void)
 	 return llc_size;
 }
 
+static unsigned
+cpu_cache_size(void)
+{
+	unsigned size;
+	FILE *file;
+
+	size = cpu_cache_size__cpuid4();
+	if (size)
+		return size;
+
+	file = fopen("/proc/cpuinfo", "r");
+	if (file) {
+		size_t len = 0;
+		char *line = NULL;
+		while (getline(&line, &len, file) != -1) {
+			int kb;
+			if (sscanf(line, "cache size : %d KB", &kb) == 1) {
+				/* Paranoid check against gargantuan caches */
+				if (kb <= 1<<20)
+					size = kb * 1024;
+				break;
+			}
+		}
+		free(line);
+		fclose(file);
+	}
+
+	if (size == 0)
+		size = 64 * 1024;
+
+	return size;
+}
+
 static int gem_param(struct kgem *kgem, int name)
 {
 	drm_i915_getparam_t gp;
@@ -1242,6 +1275,7 @@ void kgem_init(struct kgem *kgem, int fd, struct pci_device *dev, unsigned gen)
 		kgem->buffer_size = kgem->half_cpu_cache_pages << 12;
 	DBG(("%s: buffer size=%d [%d KiB]\n", __FUNCTION__,
 	     kgem->buffer_size, kgem->buffer_size / 1024));
+	assert(kgem->buffer_size);
 
 	kgem->max_object_size = 3 * (kgem->aperture_high >> 12) << 10;
 	kgem->max_gpu_size = kgem->max_object_size;
@@ -5616,6 +5650,7 @@ struct kgem_bo *kgem_create_buffer(struct kgem *kgem,
 		alloc = ALIGN(size, kgem->buffer_size);
 	if (alloc > MAX_CACHE_SIZE)
 		alloc = PAGE_ALIGN(size);
+	assert(alloc);
 
 	if (alloc > kgem->aperture_mappable / 4)
 		flags &= ~KGEM_BUFFER_INPLACE;


More information about the xorg-commit mailing list