aboutsummaryrefslogtreecommitdiff
path: root/sys/i386/include/clock.h
Commit message (Collapse)AuthorAgeFilesLines
* x86: Deduplicate clock.hMark Johnston2021-12-061-40/+2
| | | | | | | | | | | The headers were mostly identical on amd64 and i386. No functional change intended. Reviewed by: cperciva, mav, imp, kib, jhb MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D33205
* timer_restore is now unused, remove itWarner Losh2020-10-081-1/+0
| | | | | | | | apm was the only consumer of timer_restore. Now that it's gone, this can be removed. Notes: svn path=/head/; revision=366547
* re-synchronize TSC-s on SMP systems after resume, if necessaryAndriy Gapon2018-05-251-0/+1
| | | | | | | | | | | | | | | | | | | | | The TSC-s are checked and synchronized only if they were good originally. That is, invariant, synchronized, etc. This is necessary on an AMD-based system where after a wakeup from STR I see that BSP clock differs from AP clocks by a count that roughly corresponds to one second. The APs are in sync with each other. Not sure if this is a hardware quirk or a firmware bug. This is what I see after a resume with this change: SMP: passed TSC synchronization test after adjustment acpi_timer0: restoring timecounter, ACPI-fast -> TSC-low Reviewed by: kib MFC after: 3 weeks Differential Revision: https://reviews.freebsd.org/D15551 Notes: svn path=/head/; revision=334204
* xen: implement an early timer for Xen PVHRoger Pau Monné2014-03-111-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When running as a PVH guest, there's no emulated i8254, so we need to use the Xen PV timer as the early source for DELAY. This change allows for different implementations of the early DELAY function and implements a Xen variant for it. Approved by: gibbs Sponsored by: Citrix Systems R&D dev/xen/timer/timer.c: dev/xen/timer/timer.h: - Implement Xen early delay functions using the PV timer and declare them. x86/include/init.h: - Add hooks for early clock source initialization and early delay functions. i386/i386/machdep.c: pc98/pc98/machdep.c: amd64/amd64/machdep.c: - Set early delay hooks to use the i8254 on bare metal. - Use clock_init (that will in turn make use of init_ops) to initialize the early clock source. amd64/include/clock.h: i386/include/clock.h: - Declare i8254_delay and clock_init. i386/xen/clock.c: - Rename DELAY to i8254_delay. x86/isa/clock.c: - Introduce clock_init that will take care of initializing the early clock by making use of the init_ops hooks. - Move non ISA related delay functions to the newly introduced delay file. x86/x86/delay.c: - Add moved delay related functions. - Implement generic DELAY function that will use the init_ops hooks. x86/xen/pv.c: - Set PVH hooks for the early delay related functions in init_ops. conf/files.amd64: conf/files.i386: conf/files.pc98: - Add delay.c to the kernel build. Notes: svn path=/head/; revision=263008
* Implement boot-time TSC synchronization test for SMP. This test is executedJung-uk Kim2011-05-091-1/+0
| | | | | | | | | | when the user has indicated that the system has synchronized TSCs or it has P-state invariant TSCs. For the former case, we may clear the tunable if it fails the test to prevent accidental foot-shooting. For the latter case, we may set it if it passes the test to notify the user that it may be usable. Notes: svn path=/head/; revision=221703
* Add forgotten declarations for tsc_perf_stat from the previous commit.Jung-uk Kim2011-04-121-0/+1
| | | | Notes: svn path=/head/; revision=220580
* Deprecate rarely used tsc_is_broken. Instead, we zero out tsc_freq becauseJung-uk Kim2011-03-101-1/+0
| | | | | | | it is almost always used with tsc_freq any way. Notes: svn path=/head/; revision=219461
* Move functions declaration to MI code, following implementation.Alexander Motin2010-07-151-5/+0
| | | | Notes: svn path=/head/; revision=210131
* - Implement MI helper functions, dividing one or two timer interrupts withAlexander Motin2010-05-241-1/+0
| | | | | | | | | | | arbitrary frequencies into hardclock(), statclock() and profclock() calls. Same code with minor variations duplicated several times over the tree for different timer drivers and architectures. - Switch all x86 archs to new functions, simplifying the code and removing extra logic from timer drivers. Other archs are also welcome. Notes: svn path=/head/; revision=208494
* Rename statclock_disable variable to atrtcclock_disable that it actually is,Alexander Motin2009-05-031-1/+0
| | | | | | | | | | | | | | | | and hide it inside of atrtc driver. Add new tunable hint.atrtc.0.clock controlling it. Setting it to 0 disables using RTC clock as stat-/ profclock sources. Teach i386 and amd64 SMP platforms to emulate stat-/profclocks using i8254 hardclock, when LAPIC and RTC clocks are disabled. This allows to reduce global interrupt rate of idle system down to about 100 interrupts per core, permitting C3 and deeper C-states provide maximum CPU power efficiency. Notes: svn path=/head/; revision=191766
* Add support for using i8254 and rtc timers as event sources for i386 SMPAlexander Motin2009-05-021-0/+6
| | | | | | | system. Redistribute hard-/stat-/profclock events to other CPUs using IPI. Notes: svn path=/head/; revision=191745
* Turn off CPU frequency change notifiers when the TSC is P-state invariantJung-uk Kim2008-10-211-0/+1
| | | | | | | | or it is forced by setting 'kern.timecounter.invariant_tsc' tunable to non-zero. Notes: svn path=/head/; revision=184102
* Now that all platforms use genclock, shuffle things around slightlyPoul-Henning Kamp2008-04-221-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | for better structure. Much of this is related to <sys/clock.h>, which should really have been called <sys/calendar.h>, but unless and until we need the name, the repocopy can wait. In general the kernel does not know about minutes, hours, days, timezones, daylight savings time, leap-years and such. All that is theoretically a matter for userland only. Parts of kernel code does however care: badly designed filesystems store timestamps in local time and RTC chips almost universally track time in a YY-MM-DD HH:MM:SS format, and sometimes in local timezone instead of UTC. For this we have <sys/clock.h> <sys/time.h> on the other hand, deals with time_t, timeval, timespec and so on. These know only seconds and fractions thereof. Move inittodr() and resettodr() prototypes to <sys/time.h>. Retain the names as it is one of the few surviving PDP/VAX references. Move startrtclock() to <machine/clock.h> on relevant platforms, it is a MD call between machdep.c/clock.c. Remove references to it elsewhere. Remove a lot of unnecessary <sys/clock.h> includes. Move the machdep.disable_rtc_set sysctl to subr_rtc.c where it belongs. XXX: should be kern.disable_rtc_set really, it's not MD. Notes: svn path=/head/; revision=178429
* Convert amd64 and i386 to share the atrtc device driver.Poul-Henning Kamp2008-04-141-2/+0
| | | | Notes: svn path=/head/; revision=178193
* The "free-lance" timer in the i8254 is only used for the speakerPoul-Henning Kamp2008-03-261-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | these days, so de-generalize the acquire_timer/release_timer api to just deal with speakers. The new (optional) MD functions are: timer_spkr_acquire() timer_spkr_release() and timer_spkr_setfreq() the last of which configures the timer to generate a tone of a given frequency, in Hz instead of 1/1193182th of seconds. Drop entirely timer2 on pc98, it is not used anywhere at all. Move sysbeep() to kern/tty_cons.c and use the timer_spkr*() if they exist, and do nothing otherwise. Remove prototypes and empty acquire-/release-timer() and sysbeep() functions from the non-beeping archs. This eliminate the need for the speaker driver to know about i8254frequency at all. In theory this makes the speaker driver MI, contingent on the timer_spkr_*() functions existing but the driver does not know this yet and still attaches to the ISA bus. Syscons is more tricky, in one function, sc_tone(), it knows the hz and things are just fine. In the other function, sc_bell() it seems to get the period from the KDMKTONE ioctl in terms if 1/1193182th second, so we hardcode the 1193182 and leave it at that. It's probably not important. Change a few other sysbeep() uses which obviously knew that the argument was in terms of i8254 frequency, and leave alone those that look like people thought sysbeep() took frequency in hertz. This eliminates the knowledge of i8254_freq from all but the actual clock.c code and the prof_machdep.c on amd64 and i386, where I think it would be smart to ask for help from the timecounters anyway [TBD]. Notes: svn path=/head/; revision=177642
* Rename timer0_max_count to i8254_max_count.Poul-Henning Kamp2008-03-261-2/+2
| | | | | | | | Rename timer0_real_max_count to i8254_real_max_count and make it static. Rename timer_freq to i8254_freq and make it a loader tunable. Notes: svn path=/head/; revision=177631
* The RTC related pscnt and psdiv variables have no business being public.Poul-Henning Kamp2008-03-261-2/+0
| | | | Notes: svn path=/head/; revision=177628
* Split /dev/nvram driver out of isa/clock.c for i386 and amd64. I have notPeter Wemm2007-10-261-1/+2
| | | | | | | | | | | refactored it to be a generic device. Instead of being part of the standard kernel, there is now a 'nvram' device for i386/amd64. It is in DEFAULTS like io and mem, and can be turned off with 'nodevice nvram'. This matches the previous behavior when it was first committed. Notes: svn path=/head/; revision=172998
* Cleaned up declaration and initialization of clock_lock. It is onlyBruce Evans2007-01-231-1/+2
| | | | | | | | | | | | | | | | | | | | | | | 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. Notes: svn path=/head/; revision=166186
* First part of a little cleanup in the calendar/timezone/RTC handling.Poul-Henning Kamp2006-10-021-3/+0
| | | | | | | | | Move relevant variables to <sys/clock.h> and fix #includes as necessary. Use libkern's much more time- & spamce-efficient BCD routines. Notes: svn path=/head/; revision=162954
* Move clock_lock prototype into <machine/clock.h>, where it is moreMaxim Sobolev2006-05-191-0/+1
| | | | | | | | | appropriate. Discussed with: jhb Notes: svn path=/head/; revision=158748
* Tweak how the MD code calls the fooclock() methods some. Instead ofJohn Baldwin2005-12-221-1/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Move pc98 specific parts to the pc98 specific file.Yoshihiro Takahashi2005-04-131-5/+0
| | | | Notes: svn path=/head/; revision=145010
* - Remove the BURN_BRIDGES marked support for hooking into the ISA timer 0John Baldwin2005-03-091-4/+0
| | | | | | | | | | | interrupt. - Remove the timer_func variable as it now has a static value of hardclock() and is only used in one place. Axe borrowed from: phk Notes: svn path=/head/; revision=143324
* /* -> /*- for copyright notices, minor format tweaks as necessaryWarner Losh2005-01-061-1/+1
| | | | Notes: svn path=/head/; revision=139790
* - Move manipulation of td_intr_nesting_level out of assembly interruptJohn Baldwin2003-11-121-0/+1
| | | | | | | | | | | | | | | | | | | | | | vector stubs and into the C functions they call. - Move disabling and EOIing of interrupt sources out of PIC driver entry points and into intr_execute_handlers(). Intr_execute_handlers() only disables a source for an interrupt if it is a stray interrupt or has threaded handlers. Sources with fast handlers no longer disable (mask) the source while executing the handlers. - Move the setting of clkintr_pending into intr_execute_handlers() and set the variable for any interrupt source with a vector of 0. (Should only be true for IRQ 0.) This fixes clkintr_pending in the NO_MIXED_MODE case. - Implement lapic_eoi() and use it to implement ioapic_eoi_source(). - Rename atpic_sched_ithd() to atpic_handle_intr() since it is used to handle all atpic interrupts and not just threaded ones. Inspired by: peter's changes to amd64 in p4 (1) Requested by: bde (2) Notes: svn path=/head/; revision=122572
* New APIC support code:John Baldwin2003-11-031-3/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - The apic interrupt entry points have been rewritten so that each entry point can serve 32 different vectors. When the entry is executed, it uses one of the 32-bit ISR registers to determine which vector in its assigned range was triggered. Thus, the apic code can support 159 different interrupt vectors with only 5 entry points. - We now always to disable the local APIC to work around an errata in certain PPros and then re-enable it again if we decide to use the APICs to route interrupts. - We no longer map IO APICs or local APICs using special page table entries. Instead, we just use pmap_mapdev(). We also no longer export the virtual address of the local APIC as a global symbol to the rest of the system, but only in local_apic.c. To aid this, the APIC ID of each CPU is exported as a per-CPU variable. - Interrupt sources are provided for each intpin on each IO APIC. Currently, each source is given a unique interrupt vector meaning that PCI interrupts are not shared on most machines with an I/O APIC. That mapping for interrupt sources to interrupt vectors is up to the APIC enumerator driver however. - We no longer probe to see if we need to use mixed mode to route IRQ 0, instead we always use mixed mode to route IRQ 0 for now. This can be disabled via the 'NO_MIXED_MODE' kernel option. - The npx(4) driver now always probes to see if a built-in FPU is present since this test can now be performed with the new APIC code. However, an SMP kernel will panic if there is more than one CPU and a built-in FPU is not found. - PCI interrupts are now properly routed when using APICs to route interrupts, so remove the hack to psuedo-route interrupts when the intpin register was read. - The apic.h header was moved to apicreg.h and a new apicvar.h header that declares the APIs used by the new APIC code was added. Notes: svn path=/head/; revision=121986
* Per TRB vote: restore the aquire_timer0 and associated goo. This willWarner Losh2003-09-241-0/+4
| | | | | | | | | | | be gone in FreeBSD 6, so put BURN_BRIDGES around it. The TRB also felt that if something better comes along sooner, it can be used to replace this code. Delayed by: BSDcon and subsequent disk crash. Notes: svn path=/head/; revision=120404
* remove acquire_timer0() and release_timer0() and related stuff.Poul-Henning Kamp2003-08-151-2/+0
| | | | Notes: svn path=/head/; revision=118956
* Dont initialize a TSC timecounter until we know if it is broken or not.Poul-Henning Kamp2003-08-061-0/+1
| | | | Notes: svn path=/head/; revision=118550
* i386/i386/tsc.c was repo-copied from i386/isa/clock.c.Poul-Henning Kamp2003-02-051-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | Remove all the stuff that does not relate to the TSC. Change the calibration to use DELAY(1000000) rather than trying to check it against the CMOS RTC, this drastically increases precision: Using 25 samples on a Athlon 700MHz UP machine I find: stddev min max average CMOS 22200 Hz -74980 Hz 34301 Hz 704928721 Hz DELAY 1805 Hz -1984 Hz 2678 Hz 704937583 Hz (The difference between the two averages is not statistically significant.) expressed in PPM of the frequency: stddev min max CMOS 31.49 PPM -106.37 PPM 48.66 PPM DELAY 2.56 PPM 2.81 PPM 3.80 PPM This code will not be used until a followup commit to sys/isa/clock.c and sys/pc98/pc98/clock.c which will only happen after some field testing. Notes: svn path=/head/; revision=110370
* Split statclock into statclock and profclock, and made the method for drivingJake Burkholder2003-02-031-0/+2
| | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=110296
* Make tsc_freq a 64bit quantity.Poul-Henning Kamp2003-01-291-1/+1
| | | | | | | Inspired by: http://www.theinquirer.net/?article=7481 Notes: svn path=/head/; revision=110039
* Remove __P.Alfred Perlstein2002-03-201-10/+9
| | | | Notes: svn path=/head/; revision=92761
* Reenable RTC interrupts after wakeup. Some laptops have a problemMitsuru IWASAKI2001-09-041-1/+1
| | | | | | | | | | | | with system statistics monitoring tools (such as systat, vmstat...) because of stopping RTC interrupts generation. Restore all the timers (RTC and i8254) atomically. Reviewed by: bde MFC after: 1 week Notes: svn path=/head/; revision=82971
* Move DELAY() from <machine/clock.h> to <sys/systm.h>Poul-Henning Kamp2000-10-151-1/+0
| | | | Notes: svn path=/head/; revision=67158
* Change #ifdef KERNEL to #ifdef _KERNEL in the public headers. "KERNEL"Peter Wemm1999-12-291-2/+2
| | | | | | | | | is an application space macro and the applications are supposed to be free to use it as they please (but cannot). This is consistant with the other BSD's who made this change quite some time ago. More commits to come. Notes: svn path=/head/; revision=55205
* i8254_restore is called from apm_default_resume() to reloadMitsuru IWASAKI1999-10-301-0/+1
| | | | | | | | | | | | | | | the countdown register. this should not be necessary but there are broken laptops that do not restore the countdown register on resume. when it happnes, it messes up the hardclock interval and system clock, which leads to the infamous "calcru: negative time" problem. Submitted by: kjc, iwasaki Reviewed by: Steve O'Hara-Smith <steveo@eircom.net> and committers. Obtained from: PAO3 Notes: svn path=/head/; revision=52669
* $Id$ -> $FreeBSD$Peter Wemm1999-08-281-1/+1
| | | | Notes: svn path=/head/; revision=50477
* Stop the TSC from being used as timecounter on K5/step0 machines.Poul-Henning Kamp1999-05-291-1/+2
| | | | Notes: svn path=/head/; revision=47592
* Remove special handling for resuming clock interrupt when using APIC_IO.Tor Egge1998-03-051-1/+4
| | | | | | | The `generic' vector stubs do the right thing. Notes: svn path=/head/; revision=34058
* Removed vestiges of previous microtime() implementation.Bruce Evans1998-02-251-6/+2
| | | | Notes: svn path=/head/; revision=33809
* Replace TOD clock code with more systematic approach.Poul-Henning Kamp1998-02-201-65/+1
| | | | | | | | | | | | | | | | | | Highlights: * Simple model for underlying hardware. * Hardware basis for timekeeping can be changed on the fly. * Only one hardware clock responsible for TOD keeping. * Provides a real nanotime() function. * Time granularity: .232E-18 seconds. * Frequency granularity: .238E-12 s/s * Frequency adjustment is continuous in time. * Less overhead for frequency adjustment. * Improves xntpd performance. Reviewed by: bde, bde, bde Notes: svn path=/head/; revision=33690
* Fixed a recently broken comment.Bruce Evans1998-02-011-4/+4
| | | | Notes: svn path=/head/; revision=33007
* More cleanup relating to our use of the TSC.Poul-Henning Kamp1997-12-281-13/+1
| | | | | | | Look in the cpu_feature (CPUID output) to see if we have it. Notes: svn path=/head/; revision=32054
* wash, sort and put in order various nits from the i586_ctr -> tscPoul-Henning Kamp1997-12-281-11/+11
| | | | | | | | | commit. Pointed out by: bde Notes: svn path=/head/; revision=32052
* Rename "i586_ctr" to "tsc" (both upper and lower case instances).Poul-Henning Kamp1997-12-261-13/+13
| | | | | | | | | Fix a couple of printfs too. Warning: This changes the names of a couple of kernel options! Notes: svn path=/head/; revision=32005
* correct the order of the variablesPeter Wemm1997-05-051-3/+5
| | | | | | | | | use #ifdef where possible instead of #if defined Submitted by: the KNF police, ie: bde :-) Notes: svn path=/head/; revision=25485
* Don't remove i586_ctr_freq from scope, leave it defined as zero. ThisPeter Wemm1997-05-041-3/+5
| | | | | | | | | | simplifies some assumptions and stops some code compile problems. This should fix the compile hiccup in PR#3491, but smp kernel profiling isn't likely to be fixed by this. Notes: svn path=/head/; revision=25457
* Man the liferafts! Here comes the long awaited SMP -> -current merge!Peter Wemm1997-04-261-4/+4
| | | | | | | | | | | | | | | | | | | There are various options documented in i386/conf/LINT, there is more to come over the next few days. The kernel should run pretty much "as before" without the options to activate SMP mode. There are a handful of known "loose ends" that need to be fixed, but have been put off since the SMP kernel is in a moderately good condition at the moment. This commit is the result of the tinkering and testing over the last 14 months by many people. A special thanks to Steve Passe for implementing the APIC code! Notes: svn path=/head/; revision=25164