summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_intr.c
Commit message (Collapse)AuthorAgeFilesLines
* /* -> /*- for copyright notices, minor format tweaks as necessaryimp2005-01-061-1/+1
|
* Stop explicitly touching td_base_pri outside of the scheduler and simplyjhb2004-12-301-4/+3
| | | | | set a thread's priority via sched_prio() when that is the desired action. The schedulers will start managing td_base_pri internally shortly.
* Don't bother exiting storming mode once a second to see if it has gonejhb2004-11-171-12/+6
| | | | | | | away, instead only exit storming mode when an interrupt stops firing long enough for the ithread to exit the loop and go back to sleep. Tested by: macrus (cruder version)
* Adjust the interrupt storm handling code to better handle a storm. Whenjhb2004-11-161-5/+23
| | | | | | | | | | | a storm is detected, enter "storming" mode which throttles the interrupt source such that the handlers are run once every clock tick. Previously we allowed a full set of storm_threshold interations through the handler before going back to sleep. Also, this currently will intentionally exit storming mode once a second to see if the storm has passed. Tested by: marcus Discussed with: bde
* - Make setting of IT_ENTROPY a bit simpler in ithread_update().jhb2004-11-051-10/+10
| | | | | | | | | - Tweak the updating of the ithread name in ithread_update() so that the '+' and '*' characters for device names that were too short only get added at the end after as many device names as possible were fit into the allocated space. Prior to this, some long devices would result in '+' chars showing up between two different devices rather than at the end.
* Revert most of 1.109. Although it improved the situation on one particularjhb2004-11-031-42/+12
| | | | | | | | | | | | | motherboard, in practice the changes resulted in many false positives for heavy network loads, etc. resulting in poor performance. Also, the motherboard referenced in the 1.109 log has other problems and simply does not seem to work with the APIC enabled even with the changes in 1.109. The correct fix for that board seems to be to not use the APIC at all. One thing kept from 1.109 is that throttled interrupts are now effectively polled on every clock tick rather than just 10 times per second. MFC after: 1 month Tested by: Shunsuke SHINOMIYA shino at fornext dot org
* - Change the ddb paging "support" to use a variable (db_lines_per_page) tojhb2004-11-011-1/+1
| | | | | | | | | | | | | | | | | control the number of lines per page rather than a constant. The variable can be examined and changed in ddb as '$lines'. Setting the variable to 0 will effectively turn off paging. - Change db_putchar() to force out pending whitespace before outputting newlines and carriage returns so that one can rub out content on the current line via '\r \r' type strings. - Change the simple pager to rub out the --More-- prompt explicitly when the routine exits. - Add some aliases to the simple pager to make it more compatible with more(1): 'e' and 'j' do a single line. 'd' does half a page, and 'f' does a full page. MFC after: 1 month Inspired by: kris
* Refactor a bunch of scheduler code to give basically the same behaviourjulian2004-09-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | but with slightly cleaned up interfaces. The KSE structure has become the same as the "per thread scheduler private data" structure. In order to not make the diffs too great one is #defined as the other at this time. The KSE (or td_sched) structure is now allocated per thread and has no allocation code of its own. Concurrency for a KSEGRP is now kept track of via a simple pair of counters rather than using KSE structures as tokens. Since the KSE structure is different in each scheduler, kern_switch.c is now included at the end of each scheduler. Nothing outside the scheduler knows the contents of the KSE (aka td_sched) structure. The fields in the ksegrp structure that are to do with the scheduler's queueing mechanisms are now moved to the kg_sched structure. (per ksegrp scheduler private data structure). In other words how the scheduler queues and keeps track of threads is no-one's business except the scheduler's. This should allow people to write experimental schedulers with completely different internal structuring. A scheduler call sched_set_concurrency(kg, N) has been added that notifies teh scheduler that no more than N threads from that ksegrp should be allowed to be on concurrently scheduled. This is also used to enforce 'fainess' at this time so that a ksegrp with 10000 threads can not swamp a the run queue and force out a process with 1 thread, since the current code will not set the concurrency above NCPU, and both schedulers will not allow more than that many onto the system run queue at a time. Each scheduler should eventualy develop their own methods to do this now that they are effectively separated. Rejig libthr's kernel interface to follow the same code paths as linkse for scope system threads. This has slightly hurt libthr's performance but I will work to recover as much of it as I can. Thread exit code has been cleaned up greatly. exit and exec code now transitions a process back to 'standard non-threaded mode' before taking the next step. Reviewed by: scottl, peter MFC after: 1 week
* Give setrunqueue() and sched_add() more of a clue as tojulian2004-09-011-2/+2
| | | | | | where they are coming from and what is expected from them. MFC after: 2 days
* Annotate call to DELAY() in interrupt storm mitigation as beingrwatson2004-08-171-0/+3
| | | | | | something to revisit. Approved by: re (scottl)
* In ithread_schedule(), when we plan to go harvest some entropy asrwatson2004-08-061-2/+4
| | | | | | a result of scheduling an ithread, cut a KTR_INTR trace record so that it's clear in tracing interrupt activity where and when the entropy harvesting code is invoked.
* Implement preemption of kernel threads natively in the scheduler ratherjhb2004-07-021-16/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | than as one-off hacks in various other parts of the kernel: - Add a function maybe_preempt() that is called from sched_add() to determine if a thread about to be added to a run queue should be preempted to directly. If it is not safe to preempt or if the new thread does not have a high enough priority, then the function returns false and sched_add() adds the thread to the run queue. If the thread should be preempted to but the current thread is in a nested critical section, then the flag TDF_OWEPREEMPT is set and the thread is added to the run queue. Otherwise, mi_switch() is called immediately and the thread is never added to the run queue since it is switch to directly. When exiting an outermost critical section, if TDF_OWEPREEMPT is set, then clear it and call mi_switch() to perform the deferred preemption. - Remove explicit preemption from ithread_schedule() as calling setrunqueue() now does all the correct work. This also removes the do_switch argument from ithread_schedule(). - Do not use the manual preemption code in mtx_unlock if the architecture supports native preemption. - Don't call mi_switch() in a loop during shutdown to give ithreads a chance to run if the architecture supports native preemption since the ithreads will just preempt DELAY(). - Don't call mi_switch() from the page zeroing idle thread for architectures that support native preemption as it is unnecessary. - Native preemption is enabled on the same archs that supported ithread preemption, namely alpha, i386, and amd64. This change should largely be a NOP for the default case as committed except that we will do fewer context switches in a few cases and will avoid the run queues completely when preempting. Approved by: scottl (with his re@ hat)
* - Change mi_switch() and sched_switch() to accept an optional thread tojhb2004-07-021-2/+2
| | | | | | | | | | | | | switch to. If a non-NULL thread pointer is passed in, then the CPU will switch to that thread directly rather than calling choosethread() to pick a thread to choose to. - Make sched_switch() aware of idle threads and know to do TD_SET_CAN_RUN() instead of sticking them on the run queue rather than requiring all callers of mi_switch() to know to do this if they can be called from an idlethread. - Move constants for arguments to mi_switch() and thread_single() out of the middle of the function prototypes and up above into their own section.
* Detect interrupt storms better. The storm detection didn't work at allbde2004-06-051-23/+50
| | | | | | | | | | | | | | | | | with an ASUS A7N8X-E motherboard in APIC mode, since storming interrupts don't repeat immediately. Use DELAY(1) to wait a bit for them to repeat. This affects all systems. Only delay for the first (10 * intr_storm_threshold) interrupts (per interrupt handler) so that this is only a pessimization while warming up. Throttle after calling the sub-handlers instead of before so that the long delay given by throttling can be used instead of the DELAY(1) to detect storms after warming up. Reduced the throttling period from 1/10 second to 1/hz seconds so that throttling doesn't destroy performance so much. Interrupts that are detected as storming are effectively handled by polling at a frequency of hz Hz. On A7N8X-E's there is another hardware or configuration bug that makes the throttled frequency closer to 2*hz Hz.
* Fixed some style bugs in previous commit (mainly an insertion sort errorbde2004-04-171-9/+10
| | | | | | for declarations, and poorly worded messages). Fixed some nearby style bugs (unsorted declarations).
* - Enable (unmask) interrupt sources earlier in the ithread loop.jhb2004-04-161-8/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Specifically, we used to enable the source after locking sched_lock and just before we had already decided to do a context switch. This meant that an ithread could never process more than one interrupt per context switch. Enabling earlier in the loop before sched_lock is acquired allows an ithread to handle multiple interrupts per context switch if interrupts fire very rapidly. For the case of heavy interrupt load this can reduce the number of context switches (and thus overhead) as well as reduce interrupt latency. - Now that we can handle multiple interrupts per context switch, add simple interrupt storm protection to threaded interrupts. If X number of consecutive interrupts are triggered before the itherad voluntarily yields to another thread, then the interrupt thread will sleep with the associated interrupt source disabled (masked) for 1/10th of a second. The default value of X is 500, but it can be tweaked via the tunable/ sysctl hw.intr_storm_threshold. If an interrupt storm is detected, then a message is output to the kernel console on the first occurrence per interrupt thread. Interrupt storm protection can be disabled completely by setting this value to 0. There is no scientific reasoning for the 1/10th of a second or 500 interrupts values, so they may require tweaking at some point in the future. Tested by: rwatson (an earlier version w/o the storm protection) Tested by: mux (reportedly made a machine with two PCI interrupts storming usable rather than hard locked) Reviewed by: imp
* kthread_exit() no longer requires Giant, so don't force callers to acquirejhb2004-03-051-1/+0
| | | | | | Giant just to call kthread_exit(). Requested by: many
* - Add a flags parameter to mi_switch. The value of flags may be SW_VOL orjeff2004-01-251-4/+2
| | | | | | | | | | SW_INVOL. Assert that one of these is set in mi_switch() and propery adjust the rusage statistics. This is to simplify the large number of users of this interface which were previously all required to adjust the proper counter prior to calling mi_switch(). This also facilitates more switch and locking optimizations. - Change all callers of mi_switch() to pass the appropriate paramter and remove direct references to the process statistics.
* If a device attach routine fails during boot and calls bus_teardown_intr(),truckman2004-01-131-1/+5
| | | | | | | | | | | | | | ithread_remove_handler() may fail to remove the interrupt handler if it decides to let the ithread do the removal. The problem is that during boot "cold" is set, which causes msleep() to return immediately. This will cause ithread_remove_handler() to fail to wait for the ithread to do the removal from the handler TAILQ before freeing the handler back to the heap. Bad things will happen when some other user of the TAILQ, such as ithread_add_handler() or the actual ithread attempts to use the freed handler. Fix the problem by forcing ithread_remove_handler() to do the actual removal itself if the "cold" flag is set. Reviewed by: jhb
* Fix a major faux pas of mine. I was causing 2 very bad things tomarkm2003-11-201-4/+0
| | | | | | | | | | | | | | | happen in interrupt context; 1) sleep locks, and 2) malloc/free calls. 1) is fixed by using spin locks instead. 2) is fixed by preallocating a FIFO (implemented with a STAILQ) and using elements from this FIFO instead. This turns out to be rather fast. OK'ed by: re (scottl) Thanks to: peter, jhb, rwatson, jake Apologies to: *
* Hackfix to patch around a kernel panic I introduced. Real fix tomarkm2003-11-181-0/+4
| | | | | | follow. In the meanwhile, we are not harvesting interrupt entropy. Approved by: re (jhb)
* Expand the argument to the ithread enable/disable helper hooks from anpeter2003-11-171-3/+3
| | | | int to something big enough to hold a pointer. amd64 needs this.
* Don't require INTR_FAST handlers to be exclusive in the MI layer. Instead,jhb2003-11-031-7/+11
| | | | | | | let the MD code choose whether or not to implement such a policy. The new i386 interrupt code allows multiple FAST handlers for a given source for example. However, the code does not allow FAST and non-FAST handlers to be mixed.
* - Add a DDB command 'show intrcnt' to show the non-zero interrupt counts.jhb2003-10-241-0/+165
| | | | | | | - Add a DDB function to dump the contents of an ithread and optionally details about each handler in that ithread. This function can be used by MD code to implement DDB commands that display information about interrupt sources and their registered handlers.
* Make swi_vm be INTR_MPSAFE. On all platforms, it is only used to activatescottl2003-07-011-1/+1
| | | | | busdma_swi(). Now that busdma_swi() uses driver-provided locking, this should be safe.
* Use __FBSDID().obrien2003-06-111-3/+2
|
* Remove unused variable(s).phk2003-05-311-2/+0
| | | | Found by: FlexeLint
* Move the flag that indicates an idle thread from the KSE to the thread.julian2003-05-021-1/+1
| | | | | | It was always referenced via the thread anyhow. Reviewed by: jhb (a LOOOOONG time ago)
* Add some locking in for a few proc and thread fields.jhb2003-04-171-1/+2
|
* Use local struct proc variables to reduce repeated td->td_proc dereferencesjhb2003-04-171-3/+5
| | | | and improve readability.
* Adjust a KTR trace to log thread state instead of proc state as that isjhb2003-04-171-1/+1
| | | | more relevant.
* Add a WITNESS_WARN() call to verify that we hold no locks after runningjhb2003-03-041-0/+1
| | | | a handler from an interrupt thread.
* Back out M_* changes, per decision of the TRB.imp2003-02-191-2/+2
| | | | Approved by: trb
* Move a bunch of flags from the KSE to the thread.julian2003-02-171-1/+1
| | | | | | | | 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@
* Fix crash dumps on ata and scsi.alfred2003-02-141-1/+2
| | | | | | | | | | | To fix scsi, don't wait for ithreads if we're dumping, it makes the debugger sad. To fix ata, use what appears to be a polling method if we're dumping, I stole this from tmm but added code to ensure that this change is only in effect while dumping. Tested by: des
* Remove M_TRYWAIT/M_WAITOK/M_WAIT. Callers should use 0.alfred2003-01-211-2/+2
| | | | Merge M_NOWAIT/M_DONTWAIT into a single flag M_NOWAIT.
* Don't put a newline in KTR traces.jake2002-12-281-1/+1
|
* Instead of (sizeof(source_buffer) - 1) bytes, copy at mostrobert2002-10-171-1/+1
| | | | | | (sizeof(destination_buffer) - 1) bytes into the destination buffer. This was not harmful because they currently both provide space for (MAXCOMLEN + 1) bytes.
* Use strlcpy() instead of strncpy() to copy NUL terminated stringsrobert2002-10-171-1/+2
| | | | for safety and consistency.
* Some kernel threads try to do significant work, and the default KSTACK_PAGESscottl2002-10-021-1/+1
| | | | | | | | | | | | | doesn't give them enough stack to do much before blowing away the pcb. This adds MI and MD code to allow the allocation of an alternate kstack who's size can be speficied when calling kthread_create. Passing the value 0 prevents the alternate kstack from being created. Note that the ia64 MD code is missing for now, and PowerPC was only partially written due to the pmap.c being incomplete there. Though this patch does not modify anything to make use of the alternate kstack, acpi and usb are good candidates. Reviewed by: jake, peter, jhb
* Be consistent about "static" functions: if the function is markedphk2002-09-281-1/+1
| | | | | | static in its prototype, mark it static at the definition too. Inspired by: FlexeLint warning #512
* Removed unneeded include (missed in last revision).jake2002-09-221-2/+0
|
* Moved netisr code from kern/kern_intr.c to net/netisr.c as threatened in ajake2002-09-221-79/+1
| | | | comment.
* Completely redo thread states.julian2002-09-111-7/+9
| | | | Reviewed by: davidxu@freebsd.org
* Remove extra ';'davidxu2002-09-061-1/+1
|
* Slight cleanup of some comments/whitespace.julian2002-08-011-8/+9
| | | | | | | | | | | | Make idle process state more consistant. Add an assert on thread state. Clean up idleproc/mi_switch() interaction. Use a local instead of referencing curthread 7 times in a row (I've been told curthread can be expensive on some architectures) Remove some commented out code. Add a little commented out code (completion coming soon) Reviewed by: jhb@freebsd.org
* Part 1 of KSE-IIIjulian2002-06-291-13/+14
| | | | | | | | | | | | | The ability to schedule multiple threads per process (one one cpu) by making ALL system calls optionally asynchronous. to come: ia64 and power-pc patches, patches for gdb, test program (in tools) Reviewed by: Almost everyone who counts (at various times, peter, jhb, matt, alfred, mini, bernd, and a cast of thousands) NOTE: this is still Beta code, and contains lots of debugging stuff. expect slight instability in signals..
* diff reduction from KSE to keep WW-III from happenning on -currentjulian2002-05-291-1/+2
|
* - Set the base priority of an ithread that has no handlers when we set itsjhb2002-04-111-3/+5
| | | | | | normal priority. - Lock sched_lock while we dink with the priorities. - Remove a few extra blank lines.
* Don't lock the ithread lock in ithread_create(). The ithread isn't on anyjhb2002-04-091-2/+0
| | | | | lists or in any tables yet so there are no other references to it, thus we don't need to lock it.
OpenPOWER on IntegriCloud