Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Move linux_work.c and workqueue.h from sys/external/bsd/...
details: https://anonhg.NetBSD.org/src/rev/9996b68a0c67
branches: trunk
changeset: 343753:9996b68a0c67
user: skrll <skrll%NetBSD.org@localhost>
date: Wed Feb 24 22:04:15 2016 +0000
description:
Move linux_work.c and workqueue.h from sys/external/bsd/drm2 to
sys/external/common so that they can be used by others.
LGTM from riastradh@
These should really live outside sys/external, but that can be decided
later
diffstat:
sys/conf/files | 5 +-
sys/external/bsd/common/include/linux/workqueue.h | 120 +++
sys/external/bsd/common/linux/linux_work.c | 858 ++++++++++++++++++++++
sys/external/bsd/drm2/drm/files.drmkms | 4 +-
sys/external/bsd/drm2/include/linux/workqueue.h | 120 ---
sys/external/bsd/drm2/linux/files.drmkms_linux | 3 +-
sys/external/bsd/drm2/linux/linux_work.c | 858 ----------------------
sys/modules/drmkms_linux/Makefile | 9 +-
8 files changed, 993 insertions(+), 984 deletions(-)
diffs (truncated from 2045 to 300 lines):
diff -r 369ad51d53cd -r 9996b68a0c67 sys/conf/files
--- a/sys/conf/files Wed Feb 24 21:11:34 2016 +0000
+++ b/sys/conf/files Wed Feb 24 22:04:15 2016 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files,v 1.1152 2015/12/09 18:25:32 maxv Exp $
+# $NetBSD: files,v 1.1153 2016/02/24 22:04:15 skrll Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
version 20150846
@@ -1146,6 +1146,9 @@
include "external/bsd/drm/conf/files.drm"
include "dev/drm/files.drm"
+# Linux API support
+include "external/bsd/common/conf/files.linux"
+
# DRM/KMS - Newer direct rendering manager with kernel mode-switching
include "external/bsd/drm2/drm/files.drmkms"
diff -r 369ad51d53cd -r 9996b68a0c67 sys/external/bsd/common/include/linux/workqueue.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/external/bsd/common/include/linux/workqueue.h Wed Feb 24 22:04:15 2016 +0000
@@ -0,0 +1,120 @@
+/* $NetBSD: workqueue.h,v 1.1 2016/02/24 22:04:15 skrll Exp $ */
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_WORKQUEUE_H_
+#define _LINUX_WORKQUEUE_H_
+
+#include <sys/types.h>
+#include <sys/callout.h>
+#include <sys/queue.h>
+#include <sys/workqueue.h>
+
+#include <linux/kernel.h>
+
+#define INIT_DELAYED_WORK linux_INIT_DELAYED_WORK
+#define INIT_WORK linux_INIT_WORK
+#define alloc_ordered_workqueue linux_alloc_ordered_workqueue
+#define cancel_delayed_work linux_cancel_delayed_work
+#define cancel_delayed_work_sync linux_cancel_delayed_work_sync
+#define cancel_work linux_cancel_work
+#define cancel_work_sync linux_cancel_work_sync
+#define destroy_workqueue linux_destroy_workqueue
+#define flush_work linux_flush_work
+#define flush_workqueue linux_flush_workqueue
+#define queue_delayed_work linux_queue_delayed_work
+#define mod_delayed_work linux_mod_delayed_work
+#define queue_work linux_queue_work
+#define schedule_delayed_work linux_schedule_delayed_work
+#define schedule_work linux_schedule_work
+#define system_wq linux_system_wq
+#define to_delayed_work linux_to_delayed_work
+
+struct workqueue_struct;
+
+struct work_struct {
+ struct work w_wk;
+ __cpu_simple_lock_t w_lock; /* XXX */
+ enum {
+ WORK_IDLE,
+ WORK_DELAYED,
+ WORK_PENDING,
+ WORK_INVOKED,
+ WORK_CANCELLED,
+ WORK_DELAYED_CANCELLED,
+ } w_state;
+ struct workqueue_struct *w_wq;
+ void (*w_fn)(struct work_struct *);
+};
+
+struct delayed_work {
+ /* Not dw_work; name must match Linux. */
+ struct work_struct work;
+ struct callout dw_callout;
+ TAILQ_ENTRY(delayed_work) dw_entry;
+};
+
+static inline struct delayed_work *
+to_delayed_work(struct work_struct *work)
+{
+ return container_of(work, struct delayed_work, work);
+}
+
+extern struct workqueue_struct *system_wq;
+
+int linux_workqueue_init(void);
+void linux_workqueue_fini(void);
+
+#define create_singlethread_workqueue(name) \
+ alloc_ordered_workqueue((name), 0)
+
+struct workqueue_struct *
+ alloc_ordered_workqueue(const char *, int);
+void destroy_workqueue(struct workqueue_struct *);
+void flush_workqueue(struct workqueue_struct *);
+void flush_scheduled_work(void);
+
+void INIT_WORK(struct work_struct *, void (*)(struct work_struct *));
+bool schedule_work(struct work_struct *);
+bool queue_work(struct workqueue_struct *, struct work_struct *);
+bool cancel_work_sync(struct work_struct *);
+void flush_work(struct work_struct *);
+
+void INIT_DELAYED_WORK(struct delayed_work *,
+ void (*)(struct work_struct *));
+bool schedule_delayed_work(struct delayed_work *, unsigned long);
+bool queue_delayed_work(struct workqueue_struct *, struct delayed_work *,
+ unsigned long ticks);
+bool mod_delayed_work(struct workqueue_struct *, struct delayed_work *,
+ unsigned long ticks);
+bool cancel_delayed_work(struct delayed_work *);
+bool cancel_delayed_work_sync(struct delayed_work *);
+
+#endif /* _LINUX_WORKQUEUE_H_ */
diff -r 369ad51d53cd -r 9996b68a0c67 sys/external/bsd/common/linux/linux_work.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/external/bsd/common/linux/linux_work.c Wed Feb 24 22:04:15 2016 +0000
@@ -0,0 +1,858 @@
+/* $NetBSD: linux_work.c,v 1.1 2016/02/24 22:04:15 skrll Exp $ */
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Taylor R. Campbell.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: linux_work.c,v 1.1 2016/02/24 22:04:15 skrll Exp $");
+
+#include <sys/types.h>
+#include <sys/param.h>
+#include <sys/atomic.h>
+#include <sys/callout.h>
+#include <sys/condvar.h>
+#include <sys/errno.h>
+#include <sys/intr.h>
+#include <sys/kmem.h>
+#include <sys/mutex.h>
+#include <sys/queue.h>
+#include <sys/systm.h>
+#include <sys/workqueue.h>
+#include <sys/cpu.h>
+
+#include <machine/lock.h>
+
+#include <linux/workqueue.h>
+
+/* XXX Kludge until we sync with HEAD. */
+#if DIAGNOSTIC
+#define __diagused
+#else
+#define __diagused __unused
+#endif
+
+struct workqueue_struct {
+ struct workqueue *wq_workqueue;
+
+ /* XXX The following should all be per-CPU. */
+ kmutex_t wq_lock;
+
+ /*
+ * Condvar for when any state related to this workqueue
+ * changes. XXX Could split this into multiple condvars for
+ * different purposes, but whatever...
+ */
+ kcondvar_t wq_cv;
+
+ TAILQ_HEAD(, delayed_work) wq_delayed;
+ struct work_struct *wq_current_work;
+};
+
+static void linux_work_lock_init(struct work_struct *);
+static void linux_work_lock(struct work_struct *);
+static void linux_work_unlock(struct work_struct *);
+static bool linux_work_locked(struct work_struct *) __diagused;
+
+static void linux_wq_barrier(struct work_struct *);
+
+static void linux_wait_for_cancelled_work(struct work_struct *);
+static void linux_wait_for_invoked_work(struct work_struct *);
+static void linux_worker(struct work *, void *);
+
+static void linux_cancel_delayed_work_callout(struct delayed_work *, bool);
+static void linux_wait_for_delayed_cancelled_work(struct delayed_work *);
+static void linux_worker_intr(void *);
+
+struct workqueue_struct *system_wq;
+
+int
+linux_workqueue_init(void)
+{
+
+ system_wq = alloc_ordered_workqueue("lnxsyswq", 0);
+ if (system_wq == NULL)
+ return ENOMEM;
+
+ return 0;
+}
+
+void
+linux_workqueue_fini(void)
+{
+ destroy_workqueue(system_wq);
+ system_wq = NULL;
+}
+
+/*
+ * Workqueues
+ */
+
+struct workqueue_struct *
+alloc_ordered_workqueue(const char *name, int linux_flags)
+{
+ struct workqueue_struct *wq;
+ int flags = WQ_MPSAFE;
+ int error;
+
+ KASSERT(linux_flags == 0);
+
+ wq = kmem_alloc(sizeof(*wq), KM_SLEEP);
+ error = workqueue_create(&wq->wq_workqueue, name, &linux_worker,
+ wq, PRI_NONE, IPL_VM, flags);
+ if (error) {
+ kmem_free(wq, sizeof(*wq));
+ return NULL;
+ }
+
+ mutex_init(&wq->wq_lock, MUTEX_DEFAULT, IPL_VM);
+ cv_init(&wq->wq_cv, name);
+ TAILQ_INIT(&wq->wq_delayed);
+ wq->wq_current_work = NULL;
+
+ return wq;
+}
+
+void
+destroy_workqueue(struct workqueue_struct *wq)
+{
+
+ /*
+ * Cancel all delayed work.
+ */
+ for (;;) {
+ struct delayed_work *dw;
+
+ mutex_enter(&wq->wq_lock);
+ if (TAILQ_EMPTY(&wq->wq_delayed)) {
+ dw = NULL;
Home |
Main Index |
Thread Index |
Old Index