2006-10-30 16:53:38 +01:00
|
|
|
/* The kernel call that is implemented in this file:
|
|
|
|
* m_type: SYS_CPROFILE
|
|
|
|
*
|
|
|
|
* The parameters for this kernel call are:
|
|
|
|
* m7_i1: PROF_ACTION (get/reset profiling data)
|
|
|
|
* m7_i2: PROF_MEM_SIZE (available memory for data)
|
|
|
|
* m7_i4: PROF_ENDPT (endpoint of caller)
|
|
|
|
* m7_p1: PROF_CTL_PTR (location of info struct)
|
|
|
|
* m7_p2: PROF_MEM_PTR (location of memory for data)
|
|
|
|
*
|
|
|
|
* Changes:
|
|
|
|
* 14 Aug, 2006 Created (Rogier Meurs)
|
|
|
|
*/
|
|
|
|
|
2010-04-02 00:22:33 +02:00
|
|
|
#include "kernel/system.h"
|
2006-10-30 16:53:38 +01:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2011-08-02 15:24:47 +02:00
|
|
|
#if CPROFILE
|
|
|
|
|
2006-10-30 16:53:38 +01:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_cprofile *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_cprofile(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, i;
|
2008-11-19 13:26:10 +01:00
|
|
|
phys_bytes len;
|
2010-01-22 23:01:08 +01:00
|
|
|
vir_bytes vir_dst;
|
2006-10-30 16:53:38 +01:00
|
|
|
|
|
|
|
switch (m_ptr->PROF_ACTION) {
|
|
|
|
|
|
|
|
case PROF_RESET:
|
|
|
|
|
|
|
|
/* Reset profiling tables. */
|
|
|
|
|
|
|
|
cprof_ctl_inst.reset = 1;
|
|
|
|
|
2010-03-03 16:45:01 +01:00
|
|
|
printf("CPROFILE notice: resetting tables:");
|
2006-10-30 16:53:38 +01:00
|
|
|
|
|
|
|
for (i=0; i<cprof_procs_no; i++) {
|
|
|
|
|
2010-03-03 16:45:01 +01:00
|
|
|
printf(" %s", cprof_proc_info[i].name);
|
2006-10-30 16:53:38 +01:00
|
|
|
|
|
|
|
/* Test whether proc still alive. */
|
|
|
|
if (!isokendpt(cprof_proc_info[i].endpt, &proc_nr)) {
|
2010-03-03 16:45:01 +01:00
|
|
|
printf("endpt not valid %u (%s)\n",
|
2006-10-30 16:53:38 +01:00
|
|
|
cprof_proc_info[i].endpt, cprof_proc_info[i].name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set reset flag. */
|
2010-02-09 16:20:09 +01:00
|
|
|
data_copy(KERNEL, (vir_bytes) &cprof_ctl_inst.reset,
|
2008-11-19 13:26:10 +01:00
|
|
|
cprof_proc_info[i].endpt, cprof_proc_info[i].ctl_v,
|
|
|
|
sizeof(cprof_ctl_inst.reset));
|
2006-10-30 16:53:38 +01:00
|
|
|
}
|
2010-03-03 16:45:01 +01:00
|
|
|
printf("\n");
|
2006-10-30 16:53:38 +01:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
case PROF_GET:
|
|
|
|
|
|
|
|
/* Get profiling data.
|
|
|
|
*
|
|
|
|
* Calculate physical addresses of user pointers. Copy to user
|
|
|
|
* program the info struct. Copy to user program the profiling
|
|
|
|
* tables of the profiled processes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if(!isokendpt(m_ptr->PROF_ENDPT, &proc_nr))
|
|
|
|
return EINVAL;
|
|
|
|
|
|
|
|
cprof_mem_size = m_ptr->PROF_MEM_SIZE;
|
|
|
|
|
2010-03-03 16:45:01 +01:00
|
|
|
printf("CPROFILE notice: getting tables:");
|
2006-10-30 16:53:38 +01:00
|
|
|
|
|
|
|
/* Copy control structs of profiled processes to calculate total
|
|
|
|
* nr of bytes to be copied to user program and find out if any
|
|
|
|
* errors happened. */
|
|
|
|
cprof_info.mem_used = 0;
|
|
|
|
cprof_info.err = 0;
|
|
|
|
|
|
|
|
for (i=0; i<cprof_procs_no; i++) {
|
|
|
|
|
2010-03-03 16:45:01 +01:00
|
|
|
printf(" %s", cprof_proc_info[i].name);
|
2006-10-30 16:53:38 +01:00
|
|
|
|
|
|
|
/* Test whether proc still alive. */
|
|
|
|
if (!isokendpt(cprof_proc_info[i].endpt, &proc_nr)) {
|
2010-03-03 16:45:01 +01:00
|
|
|
printf("endpt not valid %u (%s)\n",
|
2006-10-30 16:53:38 +01:00
|
|
|
cprof_proc_info[i].endpt, cprof_proc_info[i].name);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy control struct from proc to local variable. */
|
2008-11-19 13:26:10 +01:00
|
|
|
data_copy(cprof_proc_info[i].endpt, cprof_proc_info[i].ctl_v,
|
2010-02-09 16:20:09 +01:00
|
|
|
KERNEL, (vir_bytes) &cprof_ctl_inst,
|
2008-11-19 13:26:10 +01:00
|
|
|
sizeof(cprof_ctl_inst));
|
2006-10-30 16:53:38 +01:00
|
|
|
|
|
|
|
/* Calculate memory used. */
|
|
|
|
cprof_proc_info[i].slots_used = cprof_ctl_inst.slots_used;
|
|
|
|
cprof_info.mem_used += CPROF_PROCNAME_LEN;
|
|
|
|
cprof_info.mem_used += sizeof(cprof_proc_info_inst.slots_used);
|
|
|
|
cprof_info.mem_used += cprof_proc_info[i].slots_used *
|
|
|
|
sizeof(cprof_tbl_inst);
|
|
|
|
/* Collect errors. */
|
|
|
|
cprof_info.err |= cprof_ctl_inst.err;
|
|
|
|
}
|
2010-03-03 16:45:01 +01:00
|
|
|
printf("\n");
|
2006-10-30 16:53:38 +01:00
|
|
|
|
|
|
|
/* Do we have the space available? */
|
|
|
|
if (cprof_mem_size < cprof_info.mem_used) cprof_info.mem_used = -1;
|
|
|
|
|
|
|
|
/* Copy the info struct to the user process. */
|
2010-02-09 16:20:09 +01:00
|
|
|
data_copy(KERNEL, (vir_bytes) &cprof_info,
|
2008-11-19 13:26:10 +01:00
|
|
|
m_ptr->PROF_ENDPT, (vir_bytes) m_ptr->PROF_CTL_PTR,
|
|
|
|
sizeof(cprof_info));
|
2006-10-30 16:53:38 +01:00
|
|
|
|
|
|
|
/* If there is no space or errors occurred, don't bother copying. */
|
|
|
|
if (cprof_info.mem_used == -1 || cprof_info.err) return OK;
|
|
|
|
|
|
|
|
/* For each profiled process, copy its name, slots_used and profiling
|
|
|
|
* table to the user process. */
|
2008-11-19 13:26:10 +01:00
|
|
|
vir_dst = (vir_bytes) m_ptr->PROF_MEM_PTR;
|
2006-10-30 16:53:38 +01:00
|
|
|
for (i=0; i<cprof_procs_no; i++) {
|
|
|
|
len = (phys_bytes) strlen(cprof_proc_info[i].name);
|
2010-02-09 16:20:09 +01:00
|
|
|
data_copy(KERNEL, (vir_bytes) cprof_proc_info[i].name,
|
2008-11-19 13:26:10 +01:00
|
|
|
m_ptr->PROF_ENDPT, vir_dst, len);
|
|
|
|
vir_dst += CPROF_PROCNAME_LEN;
|
2006-10-30 16:53:38 +01:00
|
|
|
|
|
|
|
len = (phys_bytes) sizeof(cprof_ctl_inst.slots_used);
|
2008-11-19 13:26:10 +01:00
|
|
|
data_copy(cprof_proc_info[i].endpt,
|
|
|
|
cprof_proc_info[i].ctl_v + sizeof(cprof_ctl_inst.reset),
|
|
|
|
m_ptr->PROF_ENDPT, vir_dst, len);
|
|
|
|
vir_dst += len;
|
2006-10-30 16:53:38 +01:00
|
|
|
|
|
|
|
len = (phys_bytes)
|
|
|
|
(sizeof(cprof_tbl_inst) * cprof_proc_info[i].slots_used);
|
2008-11-19 13:26:10 +01:00
|
|
|
data_copy(cprof_proc_info[i].endpt, cprof_proc_info[i].buf_v,
|
|
|
|
m_ptr->PROF_ENDPT, vir_dst, len);
|
|
|
|
vir_dst += len;
|
2006-10-30 16:53:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-02 15:24:47 +02:00
|
|
|
#endif /* CPROFILE */
|