3.1.7 branch.
[minix.git] / kernel / system / do_sprofile.c
blob629ee1dff910c138efe54b0965cf05ece62dc319
1 /* The kernel call that is implemented in this file:
2 * m_type: SYS_SPROFILE
4 * The parameters for this kernel call are:
5 * m7_i1: PROF_ACTION (start/stop profiling)
6 * m7_i2: PROF_MEM_SIZE (available memory for data)
7 * m7_i3: PROF_FREQ (requested sample frequency)
8 * m7_i4: PROF_ENDPT (endpoint of caller)
9 * m7_p1: PROF_CTL_PTR (location of info struct)
10 * m7_p2: PROF_MEM_PTR (location of memory for data)
12 * Changes:
13 * 14 Aug, 2006 Created (Rogier Meurs)
16 #include "kernel/system.h"
18 #if SPROFILE
20 /* user address to write info struct */
21 PRIVATE vir_bytes sprof_info_addr_vir;
23 /*===========================================================================*
24 * do_sprofile *
25 *===========================================================================*/
26 PUBLIC int do_sprofile(struct proc * caller, message * m_ptr)
28 int proc_nr;
30 switch(m_ptr->PROF_ACTION) {
32 case PROF_START:
33 /* Starting profiling.
35 * Check if profiling is not already running. Calculate physical
36 * addresses of user pointers. Reset counters. Start CMOS timer.
37 * Turn on profiling.
39 if (sprofiling) {
40 printf("SYSTEM: start s-profiling: already started\n");
41 return EBUSY;
44 /* Test endpoint number. */
45 if(!isokendpt(m_ptr->PROF_ENDPT, &proc_nr))
46 return EINVAL;
48 /* Set parameters for statistical profiler. */
49 sprof_ep = m_ptr->PROF_ENDPT;
50 sprof_info_addr_vir = (vir_bytes) m_ptr->PROF_CTL_PTR;
51 sprof_data_addr_vir = (vir_bytes) m_ptr->PROF_MEM_PTR;
53 sprof_info.mem_used = 0;
54 sprof_info.total_samples = 0;
55 sprof_info.idle_samples = 0;
56 sprof_info.system_samples = 0;
57 sprof_info.user_samples = 0;
59 sprof_mem_size = m_ptr->PROF_MEM_SIZE;
61 init_profile_clock(m_ptr->PROF_FREQ);
63 sprofiling = 1;
65 return OK;
67 case PROF_STOP:
68 /* Stopping profiling.
70 * Check if profiling is indeed running. Turn off profiling.
71 * Stop CMOS timer. Copy info struct to user process.
73 if (!sprofiling) {
74 printf("SYSTEM: stop s-profiling: not started\n");
75 return EBUSY;
78 sprofiling = 0;
80 stop_profile_clock();
82 data_copy(KERNEL, (vir_bytes) &sprof_info,
83 sprof_ep, sprof_info_addr_vir, sizeof(sprof_info));
85 return OK;
87 default:
88 return EINVAL;
92 #endif /* SPROFILE */