Commit Graph

40 Commits

Author SHA1 Message Date
christos a91d6c6d0a Unbreak sched_m2 (died because lwp_eproc() KASSERT in DIAGNOSTIC) and explain
what is going on. This has been broken since the introduction of l_mutex
5 months ago.
2024-01-24 16:11:48 +00:00
ad d4834fad58 Oops. If a SCHED_RR thread is preempted and has exceeded its timeslice it
needs to go to the back of the run queue so round-robin actually happens,
otherwise it should go to the front.
2020-05-23 21:24:41 +00:00
maxv 983fd9ccfe hardclock_ticks -> getticks() 2020-04-13 15:54:45 +00:00
ad 4c55fef0a6 sched_tick(): don't try to optimise something that's called 10 times a
second, it's a fine way to introduce bugs (and I did).  Use the MI
interface for rescheduling which always does the correct thing.
2019-12-06 18:33:19 +00:00
ad 57eb66c673 Fix false sharing problems with cpu_info. Identified with tprof(8).
This was a very nice win in my tests on a 48 CPU box.

- Reorganise cpu_data slightly according to usage.
- Put cpu_onproc into struct cpu_info alongside ci_curlwp (now is ci_onproc).
- On x86, put some items in their own cache lines according to usage, like
  the IPI bitmask and ci_want_resched.
2019-12-01 15:34:44 +00:00
ad 036b61e0aa PR port-sparc/54718 (sparc install hangs since recent scheduler changes)
- sched_tick: cpu_need_resched is no longer the correct thing to do here.
  All we need to do is OR the request into the local ci_want_resched.

- sched_resched_cpu: we need to set RESCHED_UPREEMPT even on softint LWPs,
  especially in the !__HAVE_FAST_SOFTINTS case, because the LWP with the
  LP_INTR flag could be running via softint_overlay() - i.e. it has been
  temporarily borrowed from a user process, and it needs to notice the
  resched after it has stopped running softints.
2019-12-01 13:20:42 +00:00
ad 398a7522b9 sched_tick: examine the correct LWP, and lock it. 2019-11-22 20:07:53 +00:00
riastradh d1579b2d70 Rename min/max -> uimin/uimax for better honesty.
These functions are defined on unsigned int.  The generic name
min/max should not silently truncate to 32 bits on 64-bit systems.
This is purely a name change -- no functional change intended.

HOWEVER!  Some subsystems have

	#define min(a, b)	((a) < (b) ? (a) : (b))
	#define max(a, b)	((a) > (b) ? (a) : (b))

even though our standard name for that is MIN/MAX.  Although these
may invite multiple evaluation bugs, these do _not_ cause integer
truncation.

