Deleted Added
full compact
kern_switch.c (178961) kern_switch.c (194936)
1/*-
2 * Copyright (c) 2001 Jake Burkholder <jake@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27
28#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2001 Jake Burkholder <jake@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 12 unchanged lines hidden (view full) ---

21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27
28#include <sys/cdefs.h>
29__FBSDID("$FreeBSD: head/sys/kern/kern_switch.c 178961 2008-05-12 06:42:06Z julian $");
29__FBSDID("$FreeBSD: head/sys/kern/kern_switch.c 194936 2009-06-25 01:33:51Z jeff $");
30
31#include "opt_sched.h"
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/kdb.h>
36#include <sys/kernel.h>
37#include <sys/ktr.h>

--- 36 unchanged lines hidden (view full) ---

74 &kern_sched_preemption, 0, "Kernel preemption enabled");
75
76/*
77 * Support for scheduler stats exported via kern.sched.stats. All stats may
78 * be reset with kern.sched.stats.reset = 1. Stats may be defined elsewhere
79 * with SCHED_STAT_DEFINE().
80 */
81#ifdef SCHED_STATS
30
31#include "opt_sched.h"
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/kdb.h>
36#include <sys/kernel.h>
37#include <sys/ktr.h>

--- 36 unchanged lines hidden (view full) ---

