1 /* The kernel call that is implemented in this file:
4 * The parameters for this kernel call are:
5 * m_lsys_krn_sys_sprof.action (start/stop profiling)
6 * m_lsys_krn_sys_sprof.mem_size (available memory for data)
7 * m_lsys_krn_sys_sprof.freq (requested sample frequency)
8 * m_lsys_krn_sys_sprof.endpt (endpoint of caller)
9 * m_lsys_krn_sys_sprof.ctl_ptr (location of info struct)
10 * m_lsys_krn_sys_sprof.mem_ptr (location of memory for data)
11 * m_lsys_krn_sys_sprof.intr_type (interrupt source: RTC/NMI)
14 * 14 Aug, 2006 Created (Rogier Meurs)
17 #include "kernel/system.h"
18 #include "kernel/watchdog.h"
22 /* user address to write info struct */
23 static vir_bytes sprof_info_addr_vir
;
25 static void clean_seen_flag(void)
29 for (i
= 0; i
< NR_TASKS
+ NR_PROCS
; i
++)
30 proc
[i
].p_misc_flags
&= ~MF_SPROF_SEEN
;
33 /*===========================================================================*
35 *===========================================================================*/
36 int do_sprofile(struct proc
* caller
, message
* m_ptr
)
41 switch(m_ptr
->m_lsys_krn_sys_sprof
.action
) {
44 /* Starting profiling.
46 * Check if profiling is not already running. Calculate physical
47 * addresses of user pointers. Reset counters. Start CMOS timer.
51 printf("SYSTEM: start s-profiling: already started\n");
55 /* Test endpoint number. */
56 if(!isokendpt(m_ptr
->m_lsys_krn_sys_sprof
.endpt
, &proc_nr
))
59 /* Set parameters for statistical profiler. */
60 sprof_ep
= m_ptr
->m_lsys_krn_sys_sprof
.endpt
;
61 sprof_info_addr_vir
= m_ptr
->m_lsys_krn_sys_sprof
.ctl_ptr
;
62 sprof_data_addr_vir
= m_ptr
->m_lsys_krn_sys_sprof
.mem_ptr
;
64 sprof_info
.mem_used
= 0;
65 sprof_info
.total_samples
= 0;
66 sprof_info
.idle_samples
= 0;
67 sprof_info
.system_samples
= 0;
68 sprof_info
.user_samples
= 0;
71 m_ptr
->m_lsys_krn_sys_sprof
.mem_size
< SAMPLE_BUFFER_SIZE
?
72 m_ptr
->m_lsys_krn_sys_sprof
.mem_size
: SAMPLE_BUFFER_SIZE
;
74 switch (sprofiling_type
= m_ptr
->m_lsys_krn_sys_sprof
.intr_type
) {
76 init_profile_clock(m_ptr
->m_lsys_krn_sys_sprof
.freq
);
79 err
= nmi_watchdog_start_profiling(
80 m_ptr
->m_lsys_krn_sys_sprof
.freq
);
85 printf("ERROR : unknown profiling interrupt type\n");
96 /* Stopping profiling.
98 * Check if profiling is indeed running. Turn off profiling.
99 * Stop CMOS timer. Copy info struct to user process.
102 printf("SYSTEM: stop s-profiling: not started\n");
108 switch (sprofiling_type
) {
110 stop_profile_clock();
113 nmi_watchdog_stop_profiling();
117 data_copy(KERNEL
, (vir_bytes
) &sprof_info
,
118 sprof_ep
, sprof_info_addr_vir
, sizeof(sprof_info
));
119 data_copy(KERNEL
, (vir_bytes
) sprof_sample_buffer
,
120 sprof_ep
, sprof_data_addr_vir
, sprof_info
.mem_used
);
131 #endif /* SPROFILE */