Skip to content

Commit f551103

Browse files
author
Kent Overstreet
committed
sched.h: move pid helpers to pid.h
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 <[email protected]>
1 parent 6d5e9d6 commit f551103

File tree

9 files changed

+134
-124
lines changed

9 files changed

+134
-124
lines changed

arch/x86/um/sysrq_64.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <linux/kernel.h>
88
#include <linux/module.h>
9+
#include <linux/pid.h>
910
#include <linux/sched.h>
1011
#include <linux/sched/debug.h>
1112
#include <linux/utsname.h>

drivers/gpu/drm/lima/lima_ctx.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: GPL-2.0 OR MIT
22
/* Copyright 2018-2019 Qiang Yu <[email protected]> */
33

4+
#include <linux/pid.h>
45
#include <linux/slab.h>
56

67
#include "lima_device.h"

drivers/irqchip/irq-gic-v4.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/irq.h>
99
#include <linux/irqdomain.h>
1010
#include <linux/msi.h>
11+
#include <linux/pid.h>
1112
#include <linux/sched.h>
1213

1314
#include <linux/irqchip/arm-gic-v4.h>

include/linux/pid.h

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44

55
#include <linux/pid_types.h>
66
#include <linux/rculist.h>
7+
#include <linux/rcupdate.h>
78
#include <linux/refcount.h>
9+
#include <linux/sched.h>
810
#include <linux/wait.h>
911

1012
/*
@@ -204,4 +206,127 @@ pid_t pid_vnr(struct pid *pid);
204206
} \
205207
task = tg___; \
206208
} while_each_pid_task(pid, type, task)
209+
210+
static inline struct pid *task_pid(struct task_struct *task)
211+
{
212+
return task->thread_pid;
213+
}
214+
215+
/*
216+
* the helpers to get the task's different pids as they are seen
217+
* from various namespaces
218+
*
219+
* task_xid_nr() : global id, i.e. the id seen from the init namespace;
220+
* task_xid_vnr() : virtual id, i.e. the id seen from the pid namespace of
221+
* current.
222+
* task_xid_nr_ns() : id seen from the ns specified;
223+
*
224+
* see also pid_nr() etc in include/linux/pid.h
225+
*/
226+
pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type, struct pid_namespace *ns);
227+
228+
static inline pid_t task_pid_nr(struct task_struct *tsk)
229+
{
230+
return tsk->pid;
231+
}
232+
233+
static inline pid_t task_pid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
234+
{
235+
return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns);
236+
}
237+
238+
static inline pid_t task_pid_vnr(struct task_struct *tsk)
239+
{
240+
return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
241+
}
242+
243+
244+
static inline pid_t task_tgid_nr(struct task_struct *tsk)
245+
{
246+
return tsk->tgid;
247+
}
248+
249+
/**
250+
* pid_alive - check that a task structure is not stale
251+
* @p: Task structure to be checked.
252+
*
253+
* Test if a process is not yet dead (at most zombie state)
254+
* If pid_alive fails, then pointers within the task structure
255+
* can be stale and must not be dereferenced.
256+
*
257+
* Return: 1 if the process is alive. 0 otherwise.
258+
*/
259+
static inline int pid_alive(const struct task_struct *p)
260+
{
261+
return p->thread_pid != NULL;
262+
}
263+
264+
static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
265+
{
266+
return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns);
267+
}
268+
269+
static inline pid_t task_pgrp_vnr(struct task_struct *tsk)
270+
{
271+
return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL);
272+
}
273+
274+
275+
static inline pid_t task_session_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
276+
{
277+
return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns);
278+
}
279+
280+
static inline pid_t task_session_vnr(struct task_struct *tsk)
281+
{
282+
return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL);
283+
}
284+
285+
static inline pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
286+
{
287+
return __task_pid_nr_ns(tsk, PIDTYPE_TGID, ns);
288+
}
289+
290+
static inline pid_t task_tgid_vnr(struct task_struct *tsk)
291+
{
292+
return __task_pid_nr_ns(tsk, PIDTYPE_TGID, NULL);
293+
}
294+
295+
static inline pid_t task_ppid_nr_ns(const struct task_struct *tsk, struct pid_namespace *ns)
296+
{
297+
pid_t pid = 0;
298+
299+
rcu_read_lock();
300+
if (pid_alive(tsk))
301+
pid = task_tgid_nr_ns(rcu_dereference(tsk->real_parent), ns);
302+
rcu_read_unlock();
303+
304+
return pid;
305+
}
306+
307+
static inline pid_t task_ppid_nr(const struct task_struct *tsk)
308+
{
309+
return task_ppid_nr_ns(tsk, &init_pid_ns);
310+
}
311+
312+
/* Obsolete, do not use: */
313+
static inline pid_t task_pgrp_nr(struct task_struct *tsk)
314+
{
315+
return task_pgrp_nr_ns(tsk, &init_pid_ns);
316+
}
317+
318+
/**
319+
* is_global_init - check if a task structure is init. Since init
320+
* is free to have sub-threads we need to check tgid.
321+
* @tsk: Task structure to be checked.
322+
*
323+
* Check if a task structure is the first user space task the kernel created.
324+
*
325+
* Return: 1 if the task structure is init. 0 otherwise.
326+
*/
327+
static inline int is_global_init(struct task_struct *tsk)
328+
{
329+
return task_tgid_nr(tsk) == 1;
330+
}
331+
207332
#endif /* _LINUX_PID_H */

