Skip to content

Commit 88d5196

Browse files
Alan HourihaneDave Jones
authored andcommitted
[PATCH] AGP performance fixes
AGP allocation/deallocation is suffering major performance issues due to the nature of global_flush_tlb() being called on every change_page_attr() call. For small allocations this isn't really seen, but when you start allocating 50000 pages of AGP space, for say, texture memory, then things can take seconds to complete. In some cases the situation is doubled or even quadrupled in the time due to SMP, or a deallocation, then a new reallocation. I've had a case of upto 20 seconds wait time to deallocate and reallocate AGP space. This patch fixes the problem by making it the caller's responsibility to call global_flush_tlb(), and so removes it from every instance of mapping a page into AGP space until the time that all change_page_attr() changes are done. Signed-off-by: Dave Jones <davej@redhat.com> Signed-off-by: Andrew Morton <akpm@osdl.org>
1 parent 329f7db commit 88d5196

4 files changed

Lines changed: 25 additions & 9 deletions

File tree

‎drivers/char/agp/backend.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ static int agp_backend_initialize(struct agp_bridge_data *bridge)
147147
printk(KERN_ERR PFX "unable to get memory for scratch page.\n");
148148
return -ENOMEM;
149149
}
150+
global_flush_tlb();
150151

151152
bridge->scratch_page_real = virt_to_gart(addr);
152153
bridge->scratch_page =
@@ -187,9 +188,11 @@ static int agp_backend_initialize(struct agp_bridge_data *bridge)
187188
return 0;
188189

189190
err_out:
190-
if (bridge->driver->needs_scratch_page)
191+
if (bridge->driver->needs_scratch_page) {
191192
bridge->driver->agp_destroy_page(
192193
gart_to_virt(bridge->scratch_page_real));
194+
global_flush_tlb();
195+
}
193196
if (got_gatt)
194197
bridge->driver->free_gatt_table(bridge);
195198
if (got_keylist) {
@@ -211,9 +214,11 @@ static void agp_backend_cleanup(struct agp_bridge_data *bridge)
211214
bridge->key_list = NULL;
212215

213216
if (bridge->driver->agp_destroy_page &&
214-
bridge->driver->needs_scratch_page)
217+
bridge->driver->needs_scratch_page) {
215218
bridge->driver->agp_destroy_page(
216219
gart_to_virt(bridge->scratch_page_real));
220+
global_flush_tlb();
221+
}
217222
}
218223

219224
/* When we remove the global variable agp_bridge from all drivers

‎drivers/char/agp/generic.c‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ int map_page_into_agp(struct page *page)
5757
{
5858
int i;
5959
i = change_page_attr(page, 1, PAGE_KERNEL_NOCACHE);
60-
global_flush_tlb();
60+
/* Caller's responsibility to call global_flush_tlb() for
61+
* performance reasons */
6162
return i;
6263
}
6364
EXPORT_SYMBOL_GPL(map_page_into_agp);
@@ -66,7 +67,8 @@ int unmap_page_from_agp(struct page *page)
6667
{
6768
int i;
6869
i = change_page_attr(page, 1, PAGE_KERNEL);
69-
global_flush_tlb();
70+
/* Caller's responsibility to call global_flush_tlb() for
71+
* performance reasons */
7072
return i;
7173
}
7274
EXPORT_SYMBOL_GPL(unmap_page_from_agp);
@@ -153,6 +155,7 @@ void agp_free_memory(struct agp_memory *curr)
153155
for (i = 0; i < curr->page_count; i++) {
154156
curr->bridge->driver->agp_destroy_page(gart_to_virt(curr->memory[i]));
155157
}
158+
global_flush_tlb();
156159
}
157160
agp_free_key(curr->key);
158161
vfree(curr->memory);
@@ -210,7 +213,9 @@ struct agp_memory *agp_allocate_memory(struct agp_bridge_data *bridge,
210213
new->memory[i] = virt_to_gart(addr);
211214
new->page_count++;
212215
}
213-
new->bridge = bridge;
216+
global_flush_tlb();
217+
218+
new->bridge = bridge;
214219

215220
flush_agp_mappings();
216221

‎drivers/char/agp/i460-agp.c‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -514,9 +514,10 @@ static void *i460_alloc_page (struct agp_bridge_data *bridge)
514514
{
515515
void *page;
516516

517-
if (I460_IO_PAGE_SHIFT <= PAGE_SHIFT)
517+
if (I460_IO_PAGE_SHIFT <= PAGE_SHIFT) {
518518
page = agp_generic_alloc_page(agp_bridge);
519-
else
519+
global_flush_tlb();
520+
} else
520521
/* Returning NULL would cause problems */
521522
/* AK: really dubious code. */
522523
page = (void *)~0UL;
@@ -525,8 +526,10 @@ static void *i460_alloc_page (struct agp_bridge_data *bridge)
525526

526527
static void i460_destroy_page (void *page)
527528
{
528-
if (I460_IO_PAGE_SHIFT <= PAGE_SHIFT)
529+
if (I460_IO_PAGE_SHIFT <= PAGE_SHIFT) {
529530
agp_generic_destroy_page(page);
531+
global_flush_tlb();
532+
}
530533
}
531534

532535
#endif /* I460_LARGE_IO_PAGES */

‎drivers/char/agp/intel-agp.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ static struct agp_memory *alloc_agpphysmem_i8xx(size_t pg_count, int type)
270270

271271
switch (pg_count) {
272272
case 1: addr = agp_bridge->driver->agp_alloc_page(agp_bridge);
273+
global_flush_tlb();
273274
break;
274275
case 4:
275276
/* kludge to get 4 physical pages for ARGB cursor */
@@ -330,9 +331,11 @@ static void intel_i810_free_by_type(struct agp_memory *curr)
330331
if(curr->type == AGP_PHYS_MEMORY) {
331332
if (curr->page_count == 4)
332333
i8xx_destroy_pages(gart_to_virt(curr->memory[0]));
333-
else
334+
else {
334335
agp_bridge->driver->agp_destroy_page(
335336
gart_to_virt(curr->memory[0]));
337+
global_flush_tlb();
338+
}
336339
vfree(curr->memory);
337340
}
338341
kfree(curr);

0 commit comments

Comments
 (0)