fix compiler warning
[minix.git] / kernel / profile.c
blob5336267437a54abe7d68f06b60c5d13884926549
1 /*
2 * This file contains several functions and variables used for system
3 * profiling.
5 * Statistical Profiling:
6 * The interrupt handler for profiling clock.
8 * Call Profiling:
9 * The table used for profiling data and a function to get its size.
11 * The function used by kernelspace processes to register the locations
12 * of their control struct and profiling table.
14 * Changes:
15 * 14 Aug, 2006 Created, (Rogier Meurs)
18 #include <minix/config.h>
20 #include <minix/profile.h>
21 #include <minix/portio.h>
22 #include "kernel.h"
23 #include "profile.h"
24 #include "proc.h"
26 #if SPROFILE
28 #include <string.h>
30 /* Function prototype for the profiling clock handler. */
31 FORWARD _PROTOTYPE( int profile_clock_handler, (irq_hook_t *hook) );
33 /* A hook for the profiling clock interrupt handler. */
34 PRIVATE irq_hook_t profile_clock_hook;
36 /*===========================================================================*
37 * init_profile_clock *
38 *===========================================================================*/
39 PUBLIC void init_profile_clock(u32_t freq)
41 int r, irq;
43 intr_disable();
45 if((irq = arch_init_profile_clock(freq)) >= 0) {
46 /* Register interrupt handler for statistical system profiling. */
47 profile_clock_hook.proc_nr_e = CLOCK;
48 put_irq_handler(&profile_clock_hook, irq, profile_clock_handler);
49 enable_irq(&profile_clock_hook);
52 intr_enable();
55 /*===========================================================================*
56 * profile_clock_stop *
57 *===========================================================================*/
58 PUBLIC void stop_profile_clock()
60 intr_disable();
61 arch_stop_profile_clock();
62 intr_enable();
64 /* Unregister interrupt handler. */
65 disable_irq(&profile_clock_hook);
66 rm_irq_handler(&profile_clock_hook);
69 /*===========================================================================*
70 * profile_clock_handler *
71 *===========================================================================*/
72 PRIVATE int profile_clock_handler(hook)
73 irq_hook_t *hook;
75 /* This executes on every tick of the CMOS timer. */
77 /* Are we profiling, and profiling memory not full? */
78 if (!sprofiling || sprof_info.mem_used == -1) return (1);
80 /* Check if enough memory available before writing sample. */
81 if (sprof_info.mem_used + sizeof(sprof_info) > sprof_mem_size) {
82 sprof_info.mem_used = -1;
83 return(1);
86 /* All is OK */
88 /* Idle process? */
89 if (priv(proc_ptr)->s_proc_nr == IDLE) {
90 sprof_info.idle_samples++;
91 } else
92 /* Runnable system process? */
93 if (priv(proc_ptr)->s_flags & SYS_PROC && !proc_ptr->p_rts_flags) {
94 /* Note: k_reenter is always 0 here. */
96 /* Store sample (process name and program counter). */
97 data_copy(SYSTEM, (vir_bytes) proc_ptr->p_name,
98 sprof_ep, sprof_data_addr_vir + sprof_info.mem_used,
99 strlen(proc_ptr->p_name));
101 data_copy(SYSTEM, (vir_bytes) &proc_ptr->p_reg.pc, sprof_ep,
102 (vir_bytes) (sprof_data_addr_vir + sprof_info.mem_used +
103 sizeof(proc_ptr->p_name)),
104 (vir_bytes) sizeof(proc_ptr->p_reg.pc));
106 sprof_info.mem_used += sizeof(sprof_sample);
108 sprof_info.system_samples++;
109 } else {
110 /* User process. */
111 sprof_info.user_samples++;
114 sprof_info.total_samples++;
116 /* Acknowledge interrupt if necessary. */
117 arch_ack_profile_clock();
119 return(1); /* reenable interrupts */
122 #endif /* SPROFILE */
124 #if CPROFILE
126 * The following variables and functions are used by the procentry/
127 * procentry syslib functions when linked with kernelspace processes.
128 * For userspace processes, the same variables and function are defined
129 * elsewhere. This enables different functionality and variable sizes,
130 * which is needed is a few cases.
133 /* A small table is declared for the kernelspace processes. */
134 struct cprof_tbl_s cprof_tbl[CPROF_TABLE_SIZE_KERNEL];
136 /* Function that returns table size. */
137 PUBLIC int profile_get_tbl_size(void)
139 return CPROF_TABLE_SIZE_KERNEL;
142 /* Function that returns on which execution of procentry to announce. */
143 PUBLIC int profile_get_announce(void)
145 return CPROF_ACCOUNCE_KERNEL;
149 * The kernel "announces" its control struct and table locations
150 * to itself through this function.
152 PUBLIC void profile_register(ctl_ptr, tbl_ptr)
153 void *ctl_ptr;
154 void *tbl_ptr;
156 int proc_nr;
157 vir_bytes vir_dst;
158 struct proc *rp;
160 if(cprof_procs_no >= NR_SYS_PROCS)
161 return;
163 /* Store process name, control struct, table locations. */
164 rp = proc_addr(SYSTEM);
166 cprof_proc_info[cprof_procs_no].endpt = rp->p_endpoint;
167 cprof_proc_info[cprof_procs_no].name = rp->p_name;
168 cprof_proc_info[cprof_procs_no].ctl_v = (vir_bytes) ctl_ptr;
169 cprof_proc_info[cprof_procs_no].buf_v = (vir_bytes) tbl_ptr;
171 cprof_procs_no++;
174 #endif