Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F162029651
D58000.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D58000.id.diff
View Options
diff --git a/sys/kern/sched_4bsd.c b/sys/kern/sched_4bsd.c
--- a/sys/kern/sched_4bsd.c
+++ b/sys/kern/sched_4bsd.c
@@ -97,7 +97,7 @@
int ts_slptime; /* Seconds !RUNNING. */
int ts_slice; /* Remaining part of time slice. */
int ts_flags;
- struct runq *ts_runq; /* runq the thread is currently on */
+ int ts_rqcpu; /* That CPU's runq or NOCPU => global */
#ifdef KTR
char ts_name[TS_NAME_LEN];
#endif
@@ -113,8 +113,12 @@
/* flags kept in ts_flags */
#define TSF_AFFINITY 0x0001 /* Has a non-"full" CPU set. */
-#define SKE_RUNQ_PCPU(ts) \
- ((ts)->ts_runq != 0 && (ts)->ts_runq != &runq_global)
+#ifdef SMP
+#define TS_RUNQ_PTR(ts) ((ts)->ts_rqcpu == NOCPU ? \
+ (&runq_global) : (DPCPU_ID_PTR((ts)->ts_rqcpu, runq_pcpu)))
+#else
+#define TS_RUNQ_PTR(ts) (&runq_global)
+#endif
#define THREAD_CAN_SCHED(td, cpu) \
CPU_ISSET((cpu), &(td)->td_cpuset->cs_mask)
@@ -164,8 +168,8 @@
/*
* Per-CPU run queues
*/
-static struct runq runq_pcpu[MAXCPU];
-long runq_length[MAXCPU];
+DPCPU_DEFINE_STATIC(struct runq, runq_pcpu);
+DPCPU_DEFINE_STATIC(long, runq_length);
static cpuset_t idle_cpus_mask;
#endif
@@ -180,10 +184,10 @@
setup_runqs(void)
{
#ifdef SMP
- int i;
+ int cpu;
- for (i = 0; i < MAXCPU; ++i)
- runq_init(&runq_pcpu[i]);
+ CPU_FOREACH(cpu)
+ runq_init(DPCPU_ID_PTR(cpu, runq_pcpu));
#endif
runq_init(&runq_global);
@@ -685,7 +689,7 @@
{
#ifdef SMP
return (runq_not_empty(&runq_global) ||
- runq_not_empty(&runq_pcpu[PCPU_GET(cpuid)]));
+ runq_not_empty(DPCPU_PTR(runq_pcpu)));
#else
return (runq_not_empty(&runq_global));
#endif
@@ -1294,7 +1298,7 @@
if (best == NOCPU)
best = cpu;
- else if (runq_length[cpu] < runq_length[best])
+ else if (DPCPU_ID_GET(cpu, runq_length) < DPCPU_ID_GET(best, runq_length))
best = cpu;
}
KASSERT(best != NOCPU, ("no valid CPUs"));
@@ -1358,13 +1362,13 @@
cpu = td->td_lastcpu;
else if (td->td_flags & TDF_BOUND) {
/* Find CPU from bound runq. */
- KASSERT(SKE_RUNQ_PCPU(ts),
+ KASSERT(ts->ts_rqcpu == NOCPU,
("sched_add: bound td_sched not on cpu runq"));
- cpu = ts->ts_runq - &runq_pcpu[0];
+ cpu = ts->ts_rqcpu;
} else
/* Find a valid CPU for our cpuset */
cpu = sched_pickcpu(td);
- ts->ts_runq = &runq_pcpu[cpu];
+ ts->ts_rqcpu = cpu;
single_cpu = 1;
CTR3(KTR_RUNQ,
"sched_add: Put td_sched:%p(td:%p) on cpu%d runq", ts, td,
@@ -1374,14 +1378,14 @@
"sched_add: adding td_sched:%p (td:%p) to gbl runq", ts,
td);
cpu = NOCPU;
- ts->ts_runq = &runq_global;
+ ts->ts_rqcpu = NOCPU;
}
if ((td->td_flags & TDF_NOLOAD) == 0)
sched_load_add();
- runq_add(ts->ts_runq, td, flags);
+ runq_add(TS_RUNQ_PTR(ts), td, flags);
if (cpu != NOCPU)
- runq_length[cpu]++;
+ (*DPCPU_ID_PTR(cpu, runq_length))++;
cpuid = PCPU_GET(cpuid);
if (single_cpu && cpu != cpuid) {
@@ -1439,11 +1443,11 @@
}
TD_SET_RUNQ(td);
CTR2(KTR_RUNQ, "sched_add: adding td_sched:%p (td:%p) to runq", ts, td);
- ts->ts_runq = &runq_global;
+ ts->ts_rqcpu = NOCPU;
if ((td->td_flags & TDF_NOLOAD) == 0)
sched_load_add();
- runq_add(ts->ts_runq, td, flags);
+ runq_add(TS_RUNQ_PTR(ts), td, flags);
if (!maybe_preempt(td))
maybe_resched(td);
if ((flags & SRQ_HOLDTD) == 0)
@@ -1470,10 +1474,10 @@
if ((td->td_flags & TDF_NOLOAD) == 0)
sched_load_rem();
#ifdef SMP
- if (ts->ts_runq != &runq_global)
- runq_length[ts->ts_runq - runq_pcpu]--;
+ if (ts->ts_rqcpu != NOCPU)
+ (*DPCPU_ID_PTR(ts->ts_rqcpu, runq_length))--;
#endif
- runq_remove(ts->ts_runq, td);
+ runq_remove(TS_RUNQ_PTR(ts), td);
TD_SET_CAN_RUN(td);
}
@@ -1493,7 +1497,7 @@
runq = &runq_global;
td = runq_choose_fuzz(&runq_global, runq_fuzz);
- tdcpu = runq_choose(&runq_pcpu[PCPU_GET(cpuid)]);
+ tdcpu = runq_choose(DPCPU_PTR(runq_pcpu));
if (td == NULL ||
(tdcpu != NULL &&
@@ -1501,7 +1505,7 @@
CTR2(KTR_RUNQ, "choosing td %p from pcpu runq %d", tdcpu,
PCPU_GET(cpuid));
td = tdcpu;
- runq = &runq_pcpu[PCPU_GET(cpuid)];
+ runq = DPCPU_PTR(runq_pcpu);
} else {
CTR1(KTR_RUNQ, "choosing td_sched %p from main runq", td);
}
@@ -1514,7 +1518,7 @@
if (td) {
#ifdef SMP
if (td == tdcpu)
- runq_length[PCPU_GET(cpuid)]--;
+ (*DPCPU_PTR(runq_length))--;
#endif
runq_remove(runq, td);
td->td_flags |= TDF_DIDRUN;
@@ -1565,7 +1569,7 @@
td->td_flags |= TDF_BOUND;
#ifdef SMP
- ts->ts_runq = &runq_pcpu[cpu];
+ ts->ts_rqcpu = cpu;
if (PCPU_GET(cpuid) == cpu)
return;
@@ -1798,8 +1802,7 @@
* If we are on a per-CPU runqueue that is in the set,
* then nothing needs to be done.
*/
- if (ts->ts_runq != &runq_global &&
- THREAD_CAN_SCHED(td, ts->ts_runq - runq_pcpu))
+ if (ts->ts_rqcpu != NOCPU && THREAD_CAN_SCHED(td, ts->ts_rqcpu))
return;
/* Put this thread on a valid per-CPU runqueue. */
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Jul 10, 2:05 AM (6 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
34859438
Default Alt Text
D58000.id.diff (4 KB)
Attached To
Mode
D58000: sched_4bsd: use DPCPU for runq
Attached
Detach File
Event Timeline
Log In to Comment