2006-10-30 16:53:38 +01:00
|
|
|
/* The kernel call that is implemented in this file:
|
2014-07-25 18:13:49 +02:00
|
|
|
* m_type: SYS_SPROF
|
2006-10-30 16:53:38 +01:00
|
|
|
*
|
|
|
|
* The parameters for this kernel call are:
|
2014-07-25 18:13:49 +02:00
|
|
|
* m_lsys_krn_sys_sprof.action (start/stop profiling)
|
|
|
|
* m_lsys_krn_sys_sprof.mem_size (available memory for data)
|
|
|
|
* m_lsys_krn_sys_sprof.freq (requested sample frequency)
|
|
|
|
* m_lsys_krn_sys_sprof.endpt (endpoint of caller)
|
|
|
|
* m_lsys_krn_sys_sprof.ctl_ptr (location of info struct)
|
|
|
|
* m_lsys_krn_sys_sprof.mem_ptr (location of memory for data)
|
|
|
|
* m_lsys_krn_sys_sprof.intr_type (interrupt source: RTC/NMI)
|
2006-10-30 16:53:38 +01:00
|
|
|
*
|
|
|
|
* Changes:
|
|
|
|
* 14 Aug, 2006 Created (Rogier Meurs)
|
|
|
|
*/
|
|
|
|
|
2010-04-02 00:22:33 +02:00
|
|
|
#include "kernel/system.h"
|
2012-11-15 12:06:41 +01:00
|
|
|
#include "kernel/watchdog.h"
|
2006-10-30 16:53:38 +01:00
|
|
|
|
|
|
|
#if SPROFILE
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
/* user address to write info struct */
|
2012-03-25 20:25:53 +02:00
|
|
|
static vir_bytes sprof_info_addr_vir;
|
2008-11-19 13:26:10 +01:00
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
static void clean_seen_flag(void)
|
2010-09-23 12:49:39 +02:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NR_TASKS + NR_PROCS; i++)
|
|
|
|
proc[i].p_misc_flags &= ~MF_SPROF_SEEN;
|
|
|
|
}
|
|
|
|
|
2006-10-30 16:53:38 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_sprofile *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_sprofile(struct proc * caller, message * m_ptr)
|
2006-10-30 16:53:38 +01:00
|
|
|
{
|
2010-01-22 23:01:08 +01:00
|
|
|
int proc_nr;
|
2010-09-23 12:49:45 +02:00
|
|
|
int err;
|
2006-10-30 16:53:38 +01:00
|
|
|
|
2014-07-25 18:13:49 +02:00
|
|
|
switch(m_ptr->m_lsys_krn_sys_sprof.action) {
|
2006-10-30 16:53:38 +01:00
|
|
|
|
|
|
|
case PROF_START:
|
|
|
|
/* Starting profiling.
|
|
|
|
*
|
|
|
|
* Check if profiling is not already running. Calculate physical
|
|
|
|
* addresses of user pointers. Reset counters. Start CMOS timer.
|
|
|
|
* Turn on profiling.
|
|
|
|
*/
|
|
|
|
if (sprofiling) {
|
2010-03-03 16:45:01 +01:00
|
|
|
printf("SYSTEM: start s-profiling: already started\n");
|
2006-10-30 16:53:38 +01:00
|
|
|
return EBUSY;
|
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
/* Test endpoint number. */
|
2014-07-25 18:13:49 +02:00
|
|
|
if(!isokendpt(m_ptr->m_lsys_krn_sys_sprof.endpt, &proc_nr))
|
2008-11-19 13:26:10 +01:00
|
|
|
return EINVAL;
|
2006-10-30 16:53:38 +01:00
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
/* Set parameters for statistical profiler. */
|
2014-07-25 18:13:49 +02:00
|
|
|
sprof_ep = m_ptr->m_lsys_krn_sys_sprof.endpt;
|
|
|
|
sprof_info_addr_vir = m_ptr->m_lsys_krn_sys_sprof.ctl_ptr;
|
|
|
|
sprof_data_addr_vir = m_ptr->m_lsys_krn_sys_sprof.mem_ptr;
|
2006-10-30 16:53:38 +01:00
|
|
|
|
|
|
|
sprof_info.mem_used = 0;
|
|
|
|
sprof_info.total_samples = 0;
|
|
|
|
sprof_info.idle_samples = 0;
|
|
|
|
sprof_info.system_samples = 0;
|
|
|
|
sprof_info.user_samples = 0;
|
|
|
|
|
2014-07-25 18:13:49 +02:00
|
|
|
sprof_mem_size =
|
|
|
|
m_ptr->m_lsys_krn_sys_sprof.mem_size < SAMPLE_BUFFER_SIZE ?
|
|
|
|
m_ptr->m_lsys_krn_sys_sprof.mem_size : SAMPLE_BUFFER_SIZE;
|
2006-10-30 16:53:38 +01:00
|
|
|
|
2014-07-25 18:13:49 +02:00
|
|
|
switch (sprofiling_type = m_ptr->m_lsys_krn_sys_sprof.intr_type) {
|
2010-09-23 12:49:45 +02:00
|
|
|
case PROF_RTC:
|
2014-07-25 18:13:49 +02:00
|
|
|
init_profile_clock(m_ptr->m_lsys_krn_sys_sprof.freq);
|
2010-09-23 12:49:45 +02:00
|
|
|
break;
|
|
|
|
case PROF_NMI:
|
2014-07-25 18:13:49 +02:00
|
|
|
err = nmi_watchdog_start_profiling(
|
|
|
|
_ptr->m_lsys_krn_sys_sprof.freq);
|
2010-09-23 12:49:45 +02:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("ERROR : unknown profiling interrupt type\n");
|
|
|
|
return EINVAL;
|
|
|
|
}
|
2006-10-30 16:53:38 +01:00
|
|
|
|
|
|
|
sprofiling = 1;
|
|
|
|
|
2010-09-23 12:49:39 +02:00
|
|
|
clean_seen_flag();
|
|
|
|
|
2006-10-30 16:53:38 +01:00
|
|
|
return OK;
|
|
|
|
|
|
|
|
case PROF_STOP:
|
|
|
|
/* Stopping profiling.
|
|
|
|
*
|
|
|
|
* Check if profiling is indeed running. Turn off profiling.
|
|
|
|
* Stop CMOS timer. Copy info struct to user process.
|
|
|
|
*/
|
|
|
|
if (!sprofiling) {
|
2010-03-03 16:45:01 +01:00
|
|
|
printf("SYSTEM: stop s-profiling: not started\n");
|
2006-10-30 16:53:38 +01:00
|
|
|
return EBUSY;
|
|
|
|
}
|
|
|
|
|
|
|
|
sprofiling = 0;
|
|
|
|
|
2010-09-23 12:49:45 +02:00
|
|
|
switch (sprofiling_type) {
|
|
|
|
case PROF_RTC:
|
|
|
|
stop_profile_clock();
|
|
|
|
break;
|
|
|
|
case PROF_NMI:
|
|
|
|
nmi_watchdog_stop_profiling();
|
|
|
|
break;
|
|
|
|
}
|
2006-10-30 16:53:38 +01:00
|
|
|
|
2010-02-09 16:20:09 +01:00
|
|
|
data_copy(KERNEL, (vir_bytes) &sprof_info,
|
2008-11-19 13:26:10 +01:00
|
|
|
sprof_ep, sprof_info_addr_vir, sizeof(sprof_info));
|
2010-09-23 12:49:48 +02:00
|
|
|
data_copy(KERNEL, (vir_bytes) sprof_sample_buffer,
|
|
|
|
sprof_ep, sprof_data_addr_vir, sprof_info.mem_used);
|
2006-10-30 16:53:38 +01:00
|
|
|
|
2010-09-23 12:49:39 +02:00
|
|
|
clean_seen_flag();
|
|
|
|
|
2006-10-30 16:53:38 +01:00
|
|
|
return OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* SPROFILE */
|
|
|
|
|