48 #undef csect_initialize_critical_section 49 #undef csect_finalize_critical_section 51 #undef csect_enter_as_reader 53 #undef csect_enter_critical_section 54 #undef csect_exit_critical_section 56 #define TOTAL_AND_MAX_TIMEVAL(total, max, elapsed) \ 59 (total).tv_sec += elapsed.tv_sec; \ 60 (total).tv_usec += elapsed.tv_usec; \ 61 (total).tv_sec += (total).tv_usec / 1000000; \ 62 (total).tv_usec %= 1000000; \ 63 if (((max).tv_sec < elapsed.tv_sec) || ((max).tv_sec == elapsed.tv_sec && (max).tv_usec < elapsed.tv_usec)) \ 65 (max).tv_sec = elapsed.tv_sec; \ 66 (max).tv_usec = elapsed.tv_usec; \ 77 "LOCATOR_CLASSNAME_TABLE",
86 "COMPACTDB_ONE_INSTANCE",
97 return c !=
NULL ? c->
name :
"UNKNOWN";
111 #define NUM_ENTRIES_OF_SYNC_STATS_BLOCK 256 126 struct timespec *to);
128 struct timespec *to);
212 error_code = pthread_cond_destroy (&csect->
readers_ok);
247 csect = &csectgl_Critical_sections[
i];
273 csect = &csectgl_Critical_sections[
i];
294 thread_p->next_wait_thrd =
NULL;
305 while (prev_thread_p->next_wait_thrd !=
NULL)
307 assert (prev_thread_p != thread_p);
309 prev_thread_p = prev_thread_p->next_wait_thrd;
312 assert (prev_thread_p != thread_p);
313 prev_thread_p->next_wait_thrd = thread_p;
324 while (prev_thread_p !=
NULL)
326 if (prev_thread_p == thread_p)
330 prev_thread_p = prev_thread_p->next_wait_thrd;
333 if (prev_thread_p !=
NULL)
363 thread_p->next_wait_thrd =
NULL;
374 while (prev_thread_p->next_wait_thrd !=
NULL)
376 assert (prev_thread_p != thread_p);
378 prev_thread_p = prev_thread_p->next_wait_thrd;
381 assert (prev_thread_p != thread_p);
382 prev_thread_p->next_wait_thrd = thread_p;
393 while (prev_thread_p !=
NULL)
395 if (prev_thread_p == thread_p)
399 prev_thread_p = prev_thread_p->next_wait_thrd;
402 if (prev_thread_p !=
NULL)
434 if (waiting_thread_p !=
NULL)
437 waiting_thread_p->next_wait_thrd =
NULL;
453 if (waiting_thread_p !=
NULL)
456 waiting_thread_p->next_wait_thrd =
NULL;
477 TSC_TICKS wait_start_tick, wait_end_tick;
482 if (thread_p ==
NULL)
501 if (csect->
rwlock < 0 && csect->
owner == thread_p->get_id ())
517 if (thread_p->event_stats.trace_slow_query ==
true)
523 if (thread_p->event_stats.trace_slow_query ==
true)
568 else if (wait_secs > 0)
571 to.tv_sec = time (
NULL) + wait_secs;
576 if (thread_p->event_stats.trace_slow_query ==
true)
582 if (thread_p->event_stats.trace_slow_query ==
true)
626 csect->
owner = thread_p->get_id ();
649 "csect_enter_critical_section_as_reader: %6d.%06d" 650 " %s total_enter %d ntotal_elapsed %d max_elapsed %d.%06d total_elapsed %d.06d\n", tv_diff.tv_sec,
656 thread_p->get_csect_tracker ().on_enter_as_writer (csect->
cs_index);
678 csect = &csectgl_Critical_sections[cs_index];
679 #if defined (SERVER_MODE) 698 TSC_TICKS wait_start_tick, wait_end_tick;
703 if (thread_p ==
NULL)
720 if (csect->
rwlock < 0 && csect->
owner == thread_p->get_id ())
738 if (thread_p->event_stats.trace_slow_query ==
true)
743 error_code = pthread_cond_wait (&csect->
readers_ok, &csect->
lock);
744 if (thread_p->event_stats.trace_slow_query ==
true)
778 else if (wait_secs > 0)
781 to.tv_sec = time (
NULL) + wait_secs;
787 if (thread_p->event_stats.trace_slow_query ==
true)
792 error_code = pthread_cond_timedwait (&csect->
readers_ok, &csect->
lock, &to);
793 if (thread_p->event_stats.trace_slow_query ==
true)
811 if (error_code != ETIMEDOUT)
868 "csect_enter_critical_section: %6d.%06d %s total_enter %d ntotal_elapsed %d max_elapsed %d.%06d" 869 " total_elapsed %d.06d\n", tv_diff.tv_sec, tv_diff.tv_usec,
csect_name (csect),
875 thread_p->get_csect_tracker ().on_enter_as_reader (csect->
cs_index);
895 csect = &csectgl_Critical_sections[cs_index];
896 #if defined (SERVER_MODE) 917 TSC_TICKS wait_start_tick, wait_end_tick;
922 if (thread_p ==
NULL)
939 if (csect->
rwlock < 0 && csect->
owner == thread_p->get_id ())
981 if (thread_p->event_stats.trace_slow_query ==
true)
986 error_code = pthread_cond_wait (&csect->
readers_ok, &csect->
lock);
987 if (thread_p->event_stats.trace_slow_query ==
true)
1021 else if (wait_secs > 0)
1024 to.tv_sec = time (
NULL) + wait_secs;
1030 if (thread_p->event_stats.trace_slow_query ==
true)
1035 error_code = pthread_cond_timedwait (&csect->
readers_ok, &csect->
lock, &to);
1036 if (thread_p->event_stats.trace_slow_query ==
true)
1045 if (error_code != 0)
1054 if (error_code != ETIMEDOUT)
1096 error_code = pthread_cond_broadcast (&csect->
readers_ok);
1128 "csect_demote_critical_section: %6d.%06d %s total_enter %d ntotal_elapsed %d max_elapsed %d.%06d" 1129 " total_elapsed %d.06d\n", tv_diff.tv_sec, tv_diff.tv_usec,
csect_name (csect),
1134 thread_p->get_csect_tracker ().on_demote (csect->
cs_index);
1154 csect = &csectgl_Critical_sections[cs_index];
1172 TSC_TICKS wait_start_tick, wait_end_tick;
1177 if (thread_p ==
NULL)
1210 while (csect->
rwlock != 0)
1213 if (csect->
rwlock < 0 && csect->
owner == thread_p->get_id ())
1228 if (thread_p->event_stats.trace_slow_query ==
true)
1234 if (thread_p->event_stats.trace_slow_query ==
true)
1256 else if (wait_secs > 0)
1259 to.tv_sec = time (
NULL) + wait_secs;
1264 if (thread_p->event_stats.trace_slow_query ==
true)
1270 if (thread_p->event_stats.trace_slow_query ==
true)
1313 csect->
owner = thread_p->get_id ();
1336 "csect_promote_critical_section: %6d.%06d %s total_enter %d ntotal_elapsed %d max_elapsed %d.%06d" 1337 " total_elapsed %d.06d\n", tv_diff.tv_sec, tv_diff.tv_usec,
csect_name (csect),
1343 thread_p->get_csect_tracker ().on_promote (csect->
cs_index);
1363 csect = &csectgl_Critical_sections[cs_index];
1380 if (thread_p ==
NULL)
1406 thread_p->get_csect_tracker ().on_exit (csect->
cs_index);
1416 else if (csect->
rwlock > 0)
1456 else if (ww ==
true)
1469 error_code = pthread_cond_broadcast (&csect->
readers_ok);
1487 thread_p->get_csect_tracker ().on_exit (csect->
cs_index);
1508 csect = &csectgl_Critical_sections[cs_index];
1509 #if defined (SERVER_MODE) 1526 fprintf (fp,
" CS Name |Total Enter|Total Wait |Total Reenter| Max elapsed | Total elapsed\n");
1530 csect = &csectgl_Critical_sections[
i];
1532 fprintf (fp,
"%-23s |%10d |%10d | %10d | %6ld.%06ld | %6ld.%06ld\n",
1556 csect = &csectgl_Critical_sections[cs_index];
1569 int error_code =
NO_ERROR, return_code;
1571 if (thread_p ==
NULL)
1584 if (csect->
rwlock < 0 && csect->
owner == thread_p->get_id ())
1589 else if (csect->
rwlock > 0)
1628 char buf[256] = { 0 };
1655 csect = &csectgl_Critical_sections[
i];
1669 snprintf (buf,
sizeof (buf),
"%d readers", ival);
1673 snprintf (buf,
sizeof (buf),
"1 writer");
1677 snprintf (buf,
sizeof (buf),
"none");
1696 owner_tid = csect->
owner;
1704 if (thread_entry !=
NULL)
1737 if (thread_entry !=
NULL)
1769 assert (idx == num_cols);
1818 rwlock->
name = name;
2054 fprintf (fp,
"\n RWlock Name |Total Enter| Max elapsed | Total elapsed\n");
2068 fprintf (fp,
"%-29s |%10d | %6ld.%06ld | %6ld.%06ld\n", stats->
name, stats->
nenter,
2168 if (thread_p ==
NULL)
2174 if (rmutex->
owner == thread_p->get_id ())
2203 rmutex->
owner = thread_p->get_id ();
2226 if (thread_p ==
NULL)
2302 for (p = p->
next; p !=
NULL; p = next)
2381 stats = &sync_stats_chunk->
block[idx];
2384 stats->
type = sync_prim_type;
2458 if (new_chunk ==
NULL)
2465 last_chunk->
next = new_chunk;
2495 idx = (int) (stats - p->
block);
2526 fprintf (fp,
"\n RMutex Name |Total Enter|Total Reenter| Max elapsed | Total elapsed\n");
2540 fprintf (fp,
"%-28s |%10d | %10d | %6ld.%06ld | %6ld.%06ld\n", stats->
name, stats->
nenter,
void rmutex_dump_statistics(FILE *fp)
int rwlock_finalize(SYNC_RWLOCK *rwlock)
cubthread::entry * thread_get_thread_entry_info(void)
int csect_enter_critical_section(THREAD_ENTRY *thread_p, SYNC_CRITICAL_SECTION *csect, int wait_secs)
static int sync_initialize_sync_stats_chunk(SYNC_STATS_CHUNK *sync_stats_chunk)
static int csect_wakeup_waiting_promoter(SYNC_CRITICAL_SECTION *csect)
int sync_finalize_sync_stats(void)
pthread_mutex_t sync_Stats_lock
#define ER_CSS_PTHREAD_COND_TIMEDOUT
void showstmt_free_array_context(THREAD_ENTRY *thread_p, SHOWSTMT_ARRAY_CONTEXT *ctx)
#define pthread_mutex_init(a, b)
int db_make_bigint(DB_VALUE *value, const DB_BIGINT num)
THREAD_ENTRY * waiting_promoters_queue
#define pthread_mutex_unlock(a)
static int csect_wakeup_waiting_writer(SYNC_CRITICAL_SECTION *csect)
void sync_dump_statistics(FILE *fp, SYNC_PRIMITIVE_TYPE type)
#define NUM_ENTRIES_OF_SYNC_STATS_BLOCK
#define TOTAL_AND_MAX_TIMEVAL(total, max, elapsed)
static SYNC_STATS_CHUNK * sync_allocate_sync_stats_chunk(void)
#define ASSERT_ERROR_AND_SET(error_code)
int csect_enter_as_reader(THREAD_ENTRY *thread_p, int cs_index, int wait_secs)
unsigned long int thread_id_t
#define ER_CSS_PTHREAD_COND_DESTROY
int csect_promote(THREAD_ENTRY *thread_p, int cs_index, int wait_secs)
#define ER_CSS_PTHREAD_MUTEX_LOCK
cubthread::manager * thread_get_manager(void)
struct timeval TSCTIMEVAL
void tsc_elapsed_time_usec(TSCTIMEVAL *tv, TSC_TICKS end_tick, TSC_TICKS start_tick)
static SYNC_STATS * sync_consume_sync_stats_from_pool(SYNC_STATS_CHUNK *sync_stats_chunk, int idx, SYNC_PRIMITIVE_TYPE sync_prim_type, const char *name)
int numeric_db_value_coerce_to_num(DB_VALUE *src, DB_VALUE *dest, DB_DATA_STATUS *data_status)
void csect_dump_statistics(FILE *fp)
int csect_initialize_critical_section(SYNC_CRITICAL_SECTION *csect, const char *name)
SHOWSTMT_ARRAY_CONTEXT * showstmt_alloc_array_context(THREAD_ENTRY *thread_p, int num_total, int num_cols)
#define ER_CSS_PTHREAD_COND_SIGNAL
#define er_log_debug(...)
#define ER_CSS_PTHREAD_COND_WAIT
static int sync_return_sync_stats_to_pool(SYNC_STATS_CHUNK *sync_stats_chunk, int idx)
int rwlock_write_unlock(SYNC_RWLOCK *rwlock)
SYNC_STATS_CHUNK sync_Stats
pthread_mutex_t global_lock
static const char * csect_name(SYNC_CRITICAL_SECTION *c)
static int csect_check_own_critical_section(THREAD_ENTRY *thread_p, SYNC_CRITICAL_SECTION *csect)
unsigned int waiting_readers
int db_make_string(DB_VALUE *value, DB_CONST_C_CHAR str)
bool is_single_thread(void)
void er_set(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
int prm_get_integer_value(PARAM_ID prm_id)
int csect_exit_critical_section(THREAD_ENTRY *thread_p, SYNC_CRITICAL_SECTION *csect)
static const char * csect_Names[]
struct timeval max_elapsed
int rmutex_initialize(SYNC_RMUTEX *rmutex, const char *name)
#define ER_OUT_OF_VIRTUAL_MEMORY
int csect_finalize_static_critical_sections(void)
unsigned int waiting_writers
int rmutex_lock(THREAD_ENTRY *thread_p, SYNC_RMUTEX *rmutex)
pthread_cond_t readers_ok
pthread_mutex_t read_lock
static int csect_demote_critical_section(THREAD_ENTRY *thread_p, SYNC_CRITICAL_SECTION *csect, int wait_secs)
int csect_enter(THREAD_ENTRY *thread_p, int cs_index, int wait_secs)
static int csect_promote_critical_section(THREAD_ENTRY *thread_p, SYNC_CRITICAL_SECTION *csect, int wait_secs)
void tsc_getticks(TSC_TICKS *tck)
int csect_finalize_critical_section(SYNC_CRITICAL_SECTION *csect)
DB_VALUE * showstmt_alloc_tuple_in_context(THREAD_ENTRY *thread_p, SHOWSTMT_ARRAY_CONTEXT *ctx)
int rwlock_initialize(SYNC_RWLOCK *rwlock, const char *name)
int csect_start_scan(THREAD_ENTRY *thread_p, int show_type, DB_VALUE **arg_values, int arg_cnt, void **ptr)
void er_set_with_oserror(int severity, const char *file_name, const int line_no, int err_id, int num_args,...)
SYNC_CRITICAL_SECTION csectgl_Critical_sections[CRITICAL_SECTION_COUNT]
THREAD_ENTRY * waiting_writers_queue
void rwlock_dump_statistics(FILE *fp)
#define ER_CSS_PTHREAD_MUTEX_DESTROY
static SYNC_STATS * sync_allocate_sync_stats(SYNC_PRIMITIVE_TYPE sync_prim_type, const char *name)
SYNC_STATS block[NUM_ENTRIES_OF_SYNC_STATS_BLOCK]
#define ER_MNT_WAITING_THREAD
static void error(const char *msg)
int rwlock_write_lock(SYNC_RWLOCK *rwlock)
int rmutex_unlock(THREAD_ENTRY *thread_p, SYNC_RMUTEX *rmutex)
#define TSC_ADD_TIMEVAL(total, diff)
struct timeval total_elapsed
#define free_and_init(ptr)
int rwlock_read_unlock(SYNC_RWLOCK *rwlock)
int csect_demote(THREAD_ENTRY *thread_p, int cs_index, int wait_secs)
int thread_suspend_with_other_mutex(cubthread::entry *thread_p, pthread_mutex_t *mutex_p, int timeout, struct timespec *to, thread_resume_suspend_status suspended_reason)
int db_make_string_copy(DB_VALUE *value, DB_CONST_C_CHAR str)
int csect_initialize_static_critical_sections(void)
#define ER_CSS_PTHREAD_MUTEX_UNLOCK
int csect_exit(THREAD_ENTRY *thread_p, int cs_index)
entry * find_by_tid(thread_id_t tid)
int db_make_null(DB_VALUE *value)
#define ER_CSS_PTHREAD_COND_BROADCAST
#define ER_CS_UNLOCKED_BEFORE
static int csect_wait_on_promoter_queue(THREAD_ENTRY *thread_p, SYNC_CRITICAL_SECTION *csect, int timeout, struct timespec *to)
int db_make_double(DB_VALUE *value, const DB_C_DOUBLE num)
static const int CRITICAL_SECTION_COUNT
static void sync_reset_stats_metrics(SYNC_STATS *stats)
#define pthread_mutex_lock(a)
int csect_enter_critical_section_as_reader(THREAD_ENTRY *thread_p, SYNC_CRITICAL_SECTION *csect, int wait_secs)
int db_make_int(DB_VALUE *value, const int num)
void thread_wakeup(cubthread::entry *thread_p, thread_resume_suspend_status resume_reason)
static int sync_deallocate_sync_stats(SYNC_STATS *stats)
static int csect_wait_on_writer_queue(THREAD_ENTRY *thread_p, SYNC_CRITICAL_SECTION *csect, int timeout, struct timespec *to)
int rmutex_finalize(SYNC_RMUTEX *rmutex)
#define ER_CSS_PTHREAD_MUTEX_INIT
#define MONITOR_WAITING_THREAD(elapsed)
int csect_check_own(THREAD_ENTRY *thread_p, int cs_index)
#define ER_CSS_PTHREAD_COND_INIT
int rwlock_read_lock(SYNC_RWLOCK *rwlock)
int db_value_domain_init(DB_VALUE *value, const DB_TYPE type, const int precision, const int scale)
int sync_initialize_sync_stats(void)
#define pthread_mutex_destroy(a)
const char * csect_name_at(int cs_index)