From owner-freebsd-bugs@FreeBSD.ORG Fri Sep 2 18:10:13 2005 Return-Path: X-Original-To: freebsd-bugs@hub.freebsd.org Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5D20716A41F for ; Fri, 2 Sep 2005 18:10:13 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id D913C43D48 for ; Fri, 2 Sep 2005 18:10:12 +0000 (GMT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.13.3/8.13.3) with ESMTP id j82IACOh059892 for ; Fri, 2 Sep 2005 18:10:12 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.13.3/8.13.1/Submit) id j82IACwt059891; Fri, 2 Sep 2005 18:10:12 GMT (envelope-from gnats) Resent-Date: Fri, 2 Sep 2005 18:10:12 GMT Resent-Message-Id: <200509021810.j82IACwt059891@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Ben Thomas Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 53F5D16A41F for ; Fri, 2 Sep 2005 18:01:06 +0000 (GMT) (envelope-from bthomas@virtualiron.com) Received: from mail.virtualiron.com (mail.virtualiron.com [209.213.88.114]) by mx1.FreeBSD.org (Postfix) with ESMTP id E040143D4C for ; Fri, 2 Sep 2005 18:01:05 +0000 (GMT) (envelope-from bthomas@virtualiron.com) Received: from [10.1.2.26] ([10.1.2.26]) by mail.virtualiron.com with Microsoft SMTPSVC(6.0.3790.1830); Fri, 2 Sep 2005 14:01:41 -0400 Message-Id: <43189360.6010304@virtualiron.com> Date: Fri, 02 Sep 2005 14:01:04 -0400 From: Ben Thomas To: FreeBSD-gnats-submit@FreeBSD.org Cc: Subject: kern/85658: [patch] add DDB command, show runq, to sched_ule.c X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Sep 2005 18:10:13 -0000 >Number: 85658 >Category: kern >Synopsis: [patch] add DDB command, show runq, to sched_ule.c >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: change-request >Submitter-Id: current-users >Arrival-Date: Fri Sep 02 18:10:12 GMT 2005 >Closed-Date: >Last-Modified: >Originator: Ben Thomas >Release: FreeBSD 5.4-RELEASE i386 >Organization: Virtual Iron Software >Environment: System: FreeBSD bthomas4.katana-technology.com 5.4-RELEASE FreeBSD 5.4-RELEASE #10: Sun Aug 28 13:48:00 EDT 2005 ben@bthomas4.katana-technology.com:/usr/obj/usr/home/ben/BSD/RELENG_5_4_0_RELEASE/src/sys/BEN i386 >Description: I've found a need to look at the run queues for debugging purposes. After a while, you get tired of running through data structures, and want something a little simpler. This patch adds a "show runq" DDB command that dumps the current run queues. Note that this is for sched_ule.c, which is all we run. I assume that with a little work, it would apply to sched_4bsd. This patch is against the 5_4_0_RELEASE source >How-To-Repeat: >Fix: --- /usr/src.original/sys/kern/sched_ule.c Fri Feb 4 15:13:21 2005 +++ /usr/src/sys/kern/sched_ule.c Fri Aug 5 15:15:38 2005 @@ -51,6 +51,10 @@ #include #include #endif +#include "opt_ddb.h" +#ifdef DDB +#include +#endif #include #include @@ -1922,3 +1926,104 @@ } #define KERN_SWITCH_INCLUDE 1 #include "kern/kern_switch.c" + +/* DDB command to dump run queues */ + +#ifdef DDB + +static void print_runq(struct runq *rq, char *string1, char *string2) +{ + struct rqbits *rqb; + int w; + int b; + int set; + int empty; + struct kse *kse; + int qIndex; + char sep; + + /* Check input arguments */ + + if ( (rq == NULL) || (string1 == NULL) || (string2 == NULL) ) + return; + + db_printf(" Run Queue '%s%s' (%p):\n", string1, string2, rq); + + rqb = &rq->rq_status; + for (w=0; w < RQB_LEN; w++) { + for (b = 0; b < RQB_BPW; b++) { + qIndex = (w * RQB_BPW) + b; + set = rqb->rqb_bits[w] & (1 << b); + empty = TAILQ_EMPTY(&rq->rq_queues[qIndex]); + if (empty) { + if (set) + db_printf(" Pri %3d-%3d: [bit set, but queue is empty]\n", + (qIndex*RQ_PPQ), ((qIndex*RQ_PPQ) + (RQ_PPQ-1))); + continue; + } + db_printf(" Pri %3d-%3d: ", + (qIndex*RQ_PPQ), ((qIndex*RQ_PPQ) + (RQ_PPQ-1))); + if (!set) + db_printf("[queue not empty, but bit NOT set]: "); + + sep = ' '; + TAILQ_FOREACH(kse, &rq->rq_queues[qIndex], ke_procq) { + db_printf("%c %s[%p]", sep, kse->ke_proc->p_comm, kse->ke_thread); + sep= ','; + } + db_printf("\n"); + } + } +} + +DB_SHOW_COMMAND(runq, runq) +{ + int i; + struct kseq *kseq; + struct pcpu *pcpu; + struct thread *td; + + /* Dump the run queues for each CPU */ + + for (i = 0; i < mp_ncpus; i++) { + kseq = &kseq_cpu[i]; + if (kseq == NULL) { + db_printf("? CPU %d has no kseq structure\n", i); + continue; + } + + /* Output basic information */ + + db_printf("CPU %d: Load %d, Load_TimeShare %d", + i, kseq->ksq_load, kseq->ksq_load_timeshare); +#ifdef SMP + db_printf(", Load_Transferrable %d\n", kseq->ksq_transferable); +#else + db_printf(", Load Average %d\n", kseq->ksq_sysload); +#endif + db_printf("\n"); + + /* Print current thread info */ + + pcpu = pcpu_find(i); + if (pcpu != NULL) { + td = pcpu->pc_curthread; + if ( (td != NULL) && (td->td_proc != NULL) ) { + db_printf(" Current thread: %s[%p] Prio: %d\n", td->td_proc->p_comm, td, td->td_priority); + } + } + + /* Now, dump each of the queues */ + + print_runq(&kseq->ksq_idle, "Idle", ""); + + print_runq(&kseq->ksq_timeshare[0], "Timeshare[0]", + ((kseq->ksq_curr == &kseq->ksq_timeshare[0]) ? " [Curr]" : " [Next]")); + + print_runq(&kseq->ksq_timeshare[1], "Timeshare[1]", + ((kseq->ksq_curr == &kseq->ksq_timeshare[1]) ? " [Curr]" : " [Next]")); + db_printf("\n"); + } + +} +#endif >Release-Note: >Audit-Trail: >Unformatted: