linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: qiang.zhang@windriver.com
To: pmladek@suse.com, tj@kernel.org
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH] kthread_worker: Add flush delayed work func
Date: Wed, 11 Nov 2020 17:13:55 +0800	[thread overview]
Message-ID: <20201111091355.19476-1-qiang.zhang@windriver.com> (raw)

From: Zqiang <qiang.zhang@windriver.com>

Add 'kthread_flush_delayed_work' func, the principle of
this func is wait for a dwork to finish executing the
last queueing.

Signed-off-by: Zqiang <qiang.zhang@windriver.com>
---
 kernel/kthread.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/kernel/kthread.c b/kernel/kthread.c
index a5eceecd4513..1afe399ccd02 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -1045,6 +1045,30 @@ void kthread_flush_work(struct kthread_work *work)
 }
 EXPORT_SYMBOL_GPL(kthread_flush_work);
 
+/*
+ * kthread_flush_delayed_work - flush a kthread_delayed_work
+ * @dwork: dwork to flush
+ *
+ * wait for a dwork to finish executing the last queueing
+ */
+void kthread_flush_delayed_work(struct kthread_delayed_work *dwork)
+{
+	struct kthread_work *work = &dwork->work;
+	struct kthread_worker *worker = work->worker;
+	unsigned long flags;
+
+	if (del_timer_sync(&dwork->timer)) {
+		raw_spin_lock_irqsave(&worker->lock, flags);
+		list_del_init(&work->node);
+		if (!work->canceling)
+			kthread_insert_work(worker, work, &worker->work_list);
+
+		raw_spin_unlock_irqrestore(&worker->lock, flags);
+	}
+	kthread_flush_work(work);
+}
+EXPORT_SYMBOL_GPL(kthread_flush_delayed_work);
+
 /*
  * This function removes the work from the worker queue. Also it makes sure
  * that it won't get queued later via the delayed work's timer.
-- 
2.17.1



             reply	other threads:[~2020-11-11  9:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-11  9:13 qiang.zhang [this message]
2020-11-13  0:01 ` [PATCH] kthread_worker: Add flush delayed work func Andrew Morton
2020-11-13  8:59   ` 回复: " Zhang, Qiang
2020-11-13 10:24     ` Petr Mladek
2020-11-16 16:23 ` Christoph Hellwig

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=20201111091355.19476-1-qiang.zhang@windriver.com \
    --to=qiang.zhang@windriver.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=pmladek@suse.com \
    --cc=tj@kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).