74 &kern_sched_preemption, 0, "Kernel preemption enabled");
75
76/*
77 * Support for scheduler stats exported via kern.sched.stats. All stats may
78 * be reset with kern.sched.stats.reset = 1. Stats may be defined elsewhere
79 * with SCHED_STAT_DEFINE().
80 */
81#ifdef SCHED_STATS
82long sched_switch_stats[SWT_COUNT]; /* Switch reasons from mi_switch(). */
83
84SYSCTL_NODE(_kern_sched, OID_AUTO, stats, CTLFLAG_RW, 0, "switch stats");
82SYSCTL_NODE(_kern_sched, OID_AUTO, stats, CTLFLAG_RW, 0, "switch stats");
85SCHED_STAT_DEFINE_VAR(uncategorized, &sched_switch_stats[SWT_NONE], "");
86SCHED_STAT_DEFINE_VAR(preempt, &sched_switch_stats[SWT_PREEMPT], "");
87SCHED_STAT_DEFINE_VAR(owepreempt, &sched_switch_stats[SWT_OWEPREEMPT], "");
88SCHED_STAT_DEFINE_VAR(turnstile, &sched_switch_stats[SWT_TURNSTILE], "");
89SCHED_STAT_DEFINE_VAR(sleepq, &sched_switch_stats[SWT_SLEEPQ], "");
90SCHED_STAT_DEFINE_VAR(sleepqtimo, &sched_switch_stats[SWT_SLEEPQTIMO], "");
91SCHED_STAT_DEFINE_VAR(relinquish, &sched_switch_stats[SWT_RELINQUISH], "");
92SCHED_STAT_DEFINE_VAR(needresched, &sched_switch_stats[SWT_NEEDRESCHED], "");
93SCHED_STAT_DEFINE_VAR(idle, &sched_switch_stats[SWT_IDLE], "");
94SCHED_STAT_DEFINE_VAR(iwait, &sched_switch_stats[SWT_IWAIT], "");
95SCHED_STAT_DEFINE_VAR(suspend, &sched_switch_stats[SWT_SUSPEND], "");
96SCHED_STAT_DEFINE_VAR(remotepreempt, &sched_switch_stats[SWT_REMOTEPREEMPT],
97 "");
98SCHED_STAT_DEFINE_VAR(remotewakeidle, &sched_switch_stats[SWT_REMOTEWAKEIDLE],
99 "");
100
83
84/* Switch reasons from mi_switch(). */
85DPCPU_DEFINE(long, sched_switch_stats[SWT_COUNT]);
86SCHED_STAT_DEFINE_VAR(uncategorized,
87 &DPCPU_NAME(sched_switch_stats[SWT_NONE]), "");
88SCHED_STAT_DEFINE_VAR(preempt,
89 &DPCPU_NAME(sched_switch_stats[SWT_PREEMPT]), "");
90SCHED_STAT_DEFINE_VAR(owepreempt,
91 &DPCPU_NAME(sched_switch_stats[SWT_OWEPREEMPT]), "");
92SCHED_STAT_DEFINE_VAR(turnstile,
93 &DPCPU_NAME(sched_switch_stats[SWT_TURNSTILE]), "");
94SCHED_STAT_DEFINE_VAR(sleepq,
95 &DPCPU_NAME(sched_switch_stats[SWT_SLEEPQ]), "");
96SCHED_STAT_DEFINE_VAR(sleepqtimo,
97 &DPCPU_NAME(sched_switch_stats[SWT_SLEEPQTIMO]), "");
98SCHED_STAT_DEFINE_VAR(relinquish,
99 &DPCPU_NAME(sched_switch_stats[SWT_RELINQUISH]), "");
100SCHED_STAT_DEFINE_VAR(needresched,
101 &DPCPU_NAME(sched_switch_stats[SWT_NEEDRESCHED]), "");
102SCHED_STAT_DEFINE_VAR(idle,
103 &DPCPU_NAME(sched_switch_stats[SWT_IDLE]), "");
104SCHED_STAT_DEFINE_VAR(iwait,
105 &DPCPU_NAME(sched_switch_stats[SWT_IWAIT]), "");
106SCHED_STAT_DEFINE_VAR(suspend,
107 &DPCPU_NAME(sched_switch_stats[SWT_SUSPEND]), "");
108SCHED_STAT_DEFINE_VAR(remotepreempt,
109 &DPCPU_NAME(sched_switch_stats[SWT_REMOTEPREEMPT]), "");
110SCHED_STAT_DEFINE_VAR(remotewakeidle,
111 &DPCPU_NAME(sched_switch_stats[SWT_REMOTEWAKEIDLE]), "");
112
101static int
102sysctl_stats_reset(SYSCTL_HANDLER_ARGS)
103{
104 struct sysctl_oid *p;
113static int
114sysctl_stats_reset(SYSCTL_HANDLER_ARGS)
115{
116 struct sysctl_oid *p;
117 uintptr_t counter;
105 int error;
106 int val;
118 int error;
119 int val;
120 int i;
107
108 val = 0;
109 error = sysctl_handle_int(oidp, &val, 0, req);
110 if (error != 0 || req->newptr == NULL)
111 return (error);
112 if (val == 0)
113 return (0);
114 /*
115 * Traverse the list of children of _kern_sched_stats and reset each
116 * to 0. Skip the reset entry.
117 */
118 SLIST_FOREACH(p, oidp->oid_parent, oid_link) {
119 if (p == oidp || p->oid_arg1 == NULL)
120 continue;
121
122 val = 0;
123 error = sysctl_handle_int(oidp, &val, 0, req);
124 if (error != 0 || req->newptr == NULL)
125 return (error);
126 if (val == 0)
127 return (0);
128 /*
129 * Traverse the list of children of _kern_sched_stats and reset each
130 * to 0. Skip the reset entry.
131 */
132 SLIST_FOREACH(p, oidp->oid_parent, oid_link) {
133 if (p == oidp || p->oid_arg1 == NULL)
134 continue;
121 *(long *)p->oid_arg1 = 0;
135 counter = (uintptr_t)p->oid_arg1;
136 for (i = 0; i <= mp_maxid; i++) {
137 if (CPU_ABSENT(i))
138 continue;
139 *(long *)(dpcpu_off[i] + counter) = 0;
140 }
122 }
123 return (0);
124}
125
126SYSCTL_PROC(_kern_sched_stats, OID_AUTO, reset, CTLTYPE_INT | CTLFLAG_WR, NULL,
127 0, sysctl_stats_reset, "I", "Reset scheduler statistics");
128#endif
129

--- 361 unchanged lines hidden ---
141 }
142 return (0);
143}
144
145SYSCTL_PROC(_kern_sched_stats, OID_AUTO, reset, CTLTYPE_INT | CTLFLAG_WR, NULL,
146 0, sysctl_stats_reset, "I", "Reset scheduler statistics");
147#endif
148

--- 361 unchanged lines hidden ---