To avoid `fixing' these cases, I first changed the name in libkern,
and then compile-tested every file where min/max occurred in order to
confirm that it failed -- and thus confirm that nothing shadowed
min/max -- before changing it.

I have left a handful of bootloaders that are too annoying to
compile-test, and some dead code:

cobalt ews4800mips hp300 hppa ia64 luna68k vax
acorn32/if_ie.c (not included in any kernels)
macppc/if_gm.c (superseded by gem(4))

It should be easy to fix the fallout once identified -- this way of
doing things fails safe, and the goal here, after all, is to _avoid_
silent integer truncations, not introduce them.

Maybe one day we can reintroduce min/max as type-generic things that
never silently truncate.  But we should avoid doing that for a while,
so that existing code has a chance to be detected by the compiler for
conversion to uimin/uimax without changing the semantics until we can
properly audit it all.  (Who knows, maybe in some cases integer
truncation is actually intended!)
2018-09-03 16:29:22 +00:00
maxv b61ced9fc0 'miliseconds' -> 'milliseconds'. 2014-06-24 10:08:45 +00:00
pooka 4f6fb3bf35 Ensure that the top level sysctl nodes (kern, vfs, net, ...) exist before
the sysctl link sets are processed, and remove redundancy.

Shaves >13kB off of an amd64 GENERIC, not to mention >1k duplicate
lines of code.
2014-02-25 18:30:08 +00:00
christos 87e56634fd This is no place to attach the primary cpu. Things go wrong from here because
for example it is missing its name.
2011-09-16 01:03:52 +00:00
mbalmer 0ae57f90dd more s/the the/the/ 2009-11-22 19:09:15 +00:00
joerg 73df1b22f7 Remove unused include. 2009-07-06 12:37:17 +00:00
rmind 65af07bb0c Make SCHED_M2 nice with nice(1). Closes PR/38048. 2008-10-18 03:44:04 +00:00
rmind 337b081fed - Replace lwp_t::l_sched_info with union: pointer and timeslice.
- Change minimal time-quantum to ~20 ms.
- Thus remove unneeded pool in M2, and unused sched_lwp_exit().
- Do not increase l_slptime twice for SCHED_4BSD (regression fix).
2008-10-07 09:48:27 +00:00
rmind 5f701aa0a3 - Make periodical balancing mandatory.
- Fix priority raising in M2 (broken after making runqueues mandatory).
2008-05-19 12:48:54 +00:00
ad 06e0894e76 Take the run queue management code from the M2 scheduler, and make it
mandatory. Remove the 4BSD run queue code. Effects:

- Pluggable scheduler is only responsible for co-ordinating timeshared jobs.
- All systems run with per-CPU run queues.
- 4BSD scheduler gets processor sets / affinity.
- 4BSD scheduler gets a significant peformance boost on some workloads.

Discussed on tech-kern@.
2008-04-12 17:02:08 +00:00
ad feb4783fdf Replace use of CACHE_LINE_SIZE in some obvious places. 2008-03-27 18:30:15 +00:00
rmind ca99f7a582 - Perform periodical balancing of CPU-bound threads, which tends to
never sleep.  Should fix PR/37245 by <yamt>.
- Fix a regression - dissalow catching of bound threads.  Also, allow
  migration of non-bound kthreads, this restriction seems pointless.
- Few micro-optimisations, misc.
2008-03-11 18:18:49 +00:00
martin d8788e7fd7 Use cpu index instead of the machine dependend, not very expressive
cpuid when naming user-visible kernel entities.
2008-03-10 22:20:14 +00:00
ad 60c1b8843d Make schedstate_percpu::spc_lwplock an exernally allocated item. Remove
the hacks in sparc/cpu.c to reinitialize it. This should be in its own
cache line but that's another change.
2008-02-14 14:26:57 +00:00
rmind fb513e5cf5 - sched_cpuattach: fix address calculation, use roundup2();
Fixes the problems with systems having > 2GB of memory;
  From <drochner>, thanks for catching this!
- Convert pool to pool-cache;
- Adjust copyright while here;
2008-01-31 00:46:55 +00:00
rmind 855e8f35f6 sched_slept: Revert inclusion of PRI_HIGHEST_TS into the range.
Reported by <drochner>.
2008-01-15 18:41:37 +00:00
rmind 78e6c5f3f6 Remove PRI_DEFAULT, which was left previously..
Note: nice(1) is only for historical purposes, schedctl(8) should be used.
2008-01-15 16:14:19 +00:00
rmind f5c269bd3e - Estimate cache-hotness in all states, except LSIDL;
- Include PRI_HIGHEST_TS value into the increasion range,
  it was missed previously by mistake;
- More KASSERTs to handle invalid priorities of threads;
- Remove PRI_DEFAULT;
- Misc;
2008-01-15 04:16:27 +00:00
rmind 5c71a4d49f Implementation of processor-sets, affinity and POSIX real-time extensions.
Add schedctl(8) - a program to control scheduling of processes and threads.

Notes:
- This is supported only by SCHED_M2;
- Migration of LWP mechanism will be revisited;

Proposed on: <tech-kern>. Reviewed by: <ad>.
2008-01-15 03:37:10 +00:00
ad 5b42fe1209 KM_NOSLEEP -> KM_SLEEP for clarity. 2007-12-21 12:05:39 +00:00
ad 598ab03ad0 Match the docs: MUTEX_DRIVER/SPIN are now only for porting code written
for Solaris.
2007-12-05 07:06:50 +00:00
rmind c75dc3277a Unify the license: All rights reserved.
No functional change.
2007-11-28 19:30:55 +00:00
rmind b68c6d084f Modifications for the recent vmlocking changes:
- Re-enqueue the thread when priority changes and it is in LSRUN state;
- Handle the __HAVE_FAST_SOFTINTS case in sched_curcpu_runnable_p();
- Few minor changes;
2007-11-07 03:07:14 +00:00
ad d831186d55 Merge scheduler changes from the vmlocking branch. All discussed on
tech-kern:

- Invert priority space so that zero is the lowest priority. Rearrange
  number and type of priority levels into bands. Add new bands like
  'kernel real time'.
- Ignore the priority level passed to tsleep. Compute priority for
  sleep dynamically.
- For SCHED_4BSD, make priority adjustment per-LWP, not per-process.
2007-11-06 00:42:39 +00:00
rmind 823cbaa23b Fix sysctl_createv "pasto" in previous. 2007-11-04 14:15:34 +00:00
rmind fc4b6513fa - sched_setup: use ilog2() for min_catch, which fixes the case when count
of CPU is non-power of 2.  Fixes PR/37244.
- sched_enqueue: initialize sl_lrtime, when it is zero (new thread).
  Part of PR/37245.
- Fix the mints/maxts sysctl helpers, use mstohz() for the checks.  Also,
  I meant miliseconds, not microseconds.  Found by <bjs>.
2007-11-04 12:36:01 +00:00
rmind 7c0340a739 - Migrate all threads when the state of CPU is changed to offline;
- Fix inverted logic with r_mcount in M2;
- setrunnable: perform sched_takecpu() when making the LWP runnable;
- setrunnable: l_mutex cannot be spc_mutex here;

This makes cpuctl(8) work with SCHED_M2.

OK by <ad>.
2007-11-04 11:43:07 +00:00
ad a2a3828545 machine/{bus,cpu,intr}.h -> sys/{bus,cpu,intr}.h 2007-10-19 11:59:34 +00:00
yamt 2171d72e8b fix typos in a comment. 2007-10-14 13:56:32 +00:00
yamt 2ea5c00ae9 sched_wakeup: remove a wrong assertion. 2007-10-13 12:05:32 +00:00
rmind a416e41211 sched_catchlwp: Estimate the pointers of CPU structures, not spc_mutex'es,
when double-locking the runqueues.
2007-10-10 22:21:17 +00:00
rmind 03d447f116 sched_tick: There is no need to re-schedule in a case when
CURCPU_IDLE_P() is true.  Simplify a little bit.

OK by <ad>.
2007-10-10 21:24:53 +00:00
rmind a21233e46b Import of SCHED_M2 - the implementation of new scheduler, which is based
on the original approach of SVR4 with some inspirations about balancing
and migration from Solaris.  It implements per-CPU runqueues, provides a
real-time (RT) and time-sharing (TS) queues, ready to support a POSIX
real-time extensions, and also prepared for the support of CPU affinity.

The following lines in the kernel config enables the SCHED_M2:

no options SCHED_4BSD
options SCHED_M2

The scheduler seems to be stable.  Further work will come soon.

http://mail-index.netbsd.org/tech-kern/2007/10/04/0001.html
http://www.netbsd.org/~rmind/m2/mysql_bench_ro_4x_local.png
Thanks <ad> for the benchmarks!
2007-10-09 19:00:13 +00:00