Lines Matching +full:entry +full:- +full:latency +full:- +full:us
1 // SPDX-License-Identifier: GPL-2.0
44 C(FUNC_TR, "function-trace"), \
45 C(DISP_GR, "display-graph"), \
134 "No latency tracers are supported by your kernel!\n";
184 struct entry { struct
222 struct entry entries[QUEUE_SIZE];
271 count -= r; in write_or_die()
519 future->tv_sec += time_us / USEC_PER_SEC; in get_time_in_future()
520 nsec = future->tv_nsec + (time_us * NSEC_PER_USEC) % NSEC_PER_SEC; in get_time_in_future()
522 future->tv_nsec = nsec % NSEC_PER_SEC; in get_time_in_future()
523 future->tv_sec += 1; in get_time_in_future()
532 if (now.tv_sec > time->tv_sec) in time_has_passed()
534 if (now.tv_sec < time->tv_sec) in time_has_passed()
536 return (now.tv_nsec >= time->tv_nsec); in time_has_passed()
560 if (state->opt_valid[i] && state->opt[i] != cur[i]) { in restore_trace_opts()
561 r = set_trace_opt(optstr[i], state->opt[i]); in restore_trace_opts()
564 optstr[i], bool2str(state->opt[i])); in restore_trace_opts()
568 bool2str(state->opt[i])); in restore_trace_opts()
588 if (r && r[psize - 1] == '\n') in read_file()
589 r[psize - 1] = '\0'; in read_file()
631 printf("The maximum detected latency was: %sus\n", maxlat); in cleanup_exit()
661 static int printstate_next_ticket(struct entry *req) in printstate_next_ticket()
666 req->ticket = r; in printstate_next_ticket()
667 req->ticket_completed_ref = printstate.ticket_completed; in printstate_next_ticket()
673 void printstate_mark_req_completed(const struct entry *req) in printstate_mark_req_completed()
675 if (req->ticket > printstate.ticket_completed) in printstate_mark_req_completed()
676 printstate.ticket_completed = req->ticket; in printstate_mark_req_completed()
680 bool printstate_has_new_req_arrived(const struct entry *req) in printstate_has_new_req_arrived()
682 return (printstate.ticket_counter != req->ticket); in printstate_has_new_req_arrived()
700 value = --printstate.cnt; in printstate_cnt_dec()
716 bool prev_req_won_race(const struct entry *req) in prev_req_won_race()
718 return (printstate.ticket_completed != req->ticket_completed_ref); in prev_req_won_race()
726 msg->len = 0; in sleeptable_resize()
728 bytes = snprintf(msg->buf, sizeof(msg->buf), in sleeptable_resize()
731 bytes = snprintf(msg->buf, sizeof(msg->buf), in sleeptable_resize()
736 msg->len = bytes; in sleeptable_resize()
746 sleeptable.table = &probabilities[PROB_TABLE_MAX_SIZE - size]; in sleeptable_resize()
756 j--; in init_probabilities()
761 static int table_get_probability(const struct entry *req, in table_get_probability()
764 int diff = req->ticket - req->ticket_completed_ref; in table_get_probability()
767 msg->len = 0; in table_get_probability()
768 diff--; in table_get_probability()
776 if (diff >= (sleeptable.size - 1)) { in table_get_probability()
777 rval = sleeptable.table[sleeptable.size - 1]; in table_get_probability()
789 q->next_prod_idx = 0; in init_queue()
790 q->next_cons_idx = 0; in init_queue()
791 mutex_init(&q->mutex, NULL); in init_queue()
792 errno = pthread_cond_init(&q->cond, NULL); in init_queue()
799 if (q->next_prod_idx >= q->next_cons_idx) in queue_len()
800 return q->next_prod_idx - q->next_cons_idx; in queue_len()
802 return QUEUE_SIZE - q->next_cons_idx + q->next_prod_idx; in queue_len()
807 int nr_free = QUEUE_SIZE - queue_len(q); in queue_nr_free()
824 const struct entry *e) in queue_push_to_back()
826 q->entries[q->next_prod_idx] = *e; in queue_push_to_back()
827 queue_idx_inc(&q->next_prod_idx); in queue_push_to_back()
830 static __always_inline struct entry queue_pop_from_front(struct queue *q) in queue_pop_from_front()
832 struct entry e = q->entries[q->next_cons_idx]; in queue_pop_from_front()
834 queue_idx_inc(&q->next_cons_idx); in queue_pop_from_front()
840 cond_signal(&q->cond); in queue_cond_signal()
845 cond_wait(&q->cond, &q->mutex); in queue_cond_wait()
849 const struct entry *e) in queue_try_to_add_entry()
853 mutex_lock(&q->mutex); in queue_try_to_add_entry()
856 cond_signal(&q->cond); in queue_try_to_add_entry()
858 r = -1; in queue_try_to_add_entry()
859 mutex_unlock(&q->mutex); in queue_try_to_add_entry()
863 static struct entry queue_wait_for_entry(struct queue *q) in queue_wait_for_entry()
865 struct entry e; in queue_wait_for_entry()
867 mutex_lock(&q->mutex); in queue_wait_for_entry()
875 mutex_unlock(&q->mutex); in queue_wait_for_entry()
884 while (p->name != NULL) { in policy_from_name()
885 if (!strcmp(name, p->name)) in policy_from_name()
897 while (p->name != NULL) { in policy_name()
898 if (p->policy == policy) in policy_name()
899 return p->name; in policy_name()
948 printf("The following latency tracers are available on your system:\n"); in show_available()
1009 static long go_to_sleep(const struct entry *req) in go_to_sleep()
1024 delay = -1; in go_to_sleep()
1074 size_t bufspace, const struct entry *req, bool excuse, in __print_skipmessage()
1079 long us, sec; in __print_skipmessage() local
1082 sec = timestamp->tv_sec; in __print_skipmessage()
1083 us = timestamp->tv_nsec / 1000; in __print_skipmessage()
1085 if (resize_msg != NULL && resize_msg->len > 0) { in __print_skipmessage()
1086 strncpy(p, resize_msg->buf, resize_msg->len); in __print_skipmessage()
1087 bytes += resize_msg->len; in __print_skipmessage()
1088 p += resize_msg->len; in __print_skipmessage()
1089 bufspace -= resize_msg->len; in __print_skipmessage()
1094 "%ld.%06ld Latency %d printout skipped due to %s\n", in __print_skipmessage()
1095 sec, us, req->ticket, str); in __print_skipmessage()
1097 r = snprintf(p, bufspace, "%ld.%06ld Latency %d detected\n", in __print_skipmessage()
1098 sec, us, req->ticket); in __print_skipmessage()
1113 size_t bufspace, const struct entry *req, in print_skipmessage()
1121 size_t bufspace, const struct entry *req, in print_lostmessage()
1131 const struct entry *req) in print_tracefile()
1137 long us, sec; in print_tracefile() local
1142 bufspace = bufspace - reserve - 1; in print_tracefile()
1144 if (resize_msg != NULL && resize_msg->len > 0) { in print_tracefile()
1145 bytes = resize_msg->len; in print_tracefile()
1146 strncpy(p, resize_msg->buf, bytes); in print_tracefile()
1149 bufspace -= bytes; in print_tracefile()
1159 sec = timestamp->tv_sec; in print_tracefile()
1160 us = timestamp->tv_nsec / 1000; in print_tracefile()
1165 "%ld.%06ld Latency %d randomly sleep for %ld ms before print\n", in print_tracefile()
1166 sec, us, req->ticket, slept_ms); in print_tracefile()
1169 "%ld.%06ld Latency %d immediate print\n", sec, in print_tracefile()
1170 us, req->ticket); in print_tracefile()
1178 bufspace -= bytes; in print_tracefile()
1191 bufspace -= bytes; in print_tracefile()
1207 bufspace -= bytes; in print_tracefile()
1334 state->opt[i] = get_trace_opt(allopt, optstr[i], in save_trace_opts()
1335 &state->opt_valid[i]); in save_trace_opts()
1393 "Use the -F [--force] option to disregard the current tracer.\n", tracer); in save_and_disable_tracer()
1420 if (state->opt_valid[i] && in set_trace_opts()
1421 state->opt[i] != new[i]) { in set_trace_opts()
1459 struct entry req; in tracing_loop()
1513 if ((event->mask & IN_MODIFY) != 0) in tracing_loop()
1515 p += istructsize + event->len; in tracing_loop()
1544 modified--; in tracing_loop()
1556 struct entry req; in do_printloop()
1589 * latency tracer. Thus by randomly sleeping we try to avoid in do_printloop()
1591 * we will sometimes get the first latency, some other times in do_printloop()
1675 "The occurrence of a latency is detected by monitoring the file\n" in show_usage()
1680 "-l, --list\t\tList the latency tracers that are supported by the\n" in show_usage()
1685 "-t, --tracer TR\t\tUse the tracer TR. The default is to use the first\n" in show_usage()
1698 "-F, --force\t\tProceed even if another ftrace tracer is active. Without\n" in show_usage()
1702 "-s, --threshold TH\tConfigure ftrace to use a threshold of TH microseconds\n" in show_usage()
1708 "-f, --function\t\tEnable the function-trace option in trace_options. With\n" in show_usage()
1710 "\t\t\texecuted during a latency, without it we only get the\n" in show_usage()
1713 "-g, --graph\t\tEnable the display-graph option in trace_option. This\n" in show_usage()
1717 "-c, --policy POL\tRun the program with scheduling policy POL. POL can be\n" in show_usage()
1722 "-p, --priority PRI\tRun the program with priority PRI. The acceptable range\n" in show_usage()
1725 "-n, --notrace\t\tIf latency is detected, do not print out the content of\n" in show_usage()
1728 "-t, --threads NRTHR\tRun NRTHR threads for printing. Default is %d.\n\n" in show_usage()
1730 "-r, --random\t\tArbitrarily sleep a certain amount of time, default\n" in show_usage()
1739 "-a, --nrlat NRLAT\tFor the purpose of arbitrary delay, assume that there\n" in show_usage()
1744 "\t\t\timplies -r. We need to know this number in order to\n" in show_usage()
1748 "\t\t\t1/NRLAT 1/(NRLAT - 1) ... 1/3 1/2 1\n\n" in show_usage()
1750 "\t\t\t1 - P, where P is from the series above\n\n" in show_usage()
1751 "\t\t\tThis descending probability will cause us to choose\n" in show_usage()
1757 "\t\t\tThis means, when a latency is detected we will sleep\n" in show_usage()
1758 "\t\t\twith 50%% probability. If we ever detect another latency\n" in show_usage()
1763 "-v, --verbose\t\tIncrease the verbosity. If this option is given once,\n" in show_usage()
1770 "-u, --time TIME\t\tArbitrarily sleep for a specified time TIME ms before\n" in show_usage()
1772 "\t\t\tis %ld ms. This option implies -r.\n\n" in show_usage()
1774 "-x, --no-ftrace\t\tDo not configure ftrace. This assume that the user\n" in show_usage()
1778 "-i, --tracefile FILE\tUse FILE as trace file. The default is\n" in show_usage()
1780 "\t\t\tThis options implies -x\n\n" in show_usage()
1782 "-m, --max-lat FILE\tUse FILE as tracing_max_latency file. The default is\n" in show_usage()
1784 "\t\t\tThis options implies -x\n\n" in show_usage()
1846 { "no-ftrace", no_argument, 0, 'x' }, in scan_arguments()
1848 { "max-lat", required_argument, 0, 'm' }, in scan_arguments()
1865 if (c == -1) in scan_arguments()
1876 warnx("%s is not a known latency tracer!\n", in scan_arguments()
1890 check_alldigits(optarg, "-s [--threshold]"); in scan_arguments()
1902 sched_policy = p->policy; in scan_arguments()
1905 sched_pri = p->default_pri; in scan_arguments()
1915 check_alldigits(optarg, "-p [--priority]"); in scan_arguments()
1928 check_alldigits(optarg, "-e [--threads]"); in scan_arguments()
1939 check_alldigits(optarg, "-u [--time]"); in scan_arguments()
1958 check_alldigits(optarg, "-a [--nrlat]"); in scan_arguments()