summaryrefslogtreecommitdiffstats
path: root/sys/amd64/isa/clock.c
Commit message (Collapse)AuthorAgeFilesLines
* o break newbus api: add a new argument of type driver_filter_t topiso2007-02-231-6/+10
| | | | | | | | | | | | | bus_setup_intr() o add an int return code to all fast handlers o retire INTR_FAST/IH_FAST For more info: http://docs.freebsd.org/cgi/getmsg.cgi?fetch=465712+0+current/freebsd-current Reviewed by: many Approved by: re@
* Cleaned up declaration and initialization of clock_lock. It is onlybde2007-01-231-13/+10
| | | | | | | | | | | | | | | | | | | | used by clock code, so don't export it to the world for machdep.c to initialize. There is a minor problem initializing it before it is used, since although clock initialization is split up so that parts of it can be done early, the first part was never done early enough to actually work. Split it up a bit more and do the first part as late as possible to document the necessary order. The functions that implement the split are still bogusly exported. Cleaned up initialization of the i8254 clock hardware using the new split. Actually initialize it early enough, and don't work around it not being initialized in DELAY() when DELAY() is called early for initialization of some console drivers. This unfortunately moves a little more code before the early debugger breakpoint so that it is harder to debug. The ordering of console and related initialization is delicate because we want to do as little as possible before the breakpoint, but must initialize a console.
* Optimized RTC accesses by avoiding null writes to the index registerbde2006-12-031-9/+16
| | | | | | | | | | | | | | | | | | | | | | | | | and by only delaying when an RTC register is written to. The delay after writing to the data register is now not just a workaround. This reduces the number of ISA accesses in the usual case from 4 to 1. The usual case is 2 rtcin()'s for each RTC interrupt. The index register is almost always RTC_INTR for this. The 3 extra ISA accesses were 1 for writing the index and 2 for delays. Some delays are needed in theory, but in practice they now just slow down slow accesses some more since almost eveyone including us does them wrong so modern systems enforce sufficient delays in hardware. I used to have the delays ifdefed out, but with the index register optimization the delays are rarely executed so the old magic ones can be kept or even implemented non- magically without significant cost. Optimizing RTC interrupt handling is more interesting than it used to be because RTC interrupts are currently needed to fix the more efficient apic timer interrupts on some systems. apic_timer_hz is normally 2000 so the RTC interrupt rate needs to be 2048 to keep the apic timer firing on such systems. Without these changes, each RTC interrupt normally took 10 ISA accesses (2 PIC accesses and 2 sets of 4 RTC accesses). Each ISA access takes 1-1.5uS so 10 of then at 2048 Hz takes 2-3% of a CPU. Now 4 of them take 0.8-1.2% of a CPU.
* Use utc_offset() where applicable, and hide the internals of itphk2006-10-021-2/+2
| | | | as static variables.
* Second part of a little cleanup in the calendar/timezone/RTC handling.phk2006-10-021-3/+0
| | | | | | | | | | | Split subr_clock.c in two parts (by repo-copy): subr_clock.c contains generic RTC and calendaric stuff. etc. subr_rtc.c contains the newbus'ified RTC interface. Centralize the machdep.{adjkerntz,disable_rtc_set,wall_cmos_clock} sysctls and associated variables into subr_clock.c. They are not machine dependent and we have generic code that relies on being present so they are not even optional.
* First part of a little cleanup in the calendar/timezone/RTC handling.phk2006-10-021-0/+1
| | | | | | Move relevant variables to <sys/clock.h> and fix #includes as necessary. Use libkern's much more time- & spamce-efficient BCD routines.
* Tweak how the MD code calls the fooclock() methods some. Instead ofjhb2005-12-221-6/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* For the amd64 platform, we can depend on the TSC being present. This patchpeter2005-12-121-0/+15
| | | | | | | changes DELAY to use the TSC once it has been calibrated. This does NOT use the TSC for long-term timekeeping. It only uses it to bound the DELAY() spinloop. This should not be affected by the Athlon64 X2 TSC quirks because the cpu is not halted while we use DELAY().
* Fixup some more fallout from the lapic/i8254 changes:jhb2005-07-131-23/+15
| | | | | | | | | | | | - Make sure timer0_max_count is set to a correct value in the lapic case. - Revert i8254_restore() to explicitly reprogram timer 0 rather than calling set_timer_freq() to do it. set_timer_freq() only reprograms the counter if the max count changes which it never does on resume. This unbreaks suspend/resume for several people. Tested by: marks, others Reviewed by: bde MFC after: 3 days
* Remove a || 1 that crept into the i8254 commit and was subsequentlyjhb2005-07-051-1/+1
| | | | | | | | | copied and pasted. I had actually tested without this change in my trees as had the other testers. Reported by: bde, Rostislav Krasny rosti dot bsd at gmail dot com Approved by: re (scottl) Pointy hat to: jhb
* MFi386: r1.221: use simple timecounter that is aware of irq0 being off.peter2005-07-011-7/+34
| | | | Approved by: re
* - Move timerreg.h to <arch>/include and split i8253 specific defines intonyan2005-05-141-8/+8
| | | | | | | | | i8253reg.h, and add some defines to control a speaker. - Move PPI related defines from i386/isa/spkr.c into ppireg.h and use them. - Move IO_{PPI,TIMER} defines into ppireg.h and timerreg.h respectively. - Use isa/isareg.h rather than <arch>/isa/isa.h. Tested on: i386, pc98
* MFi386: sync rtc code - don't setup an interrupt handler for irq0 whenpeter2005-04-151-28/+32
| | | | | the lapic timer is active. Don't enable periodic interrupts unless we are using them. Replace spl protection with a spinlock.
* Fix a mismerge of i386 rev 1.209peter2005-03-111-1/+1
|
* MFi386: Bring over John's local apic timer codepeter2005-02-281-12/+11
|
* MFi386: read from RTC_INTR after writing to RTC_STATUSBpeter2005-02-081-0/+2
|
* Sync with i386 - cosmetic fixespeter2004-08-161-1/+2
|
* MFi386: rev 1.213 -- fix DELAY while the debugger is active.marcel2004-07-111-12/+23
| | | | | | This also fixes the (runtime) breakage introduced in the previous commit that was the result of a botched merge. This hasn't even been compile-tested...
* MFi386: don't fake the time counter when the debugger is active.marcel2004-07-101-20/+12
| | | | | This breaks the fundamental property of DELAY(). Instead, avoid grabbing clock_lock when kdb_active is non-zero.
* Move module.h include to the same place as on i386 for diff reduction.peter2004-06-031-1/+1
|
* Add missing <sys/module.h> instances which were shadowed by the nestedphk2004-06-031-0/+1
| | | | include in <sys/kernel.h>
* MFi386: numerous interrupt and acpi updatespeter2004-05-161-5/+6
|
* Remove advertising clause from University of California Regent's license,imp2004-04-051-4/+0
| | | | | | per letter dated July 22, 1999. Approved by: core
* MFi386 rev 1.207 (phk): Don't mistakenly disable the TSC when usingpeter2003-11-211-10/+10
| | | | | | statclock_disable. Approved by: re (scottl)
* Initial landing of SMP support for FreeBSD/amd64.peter2003-11-171-30/+22
| | | | | | | | | | | | | | | | - This is heavily derived from John Baldwin's apic/pci cleanup on i386. - I have completely rewritten or drastically cleaned up some other parts. (in particular, bootstrap) - This is still a WIP. It seems that there are some highly bogus bioses on nVidia nForce3-150 boards. I can't stress how broken these boards are. I have a workaround in mind, but right now the Asus SK8N is broken. The Gigabyte K8NPro (nVidia based) is also mind-numbingly hosed. - Most of my testing has been with SCHED_ULE. SCHED_4BSD works. - the apic and acpi components are 'standard'. - If you have an nVidia nForce3-150 board, you are stuck with 'device atpic' in addition, because they somehow managed to forget to connect the 8254 timer to the apic, even though its in the same silicon! ARGH! This directly violates the ACPI spec.
* Preemptively burn a bridges. The isa timer code is likely to bepeter2003-11-141-141/+0
| | | | | replaced by the HPET timer at some point, so dont even make a release with the aquire/release_timer0 functions.
* MFi386: Do not depend on LEAPYEAR() macro boolean values being 0 or 1.peter2003-09-301-2/+3
| | | | MFi386: Add quality field for timer0
* MFi386: BURN_BRIDGES around timer0 functionspeter2003-09-301-2/+14
|
* MFi386 machdep.c rev 1.201, clock.c 1.201, clock.h 1.45 by phk: Dontpeter2003-09-221-0/+2
| | | | | | | | | | | initialize a TSC timecounter until we know if it is broke or not. XXX I think there is a bug in the i386 code here. init_TSC_tc() comes after: if (statclock_disable) return; ie: if you turn off the statclock interrupt, you dont get the TSC either.
* MFi386: machdep.c:1.570 clock.c:1.204 by bde: Quick fix for calling DELAYpeter2003-09-221-2/+18
| | | | | | for ddb input in some atkbd-based console drivers. ddb must not use any normal locks but DELAY() normally calls getit() which needs clock_lock. This also removes the need for recursion on clock_lock.
* Use __FBSDID().obrien2003-07-251-2/+4
| | | | Brought to you by: a boring talk at Ottawa Linux Symposium
* Commit MD parts of a loosely functional AMD64 port. This is based onpeter2003-05-011-221/+7
| | | | | | | | | | | | | | | | | | | | | | a heavily stripped down FreeBSD/i386 (brutally stripped down actually) to attempt to get a stable base to start from. There is a lot missing still. Worth noting: - The kernel runs at 1GB in order to cheat with the pmap code. pmap uses a variation of the PAE code in order to avoid having to worry about 4 levels of page tables yet. - It boots in 64 bit "long mode" with a tiny trampoline embedded in the i386 loader. This simplifies locore.s greatly. - There are still quite a few fragments of i386-specific code that have not been translated yet, and some that I cheated and wrote dumb C versions of (bcopy etc). - It has both int 0x80 for syscalls (but using registers for argument passing, as is native on the amd64 ABI), and the 'syscall' instruction for syscalls. int 0x80 preserves all registers, 'syscall' does not. - I have tried to minimize looking at the NetBSD code, except in a couple of places (eg: to find which register they use to replace the trashed %rcx register in the syscall instruction). As a result, there is not a lot of similarity. I did look at NetBSD a few times while debugging to get some ideas about what I might have done wrong in my first attempt.
* Deprecate machine/limits.h in favor of new sys/limits.h.kan2003-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>
* Use repo-copied files in sys/i386/bios.mdodd2003-03-241-1/+1
|
* Including <sys/stdint.h> is (almost?) universally only to be able to usephk2003-03-181-1/+0
| | | | | %j in printfs, so put a newsted include in <sys/systm.h> where the printf prototype lives and save everybody else the trouble.
* Switch to using the TSC code in i386/i386/tsc.c.phk2003-02-111-114/+1
|
* Split the global timezone structure into two integer fields tophk2003-02-031-2/+2
| | | | | | | | | | prevent the compiler from optimizing assignments into byte-copy operations which might make access to the individual fields non-atomic. Use the individual fields throughout, and don't bother locking them with Giant: it is no longer needed. Inspired by: tjr
* Split statclock into statclock and profclock, and made the method for drivingjake2003-02-031-6/+22
| | | | | | | | | | | | | statclock based on profhz when profiling is enabled MD, since most platforms don't use this anyway. This removes the need for statclock_process, whose only purpose was to subdivide profhz, and gets the profiling clock running outside of sched_lock on platforms that implement suswintr. Also changed the interface for starting and stopping the profiling clock to do just that, instead of changing the rate of statclock, since they can now be separate. Reviewed by: jhb, tmm Tested on: i386, sparc64
* Make tsc_freq a 64bit quantity.phk2003-01-291-5/+7
| | | | Inspired by: http://www.theinquirer.net/?article=7481
* Use the correct value when writing the Day Of Week byte in the CMOS.phk2002-12-041-1/+1
| | | | | | | | | | | | | | | | | The correct range is [1...7] with Sunday=1, but we have been writing [0...6] with Sunday=0. The Soekris computers flagged the zero, zapped the date, so if you rebooted your soekris on a sunday, it would come up with a wrong date. Bruce has a more extensive rework of this code, but we will stick with the minimalist fix for now. Spotted by: Soren Kristensen <soren@soekris.com> Thanks to: Michael Sierchio <kudzu@tenebras.com>. Confirmed by: bde Approved by: re
* 1. Fix a comment. Locking _is_ needed (but not done).iwasaki2002-10-171-12/+8
| | | | | | | | | | | | | | | | | | | | | | | | | 2. Update a comment. We now restore much more than RTC updates and interrupts. 3. Order change. Stop interrupts by writing to RTC_STATUSB, restore rate bits for the interrupts by writing to RTC_STATUSA, then enable interrupts again. This seems to be done perfectly backwards in startrtclock(). Otherwise, the idea for this change was obtained from startrtclock(). 4. Don't stop the clock (RTCB_HALT). We only program some control bits and don't want to stop the clock. 5. (Not really related.) Add caveats to the comment about timer_restore(). The update is non-atomic since locking is not done. On locking: 6. rtcin() and writertc() are locked() adequately by splhigh() in RELENG_4, but this locking is null in -current. 7. Doing things in the correct order in (3) combined with (6) is probably enough locking for rtcrestore() in RELENG_4. In -current, the writertc()'s race with rtcintr() unless the BIOS disables RTC interrupts. Submitted by: bde (including commit message) MFC after: 1 week
* Fix a 3 year old oversight: Remove the #ifdef/#endif pair now that therephk2002-09-211-2/+0
| | | | | | is nothing between them anymore. Spotted by: peter.
* Restore status register A of RTC at resume time.iwasaki2002-09-181-0/+1
| | | | | | | This should fix the 'too many RTC interrupts and statclock seems broken after resume' problem. MFC after: 1 week
* Clock frequencies reported by sysctl should be unsigned values. Discoveredmp2002-06-221-2/+2
| | | | | | | | when machdep.tsc_freq returned a negative number on a 2.2GHz Xeon. Submitted by: Brian Harrison <bharrison@ironport.com> Reviewed by: phk MFC after: 1 week
* Don't export timecounter structures under debug. with sysctl, theyphk2002-04-301-6/+0
| | | | contain no truly interesting data anymore.
* Remove the tc_update() function. Any frequency change to thephk2002-04-261-2/+0
| | | | | | timecounter will be used starting at the next second, which is good enough for sysctl purposes. If better adjustment is needed the NTP PLL should be used.
* Compromise for critical*()/cpu_critical*() recommit. Cleanup the interruptdillon2002-03-271-0/+12
| | | | | | | | | | | | | | | | | | | disablement assumptions in kern_fork.c by adding another API call, cpu_critical_fork_exit(). Cleanup the td_savecrit field by moving it from MI to MD. Temporarily move cpu_critical*() from <arch>/include/cpufunc.h to <arch>/<arch>/critical.c (stage-2 will clean this up). Implement interrupt deferral for i386 that allows interrupts to remain enabled inside critical sections. This also fixes an IPI interlock bug, and requires uses of icu_lock to be enclosed in a true interrupt disablement. This is the stage-1 commit. Stage-2 will occur after stage-1 has stabilized, and will move cpu_critical*() into its own header file(s) + other things. This commit may break non-i386 architectures in trivial ways. This should be temporary. Reviewed by: core Approved by: core
* Remove __P.alfred2002-03-201-7/+7
|
* revert last commit temporarily due to whining on the lists.dillon2002-02-261-13/+0
|
* STAGE-1 of 3 commit - allow (but do not require) interrupts to remaindillon2002-02-261-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | enabled in critical sections and streamline critical_enter() and critical_exit(). This commit allows an architecture to leave interrupts enabled inside critical sections if it so wishes. Architectures that do not wish to do this are not effected by this change. This commit implements the feature for the I386 architecture and provides a sysctl, debug.critical_mode, which defaults to 1 (use the feature). For now you can turn the sysctl on and off at any time in order to test the architectural changes or track down bugs. This commit is just the first stage. Some areas of the code, specifically the MACHINE_CRITICAL_ENTER #ifdef'd code, is strictly temporary and will be cleaned up in the STAGE-2 commit when the critical_*() functions are moved entirely into MD files. The following changes have been made: * critical_enter() and critical_exit() for I386 now simply increment and decrement curthread->td_critnest. They no longer disable hard interrupts. When critical_exit() decrements the counter to 0 it effectively calls a routine to deal with whatever interrupts were deferred during the time the code was operating in a critical section. Other architectures are unaffected. * fork_exit() has been conditionalized to remove MD assumptions for the new code. Old code will still use the old MD assumptions in regards to hard interrupt disablement. In STAGE-2 this will be turned into a subroutine call into MD code rather then hardcoded in MI code. The new code places the burden of entering the critical section in the trampoline code where it belongs. * I386: interrupts are now enabled while we are in a critical section. The interrupt vector code has been adjusted to deal with the fact. If it detects that we are in a critical section it currently defers the interrupt by adding the appropriate bit to an interrupt mask. * In order to accomplish the deferral, icu_lock is required. This is i386-specific. Thus icu_lock can only be obtained by mainline i386 code while interrupts are hard disabled. This change has been made. * Because interrupts may or may not be hard disabled during a context switch, cpu_switch() can no longer simply assume that PSL_I will be in a consistent state. Therefore, it now saves and restores eflags. * FAST INTERRUPT PROVISION. Fast interrupts are currently deferred. The intention is to eventually allow them to operate either while we are in a critical section or, if we are able to restrict the use of sched_lock, while we are not holding the sched_lock. * ICU and APIC vector assembly for I386 cleaned up. The ICU code has been cleaned up to match the APIC code in regards to format and macro availability. Additionally, the code has been adjusted to deal with deferred interrupts. * Deferred interrupts use a per-cpu boolean int_pending, and masks ipending, spending, and fpending. Being per-cpu variables it is not currently necessary to lock; bus cycles modifying them. Note that the same mechanism will enable preemption to be incorporated as a true software interrupt without having to further hack up the critical nesting code. * Note: the old critical_enter() code in kern/kern_switch.c is currently #ifdef to be compatible with both the old and new methodology. In STAGE-2 it will be moved entirely to MD code. Performance issues: One of the purposes of this commit is to enhance critical section performance, specifically to greatly reduce bus overhead to allow the critical section code to be used to protect per-cpu caches. These caches, such as Jeff's slab allocator work, can potentially operate very quickly making the effective savings of the new critical section code's performance very significant. The second purpose of this commit is to allow architectures to enable certain interrupts while in a critical section. Specifically, the intention is to eventually allow certain FAST interrupts to operate rather then defer. The third purpose of this commit is to begin to clean up the critical_enter()/critical_exit()/cpu_critical_enter()/ cpu_critical_exit() API which currently has serious cross pollution in MI code (in fork_exit() and ast() for example). The fourth purpose of this commit is to provide a framework that allows kernel-preempting software interrupts to be implemented cleanly. This is currently used for two forward interrupts in I386. Other architectures will have the choice of using this infrastructure or building the functionality directly into critical_enter()/ critical_exit(). Finally, this commit is designed to greatly improve the flexibility of various architectures to manage critical section handling, software interrupts, preemption, and other highly integrated architecture-specific details.
OpenPOWER on IntegriCloud