events.c revision bcde4861cca9caf5cab2b710a3241b038fec477c
/*
* Copyright 2008, Intel Corporation
* Copyright 2008, Sun Microsystems, Inc
*
* This file is part of PowerTOP
*
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program in a file named COPYING; if not, write to the
* Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* Authors:
* Arjan van de Ven <arjan@linux.intel.com>
* Eric C Saxe <eric.saxe@sun.com>
* Aubrey Li <aubrey.li@intel.com>
*/
/*
* GPL Disclaimer
*
* For the avoidance of doubt, except that if any license choice other
* than GPL or LGPL is available it will apply instead, Sun elects to
* use only the General Public License version 2 (GPLv2) at this time
* for any software where a choice of GPL license versions is made
* available with the language indicating that GPLv2 or any later
* version may be used, or where a choice of which version of the GPL
* is applied is otherwise unspecified.
*/
#include <string.h>
#include <stdlib.h>
#include <dtrace.h>
#include "powertop.h"
static dtrace_hdl_t *g_dtp;
/*
* DTrace scripts for observing interrupts, callouts and cyclic events
* that cause CPU activity. Such activity prevents the processor from
* entering lower power states and reducing power consumption.
*
* g_prog is the default script
*/
static const char *g_prog =
"interrupt-complete"
"/arg0 != NULL && arg3 !=0/"
"{"
" this->devi = (struct dev_info *)arg0;"
" @interrupts[stringof(`devnamesp[this->devi->devi_major].dn_name),"
" this->devi->devi_instance] = count();"
"}"
""
"sdt:::callout-start"
"/(caddr_t)((callout_t *)arg0)->c_func == (caddr_t)&`setrun/"
"{"
" this->thr = (kthread_t *)(((callout_t *)arg0)->c_arg);"
" @events_u[stringof(this->thr->t_procp->p_user.u_comm)] = count();"
"}"
""
"sdt:::callout-start"
"/(caddr_t)((callout_t *)arg0)->c_func != (caddr_t)&`setrun/"
"{"
" @events_k[(caddr_t)((callout_t *)arg0)->c_func] = count();"
"}"
""
"sdt:::cyclic-start"
"/(caddr_t)((cyclic_t *)arg0)->cy_handler == (caddr_t)&`clock/"
"{"
" @events_k[(caddr_t)((cyclic_t *)arg0)->cy_handler] = count();"
"}"
""
"sysinfo:::xcalls"
"/pid != $pid/"
"{"
" @events_x[execname] = sum(arg0);"
"}";
/*
* g_prog_V is enabled through the -v option, it includes cyclic events
* in the report, allowing a complete view of system activity
*/
static const char *g_prog_v =
"interrupt-complete"
"/arg0 != NULL && arg3 !=0/"
"{"
" this->devi = (struct dev_info *)arg0;"
" @interrupts[stringof(`devnamesp[this->devi->devi_major].dn_name),"
" this->devi->devi_instance] = count();"
"}"
""
"sdt:::callout-start"
"/(caddr_t)((callout_t *)arg0)->c_func == (caddr_t)&`setrun/"
"{"
" this->thr = (kthread_t *)(((callout_t *)arg0)->c_arg);"
" @events_u[stringof(this->thr->t_procp->p_user.u_comm)] = count();"
"}"
""
"sdt:::callout-start"
"/(caddr_t)((callout_t *)arg0)->c_func != (caddr_t)&`setrun/"
"{"
" @events_k[(caddr_t)((callout_t *)arg0)->c_func] = count();"
"}"
""
"sdt:::cyclic-start"
"/(caddr_t)((cyclic_t *)arg0)->cy_handler != (caddr_t)&`dtrace_state_deadman &&"
" (caddr_t)((cyclic_t *)arg0)->cy_handler != (caddr_t)&`dtrace_state_clean/"
"{"
" @events_k[(caddr_t)((cyclic_t *)arg0)->cy_handler] = count();"
"}"
""
"sysinfo:::xcalls"
"/pid != $pid/"
"{"
" @events_x[execname] = sum(arg0);"
"}";
/*ARGSUSED*/
static int
{
char *offense_name;
int i;
uint64_t n = 0;
if (top_events >= EVENT_NUM_MAX)
return (0);
/*
* Report interrupts
*/
/* LINTED - alignment */
/*
* Report kernel events
*/
/*
* Casting offender_addr to the wrong type will cause
* dtrace_lookup_by_addr to return 0 and the report
* to show an address instead of a name.
*/
switch (bit_depth) {
case 32:
/* LINTED - alignment */
rec1->dtrd_offset);
break;
case 64:
/* LINTED - alignment */
rec1->dtrd_offset);
break;
}
/*
* We have the address of the kernel callout.
* Try to resolve it into a meaningful symbol
*/
} else {
}
/*
* Report user events
*/
EVENT_NAME_MAX, "<scheduled timeout expiration>");
/*
* Report cross calls
*/
EVENT_NAME_MAX, "<cross calls>");
/*
* Report unknown events
*/
} else {
}
for (i = 0; i < g_ncpus; i++)
/* LINTED - alignment */
p_event->total_count = n;
p_event++;
top_events++;
return (DTRACE_AGGWALK_NEXT);
}
int
pt_events_stat_prepare(void)
{
int err;
return (-1);
}
/*
* Execute different scripts (defined above) depending on
* user specified options. Default mode has event_mode empty
*/
switch (event_mode) {
default:
return (dtrace_errno(g_dtp));
}
break;
case 'v':
return (dtrace_errno(g_dtp));
}
break;
}
return (dtrace_errno(g_dtp));
}
return (dtrace_errno(g_dtp));
}
return (dtrace_errno(g_dtp));
}
return (dtrace_errno(g_dtp));
}
return (dtrace_errno(g_dtp));
}
return (dtrace_errno(g_dtp));
}
return (0);
}
int
pt_events_stat_collect(void)
{
top_events = 0;
return (-1);
if (dtrace_aggregate_snap(g_dtp) != 0)
return (0);
}