ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / oprofile / oprofile_stats.c
1 /**
2  * @file oprofile_stats.c
3  *
4  * @remark Copyright 2002 OProfile authors
5  * @remark Read the file COPYING
6  *
7  * @author John Levon
8  */
9
10 #include <linux/oprofile.h>
11 #include <linux/smp.h>
12 #include <linux/cpumask.h>
13 #include <linux/threads.h>
14  
15 #include "oprofile_stats.h"
16 #include "cpu_buffer.h"
17  
18 struct oprofile_stat_struct oprofile_stats;
19  
20 void oprofile_reset_stats(void)
21 {
22         struct oprofile_cpu_buffer * cpu_buf; 
23         int i;
24  
25         for (i = 0; i < NR_CPUS; ++i) {
26                 if (!cpu_possible(i))
27                         continue;
28
29                 cpu_buf = &cpu_buffer[i]; 
30                 cpu_buf->sample_received = 0;
31                 cpu_buf->sample_lost_overflow = 0;
32                 cpu_buf->sample_lost_task_exit = 0;
33         }
34  
35         atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36         atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
37         atomic_set(&oprofile_stats.event_lost_overflow, 0);
38 }
39
40
41 void oprofile_create_stats_files(struct super_block * sb, struct dentry * root)
42 {
43         struct oprofile_cpu_buffer * cpu_buf;
44         struct dentry * cpudir;
45         struct dentry * dir;
46         char buf[10];
47         int i;
48
49         dir = oprofilefs_mkdir(sb, root, "stats");
50         if (!dir)
51                 return;
52
53         for (i = 0; i < NR_CPUS; ++i) {
54                 if (!cpu_possible(i))
55                         continue;
56
57                 cpu_buf = &cpu_buffer[i]; 
58                 snprintf(buf, 10, "cpu%d", i);
59                 cpudir = oprofilefs_mkdir(sb, dir, buf);
60  
61                 /* Strictly speaking access to these ulongs is racy,
62                  * but we can't simply lock them, and they are
63                  * informational only.
64                  */
65                 oprofilefs_create_ro_ulong(sb, cpudir, "sample_received",
66                         &cpu_buf->sample_received);
67                 oprofilefs_create_ro_ulong(sb, cpudir, "sample_lost_overflow",
68                         &cpu_buf->sample_lost_overflow);
69                 oprofilefs_create_ro_ulong(sb, cpudir, "sample_lost_task_exit",
70                         &cpu_buf->sample_lost_task_exit);
71         }
72  
73         oprofilefs_create_ro_atomic(sb, dir, "sample_lost_no_mm",
74                 &oprofile_stats.sample_lost_no_mm);
75         oprofilefs_create_ro_atomic(sb, dir, "sample_lost_no_mapping",
76                 &oprofile_stats.sample_lost_no_mapping);
77         oprofilefs_create_ro_atomic(sb, dir, "event_lost_overflow",
78                 &oprofile_stats.event_lost_overflow);
79 }