From owner-svn-src-head@freebsd.org Mon Dec 21 11:59:01 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 1FC97A4DB41; Mon, 21 Dec 2015 11:59:01 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id EEB121B3E; Mon, 21 Dec 2015 11:59:00 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tBLBx06q032116; Mon, 21 Dec 2015 11:59:00 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tBLBwxRb032110; Mon, 21 Dec 2015 11:58:59 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201512211158.tBLBwxRb032110@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 21 Dec 2015 11:58:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r292542 - in head/sys/compat/linuxkpi/common: include/linux src X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Dec 2015 11:59:01 -0000 Author: hselasky Date: Mon Dec 21 11:58:59 2015 New Revision: 292542 URL: https://svnweb.freebsd.org/changeset/base/292542 Log: Minor workqueue cleanup: - Make some functions global instead of inline to ease debugging. - Fix some minor style issues. MFC after: 1 week Sponsored by: Mellanox Technologies Modified: head/sys/compat/linuxkpi/common/include/linux/workqueue.h head/sys/compat/linuxkpi/common/src/linux_compat.c Modified: head/sys/compat/linuxkpi/common/include/linux/workqueue.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/linux/workqueue.h Mon Dec 21 11:50:32 2015 (r292541) +++ head/sys/compat/linuxkpi/common/include/linux/workqueue.h Mon Dec 21 11:58:59 2015 (r292542) @@ -55,6 +55,12 @@ struct delayed_work { struct callout timer; }; +extern void linux_work_fn(void *, int); +extern void linux_flush_fn(void *, int); +extern void linux_delayed_work_fn(void *); +extern struct workqueue_struct *linux_create_workqueue_common(const char *, int); +extern void destroy_workqueue(struct workqueue_struct *); + static inline struct delayed_work * to_delayed_work(struct work_struct *work) { @@ -62,21 +68,11 @@ to_delayed_work(struct work_struct *work return container_of(work, struct delayed_work, work); } - -static inline void -_work_fn(void *context, int pending) -{ - struct work_struct *work; - - work = context; - work->fn(work); -} - #define INIT_WORK(work, func) \ do { \ (work)->fn = (func); \ (work)->taskqueue = NULL; \ - TASK_INIT(&(work)->work_task, 0, _work_fn, (work)); \ + TASK_INIT(&(work)->work_task, 0, linux_work_fn, (work)); \ } while (0) #define INIT_DELAYED_WORK(_work, func) \ @@ -85,7 +81,7 @@ do { \ callout_init(&(_work)->timer, 1); \ } while (0) -#define INIT_DEFERRABLE_WORK INIT_DELAYED_WORK +#define INIT_DEFERRABLE_WORK(...) INIT_DELAYED_WORK(__VA_ARGS__) #define schedule_work(work) \ do { \ @@ -95,20 +91,12 @@ do { \ #define flush_scheduled_work() flush_taskqueue(taskqueue_thread) -static inline int queue_work(struct workqueue_struct *q, struct work_struct *work) -{ - (work)->taskqueue = (q)->taskqueue; - /* Return opposite val to align with Linux logic */ - return !taskqueue_enqueue((q)->taskqueue, &(work)->work_task); -} - -static inline void -_delayed_work_fn(void *arg) +static inline int +queue_work(struct workqueue_struct *wq, struct work_struct *work) { - struct delayed_work *work; - - work = arg; - taskqueue_enqueue(work->work.taskqueue, &work->work.work_task); + work->taskqueue = wq->taskqueue; + /* Return opposite value to align with Linux logic */ + return (!taskqueue_enqueue(wq->taskqueue, &work->work_task)); } static inline int @@ -120,68 +108,44 @@ queue_delayed_work(struct workqueue_stru pending = work->work.work_task.ta_pending; work->work.taskqueue = wq->taskqueue; if (delay != 0) - callout_reset(&work->timer, delay, _delayed_work_fn, work); + callout_reset(&work->timer, delay, linux_delayed_work_fn, work); else - _delayed_work_fn((void *)work); + linux_delayed_work_fn((void *)work); return (!pending); } -static inline bool schedule_delayed_work(struct delayed_work *dwork, - unsigned long delay) -{ - struct workqueue_struct wq; - wq.taskqueue = taskqueue_thread; - return queue_delayed_work(&wq, dwork, delay); -} - -static inline struct workqueue_struct * -_create_workqueue_common(char *name, int cpus) +static inline bool +schedule_delayed_work(struct delayed_work *dwork, + unsigned long delay) { - struct workqueue_struct *wq; - - wq = kmalloc(sizeof(*wq), M_WAITOK); - wq->taskqueue = taskqueue_create((name), M_WAITOK, - taskqueue_thread_enqueue, &wq->taskqueue); - taskqueue_start_threads(&wq->taskqueue, cpus, PWAIT, "%s", name); + struct workqueue_struct wq; - return (wq); + wq.taskqueue = taskqueue_thread; + return (queue_delayed_work(&wq, dwork, delay)); } - #define create_singlethread_workqueue(name) \ - _create_workqueue_common(name, 1) + linux_create_workqueue_common(name, 1) #define create_workqueue(name) \ - _create_workqueue_common(name, MAXCPU) + linux_create_workqueue_common(name, MAXCPU) #define alloc_ordered_workqueue(name, flags) \ - _create_workqueue_common(name, 1) + linux_create_workqueue_common(name, 1) #define alloc_workqueue(name, flags, max_active) \ - _create_workqueue_common(name, max_active) - -static inline void -destroy_workqueue(struct workqueue_struct *wq) -{ - taskqueue_free(wq->taskqueue); - kfree(wq); -} + linux_create_workqueue_common(name, max_active) #define flush_workqueue(wq) flush_taskqueue((wq)->taskqueue) static inline void -_flush_fn(void *context, int pending) -{ -} - -static inline void flush_taskqueue(struct taskqueue *tq) { struct task flushtask; PHOLD(curproc); - TASK_INIT(&flushtask, 0, _flush_fn, NULL); + TASK_INIT(&flushtask, 0, linux_flush_fn, NULL); taskqueue_enqueue(tq, &flushtask); taskqueue_drain(tq, &flushtask); PRELE(curproc); @@ -223,7 +187,7 @@ cancel_delayed_work_sync(struct delayed_ static inline bool mod_delayed_work(struct workqueue_struct *wq, struct delayed_work *dwork, - unsigned long delay) + unsigned long delay) { cancel_delayed_work(dwork); queue_delayed_work(wq, dwork, delay); Modified: head/sys/compat/linuxkpi/common/src/linux_compat.c ============================================================================== --- head/sys/compat/linuxkpi/common/src/linux_compat.c Mon Dec 21 11:50:32 2015 (r292541) +++ head/sys/compat/linuxkpi/common/src/linux_compat.c Mon Dec 21 11:58:59 2015 (r292542) @@ -64,6 +64,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include @@ -913,6 +914,49 @@ linux_completion_done(struct completion return (isdone); } +void +linux_delayed_work_fn(void *arg) +{ + struct delayed_work *work; + + work = arg; + taskqueue_enqueue(work->work.taskqueue, &work->work.work_task); +} + +void +linux_work_fn(void *context, int pending) +{ + struct work_struct *work; + + work = context; + work->fn(work); +} + +void +linux_flush_fn(void *context, int pending) +{ +} + +struct workqueue_struct * +linux_create_workqueue_common(const char *name, int cpus) +{ + struct workqueue_struct *wq; + + wq = kmalloc(sizeof(*wq), M_WAITOK); + wq->taskqueue = taskqueue_create(name, M_WAITOK, + taskqueue_thread_enqueue, &wq->taskqueue); + taskqueue_start_threads(&wq->taskqueue, cpus, PWAIT, "%s", name); + + return (wq); +} + +void +destroy_workqueue(struct workqueue_struct *wq) +{ + taskqueue_free(wq->taskqueue); + kfree(wq); +} + static void linux_compat_init(void *arg) {