1df8db295SFrançois Tigeot /* 2*d6aa1cc5SFrançois Tigeot * Copyright (c) 2015-2018 François Tigeot <ftigeot@wolfpond.org> 3df8db295SFrançois Tigeot * All rights reserved. 4df8db295SFrançois Tigeot * 5df8db295SFrançois Tigeot * Redistribution and use in source and binary forms, with or without 6df8db295SFrançois Tigeot * modification, are permitted provided that the following conditions 7df8db295SFrançois Tigeot * are met: 8df8db295SFrançois Tigeot * 1. Redistributions of source code must retain the above copyright 9df8db295SFrançois Tigeot * notice unmodified, this list of conditions, and the following 10df8db295SFrançois Tigeot * disclaimer. 11df8db295SFrançois Tigeot * 2. Redistributions in binary form must reproduce the above copyright 12df8db295SFrançois Tigeot * notice, this list of conditions and the following disclaimer in the 13df8db295SFrançois Tigeot * documentation and/or other materials provided with the distribution. 14df8db295SFrançois Tigeot * 15df8db295SFrançois Tigeot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16df8db295SFrançois Tigeot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17df8db295SFrançois Tigeot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18df8db295SFrançois Tigeot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19df8db295SFrançois Tigeot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20df8db295SFrançois Tigeot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21df8db295SFrançois Tigeot * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22df8db295SFrançois Tigeot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23df8db295SFrançois Tigeot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24df8db295SFrançois Tigeot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25df8db295SFrançois Tigeot */ 26df8db295SFrançois Tigeot 27df8db295SFrançois Tigeot #include <drm/drmP.h> 28df8db295SFrançois Tigeot #include <linux/workqueue.h> 29df8db295SFrançois Tigeot 30df8db295SFrançois Tigeot struct workqueue_struct *system_wq; 31df8db295SFrançois Tigeot struct workqueue_struct *system_long_wq; 32591d5043SFrançois Tigeot struct workqueue_struct *system_power_efficient_wq; 3396b26154SFrançois Tigeot struct workqueue_struct *system_unbound_wq; 34df8db295SFrançois Tigeot 35df8db295SFrançois Tigeot static int init_workqueues(void *arg) 36df8db295SFrançois Tigeot { 37df8db295SFrançois Tigeot system_wq = alloc_workqueue("system_wq", 0, 1); 38df8db295SFrançois Tigeot system_long_wq = alloc_workqueue("system_long_wq", 0, 1); 39591d5043SFrançois Tigeot system_power_efficient_wq = alloc_workqueue("system_power_efficient_wq", 0, 1); 4096b26154SFrançois Tigeot system_unbound_wq = alloc_workqueue("system_unbound_wq", 0, 1); 41df8db295SFrançois Tigeot 42df8db295SFrançois Tigeot return 0; 43df8db295SFrançois Tigeot } 44f5e8ad19SImre Vadász 45f5e8ad19SImre Vadász static int destroy_workqueues(void *arg) 46f5e8ad19SImre Vadász { 47f5e8ad19SImre Vadász destroy_workqueue(system_wq); 48f5e8ad19SImre Vadász destroy_workqueue(system_long_wq); 49fd45815cSImre Vadasz destroy_workqueue(system_power_efficient_wq); 5096b26154SFrançois Tigeot destroy_workqueue(system_unbound_wq); 51f5e8ad19SImre Vadász 52f5e8ad19SImre Vadász return 0; 53f5e8ad19SImre Vadász } 54f5e8ad19SImre Vadász 55*d6aa1cc5SFrançois Tigeot struct workqueue_struct * 56*d6aa1cc5SFrançois Tigeot _create_workqueue_common(char *name, int cpus) 57*d6aa1cc5SFrançois Tigeot { 58*d6aa1cc5SFrançois Tigeot struct workqueue_struct *wq; 59*d6aa1cc5SFrançois Tigeot 60*d6aa1cc5SFrançois Tigeot wq = kmalloc(sizeof(*wq), M_DRM, M_WAITOK); 61*d6aa1cc5SFrançois Tigeot wq->taskqueue = taskqueue_create((name), M_WAITOK, 62*d6aa1cc5SFrançois Tigeot taskqueue_thread_enqueue, &wq->taskqueue); 63*d6aa1cc5SFrançois Tigeot taskqueue_start_threads(&wq->taskqueue, cpus, 64*d6aa1cc5SFrançois Tigeot TDPRI_KERN_DAEMON, -1, "%s", name); 65*d6aa1cc5SFrançois Tigeot 66*d6aa1cc5SFrançois Tigeot return (wq); 67*d6aa1cc5SFrançois Tigeot } 68*d6aa1cc5SFrançois Tigeot 69*d6aa1cc5SFrançois Tigeot void 70*d6aa1cc5SFrançois Tigeot destroy_workqueue(struct workqueue_struct *wq) 71*d6aa1cc5SFrançois Tigeot { 72*d6aa1cc5SFrançois Tigeot taskqueue_free(wq->taskqueue); 73*d6aa1cc5SFrançois Tigeot kfree(wq); 74*d6aa1cc5SFrançois Tigeot } 75*d6aa1cc5SFrançois Tigeot 76f5e8ad19SImre Vadász SYSINIT(linux_workqueue_init, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, init_workqueues, NULL); 77f5e8ad19SImre Vadász SYSUNINIT(linux_workqueue_destroy, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, destroy_workqueues, NULL); 78