All of lore.kernel.org
 help / color / mirror / Atom feed
From: "J. Bruce Fields" <bfields@fieldses.org>
To: Tejun Heo <tj@kernel.org>
Cc: "J. Bruce Fields" <bfields@redhat.com>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	"open list:NFS, SUNRPC, AND..." <linux-nfs@vger.kernel.org>,
	Jeff Layton <jlayton@redhat.com>,
	David Howells <dhowells@redhat.com>, Shaohua Li <shli@fb.com>,
	Oleg Nesterov <oleg@redhat.com>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 0/4] allow multiple kthreadd's
Date: Wed, 6 May 2020 11:36:58 -0400	[thread overview]
Message-ID: <20200506153658.GA21307@fieldses.org> (raw)
In-Reply-To: <20200505212527.GA1265@fieldses.org>

On Tue, May 05, 2020 at 05:25:27PM -0400, J. Bruce Fields wrote:
> On Tue, May 05, 2020 at 05:09:56PM -0400, Tejun Heo wrote:
> > It's not the end of the world but a bit hacky. I wonder whether something
> > like the following would work better for identifying worker type so that you
> > can do sth like
> > 
> >  if (kthread_fn(current) == nfsd)
> >         return kthread_data(current);
> >  else
> >         return NULL;     
> 
> Yes, definitely more generic, looks good to me.

This is what I'm testing with.

If it's OK with you, could I add your Signed-off-by and take it through
the nfsd tree? I'll have some other patches that will depend on it.

--b.


commit 379bfe5257b6
Author: Tejun Heo <tj@kernel.org>
Date:   Tue May 5 21:26:07 2020 -0400

    kthread: save thread function
    
    It's handy to keep the kthread_fn just as a unique cookie to identify
    classes of kthreads.  E.g. if you can verify that a given task is
    running your thread_fn, then you may know what sort of type kthread_data
    points to.
    
    We'll use this in nfsd to pass some information into the vfs.  Note it
    will need kthread_data() exported too.
    
    Signed-off-by: J. Bruce Fields <bfields@redhat.com>

diff --git a/include/linux/kthread.h b/include/linux/kthread.h
index 8bbcaad7ef0f..c00ee443833f 100644
--- a/include/linux/kthread.h
+++ b/include/linux/kthread.h
@@ -57,6 +57,7 @@ bool kthread_should_stop(void);
 bool kthread_should_park(void);
 bool __kthread_should_park(struct task_struct *k);
 bool kthread_freezable_should_stop(bool *was_frozen);
+void *kthread_fn(struct task_struct *k);
 void *kthread_data(struct task_struct *k);
 void *kthread_probe_data(struct task_struct *k);
 int kthread_park(struct task_struct *k);
diff --git a/kernel/kthread.c b/kernel/kthread.c
index bfbfa481be3a..b87c4a9ba91d 100644
--- a/kernel/kthread.c
+++ b/kernel/kthread.c
@@ -46,6 +46,7 @@ struct kthread_create_info
 struct kthread {
 	unsigned long flags;
 	unsigned int cpu;
+	int (*threadfn)(void *);
 	void *data;
 	struct completion parked;
 	struct completion exited;
@@ -152,6 +153,20 @@ bool kthread_freezable_should_stop(bool *was_frozen)
 }
 EXPORT_SYMBOL_GPL(kthread_freezable_should_stop);
 
+/**
+ * kthread_fn - return the function specified on kthread creation
+ * @task: kthread task in question
+ *
+ * Returns NULL if the task is not a kthread.
+ */
+void *kthread_fn(struct task_struct *task)
+{
+	if (task->flags & PF_KTHREAD)
+		return to_kthread(task)->threadfn;
+	return NULL;
+}
+EXPORT_SYMBOL_GPL(kthread_fn);
+
 /**
  * kthread_data - return data value specified on kthread creation
  * @task: kthread task in question
@@ -164,6 +179,7 @@ void *kthread_data(struct task_struct *task)
 {
 	return to_kthread(task)->data;
 }
+EXPORT_SYMBOL_GPL(kthread_data);
 
 /**
  * kthread_probe_data - speculative version of kthread_data()
@@ -244,6 +260,7 @@ static int kthread(void *_create)
 		do_exit(-ENOMEM);
 	}
 
+	self->threadfn = threadfn;
 	self->data = data;
 	init_completion(&self->exited);
 	init_completion(&self->parked);

  reply	other threads:[~2020-05-06 15:37 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-01 16:01 [PATCH 0/4] allow multiple kthreadd's J. Bruce Fields
2020-05-01 16:01 ` [PATCH 1/4] kthreads: minor kthreadd refactoring J. Bruce Fields
2020-05-01 16:01 ` [PATCH 2/4] kthreads: Simplify tsk_fork_get_node J. Bruce Fields
2020-05-01 16:01 ` [PATCH 3/4] kthreads: allow multiple kthreadd's J. Bruce Fields
2020-05-01 16:01 ` [PATCH 4/4] kthreads: allow cloning threads with different flags J. Bruce Fields
2020-05-01 17:59 ` [PATCH 0/4] allow multiple kthreadd's Linus Torvalds
2020-05-01 18:21   ` Tejun Heo
2020-05-01 18:30     ` Linus Torvalds
2020-05-01 19:02       ` J. Bruce Fields
2020-05-01 18:49     ` J. Bruce Fields
2020-05-01 19:05       ` Trond Myklebust
2020-05-01 19:20         ` tj
2020-05-01 19:22         ` J. Bruce Fields
2020-05-05  2:15     ` J. Bruce Fields
2020-05-05 15:54       ` Tejun Heo
2020-05-05 16:23         ` J. Bruce Fields
2020-05-05 21:01       ` J. Bruce Fields
2020-05-05 21:09         ` Tejun Heo
2020-05-05 21:25           ` J. Bruce Fields
2020-05-06 15:36             ` J. Bruce Fields [this message]
2020-05-06 15:39               ` Tejun Heo
2020-05-06 15:54                 ` J. Bruce Fields

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=20200506153658.GA21307@fieldses.org \
    --to=bfields@fieldses.org \
    --cc=bfields@redhat.com \
    --cc=dhowells@redhat.com \
    --cc=jlayton@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=oleg@redhat.com \
    --cc=shli@fb.com \
    --cc=tj@kernel.org \
    --cc=torvalds@linux-foundation.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 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.