OpenBSD CVS

CVS log for src/sys/kern/kern_timeout.c


[BACK] Up to [local] / src / sys / kern

Request diff between arbitrary revisions


Default branch: MAIN


Revision 1.97 / (download) - annotate - [select for diffs], Fri Feb 23 16:51:39 2024 UTC (3 months, 2 weeks ago) by cheloha
Branch: MAIN
CVS Tags: OPENBSD_7_5_BASE, OPENBSD_7_5, HEAD
Changes since 1.96: +23 -10 lines
Diff to previous 1.96 (colored)

timeout: make to_kclock validation more rigorous

In kern_timeout.c, the to_kclock checks are not strict enough to catch
all plausible programmer mistakes.  Tighten them up:

- timeout_set_flags: KASSERT that kclock is valid
- timeout_abs_ts: KASSERT that to_kclock is KCLOCK_UPTIME

We can also add to_kclock validation to softclock() and
db_show_timeout(), which may help to debug memory corruption:

- softclock: panic if to_kclock is not KCLOCK_NONE or KCLOCK_UPTIME
- db_show_timeout: print warning if to_kclock is invalid

Prompted by bluhm@ in response to a syzbot panic.  Hopefully these
changes help to narrow down the root cause.

Link: https://syzkaller.appspot.com/bug?extid=49d3f7118413963f651a
Reported-by: syzbot+49d3f7118413963f651a@syzkaller.appspotmail.com
ok bluhm@

Revision 1.96 / (download) - annotate - [select for diffs], Thu Oct 12 15:32:38 2023 UTC (7 months, 4 weeks ago) by cheloha
Branch: MAIN
Changes since 1.95: +99 -21 lines
Diff to previous 1.95 (colored)

timeout: add TIMEOUT_MPSAFE flag

Add a TIMEOUT_MPSAFE flag to signal that a timeout is safe to run
without the kernel lock.  Currently, TIMEOUT_MPSAFE requires
TIMEOUT_PROC.  When the softclock() is unlocked in the future this
dependency will be removed.

On MULTIPROCESSOR kernels, softclock() now shunts TIMEOUT_MPSAFE
timeouts to a dedicated "timeout_proc_mp" bucket for processing by the
dedicated softclock_thread_mp() kthread.  Unlike softclock_thread(),
softclock_thread_mp() is not pinned to any CPU and runs run at IPL_NONE.

Prompted by bluhm@.  Lots of input from bluhm@.  Joint work with mvs@.

Prompt: https://marc.info/?l=openbsd-tech&m=169646019109736&w=2
Thread: https://marc.info/?l=openbsd-tech&m=169652212131109&w=2

ok mvs@

Revision 1.95 / (download) - annotate - [select for diffs], Sat Jul 29 06:52:08 2023 UTC (10 months, 2 weeks ago) by anton
Branch: MAIN
CVS Tags: OPENBSD_7_4_BASE, OPENBSD_7_4
Changes since 1.94: +5 -3 lines
Diff to previous 1.94 (colored)

Avoid accessing curproc early during boot when kcov is enabled as it
might be unassigned until all secondary processors are up and running.

Revision 1.94 / (download) - annotate - [select for diffs], Fri Jul 14 07:07:08 2023 UTC (10 months, 4 weeks ago) by claudio
Branch: MAIN
Changes since 1.93: +3 -4 lines
Diff to previous 1.93 (colored)

struct sleep_state is no longer used, remove it.
Also remove the priority argument to sleep_finish() the code can use
the p_flag P_SINTR flag to know if the signal check is needed or not.
OK cheloha@ kettenis@ mpi@

Revision 1.93 / (download) - annotate - [select for diffs], Thu Jul 6 23:24:37 2023 UTC (11 months ago) by cheloha
Branch: MAIN
Changes since 1.92: +3 -4 lines
Diff to previous 1.92 (colored)

timeout_hardclock_update: enter timeout_mutex before reading uptime clock

We have no way of knowing how long we will spin before entering
timeout_mutex.  Enter timeout_mutex first, then wait until just before
we start dumping kclock buckets to read the uptime clock.

Revision 1.92 / (download) - annotate - [select for diffs], Wed Jun 28 08:23:25 2023 UTC (11 months, 2 weeks ago) by claudio
Branch: MAIN
Changes since 1.91: +3 -3 lines
Diff to previous 1.91 (colored)

First step at removing struct sleep_state.

Pass the timeout and sleep priority not only to sleep_setup() but also
to sleep_finish(). With that sls_timeout and sls_catch can be removed
from struct sleep_state.

The timeout is now setup first thing in sleep_finish() and no longer as
last thing in sleep_setup(). This should not cause a noticeable difference
since the code run between sleep_setup() and sleep_finish() is minimal.

OK kettenis@

Revision 1.91 / (download) - annotate - [select for diffs], Mon Jun 26 16:26:20 2023 UTC (11 months, 2 weeks ago) by cheloha
Branch: MAIN
Changes since 1.90: +3 -5 lines
Diff to previous 1.90 (colored)

timeout_hardclock_update: provide initial value for automatic variables

Revision 1.90 / (download) - annotate - [select for diffs], Sat Dec 31 16:06:24 2022 UTC (17 months, 1 week ago) by cheloha
Branch: MAIN
CVS Tags: OPENBSD_7_3_BASE, OPENBSD_7_3
Changes since 1.89: +2 -2 lines
Diff to previous 1.89 (colored)

timeout: rename "timeout_at_ts" to "timeout_abs_ts"

I think "abs" ("absolute timeout") is a better mnemonic than
"at" ("at the given time").

The interface is undocumented and there are only two callers, so
renaming it is not a big deal.

probably ok kn@

Revision 1.89 / (download) - annotate - [select for diffs], Mon Dec 5 23:18:37 2022 UTC (18 months ago) by deraadt
Branch: MAIN
Changes since 1.88: +3 -3 lines
Diff to previous 1.88 (colored)

zap a pile of dangling tabs

Revision 1.88 / (download) - annotate - [select for diffs], Fri Nov 11 18:09:58 2022 UTC (18 months, 4 weeks ago) by cheloha
Branch: MAIN
Changes since 1.87: +11 -23 lines
Diff to previous 1.87 (colored)

timeout(9): remove timeout_set_kclock(), TIMEOUT_INITIALIZER_KCLOCK()

We have too many timeout(9) initialization functions and macros.
Let's slim it down and combine some interfaces.

- Remove timeout_set_kclock(), TIMEOUT_INITIALIZER_KCLOCK().
- Expand timeout_set_flags(), TIMEOUT_INITIALIZER_FLAGS() to accept
  an additional "kclock" parameter.
- Reimplement timeout_set(), timeout_set_proc() with timeout_set_flags().
- Reimplement TIMEOUT_INITIALIZER() with TIMEOUT_INITIALIZER_FLAGS().
- Update the sole timeout_set_flags() user to pass a kclock parameter.
- Update the sole timeout_set_kclock() user to call timeout_set_flags().
- Update the sole TIMEOUT_INITIALIZER_FLAGS() user to provide a kclock
  parameter.

The timeout(9) code is now a bit out of sync with the manpage.  This
will be corrected in a subsequent commit.

ok kn@

Revision 1.87 / (download) - annotate - [select for diffs], Wed Nov 9 17:12:50 2022 UTC (19 months ago) by cheloha
Branch: MAIN
Changes since 1.86: +10 -10 lines
Diff to previous 1.86 (colored)

timeout(9): remove TIMEOUT_KCLOCK flag

I never should have added the TIMEOUT_KCLOCK flag.  It is redundant
and only serves to complicate the timeout(9) logic.  In every place
where we check for the flag we can just use timeout.to_kclock.

So, remove the flag from <sys/timeout.h> and rewrite all affected
logic to use the value of timeout.to_kclock instead.

ok kn@

Revision 1.86 / (download) - annotate - [select for diffs], Tue Nov 8 19:09:53 2022 UTC (19 months ago) by cheloha
Branch: MAIN
Changes since 1.85: +1 -26 lines
Diff to previous 1.85 (colored)

timeout(9): remove unused, undocumented timeout_in_nsec() interface

The kernel is not quite ready for timeout_in_nsec().  Remove it and
kclock_nanotime().  Both are unused.

Prompted by jsg@.

ok kn@

Revision 1.85 / (download) - annotate - [select for diffs], Sat Jun 19 02:05:33 2021 UTC (2 years, 11 months ago) by cheloha
Branch: MAIN
CVS Tags: OPENBSD_7_2_BASE, OPENBSD_7_2, OPENBSD_7_1_BASE, OPENBSD_7_1, OPENBSD_7_0_BASE, OPENBSD_7_0
Changes since 1.84: +9 -9 lines
Diff to previous 1.84 (colored)

timeout(9): change argument order for timeout_set_kclock()

Move the kclock argument before the flags argument.  XORing a bunch of
flags together may "sprawl", and I'd rather have any sprawl at the end
of the parameter list.

timeout_set_kclock() is undocumented and there is only one caller, so
no big refactor required.

Best to do this argument order shuffle before any bigger refactors of
e.g. timeout_set(9).

Revision 1.84 / (download) - annotate - [select for diffs], Tue May 11 13:29:25 2021 UTC (3 years, 1 month ago) by cheloha
Branch: MAIN
Changes since 1.83: +25 -21 lines
Diff to previous 1.83 (colored)

timeout_barrier(9), timeout_del_barrier(9): remove kernel lock

In timeout_barrier(9) we take/release the kernel lock to ensure that the
given timeout has finished running (if it had been running at all).

This approach is inefficient.  If we put a barrier timeout on the
queue and wait for it to run in cond_wait(9) we can block instead of
spinning for the kernel lock.  We already do this for process-context
timeouts in timeout_barrier(9) anyway.

Discussed with dlg@, visa@, and mpi@.

ok dlg@

Revision 1.83 / (download) - annotate - [select for diffs], Mon Feb 8 08:18:45 2021 UTC (3 years, 4 months ago) by mpi
Branch: MAIN
CVS Tags: OPENBSD_6_9_BASE, OPENBSD_6_9
Changes since 1.82: +2 -2 lines
Diff to previous 1.82 (colored)

Simplify sleep_setup API to two operations in preparation for splitting
the SCHED_LOCK().

Putting a thread on a sleep queue is reduce to the following:

sleep_setup();
/* check condition or release lock */
sleep_finish();

Previous version ok cheloha@, jmatthew@, ok claudio@

Revision 1.82 / (download) - annotate - [select for diffs], Tue Oct 20 22:37:12 2020 UTC (3 years, 7 months ago) by cheloha
Branch: MAIN
Changes since 1.81: +2 -2 lines
Diff to previous 1.81 (colored)

timeout(9): fix compilation under NKCOV

Revision 1.81 / (download) - annotate - [select for diffs], Thu Oct 15 20:03:43 2020 UTC (3 years, 7 months ago) by cheloha
Branch: MAIN
Changes since 1.80: +337 -59 lines
Diff to previous 1.80 (colored)

timeout(9): basic support for kclock timeouts

A kclock timeout is a timeout that expires at an absolute time on one
of the kernel's clocks.  A timeout's absolute expiration time is kept
in a new member of the timeout struct, to_abstime.  The timeout's
kclock is set at initialization and is kept in another new member of
the timeout struct, to_kclock.

Kclock timeouts are desireable because they have nanosecond
resolution, regardless of the value of hz(9).  The timecounter
subsystem is also inherently NTP-sensitive, so timeouts scheduled
against the subsystem are NTP-sensitive.  These two qualities
guarantee that a kclock timeout will never expire early.

Currently there is support for one kclock, KCLOCK_UPTIME (the uptime
clock).  Support for KCLOCK_RUNTIME (the runtime clock) and KCLOCK_UTC
(the UTC clock) is planned for the future.

Support for these additional kclocks will allow us to implement some
of the POSIX interfaces OpenBSD is missing, e.g. clock_nanosleep() and
timer_create().  We could also use it to provide proper absolute
timeouts for e.g. pthread_mutex_timedlock(3).

Kclock timeouts are initialized with timeout_set_kclock().  They can
be scheduled with either timeout_in_nsec() (relative timeout) or
timeout_at_ts() (absolute timeout).  They are incompatible with
timeout_add(9), timeout_add_sec(9), timeout_add_msec(9),
timeout_add_usec(9), timeout_add_nsec(9), and timeout_add_tv(9).
They can be cancelled with timeout_del(9) or timeout_del_barrier(9).

Documentation for the new interfaces is a work in progress.

For now, tick-based timeouts remain supported alongside kclock
timeouts.  They will remain supported until we are certain we don't
need them anymore.  It is possible we will never remove them.  I would
rather not keep them around forever, but I cannot predict what
difficulties we will encounter while converting tick-based timeouts to
kclock timeouts.  There are a *lot* of timeouts in the kernel.

Kclock timeouts are more costly than tick-based timeouts:

 - Calling timeout_in_nsec() incurs a call to nanouptime(9).  Reading
   the hardware timecounter is too expensive in some contexts, so care
   must be taken when converting existing timeouts.

   We may add a flag in the future to cause timeout_in_nsec() to use
   getnanouptime(9) instead of nanouptime(9), which is much cheaper.
   This may be appropriate for certain classes of timeouts.  tcp/ip
   session timeouts come to mind.

 - Kclock timeout expirations are kept in a timespec.  Timespec
   arithmetic has more overhead than 32-bit tick arithmetic, so
   processing kclock timeouts during softclock() is more expensive.
   On my machine the overhead for processing a tick-based timeout is
   ~125 cycles.  The overhead for a kclock timeout is ~500 cycles.

   The overhead difference on 32-bit platforms is unknown.  If it
   proves too large we may need to use a 64-bit value to store the
   expiration time.  More measurement is needed.

Priority targets for conversion are setitimer(2), *sleep_nsec(9), and
the kevent(2) EVFILT_TIMER timers.  Others will follow.

With input from mpi@, visa@, kettenis@, dlg@, guenther@, claudio@,
deraadt@, probably many others.  Older version tested by visa@.
Problems found in older version by bluhm@.  Current version tested by
Yuichiro Naito.

"wait until after unlock" deraadt@, ok kettenis@

Revision 1.80 / (download) - annotate - [select for diffs], Tue Sep 22 13:43:28 2020 UTC (3 years, 8 months ago) by cheloha
Branch: MAIN
CVS Tags: OPENBSD_6_8_BASE, OPENBSD_6_8
Changes since 1.79: +4 -2 lines
Diff to previous 1.79 (colored)

timeout(9): timeout_run(): read to_process before leaving timeout_mutex

to_process is assigned during timeout_add(9) within timeout_mutex.  In
timeout_run() we need to read to_process before leaving timeout_mutex
to ensure that the process pointer given to kcov_remote_enter(9) is
the same as the one we set from timeout_add(9) when the candidate
timeout was originally scheduled to run.

Revision 1.79 / (download) - annotate - [select for diffs], Fri Aug 7 00:45:25 2020 UTC (3 years, 10 months ago) by cheloha
Branch: MAIN
Changes since 1.78: +1 -30 lines
Diff to previous 1.78 (colored)

timeout(9): remove unused interfaces: timeout_add_ts(9), timeout_add_bt(9)

These two interfaces have been entirely unused since introduction.
Remove them and thin the "timeout" namespace a bit.

Discussed with mpi@ and ratchov@ almost a year ago, though I blocked
the change at that time.  Also discussed with visa@.

ok visa@, mpi@

Revision 1.78 / (download) - annotate - [select for diffs], Thu Aug 6 17:54:08 2020 UTC (3 years, 10 months ago) by cheloha
Branch: MAIN
Changes since 1.77: +6 -3 lines
Diff to previous 1.77 (colored)

timeout(9): fix miscellaneous remote kcov(4) bugs

Commit v1.77 introduced remote kcov support for timeouts.  We need to
tweak a few things to make our support more correct:

- Set to_process for barrier timeouts to the calling thread's parent
  process.  Currently it is uninitialized, so during timeout_run() we
  are passing stack garbage to kcov_remote_enter(9).

- Set to_process to NULL during timeout_set_flags(9).  If in the
  future we forget to properly initialize to_process before reaching
  timeout_run(), we'll pass NULL to kcov_remote_enter(9).

  anton@ says this is harmless.  I assume it is also preferable to
  passing stack garbage.

- Save a copy of to_process on the stack in timeout_run() before
  calling to_func to ensure that we pass the same process pointer
  to kcov_remote_leave(9) upon return.  The timeout may be freely
  modified from to_func, so to_process may have changed when we
  return.

Tested by anton@.

ok anton@

Revision 1.77 / (download) - annotate - [select for diffs], Sat Aug 1 08:40:20 2020 UTC (3 years, 10 months ago) by anton
Branch: MAIN
Changes since 1.76: +15 -1 lines
Diff to previous 1.76 (colored)

Add support for remote coverage to kcov. Remote coverage is collected
from threads other than the one currently having kcov enabled. A thread
with kcov enabled occasionally delegates work to another thread,
collecting coverage from such threads improves the ability of syzkaller
to correlate side effects in the kernel caused by issuing a syscall.

Remote coverage is divided into subsystems. The only supported subsystem
right now collects coverage from scheduled tasks and timeouts on behalf
of a kcov enabled thread. In order to make this work `struct task' and
`struct timeout' must be extended with a new field keeping track of the
process that scheduled the task/timeout. Both aforementioned structures
have therefore increased with the size of a pointer on all
architectures.

The kernel API is documented in a new kcov_remote_register(9) manual.

Remote coverage is also supported by kcov on NetBSD and Linux.

ok mpi@

Revision 1.76 / (download) - annotate - [select for diffs], Sat Jul 25 00:48:04 2020 UTC (3 years, 10 months ago) by cheloha
Branch: MAIN
Changes since 1.75: +16 -11 lines
Diff to previous 1.75 (colored)

timeout(9): remove TIMEOUT_SCHEDULED flag

The TIMEOUT_SCHEDULED flag was added a few months ago to differentiate
between wheel timeouts and new timeouts during softclock().  The
distinction is useful when incrementing the "rescheduled" stat and the
"late" stat.

Now that we have an intermediate queue for new timeouts, timeout_new,
we don't need the flag.  The distinction between wheel timeouts and
new timeouts can be made computationally.

Suggested by procter@ several months ago.

Revision 1.75 / (download) - annotate - [select for diffs], Fri Jul 24 21:01:33 2020 UTC (3 years, 10 months ago) by cheloha
Branch: MAIN
Changes since 1.74: +14 -6 lines
Diff to previous 1.74 (colored)

timeout(9): delay processing of timeouts added during softclock()

New timeouts are appended to the timeout_todo circq via
timeout_add(9).  If this is done during softclock(), i.e. a timeout
function calls timeout_add(9) to reschedule itself, the newly added
timeout will be processed later during the same softclock().

This works, but it is not optimal:

1. If a timeout reschedules itself to run in zero ticks, i.e.

	timeout_add(..., 0);

   it will be run again during the current softclock().  This can
   cause an infinite loop, softlocking the primary CPU.

2. Many timeouts are cancelled before they execute.  Processing a
   timeout during the current softclock() is "eager": if we waited, the
   timeout might be cancelled and we could spare ourselves the effort.

   If the timeout is not cancelled before the next softclock() we can
   bucket it as we normally would with no change in behavior.

3. Many timeouts are scheduled to run after 1 tick, i.e.

	timeout_add(..., 1);

   Processing these timeouts during the same softclock means bucketing
   them for no reason: they will be dumped into the timeout_todo queue
   during the next hardclock(9) anyway.  Processing them is pointless.

We can avoid these issues by using an intermediate queue, timeout_new.
New timeouts are put onto this queue during timeout_add(9).  The queue
is concatenated to the end of the timeout_todo queue at the start of
each softclock() and then softclock() proceeds.  This means the amount
of work done during a given softclock() is finite and we avoid doing
extra work with eager processing.

Any timeouts that *depend* upon being rerun during the current
softclock() will need to be updated, though I doubt any such timeouts
exist.

Discussed with visa@ last year.

No complaints after a month.

Revision 1.74 / (download) - annotate - [select for diffs], Fri Jul 24 04:53:04 2020 UTC (3 years, 10 months ago) by kn
Branch: MAIN
Changes since 1.73: +3 -1 lines
Diff to previous 1.73 (colored)

Make timeout_add_sec(9) add a tick if given zero seconds

All other timeout_add_*() functions do so before calling timeout_add(9) as
described in the manual, this one did not.

OK cheloha

Revision 1.73 / (download) - annotate - [select for diffs], Sat Jul 4 08:06:08 2020 UTC (3 years, 11 months ago) by anton
Branch: MAIN
Changes since 1.72: +6 -6 lines
Diff to previous 1.72 (colored)

It's been agreed upon that global locks should be expressed using
capital letters in locking annotations. Therefore harmonize the existing
annotations.

Also, if multiple locks are required they should be delimited using
commas.

ok mpi@

Revision 1.72 / (download) - annotate - [select for diffs], Tue Feb 18 12:13:40 2020 UTC (4 years, 3 months ago) by mpi
Branch: MAIN
CVS Tags: OPENBSD_6_7_BASE, OPENBSD_6_7
Changes since 1.71: +2 -1 lines
Diff to previous 1.71 (colored)

Cleanup <sys/kthread.h> and <sys/proc.h> includes.

Do not include <sys/kthread.h> where it is not needed and stop including
<sys/proc.h> in it.

ok visa@, anton@

Revision 1.71 / (download) - annotate - [select for diffs], Mon Jan 13 09:51:52 2020 UTC (4 years, 4 months ago) by mpi
Branch: MAIN
Changes since 1.70: +4 -1 lines
Diff to previous 1.70 (colored)

Raise ipl of the softclock thread to IPL_SOFTCLOCK.

This prevent the soft-interrupt to run in-between of timeouts executed
in a thread context.

ok kettenis@, visa@

Revision 1.70 / (download) - annotate - [select for diffs], Fri Jan 3 20:11:11 2020 UTC (4 years, 5 months ago) by cheloha
Branch: MAIN
Changes since 1.69: +3 -4 lines
Diff to previous 1.69 (colored)

timeout(9): delay thread wakeup(9) decision to end of softclock() loop

The process-context timeout(s) in question might be cancelled before we
leave the loop, leading to a spurious wakeup(9).

ok mpi@

Revision 1.69 / (download) - annotate - [select for diffs], Fri Jan 3 02:16:38 2020 UTC (4 years, 5 months ago) by cheloha
Branch: MAIN
Changes since 1.68: +11 -6 lines
Diff to previous 1.68 (colored)

timeout(9): Add timeout_set_flags(9) and TIMEOUT_INITIALIZER_FLAGS(9)

These allow the caller to initialize timeouts with arbitrary flags.  We
only have one flag at the moment, TIMEOUT_PROC, but experimenting with
other flags is easier if these interfaces are available in-tree.

With input from bluhm@, guenther@, and visa@.

"makes sense to me" bluhm@, ok visa@

Revision 1.68 / (download) - annotate - [select for diffs], Fri Jan 3 01:16:12 2020 UTC (4 years, 5 months ago) by cheloha
Branch: MAIN
Changes since 1.67: +6 -6 lines
Diff to previous 1.67 (colored)

timeout(9): Rename the TIMEOUT_NEEDPROCCTX flag to TIMEOUT_PROC.

This makes it more likely to fit into 80 columns if used alongside
the forthcoming timeout_set_flags() and TIMEOUT_INITIALIZER_FLAGS()
interfaces.

"makes sense to me" bluhm@, ok visa@

Revision 1.67 / (download) - annotate - [select for diffs], Wed Dec 25 00:15:36 2019 UTC (4 years, 5 months ago) by cheloha
Branch: MAIN
Changes since 1.66: +10 -6 lines
Diff to previous 1.66 (colored)

timeout(9): new flag: TIMEOUT_SCHEDULED, new statistic: tos_scheduled

This flag is set whenever a timeout is put on the wheel and cleared upon
(a) running, (b) deletion, and (c) readdition.  It serves two purposes:

1. Facilitate distinguishing scheduled and rescheduled timeouts.  When a
   timeout is put on the wheel it is "scheduled" for a later softclock().
   If this happens two or more times it is also said to be "rescheduled".
   The tos_rescheduled value thus indicates how many distant timeouts
   have been cascaded into a lower wheel level.

2. Eliminate false late timeouts.  A timeout is not late if it is due
   before softclock() has had a chance to schedule it.  To track this we
   need additional state, hence a new flag.

rprocter@ raises some interesting questions.  Some answers:

 - This interface is not stable and name changes are possible at a
   later date.

 - Although rescheduling timeouts is a side effect of the underlying
   implementation, I don't forsee us using anything but a timeout wheel
   in the future.  Other data structures are too slow in practice, so
   I doubt that the concept of a rescheduled timeout will be irrelevant
   any time soon.

 - I think the development utility of gathering these sorts of statistics
   is high.  Watching the distribution of timeouts under a given workflow
   is informative.

ok visa@

Revision 1.66 / (download) - annotate - [select for diffs], Thu Dec 12 18:12:43 2019 UTC (4 years, 6 months ago) by cheloha
Branch: MAIN
Changes since 1.65: +34 -29 lines
Diff to previous 1.65 (colored)

Recommit "timeout(9): make CIRCQ look more like other sys/queue.h data structures"

Backed out during revert of "timeout(9): switch to tickless backend".

Original commit message:

 - CIRCQ_APPEND -> CIRCQ_CONCAT
 - Flip argument order of CIRCQ_INSERT to match e.g. TAILQ_INSERT_TAIL
 - CIRCQ_INSERT -> CIRCQ_INSERT_TAIL
 - Add CIRCQ_FOREACH, use it in ddb(4) when printing buckets
 - While here, use tabs for indentation like we do with other macros

ok visa@ mpi@

Revision 1.65 / (download) - annotate - [select for diffs], Mon Dec 2 21:47:54 2019 UTC (4 years, 6 months ago) by cheloha
Branch: MAIN
Changes since 1.64: +135 -210 lines
Diff to previous 1.64 (colored)

Revert "timeout(9): switch to tickless backend"

It appears to have caused major performance regressions all over the
network stack.

Reported by bluhm@

ok deraadt@

Revision 1.64 / (download) - annotate - [select for diffs], Fri Nov 29 12:50:48 2019 UTC (4 years, 6 months ago) by cheloha
Branch: MAIN
Changes since 1.63: +33 -28 lines
Diff to previous 1.63 (colored)

timeout(9): make CIRCQ look more like other sys/queue.h data structures

 - CIRCQ_APPEND -> CIRCQ_CONCAT
 - Flip argument order of CIRCQ_INSERT to match e.g. TAILQ_INSERT_TAIL
 - CIRCQ_INSERT -> CIRCQ_INSERT_TAIL
 - Add CIRCQ_FOREACH, use it in ddb(4) when printing buckets
 - While here, use tabs for indentation like we do with other macros

ok visa@

Revision 1.63 / (download) - annotate - [select for diffs], Tue Nov 26 15:27:08 2019 UTC (4 years, 6 months ago) by cheloha
Branch: MAIN
Changes since 1.62: +182 -112 lines
Diff to previous 1.62 (colored)

timeout(9): switch to tickless backend

Rebase the timeout wheel on the system uptime clock.  Timeouts are now
set to run at or after an absolute time as returned by nanouptime(9).
Timeouts are thus "tickless": they expire at a real time on that clock
instead of at a particular value of the global "ticks" variable.

To facilitate this change the timeout struct's .to_time member becomes a
timespec.  Hashing timeouts into a bucket on the wheel changes slightly:
we build a 32-bit hash with 25 bits of seconds (.tv_sec) and 7 bits of
subseconds (.tv_nsec).  7 bits of subseconds means the width of the
lowest wheel level is now 2 seconds on all platforms and each bucket in
that lowest level corresponds to 1/128 seconds on the uptime clock.
These values were chosen to closely align with the current 100hz
hardclock(9) typical on almost all of our platforms.  At 100hz a bucket
is currently ~1/100 seconds wide on the lowest level and the lowest
level itself is ~2.56 seconds wide.  Not a huge change, but a change
nonetheless.

Because a bucket no longer corresponds to a single tick more than one
bucket may be dumped during an average timeout_hardclock_update() call.
On 100hz platforms you now dump ~2 buckets.  On 64hz machines (sh) you
dump ~4 buckets.  On 1024hz machines (alpha) you dump only 1 bucket,
but you are doing extra work in softclock() to reschedule timeouts
that aren't due yet.

To avoid changing current behavior all timeout_add*(9) interfaces
convert their timeout interval into ticks, compute an equivalent
timespec interval, and then add that interval to the timestamp of
the most recent timeout_hardclock_update() call to determine an
absolute deadline.  So all current timeouts still "use" ticks,
but the ticks are faked in the timeout layer.

A new interface, timeout_at_ts(9), is introduced here to bypass this
backwardly compatible behavior.  It will be used in subsequent diffs
to add absolute timeout support for userland and to clean up some of
the messier parts of kernel timekeeping, especially at the syscall
layer.

Because timeouts are based against the uptime clock they are subject to
NTP adjustment via adjtime(2) and adjfreq(2).  Unless you have a crazy
adjfreq(2) adjustment set this will not change the expiration behavior
of your timeouts.

Tons of design feedback from mpi@, visa@, guenther@, and kettenis@.
Additional amd64 testing from anton@ and visa@.  Octeon testing from visa@.
macppc testing from me.

Positive feedback from deraadt@, ok visa@

Revision 1.62 / (download) - annotate - [select for diffs], Thu Nov 7 14:05:12 2019 UTC (4 years, 7 months ago) by mpi
Branch: MAIN
Changes since 1.61: +2 -2 lines
Diff to previous 1.61 (colored)

db_addr_t -> vaddr_t, missed in previous.

ok deraadt@

Revision 1.61 / (download) - annotate - [select for diffs], Sun Nov 3 17:01:46 2019 UTC (4 years, 7 months ago) by cheloha
Branch: MAIN
Changes since 1.60: +45 -49 lines
Diff to previous 1.60 (colored)

kern_timeout.c: style(9), misc. cleanup

 - Move mutex to top of file, annotate locking for module
 - Group module-local prototypes below globals but above function defs
 - __inline -> inline
 - No static without inline
 - Drop extra parentheses around return values

Compiler input from visa@.

ok visa@

Revision 1.60 / (download) - annotate - [select for diffs], Sat Nov 2 16:56:17 2019 UTC (4 years, 7 months ago) by cheloha
Branch: MAIN
Changes since 1.59: +22 -7 lines
Diff to previous 1.59 (colored)

softclock: move softintr registration/scheduling into timeout module

softclock() is scheduled from hardclock(9) because long ago callouts were
processed from hardclock(9) directly.  The introduction of timeout(9) circa
2000 moved all callout processing into a dedicated module, but the softclock
scheduling stayed behind in hardclock(9).

We can move all the softclock() "stuff" into the timeout module to make
kern_clock.c a bit cleaner.  Neither initclocks() nor hardclock(9) need
to "know" about softclock().  The initial softclock() softintr registration
can be done from timeout_proc_init() and softclock() can be scheduled
from timeout_hardclock_update().

ok visa@

Revision 1.59 / (download) - annotate - [select for diffs], Fri Sep 20 16:44:32 2019 UTC (4 years, 8 months ago) by cheloha
Branch: MAIN
CVS Tags: OPENBSD_6_6_BASE, OPENBSD_6_6
Changes since 1.58: +9 -11 lines
Diff to previous 1.58 (colored)

timeout(9): process-context timeouts can be late

Move the check for lateness earlier in the softclock() loop so every
timeout is checked before being run.

While here, remove an unsafe DEBUG printf(9).  You can't safely printf(9)
within a mutex, and the print itself isn't even particularly useful.

ok bluhm@

Revision 1.58 / (download) - annotate - [select for diffs], Fri Sep 20 02:59:18 2019 UTC (4 years, 8 months ago) by cheloha
Branch: MAIN
Changes since 1.57: +15 -18 lines
Diff to previous 1.57 (colored)

timeout(9): use CLR/ISSET/SET consistently

While here in timeout_add(9), use KASSERT for brevity.

CLR/ISSET/SET bits ok krw@

Revision 1.57 / (download) - annotate - [select for diffs], Fri Jul 19 00:11:38 2019 UTC (4 years, 10 months ago) by cheloha
Branch: MAIN
Changes since 1.56: +19 -6 lines
Diff to previous 1.56 (colored)

ddb(4): clean up callout command

 - display timeouts in the thread work queue, if any
 - identify timeouts in the thread/softint work queue as such
 - if not in work queue, print <bucket>/<level>; easier to right-align
 - print arg pointer by hand to ensure consistent length for all pointers
   on both 32 and 64-bit platforms
 - generally make sure columns are correctly aligned and spaced

ok mpi@ visa@

Revision 1.56 / (download) - annotate - [select for diffs], Fri Jul 12 00:04:59 2019 UTC (4 years, 11 months ago) by cheloha
Branch: MAIN
Changes since 1.55: +30 -2 lines
Diff to previous 1.55 (colored)

sysctl(2): add KERN_TIMEOUT_STATS: timeout(9) status and statistics.

With these totals one can track the throughput of the timeout(9) layer
from userspace.

With input from mpi@.

ok mpi@

Revision 1.55 / (download) - annotate - [select for diffs], Tue Apr 23 13:35:12 2019 UTC (5 years, 1 month ago) by visa
Branch: MAIN
Changes since 1.54: +4 -5 lines
Diff to previous 1.54 (colored)

Remove file name and line number output from witness(4)

Reduce code clutter by removing the file name and line number output
from witness(4). Typically it is easy enough to locate offending locks
using the stack traces that are shown in lock order conflict reports.
Tricky cases can be tracked using sysctl kern.witness.locktrace=1 .

This patch additionally removes the witness(4) wrapper for mutexes.
Now each mutex implementation has to invoke the WITNESS_*() macros
in order to utilize the checker.

Discussed with and OK dlg@, OK mpi@

Revision 1.54 / (download) - annotate - [select for diffs], Sun Apr 14 08:51:31 2019 UTC (5 years, 1 month ago) by visa
Branch: MAIN
Changes since 1.53: +69 -2 lines
Diff to previous 1.53 (colored)

Add lock order checking for timeouts

The caller of timeout_barrier() must not hold locks that could prevent
timeout handlers from making progress. The system could deadlock
otherwise.

This patch makes witness(4) able to detect barrier locking errors.
This is done by introducing a pseudo-lock that couples the lock chains
of barrier callers to the lock chains of timeout handlers.

In order to find these errors faster, this diff adds a synchronous
version of cancelling timeouts, timeout_del_barrier(9). As the
synchronous intent is explicit, this interface can check lock order
immediately instead of waiting for the potentially rare occurrence of
timeout_barrier(9).

OK dlg@ mpi@

Revision 1.53 / (download) - annotate - [select for diffs], Thu Dec 14 02:42:18 2017 UTC (6 years, 5 months ago) by dlg
Branch: MAIN
CVS Tags: OPENBSD_6_5_BASE, OPENBSD_6_5, OPENBSD_6_4_BASE, OPENBSD_6_4, OPENBSD_6_3_BASE, OPENBSD_6_3
Changes since 1.52: +3 -5 lines
Diff to previous 1.52 (colored)

i forgot to convert timeout_proc_barrier to cond_signal

Revision 1.52 / (download) - annotate - [select for diffs], Thu Dec 14 00:45:16 2017 UTC (6 years, 5 months ago) by dlg
Branch: MAIN
Changes since 1.51: +4 -8 lines
Diff to previous 1.51 (colored)

replace the bare sleep state handling in barriers with wait cond code

Revision 1.51 / (download) - annotate - [select for diffs], Fri Nov 24 02:36:53 2017 UTC (6 years, 6 months ago) by dlg
Branch: MAIN
Changes since 1.50: +41 -1 lines
Diff to previous 1.50 (colored)

add timeout_barrier, which is like intr_barrier and taskq_barrier.

if you're trying to free something that a timeout is using, you
have to wait for that timeout to finish running before doing the
free. timeout_del can stop a timeout from running in the future,
but it doesn't know if a timeout has finished being scheduled and
is now running.

previously you could know that timeouts are not running by simply
masking softclock interrupts on the cpu running the kernel. however,
code is now running outside the kernel lock, and timeouts can run
in a thread instead of softclock.

timeout_barrier solves the first problem by taking the kernel lock
and then masking softclock interrupts. that is enough to ensure
that any further timeout processing is waiting for those resources
to run again.

the second problem is solved by having timeout_barrier insert work
into the thread. when that work runs, that means all previous work
running in that thread has completed.

fixes and ok visa@, who thinks this will be useful for his work
too.

Revision 1.50 / (download) - annotate - [select for diffs], Mon Oct 3 11:54:29 2016 UTC (7 years, 8 months ago) by dlg
Branch: MAIN
CVS Tags: OPENBSD_6_2_BASE, OPENBSD_6_2, OPENBSD_6_1_BASE, OPENBSD_6_1
Changes since 1.49: +16 -9 lines
Diff to previous 1.49 (colored)

avoid holding timeout_mutex while interacting with the scheduler.

as noted by haesbaert, this is necessary to avoid deadlocks because
the scheduler can call back into the timeout subsystem while its
holding its own locks.

this happened in two places. firstly, in softclock() it would take
timeout_mutex to find pending work. if that pending work needs a
process context, it would queue the work for the thread and call
wakeup, which enters the scheduler locks. if another cpu is trying
to tsleep (or msleep) with a timeout specified, the sleep code would
be holding the sched lock and call timeout_add, which takes
timeout_mutex.

this is solved by deferring the wakeup to after timeout_mutex is
left. this also has the benefit of mitigating the number of wakeups
done per softclock tick.

secondly, the timeout worker thread takes timeout_mutex and calls
msleep when there's no work to do (ie, the queue is empty). msleep
will take the sched locks. again, if another cpu does a tsleep
with a timeout, you get a deadlock.

to solve this im using sleep_setup and sleep_finish to sleep on an
empty queue, which is safe to do outside the lock as it is comparisons
of the queue head pointers, not derefs of the contents of the queue.

as long as the sleeps and wakeups are ordered correctly with the
enqueue and dequeue operations under the mutex, this all works.
you can think of the queue as a single descriptor ring, and the
wakeup as an interrupt.

the second deadlock was identified by guenther@
ok tedu@ mpi@

Revision 1.49 / (download) - annotate - [select for diffs], Thu Sep 22 12:55:24 2016 UTC (7 years, 8 months ago) by mpi
Branch: MAIN
Changes since 1.48: +81 -12 lines
Diff to previous 1.48 (colored)

Introduce a new 'softclock' thread that will be used to execute timeout
callbacks needing a process context.

The function timeout_set_proc(9) has to be used instead of timeout_set(9)
when a timeout callback needs a process context.

Note that if such a timeout is waiting, understand sleeping, for a non
negligible amount of time it might delay other timeouts needing a process
context.

dlg@ agrees with this as a temporary solution.

Manpage tweaks from jmc@

ok kettenis@, bluhm@, mikeb@

Revision 1.43.4.1 / (download) - annotate - [select for diffs], Thu Jul 14 02:46:11 2016 UTC (7 years, 10 months ago) by tedu
Branch: OPENBSD_5_8
Changes since 1.43: +11 -11 lines
Diff to previous 1.43 (colored) next main 1.44 (colored)

backport timeout overflow fixes:
fix several places where calculating ticks could overflow.
it's not enough to assign to an unsigned type because if the arithmetic
overflows the compiler may decide to do anything. so change all the
long long casts to uint64_t so that we start with the right type.
reported by Tim Newsham of NCC.
ok deraadt

Revision 1.43.2.1 / (download) - annotate - [select for diffs], Thu Jul 14 02:45:23 2016 UTC (7 years, 10 months ago) by tedu
Branch: OPENBSD_5_9
Changes since 1.43: +11 -11 lines
Diff to previous 1.43 (colored) next main 1.44 (colored)

backport timeout overflow fixes:
fix several places where calculating ticks could overflow.
it's not enough to assign to an unsigned type because if the arithmetic
overflows the compiler may decide to do anything. so change all the
long long casts to uint64_t so that we start with the right type.
reported by Tim Newsham of NCC.
ok deraadt

Revision 1.48 / (download) - annotate - [select for diffs], Wed Jul 6 15:53:01 2016 UTC (7 years, 11 months ago) by tedu
Branch: MAIN
CVS Tags: OPENBSD_6_0_BASE, OPENBSD_6_0
Changes since 1.47: +11 -11 lines
Diff to previous 1.47 (colored)

fix several places where calculating ticks could overflow.
it's not enough to assign to an unsigned type because if the arithmetic
overflows the compiler may decide to do anything. so change all the
long long casts to uint64_t so that we start with the right type.
reported by Tim Newsham of NCC.
ok deraadt

Revision 1.47 / (download) - annotate - [select for diffs], Thu Jun 23 18:41:44 2016 UTC (7 years, 11 months ago) by stefan
Branch: MAIN
Changes since 1.46: +9 -7 lines
Diff to previous 1.46 (colored)

Avoid multiple evaluation of macro arguments in softclock()

ok mikeb@ tedu@

Revision 1.46 / (download) - annotate - [select for diffs], Tue Jun 14 15:58:03 2016 UTC (7 years, 11 months ago) by bluhm
Branch: MAIN
Changes since 1.45: +15 -1 lines
Diff to previous 1.45 (colored)

Prevent a round to zero in the timeout_add_...() functions.  Getting
an immediate timeout if a positive value is specified is unexpected
behavior.  Defer calling the handler for at least one tick.  Do not
change that timeout_add(0) gives you an immediate timeout.
OK millert@ uebayasi@ tedu@

Revision 1.45 / (download) - annotate - [select for diffs], Sun Mar 20 07:56:08 2016 UTC (8 years, 2 months ago) by uebayasi
Branch: MAIN
Changes since 1.44: +1 -3 lines
Diff to previous 1.44 (colored)

Update ticks in hardclock().

OK mikeb@

Revision 1.44 / (download) - annotate - [select for diffs], Thu Mar 17 10:53:57 2016 UTC (8 years, 2 months ago) by uebayasi
Branch: MAIN
Changes since 1.43: +1 -2 lines
Diff to previous 1.43 (colored)

KNF: Remove a blank line.

Revision 1.43 / (download) - annotate - [select for diffs], Mon Jul 20 23:47:20 2015 UTC (8 years, 10 months ago) by uebayasi
Branch: MAIN
CVS Tags: OPENBSD_5_9_BASE, OPENBSD_5_8_BASE
Branch point for: OPENBSD_5_9, OPENBSD_5_8
Changes since 1.42: +1 -2 lines
Diff to previous 1.42 (colored)

Move `ticks' declaration to sys/kernel.h.

Revision 1.42 / (download) - annotate - [select for diffs], Sat Mar 14 03:38:50 2015 UTC (9 years, 3 months ago) by jsg
Branch: MAIN
Changes since 1.41: +1 -2 lines
Diff to previous 1.41 (colored)

Remove some includes include-what-you-use claims don't
have any direct symbols used.  Tested for indirect use by compiling
amd64/i386/sparc64 kernels.

ok tedu@ deraadt@

Revision 1.41 / (download) - annotate - [select for diffs], Wed Nov 27 04:28:32 2013 UTC (10 years, 6 months ago) by dlg
Branch: MAIN
CVS Tags: OPENBSD_5_7_BASE, OPENBSD_5_7, OPENBSD_5_6_BASE, OPENBSD_5_6, OPENBSD_5_5_BASE, OPENBSD_5_5
Changes since 1.40: +20 -16 lines
Diff to previous 1.40 (colored)

make timeout_add and its wrappers return whether the timeout was scheduled
in this call by returning 1, or a previous call by returning 0. this makes
it easy to refcount the stuff we're scheduling a timeout for, and brings
the api in line with what task_add(9) provides.

ok mpi@ matthew@ mikeb@ guenther@

Revision 1.40 / (download) - annotate - [select for diffs], Sun Oct 6 04:34:35 2013 UTC (10 years, 8 months ago) by guenther
Branch: MAIN
Changes since 1.39: +15 -4 lines
Diff to previous 1.39 (colored)

Replace some XXX casts with an inline function that explains what's going on

ok deraadt@

Revision 1.39 / (download) - annotate - [select for diffs], Wed Oct 2 21:03:21 2013 UTC (10 years, 8 months ago) by sf
Branch: MAIN
Changes since 1.38: +2 -2 lines
Diff to previous 1.38 (colored)

Format string fix: Use %td for pointer difference

Revision 1.38 / (download) - annotate - [select for diffs], Tue Oct 1 19:36:25 2013 UTC (10 years, 8 months ago) by sf
Branch: MAIN
Changes since 1.37: +2 -2 lines
Diff to previous 1.37 (colored)

format string fix

to_arg is void *

Revision 1.37 / (download) - annotate - [select for diffs], Tue Sep 17 04:52:53 2013 UTC (10 years, 8 months ago) by guenther
Branch: MAIN
Changes since 1.36: +2 -2 lines
Diff to previous 1.36 (colored)

Fix a misaligned backslash

Revision 1.36 / (download) - annotate - [select for diffs], Sat Aug 3 06:47:15 2013 UTC (10 years, 10 months ago) by guenther
Branch: MAIN
Changes since 1.35: +2 -4 lines
Diff to previous 1.35 (colored)

Delete variable left over from the diagnostic code removed by previous commit

pointed out by Artturi Alm (artturi.alm (at) gmail.com)

Revision 1.35 / (download) - annotate - [select for diffs], Sat Jun 2 00:11:16 2012 UTC (12 years ago) by guenther
Branch: MAIN
CVS Tags: OPENBSD_5_4_BASE, OPENBSD_5_4, OPENBSD_5_3_BASE, OPENBSD_5_3, OPENBSD_5_2_BASE, OPENBSD_5_2
Changes since 1.34: +1 -13 lines
Diff to previous 1.34 (colored)

Delete diagnostic code that reports timeout adjustments on resume.
It was useful for tracking down the last devices which weren't deleting
their timeouts on suspend and recreating them on resume, but it's too
verbose to keep around.

noted by deraadt@

Revision 1.34 / (download) - annotate - [select for diffs], Thu May 24 07:17:42 2012 UTC (12 years ago) by guenther
Branch: MAIN
Changes since 1.33: +47 -1 lines
Diff to previous 1.33 (colored)

On resume, run forward the monotonic and realtimes clocks instead of jumping
just the realtime clock, triggering and adjusting timeouts to reflect that.

ok matthew@ deraadt@

Revision 1.33 / (download) - annotate - [select for diffs], Tue May 10 00:58:42 2011 UTC (13 years, 1 month ago) by dlg
Branch: MAIN
CVS Tags: OPENBSD_5_1_BASE, OPENBSD_5_1, OPENBSD_5_0_BASE, OPENBSD_5_0
Changes since 1.32: +7 -2 lines
Diff to previous 1.32 (colored)

tweak timeout_del so it can tell the caller if it actually did remove a
timeout or not.

without this it is impossible to tell if the timeout was removed
or if it is just about to run. if the caller of timeout_del is about
to free some state the timeout itself might use, this could lead
to a use after free.

now if timeout_del returns 1, you know the timeout wont fire and
you can proceed with cleanup. how you cope with the timeout being
about to fire is up to the caller of timeout_del.

discussed with drinking art and art, and most of k2k11
ok miod@

Revision 1.32 / (download) - annotate - [select for diffs], Wed Nov 4 19:14:10 2009 UTC (14 years, 7 months ago) by kettenis
Branch: MAIN
CVS Tags: OPENBSD_4_9_BASE, OPENBSD_4_9, OPENBSD_4_8_BASE, OPENBSD_4_8, OPENBSD_4_7_BASE, OPENBSD_4_7
Changes since 1.31: +2 -3 lines
Diff to previous 1.31 (colored)

Get rid of __HAVE_GENERIC_SOFT_INTERRUPTS now that all our platforms support it.

ok jsing@, miod@

Revision 1.31 / (download) - annotate - [select for diffs], Tue Jun 2 22:05:54 2009 UTC (15 years ago) by guenther
Branch: MAIN
CVS Tags: OPENBSD_4_6_BASE, OPENBSD_4_6
Changes since 1.30: +6 -6 lines
Diff to previous 1.30 (colored)

Constipate the second argument to timeout_add_*().  Also, use
nitems() in two places instead of coding the array size and fix a
spot of whitespace.

ok miod@ blambert@

Revision 1.30 / (download) - annotate - [select for diffs], Tue Mar 3 19:09:13 2009 UTC (15 years, 3 months ago) by miod
Branch: MAIN
Changes since 1.29: +4 -1 lines
Diff to previous 1.29 (colored)

put back r1.25 (poisoning chain pointers after removing items from the
wheel). This was safe, except for osiop bugs.

Revision 1.29 / (download) - annotate - [select for diffs], Wed Oct 22 08:38:06 2008 UTC (15 years, 7 months ago) by blambert
Branch: MAIN
CVS Tags: OPENBSD_4_5_BASE, OPENBSD_4_5
Changes since 1.28: +13 -1 lines
Diff to previous 1.28 (colored)

Add timeout_add_msec(), for timeouts in milliseconds.

Idea and original patch mk@

ok mk@, krw@

Revision 1.28 / (download) - annotate - [select for diffs], Mon Jul 14 15:17:08 2008 UTC (15 years, 11 months ago) by art
Branch: MAIN
CVS Tags: OPENBSD_4_4_BASE, OPENBSD_4_4
Changes since 1.27: +1 -3 lines
Diff to previous 1.27 (colored)

Don't lock timeouts in db_show_callout.

All cpus are stopped and this cpu blocks all interrupts. It doesn't make
sense to grab locks that ddb can then jump past with longjmp.

Noticed by Pierre Riteau. I just forgot about the bug until reminded
today.

Revision 1.27 / (download) - annotate - [select for diffs], Fri Jul 11 14:18:39 2008 UTC (15 years, 11 months ago) by blambert
Branch: MAIN
Changes since 1.26: +67 -1 lines
Diff to previous 1.26 (colored)

Add timeout_add_{tv,ts,bt,sec,usec,nsec} so that we can add timeouts
in something other than clock ticks. From art@'s punchlist and (for
the time being) not yet used.

"you're doing it wrong" art@,ray@,otto@,tedu@

ok art@

Revision 1.26 / (download) - annotate - [select for diffs], Sun Jan 20 18:23:38 2008 UTC (16 years, 4 months ago) by miod
Branch: MAIN
CVS Tags: OPENBSD_4_3_BASE, OPENBSD_4_3
Changes since 1.25: +1 -4 lines
Diff to previous 1.25 (colored)

Revert 1.25 and do not use _Q_INVALIDATE on timeout structures; being
subtly different from CIRCLEQ, it is possible, when emptying the whole
timeout chain, to end up with CIRCQ_EMPTY being false, and bad things
happen. Back to the drawing board...

Revision 1.25 / (download) - annotate - [select for diffs], Wed Jul 19 20:25:08 2006 UTC (17 years, 10 months ago) by miod
Branch: MAIN
CVS Tags: OPENBSD_4_2_BASE, OPENBSD_4_2, OPENBSD_4_1_BASE, OPENBSD_4_1, OPENBSD_4_0_BASE, OPENBSD_4_0
Changes since 1.24: +4 -1 lines
Diff to previous 1.24 (colored)

Sprinkle some _Q_INVALIDATE love for timeout structures as well; ok otto@

Revision 1.24 / (download) - annotate - [select for diffs], Fri Apr 21 01:35:27 2006 UTC (18 years, 1 month ago) by dlg
Branch: MAIN
Changes since 1.23: +1 -6 lines
Diff to previous 1.23 (colored)

back out my last commit.

art pointed out that timeout_set is the initializer of timeout structs.
this means that the ONQUEUE flag could be set when timeout_set is given
freshly allocated memory. my commit suddenly introduced the requirement
that you bzero a timeout before initialising it. without the bzero we
could generate false positives about the timeout being already queued.

art did produce a diff that would walk the queues when the flag was set
to see if it really was in the lists, but deraadt considers this too much
of a hit.

Revision 1.23 / (download) - annotate - [select for diffs], Tue Apr 18 21:48:34 2006 UTC (18 years, 1 month ago) by dlg
Branch: MAIN
Changes since 1.22: +6 -1 lines
Diff to previous 1.22 (colored)

if you go timeout_set, timeout_add, and then timeout_set again you can
screw up the queues that tie all the timeouts together. this makes us
panic if we detect that happening. its a lot easier to debug that the
weird side effects of broken timeout queues.

ok mickey@ kettenis@ deraadt@ pedro@

Revision 1.22 / (download) - annotate - [select for diffs], Tue Dec 28 22:48:30 2004 UTC (19 years, 5 months ago) by deraadt
Branch: MAIN
CVS Tags: OPENBSD_3_9_BASE, OPENBSD_3_9, OPENBSD_3_8_BASE, OPENBSD_3_8, OPENBSD_3_7_BASE, OPENBSD_3_7
Changes since 1.21: +2 -2 lines
Diff to previous 1.21 (colored)

when panicing from timeout_add being < 0, print the value; ok miod

Revision 1.21 / (download) - annotate - [select for diffs], Sun Dec 12 20:37:01 2004 UTC (19 years, 6 months ago) by espie
Branch: MAIN
Changes since 1.20: +9 -8 lines
Diff to previous 1.20 (colored)

simplify slightly, kill lvalue weirdness that's not ANSI C.
okay nordin@

Revision 1.20 / (download) - annotate - [select for diffs], Wed Nov 10 11:00:00 2004 UTC (19 years, 7 months ago) by grange
Branch: MAIN
Changes since 1.19: +9 -2 lines
Diff to previous 1.19 (colored)

Diff from art@:

Update ticks in timeout_hardclock_update to avoid errors in hardclock (this
is the third time we mess up here). ticks is only used for timeouts anyway.
At the same protect updating ticks with timeout_mutex and be slightly
more paranoid in timeout_hardclock_update.

ok tdeval@ miod@

Revision 1.19 / (download) - annotate - [select for diffs], Tue Jul 20 20:20:52 2004 UTC (19 years, 10 months ago) by art
Branch: MAIN
CVS Tags: OPENBSD_3_6_BASE, OPENBSD_3_6
Changes since 1.18: +19 -30 lines
Diff to previous 1.18 (colored)

The timeout wheels are manipulated by hardclock that's not protected with
biglock. We need to protect them with a mutex.

Revision 1.3.2.8 / (download) - annotate - [select for diffs], Sat Jun 7 11:03:40 2003 UTC (21 years ago) by ho
Branch: SMP
Changes since 1.3.2.7: +3 -6 lines
Diff to previous 1.3.2.7 (colored) next main 1.4 (colored)

Sync SMP branch to -current

Revision 1.18 / (download) - annotate - [select for diffs], Tue Jun 3 12:05:25 2003 UTC (21 years ago) by art
Branch: MAIN
CVS Tags: SMP_SYNC_B, SMP_SYNC_A, OPENBSD_3_5_BASE, OPENBSD_3_5, OPENBSD_3_4_BASE, OPENBSD_3_4
Changes since 1.17: +2 -5 lines
Diff to previous 1.17 (colored)

Two term license with approval from nordin@

Revision 1.11.4.3 / (download) - annotate - [select for diffs], Mon May 19 22:31:10 2003 UTC (21 years ago) by tedu
Branch: UBC
Changes since 1.11.4.2: +5 -4 lines
Diff to previous 1.11.4.2 (colored) to branchpoint 1.11 (colored) next main 1.12 (colored)

sync

Revision 1.17 / (download) - annotate - [select for diffs], Sat May 17 14:02:06 2003 UTC (21 years, 1 month ago) by grange
Branch: MAIN
Changes since 1.16: +2 -2 lines
Diff to previous 1.16 (colored)

Typos; from Julien Bordet <zejames@greyhats.org>
Close PR 3262

Revision 1.3.2.7 / (download) - annotate - [select for diffs], Tue May 13 19:21:28 2003 UTC (21 years, 1 month ago) by ho
Branch: SMP
Changes since 1.3.2.6: +2 -2 lines
Diff to previous 1.3.2.6 (colored)

Sync the SMP branch to -current. This includes moving to ELF.

Revision 1.16 / (download) - annotate - [select for diffs], Sun Apr 13 21:04:52 2003 UTC (21 years, 2 months ago) by tedu
Branch: MAIN
CVS Tags: UBC_SYNC_A
Changes since 1.15: +2 -2 lines
Diff to previous 1.15 (colored)

diff from nordin@ to prevent wraparound on long uptime machines.
ok art@ deraadt@ miod@ tdeval@

Revision 1.3.2.6 / (download) - annotate - [select for diffs], Fri Mar 28 00:41:26 2003 UTC (21 years, 2 months ago) by niklas
Branch: SMP
Changes since 1.3.2.5: +3 -2 lines
Diff to previous 1.3.2.5 (colored)

Sync the SMP branch with 3.3

Revision 1.15 / (download) - annotate - [select for diffs], Sun Dec 8 04:21:07 2002 UTC (21 years, 6 months ago) by art
Branch: MAIN
CVS Tags: OPENBSD_3_3_BASE, OPENBSD_3_3
Changes since 1.14: +4 -3 lines
Diff to previous 1.14 (colored)

 - Lock the timeout wheel after the diagnostic checks.
 - show timeout_todo in the ddb command.

Revision 1.11.4.2 / (download) - annotate - [select for diffs], Tue Jun 11 03:29:40 2002 UTC (22 years ago) by art
Branch: UBC
Changes since 1.11.4.1: +19 -9 lines
Diff to previous 1.11.4.1 (colored) to branchpoint 1.11 (colored)

Sync UBC branch to -current

Revision 1.3.2.5 / (download) - annotate - [select for diffs], Thu Mar 28 11:43:04 2002 UTC (22 years, 2 months ago) by niklas
Branch: SMP
Changes since 1.3.2.4: +1 -1 lines
Diff to previous 1.3.2.4 (colored)

Merge in -current from about a week ago

Revision 1.14 / (download) - annotate - [select for diffs], Thu Mar 14 01:27:04 2002 UTC (22 years, 3 months ago) by millert
Branch: MAIN
CVS Tags: UBC_SYNC_B, OPENBSD_3_2_BASE, OPENBSD_3_2, OPENBSD_3_1_BASE, OPENBSD_3_1
Changes since 1.13: +2 -2 lines
Diff to previous 1.13 (colored)

First round of __P removal in sys

Revision 1.3.2.4 / (download) - annotate - [select for diffs], Wed Mar 6 02:13:23 2002 UTC (22 years, 3 months ago) by niklas
Branch: SMP
Changes since 1.3.2.3: +161 -122 lines
Diff to previous 1.3.2.3 (colored)

Merge in trunk

Revision 1.13 / (download) - annotate - [select for diffs], Fri Feb 15 18:10:15 2002 UTC (22 years, 4 months ago) by nordin
Branch: MAIN
Changes since 1.12: +18 -8 lines
Diff to previous 1.12 (colored)

Make rescheduling to a later time faster. ok art@

Revision 1.11.4.1 / (download) - annotate - [select for diffs], Thu Jan 31 22:55:40 2002 UTC (22 years, 4 months ago) by niklas
Branch: UBC
Changes since 1.11: +152 -123 lines
Diff to previous 1.11 (colored)

Merge in -current, builds on i386, otherwise untested

Revision 1.12 / (download) - annotate - [select for diffs], Sat Dec 22 16:41:51 2001 UTC (22 years, 5 months ago) by nordin
Branch: MAIN
Changes since 1.11: +152 -123 lines
Diff to previous 1.11 (colored)

New scalable implementation with constant time add and delete. ok deraadt@

Revision 1.3.2.3 / (download) - annotate - [select for diffs], Wed Oct 31 03:26:29 2001 UTC (22 years, 7 months ago) by nate
Branch: SMP
Changes since 1.3.2.2: +2 -73 lines
Diff to previous 1.3.2.2 (colored)

Sync the SMP branch to something just after 3.0

Revision 1.11 / (download) - annotate - [select for diffs], Wed Sep 12 15:48:45 2001 UTC (22 years, 9 months ago) by art
Branch: MAIN
CVS Tags: UBC_BASE, OPENBSD_3_0_BASE, OPENBSD_3_0
Branch point for: UBC
Changes since 1.10: +2 -2 lines
Diff to previous 1.10 (colored)

Rename timeout_init to timeout_startup to deconfuse a bit.

Revision 1.10 / (download) - annotate - [select for diffs], Thu Aug 23 11:20:05 2001 UTC (22 years, 9 months ago) by art
Branch: MAIN
Changes since 1.9: +1 -9 lines
Diff to previous 1.9 (colored)

Remove even more leftovers from old timeouts.

Revision 1.9 / (download) - annotate - [select for diffs], Thu Aug 23 08:18:57 2001 UTC (22 years, 9 months ago) by miod
Branch: MAIN
Changes since 1.8: +1 -64 lines
Diff to previous 1.8 (colored)

Remove the old timeout legacy code.

Revision 1.3.2.2 / (download) - annotate - [select for diffs], Mon May 14 22:32:42 2001 UTC (23 years, 1 month ago) by niklas
Branch: SMP
Changes since 1.3.2.1: +44 -10 lines
Diff to previous 1.3.2.1 (colored)

merge in approximately 2.9 into SMP branch

Revision 1.8 / (download) - annotate - [select for diffs], Wed Mar 28 07:33:51 2001 UTC (23 years, 2 months ago) by art
Branch: MAIN
CVS Tags: OPENBSD_2_9_BASE, OPENBSD_2_9
Changes since 1.7: +31 -7 lines
Diff to previous 1.7 (colored)

Add some DIAGNOSTIC checks that panic on some of the common mistakes.

Revision 1.7 / (download) - annotate - [select for diffs], Thu Mar 15 16:47:50 2001 UTC (23 years, 3 months ago) by csapuntz
Branch: MAIN
Changes since 1.6: +4 -1 lines
Diff to previous 1.6 (colored)



Triggered mechanism allows a handler to figure out whether a given
timeout is actually executing.

Revision 1.6 / (download) - annotate - [select for diffs], Fri Feb 16 13:47:40 2001 UTC (23 years, 3 months ago) by espie
Branch: MAIN
Changes since 1.5: +1 -1 lines
Diff to previous 1.5 (colored)

typo (incidentally, removed a bogus -k in the cvs file, the update
will trigger $OpenBSD$ fill-in)

Revision 1.5 / (download) - annotate - [select for diffs], Tue Jun 20 02:45:55 2000 UTC (23 years, 11 months ago) by art
Branch: MAIN
CVS Tags: OPENBSD_2_8_BASE, OPENBSD_2_8
Changes since 1.4: +1 -1 lines
Diff to previous 1.4 (colored)

timeout_add: Remove the right timeout when we see that it is on the list.

Revision 1.4 / (download) - annotate - [select for diffs], Mon May 8 01:28:59 2000 UTC (24 years, 1 month ago) by mickey
Branch: MAIN
CVS Tags: OPENBSD_2_7_BASE, OPENBSD_2_7
Changes since 1.3: +9 -2 lines
Diff to previous 1.3 (colored)

from art@:
in timeout_hardclock_update() check out if there is
anything in the timeout queue before calculating the return value.
thanks to Adam Rogoyski <rogoyski@cs.utexas.edu> for
debugging and testing help.

Revision 1.3.2.1 / (download) - annotate - [select for diffs], Fri Mar 24 09:09:25 2000 UTC (24 years, 2 months ago) by niklas
Branch: SMP
Changes since 1.3: +1 -1 lines
Diff to previous 1.3 (colored)

Sync with -current

Revision 1.3 / (download) - annotate - [select for diffs], Thu Mar 23 11:07:34 2000 UTC (24 years, 2 months ago) by art
Branch: MAIN
Branch point for: SMP
Changes since 1.2: +3 -3 lines
Diff to previous 1.2 (colored)

Provide methods to check if a timeout was initalized and if it is scheduled.

Revision 1.2 / (download) - annotate - [select for diffs], Thu Mar 23 10:27:05 2000 UTC (24 years, 2 months ago) by art
Branch: MAIN
Changes since 1.1: +2 -2 lines
Diff to previous 1.1 (colored)

Preserve the FIFO order of issued timeouts.

Revision 1.1 / (download) - annotate - [select for diffs], Thu Mar 23 09:59:57 2000 UTC (24 years, 2 months ago) by art
Branch: MAIN

New API for timeouts. Replaces the old timeout()/untimeout() API and
makes it the callers responsibility to allocate resources for the
timeouts.

This is a KISS implementation and does _not_ solve the problems of slow
handling of a large number of pending timeouts (this will be solved in
future work) (although hardclock is now guarateed to take constant time
for handling of timeouts).

Old timeout() and untimeout() are implemented as wrappers around the new
API and kept for compatibility. They will be removed as soon as all
subsystems are converted to use the new API.

This form allows you to request diff's between any two revisions of a file. You may select a symbolic revision name using the selection box or you may type in a numeric name using the type-in text box.