summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_time.c
Commit message (Collapse)AuthorAgeFilesLines
* sys: extend use of the howmany() macro when available.pfg2016-04-261-1/+1
| | | | | We have a howmany() macro in the <sys/param.h> header that is convenient to re-use as it makes things easier to read.
* Verify that tv_sec value specified in settimeofday() and clock_settime()dchagin2015-12-271-2/+4
| | | | | | | | | | | | | | (CLOCK_REALTIME case) system calls is non negative. This commit hides a kernel panic in atrtc_settime() as the clock_ts_to_ct() does not properly convert negative tv_sec. ps. in my opinion clock_ts_to_ct() should be rewritten to properly handle negative tv_sec values. Differential Revision: https://reviews.freebsd.org/D4714 Reviewed by: kib MFC after: 1 week
* Fix an off by one in ppsratecheck(). If you asked for N=1 you'd get one,ian2015-01-111-1/+1
| | | | but for any N>1 you'd get N-1 packets/events per second.
* Allow clock_getcpuclockid() on the CPU-time clock for zombie process.dchagin2015-01-101-5/+2
| | | | | | | | | Posix does not prohibit this. Differential Revision: https://reviews.freebsd.org/D1470 Reviewed by: kib MFC after: 1 week
* The process spin lock currently has the following distinct uses:kib2014-11-261-10/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | - Threads lifetime cycle, in particular, counting of the threads in the process, and interlocking with process mutex and thread lock. The main reason of this is that turnstile locks are after thread locks, so you e.g. cannot unlock blockable mutex (think process mutex) while owning thread lock. - Virtual and profiling itimers, since the timers activation is done from the clock interrupt context. Replace the p_slock by p_itimmtx and PROC_ITIMLOCK(). - Profiling code (profil(2)), for similar reason. Replace the p_slock by p_profmtx and PROC_PROFLOCK(). - Resource usage accounting. Need for the spinlock there is subtle, my understanding is that spinlock blocks context switching for the current thread, which prevents td_runtime and similar fields from changing (updates are done at the mi_switch()). Replace the p_slock by p_statmtx and PROC_STATLOCK(). The split is done mostly for code clarity, and should not affect scalability. Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week
* Split up sys_ktimer_getoverrun() into a sys_ and a kern_ variantbz2014-08-071-2/+9
| | | | | | | and export the kern_ version needed by an upcoming linuxolator change. MFC after: 3 days Sponsored by: DARPA,AFRL
* Fix VIRTUAL and PROF interval timers for short intervals, broken at r247903.mav2014-04-161-0/+8
| | | | | | | | | Due to the way those timers are implemented, we can't handle very short intervals. In addition to that mentioned patch caused math overflows for short intervals. To avoid that round those intervals to 1 tick. PR: kern/187668 MFC after: 1 week
* Implement compat32 wrappers for the ktimer_* syscalls.kib2013-07-211-40/+50
| | | | | | Reported, reviewed and tested by: Petr Salinger <Petr.Salinger@seznam.cz> Sponsored by: The FreeBSD Foundation MFC after: 1 week
* id_t is 64bit, provide the compat32 wrapper for clock_getcpuclockid2(2).kib2013-07-201-14/+22
| | | | | | Reported and tested by: Petr Salinger <Petr.Salinger@seznam.cz> PR: threads/180652 Sponsored by: The FreeBSD Foundation
* Allow to call clock_gettime() on the clock id for zombie process.kib2013-07-131-7/+2
| | | | | | Reported by: Petr Salinger <Petr.Salinger@seznam.cz> PR: threads/180496 Sponsored by: The FreeBSD Foundation
* Make kern_nanosleep() and pause_sbt() to use per-CPU sleep queues.mav2013-03-121-3/+3
| | | | | This removes significant sleep queue lock congestion on multithreaded microbenchmarks, making them scale to multiple CPUs almost linearly.
* Reduce minimal time intervals of setitimer(2) from 1/HZ to 1/(16*HZ) bymav2013-03-061-20/+25
| | | | | | | | | | using callout_reset_sbt() instead of callout_reset(). We can't remove lower limit completely in this case because of significant processing overhead, caused by unability to use direct callout execution due to using process mutex in callout handler for sending SEGALRM signal. With support of periodic events that would allow unprivileged user to abuse the system. Reviewed by: davide
* Fix time math overflows and improve zero intervals handling in poll(),mav2013-03-061-1/+9
| | | | | | select(), nanosleep() and kevent() functions after calloutng changes. Reported by: bde
* MFcalloutng:davide2013-03-041-23/+23
| | | | | | | | | | | | kern_nanosleep() is now converted to use tsleep_sbt(). With this change nanosleep() and usleep() can handle sub-tick precision for timeouts. Also, try to help coalesce of events passing as argument to tsleep_bt() a precision value calculated as a percentage of the sleep time. This percentage is default 5%, but it can tuned according to users need via the sysctl interface. Sponsored by: Google Summer of Code 2012, iXsystems inc. Tested by: flo, marius, ian, markj, Fabian Keil
* Fix a race between kern_setitimer() and realitexpire(), where thekib2012-12-041-3/+0
| | | | | | | | | | | | | | | | | | | | | callout is started before kern_setitimer() acquires process mutex, but looses a race and kern_setitimer() gets the process mutex before the callout. Then, assuming that new specified struct itimerval has it_interval zero, but it_value non-zero, the callout, after it starts executing again, clears p->p_realtimer.it_value, but kern_setitimer() already rescheduled the callout. As the result of the race, both p_realtimer is zero, and the callout is rescheduled. Then, in the exit1(), the exit code sees that it_value is zero and does not even try to stop the callout. This allows the struct proc to be reused and eventually the armed callout is re-initialized. The consequence is the corrupted callwheel tailq. Use process mutex to interlock the callout start, which fixes the race. Reported and tested by: pho Reviewed by: jhb MFC after: 2 weeks
* Implement syscall clock_getcpuclockid2, so we can get a clock iddavidxu2012-08-171-10/+139
| | | | | | | | for process, thread or others we want to support. Use the syscall to implement POSIX API clock_getcpuclock and pthread_getcpuclockid. PR: 168417
* In order to maximize the re-usability of kernel code in user space thiskmacy2011-09-161-15/+15
| | | | | | | | | | | | | patch modifies makesyscalls.sh to prefix all of the non-compatibility calls (e.g. not linux_, freebsd32_) with sys_ and updates the kernel entry points and all places in the code that use them. It also fixes an additional name space collision between the kernel function psignal and the libc function of the same name by renaming the kernel psignal kern_psignal(). By introducing this change now we will ease future MFCs that change syscalls. Reviewed by: rwatson Approved by: re (bz)
* Create a global thread hash table to speed up thread lookup, usedavidxu2010-10-091-17/+11
| | | | | | | | | | rwlock to protect the table. In old code, thread lookup is done with process lock held, to find a thread, kernel has to iterate through process and thread list, this is quite inefficient. With this change, test shows in extreme case performance is dramatically improved. Earlier patch was reviewed by: jhb, julian
* Remove VOP_LEASE and supporting functions. This hasn't been used sincerwatson2009-04-101-12/+0
| | | | | | | | | | | | | | the removal of NQNFS, but was left in in case it was required for NFSv4. Since our new NFSv4 client and server can't use it for their requirements, GC the old mechanism, as well as other unused lease- related code and interfaces. Due to its impact on kernel programming and binary interfaces, this change should not be MFC'd. Proposed by: jeff Reviewed by: jeff Discussed with: rmacklem, zach loafman @ isilon
* Correctly sanity-check timer IDs. [SA-09:06]cperciva2009-03-231-1/+2
| | | | | | | | | | Limit the size of malloced buffer when dumping environment variables. [EN-09:01] Approved by: so (cperciva) Approved by: re (kensmith) Security: FreeBSD-SA-09:06.ktimer Errata: FreeBSD-EN-09:01.kenv
* Remove even more unneeded variable assignments.ed2009-02-261-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | kern_time.c: - Unused variable `p'. kern_thr.c: - Variable `error' is always caught immediately, so no reason to initialize it. There is no way that error != 0 at the end of create_thread(). kern_sig.c: - Unused variable `code'. kern_synch.c: - `rval' is always assigned in all different cases. kern_rwlock.c: - `v' is always overwritten with RW_UNLOCKED further on. kern_malloc.c: - `size' is always initialized with the proper value before being used. kern_exit.c: - `error' is always caught and returned immediately. abort2() never returns a non-zero value. kern_exec.c: - `len' is always assigned inside the if-statement right below it. tty_info.c: - `td' is always overwritten by FOREACH_THREAD_IN_PROC(). Found by: LLVM's scan-build
* In realtimer_delete(), clear timer's value and interval to telldavidxu2008-10-201-0/+8
| | | | | | | realtimer_expire() to not rearm the timer, otherwise there is a chance that a callout will be left there and be tiggered in future unexpectly. Bug reported by: tegge@
* Make sure reading td_runtime in critical section since thread may bedavidxu2008-01-181-1/+2
| | | | preempted and td_runtime will be modified.
* Add POSIX clock id CLOCK_THREAD_CPUTIME_ID, this can be used to measuredavidxu2008-01-181-0/+16
| | | | per-thread runtime in user code.
* rufetch and calcru sometimes should be called atomically together.attilio2007-06-091-0/+4
| | | | | | | | | | This patch fixes places where they should be called atomically changing their locking requirements (both assume per-proc spinlock held) and introducing rufetchcalc which wrappers both calls to be performed in atomic way. Reviewed by: jeff Approved by: jeff (mentor)
* Commit 14/14 of sched_lock decomposition.jeff2007-06-051-4/+4
| | | | | | | | | | | - Use thread_lock() rather than sched_lock for per-thread scheduling sychronization. - Use the per-process spinlock rather than the sched_lock for per-process scheduling synchronization. Tested by: kris, current@ Tested on: i386, amd64, ULE, 4BSD, libthr, libkse, PREEMPTION, etc. Discussed with: kris, attilio, kmacy, jhb, julian, bde (small parts each)
* Remove MAC Framework access control check entry points made redundant withrwatson2007-04-221-14/+0
| | | | | | | | | | | | | | | | | | the introduction of priv(9) and MAC Framework entry points for privilege checking/granting. These entry points exactly aligned with privileges and provided no additional security context: - mac_check_sysarch_ioperm() - mac_check_kld_unload() - mac_check_settime() - mac_check_system_nfsd() Add mpo_priv_check() implementations to Biba and LOMAC policies, which, for each privilege, determine if they can be granted to processes considered unprivileged by those two policies. These mostly, but not entirely, align with the set of privileges granted in jails. Obtained from: TrustedBSD Project
* Further system call comment cleanup:rwatson2007-03-051-26/+16
| | | | | | | | | | - Remove also "MP SAFE" after prior "MPSAFE" pass. (suggested by bde) - Remove extra blank lines in some cases. - Add extra blank lines in some cases. - Remove no-op comments consisting solely of the function name, the word "syscall", or the system call name. - Add punctuation. - Re-wrap some comments.
* Remove 'MPSAFE' annotations from the comments above most system calls: allrwatson2007-03-041-21/+0
| | | | | | | | system calls now enter without Giant held, and then in some cases, acquire Giant explicitly. Remove a number of other MPSAFE annotations in the credential code and tweak one or two other adjacent comments.
* - Remove third parameter of itimer_find, the parameter is always zero.davidxu2006-11-281-46/+16
| | | | | - Call callout_drain on deleting POSIX timer. - Use kern_timer_delete in exiting hook.
* Merge posix4/* into normal kernel hierarchy.trhodes2006-11-111-2/+1
| | | | | Reviewed by: glanced at by jhb Approved by: silence on -arch@ and -standards@
* Sweep kernel replacing suser(9) calls with priv(9) calls, assigningrwatson2006-11-061-2/+3
| | | | | | | | | | | | | specific privilege names to a broad range of privileges. These may require some future tweaking. Sponsored by: nCircle Network Security, Inc. Obtained from: TrustedBSD Project Discussed on: arch@ Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri, Alex Lyashkov <umka at sevcity dot net>, Skip Ford <skip dot ford at verizon dot net>, Antoine Brodin <antoine dot brodin at laposte dot net>
* Complete break-out of sys/sys/mac.h into sys/security/mac/mac_framework.hrwatson2006-10-221-1/+2
| | | | | | | | | | | | | begun with a repo-copy of mac.h to mac_framework.h. sys/mac.h now contains the userspace and user<->kernel API and definitions, with all in-kernel interfaces moved to mac_framework.h, which is now included across most of the kernel instead. This change is the first step in a larger cleanup and sweep of MAC Framework interfaces in the kernel, and will not be MFC'd. Obtained from: TrustedBSD Project Sponsored by: SPARTA
* Move tz_minuteswest and tz_dsttime to subr_clock.cphk2006-10-021-3/+0
|
* 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.
* - Change process_exec function handlers prototype to include structnetchild2006-08-151-4/+11
| | | | | | | | | | | | | image_params arg. - Change struct image_params to include struct sysentvec pointer and initialize it. - Change all consumers of process_exit/process_exec eventhandlers to new prototypes (includes splitting up into distinct exec/exit functions). - Add eventhandler to userret. Sponsored by: Google SoC 2006 Submitted by: rdivacky Parts suggested by: jhb (on hackers@)
* INT_MAX is defined in file sys/limits.h, include the file now.davidxu2006-08-021-0/+1
|
* Let kernel POSIX timer code and mqueue code to use integer as a resourcedavidxu2006-03-011-23/+23
| | | | | handle, the timer_t and mqd_t types will be a pointer which userland will define it.
* Fix compiling warning on 64 bits system.davidxu2005-12-091-1/+1
|
* Register itimers_event_hook as a kernel event handler, so I don'tdavidxu2005-12-091-2/+9
| | | | have to duplicate code to call it in exec() and exit1().
* 1. Set timer configuration values for sysconf().davidxu2005-12-011-2/+15
| | | | | 2. Set overrun limit to INT_MAX, report ERANGE error if overrun will be greater than INT_MAX.
* Add several aliases for existing clockid_t names to indicate that therwatson2005-11-271-2/+26
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | application wishes to request high precision time stamps be returned: Alias Existing CLOCK_REALTIME_PRECISE CLOCK_REALTIME CLOCK_MONOTONIC_PRECISE CLOCK_MONOTONIC CLOCK_UPTIME_PRECISE CLOCK_UPTIME Add experimental low-precision clockid_t names corresponding to these clocks, but implemented using cached timestamps in kernel rather than a full time counter query. This offers a minimum update rate of 1/HZ, but in practice will often be more frequent due to the frequency of time stamping in the kernel: New clockid_t name Approximates existing clockid_t CLOCK_REALTIME_FAST CLOCK_REALTIME CLOCK_MONOTONIC_FAST CLOCK_MONOTONIC CLOCK_UPTIME_FAST CLOCK_UPTIME Add one additional new clockid_t, CLOCK_SECOND, which returns the current second without performing a full time counter query or cache lookup overhead to make sure the cached timestamp is stable. This is intended to support very low granularity consumers, such as time(3). The names, visibility, and implementation of the above are subject to change, and will not be MFC'd any time soon. The goal is to expose lower quality time measurement to applications willing to sacrifice accuracy in performance critical paths, such as when taking time stamps for the purpose of rescheduling select() and poll() timeouts. Future changes might include retrofitting the time counter infrastructure to allow the "fast" time query mechanisms to use a different time counter, rather than a cached time counter (i.e., TSC). NOTE: With different underlying time mechanisms exposed, using different time query mechanisms in the same application may result in relative non-monoticity or the appearance of clock stalling for a single clockid_t, as a cached time stamp queried after a precision time stamp lookup may be "before" the time returned by the earlier live time counter query.
* Add CLOCK_UPTIME to clock_gettime(2) reporting the currentandre2005-11-181-0/+2
| | | | | | uptime measured in SI seconds. Sponsored by: TCP/IP Optimization Fundraise 2005
* Fix name compatible problem with POSIX standard. the sigval_ptr anddavidxu2005-11-041-1/+1
| | | | | | sigval_int really should be sival_ptr and sival_int. Also sigev_notify_function accepts a union sigval value but not a pointer.
* Cleanup some signal interfaces. Now the tdsignal function acceptsdavidxu2005-11-031-28/+11
| | | | | | | | | both proc pointer and thread pointer, if thread pointer is NULL, tdsignal automatically finds a thread, otherwise it sends signal to given thread. Add utility function psignal_event to send a realtime sigevent to a process according to the delivery requirement specified in struct sigevent.
* Let itimer store itimerspec instead of itimerval, so I don't have todavidxu2005-10-301-59/+118
| | | | | | | | | | | | | | | | | | | convert to or from timeval frequently. Introduce function itimer_accept() to ack a timer signal in signal acceptance code, this allows us to return more fresh overrun counter than at signal generating time. while POSIX says: "the value returned by timer_getoverrun() shall apply to the most recent expiration signal delivery or acceptance for the timer,.." I prefer returning it at acceptance time. Introduce SIGEV_THREAD_ID notification mode, it is used by thread libary to request kernel to deliver signal to a specified thread, and in turn, the thread library may use the mechanism to implement SIGEV_THREAD which is required by POSIX. Timer signal is managed by timer code, so it can not fail even if signal queue is full filled by sigqueue syscall.
* Don't touch last overrun if signal was already on queue.davidxu2005-10-231-2/+0
|
* Make p_itimers as a pointer, so file sys/proc.h does not need to includedavidxu2005-10-231-28/+25
| | | | sys/timers.h.
* Implement POSIX timers. Current only CLOCK_REALTIME and CLOCK_MONOTONICdavidxu2005-10-231-2/+664
| | | | | | | | | | | | clock are supported. I have plan to merge XSI timer ITIMER_REAL and other two CPU timers into the new code, current three slots are available for the XSI timers. The SIGEV_THREAD notification type is not supported yet because our sigevent struct lacks of two member fields: sigev_notify_function sigev_notify_attributes I have found the sigevent is used in AIO, so I won't add the two members unless the AIO code is adjusted.
* Implement 32bit wrappers for clock_gettime, clock_settime, andps2005-10-151-19/+51
| | | | clock_getres.
OpenPOWER on IntegriCloud