#define DBG_FUNC_ALL (DBG_FUNC_START | DBG_FUNC_END)
#define DBG_FUNC_MASK 0xfffffffc
+#define CPU_NUMBER(ts) ((ts & KDBG_CPU_MASK) >> KDBG_CPU_SHIFT)
+
#define DBG_ZERO_FILL_FAULT 1
#define DBG_PAGEIN_FAULT 2
#define DBG_COW_FAULT 3
sysctl(mib, 3, &kr, &needed, NULL, 0);
}
-set_rtcdec(decval)
+void set_rtcdec(decval)
int decval;
{kd_regtype kr;
int ret;
mib[5] = 0; /* no flags */
errno = 0;
-
if ((ret=sysctl(mib, 3, &kr, &needed, NULL, 0)) < 0)
{
- decrementer_val = 0;
- quit("trace facility failure, KERN_KDSETRTCDEC\n");
+ decrementer_val = 0;
+ /* ignore this sysctl error if it's not supported */
+ if (errno == ENOENT)
+ return;
+ else
+ quit("trace facility failure, KERN_KDSETRTCDEC\n");
}
}
set_enable(0);
set_pidexclude(getpid(), 0);
screen_update(log_fp);
+ endwin();
set_rtcdec(0);
set_remove();
{
set_enable(0);
set_pidexclude(getpid(), 0);
+ endwin();
set_rtcdec(0);
set_remove();
elapsed_secs -= elapsed_mins * 60;
sprintf(tbuf, "%-19.19s %2ld:%02ld:%02ld\n", &(ctime(&curr_time)[0]),
- elapsed_hours, elapsed_mins, elapsed_secs);
+ (long)elapsed_hours, (long)elapsed_mins, (long)elapsed_secs);
if (fp)
fprintf(fp, "%s", tbuf);
else
{
fprintf(stderr, "Usage: latency [-rt] [-c codefile] [-l logfile] [-st threshold]\n");
- fprintf(stderr, " [-it threshold] [-s sleep_in_usecs]\n");
+
+#if defined (__i386__)
+ fprintf(stderr, " [-it threshold] [-s sleep_in_usecs] [-n kernel]\n\n");
+#else
+ fprintf(stderr, " [-it threshold] [-s sleep_in_usecs]\n");
fprintf(stderr, " [-d decrementer_in_usecs] [-n kernel]\n\n");
+#endif
+
fprintf(stderr, " -rt Set realtime scheduling policy. Default is timeshare.\n");
fprintf(stderr, " -c specify name of codes file\n");
fprintf(stderr, " -st set scheduler latency threshold in microseconds... if latency exceeds this, then log trace\n");
fprintf(stderr, " -it set interrupt latency threshold in microseconds... if latency exceeds this, then log trace\n");
fprintf(stderr, " -s set sleep time in microseconds\n");
+#if !defined (__i386__)
fprintf(stderr, " -d set decrementer in microseconds.\n");
+#endif
fprintf(stderr, " -n specify kernel, default is /mach_kernel\n");
fprintf(stderr, "\nlatency must be run as root\n\n");
}
-
+int
main(argc, argv)
int argc;
char *argv[];
{
- mach_timespec_t remain;
uint64_t start, stop;
uint64_t timestamp1;
uint64_t timestamp2;
int decrementer_usec = 0;
kern_return_t ret;
int size;
- int i, count;
host_name_port_t host;
void getdivisor();
void sample_sc();
num_of_usecs_to_sleep = atoi(argv[1]);
else
exit_usage();
- } else if (strcmp(argv[1], "-d") == 0) {
+ }
+ else if (strcmp(argv[1], "-d") == 0) {
argc--;
argv++;
decrementer_usec = atoi(argv[1]);
else
exit_usage();
- } else if (strcmp(argv[1], "-n") == 0) {
+#if defined(__i386__)
+ /* ignore this option - setting the decrementer has no effect */
+ decrementer_usec = 0;
+#endif
+ }
+ else if (strcmp(argv[1], "-n") == 0) {
argc--;
argv++;
getdivisor();
decrementer_val = decrementer_usec * divisor;
- /* get the cpu count for the DECR_TRAP array */
+ /* get the cpu countfor the DECR_TRAP array */
host = mach_host_self();
size = sizeof(hi)/sizeof(int);
ret = host_info(host, HOST_BASIC_INFO, (host_info_t)&hi, &size);
timestamp1 = mach_absolute_time();
adeadline = timestamp1 + adelay;
- mk_wait_until(adeadline);
+ mach_wait_until(adeadline);
timestamp2 = mach_absolute_time();
start = timestamp1;
size = bufinfo.nkdthreads * sizeof(kd_threadmap);
if (size)
{
- if (mapptr = (kd_threadmap *) malloc(size))
+ if ((mapptr = (kd_threadmap *) malloc(size)))
bzero (mapptr, size);
else
{
{
kd_threadmap *map;
- if (map = find_thread_map(thread)) {
+ if ((map = find_thread_map(thread))) {
#if 0
if (log_fp)
uint64_t now;
int count, i;
int first_entry = 1;
+ double timestamp = 0.0;
+ double last_timestamp = 0.0;
+ double delta = 0.0;
+ double start_bias = 0.0;
char command[32];
- double timestamp, last_timestamp, delta, start_bias;
void read_command_map();
if (log_fp && (my_policy == THREAD_TIME_CONSTRAINT_POLICY))
char *p;
long *sargptr;
kd_buf *cur_kd;
- double i_latency;
+ double i_latency = 0.0;
struct th_info *ti;
char command1[32];
char sched_info[64];
void exit_syscall();
void print_entry();
- thread = kd->arg5 & KDBG_THREAD_MASK;
- cpunum = (kd->arg5 & KDBG_CPU_MASK) ? 1: 0;
+ thread = kd->arg5;
+ cpunum = CPU_NUMBER(kd->timestamp);
debugid = kd->debugid;
type = kd->debugid & DBG_FUNC_MASK;
if (type == DECR_TRAP)
i_latency = handle_decrementer(kd);
- now = (((uint64_t)kd->timestamp.tv_sec) << 32) |
- (uint64_t)((unsigned int)(kd->timestamp.tv_nsec));
+ now = kd->timestamp & KDBG_TIMESTAMP_MASK;
timestamp = ((double)now) / divisor;
}
if ((kd->debugid & DBG_FUNC_MASK) == DECR_TRAP)
{
- cpunum = (kd->arg5 & KDBG_CPU_MASK) ? 1: 0;
+ cpunum = CPU_NUMBER(kd->timestamp);
last_decrementer_kd[cpunum] = kd;
}
else
}
delta = timestamp - last_timestamp;
- if (map = find_thread_map(thread))
+ if ((map = find_thread_map(thread)))
strcpy(command, map->command);
else
command[0] = 0;
mode = 1;
- if (ti = find_thread((kd->arg5 & KDBG_THREAD_MASK), 0, 0)) {
+ if ((ti = find_thread(kd->arg5, 0, 0))) {
if (ti->type == -1 && strcmp(command, "kernel_task"))
mode = 0;
}
case MACH_stkhandoff:
last_mach_sched = kd;
- if (map = find_thread_map(kd->arg2))
+ if ((map = find_thread_map(kd->arg2)))
strcpy(command1, map->command);
else
sprintf(command1, "%-8x", kd->arg2);
- if (ti = find_thread(kd->arg2, 0, 0)) {
+ if ((ti = find_thread(kd->arg2, 0, 0))) {
if (ti->type == -1 && strcmp(command1, "kernel_task"))
p = "U";
else
int cpunum;
char *p;
- cpunum = (kd->arg5 & KDBG_CPU_MASK) ? 1: 0;
+ cpunum = CPU_NUMBER(kd->timestamp);
if (print_info && fp) {
- if (p = find_code(type)) {
+ if ((p = find_code(type))) {
if (type == INTERRUPT) {
int mode = 1;
- if (ti = find_thread((kd->arg5 & KDBG_THREAD_MASK), 0, 0)) {
+ if ((ti = find_thread(kd->arg5, 0, 0))) {
if (ti->type == -1 && strcmp(command, "kernel_task"))
mode = 0;
}
int cpunum;
char *p;
- cpunum = (kd->arg5 & KDBG_CPU_MASK) ? 1: 0;
+ cpunum = CPU_NUMBER(kd->timestamp);
+
ti = find_thread(thread, type, type);
#if 0
if (print_info && fp)
else
fprintf(fp, "%9.1f %8.1f() \t", timestamp - bias, delta);
- if (p = find_code(type)) {
+ if ((p = find_code(type))) {
if (type == INTERRUPT) {
fprintf(fp, "INTERRUPT %-8x %d %s\n", thread, cpunum, command);
} else if (type == MACH_vmfault && kd->arg2 <= DBG_CACHE_HIT_FAULT) {
if (!fp)
return;
- cpunum = (kd->arg5 & KDBG_CPU_MASK) ? 1: 0;
-
+ cpunum = CPU_NUMBER(kd->timestamp);
#if 0
fprintf(fp, "cur_max = %d, type = %x, thread = %x, cpunum = %d\n", cur_max, type, thread, cpunum);
#endif
- if (p = find_code(type)) {
+ if ((p = find_code(type))) {
fprintf(fp, "%9.1f %8.1f\t\t%-28.28s %-8x %-8x %-8x %-8x %-8x %d %s\n",
timestamp - bias, delta, p, kd->arg1, kd->arg2, kd->arg3, kd->arg4,
thread, cpunum, command);
{
kd_buf *kd, *kd_start, *kd_stop;
int kd_count; /* Limit the boundary of kd_start */
- double timestamp, last_timestamp, delta, start_bias;
+ double timestamp = 0.0;
+ double last_timestamp = 0.0;
+ double delta = 0.0;
+ double start_bias = 0.0;
int thread, cpunum;
int debugid, type, clen;
int len;
fprintf(log_fp, "RelTime(Us) Delta debugid arg1 arg2 arg3 arg4 thread cpu command\n\n");
- thread = kd_beg->arg5 & KDBG_THREAD_MASK;
- cpunum = (kd_end->arg5 & KDBG_CPU_MASK) ? 1: 0;
+ thread = kd_beg->arg5;
+ cpunum = CPU_NUMBER(kd_end->timestamp);
for (kd_count = 0, kd_start = kd_beg - 1; (kd_start >= (kd_buf *)my_buffer); kd_start--, kd_count++) {
if (kd_count == MAX_LOG_COUNT)
break;
- if((kd_start->arg5 & KDBG_CPU_MASK) != cpunum)
+ if (CPU_NUMBER(kd_start->timestamp) != cpunum)
continue;
if ((kd_start->debugid & DBG_FUNC_MASK) == DECR_TRAP)
break;
- if((kd_start->arg5 & KDBG_THREAD_MASK) != thread)
+ if (kd_start->arg5 != thread)
break;
}
if (kd_start < (kd_buf *)my_buffer)
kd_start = (kd_buf *)my_buffer;
- thread = kd_end->arg5 & KDBG_THREAD_MASK;
+ thread = kd_end->arg5;
for (kd_stop = kd_end + 1; kd_stop < end_of_sample; kd_stop++) {
if ((kd_stop->debugid & DBG_FUNC_MASK) == DECR_TRAP)
break;
- if((kd_stop->arg5 & KDBG_CPU_MASK) != cpunum)
+ if (CPU_NUMBER(kd_stop->timestamp) != cpunum)
continue;
- if((kd_stop->arg5 & KDBG_THREAD_MASK) != thread)
+ if (kd_stop->arg5 != thread)
break;
}
if (kd_stop >= end_of_sample)
kd_stop = end_of_sample - 1;
- now = (((uint64_t)kd_start->timestamp.tv_sec) << 32) |
- (uint64_t)((unsigned int)(kd_start->timestamp.tv_nsec));
+ now = kd_start->timestamp & KDBG_TIMESTAMP_MASK;
timestamp = ((double)now) / divisor;
for (kd = kd_start; kd <= kd_stop; kd++) {
type = kd->debugid & DBG_FUNC_MASK;
- if (ti = find_thread((kd->arg5 & KDBG_THREAD_MASK), type, type)) {
+ if ((ti = find_thread(kd->arg5, type, type))) {
if (ti->stime >= timestamp)
ti->type = -1;
}
for (kd = kd_start; kd <= kd_stop; kd++) {
int mode;
- thread = kd->arg5 & KDBG_THREAD_MASK;
- cpunum = (kd->arg5 & KDBG_CPU_MASK) ? 1: 0;
+ thread = kd->arg5;
+ cpunum = CPU_NUMBER(kd->timestamp);
debugid = kd->debugid;
type = kd->debugid & DBG_FUNC_MASK;
- now = (((uint64_t)kd->timestamp.tv_sec) << 32) |
- (uint64_t)((unsigned int)(kd->timestamp.tv_nsec));
+ now = kd->timestamp & KDBG_TIMESTAMP_MASK;
timestamp = ((double)now) / divisor;
}
delta = timestamp - last_timestamp;
- if (map = find_thread_map(thread))
+ if ((map = find_thread_map(thread)))
strcpy(command, map->command);
else
command[0] = 0;
mode = 1;
- if (ti = find_thread((kd->arg5 & KDBG_THREAD_MASK), 0, 0)) {
+ if ((ti = find_thread(kd->arg5, 0, 0))) {
if (ti->type == -1 && strcmp(command, "kernel_task"))
mode = 0;
}
case MACH_sched:
case MACH_stkhandoff:
- if (map = find_thread_map(kd->arg2))
+ if ((map = find_thread_map(kd->arg2)))
strcpy(command1, map->command);
else
sprintf(command1, "%-8x", kd->arg2);
- if (ti = find_thread(kd->arg2, 0, 0)) {
+ if ((ti = find_thread(kd->arg2, 0, 0))) {
if (ti->type == -1 && strcmp(command1, "kernel_task"))
p = "U";
else
FILE *fp = (FILE *)0;
char tmp_nm_file[128];
char tmpstr[1024];
- int inchr;
+ char inchr;
bzero(tmp_nm_file, 128);
bzero(tmpstr, 1024);
for (i=0; i<kern_sym_count; i++)
{
bzero(tmpstr, 1024);
- if (fscanf(fp, "%x %c %s", &kern_sym_tbl[i].k_sym_addr, &inchr, tmpstr) != 3)
+ if (fscanf(fp, "%lx %c %s", &kern_sym_tbl[i].k_sym_addr, &inchr, tmpstr) != 3)
break;
else
{
len = max_len - 8;
memcpy(pcstring, kern_sym_tbl[ret].k_sym_name, len);
- sprintf(&pcstring[len], "+0x%-5x", pc - kern_sym_tbl[ret].k_sym_addr);
+ sprintf(&pcstring[len], "+0x%-5lx", pc - kern_sym_tbl[ret].k_sym_addr);
return (pcstring);
}