include/linux/sched.h

Lines changed: 0 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,114 +1561,6 @@ struct task_struct {
15611561
*/
15621562
};
15631563

1564-
static inline struct pid *task_pid(struct task_struct *task)
1565-
{
1566-
return task->thread_pid;
1567-
}
1568-
1569-
/*
1570-
* the helpers to get the task's different pids as they are seen
1571-
* from various namespaces
1572-
*
1573-
* task_xid_nr() : global id, i.e. the id seen from the init namespace;
1574-
* task_xid_vnr() : virtual id, i.e. the id seen from the pid namespace of
1575-
* current.
1576-
* task_xid_nr_ns() : id seen from the ns specified;
1577-
*
1578-
* see also pid_nr() etc in include/linux/pid.h
1579-
*/
1580-
pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type, struct pid_namespace *ns);
1581-
1582-
static inline pid_t task_pid_nr(struct task_struct *tsk)
1583-
{
1584-
return tsk->pid;
1585-
}
1586-
1587-
static inline pid_t task_pid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
1588-
{
1589-
return __task_pid_nr_ns(tsk, PIDTYPE_PID, ns);
1590-
}
1591-
1592-
static inline pid_t task_pid_vnr(struct task_struct *tsk)
1593-
{
1594-
return __task_pid_nr_ns(tsk, PIDTYPE_PID, NULL);
1595-
}
1596-
1597-
1598-
static inline pid_t task_tgid_nr(struct task_struct *tsk)
1599-
{
1600-
return tsk->tgid;
1601-
}
1602-
1603-
/**
1604-
* pid_alive - check that a task structure is not stale
1605-
* @p: Task structure to be checked.
1606-
*
1607-
* Test if a process is not yet dead (at most zombie state)
1608-
* If pid_alive fails, then pointers within the task structure
1609-
* can be stale and must not be dereferenced.
1610-
*
1611-
* Return: 1 if the process is alive. 0 otherwise.
1612-
*/
1613-
static inline int pid_alive(const struct task_struct *p)
1614-
{
1615-
return p->thread_pid != NULL;
1616-
}
1617-
1618-
static inline pid_t task_pgrp_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
1619-
{
1620-
return __task_pid_nr_ns(tsk, PIDTYPE_PGID, ns);
1621-
}
1622-
1623-
static inline pid_t task_pgrp_vnr(struct task_struct *tsk)
1624-
{
1625-
return __task_pid_nr_ns(tsk, PIDTYPE_PGID, NULL);
1626-
}
1627-
1628-
1629-
static inline pid_t task_session_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
1630-
{
1631-
return __task_pid_nr_ns(tsk, PIDTYPE_SID, ns);
1632-
}
1633-
1634-
static inline pid_t task_session_vnr(struct task_struct *tsk)
1635-
{
1636-
return __task_pid_nr_ns(tsk, PIDTYPE_SID, NULL);
1637-
}
1638-
1639-
static inline pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
1640-
{
1641-
return __task_pid_nr_ns(tsk, PIDTYPE_TGID, ns);
1642-
}
1643-
1644-
static inline pid_t task_tgid_vnr(struct task_struct *tsk)
1645-
{
1646-
return __task_pid_nr_ns(tsk, PIDTYPE_TGID, NULL);
1647-
}
1648-
1649-
static inline pid_t task_ppid_nr_ns(const struct task_struct *tsk, struct pid_namespace *ns)
1650-
{
1651-
pid_t pid = 0;
1652-
1653-
rcu_read_lock();
1654-
if (pid_alive(tsk))
1655-
pid = task_tgid_nr_ns(rcu_dereference(tsk->real_parent), ns);
1656-
rcu_read_unlock();
1657-
1658-
return pid;
1659-
}
1660-
1661-
static inline pid_t task_ppid_nr(const struct task_struct *tsk)
1662-
{
1663-
return task_ppid_nr_ns(tsk, &init_pid_ns);
1664-
}
1665-
1666-
/* Obsolete, do not use: */
1667-
static inline pid_t task_pgrp_nr(struct task_struct *tsk)
1668-
{
1669-
return task_pgrp_nr_ns(tsk, &init_pid_ns);
1670-
}
1671-
16721564
#define TASK_REPORT_IDLE (TASK_REPORT + 1)
16731565
#define TASK_REPORT_MAX (TASK_REPORT_IDLE << 1)
16741566

