summaryrefslogtreecommitdiffstats
path: root/src/include/k5-thread.h
Commit message (Collapse)AuthorAgeFilesLines
* hooks for recording statistics on locking behaviorKen Raeburn2004-12-061-10/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Finish the hooks (left disabled by default) for logging somewhere the recorded timing behavior relating to the use of locks in the krb5 code. Currently, "reporting" means writing to /dev/tty or stderr, and the data is the number of times a mutex is locked, file and line where it was created, min/avg/max/stddev wait times to acquire the lock and hold times, and stats are only written out for locks that were locked a certain minimum number of times and with a minimum average wait time. The criteria are all controlled in threads.c, and k5-thread.h just has the hooks for gathering data. So turning on/off the data gathering requires a full rebuild, but tweaking the reporting is mostly just a relinking pass. (May also require adding a dependence on the math library to the support library; for a static build that may impact a lot of makefiles.) * include/k5-thread.h [DEBUG_THREADS_STATS]: Include string.h and inttypes.h. (get_current_time) [DEBUG_THREADS_STATS]: Define as inline. (k5_mutex_init_stats) [DEBUG_THREADS_STATS]: Save away current time as creation time. (k5_mutex_stats_tmp): New typedef, k5_debug_time_t if recording stats, dummy int otherwise. (k5_mutex_stats_start): New macro, get current time if recording, zero otherwise. (krb5int_mutex_lock_update_stats, krb5int_mutex_unlock_update_stats, krb5int_mutex_report_stats) [DEBUG_THREADS_STATS]: Declare. (krb5int_mutex_report_stats) [! DEBUG_THREADS_STATS]: New macro, does nothing. (k5_mutex_lock_update_stats, k5_mutex_unlock_update_stats): New macros, map to krb5int_ functions if recording, dummy statements otherwise. (k5_mutex_destroy): Call krb5int_mutex_report_stats. (k5_mutex_lock, k5_mutex_lock_1): Call k5_mutex_stats_start and k5_mutex_lock_update_stats. (k5_mutex_unlock_1): Call k5_mutex_unlock_update_stats. * util/support/threads.c [DEBUG_THREADS_STATS]: Include stdio.h. (stats_logfile) [DEBUG_THREADS_STATS]: New variable. (krb5int_thread_support_init) [DEBUG_THREADS_STATS]: Set it to point to a file on /dev/tty or stderr. (krb5int_thread_support_fini) [DEBUG_THREADS_STATS]: Flush it. (k5_mutex_lock_update_stats, krb5int_mutex_unlock_update_stats, get_stddev, krb5int_mutex_report_stats) [DEBUG_THREADS_STATS]: New functions. * util/support/libkrb5support.exports: Add krb5int_mutex_*_stats. ticket: new git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16913 dc483132-0cff-0310-8789-dd5450dbe970
* * k5-thread.h (return_after_yield, k5_mutex_lock) [__GNUC__]: Add macroKen Raeburn2004-10-281-1/+21
| | | | | | | versions so debugging line numbers will be useful. (DEBUG_THREADS_SLOW): Don't define. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16842 dc483132-0cff-0310-8789-dd5450dbe970
* Fix Tru64 build:Ken Raeburn2004-08-151-6/+6
| | | | | | | | * k5-thread.h (k5_os_nothread_mutex_assert_locked, k5_os_nothread_mutex_assert_unlocked, k5_os_mutex_assert_locked, k5_os_mutex_assert_unlocked): Assertion macros should always have type void. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16663 dc483132-0cff-0310-8789-dd5450dbe970
* * k5-thread.h (k5_os_nothread_mutex_finish_init, k5_os_nothread_mutex_init,Ken Raeburn2004-08-131-25/+53
| | | | | | | | | | | | | | k5_os_nothread_mutex_destroy, k5_os_nothread_mutex_lock, k5_os_nothread_mutex_unlock) [!DEBUG_THREADS]: Replace macros with inline functions, to gain type checking and eliminate gratuitous compiler warnings. (k5_pthread_assert_unlocked, k5_pthread_assert_locked): Likewise. (k5_os_mutex_finish_init) [HAVE_PTHREAD && !USE_PTHREAD_LOCK_ONLY_IF_LOADED]: Likewise. (return_after_yield): New inline function. (k5_os_mutex_lock) [HAVE_PTHREAD]: Change back to a macro, calling return_after_yield. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16661 dc483132-0cff-0310-8789-dd5450dbe970
* * configure.in: Look for sched.h and sched_yield.Ken Raeburn2004-08-071-2/+7
| | | | | | | | | * k5-thread.h: Only include sched.h if it's available. (MAYBE_SCHED_YIELD): Only use sched_yield if sched.h and sched_yield are available; if weak references are supported and sched_yield isn't available by default, check for it at run time. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16645 dc483132-0cff-0310-8789-dd5450dbe970
* * k5-thread.h [HAVE_PTHREAD]: Include sched.h if DEBUG_THREADS_SLOW is defined.Ken Raeburn2004-08-051-10/+30
| | | | | | | | | (MAYBE_SCHED_YIELD) [HAVE_PTHREAD]: Define, to call sched_yield or not, depending on DEBUG_THREADS_SLOW. (k5_os_mutex_lock, k5_os_mutex_unlock) [HAVE_PTHREAD]: Use MAYBE_SCHED_YIELD. (DEBUG_THREADS_SLOW): Define. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16642 dc483132-0cff-0310-8789-dd5450dbe970
* * k5-thread.h [HAVE_PRAGMA_WEAK_REF]: Declare the pthread mutex functions asKen Raeburn2004-07-281-0/+8
| | | | | | | | weak. (USE_PTHREAD_LOCK_ONLY_IF_LOADED): Define if pthread_mutex_lock isn't available by default. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16625 dc483132-0cff-0310-8789-dd5450dbe970
* * k5-thread.h (k5_key_t): Add a couple new values for GSSAPI ccache name ↵Ken Raeburn2004-07-141-0/+2
| | | | | | manipulation git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16588 dc483132-0cff-0310-8789-dd5450dbe970
* * k5-thread.h (k5_os_mutex_init, k5_os_mutex_destroy): IfKen Raeburn2004-07-141-2/+6
| | | | | | | USE_PTHREAD_LOCK_ONLY_IF_LOADED is defined, use pthread_mutex_init and _destroy only if pthread support is loaded. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16587 dc483132-0cff-0310-8789-dd5450dbe970
* * k5-thread.h (k5_os_mutex_lock, k5_os_mutex_unlock, k5_os_mutex_assert_locked,Ken Raeburn2004-07-111-4/+4
| | | | | | | k5_os_mutex_assert_unlocked) [USE_PTHREAD_LOCK_ONLY_IF_LOADED]: Fix typo in accessing non-pthread versions. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16580 dc483132-0cff-0310-8789-dd5450dbe970
* * k5-thread.h: Test HAVE_PTHREAD instead of HAVE_PTHREAD_HKen Raeburn2004-07-091-1/+1
| | | | git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16573 dc483132-0cff-0310-8789-dd5450dbe970
* * k5-thread.h [! HAVE_PTHREAD_H]: Don't explicitly disable thread support whenKen Raeburn2004-07-071-5/+40
| | | | | | | | | | pthread.h is missing. (k5_os_mutex, K5_OS_MUTEX_PARTIAL_INITIALIZER, k5_os_mutex_finish_init, k5_os_mutex_init, k5_os_mutex_destroy, k5_os_mutex_lock, k5_os_mutex_unlock, k5_os_mutex_assert_unlocked, k5_os_mutex_assert_locked) [_WIN32]: Define Windows versions; still not enabled by default. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16552 dc483132-0cff-0310-8789-dd5450dbe970
* * k5-thread.h: Use K5_THREAD_H for multiple inclusion protection.Ken Raeburn2004-07-071-3/+65
| | | | | | | | | | | (k5_debug_mutex_stats, k5_mutex_init_stats, k5_mutex_finish_init_stats, K5_MUTEX_STATS_INIT): Add some dummy support for recording statistics on how long mutexes are held, etc. Incomplete implementation started, but code not enabled. (k5_mutex_t): Add statistics field. (K5_MUTEX_PARTIAL_INITIALIZER, k5_mutex_init_1, k5_mutex_init): Initialize it. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16550 dc483132-0cff-0310-8789-dd5450dbe970
* * k5-thread.h: Restructured mutex code.Ken Raeburn2004-07-021-175/+278
| | | | | | | | | | | | | | | (k5_debug_loc): New type, may contain file/line info if DEBUG_THREADS_LOC is defined. (k5_os_nothread_*): Dummy implementation of mutex lock for a single-threded process. Uses a flag and assert() if DEBUG_THREADS is defined, does nothing interesting otherwise. (k5_os_mutex*, k5_once*): General implementations, with dummy or POSIX or POSIX-if-loaded-otherwise-dummy variants. (k5_mutex_*): Combine OS-specific mutex implementation with optional file/line tracking, and provide a place to instrument for other debugging or performance data. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16539 dc483132-0cff-0310-8789-dd5450dbe970
* * k5-thread.h (K5_MUTEX_DEBUG_INITIALIZER): Use current file and line.Ken Raeburn2004-07-011-10/+14
| | | | | | | | | | | | | (k5_mutex_debug_finish_init, k5_mutex_debug_init, k5_mutex_debug_destroy): Save current file and line. (k5_mutex_debug_lock): Verify that the lock was unlocked before, and set the state to locked. (k5_mutex_debug_unlock): Verify that the mutex was locked before, and set the state to unlocked. (k5_debug_assert_locked, k5_debug_assert_unlocked): Use k5_mutex_debug_check_init instead of checking initialized==1. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16535 dc483132-0cff-0310-8789-dd5450dbe970
* * k5-thread.h (k5_debug_assert_locked, k5_debug_assert_unlocked): New macros.Ken Raeburn2004-06-301-0/+15
| | | | | | | (k5_assert_locked, k5_assert_unlocked): New macros, may or may not call the debug macros. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16533 dc483132-0cff-0310-8789-dd5450dbe970
* * k5-thread.h: Error out at compile time if thread support is enabled but theKen Raeburn2004-06-021-0/+20
| | | | | | | | thread system isn't pthreads. (This is after the code disabling thread support for non-pthreads systems, so it's a placeholder for now that should never get invoked.) git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16393 dc483132-0cff-0310-8789-dd5450dbe970
* * k5-thread.h: On IRIX, with threads enabled, reject gcc older than v3Ken Raeburn2004-05-131-1/+1
| | | | git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16330 dc483132-0cff-0310-8789-dd5450dbe970
* * k5-thread.h: On IRIX, if gcc is older than v3, tell the user to get a newerKen Raeburn2004-05-131-1/+4
| | | | | | | | | one, and error out. (We need weak reference support for pthread_once, gcc 2.95 doesn't support them, but gcc 3, which has been out for nearly 3 years, does.) git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16329 dc483132-0cff-0310-8789-dd5450dbe970
* Update mutex debug code to be somewhat compatible with multi-threadedKen Raeburn2004-05-011-24/+28
| | | | | | | | | | | | | | | | | execution. It won't be as useful in single-threaded programs for detecting bugs in the mutex handling for now, though. * k5-thread.h (k5_mutex_debug_check_init, k5_mutex_debug_update_loc): New macros. (k5_mutex_debug_lock, k5_mutex_debug_unlock): Use them. (k5_mutex_lock, k5_mutex_unlock) [ENABLE_THREADS && DEBUG_THREADS]: Use them instead of k5_mutex_debug_lock and k5_mutex_debug_unlock. (enum k5_mutex_debug_states): New enum. (K5_MUTEX_DEBUG_LOCKED, K5_MUTEX_DEBUG_UNLOCKED): Change to enumerator values. (k5_mutex_debug_info): Use the enum type. Reorder fields. (K5_MUTEX_DEBUG_INITIALIZER): Update for new field order. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16293 dc483132-0cff-0310-8789-dd5450dbe970
* Added support for library initialization and finalization, and verificationKen Raeburn2004-04-241-27/+200
| | | | | | | | | | | | | | | | | | | | | | | | | | | that the initializer completed successfully. Delay initialization on POSIX until the first "verification" call. Currently specific to a few platforms, but should still build on others without thread support enabled. Use it to finish creating (if necessary) and destroy mutexes, and free some other storage "permanently" allocated by libraries (currently, libkrb5 cache/keytab type registries only). Change initialization of static mutexes to a two-step operation, a static "partial" initializer and a "finish_init" routine called from a thread-safe environment like library initialization is assumed to be. POSIX will use the former, Windows will use the latter, and the debug support will check that *both* have been used. Added init/fini functions to com_err, profile, krb5, and gssapi libraries. (The profile library one may need to be removed later.) The existing ones, not thread-safe, are still around. Use weak symbol support if available to figure out if the pthread library has been linked in, and avoid calling certain routines if the C library stubs are known not to exist or work. Stub declarations for thread-specific data. Minor bugfixes, whitespace changes. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16268 dc483132-0cff-0310-8789-dd5450dbe970
* fix debug initializer and copyrightKen Raeburn2004-03-061-3/+29
| | | | git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16152 dc483132-0cff-0310-8789-dd5450dbe970
* * k5-thread.h: New fileKen Raeburn2004-03-061-0/+147
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@16148 dc483132-0cff-0310-8789-dd5450dbe970