From: Kent Overstreet <kent.overstreet@linux.dev>
To: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
linux-fsdevel@vger.kernel.org
Cc: Kent Overstreet <kent.overstreet@linux.dev>,
tglx@linutronix.de, x86@kernel.org, tj@kernel.org,
peterz@infradead.org, mathieu.desnoyers@efficios.com,
paulmck@kernel.org, keescook@chromium.org,
dave.hansen@linux.intel.com, mingo@redhat.com, will@kernel.org,
longman@redhat.com, boqun.feng@gmail.com, brauner@kernel.org
Subject: [PATCH 23/50] sched.h: move pid helpers to pid.h
Date: Fri, 15 Dec 2023 22:29:29 -0500 [thread overview]
Message-ID: <20231216032957.3553313-2-kent.overstreet@linux.dev> (raw)
In-Reply-To: <20231216032957.3553313-1-kent.overstreet@linux.dev>
This is needed for killing the sched.h dependency on rcupdate.h, and
pid.h is a better place for this code anyways.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
---
include/linux/pid.h | 125 +++++++++++++++++++++++++++++++++++
include/linux/sched.h | 122 ----------------------------------
include/linux/sched/signal.h | 1 +
3 files changed, 126 insertions(+), 122 deletions(-)
diff --git a/include/linux/pid.h b/include/linux/pid.h
index f254c3a45b9b..395cacce1179 100644
--- a/include/linux/pid.h
+++ b/include/linux/pid.h
@@ -4,7 +4,9 @@
#include <linux/pid_types.h>
#include <linux/rculist.h>
+#include <linux/rcupdate.h>
#include <linux/refcount.h>
+#include <linux/sched.h>
#include <linux/wait.h>
/*
@@ -204,4 +206,127 @@ pid_t pid_vnr(struct pid *pid);
} \
task = tg___; \
} while_each_pid_task(pid, type, task)
+
+static inline struct pid *task_pid(struct task_struct *task)
+{
+ return task->thread_pid;
+}
+
+/*
+ * the helpers to get the task's different pids as they are seen
+ * from various namespaces
+ *
+ * task_xid_nr() : global id, i.e. the id seen from the init namespace;
+ * task_xid_vnr() : virtual id, i.e. the id seen from the pid namespace of
+ * current.
+ * task_xid_nr_ns() : id seen from the ns specified;
+ *
+ * see also pid_nr() etc in include/linux/pid.h
+ */
+pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type, struct pid_namespace *ns);
+
+static inline pid_t task_pid_nr(struct task_struct *tsk)
+{
+ return tsk->pid;
+}
+
+static inline pid_t task_pid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
+{
+ return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns);
+}
+
+static inline pid_t task_pid_vnr(struct task_struct *tsk)
+{
+ return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
+}
+
+
+static inline pid_t task_tgid_nr(struct task_struct *tsk)
+{
+ return tsk->tgid;
+}
+
+/**
+ * pid_alive - check that a task structure is not stale
+ * @p: Task structure to be checked.
+ *
+ * Test if a process is not yet dead (at most zombie state)
+ * If pid_alive fails, then pointers within the task structure
+ * can be stale and must not be dereferenced.
+ *
+ * Return: 1 if the process is alive. 0 otherwise.
+ */
+static inline int pid_alive(const struct task_struct *p)
+{
+ return p->thread_pid != NULL;
+}
+
+static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
+{
+ return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns);
+}
+
+static inline pid_t task_pgrp_vnr(struct task_struct *tsk)
+{
+ return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL);
+}
+
+
+static inline pid_t task_session_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
+{
+ return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns);
+}
+
+static inline pid_t task_session_vnr(struct task_struct *tsk)
+{
+ return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL);
+}
+
+static inline pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
+{
+ return __task_pid_nr_ns(tsk, PIDTYPE_TGID, ns);
+}
+
+static inline pid_t task_tgid_vnr(struct task_struct *tsk)
+{
+ return __task_pid_nr_ns(tsk, PIDTYPE_TGID, NULL);
+}
+
+static inline pid_t task_ppid_nr_ns(const struct task_struct *tsk, struct pid_namespace *ns)
+{
+ pid_t pid = 0;
+
+ rcu_read_lock();
+ if (pid_alive(tsk))
+ pid = task_tgid_nr_ns(rcu_dereference(tsk->real_parent), ns);
+ rcu_read_unlock();
+
+ return pid;
+}
+
+static inline pid_t task_ppid_nr(const struct task_struct *tsk)
+{
+ return task_ppid_nr_ns(tsk, &init_pid_ns);
+}
+
+/* Obsolete, do not use: */
+static inline pid_t task_pgrp_nr(struct task_struct *tsk)
+{
+ return task_pgrp_nr_ns(tsk, &init_pid_ns);
+}
+
+/**
+ * is_global_init - check if a task structure is init. Since init
+ * is free to have sub-threads we need to check tgid.
+ * @tsk: Task structure to be checked.
+ *
+ * Check if a task structure is the first user space task the kernel created.
+ *
+ * Return: 1 if the task structure is init. 0 otherwise.
+ */
+static inline int is_global_init(struct task_struct *tsk)
+{
+ return task_tgid_nr(tsk) == 1;
+}
+
#endif /* _LINUX_PID_H */
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 37cc9d257073..9e2708c2cfa6 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1561,114 +1561,6 @@ struct task_struct {
*/
};
-static inline struct pid *task_pid(struct task_struct *task)
-{
- return task->thread_pid;
-}
-
-/*
- * the helpers to get the task's different pids as they are seen
- * from various namespaces
- *
- * task_xid_nr() : global id, i.e. the id seen from the init namespace;
- * task_xid_vnr() : virtual id, i.e. the id seen from the pid namespace of
- * current.
- * task_xid_nr_ns() : id seen from the ns specified;
- *
- * see also pid_nr() etc in include/linux/pid.h
- */
-pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type, struct pid_namespace *ns);
-
-static inline pid_t task_pid_nr(struct task_struct *tsk)
-{
- return tsk->pid;
-}
-
-static inline pid_t task_pid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
-{
- return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns);
-}
-
-static inline pid_t task_pid_vnr(struct task_struct *tsk)
-{
- return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
-}
-
-
-static inline pid_t task_tgid_nr(struct task_struct *tsk)
-{
- return tsk->tgid;
-}
-
-/**
- * pid_alive - check that a task structure is not stale
- * @p: Task structure to be checked.
- *
- * Test if a process is not yet dead (at most zombie state)
- * If pid_alive fails, then pointers within the task structure
- * can be stale and must not be dereferenced.
- *
- * Return: 1 if the process is alive. 0 otherwise.
- */
-static inline int pid_alive(const struct task_struct *p)
-{
- return p->thread_pid != NULL;
-}
-
-static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
-{
- return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns);
-}
-
-static inline pid_t task_pgrp_vnr(struct task_struct *tsk)
-{
- return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL);
-}
-
-
-static inline pid_t task_session_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
-{
- return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns);
-}
-
-static inline pid_t task_session_vnr(struct task_struct *tsk)
-{
- return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL);
-}
-
-static inline pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
-{
- return __task_pid_nr_ns(tsk, PIDTYPE_TGID, ns);
-}
-
-static inline pid_t task_tgid_vnr(struct task_struct *tsk)
-{
- return __task_pid_nr_ns(tsk, PIDTYPE_TGID, NULL);
-}
-
-static inline pid_t task_ppid_nr_ns(const struct task_struct *tsk, struct pid_namespace *ns)
-{
- pid_t pid = 0;
-
- rcu_read_lock();
- if (pid_alive(tsk))
- pid = task_tgid_nr_ns(rcu_dereference(tsk->real_parent), ns);
- rcu_read_unlock();
-
- return pid;
-}
-
-static inline pid_t task_ppid_nr(const struct task_struct *tsk)
-{
- return task_ppid_nr_ns(tsk, &init_pid_ns);
-}
-
-/* Obsolete, do not use: */
-static inline pid_t task_pgrp_nr(struct task_struct *tsk)
-{
- return task_pgrp_nr_ns(tsk, &init_pid_ns);
-}
-
#define TASK_REPORT_IDLE (TASK_REPORT + 1)
#define TASK_REPORT_MAX (TASK_REPORT_IDLE << 1)
@@ -1712,20 +1604,6 @@ static inline char task_state_to_char(struct task_struct *tsk)
return task_index_to_char(task_state_index(tsk));
}
-/**
- * is_global_init - check if a task structure is init. Since init
- * is free to have sub-threads we need to check tgid.
- * @tsk: Task structure to be checked.
- *
- * Check if a task structure is the first user space task the kernel created.
- *
- * Return: 1 if the task structure is init. 0 otherwise.
- */
-static inline int is_global_init(struct task_struct *tsk)
-{
- return task_tgid_nr(tsk) == 1;
-}
-
extern struct pid *cad_pid;
/*
diff --git a/include/linux/sched/signal.h b/include/linux/sched/signal.h
index 3499c1a8b929..b847d8fa75a9 100644
--- a/include/linux/sched/signal.h
+++ b/include/linux/sched/signal.h
@@ -9,6 +9,7 @@
#include <linux/sched/task.h>
#include <linux/cred.h>
#include <linux/refcount.h>
+#include <linux/pid.h>
#include <linux/posix-timers.h>
#include <linux/mm_types.h>
#include <asm/ptrace.h>
--
2.43.0
next prev parent reply other threads:[~2023-12-16 3:30 UTC|newest]
Thread overview: 96+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-16 2:47 [PATCH 00/50] big header dependency cleanup targeting sched.h Kent Overstreet
2023-12-16 2:47 ` [PATCH 01/50] drivers/gpu/drm/i915/i915_memcpy.c: fix missing includes Kent Overstreet
2024-03-08 13:46 ` Jani Nikula
2023-12-16 2:47 ` [PATCH 02/50] x86/kernel/fpu/bugs.c: fix missing include Kent Overstreet
2023-12-18 11:08 ` Sohil Mehta
2023-12-19 2:05 ` Kent Overstreet
2023-12-16 2:47 ` [PATCH 03/50] x86/lib/cache-smp.c: " Kent Overstreet
2023-12-18 10:48 ` Sohil Mehta
2023-12-19 2:06 ` Kent Overstreet
2023-12-19 4:04 ` Sohil Mehta
2023-12-16 2:47 ` [PATCH 04/50] x86/include/asm/debugreg.h: " Kent Overstreet
2023-12-16 2:47 ` [PATCH 05/50] x86/include/asm/paravirt_types.h: " Kent Overstreet
2023-12-16 2:47 ` [PATCH 06/50] task_stack.h: add " Kent Overstreet
2023-12-16 2:47 ` [PATCH 07/50] nsproxy.h: " Kent Overstreet
2023-12-16 2:47 ` [PATCH 08/50] kernel/fork.c: " Kent Overstreet
2023-12-16 2:47 ` [PATCH 09/50] kmsan: add missing types.h dependency Kent Overstreet
2023-12-16 2:47 ` [PATCH 10/50] time_namespace.h: fix missing include Kent Overstreet
2023-12-16 3:26 ` [PATCH 11/50] nodemask: Split out include/linux/nodemask_types.h Kent Overstreet
2023-12-16 3:26 ` [PATCH 12/50] prandom: Remove unused include Kent Overstreet
2023-12-16 18:52 ` Randy Dunlap
2023-12-16 22:19 ` Kent Overstreet
2023-12-16 3:26 ` [PATCH 13/50] timekeeping: Kill percpu.h dependency Kent Overstreet
2023-12-16 3:26 ` [PATCH 14/50] arm64: Fix circular header dependency Kent Overstreet
2023-12-16 3:26 ` [PATCH 15/50] kernel/numa.c: Move logging out of numa.h Kent Overstreet
2023-12-19 16:36 ` Nathan Chancellor
2023-12-19 21:02 ` Kent Overstreet
2023-12-19 22:52 ` Matthew Wilcox
2023-12-20 0:37 ` Kent Overstreet
2023-12-16 3:26 ` [PATCH 16/50] sched.h: Move (spin|rwlock)_needbreak() to spinlock.h Kent Overstreet
2024-01-15 20:31 ` Leonardo Bras
2023-12-16 3:26 ` [PATCH 17/50] ktime.h: move ktime_t to types.h Kent Overstreet
2023-12-16 3:26 ` [PATCH 18/50] hrtimers: Split out hrtimer_types.h Kent Overstreet
2023-12-16 3:26 ` [PATCH 19/50] locking/mutex: split out mutex_types.h Kent Overstreet
2023-12-18 16:53 ` Waiman Long
2023-12-18 18:12 ` Waiman Long
2023-12-19 1:46 ` Kent Overstreet
2023-12-19 3:04 ` Waiman Long
2023-12-19 3:37 ` Kent Overstreet
2023-12-19 3:39 ` Waiman Long
2023-12-16 3:26 ` [PATCH 20/50] posix-cpu-timers: Split out posix-timers_types.h Kent Overstreet
2023-12-16 3:26 ` [PATCH 21/50] locking/seqlock: Split out seqlock_types.h Kent Overstreet
2023-12-18 17:02 ` Waiman Long
2023-12-16 3:29 ` [PATCH 22/50] pid: Split out pid_types.h Kent Overstreet
2023-12-16 3:29 ` Kent Overstreet [this message]
2023-12-16 3:29 ` [PATCH 24/50] plist: Split out plist_types.h Kent Overstreet
2023-12-16 3:29 ` [PATCH 25/50] wait: Remove uapi header file from main header file Kent Overstreet
2023-12-18 12:39 ` Christian Brauner
2023-12-16 3:29 ` [PATCH 26/50] rslib: kill bogus dependency on list.h Kent Overstreet
2023-12-16 19:05 ` Randy Dunlap
2023-12-16 19:09 ` Kent Overstreet
2023-12-16 19:10 ` Randy Dunlap
2023-12-16 3:29 ` [PATCH 27/50] timerqueue: Split out timerqueue_types.h Kent Overstreet
2023-12-16 3:29 ` [PATCH 28/50] signal: Kill bogus dependency on list.h Kent Overstreet
2023-12-16 3:29 ` [PATCH 29/50] timers: Split out timer_types.h Kent Overstreet
2023-12-16 3:29 ` [PATCH 30/50] workqueue: Split out workqueue_types.h Kent Overstreet
2023-12-16 3:29 ` [PATCH 31/50] shm: Slim down dependencies Kent Overstreet
2023-12-16 3:29 ` [PATCH 32/50] ipc: Kill bogus dependency on spinlock.h Kent Overstreet
2023-12-18 11:04 ` [PATCH 22/50] pid: Split out pid_types.h Christian Brauner
2023-12-16 3:32 ` [PATCH 33/50] Split out irqflags_types.h Kent Overstreet
2023-12-16 3:32 ` [PATCH 34/50] mm_types_task.h: Trim dependencies Kent Overstreet
2023-12-16 3:32 ` [PATCH 35/50] cpumask: Split out cpumask_types.h Kent Overstreet
2023-12-16 3:32 ` [PATCH 36/50] syscall_user_dispatch.h: split out *_types.h Kent Overstreet
2023-12-16 3:32 ` [PATCH 37/50] x86/signal: kill dependency on time.h Kent Overstreet
2023-12-16 3:32 ` [PATCH 38/50] uapi/linux/resource.h: fix include Kent Overstreet
2023-12-16 3:32 ` [PATCH 39/50] refcount: Split out refcount_types.h Kent Overstreet
2023-12-16 3:32 ` [PATCH 40/50] seccomp: Split out seccomp_types.h Kent Overstreet
2023-12-16 3:32 ` [PATCH 41/50] uidgid: Split out uidgid_types.h Kent Overstreet
2023-12-18 11:01 ` Christian Brauner
2023-12-16 3:32 ` [PATCH 42/50] sem: Split out sem_types.h Kent Overstreet
2023-12-20 11:53 ` Geert Uytterhoeven
2023-12-20 21:39 ` Kent Overstreet
2024-01-02 8:47 ` Geert Uytterhoeven
2023-12-16 3:32 ` [PATCH 43/50] lockdep: move held_lock to lockdep_types.h Kent Overstreet
2023-12-18 17:05 ` Waiman Long
2023-12-16 3:35 ` [PATCH 44/50] restart_block: Trim includes Kent Overstreet
2023-12-16 3:35 ` [PATCH 45/50] rseq: Split out rseq.h from sched.h Kent Overstreet
2023-12-16 3:35 ` [PATCH 46/50] preempt.h: Kill dependency on list.h Kent Overstreet
2023-12-16 6:13 ` Matthew Wilcox
2023-12-16 19:21 ` Randy Dunlap
2023-12-16 22:35 ` Kent Overstreet
2023-12-17 0:04 ` Randy Dunlap
2023-12-17 0:18 ` Matthew Wilcox
2023-12-17 0:20 ` Kent Overstreet
2023-12-17 2:03 ` Randy Dunlap
2023-12-17 2:05 ` Kent Overstreet
2023-12-17 0:18 ` Kent Overstreet
2023-12-17 0:26 ` Randy Dunlap
2023-12-16 3:35 ` [PATCH 47/50] thread_info, uaccess.h: Move HARDENED_USERCOPY to better location Kent Overstreet
2023-12-16 3:35 ` [PATCH 48/50] Kill unnecessary kernel.h include Kent Overstreet
2023-12-16 3:35 ` [PATCH 49/50] kill unnecessary thread_info.h include Kent Overstreet
2023-12-16 3:35 ` [PATCH 50/50] Kill sched.h dependency on rcupdate.h Kent Overstreet
2023-12-16 19:35 ` Paul E. McKenney
2023-12-16 22:20 ` Kent Overstreet
2023-12-20 11:59 ` Geert Uytterhoeven
2023-12-20 21:39 ` Kent Overstreet
2024-01-02 11:39 ` Geert Uytterhoeven
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=20231216032957.3553313-2-kent.overstreet@linux.dev \
--to=kent.overstreet@linux.dev \
--cc=boqun.feng@gmail.com \
--cc=brauner@kernel.org \
--cc=dave.hansen@linux.intel.com \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=longman@redhat.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@redhat.com \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=will@kernel.org \
--cc=x86@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