Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 32671
b: refs/heads/master
c: ad4ecbc
h: refs/heads/master
i:
  32669: 1c3319f
  32667: 8638974
  32663: 2238b59
  32655: 204cc5b
  32639: 465da75
v: v3
  • Loading branch information
Shailabh Nagar authored and Linus Torvalds committed Jul 15, 2006
1 parent 16af033 commit bffff5b
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 82 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 25890454667b3295f67b3372352be90705f8667c
refs/heads/master: ad4ecbcba72855a2b5319b96e2a3a65ed1ca3bfd
13 changes: 4 additions & 9 deletions trunk/Documentation/accounting/delay-accounting.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ counter (say cpu_delay_total) for a task will give the delay
experienced by the task waiting for the corresponding resource
in that interval.

When a task exits, records containing the per-task and per-process statistics
are sent to userspace without requiring a command. More details are given in
the taskstats interface description.
When a task exits, records containing the per-task statistics
are sent to userspace without requiring a command. If it is the last exiting
task of a thread group, the per-tgid statistics are also sent. More details
are given in the taskstats interface description.

The getdelays.c userspace utility in this directory allows simple commands to
be run and the corresponding delay statistics to be displayed. It also serves
Expand Down Expand Up @@ -107,9 +108,3 @@ IO count delay total
0 0
MEM count delay total
0 0






33 changes: 13 additions & 20 deletions trunk/Documentation/accounting/taskstats.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ The response contains statistics for a task (if pid is specified) or the sum of
statistics for all tasks of the process (if tgid is specified).

To obtain statistics for tasks which are exiting, userspace opens a multicast
netlink socket. Each time a task exits, two records are sent by the kernel to
each listener on the multicast socket. The first the per-pid task's statistics
and the second is the sum for all tasks of the process to which the task
belongs (the task does not need to be the thread group leader). The need for
per-tgid stats to be sent for each exiting task is explained in the per-tgid
stats section below.
netlink socket. Each time a task exits, its per-pid statistics is always sent
by the kernel to each listener on the multicast socket. In addition, if it is
the last thread exiting its thread group, an additional record containing the
per-tgid stats are also sent. The latter contains the sum of per-pid stats for
all threads in the thread group, both past and present.

getdelays.c is a simple utility demonstrating usage of the taskstats interface
for reporting delay accounting statistics.
Expand Down Expand Up @@ -104,20 +103,14 @@ stats in userspace alone is inefficient and potentially inaccurate (due to lack
of atomicity).

However, maintaining per-process, in addition to per-task stats, within the
kernel has space and time overheads. Hence the taskstats implementation
dynamically sums up the per-task stats for each task belonging to a process
whenever per-process stats are needed.

Not maintaining per-tgid stats creates a problem when userspace is interested
in getting these stats when the process dies i.e. the last thread of
a process exits. It isn't possible to simply return some aggregated per-process
statistic from the kernel.

The approach taken by taskstats is to return the per-tgid stats *each* time
a task exits, in addition to the per-pid stats for that task. Userspace can
maintain task<->process mappings and use them to maintain the per-process stats
in userspace, updating the aggregate appropriately as the tasks of a process
exit.
kernel has space and time overheads. To address this, the taskstats code
accumalates each exiting task's statistics into a process-wide data structure.
When the last task of a process exits, the process level data accumalated also
gets sent to userspace (along with the per-task data).

When a user queries to get per-tgid data, the sum of all other live threads in
the group is added up and added to the accumalated total for previously exited
threads of the same thread group.

Extending taskstats
-------------------
Expand Down
12 changes: 12 additions & 0 deletions trunk/MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -2240,6 +2240,12 @@ M: tsbogend@alpha.franken.de
L: netdev@vger.kernel.org
S: Maintained

PER-TASK DELAY ACCOUNTING
P: Shailabh Nagar
M: nagar@watson.ibm.com
L: linux-kernel@vger.kernel.org
S: Maintained

PERSONALITY HANDLING
P: Christoph Hellwig
M: hch@infradead.org
Expand Down Expand Up @@ -2767,6 +2773,12 @@ P: Deepak Saxena
M: dsaxena@plexity.net
S: Maintained

TASKSTATS STATISTICS INTERFACE
P: Shailabh Nagar
M: nagar@watson.ibm.com
L: linux-kernel@vger.kernel.org
S: Maintained

TI PARALLEL LINK CABLE DRIVER
P: Romain Lievin
M: roms@lpg.ticalc.org
Expand Down
4 changes: 4 additions & 0 deletions trunk/include/linux/sched.h
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,10 @@ struct signal_struct {
#ifdef CONFIG_BSD_PROCESS_ACCT
struct pacct_struct pacct; /* per-process accounting information */
#endif
#ifdef CONFIG_TASKSTATS
spinlock_t stats_lock;
struct taskstats *stats;
#endif
};

/* Context switch must be unlocked if interrupts are to be enabled */
Expand Down
71 changes: 55 additions & 16 deletions trunk/include/linux/taskstats_kern.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,75 @@ enum {
extern kmem_cache_t *taskstats_cache;
extern struct mutex taskstats_exit_mutex;

static inline void taskstats_exit_alloc(struct taskstats **ptidstats,
struct taskstats **ptgidstats)
static inline void taskstats_exit_alloc(struct taskstats **ptidstats)
{
*ptidstats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL);
*ptgidstats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL);
}

