Skip to content

Commit 6883f81

Browse files
committed
pid: Implement PIDTYPE_TGID
Everywhere except in the pid array we distinguish between a tasks pid and a tasks tgid (thread group id). Even in the enumeration we want that distinction sometimes so we have added __PIDTYPE_TGID. With leader_pid we almost have an implementation of PIDTYPE_TGID in struct signal_struct. Add PIDTYPE_TGID as a first class member of the pid_type enumeration and into the pids array. Then remove the __PIDTYPE_TGID special case and the leader_pid in signal_struct. The net size increase is just an extra pointer added to struct pid and an extra pair of pointers of an hlist_node added to task_struct. The effect on code maintenance is the removal of a number of special cases today and the potential to remove many more special cases as PIDTYPE_TGID gets used to it's fullest. The long term potential is allowing zombie thread group leaders to exit, which will remove a lot more special cases in the code. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
1 parent 2c47047 commit 6883f81

14 files changed

Lines changed: 19 additions & 19 deletions

File tree

‎arch/ia64/kernel/asm-offsets.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void foo(void)
6767
DEFINE(IA64_SIGNAL_GROUP_STOP_COUNT_OFFSET,offsetof (struct signal_struct,
6868
group_stop_count));
6969
DEFINE(IA64_SIGNAL_SHARED_PENDING_OFFSET,offsetof (struct signal_struct, shared_pending));
70-
DEFINE(IA64_SIGNAL_LEADER_PID_OFFSET, offsetof (struct signal_struct, leader_pid));
70+
DEFINE(IA64_SIGNAL_PIDS_TGID_OFFSET, offsetof (struct signal_struct, pids[PIDTYPE_TGID]));
7171

7272
BLANK();
7373

‎arch/ia64/kernel/fsys.S‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ ENTRY(fsys_getpid)
6868
add r9=TI_FLAGS+IA64_TASK_SIZE,r16
6969
;;
7070
ld4 r9=[r9]
71-
add r17=IA64_SIGNAL_LEADER_PID_OFFSET,r17
71+
add r17=IA64_SIGNAL_PIDS_TGID_OFFSET,r17
7272
;;
7373
and r9=TIF_ALLWORK_MASK,r9
74-
ld8 r17=[r17] // r17 = current->signal->leader_pid
74+
ld8 r17=[r17] // r17 = current->signal->pids[PIDTYPE_TGID]
7575
;;
7676
add r8=IA64_PID_LEVEL_OFFSET,r17
7777
;;

‎arch/s390/kernel/perf_cpum_sf.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ static void cpumsf_output_event_pid(struct perf_event *event,
665665
goto out;
666666

667667
/* Update the process ID (see also kernel/events/core.c) */
668-
data->tid_entry.pid = cpumsf_pid_type(event, pid, __PIDTYPE_TGID);
668+
data->tid_entry.pid = cpumsf_pid_type(event, pid, PIDTYPE_TGID);
669669
data->tid_entry.tid = cpumsf_pid_type(event, pid, PIDTYPE_PID);
670670

671671
perf_output_sample(&handle, &header, data, event);

‎fs/exec.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,7 @@ static int de_thread(struct task_struct *tsk)
11461146
*/
11471147
tsk->pid = leader->pid;
11481148
change_pid(tsk, PIDTYPE_PID, task_pid(leader));
1149+
transfer_pid(leader, tsk, PIDTYPE_TGID);
11491150
transfer_pid(leader, tsk, PIDTYPE_PGID);
11501151
transfer_pid(leader, tsk, PIDTYPE_SID);
11511152

‎include/linux/pid.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
enum pid_type
88
{
99
PIDTYPE_PID,
10+
PIDTYPE_TGID,
1011
PIDTYPE_PGID,
1112
PIDTYPE_SID,
1213
PIDTYPE_MAX,
13-
/* only valid to __task_pid_nr_ns() */
14-
__PIDTYPE_TGID
1514
};
1615

1716
/*

‎include/linux/sched.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,12 +1275,12 @@ static inline pid_t task_session_vnr(struct task_struct *tsk)
12751275

12761276
static inline pid_t task_tgid_nr_ns(struct task_struct *tsk, struct pid_namespace *ns)
12771277
{
1278-
return __task_pid_nr_ns(tsk, __PIDTYPE_TGID, ns);
1278+
return __task_pid_nr_ns(tsk, PIDTYPE_TGID, ns);
12791279
}
12801280

12811281
static inline pid_t task_tgid_vnr(struct task_struct *tsk)
12821282
{
1283-
return __task_pid_nr_ns(tsk, __PIDTYPE_TGID, NULL);
1283+
return __task_pid_nr_ns(tsk, PIDTYPE_TGID, NULL);
12841284
}
12851285

12861286
static inline pid_t task_ppid_nr_ns(const struct task_struct *tsk, struct pid_namespace *ns)

‎include/linux/sched/signal.h‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ struct signal_struct {
147147
#endif
148148

149149
/* PID/PID hash table linkage. */
150-
struct pid *leader_pid;
151150
struct pid *pids[PIDTYPE_MAX];
152151

153152
#ifdef CONFIG_NO_HZ_FULL
@@ -571,7 +570,7 @@ struct pid *task_pid_type(struct task_struct *task, enum pid_type type)
571570

572571
static inline struct pid *task_tgid(struct task_struct *task)
573572
{
574-
return task->signal->leader_pid;
573+
return task->signal->pids[PIDTYPE_TGID];
575574
}
576575

577576
/*
@@ -607,7 +606,7 @@ static inline bool thread_group_leader(struct task_struct *p)
607606
*/
608607
static inline bool has_group_leader_pid(struct task_struct *p)
609608
{
610-
return task_pid(p) == p->signal->leader_pid;
609+
return task_pid(p) == task_tgid(p);
611610
}
612611

613612
static inline

‎init/init_task.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ static struct signal_struct init_signals = {
3333
},
3434
#endif
3535
INIT_CPU_TIMERS(init_signals)
36-
.leader_pid = &init_struct_pid,
3736
.pids = {
3837
[PIDTYPE_PID] = &init_struct_pid,
38+
[PIDTYPE_TGID] = &init_struct_pid,
3939
[PIDTYPE_PGID] = &init_struct_pid,
4040
[PIDTYPE_SID] = &init_struct_pid,
4141
},

‎kernel/events/core.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1334,7 +1334,7 @@ static u32 perf_event_pid_type(struct perf_event *event, struct task_struct *p,
13341334

13351335
static u32 perf_event_pid(struct perf_event *event, struct task_struct *p)
13361336
{
1337-
return perf_event_pid_type(event, p, __PIDTYPE_TGID);
1337+
return perf_event_pid_type(event, p, PIDTYPE_TGID);
13381338
}
13391339

13401340
static u32 perf_event_tid(struct perf_event *event, struct task_struct *p)

‎kernel/exit.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ static void __unhash_process(struct task_struct *p, bool group_dead)
7373
nr_threads--;
7474
detach_pid(p, PIDTYPE_PID);
7575
if (group_dead) {
76+
detach_pid(p, PIDTYPE_TGID);
7677
detach_pid(p, PIDTYPE_PGID);
7778
detach_pid(p, PIDTYPE_SID);
7879

0 commit comments

Comments
 (0)