From: Lyude Paul <lyude@redhat.com>
To: nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Cc: "Daniel Vetter" <daniel@ffwll.ch>, "Tejun Heo" <tj@kernel.org>,
"Ville Syrjälä" <ville.syrjala@linux.intel.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Petr Mladek" <pmladek@suse.com>,
"Suren Baghdasaryan" <surenb@google.com>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Liang Chen" <cl@rock-chips.com>,
"Ben Dooks" <ben.dooks@codethink.co.uk>,
"Thomas Gleixner" <tglx@linutronix.de>
Subject: [RFC v4 02/12] kthread: Add kthread_(un)block_work_queuing() and kthread_work_queuable()
Date: Fri, 8 May 2020 16:46:52 -0400 [thread overview]
Message-ID: <20200508204751.155488-3-lyude@redhat.com> (raw)
In-Reply-To: <20200508204751.155488-1-lyude@redhat.com>
Add some simple wrappers around incrementing/decrementing
kthread_work.cancelling under lock, along with checking whether queuing
is currently allowed on a given kthread_work, which we'll use want to
implement work cancelling with DRM's vblank work helpers.
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Tejun Heo <tj@kernel.org>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: dri-devel@lists.freedesktop.org
Cc: nouveau@lists.freedesktop.org
Signed-off-by: Lyude Paul <lyude@redhat.com>
---
include/linux/kthread.h | 19 +++++++++++++++++
kernel/kthread.c | 46 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+)
diff --git a/include/linux/kthread.h b/include/linux/kthread.h
index 0006540ce7f9..c6fee200fced 100644
--- a/include/linux/kthread.h
+++ b/include/linux/kthread.h
@@ -211,9 +211,28 @@ void kthread_flush_worker(struct kthread_worker *worker);
bool kthread_cancel_work_sync(struct kthread_work *work);
bool kthread_cancel_delayed_work_sync(struct kthread_delayed_work *work);
+void kthread_block_work_queuing(struct kthread_worker *worker,
+ struct kthread_work *work);
+void kthread_unblock_work_queuing(struct kthread_worker *worker,
+ struct kthread_work *work);
void kthread_destroy_worker(struct kthread_worker *worker);
+/**
+ * kthread_work_queuable - whether or not a kthread work can be queued
+ * @work: The kthread work to check
+ *
+ * Checks whether or not queuing @work is currently blocked from queuing,
+ * either by kthread_cancel_work_sync() and friends or
+ * kthread_block_work_queuing().
+ *
+ * Returns: whether or not the @work may be queued.
+ */
+static inline bool kthread_work_queuable(struct kthread_work *work)
+{
+ return READ_ONCE(work->canceling) == 0;
+}
+
struct cgroup_subsys_state;
#ifdef CONFIG_BLK_CGROUP
diff --git a/kernel/kthread.c b/kernel/kthread.c
index c1f8ec9d5836..f8a5c5a87cc6 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -1187,6 +1187,52 @@ bool kthread_cancel_delayed_work_sync(struct kthread_delayed_work *dwork)
}
EXPORT_SYMBOL_GPL(kthread_cancel_delayed_work_sync);
+/**
+ * kthread_block_work_queuing - prevent a kthread_work from being queued
+ * without actually cancelling it
+ * @worker: kthread worker to use
+ * @work: work to block queuing on
+ *
+ * Prevents @work from being queued using kthread_queue_work() and friends,
+ * but doesn't attempt to cancel any previous queuing. The caller must unblock
+ * queuing later by calling kthread_unblock_work_queuing(). This call can be
+ * called multiple times.
+ *
+ * See also: kthread_work_queuable()
+ */
+void kthread_block_work_queuing(struct kthread_worker *worker,
+ struct kthread_work *work)
+{
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(&worker->lock, flags);
+ work->canceling++;
+ raw_spin_unlock_irqrestore(&worker->lock, flags);
+}
+EXPORT_SYMBOL_GPL(kthread_block_work_queuing);
+
+/**
+ * kthread_unblock_work_queuing - unblock queuing on a kthread_work
+ * @worker: kthread worker to use
+ * @work: work to unblock queuing on
+ *
+ * Removes a request to prevent @work from being queued with
+ * kthread_queue_work() and friends, so that it may potentially be queued
+ * again.
+ *
+ * See also: kthread_work_queuable()
+ */
+void kthread_unblock_work_queuing(struct kthread_worker *worker,
+ struct kthread_work *work)
+{
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(&worker->lock, flags);
+ WARN_ON_ONCE(--work->canceling < 0);
+ raw_spin_unlock_irqrestore(&worker->lock, flags);
+}
+EXPORT_SYMBOL_GPL(kthread_unblock_work_queuing);
+
/**
* kthread_flush_worker - flush all current works on a kthread_worker
* @worker: worker to flush
--
2.25.4
WARNING: multiple messages have this Message-ID (diff)
From: Lyude Paul <lyude@redhat.com>
To: nouveau@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org
Cc: Petr Mladek <pmladek@suse.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Ben Dooks <ben.dooks@codethink.co.uk>,
Liang Chen <cl@rock-chips.com>,
Johannes Weiner <hannes@cmpxchg.org>, Tejun Heo <tj@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Suren Baghdasaryan <surenb@google.com>,
Thomas Gleixner <tglx@linutronix.de>
Subject: [RFC v4 02/12] kthread: Add kthread_(un)block_work_queuing() and kthread_work_queuable()
Date: Fri, 8 May 2020 16:46:52 -0400 [thread overview]
Message-ID: <20200508204751.155488-3-lyude@redhat.com> (raw)
In-Reply-To: <20200508204751.155488-1-lyude@redhat.com>
Add some simple wrappers around incrementing/decrementing
kthread_work.cancelling under lock, along with checking whether queuing
is currently allowed on a given kthread_work, which we'll use want to
implement work cancelling with DRM's vblank work helpers.
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Tejun Heo <tj@kernel.org>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: dri-devel@lists.freedesktop.org
Cc: nouveau@lists.freedesktop.org
Signed-off-by: Lyude Paul <lyude@redhat.com>
---
include/linux/kthread.h | 19 +++++++++++++++++
kernel/kthread.c | 46 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+)
diff --git a/include/linux/kthread.h b/include/linux/kthread.h
index 0006540ce7f9..c6fee200fced 100644
--- a/include/linux/kthread.h
+++ b/include/linux/kthread.h
@@ -211,9 +211,28 @@ void kthread_flush_worker(struct kthread_worker *worker);
bool kthread_cancel_work_sync(struct kthread_work *work);
bool kthread_cancel_delayed_work_sync(struct kthread_delayed_work *work);
+void kthread_block_work_queuing(struct kthread_worker *worker,
+ struct kthread_work *work);
+void kthread_unblock_work_queuing(struct kthread_worker *worker,
+ struct kthread_work *work);
void kthread_destroy_worker(struct kthread_worker *worker);
+/**
+ * kthread_work_queuable - whether or not a kthread work can be queued
+ * @work: The kthread work to check
+ *
+ * Checks whether or not queuing @work is currently blocked from queuing,
+ * either by kthread_cancel_work_sync() and friends or
+ * kthread_block_work_queuing().
+ *
+ * Returns: whether or not the @work may be queued.
+ */
+static inline bool kthread_work_queuable(struct kthread_work *work)
+{
+ return READ_ONCE(work->canceling) == 0;
+}
+
struct cgroup_subsys_state;
#ifdef CONFIG_BLK_CGROUP
diff --git a/kernel/kthread.c b/kernel/kthread.c
index c1f8ec9d5836..f8a5c5a87cc6 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -1187,6 +1187,52 @@ bool kthread_cancel_delayed_work_sync(struct kthread_delayed_work *dwork)
}
EXPORT_SYMBOL_GPL(kthread_cancel_delayed_work_sync);
+/**
+ * kthread_block_work_queuing - prevent a kthread_work from being queued
+ * without actually cancelling it
+ * @worker: kthread worker to use
+ * @work: work to block queuing on
+ *
+ * Prevents @work from being queued using kthread_queue_work() and friends,
+ * but doesn't attempt to cancel any previous queuing. The caller must unblock
+ * queuing later by calling kthread_unblock_work_queuing(). This call can be
+ * called multiple times.
+ *
+ * See also: kthread_work_queuable()
+ */
+void kthread_block_work_queuing(struct kthread_worker *worker,
+ struct kthread_work *work)
+{
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(&worker->lock, flags);
+ work->canceling++;
+ raw_spin_unlock_irqrestore(&worker->lock, flags);
+}
+EXPORT_SYMBOL_GPL(kthread_block_work_queuing);
+
+/**
+ * kthread_unblock_work_queuing - unblock queuing on a kthread_work
+ * @worker: kthread worker to use
+ * @work: work to unblock queuing on
+ *
+ * Removes a request to prevent @work from being queued with
+ * kthread_queue_work() and friends, so that it may potentially be queued
+ * again.
+ *
+ * See also: kthread_work_queuable()
+ */
+void kthread_unblock_work_queuing(struct kthread_worker *worker,
+ struct kthread_work *work)
+{
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(&worker->lock, flags);
+ WARN_ON_ONCE(--work->canceling < 0);
+ raw_spin_unlock_irqrestore(&worker->lock, flags);
+}
+EXPORT_SYMBOL_GPL(kthread_unblock_work_queuing);
+
/**
* kthread_flush_worker - flush all current works on a kthread_worker
* @worker: worker to flush
--
2.25.4
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel
next prev parent reply other threads:[~2020-05-08 20:46 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-08 20:46 [RFC v4 00/12] drm/nouveau: Introduce CRC support for gf119+ Lyude Paul
2020-05-08 20:46 ` Lyude Paul
2020-05-08 20:46 ` Lyude Paul
2020-05-08 20:46 ` [RFC v4 01/12] kthread: Add kthread_queue_flush_work() Lyude Paul
2020-05-08 20:46 ` Lyude Paul
2020-05-09 16:31 ` kbuild test robot
2020-05-11 14:49 ` Tejun Heo
2020-05-11 14:49 ` Tejun Heo
2020-05-11 15:02 ` Daniel Vetter
2020-05-11 15:02 ` Daniel Vetter
2020-05-08 20:46 ` Lyude Paul [this message]
2020-05-08 20:46 ` [RFC v4 02/12] kthread: Add kthread_(un)block_work_queuing() and kthread_work_queuable() Lyude Paul
2020-05-11 15:02 ` Tejun Heo
2020-05-11 15:02 ` Tejun Heo
[not found] ` <20200508204751.155488-3-lyude-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2020-05-14 15:07 ` William Lewis
2020-05-08 20:46 ` [RFC v4 03/12] drm/vblank: Register drmm cleanup action once per drm_vblank_crtc Lyude Paul
2020-05-08 20:46 ` Lyude Paul
2020-05-08 20:59 ` Daniel Vetter
2020-05-08 20:59 ` Daniel Vetter
2020-05-08 20:46 ` [RFC v4 04/12] drm/vblank: Add vblank works Lyude Paul
2020-05-08 20:46 ` Lyude Paul
2020-05-10 3:03 ` kbuild test robot
2020-05-12 17:56 ` Nick Desaulniers
2020-05-08 20:46 ` [RFC v4 06/12] drm/nouveau/kms/nv140-: Don't modify depth in state during atomic commit Lyude Paul
2020-05-08 20:46 ` Lyude Paul
2020-05-08 20:46 ` [RFC v4 07/12] drm/nouveau/kms/nv50-: Fix disabling dithering Lyude Paul
2020-05-08 20:46 ` Lyude Paul
2020-05-08 20:46 ` [RFC v4 08/12] drm/nouveau/kms/nv50-: s/harm/armh/g Lyude Paul
2020-05-08 20:46 ` Lyude Paul
[not found] ` <20200508204751.155488-1-lyude-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2020-05-08 20:46 ` [RFC v4 05/12] drm/nouveau/kms/nv50-: Unroll error cleanup in nv50_head_create() Lyude Paul
2020-05-08 20:46 ` Lyude Paul
2020-05-08 20:46 ` Lyude Paul
2020-05-08 20:46 ` [RFC v4 09/12] drm/nouveau/kms/nv140-: Track wndw mappings in nv50_head_atom Lyude Paul
2020-05-08 20:46 ` Lyude Paul
2020-05-08 20:46 ` Lyude Paul
2020-05-08 20:47 ` [RFC v4 10/12] drm/nouveau/kms/nv50-: Expose nv50_outp_atom in disp.h Lyude Paul
2020-05-08 20:47 ` Lyude Paul
2020-05-08 20:47 ` Lyude Paul
2020-05-08 20:47 ` [RFC v4 12/12] drm/nouveau/kms/nvd9-: Add CRC support Lyude Paul
2020-05-08 20:47 ` Lyude Paul
2020-05-08 20:47 ` Lyude Paul
2020-05-08 20:47 ` [RFC v4 11/12] drm/nouveau/kms/nv50-: Move hard-coded object handles into header Lyude Paul
2020-05-08 20:47 ` Lyude Paul
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200508204751.155488-3-lyude@redhat.com \
--to=lyude@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=ben.dooks@codethink.co.uk \
--cc=cl@rock-chips.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=gregkh@linuxfoundation.org \
--cc=hannes@cmpxchg.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nouveau@lists.freedesktop.org \
--cc=pmladek@suse.com \
--cc=surenb@google.com \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=ville.syrjala@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.