@@ -1712,20 +1604,6 @@ static inline char task_state_to_char(struct task_struct *tsk)
17121604
return task_index_to_char(task_state_index(tsk));
17131605
}
17141606

1715-
/**
1716-
* is_global_init - check if a task structure is init. Since init
1717-
* is free to have sub-threads we need to check tgid.
1718-
* @tsk: Task structure to be checked.
1719-
*
1720-
* Check if a task structure is the first user space task the kernel created.
1721-
*
1722-
* Return: 1 if the task structure is init. 0 otherwise.
1723-
*/
1724-
static inline int is_global_init(struct task_struct *tsk)
1725-
{
1726-
return task_tgid_nr(tsk) == 1;
1727-
}
1728-
17291607
extern struct pid *cad_pid;
17301608

17311609
/*

include/linux/sched/signal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <linux/sched/task.h>
1010
#include <linux/cred.h>
1111
#include <linux/refcount.h>
12+
#include <linux/pid.h>
1213
#include <linux/posix-timers.h>
1314
#include <linux/mm_types.h>
1415
#include <asm/ptrace.h>

ipc/util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/unistd.h>
1515
#include <linux/err.h>
1616
#include <linux/ipc_namespace.h>
17+
#include <linux/pid.h>
1718

1819
/*
1920
* The IPC ID contains 2 separate numbers - index and sequence number.

kernel/async.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ asynchronous and synchronous parts of the kernel.
4646

4747
#include <linux/async.h>
4848
#include <linux/atomic.h>
49-
#include <linux/ktime.h>
5049
#include <linux/export.h>
51-
#include <linux/wait.h>
50+
#include <linux/ktime.h>
51+
#include <linux/pid.h>
5252
#include <linux/sched.h>
5353
#include <linux/slab.h>
54+
#include <linux/wait.h>
5455
#include <linux/workqueue.h>
5556

5657
#include "workqueue_internal.h"

kernel/locking/spinlock_debug.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/debug_locks.h>
1313
#include <linux/delay.h>
1414
#include <linux/export.h>
15+
#include <linux/pid.h>
1516

1617
void __raw_spin_lock_init(raw_spinlock_t *lock, const char *name,
1718
struct lock_class_key *key, short inner)

0 commit comments

Comments
 (0)