static inline void taskstats_exit_free(struct taskstats *tidstats,
struct taskstats *tgidstats)
static inline void taskstats_exit_free(struct taskstats *tidstats)
{
if (tidstats)
kmem_cache_free(taskstats_cache, tidstats);
if (tgidstats)
kmem_cache_free(taskstats_cache, tgidstats);
}

extern void taskstats_exit_send(struct task_struct *, struct taskstats *,
struct taskstats *);
extern void taskstats_init_early(void);
static inline void taskstats_tgid_init(struct signal_struct *sig)
{
spin_lock_init(&sig->stats_lock);
sig->stats = NULL;
}

static inline void taskstats_tgid_alloc(struct signal_struct *sig)
{
struct taskstats *stats;
unsigned long flags;

stats = kmem_cache_zalloc(taskstats_cache, SLAB_KERNEL);
if (!stats)
return;

spin_lock_irqsave(&sig->stats_lock, flags);
if (!sig->stats) {
sig->stats = stats;
stats = NULL;
}
spin_unlock_irqrestore(&sig->stats_lock, flags);

if (stats)
kmem_cache_free(taskstats_cache, stats);
}

static inline void taskstats_tgid_free(struct signal_struct *sig)
{
struct taskstats *stats = NULL;
unsigned long flags;

spin_lock_irqsave(&sig->stats_lock, flags);
if (sig->stats) {
stats = sig->stats;
sig->stats = NULL;
}
spin_unlock_irqrestore(&sig->stats_lock, flags);
if (stats)
kmem_cache_free(taskstats_cache, stats);
}

extern void taskstats_exit_send(struct task_struct *, struct taskstats *, int);
extern void taskstats_init_early(void);
extern void taskstats_tgid_alloc(struct signal_struct *);
#else
static inline void taskstats_exit_alloc(struct taskstats **ptidstats,
struct taskstats **ptgidstats)
static inline void taskstats_exit_alloc(struct taskstats **ptidstats)
{}
static inline void taskstats_exit_free(struct taskstats *ptidstats,
struct taskstats *ptgidstats)
static inline void taskstats_exit_free(struct taskstats *ptidstats)
{}
static inline void taskstats_exit_send(struct task_struct *tsk,
struct taskstats *tidstats,
struct taskstats *tgidstats)
struct taskstats *tidstats,
int group_dead)
{}
static inline void taskstats_tgid_init(struct signal_struct *sig)
{}
static inline void taskstats_tgid_alloc(struct signal_struct *sig)
{}
static inline void taskstats_tgid_free(struct signal_struct *sig)
{}
static inline void taskstats_init_early(void)
{}
Expand Down
8 changes: 4 additions & 4 deletions trunk/kernel/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ static void exit_notify(struct task_struct *tsk)
fastcall NORET_TYPE void do_exit(long code)
{
struct task_struct *tsk = current;
struct taskstats *tidstats, *tgidstats;
struct taskstats *tidstats;
int group_dead;

profile_task_exit(tsk);
Expand Down Expand Up @@ -884,7 +884,7 @@ fastcall NORET_TYPE void do_exit(long code)
current->comm, current->pid,
preempt_count());

taskstats_exit_alloc(&tidstats, &tgidstats);
taskstats_exit_alloc(&tidstats);

acct_update_integrals(tsk);
if (tsk->mm) {
Expand All @@ -905,8 +905,8 @@ fastcall NORET_TYPE void do_exit(long code)
#endif
if (unlikely(tsk->audit_context))
audit_free(tsk);
taskstats_exit_send(tsk, tidstats, tgidstats);
taskstats_exit_free(tidstats, tgidstats);
taskstats_exit_send(tsk, tidstats, group_dead);
taskstats_exit_free(tidstats);
delayacct_tsk_exit(tsk);

exit_mm(tsk);
Expand Down
4 changes: 4 additions & 0 deletions trunk/kernel/fork.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <linux/acct.h>
#include <linux/cn_proc.h>
#include <linux/delayacct.h>
#include <linux/taskstats_kern.h>

#include <asm/pgtable.h>
#include <asm/pgalloc.h>
Expand Down Expand Up @@ -819,6 +820,7 @@ static inline int copy_signal(unsigned long clone_flags, struct task_struct * ts
if (clone_flags & CLONE_THREAD) {
atomic_inc(&current->signal->count);
atomic_inc(&current->signal->live);
taskstats_tgid_alloc(current->signal);
return 0;
}
sig = kmem_cache_alloc(signal_cachep, GFP_KERNEL);
Expand Down Expand Up @@ -863,6 +865,7 @@ static inline int copy_signal(unsigned long clone_flags, struct task_struct * ts
INIT_LIST_HEAD(&sig->cpu_timers[0]);
INIT_LIST_HEAD(&sig->cpu_timers[1]);
INIT_LIST_HEAD(&sig->cpu_timers[2]);
taskstats_tgid_init(sig);

task_lock(current->group_leader);
memcpy(sig->rlim, current->signal->rlim, sizeof sig->rlim);
Expand All @@ -884,6 +887,7 @@ static inline int copy_signal(unsigned long clone_flags, struct task_struct * ts
void __cleanup_signal(struct signal_struct *sig)
{
exit_thread_group_keys(sig);
taskstats_tgid_free(sig);
kmem_cache_free(signal_cachep, sig);
}

Expand Down
Loading

0 comments on commit bffff5b

Please sign in to comment.