From bthomas@virtualiron.com  Fri Sep  2 18:01:06 2005
Return-Path: <bthomas@virtualiron.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 53F5D16A41F
	for <FreeBSD-gnats-submit@freebsd.org>; 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 <FreeBSD-gnats-submit@freebsd.org>; 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 <bthomas@virtualiron.com>
To: FreeBSD-gnats-submit@freebsd.org
Subject: [patch] add DDB command, show runq, to sched_ule.c

>Number:         85658
>Category:       kern
>Synopsis:       [sched_ule] [patch] add DDB command, show runq, to sched_ule.c
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    jeff
>State:          suspended
>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:  Sun Mar 02 02:33:16 UTC 2008
>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 <sys/uio.h>
 #include <sys/ktrace.h>
 #endif
+#include "opt_ddb.h"
+#ifdef DDB
+#include <ddb/ddb.h>
+#endif

 #include <machine/cpu.h>
 #include <machine/smp.h>
@@ -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:
Responsible-Changed-From-To: freebsd-bugs->jeff 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Mon Oct 24 00:16:16 GMT 2005 
Responsible-Changed-Why:  
Over to maintainer. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=85658 
State-Changed-From-To: open->feedback 
State-Changed-By: linimon 
State-Changed-When: Wed Mar 14 22:25:33 UTC 2007 
State-Changed-Why:  
The ULE scheduler has been extensively upgraded in -CURRENT.  Does this 
patch still apply? 

http://www.freebsd.org/cgi/query-pr.cgi?pr=85658 

From: Ben Thomas <thomas@computer.org>
To: bug-followup@FreeBSD.org,  bthomas@virtualiron.com
Cc:  
Subject: Re: kern/85658: [sched_ule] [patch] add DDB command, show runq, to
 sched_ule.c
Date: Wed, 14 Mar 2007 22:06:52 -0400

 Why:	The ULE scheduler has been extensively upgraded in -CURRENT. Does this
 patch still apply?
 
 
 I really don't know. I submitted this about 18 months ago. I'm sure
 that a lot has changed.
 
 -b
State-Changed-From-To: feedback->suspended 
State-Changed-By: linimon 
State-Changed-When: Sun Mar 2 02:32:21 UTC 2008 
State-Changed-Why:  
No more recent patch is available.  It does not sound as though the 
functionality has been added. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=85658 
>Unformatted:
