History log of /haiku/headers/private/kernel/thread.h
Revision Date Author Comments
# efbeada7 21-Aug-2023 Jérôme Duval <jerome.duval@gmail.com>

gnu: add sched_getcpu()

on x86_64 implemented with rdtscp or rdpid, generically with a syscall.

Change-Id: I8f776848bf35575abec8a8c612c4a25d8550daea
Reviewed-on: https://review.haiku-os.org/c/haiku/+/6866
Reviewed-by: waddlesplash <waddlesplash@gmail.com>
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>


# 914b10c1 11-Mar-2022 Jessica Hamilton <jessica.l.hamilton@gmail.com>

wait_for_thread_etc: expose as syscall/make public.

* This will be needed for the following commit that implements
`pthread_tryjoin_np` and `pthread_timedjoin_np`.

Change-Id: Idccb1aa588d6d10825294d14925d9bd046b65f19
Reviewed-on: https://review.haiku-os.org/c/haiku/+/5098
Tested-by: Commit checker robot <no-reply+buildbot@haiku-os.org>
Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>


# 5d4501aa 20-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

Assorted whitespace cleanup and typo fixes.


# b1673075 16-Mar-2014 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Properly synchronize suspending new thread

After load_image() the child thread is suspended and the parent is
expected to resume it later. However, it is possible that the parent
attempts to resume its child after it has been notified that the image
had been loaded but before the child managed to suspend itself. In such
case the child would suspends itself after that wake up attempt and,
consequently will not be ever resumed.

To mitigate that problem flag Thread::going_to_suspend has been added
which helps synchronizing thread suspension and continuation in a similar
way that "traditional" thread blocking is performed. This means that
the child should behave in a following manner: set its going_to_suspend flag,
notify the parent (i.e. any thread that may want to resume it), acquire
its scheduler_lock and suspend itself if the going_to_suspend flag is set.
The parent should follow pattern: clear going_to_suspend flag of the thread
that is about to be resumed, acquire that thread scheduler_lock and enqueue
it in a run queue if it is suspended.

Thanks Oliver for reporting the bug and identifying what causes it.


# 8cf8e537 05-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

kernel/x86: Inline atomic functions and memory barriers


# 135bb9c9 30-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Do not attempt to interrupt a thread that is not waiting


# 2b7ea4cd 29-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove Thread::next_state


# 673f08a9 28-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Make thread_block_locked() private


# 03f7d3d1 24-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Restore logical processor disabling


# 03fb2d88 07-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove gSchedulerLock

* Thread::scheduler_lock protects thread state, priority, etc.
* sThreadCreationLock protects thread creation and removal and list of
threads in team.
* Team::signal_lock and Team::time_lock protect list of threads in team
as well.
* Scheduler uses its own internal locking.


# 11cacd0c 04-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove thread_block_with_timeout_locked()


# c8dd9f77 29-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Add thread_unblock() and use it where possible


# ea79da95 20-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove support for thread_queue


# 29e65827 09-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove possibility to yield to all threads

Kernel support for yielding to all (including lower priority) threads
has been removed. POSIX sched_yield() remains unchanged.

If a thread really needs to yield to everyone it can reduce its priority
to the lowest possible and then yield (it will then need to manually
return to its prvious priority upon continuing).


# 0e35d5d2 12-Dec-2011 John Scipione <jscipione@gmail.com>

Change instances of wether in comments to whether. No functional change intended.


# 24df6592 11-Jun-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged signals-merge branch into trunk with the following changes:
* Reorganized the kernel locking related to threads and teams.
* We now discriminate correctly between process and thread signals. Signal
handlers have been moved to teams. Fixes #5679.
* Implemented real-time signal support, including signal queuing, SA_SIGINFO
support, sigqueue(), sigwaitinfo(), sigtimedwait(), waitid(), and the addition
of the real-time signal range. Closes #1935 and #2695.
* Gave SIGBUS a separate signal number. Fixes #6704.
* Implemented <time.h> clock and timer support, and fixed/completed alarm() and
[set]itimer(). Closes #5682.
* Implemented support for thread cancellation. Closes #5686.
* Moved send_signal() from <signal.h> to <OS.h>. Fixes #7554.
* Lots over smaller more or less related changes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42116 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4535495d 10-Jan-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged the signals branch into trunk, with these changes:
* The team and thread kernel structures have been renamed to Team and Thread
respectively and moved into the new BKernel namespace.
* Several (kernel add-on) sources have been converted from C to C++ since
private kernel headers are included that are no longer C compatible.

Changes after merging:
* Fixed gcc 2 build (warnings mainly in the scary firewire bus manager).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40196 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4ebc8f61 15-Dec-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added a "name changed" notification to the thread notification service.
* Added a "team" field to the notification events.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39861 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0338371f 13-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* All scheduler implementations:
- enqueue_in_run_queue() no longer returns whether rescheduling is supposed
to happen. Instead is sets cpu_ent::invoke_scheduler on the current CPU.
- reschedule() does now handle cpu_ent::invoke_scheduler_if_idle(). No need
to let all callers do that.
* thread_unblock[_locked]() no longer return whether rescheduling is supposed
to happen.
* Got rid of the B_INVOKE_SCHEDULER handling. The interrupt hooks really
can't know, when it makes sense to reschedule or not.
* Introduced scheduler_reschedule_if_necessary[_locked]() functions for
checking+invoking the scheduler.
* Some semaphore functions (e.g. delete_sem()) invoke the scheduler now, if
they wake up anything with greater priority.
I've also tried to add scheduler invocations in the condition variable and
mutex/rw_lock code, but that actually has a negative impact on performance,
probably because it causes too much ping-ponging between threads when
multiple locking primitives are involved.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34657 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3533b659 10-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Reintroduced the SMP_MSG_RESCHEDULE_IF_IDLE ICI message. This time
implemented by means of an additional member in cpu_ent.
* Removed thread::keep_scheduled and the related functions. The feature
wasn't used yet and wouldn't have worked as implemented anyway.
* Resurrected an older, SMP aware version of our simple scheduler and made it
the default instead of the affine scheduler. The latter is in no state to
be used yet. It causes enormous latencies (I've seen up to 0.1s) even when
six or seven CPUs were idle at the same time, totally killing parallelism.
That's also the reason why a -j8 build was slower than a -j2. This is no
longer the case. On my machine the -j2 build takes about 10% less time now
and the -j8 build saves another 20%. The latter is not particularly
impressive (compared with Linux), but that seems to be due to lock
contention.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34615 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 009ccc29 20-Aug-2009 Rene Gollent <anevilyak@gmail.com>

anevilyak+mmlr:
* scheduler_enqueue_in_runqueue() now allows the scheduler to return a hint as to whether a reschedule is desirable or not. This is used in a few other places in order to relegate scheduling decisions entirely to the scheduler rather than the priority hacks previously used. There are probably other places in the kernel that could now make use of that information to more intelligently call reschedule() though.
* Switch over the default scheduler to scheduler_affine().



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32554 a95241bf-73f2-0310-859d-f6bbb57e9c96


# efd536ff 11-Apr-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Cleared up a misconception in the notification mechanism. We already had
methods that used an "event mask" field. There was no need to introduce
a "flags" field for the same purpose.
* Renamed protected DefaultNotificationService methods (removed "_" prefix).
* Adjusted the code providing a notification service accordingly.
* Changed the event message several notification services generated by renaming
the "opcode" field to "event".
* Implemented the TEAM_ADDED event and also added a TEAM_EXEC event.
* Added notifications for threads and images.
* Added visitor-like iteration functions for teams, threads, and images.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30126 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6503e5d9 11-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added functions to pin a thread to the current CPU (i.e. it will only be
scheduled on that CPU) and to avoid unscheduling it.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27974 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3b3e3805 30-Aug-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added thread::io_priority field and functions to get/set it.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27247 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 07569b03 22-Aug-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added kernel private thread_state_to_text() which just calls
state_to_text().
* state_to_text() can now deal with a NULL thread argument.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27163 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6b202f4e 13-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Introduced new header directory headers/private/system which is supposed
to contain headers shared by kernel and userland (mainly libroot).
* Moved quite a few private kernel headers to the new location. Split
several kernel headers into a shared part and one that is still kernel
private. Adjusted all affected Jamfiles and source in the standard x86
build accordingly. The build for other architectures and for test code
may be broken.
* Quite a bit of userland code still includes private kernel headers.
Mostly those are <util/*> headers. The ones that aren't strictly
kernel-only should be moved to some other place (maybe
headers/private/shared/util).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25486 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b5e3c0a1 12-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added new syscalls _kern_block_thread()/_kern_unblock_thread[s]().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25469 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4c49f205 08-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Changed _kern_spawn_thread() and create_thread(): Instead of individual
arguments they get a single thread_creation_attributes structure now.
* Added stack_address and stack_size to thread_creation_attributes,
which allow to specify the stack size or the stack to be used for the
new user thread.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25389 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f842b6fa 22-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added THREAD_BLOCK_TYPE_OTHER.
* Made the object pointer passed to thread_prepare_to_block() const, so
that strings can be passed without casting. Passing a string could
maybe be made a convention for THREAD_BLOCK_TYPE_OTHER.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25109 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b95f6d47 22-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Introduced a set of functions (thread_prepare_to_block(),
thread_block(), thread_unblock(),...) that allow a thread to wait for
something without needing a semaphore or condition variable. It can
simply block and another thread can unblock it. Supports timeouts and
interrupting. Both semaphores and condition variables use this
common mechanism, now.
* Semaphores:
- Some simplifications due to the thread blocking mechanism.
- Changed locking order to sem -> thread. It was the other way around
before and when introducing the wait_for_objects() support I had
also introduced a situation where the locking was reverse, which
could potentially cause a dead lock on SMP systems.
- Instead of queueing thread structures, a semaphore queues
queued_thread entries now, which are created on the stack. The
thread::sem structure could thus be removed.
- Added sem_entry::net_count, which is sem_entry::count plus the
acquisition count of all waiting threads. This number is needed in
remove_thread_from_sem() and instead of computing it there we
maintain it.
- Fixed remove_thread_from_sem(). It would not unblock threads, if
the sem count was <= 0.
- Made sem::last_acquirer unconditional. It is actually needed for
sem_info::latest_holder. Fixed fill_sem_info() accordingly.
- Added some optional tracing output, though only via ktrace_printf().
* Condition variables:
- Could be simplified significantly through the use of the thread
blocking mechanism. Removed a good deal of unnecessary code.
- Moved the ConditionVariableEntry "flags" parameter from Wait() to
Add(), and adjusted all places where condition variables are used
accordingly.
* snooze() uses thread_block_with_timeout() instead of a semaphore.
* Simplified thread interrupting in the signal and user debugger code.
Instead of separate functions for threads waiting on a semaphore or
condititon variable, we only have a single thread_interrupt(), now.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25099 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9835c090 07-Feb-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added a boolean "force" parameter to thread_yield(). When true, the
function has the old behavior. When false, it just calls the scheduler
without any priority adjustment or other stuff.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23906 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 34b3b26b 10-Jan-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged branch haiku/branches/developer/bonefish/optimization revision
23139 into trunk, with roughly the following changes (for details svn
log the branch):
* The int 99 syscall handler is now fully in assembly.
* Added a sysenter/sysexit handler and use it on Pentiums that support
it (via commpage).
* Got rid of i386_handle_trap(). A bit of functionality was moved into
the assembly handler which now uses a jump table to call C functions
handling the respective interrupt.
* Some optimizations to get user debugger support code out of the
interrupt handling path.
* Introduced a thread::flags fields which allows to skip handling of
rare events (signals, user debug enabling/disabling) on the
common interrupt handling path.
* Got rid of the explicit iframe stack. The iframes can still be
retrieved by iterating through the stack frames.
* Made the commpage an architecture independent feature. It's used for
the real time data stuff (instead of creating a separate area).
* The x86 CPU modules can now provide processor optimized versions for
common functions (currently memcpy() only). They are used in the
kernel and are provided to the userland via commpage entries.
* Introduced build system feature allowing easy use of C structure
member offsets in assembly code.

Changes after merging:
* Fixed merge conflict in src/system/kernel/arch/x86/arch_debug.cpp
(caused by refactoring and introduction of "call" debugger command).



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23370 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 636bfc08 02-Oct-2007 Ingo Weinhold <ingo_weinhold@gmx.de>

* Renamed fs/vfs_select.cpp to wait_for_objects.cpp and got rid of
vfs_select.h, respectively moved most of it into the new kernel
private header wait_for_objects.h.
* Added new experimental API functions wait_for_objects[_etc](). They
work pretty much like poll(), but also for semaphores, ports, and
threads.
* Removed the "ref" parameter from notify_select_events() and the
select_sync_pool functions as well as from fd_ops::fd_[de]select(). It
is no longer needed. The FS interface select() hook still has it,
though -- the VFS will always pass 0.
* de]select_fd() take a select_info* instead of a select_sync* + ref
pair, now. Added respective functions for semaphores, ports, and
threads.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22416 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0b70ea59 16-Aug-2007 Axel Dörfler <axeld@pinc-software.de>

* Implemented sigaltstack() and set_signal_stack(), thus closing bug #1401.
* On exec() the new function thread_reset_for_exec() is called which clears the signals
and cancels an eventually set alarm. Both things weren't done before...
* Some minor cleanups.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21989 a95241bf-73f2-0310-859d-f6bbb57e9c96


# badc7b67 18-Feb-2007 Travis Geiselbrecht <geist@foobox.com>

yet another fix for #1018, which has at this point blossomed into a reorg of how AP cpus are initialized.
the new cpuid stuff was apparently exacerbating an existing problem where various bits of low level
cpu code (specifically get_current_cpu) weren't really initialized before being used. Changed the
order to set up a fake set of threads to point each cpu at really early in boot to make sure that at
all points in code it can get the current 'thread' and thus the current cpu.
A probably better solution would be to have dr3 point to the current cpu which would then point to the
current thread, but that has a race condition that would require an int disable, etc.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20160 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 33a9adb3 08-Mar-2006 Axel Dörfler <axeld@pinc-software.de>

* Added a wait_for_thread_etc() function that allows specifying semaphore flags
and a timeout.
* _user_wait_for_thread() was not interruptible before, ie. Control-C wouldn't
work.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16654 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d14aab0d 01-Feb-2006 Axel Dörfler <axeld@pinc-software.de>

Changed the way how CPU activity is monitored: instead of taking the active
time of the idle thread as a measure, we now compute the CPU activity on
each thread switch - the time the CPU worked is the total of user and kernel
time a thread spent during its quantum.
Unlike before, this mechanism works correctly on SMP machines. I hope this
works as expected :)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16193 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 204131dc 30-Jan-2006 Axel Dörfler <axeld@pinc-software.de>

Added a real yield function to the kernel (using the next_priority approach).
The test application lets run a thread at the highest priority that calls
yield all the time - the system stays responsible when it runs, so it seems
to work fine :)
Changed the malloc implementation to use _kern_thread_yield() instead of
snoozing.
We should think about making this call public, too.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16166 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6cd505ce 25-Oct-2005 Axel Dörfler <axeld@pinc-software.de>

Changed the boot procedure a bit.
Extracted scheduler_init() from start_scheduler() (which is now called scheduler_start()).
Moved scheduler related function prototypes from thread.h to the new scheduler.h.
Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14518 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b7a96f02 30-Jun-2005 Axel Dörfler <axeld@pinc-software.de>

Now fills in system_info::cpu_infos[] (ie. CPU activity) by looking at the active
time of the idle thread. IOW Pulse now works :-)
Renamed the idle thread/stack to start with 1 instead of 0 (first idle thread will
be called "idle thread 1").
Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13373 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 74b043d9 17-Mar-2005 Axel Dörfler <axeld@pinc-software.de>

Removed execute property that was set accidently (since CVS days).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@11896 a95241bf-73f2-0310-859d-f6bbb57e9c96


# db75a08b 08-Mar-2005 Axel Dörfler <axeld@pinc-software.de>

Solved the big mystery in Ingo's life: in C, func(); and func(void); is not the same.
This fixes the "missing prototype" warnings.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11627 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5939c4d7 08-Mar-2005 Ingo Weinhold <ingo_weinhold@gmx.de>

Added functions allocate_thread_id() and peek_next_thread_id() and a
threadID parameter to spawn_kernel_thread_etc(). It's now possible to
set the ID of a new thread. Used in team.c to make team ID and the ID of
the main thread equal.

Fascinatingly the two added functions prompt my compiler to issue
`missing prototype' warnings, although those are obviously there. It would
be nice if someone could solve that riddle.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11621 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 90bce836 10-Feb-2005 Axel Dörfler <axeld@pinc-software.de>

Changed the way user/kernel time is tracked for threads. Now, thread_at_kernel_entry()
and thread_at_kernel_exit() are always called for userland threads at the appropriate
situation (note, I've renamed those from *_atkernel_*).
The timing should be more accurate this way, and the thread::last_time_type field
is no longer needed: all interrupts are now added to the kernel time (where the
time is actually spent).


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11331 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f3cadd05 25-Jan-2005 Axel Dörfler <axeld@pinc-software.de>

Improved header - struct kernel_args was only defined in arch headers.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11019 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 97dda329 13-Dec-2004 Axel Dörfler <axeld@pinc-software.de>

Some header work to reduce dependencies. Also fixes the debug build.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10434 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 545ecbe8 30-Nov-2004 Axel Dörfler <axeld@pinc-software.de>

Extended the get_system_info() mechanism; it now gets info about threads/teams
as well as architecture specific stuff.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10313 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 655c4f0c 01-Sep-2004 Axel Dörfler <axeld@pinc-software.de>

Resolved the argument type change of _user- vs. _kern_spawn_thread() - introduced
a new thread_entry_func typedef in the kernel only. Unlike thread_func, it accepts
two arguments - that functionality is not exported to the user, though.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8777 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0865e4b2 23-May-2004 Axel Dörfler <axeld@pinc-software.de>

Added syscall for rename_thread(), courtesy of Jack Burton.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7631 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 54327b01 06-Apr-2004 Axel Dörfler <axeld@pinc-software.de>

Added prototype for _user_rename_thread().


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7178 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1e14a27e 17-Mar-2004 Axel Dörfler <axeld@pinc-software.de>

Changed prototype for thread_init(), renamed thread_init_percpu() to thread_per_cpu_init().
Removed thread_kill_thread_nowait(), removed prototype for non-existing thread_kill_thread().


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7009 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 14f5ad8c 15-Mar-2004 Axel Dörfler <axeld@pinc-software.de>

Separated the team functions from the thread.h header into the new team.h.
Fixed fd.h to include that file.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6995 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9e5bff5f 02-Mar-2004 Axel Dörfler <axeld@pinc-software.de>

Replaced the syscall for thread_get_current_thread_id() with one for find_thread().
Renamed the thread/team syscalls to the new naming scheme.
Some other minor cleanups.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6867 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 166515d6 22-Feb-2004 Axel Dörfler <axeld@pinc-software.de>

Replaced the scary team_get_team_struct() with the more pleasing team_is_valid().


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6676 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a02a5888 18-Apr-2003 Axel Dörfler <axeld@pinc-software.de>

Added another argument parameter for the thread creation code. Helps
implementing a more efficient on_exit_thread().


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3073 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a9731b41 26-Jan-2003 Axel Dörfler <axeld@pinc-software.de>

Housekeeping changes and small bug-fixes:
Added new syscall for set_thread_priority().
Replaced the userland syscall snooze_until() with snooze_etc() (the latter
has to be exported to userland and realize snooze() and snooze_until()).
Cleaned the sources - scheduler functions now have the scheduler_ prefix.
Moved signal related stuff into ksignal.h (out of thread.h).
Replaced public kernel API with direct exports (i.e. resume_thread() instead
of thread_resume_thread()).
Removed the thread_create_XXX_thread*() calls, and replaced them with a
BeOS compatible set.
Made some fields of struct thread a bit prettier.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2569 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5e7d6a17 31-Oct-2002 lillo <lillo@nowhere.fake>

Enabled the single ordered queue scheduler and made some little fixes


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1804 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f2bc6130 28-Oct-2002 lillo <lillo@nowhere.fake>

replaced sys_kill with general thread-aimed sys_send_signal; cleaned up


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1740 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8fe70e82 25-Oct-2002 lillo <lillo@nowhere.fake>

beos compatibility fixes: exit_thread now issues a signal; wait_for_thread returns B_INTERRUPTED if target thread gets killed


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1674 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f510e6ce 23-Oct-2002 lillo <lillo@nowhere.fake>

posix signals support, 1st pass


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1623 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ee02a939 05-Oct-2002 Axel Dörfler <axeld@pinc-software.de>

Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1394 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e96a8449 04-Oct-2002 Axel Dörfler <axeld@pinc-software.de>

Removed some type definitions from ktypes.h that are now located in OS.h.
Changed lock.h to like those changes.
Moved the create_sem_etc() from the public OS.h to the private kernel only
sem.h, cleaned it up a bit.
gcc doesn't seem to like the "extern inlines" with -O0 -g, so I replaced
an inline function in thread.h with "static inline" (which it does always
like).


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1376 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 615a79cc 19-Aug-2002 lillo <lillo@nowhere.fake>

Implemented send_data/receive_data/has_data thread syscalls


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@815 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e196b7bb 16-Aug-2002 lillo <lillo@nowhere.fake>

added single-queue scheduler; the old scheduler is compiled by default - to enable the new one uncomment the #define at the beginning of thread.h


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@776 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 854c31f8 03-Aug-2002 lillo <lillo@nowhere.fake>

finished implementing get_thread_info, get_next_thread_info, get_team_info, get_next_team_info. New ps command behaving like the BeOS one is here, but doesn't work as libroot seems to crash when loaded at process startup... :/


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@570 a95241bf-73f2-0310-859d-f6bbb57e9c96


# aded06e0 03-Aug-2002 lillo <lillo@nowhere.fake>

Second round of changes. Splitted thread.c into thread.c, team.c and scheduler.c. First kernel-only get_team_info and get_next_team_info implementation.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@569 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3cfbecf1 02-Aug-2002 lillo <lillo@nowhere.fake>

First round of big changes: the term team has replaced proc all over the kernel, the few kern_* syscalls have been renamed to sys_* for consistency, and other small changes. The ps app is temporarily disabled until get_next_team_info is implemented.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@557 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0ba337c0 18-Jul-2002 lillo <lillo@nowhere.fake>

adding environmental variables support


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@304 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 52a38012 08-Jul-2002 ejakowatz <ejakowatz@nowhere.fake>

It is accomplished ...


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5d4501aa0187e1a8790784dc2ab3382a16660e93 20-Aug-2015 Michael Lotz <mmlr@mlotz.ch>

Assorted whitespace cleanup and typo fixes.


# b167307526897db52743daa0aeffe2a0041abaa8 16-Mar-2014 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Properly synchronize suspending new thread

After load_image() the child thread is suspended and the parent is
expected to resume it later. However, it is possible that the parent
attempts to resume its child after it has been notified that the image
had been loaded but before the child managed to suspend itself. In such
case the child would suspends itself after that wake up attempt and,
consequently will not be ever resumed.

To mitigate that problem flag Thread::going_to_suspend has been added
which helps synchronizing thread suspension and continuation in a similar
way that "traditional" thread blocking is performed. This means that
the child should behave in a following manner: set its going_to_suspend flag,
notify the parent (i.e. any thread that may want to resume it), acquire
its scheduler_lock and suspend itself if the going_to_suspend flag is set.
The parent should follow pattern: clear going_to_suspend flag of the thread
that is about to be resumed, acquire that thread scheduler_lock and enqueue
it in a run queue if it is suspended.

Thanks Oliver for reporting the bug and identifying what causes it.


# 8cf8e537740789b1b103f0aa0736dbfcf55359c2 05-Jan-2014 Pawel Dziepak <pdziepak@quarnos.org>

kernel/x86: Inline atomic functions and memory barriers


# 135bb9c9596ff16f1d775ca48f6ae884af7dc52b 30-Dec-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Do not attempt to interrupt a thread that is not waiting


# 2b7ea4cddf362859cd3089e3cb95481cda4adc5f 29-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove Thread::next_state


# 673f08a995666c3e818bf0f936152f34f8b1e81e 28-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Make thread_block_locked() private


# 03f7d3d1db10c0a467bea944fb3230ee70c6e015 24-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Restore logical processor disabling


# 03fb2d886830e4dd4b344c56725db59f96733216 07-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove gSchedulerLock

* Thread::scheduler_lock protects thread state, priority, etc.
* sThreadCreationLock protects thread creation and removal and list of
threads in team.
* Team::signal_lock and Team::time_lock protect list of threads in team
as well.
* Scheduler uses its own internal locking.


# 11cacd0c1345cd3296f12e07d18996a2c7572a64 04-Nov-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove thread_block_with_timeout_locked()


# c8dd9f7780c426e592a3ccb231e6bfab51f15eb9 29-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Add thread_unblock() and use it where possible


# ea79da95009a2f916bebbd5d3b57281035548e25 20-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove support for thread_queue


# 29e65827fd93f67acbebcdbbe1f233b004a48e18 09-Oct-2013 Pawel Dziepak <pdziepak@quarnos.org>

kernel: Remove possibility to yield to all threads

Kernel support for yielding to all (including lower priority) threads
has been removed. POSIX sched_yield() remains unchanged.

If a thread really needs to yield to everyone it can reduce its priority
to the lowest possible and then yield (it will then need to manually
return to its prvious priority upon continuing).


# 0e35d5d2e5ef3d288e056d60ef1b16dc399eaa0c 12-Dec-2011 John Scipione <jscipione@gmail.com>

Change instances of wether in comments to whether. No functional change intended.


# 24df65921befcd0ad0c5c7866118f922da61cb96 11-Jun-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged signals-merge branch into trunk with the following changes:
* Reorganized the kernel locking related to threads and teams.
* We now discriminate correctly between process and thread signals. Signal
handlers have been moved to teams. Fixes #5679.
* Implemented real-time signal support, including signal queuing, SA_SIGINFO
support, sigqueue(), sigwaitinfo(), sigtimedwait(), waitid(), and the addition
of the real-time signal range. Closes #1935 and #2695.
* Gave SIGBUS a separate signal number. Fixes #6704.
* Implemented <time.h> clock and timer support, and fixed/completed alarm() and
[set]itimer(). Closes #5682.
* Implemented support for thread cancellation. Closes #5686.
* Moved send_signal() from <signal.h> to <OS.h>. Fixes #7554.
* Lots over smaller more or less related changes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42116 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4535495d80c86e19e2610e7444a4fcefe3e0f8e6 10-Jan-2011 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged the signals branch into trunk, with these changes:
* The team and thread kernel structures have been renamed to Team and Thread
respectively and moved into the new BKernel namespace.
* Several (kernel add-on) sources have been converted from C to C++ since
private kernel headers are included that are no longer C compatible.

Changes after merging:
* Fixed gcc 2 build (warnings mainly in the scary firewire bus manager).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40196 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4ebc8f615d5a495671343519051b9094b2867808 15-Dec-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added a "name changed" notification to the thread notification service.
* Added a "team" field to the notification events.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39861 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0338371f26864c2a248b1ea53b9fe78c884af7f2 13-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* All scheduler implementations:
- enqueue_in_run_queue() no longer returns whether rescheduling is supposed
to happen. Instead is sets cpu_ent::invoke_scheduler on the current CPU.
- reschedule() does now handle cpu_ent::invoke_scheduler_if_idle(). No need
to let all callers do that.
* thread_unblock[_locked]() no longer return whether rescheduling is supposed
to happen.
* Got rid of the B_INVOKE_SCHEDULER handling. The interrupt hooks really
can't know, when it makes sense to reschedule or not.
* Introduced scheduler_reschedule_if_necessary[_locked]() functions for
checking+invoking the scheduler.
* Some semaphore functions (e.g. delete_sem()) invoke the scheduler now, if
they wake up anything with greater priority.
I've also tried to add scheduler invocations in the condition variable and
mutex/rw_lock code, but that actually has a negative impact on performance,
probably because it causes too much ping-ponging between threads when
multiple locking primitives are involved.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34657 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3533b6597db4ad65493632da8a92c1f6ea3de149 10-Dec-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Reintroduced the SMP_MSG_RESCHEDULE_IF_IDLE ICI message. This time
implemented by means of an additional member in cpu_ent.
* Removed thread::keep_scheduled and the related functions. The feature
wasn't used yet and wouldn't have worked as implemented anyway.
* Resurrected an older, SMP aware version of our simple scheduler and made it
the default instead of the affine scheduler. The latter is in no state to
be used yet. It causes enormous latencies (I've seen up to 0.1s) even when
six or seven CPUs were idle at the same time, totally killing parallelism.
That's also the reason why a -j8 build was slower than a -j2. This is no
longer the case. On my machine the -j2 build takes about 10% less time now
and the -j8 build saves another 20%. The latter is not particularly
impressive (compared with Linux), but that seems to be due to lock
contention.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34615 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 009ccc29623e2b54f3e881739754c5cea121e7d6 20-Aug-2009 Rene Gollent <anevilyak@gmail.com>

anevilyak+mmlr:
* scheduler_enqueue_in_runqueue() now allows the scheduler to return a hint as to whether a reschedule is desirable or not. This is used in a few other places in order to relegate scheduling decisions entirely to the scheduler rather than the priority hacks previously used. There are probably other places in the kernel that could now make use of that information to more intelligently call reschedule() though.
* Switch over the default scheduler to scheduler_affine().



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@32554 a95241bf-73f2-0310-859d-f6bbb57e9c96


# efd536ff89954302f42c59e2c71fba45e5cb4c25 11-Apr-2009 Ingo Weinhold <ingo_weinhold@gmx.de>

* Cleared up a misconception in the notification mechanism. We already had
methods that used an "event mask" field. There was no need to introduce
a "flags" field for the same purpose.
* Renamed protected DefaultNotificationService methods (removed "_" prefix).
* Adjusted the code providing a notification service accordingly.
* Changed the event message several notification services generated by renaming
the "opcode" field to "event".
* Implemented the TEAM_ADDED event and also added a TEAM_EXEC event.
* Added notifications for threads and images.
* Added visitor-like iteration functions for teams, threads, and images.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30126 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6503e5d9c6ab89ebb681b4819b07d3ff4890e5fb 11-Oct-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added functions to pin a thread to the current CPU (i.e. it will only be
scheduled on that CPU) and to avoid unscheduling it.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27974 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3b3e3805f8e693bbb48ab203379efd47fb7e73dc 30-Aug-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added thread::io_priority field and functions to get/set it.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27247 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 07569b03c9d1cd80a23479243e9aef030f66272c 22-Aug-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added kernel private thread_state_to_text() which just calls
state_to_text().
* state_to_text() can now deal with a NULL thread argument.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27163 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6b202f4e3da73d4c131355fcd82b792d153f84f6 13-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Introduced new header directory headers/private/system which is supposed
to contain headers shared by kernel and userland (mainly libroot).
* Moved quite a few private kernel headers to the new location. Split
several kernel headers into a shared part and one that is still kernel
private. Adjusted all affected Jamfiles and source in the standard x86
build accordingly. The build for other architectures and for test code
may be broken.
* Quite a bit of userland code still includes private kernel headers.
Mostly those are <util/*> headers. The ones that aren't strictly
kernel-only should be moved to some other place (maybe
headers/private/shared/util).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25486 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b5e3c0a1ead149af5ebe1a99786fabaf871711f6 12-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added new syscalls _kern_block_thread()/_kern_unblock_thread[s]().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25469 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4c49f2056bbec860092e8c26520398b4121f8d1a 08-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Changed _kern_spawn_thread() and create_thread(): Instead of individual
arguments they get a single thread_creation_attributes structure now.
* Added stack_address and stack_size to thread_creation_attributes,
which allow to specify the stack size or the stack to be used for the
new user thread.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25389 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f842b6fa57859c5898273b5ae9c16499d06963cb 22-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Added THREAD_BLOCK_TYPE_OTHER.
* Made the object pointer passed to thread_prepare_to_block() const, so
that strings can be passed without casting. Passing a string could
maybe be made a convention for THREAD_BLOCK_TYPE_OTHER.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25109 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b95f6d4710855a27bec41b6fae2b064347780173 22-Apr-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Introduced a set of functions (thread_prepare_to_block(),
thread_block(), thread_unblock(),...) that allow a thread to wait for
something without needing a semaphore or condition variable. It can
simply block and another thread can unblock it. Supports timeouts and
interrupting. Both semaphores and condition variables use this
common mechanism, now.
* Semaphores:
- Some simplifications due to the thread blocking mechanism.
- Changed locking order to sem -> thread. It was the other way around
before and when introducing the wait_for_objects() support I had
also introduced a situation where the locking was reverse, which
could potentially cause a dead lock on SMP systems.
- Instead of queueing thread structures, a semaphore queues
queued_thread entries now, which are created on the stack. The
thread::sem structure could thus be removed.
- Added sem_entry::net_count, which is sem_entry::count plus the
acquisition count of all waiting threads. This number is needed in
remove_thread_from_sem() and instead of computing it there we
maintain it.
- Fixed remove_thread_from_sem(). It would not unblock threads, if
the sem count was <= 0.
- Made sem::last_acquirer unconditional. It is actually needed for
sem_info::latest_holder. Fixed fill_sem_info() accordingly.
- Added some optional tracing output, though only via ktrace_printf().
* Condition variables:
- Could be simplified significantly through the use of the thread
blocking mechanism. Removed a good deal of unnecessary code.
- Moved the ConditionVariableEntry "flags" parameter from Wait() to
Add(), and adjusted all places where condition variables are used
accordingly.
* snooze() uses thread_block_with_timeout() instead of a semaphore.
* Simplified thread interrupting in the signal and user debugger code.
Instead of separate functions for threads waiting on a semaphore or
condititon variable, we only have a single thread_interrupt(), now.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25099 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9835c090a69357df22aaaa5a3e12483a36f8deb0 07-Feb-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Added a boolean "force" parameter to thread_yield(). When true, the
function has the old behavior. When false, it just calls the scheduler
without any priority adjustment or other stuff.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23906 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 34b3b26b3b8c46ba46ddde037b10dd173f4936d6 10-Jan-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

Merged branch haiku/branches/developer/bonefish/optimization revision
23139 into trunk, with roughly the following changes (for details svn
log the branch):
* The int 99 syscall handler is now fully in assembly.
* Added a sysenter/sysexit handler and use it on Pentiums that support
it (via commpage).
* Got rid of i386_handle_trap(). A bit of functionality was moved into
the assembly handler which now uses a jump table to call C functions
handling the respective interrupt.
* Some optimizations to get user debugger support code out of the
interrupt handling path.
* Introduced a thread::flags fields which allows to skip handling of
rare events (signals, user debug enabling/disabling) on the
common interrupt handling path.
* Got rid of the explicit iframe stack. The iframes can still be
retrieved by iterating through the stack frames.
* Made the commpage an architecture independent feature. It's used for
the real time data stuff (instead of creating a separate area).
* The x86 CPU modules can now provide processor optimized versions for
common functions (currently memcpy() only). They are used in the
kernel and are provided to the userland via commpage entries.
* Introduced build system feature allowing easy use of C structure
member offsets in assembly code.

Changes after merging:
* Fixed merge conflict in src/system/kernel/arch/x86/arch_debug.cpp
(caused by refactoring and introduction of "call" debugger command).



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@23370 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 636bfc08aeaaa7f1bab813c5aa2e8e666b40ec64 02-Oct-2007 Ingo Weinhold <ingo_weinhold@gmx.de>

* Renamed fs/vfs_select.cpp to wait_for_objects.cpp and got rid of
vfs_select.h, respectively moved most of it into the new kernel
private header wait_for_objects.h.
* Added new experimental API functions wait_for_objects[_etc](). They
work pretty much like poll(), but also for semaphores, ports, and
threads.
* Removed the "ref" parameter from notify_select_events() and the
select_sync_pool functions as well as from fd_ops::fd_[de]select(). It
is no longer needed. The FS interface select() hook still has it,
though -- the VFS will always pass 0.
* de]select_fd() take a select_info* instead of a select_sync* + ref
pair, now. Added respective functions for semaphores, ports, and
threads.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@22416 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0b70ea5992e7913f4ce19c4bc2ab75273364ff06 16-Aug-2007 Axel Dörfler <axeld@pinc-software.de>

* Implemented sigaltstack() and set_signal_stack(), thus closing bug #1401.
* On exec() the new function thread_reset_for_exec() is called which clears the signals
and cancels an eventually set alarm. Both things weren't done before...
* Some minor cleanups.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21989 a95241bf-73f2-0310-859d-f6bbb57e9c96


# badc7b674eca3e33d1c5f865a626966110790f8f 18-Feb-2007 Travis Geiselbrecht <geist@foobox.com>

yet another fix for #1018, which has at this point blossomed into a reorg of how AP cpus are initialized.
the new cpuid stuff was apparently exacerbating an existing problem where various bits of low level
cpu code (specifically get_current_cpu) weren't really initialized before being used. Changed the
order to set up a fake set of threads to point each cpu at really early in boot to make sure that at
all points in code it can get the current 'thread' and thus the current cpu.
A probably better solution would be to have dr3 point to the current cpu which would then point to the
current thread, but that has a race condition that would require an int disable, etc.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@20160 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 33a9adb3761f54bac8cd70850577f46b28d44799 08-Mar-2006 Axel Dörfler <axeld@pinc-software.de>

* Added a wait_for_thread_etc() function that allows specifying semaphore flags
and a timeout.
* _user_wait_for_thread() was not interruptible before, ie. Control-C wouldn't
work.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16654 a95241bf-73f2-0310-859d-f6bbb57e9c96


# d14aab0dcabc0de98bd380cefd6929599fbe53cb 01-Feb-2006 Axel Dörfler <axeld@pinc-software.de>

Changed the way how CPU activity is monitored: instead of taking the active
time of the idle thread as a measure, we now compute the CPU activity on
each thread switch - the time the CPU worked is the total of user and kernel
time a thread spent during its quantum.
Unlike before, this mechanism works correctly on SMP machines. I hope this
works as expected :)


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16193 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 204131dc9755d05c7bb677c1095613d8340ebfb3 30-Jan-2006 Axel Dörfler <axeld@pinc-software.de>

Added a real yield function to the kernel (using the next_priority approach).
The test application lets run a thread at the highest priority that calls
yield all the time - the system stays responsible when it runs, so it seems
to work fine :)
Changed the malloc implementation to use _kern_thread_yield() instead of
snoozing.
We should think about making this call public, too.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16166 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6cd505cee71447d8c4829e79c2fee9c6d92badc7 25-Oct-2005 Axel Dörfler <axeld@pinc-software.de>

Changed the boot procedure a bit.
Extracted scheduler_init() from start_scheduler() (which is now called scheduler_start()).
Moved scheduler related function prototypes from thread.h to the new scheduler.h.
Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@14518 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b7a96f02fd5d6ac737c389c9168cda91d7e1376a 30-Jun-2005 Axel Dörfler <axeld@pinc-software.de>

Now fills in system_info::cpu_infos[] (ie. CPU activity) by looking at the active
time of the idle thread. IOW Pulse now works :-)
Renamed the idle thread/stack to start with 1 instead of 0 (first idle thread will
be called "idle thread 1").
Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@13373 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 74b043d98d35652a6892fc430537a02f5f9d9f76 17-Mar-2005 Axel Dörfler <axeld@pinc-software.de>

Removed execute property that was set accidently (since CVS days).


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@11896 a95241bf-73f2-0310-859d-f6bbb57e9c96


# db75a08b982b5471ca529d6d3b6f7e32f1108158 08-Mar-2005 Axel Dörfler <axeld@pinc-software.de>

Solved the big mystery in Ingo's life: in C, func(); and func(void); is not the same.
This fixes the "missing prototype" warnings.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11627 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5939c4d7a917afbd9594a07e70203b5f97436379 08-Mar-2005 Ingo Weinhold <ingo_weinhold@gmx.de>

Added functions allocate_thread_id() and peek_next_thread_id() and a
threadID parameter to spawn_kernel_thread_etc(). It's now possible to
set the ID of a new thread. Used in team.c to make team ID and the ID of
the main thread equal.

Fascinatingly the two added functions prompt my compiler to issue
`missing prototype' warnings, although those are obviously there. It would
be nice if someone could solve that riddle.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11621 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 90bce836e00440cce2de427c851ae003bb3b6813 10-Feb-2005 Axel Dörfler <axeld@pinc-software.de>

Changed the way user/kernel time is tracked for threads. Now, thread_at_kernel_entry()
and thread_at_kernel_exit() are always called for userland threads at the appropriate
situation (note, I've renamed those from *_atkernel_*).
The timing should be more accurate this way, and the thread::last_time_type field
is no longer needed: all interrupts are now added to the kernel time (where the
time is actually spent).


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11331 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f3cadd05dddd7e0781ae57e6f33b1d33123dacd6 25-Jan-2005 Axel Dörfler <axeld@pinc-software.de>

Improved header - struct kernel_args was only defined in arch headers.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@11019 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 97dda329edce2caf11004390ff9dce1a5b1a86d1 13-Dec-2004 Axel Dörfler <axeld@pinc-software.de>

Some header work to reduce dependencies. Also fixes the debug build.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10434 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 545ecbe86d5ba2c3ca5c07e18c2d3208d1eea11b 30-Nov-2004 Axel Dörfler <axeld@pinc-software.de>

Extended the get_system_info() mechanism; it now gets info about threads/teams
as well as architecture specific stuff.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10313 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 655c4f0c9952ce697cd80bdc89c7041d02d1a616 01-Sep-2004 Axel Dörfler <axeld@pinc-software.de>

Resolved the argument type change of _user- vs. _kern_spawn_thread() - introduced
a new thread_entry_func typedef in the kernel only. Unlike thread_func, it accepts
two arguments - that functionality is not exported to the user, though.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8777 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0865e4b204ad72251e05d977b17b68a46bc1a491 23-May-2004 Axel Dörfler <axeld@pinc-software.de>

Added syscall for rename_thread(), courtesy of Jack Burton.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7631 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 54327b01b3eacb0dbe14defebaa947b5ebfc6ade 06-Apr-2004 Axel Dörfler <axeld@pinc-software.de>

Added prototype for _user_rename_thread().


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7178 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 1e14a27ee842838d501331979d04a6026f8d2c8c 17-Mar-2004 Axel Dörfler <axeld@pinc-software.de>

Changed prototype for thread_init(), renamed thread_init_percpu() to thread_per_cpu_init().
Removed thread_kill_thread_nowait(), removed prototype for non-existing thread_kill_thread().


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7009 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 14f5ad8ce4e1f9502f7defab977670e86eea0950 15-Mar-2004 Axel Dörfler <axeld@pinc-software.de>

Separated the team functions from the thread.h header into the new team.h.
Fixed fd.h to include that file.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6995 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9e5bff5febfe5049547beaf9de6a2939782e7858 02-Mar-2004 Axel Dörfler <axeld@pinc-software.de>

Replaced the syscall for thread_get_current_thread_id() with one for find_thread().
Renamed the thread/team syscalls to the new naming scheme.
Some other minor cleanups.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6867 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 166515d66302fa962e35037ed3d203c62509c7ed 22-Feb-2004 Axel Dörfler <axeld@pinc-software.de>

Replaced the scary team_get_team_struct() with the more pleasing team_is_valid().


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6676 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a02a5888af17e257161fa59ac3b8ca663b5a2673 18-Apr-2003 Axel Dörfler <axeld@pinc-software.de>

Added another argument parameter for the thread creation code. Helps
implementing a more efficient on_exit_thread().


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3073 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a9731b41c119ec606f9585d2370c0d5d5539eb53 26-Jan-2003 Axel Dörfler <axeld@pinc-software.de>

Housekeeping changes and small bug-fixes:
Added new syscall for set_thread_priority().
Replaced the userland syscall snooze_until() with snooze_etc() (the latter
has to be exported to userland and realize snooze() and snooze_until()).
Cleaned the sources - scheduler functions now have the scheduler_ prefix.
Moved signal related stuff into ksignal.h (out of thread.h).
Replaced public kernel API with direct exports (i.e. resume_thread() instead
of thread_resume_thread()).
Removed the thread_create_XXX_thread*() calls, and replaced them with a
BeOS compatible set.
Made some fields of struct thread a bit prettier.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@2569 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5e7d6a17a03af89a05c1a96fb6a3508b954750ec 31-Oct-2002 lillo <lillo@nowhere.fake>

Enabled the single ordered queue scheduler and made some little fixes


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1804 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f2bc61304f09c3804c98f1ac78da87e9129083d7 28-Oct-2002 lillo <lillo@nowhere.fake>

replaced sys_kill with general thread-aimed sys_send_signal; cleaned up


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1740 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 8fe70e8212d0de7e9d252885d37d81fbf1787db4 25-Oct-2002 lillo <lillo@nowhere.fake>

beos compatibility fixes: exit_thread now issues a signal; wait_for_thread returns B_INTERRUPTED if target thread gets killed


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1674 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f510e6ce601d2e7f3f88df110749a5bf02e79268 23-Oct-2002 lillo <lillo@nowhere.fake>

posix signals support, 1st pass


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1623 a95241bf-73f2-0310-859d-f6bbb57e9c96


# ee02a939730b59e8c9076404591e5e980b7e1d59 05-Oct-2002 Axel Dörfler <axeld@pinc-software.de>

Cleanup.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1394 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e96a844909dac884bab3c194f73b158e428e7481 04-Oct-2002 Axel Dörfler <axeld@pinc-software.de>

Removed some type definitions from ktypes.h that are now located in OS.h.
Changed lock.h to like those changes.
Moved the create_sem_etc() from the public OS.h to the private kernel only
sem.h, cleaned it up a bit.
gcc doesn't seem to like the "extern inlines" with -O0 -g, so I replaced
an inline function in thread.h with "static inline" (which it does always
like).


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@1376 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 615a79cc3cafb8aa90ad2ee9f722d0a4700a7b59 19-Aug-2002 lillo <lillo@nowhere.fake>

Implemented send_data/receive_data/has_data thread syscalls


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@815 a95241bf-73f2-0310-859d-f6bbb57e9c96


# e196b7bbc53c5c253258cf30ee58dfb10b06d352 16-Aug-2002 lillo <lillo@nowhere.fake>

added single-queue scheduler; the old scheduler is compiled by default - to enable the new one uncomment the #define at the beginning of thread.h


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@776 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 854c31f835e445f5caecc8a9d6342f3677cb48c8 03-Aug-2002 lillo <lillo@nowhere.fake>

finished implementing get_thread_info, get_next_thread_info, get_team_info, get_next_team_info. New ps command behaving like the BeOS one is here, but doesn't work as libroot seems to crash when loaded at process startup... :/


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@570 a95241bf-73f2-0310-859d-f6bbb57e9c96


# aded06e0aa5d39e231d14a33def2bd5f0655bdab 03-Aug-2002 lillo <lillo@nowhere.fake>

Second round of changes. Splitted thread.c into thread.c, team.c and scheduler.c. First kernel-only get_team_info and get_next_team_info implementation.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@569 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 3cfbecf1a6bfb811556eed42284ad75f9568a9fe 02-Aug-2002 lillo <lillo@nowhere.fake>

First round of big changes: the term team has replaced proc all over the kernel, the few kern_* syscalls have been renamed to sys_* for consistency, and other small changes. The ps app is temporarily disabled until get_next_team_info is implemented.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@557 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 0ba337c0a41c6245ba204209d7b899dc03767bd6 18-Jul-2002 lillo <lillo@nowhere.fake>

adding environmental variables support


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@304 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 52a380120846174213ccce9c4aab0dda17c72083 08-Jul-2002 ejakowatz <ejakowatz@nowhere.fake>

It is accomplished ...


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10 a95241bf-73f2-0310-859d-f6bbb57e9c96