summaryrefslogtreecommitdiff
path: root/sys/kern/kern_clock.c
Commit message (Collapse)AuthorAgeFilesLines
* Initialize time_lock before calling cpu_initclocks(). This corrects aRobert Watson2007-05-231-1/+1
| | | | | | | | | | race condition in which hardclock fires before the mutex is initialized leading to a "corrupt spinlock" panic. Submitted by: attilio Notes: svn path=/head/; revision=169906
* - Move clock synchronization into a seperate clock lock so the globalJeff Roberson2007-05-201-10/+13
| | | | | | | | | | | scheduler lock is not involved. sched_lock still protects the sched_clock call. Another patch will remedy this. Contributed by: Attilio Rao <attilio@FreeBSD.org> Tested by: kris, jeff Notes: svn path=/head/; revision=169803
* Instead of doing comparisons using the pcpu area to see ifJulian Elischer2007-03-081-1/+1
| | | | | | | | | | a thread is an idle thread, just see if it has the IDLETD flag set. That flag will probably move to the pflags word as it's permenent and never chenges for the life of the system so it doesn't need locking. Notes: svn path=/head/; revision=167327
* Align the interfaces for the various watchdogs and make the interfaceNick Hibma2006-12-151-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | behave as expected. Also: - Return an error if WD_PASSIVE is passed in to the ioctl as only WD_ACTIVE is implemented at the moment. See sys/watchdog.h for an explanation of the difference between WD_ACTIVE and WD_PASSIVE. - Remove the I_HAVE_TOTALLY_LOST_MY_SENSE_OF_HUMOR define. If you've lost your sense of humor, than don't add a define. Specific changes: i80321_wdog.c Don't roll your own passive watchdog tickle as this would defeat the purpose of an active (userland) watchdog tickle. ichwd.c / ipmi.c: WD_ACTIVE means active patting of the watchdog by a userland process, not whether the watchdog is active. See sys/watchdog.h. kern_clock.c: (software watchdog) Remove a check for WD_ACTIVE as this does not make sense here. This reverts r1.181. Notes: svn path=/head/; revision=165260
* Threading cleanup.. part 2 of several.Julian Elischer2006-12-061-16/+4
| | | | | | | | | | | | | | | | | | | | | | | | | Make part of John Birrell's KSE patch permanent.. Specifically, remove: Any reference of the ksegrp structure. This feature was never fully utilised and made things overly complicated. All code in the scheduler that tried to make threaded programs fair to unthreaded programs. Libpthread processes will already do this to some extent and libthr processes already disable it. Also: Since this makes such a big change to the scheduler(s), take the opportunity to rename some structures and elements that had to be moved anyhow. This makes the code a lot more readable. The ULE scheduler compiles again but I have no idea if it works. The 4bsd scheduler still reqires a little cleaning and some functions that now do ALMOST nothing will go away, but I thought I'd do that as a separate commit. Tested by David Xu, and Dan Eischen using libthr and libpthread. Notes: svn path=/head/; revision=164936
* Make KSE a kernel option, turned on by default in all GENERICJohn Birrell2006-10-261-0/+19
| | | | | | | | | | kernel configs except sun4v (which doesn't process signals properly with KSE). Reviewed by: davidxu@ Notes: svn path=/head/; revision=163709
* Unexpand an instance of TAILQ_EMPTY()Xin LI2006-06-141-1/+1
| | | | Notes: svn path=/head/; revision=159598
* Add scheduler CORE, the work I have done half a year ago, recent,David Xu2006-06-131-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | I picked it up again. The scheduler is forked from ULE, but the algorithm to detect an interactive process is almost completely different with ULE, it comes from Linux paper "Understanding the Linux 2.6.8.1 CPU Scheduler", although I still use same word "score" as a priority boost in ULE scheduler. Briefly, the scheduler has following characteristic: 1. Timesharing process's nice value is seriously respected, timeslice and interaction detecting algorithm are based on nice value. 2. per-cpu scheduling queue and load balancing. 3. O(1) scheduling. 4. Some cpu affinity code in wakeup path. 5. Support POSIX SCHED_FIFO and SCHED_RR. Unlike scheduler 4BSD and ULE which using fuzzy RQ_PPQ, the scheduler uses 256 priority queues. Unlike ULE which using pull and push, the scheduelr uses pull method, the main reason is to let relative idle cpu do the work, but current the whole scheduler is protected by the big sched_lock, so the benefit is not visible, it really can be worse than nothing because all other cpu are locked out when we are doing balancing work, which the 4BSD scheduelr does not have this problem. The scheduler does not support hyperthreading very well, in fact, the scheduler does not make the difference between physical CPU and logical CPU, this should be improved in feature. The scheduler has priority inversion problem on MP machine, it is not good for realtime scheduling, it can cause realtime process starving. As a result, it seems the MySQL super-smack runs better on my Pentium-D machine when using libthr, despite on UP or SMP kernel. Notes: svn path=/head/; revision=159570
* Trim trailing whitespace.John Baldwin2006-04-171-3/+3
| | | | Notes: svn path=/head/; revision=157822
* CPU time accounting speedup (step 2)Poul-Henning Kamp2006-02-111-3/+3
| | | | | | | | | | | | | | | | | | | | | | Keep accounting time (in per-cpu) cputicks and the statistics counts in the thread and summarize into struct proc when at context switch. Don't reach across CPUs in calcru(). Add code to calibrate the top speed of cpu_tickrate() for variable cpu_tick hardware (like TSC on power managed machines). Don't enforce monotonicity (at least for now) in calcru. While the calibrated cpu_tickrate ramps up it may not be true. Use 27MHz counter on i386/Geode. Use TSC on amd64 & i386 if present. Use tick counter on sparc64 Notes: svn path=/head/; revision=155534
* Simplify system time accounting for profiling.Poul-Henning Kamp2006-02-081-1/+1
| | | | | | | | | | | | | Rename struct thread's td_sticks to td_pticks, we will need the other name for more appropriately named use shortly. Reduce it from uint64_t to u_int. Clear td_pticks whenever we enter the kernel instead of recording its value as reference for userret(). Use the absolute value of td->pticks in userret() and eliminate third argument. Notes: svn path=/head/; revision=155455
* Tweak how the MD code calls the fooclock() methods some. Instead ofJohn Baldwin2005-12-221-22/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | passing a pointer to an opaque clockframe structure and requiring the MD code to supply CLKF_FOO() macros to extract needed values out of the opaque structure, just pass the needed values directly. In practice this means passing the pair (usermode, pc) to hardclock() and profclock() and passing the boolean (usermode) to hardclock_cpu() and hardclock_process(). Other details: - Axe clockframe and CLKF_FOO() macros on all architectures. Basically, all the archs were taking a trapframe and converting it into a clockframe one way or another. Now they can just extract the PC and usermode values directly out of the trapframe and pass it to fooclock(). - Renamed hardclock_process() to hardclock_cpu() as the latter is more accurate. - On Alpha, we now run profclock() at hz (profhz == hz) rather than at the slower stathz. - On Alpha, for the TurboLaser machines that don't have an 8254 timecounter, call hardclock() directly. This removes an extra conditional check from every clock interrupt on Alpha on the BSP. There is probably room for even further pruning here by changing Alpha to use the simplified timecounter we use on x86 with the lapic timer since we don't get interrupts from the 8254 on Alpha anyway. - On x86, clkintr() shouldn't ever be called now unless using_lapic_timer is false, so add a KASSERT() to that affect and remove a condition to slightly optimize the non-lapic case. - Change prototypeof arm_handler_execute() so that it's first arg is a trapframe pointer rather than a void pointer for clarity. - Use KCOUNT macro in profclock() to lookup the kernel profiling bucket. Tested on: alpha, amd64, arm, i386, ia64, sparc64 Reviewed by: bde (mostly) Notes: svn path=/head/; revision=153666
* Remove the KTR for hardclock completely. It seems to not be useful.Nate Lawson2005-12-181-1/+0
| | | | | | | Requested by: jhb Notes: svn path=/head/; revision=153511
* Clean up unused or poorly utilized KTR values. Remove KTR_FS, KTR_KGDB,Nate Lawson2005-12-171-1/+1
| | | | | | | | | | and KTR_IO as they were never used. Remove KTR_CLK since it was only used for hardclock firing and use KTR_INTR there instead. Remove KTR_CRITICAL since it was only used for crit enter/exit and use KTR_CONTENTION instead. Notes: svn path=/head/; revision=153493
* - Use uintfptr_t rather than int for the kernel profiling index (though itJohn Baldwin2005-12-161-3/+3
| | | | | | | | | | | | | really should be a fptrdiff_t if we had that) in profclock(). - Don't try to profile kernel pc's that are >= the kernel lowpc to avoid underflows when computing a profiling index. - Use the PC_TO_I() macro to compute the kernel profiling index rather than doing it inline. Discussed with: bde Notes: svn path=/head/; revision=153490
* In watchdog_config enable the software watchdog iff the WD_ACTIVE flag isEd Maste2005-10-271-2/+1
| | | | | | | | | | | | set. When watchdogd(1) is terminated intentionally it clears the bit, which should then disable it in the kernel. PR: kern/74386 Submitted by: Alex Hoff <ahoff at sandvine dot com> Approved by: phk, rwatson (mentor) Notes: svn path=/head/; revision=151747
* Reorganize the interrupt handling code a bit to make a few things cleanerJohn Baldwin2005-10-251-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | and increase flexibility to allow various different approaches to be tried in the future. - Split struct ithd up into two pieces. struct intr_event holds the list of interrupt handlers associated with interrupt sources. struct intr_thread contains the data relative to an interrupt thread. Currently we still provide a 1:1 relationship of events to threads with the exception that events only have an associated thread if there is at least one threaded interrupt handler attached to the event. This means that on x86 we no longer have 4 bazillion interrupt threads with no handlers. It also means that interrupt events with only INTR_FAST handlers no longer have an associated thread either. - Renamed struct intrhand to struct intr_handler to follow the struct intr_foo naming convention. This did require renaming the powerpc MD struct intr_handler to struct ppc_intr_handler. - INTR_FAST no longer implies INTR_EXCL on all architectures except for powerpc. This means that multiple INTR_FAST handlers can attach to the same interrupt and that INTR_FAST and non-INTR_FAST handlers can attach to the same interrupt. Sharing INTR_FAST handlers may not always be desirable, but having sio(4) and uhci(4) fight over an IRQ isn't fun either. Drivers can always still use INTR_EXCL to ask for an interrupt exclusively. The way this sharing works is that when an interrupt comes in, all the INTR_FAST handlers are executed first, and if any threaded handlers exist, the interrupt thread is scheduled afterwards. This type of layout also makes it possible to investigate using interrupt filters ala OS X where the filter determines whether or not its companion threaded handler should run. - Aside from the INTR_FAST changes above, the impact on MD interrupt code is mostly just 's/ithread/intr_event/'. - A new MI ddb command 'show intrs' walks the list of interrupt events dumping their state. It also has a '/v' verbose switch which dumps info about all of the handlers attached to each event. - We currently don't destroy an interrupt thread when the last threaded handler is removed because it would suck for things like ppbus(8)'s braindead behavior. The code is present, though, it is just under #if 0 for now. - Move the code to actually execute the threaded handlers for an interrrupt event into a separate function so that ithread_loop() becomes more readable. Previously this code was all in the middle of ithread_loop() and indented halfway across the screen. - Made struct intr_thread private to kern_intr.c and replaced td_ithd with a thread private flag TDP_ITHREAD. - In statclock, check curthread against idlethread directly rather than curthread's proc against idlethread's proc. (Not really related to intr changes) Tested on: alpha, amd64, i386, sparc64 Tested on: arm, ia64 (older version of patch by cognet and marcel) Notes: svn path=/head/; revision=151658
* - Don't pollute opt_global.h with DEVICE_POLLING and introduceGleb Smirnoff2005-10-051-0/+1
| | | | | | | | | | | | opt_device_polling.h - Include opt_device_polling.h into appropriate files. - Embrace with HAVE_KERNEL_OPTION_HEADERS the include in the files that can be compiled as loadable modules. Reviewed by: bde Notes: svn path=/head/; revision=150968
* Use SCTL_MASK32 to determine that the sysctl call is from a 32bitPaul Saab2005-06-301-7/+2
| | | | | | | | | binary for kern.cp_time. Approved by: re Notes: svn path=/head/; revision=147703
* Jumbo-commit to enhance 32 bit application support on 64 bit kernels.Peter Wemm2005-06-301-2/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | This is good enough to be able to run a RELENG_4 gdb binary against a RELENG_4 application, along with various other tools (eg: 4.x gcore). We use this at work. ia32_reg.[ch]: handle the 32 bit register file format, used by ptrace, procfs and core dumps. procfs_*regs.c: vary the format of proc/XXX/*regs depending on the client and target application. procfs_map.c: Don't print a 64 bit value to 32 bit consumers, or their sscanf fails. They expect an unsigned long. imgact_elf.c: produce a valid 32 bit coredump for 32 bit apps. sys_process.c: handle 32 bit consumers debugging 32 bit targets. Note that 64 bit consumers can still debug 32 bit targets. IA64 has got stubs for ia32_reg.c. Known limitations: a 5.x/6.x gdb uses get/setcontext(), which isn't implemented in the 32/64 wrapper yet. We also make a tiny patch to gdb pacify it over conflicting formats of ld-elf.so.1. Approved by: re Notes: svn path=/head/; revision=147692
* Move HWPMC_HOOKS into its own opt_hwpmc_hooks.h file. It doesn't meritPeter Wemm2005-06-241-0/+1
| | | | | | | | | | being in opt_global.h and forcing a global recompile when only a few files reference it. Approved by: re Notes: svn path=/head/; revision=147565
* Kernel hooks to support PMC sampling modes.Joseph Koshy2005-05-301-0/+9
| | | | | | | Reviewed by: alc Notes: svn path=/head/; revision=146799
* - Define KTR points for KTR_SCHED.Jeff Roberson2004-12-261-0/+2
| | | | Notes: svn path=/head/; revision=139315
* Rework how we store process times in the kernel such that we always storeJohn Baldwin2004-10-051-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | the raw values including for child process statistics and only compute the system and user timevals on demand. - Fix the various kern_wait() syscall wrappers to only pass in a rusage pointer if they are going to use the result. - Add a kern_getrusage() function for the ABI syscalls to use so that they don't have to play stackgap games to call getrusage(). - Fix the svr4_sys_times() syscall to just call calcru() to calculate the times it needs rather than calling getrusage() twice with associated stackgap, etc. - Add a new rusage_ext structure to store raw time stats such as tick counts for user, system, and interrupt time as well as a bintime of the total runtime. A new p_rux field in struct proc replaces the same inline fields from struct proc (i.e. p_[isu]ticks, p_[isu]u, and p_runtime). A new p_crux field in struct proc contains the "raw" child time usage statistics. ruadd() has been changed to handle adding the associated rusage_ext structures as well as the values in rusage. Effectively, the values in rusage_ext replace the ru_utime and ru_stime values in struct rusage. These two fields in struct rusage are no longer used in the kernel. - calcru() has been split into a static worker function calcru1() that calculates appropriate timevals for user and system time as well as updating the rux_[isu]u fields of a passed in rusage_ext structure. calcru() uses a copy of the process' p_rux structure to compute the timevals after updating the runtime appropriately if any of the threads in that process are currently executing. It also now only locks sched_lock internally while doing the rux_runtime fixup. calcru() now only requires the caller to hold the proc lock and calcru1() only requires the proc lock internally. calcru() also no longer allows callers to ask for an interrupt timeval since none of them actually did. - calcru() now correctly handles threads executing on other CPUs. - A new calccru() function computes the child system and user timevals by calling calcru1() on p_crux. Note that this means that any code that wants child times must now call this function rather than reading from p_cru directly. This function also requires the proc lock. - This finishes the locking for rusage and friends so some of the Giant locks in exit1() and kern_wait() are now gone. - The locking in ttyinfo() has been tweaked so that a shared lock of the proctree lock is used to protect the process group rather than the process group lock. By holding this lock until the end of the function we now ensure that the process/thread that we pick to dump info about will no longer vanish while we are trying to output its info to the console. Submitted by: bde (mostly) MFC after: 1 month Notes: svn path=/head/; revision=136152
* Update for the KDB framework:Marcel Moolenaar2004-07-101-10/+6
| | | | | | | | | | | | | | | | | | | | | | | | | o Make debugging code conditional upon KDB instead of DDB. o Call kdb_enter() instead of Debugger(). o Call kdb_backtrace() instead of db_print_backtrace() or backtrace(). kern_mutex.c: o Replace checks for db_active with checks for kdb_active and make them unconditional. kern_shutdown.c: o s/DDB_UNATTENDED/KDB_UNATTENDED/g o s/DDB_TRACE/KDB_TRACE/g o Save the TID of the thread doing the kernel dump so the debugger knows which thread to select as the current when debugging the kernel core file. o Clear kdb_active instead of db_active and do so unconditionally. o Remove backtrace() implementation. kern_synch.c: o Call kdb_reenter() instead of db_error(). Notes: svn path=/head/; revision=131927
* - Assert that any process that has statclock called on it has both aJohn Baldwin2004-07-021-11/+10
| | | | | | | | | | | stats structure and a vmspace as this should always be true rather than checking the always true condition in an if statement. - Remove never-false check: if ((ru = &pstats->p_ru) != NULL) - Remove pstats variable that is only used once and inline its one use instead. Notes: svn path=/head/; revision=131436
* Nice, is a property of a process as a whole..Julian Elischer2004-06-161-1/+1
| | | | | | | | I mistakenly moved it to the ksegroup when breaking up the process structure. Put it back in the proc structure. Notes: svn path=/head/; revision=130551
* Remove a redundant "td = curthread" statement from profclock().Tim J. Robbins2004-06-021-1/+0
| | | | Notes: svn path=/head/; revision=129996
* Fix a race condition which could result in profprocs being decrementedColin Percival2004-05-031-0/+2
| | | | | | | | more than once if stopprofclock is called multiple times on the same process. Notes: svn path=/head/; revision=128852
* Remove advertising clause from University of California Regent's license,Warner Losh2004-04-051-4/+0
| | | | | | | | | per letter dated July 22, 1999. Approved by: core Notes: svn path=/head/; revision=127911
* Make sure to disable the watchdog if we cannot honour the timeout.Poul-Henning Kamp2004-02-281-3/+2
| | | | Notes: svn path=/head/; revision=126386
* Rename the WATCHDOG option to SW_WATCHDOG and make it use thePoul-Henning Kamp2004-02-281-33/+29
| | | | | | | | | | | | | | generic watchdoc(9) interface. Make watchdogd(8) perform as watchdog(8) as well, and make it possible to specify a check command to run, timeout and sleep periods. Update watchdog(4) to talk about the generic interface and add new watchdog(8) page. Notes: svn path=/head/; revision=126383
* Catch a few places where NULL (pointer) was used where 0 (integer) wasPeter Wemm2003-12-231-1/+1
| | | | | | | expected. Notes: svn path=/head/; revision=123740
* - Update the sched api. sched_{add,rem,clock,pctcpu} now all accept a tdJeff Roberson2003-10-161-4/+2
| | | | | | | argument rather than a kse. Notes: svn path=/head/; revision=121127
* Fix this to build on alpha. Build test successful.Sean Kelly2003-06-271-1/+1
| | | | | | | Suggested fix from: tjr Notes: svn path=/head/; revision=116908
* - Add a software watchdog facility.Sean Kelly2003-06-261-0/+82
| | | | | | | | | | | | This commit has two pieces. One half is the watchdog kernel code which lives primarily in hardclock() in sys/kern/kern_clock.c. The other half is a userland daemon which, when run, will keep the watchdog from firing while the userland is intact and functioning. Approved by: jeff (mentor) Notes: svn path=/head/; revision=116874
* Rename P_THREADED to P_SA. P_SA means a process is using schedulerDavid Xu2003-06-151-3/+3
| | | | | | | activations. Notes: svn path=/head/; revision=116361
* Use __FBSDID().David E. O'Brien2003-06-111-1/+3
| | | | Notes: svn path=/head/; revision=116182
* Deprecate machine/limits.h in favor of new sys/limits.h.Alexander Kabaev2003-04-291-1/+1
| | | | | | | | | | Change all in-tree consumers to include <sys/limits.h> Discussed on: standards@ Partially submitted by: Craig Rodrigues <rodrigc@attbi.com> Notes: svn path=/head/; revision=114216
* - Move PS_PROFIL and its new cousin PS_STOPPROF back over to p_flag andJohn Baldwin2003-04-221-19/+17
| | | | | | | | | | rename them appropriately. Protect both flags with both the proc lock and the sched_lock. - Protect p_profthreads with the proc lock. - Remove Giant from profil(2). Notes: svn path=/head/; revision=113874
* - Adjust sched hooks for fork and exec to take processes as arguments insteadJeff Roberson2003-04-111-1/+1
| | | | | | | | | | | | | of ksegs since they primarily operation on processes. - KSEs take ticks so pass the kse through sched_clock(). - Add a sched_class() routine that adjusts a ksegrp pri class. - Define a sched_fork_{kse,thread,ksegrp} and sched_exit_{kse,thread,ksegrp} that will be used to tell the scheduler about new instances of these structures within the same process. These will be used by THR and KSE. - Change sched_4bsd to reflect this API update. Notes: svn path=/head/; revision=113355
* Update netisr handling; Each SWI now registers its queue, and all queueJonathan Lemon2003-03-041-4/+0
| | | | | | | | | | | | | drain routines are done by swi_net, which allows for better queue control at some future point. Packets may also be directly dispatched to a netisr instead of queued, this may be of interest at some installations, but currently defaults to off. Reviewed by: hsu, silby, jayanth, sam Sponsored by: DARPA, NAI Labs Notes: svn path=/head/; revision=111888
* Change the process flags P_KSES to be P_THREADED.Julian Elischer2003-02-271-3/+3
| | | | | | | This is just a cosmetic change but I've been meaning to do it for about a year. Notes: svn path=/head/; revision=111585
* Remove a never true condition.David Xu2003-02-251-2/+1
| | | | Notes: svn path=/head/; revision=111464
* Move a bunch of flags from the KSE to the thread.Julian Elischer2003-02-171-3/+4
| | | | | | | | | | | I was in two minds as to where to put them in the first case.. I should have listenned to the other mind. Submitted by: parts by davidxu@ Reviewed by: jeff@ mini@ Notes: svn path=/head/; revision=111032
* - Split the struct kse into struct upcall and struct kse. struct kse willJeff Roberson2003-02-171-2/+2
| | | | | | | | | | soon be visible only to schedulers. This greatly simplifies much the KSE code. Submitted by: davidxu Notes: svn path=/head/; revision=111028
* - Move ke_sticks, ke_iticks, ke_uticks, ke_uu, ke_su, and ke_iu back intoJeff Roberson2003-02-171-3/+5
| | | | | | | | | | the proc. These counters are only examined through calcru. Submitted by: davidxu Tested on: x86, alpha, UP/SMP Notes: svn path=/head/; revision=111024
* Remove #include <sys/dkstat.h>Poul-Henning Kamp2003-02-161-1/+0
| | | | Notes: svn path=/head/; revision=111002
* Move the tty related statistics counters to live with the tty code.Poul-Henning Kamp2003-02-161-5/+0
| | | | Notes: svn path=/head/; revision=110996
* A little infrastructure, preceding some upcoming changesJulian Elischer2003-02-081-3/+19
| | | | | | | | | | to the profiling and statistics code. Submitted by: DavidXu@ Reviewed by: peter@ Notes: svn path=/head/; revision=110530