/* * linux/drivers/video/fb_defio.c * * Copyright (C) 2006 Jaya Kumar * * This file is subject to the terms and conditions of the GNU General Public * License. See the file COPYING in the main directory of this archive * for more details.
*/
pageref = fb_deferred_io_pageref_lookup(info, offset, page); if (!pageref) return NULL;
/* * This check is to catch the case where a new process could start * writing to the same page through a new PTE. This new access * can cause a call to .page_mkwrite even if the original process' * PTE is marked writable.
*/ if (!list_empty(&pageref->list)) goto pageref_already_added;
if (unlikely(fbdefio->sort_pagereflist)) { /* * We loop through the list of pagerefs before adding in * order to keep the pagerefs sorted. This has significant * overhead of O(n^2) with n being the number of written * pages. If possible, drivers should try to work with * unsorted page lists instead.
*/
list_for_each_entry(cur, &fbdefio->pagereflist, list) { if (cur->offset > pageref->offset) break;
}
pos = &cur->list;
}
/* * Adds a page to the dirty list. Call this from struct * vm_operations_struct.page_mkwrite.
*/ static vm_fault_t fb_deferred_io_track_page(struct fb_info *info, unsignedlong offset, struct page *page)
{ struct fb_deferred_io *fbdefio = info->fbdefio; struct fb_deferred_io_pageref *pageref;
vm_fault_t ret;
/* protect against the workqueue changing the page list */
mutex_lock(&fbdefio->lock);
pageref = fb_deferred_io_pageref_get(info, offset, page); if (WARN_ON_ONCE(!pageref)) {
ret = VM_FAULT_OOM; goto err_mutex_unlock;
}
/* * We want the page to remain locked from ->page_mkwrite until * the PTE is marked dirty to avoid mapping_wrprotect_range() * being called before the PTE is updated, which would leave * the page ignored by defio. * Do this by locking the page here and informing the caller * about it with VM_FAULT_LOCKED.
*/
lock_page(pageref->page);
mutex_unlock(&fbdefio->lock);
/* come back after delay to process the deferred IO */
schedule_delayed_work(&info->deferred_work, fbdefio->delay); return VM_FAULT_LOCKED;
/* * fb_deferred_io_page_mkwrite - Mark a page as written for deferred I/O * @fb_info: The fbdev info structure * @vmf: The VM fault * * This is a callback we get when userspace first tries to * write to the page. We schedule a workqueue. That workqueue * will eventually mkclean the touched pages and execute the * deferred framebuffer IO. Then if userspace touches a page * again, we repeat the same scheme. * * Returns: * VM_FAULT_LOCKED on success, or a VM_FAULT error otherwise.
*/ static vm_fault_t fb_deferred_io_page_mkwrite(struct fb_info *info, struct vm_fault *vmf)
{ unsignedlong offset = vmf->pgoff << PAGE_SHIFT; struct page *page = vmf->page;
/* driver's callback with pagereflist */
fbdefio->deferred_io(info, &fbdefio->pagereflist);
/* clear the list */
list_for_each_entry_safe(pageref, next, &fbdefio->pagereflist, list)
fb_deferred_io_pageref_put(pageref, info);
mutex_unlock(&fbdefio->lock);
}
int fb_deferred_io_init(struct fb_info *info)
{ struct fb_deferred_io *fbdefio = info->fbdefio; struct fb_deferred_io_pageref *pagerefs; unsignedlong npagerefs; int ret;
BUG_ON(!fbdefio);
if (WARN_ON(!info->fix.smem_len)) return -EINVAL;
mutex_init(&fbdefio->lock);
INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
INIT_LIST_HEAD(&fbdefio->pagereflist); if (fbdefio->delay == 0) /* set a default of 1 s */
fbdefio->delay = HZ;
/* alloc a page ref for each page of the display memory */
pagerefs = kvcalloc(npagerefs, sizeof(*pagerefs), GFP_KERNEL); if (!pagerefs) {
ret = -ENOMEM; goto err;
}
info->npagerefs = npagerefs;
info->pagerefs = pagerefs;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.