Skip to content

Commit

Permalink
attach_pid() with struct pid parameter
Browse files Browse the repository at this point in the history
attach_pid() currently takes a pid_t and then uses find_pid() to find the
corresponding struct pid.  Sometimes we already have the struct pid.  We can
then skip find_pid() if attach_pid() were to take a struct pid parameter.

Signed-off-by: Sukadev Bhattiprolu <[email protected]>
Cc: Cedric Le Goater <[email protected]>
Cc: Dave Hansen <[email protected]>
Cc: Serge Hallyn <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Sukadev Bhattiprolu authored and Linus Torvalds committed May 11, 2007
1 parent 4ac24b3 commit e713d0d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion fs/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ static int de_thread(struct task_struct *tsk)
*/
detach_pid(tsk, PIDTYPE_PID);
tsk->pid = leader->pid;
attach_pid(tsk, PIDTYPE_PID, tsk->pid);
attach_pid(tsk, PIDTYPE_PID, find_pid(tsk->pid));
transfer_pid(leader, tsk, PIDTYPE_PGID);
transfer_pid(leader, tsk, PIDTYPE_SID);
list_replace_rcu(&leader->tasks, &tsk->tasks);
Expand Down
3 changes: 1 addition & 2 deletions include/linux/pid.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ extern struct pid *get_task_pid(struct task_struct *task, enum pid_type type);
* write-held.
*/
extern int FASTCALL(attach_pid(struct task_struct *task,
enum pid_type type, int nr));

enum pid_type type, struct pid *pid));
extern void FASTCALL(detach_pid(struct task_struct *task, enum pid_type));
extern void FASTCALL(transfer_pid(struct task_struct *old,
struct task_struct *new, enum pid_type));
Expand Down
4 changes: 2 additions & 2 deletions kernel/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,12 @@ void __set_special_pids(pid_t session, pid_t pgrp)
if (process_session(curr) != session) {
detach_pid(curr, PIDTYPE_SID);
set_signal_session(curr->signal, session);
attach_pid(curr, PIDTYPE_SID, session);
attach_pid(curr, PIDTYPE_SID, find_pid(session));
}
if (process_group(curr) != pgrp) {
detach_pid(curr, PIDTYPE_PGID);
curr->signal->pgrp = pgrp;
attach_pid(curr, PIDTYPE_PGID, pgrp);
attach_pid(curr, PIDTYPE_PGID, find_pid(pgrp));
}
}

Expand Down
11 changes: 7 additions & 4 deletions kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -1249,16 +1249,19 @@ static struct task_struct *copy_process(unsigned long clone_flags,
__ptrace_link(p, current->parent);

if (thread_group_leader(p)) {
pid_t pgid = process_group(current);
pid_t sid = process_session(current);

p->signal->tty = current->signal->tty;
p->signal->pgrp = process_group(current);
p->signal->pgrp = pgid;
set_signal_session(p->signal, process_session(current));
attach_pid(p, PIDTYPE_PGID, process_group(p));
attach_pid(p, PIDTYPE_SID, process_session(p));
attach_pid(p, PIDTYPE_PGID, find_pid(pgid));
attach_pid(p, PIDTYPE_SID, find_pid(sid));

list_add_tail_rcu(&p->tasks, &init_task.tasks);
__get_cpu_var(process_counts)++;
}
attach_pid(p, PIDTYPE_PID, p->pid);
attach_pid(p, PIDTYPE_PID, find_pid(p->pid));
nr_threads++;
}

Expand Down
9 changes: 6 additions & 3 deletions kernel/pid.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,16 @@ struct pid * fastcall find_pid(int nr)
}
EXPORT_SYMBOL_GPL(find_pid);

int fastcall attach_pid(struct task_struct *task, enum pid_type type, int nr)
/*
* attach_pid() must be called with the tasklist_lock write-held.
*/
int fastcall attach_pid(struct task_struct *task, enum pid_type type,
struct pid *pid)
{
struct pid_link *link;
struct pid *pid;

link = &task->pids[type];
link->pid = pid = find_pid(nr);
link->pid = pid;
hlist_add_head_rcu(&link->node, &pid->tasks[type]);

return 0;
Expand Down
2 changes: 1 addition & 1 deletion kernel/sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@ asmlinkage long sys_setpgid(pid_t pid, pid_t pgid)
if (process_group(p) != pgid) {
detach_pid(p, PIDTYPE_PGID);
p->signal->pgrp = pgid;
attach_pid(p, PIDTYPE_PGID, pgid);
attach_pid(p, PIDTYPE_PGID, find_pid(pgid));
}

err = 0;
Expand Down

0 comments on commit e713d0d

Please sign in to comment.