Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'trace-tools-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace

Pull tracing tools updates from Steven Rostedt:

- Add ':' to getopt option 'trace-buffer-size' in timerlat_hist for
consistency

- Remove unused sched_getattr define

- Rename sched_setattr() helper to syscall_sched_setattr() to avoid
conflicts

- Update counters to long from int to avoid overflow

- Add libcpupower dependency detection

- Add --deepest-idle-state to timerlat to limit deep idle sleeps

- Other minor clean ups and documentation changes

* tag 'trace-tools-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace:
verification/dot2: Improve dot parser robustness
tools/rtla: Improve exception handling in timerlat_load.py
tools/rtla: Enhance argument parsing in timerlat_load.py
tools/rtla: Improve code readability in timerlat_load.py
rtla/timerlat: Do not set params->user_workload with -U
rtla: Documentation: Mention --deepest-idle-state
rtla/timerlat: Add --deepest-idle-state for hist
rtla/timerlat: Add --deepest-idle-state for top
rtla/utils: Add idle state disabling via libcpupower
rtla: Add optional dependency on libcpupower
tools/build: Add libcpupower dependency detection
rtla/timerlat: Make timerlat_hist_cpu->*_count unsigned long long
rtla/timerlat: Make timerlat_top_cpu->*_count unsigned long long
tools/rtla: fix collision with glibc sched_attr/sched_set_attr
tools/rtla: drop __NR_sched_getattr
rtla: Fix consistency in getopt_long for timerlat_hist
rv: Fix a typo
tools/rv: Correct the grammatical errors in the comments
tools/rv: Correct the grammatical errors in the comments
rtla: use the definition for stdout fd when calling isatty()

+361 -79
+8
Documentation/tools/rtla/common_timerlat_options.rst
··· 31 31 *cyclictest* sets this value to *0* by default, use **--dma-latency** *0* to have 32 32 similar results. 33 33 34 + **--deepest-idle-state** *n* 35 + Disable idle states higher than *n* for cpus that are running timerlat threads to 36 + reduce exit from idle latencies. If *n* is -1, all idle states are disabled. 37 + On exit from timerlat, the idle state setting is restored to its original state 38 + before running timerlat. 39 + 40 + Requires rtla to be built with libcpupower. 41 + 34 42 **-k**, **--kernel-threads** 35 43 36 44 Use timerlat kernel-space threads, in contrast of **-u**.
+1 -1
kernel/trace/rv/rv.c
··· 41 41 * per-task monitor, and so on), and the helper functions that glue the 42 42 * monitor to the system via trace. Generally, a monitor includes some form 43 43 * of trace output as a reaction for event parsing and exceptions, 44 - * as depicted bellow: 44 + * as depicted below: 45 45 * 46 46 * Linux +----- RV Monitor ----------------------------------+ Formal 47 47 * Realm | | Realm
+1
tools/build/Makefile.feature
··· 53 53 libslang-include-subdir \ 54 54 libtraceevent \ 55 55 libtracefs \ 56 + libcpupower \ 56 57 libcrypto \ 57 58 libunwind \ 58 59 pthread-attr-setaffinity-np \
+4
tools/build/feature/Makefile
··· 38 38 test-libslang.bin \ 39 39 test-libslang-include-subdir.bin \ 40 40 test-libtraceevent.bin \ 41 + test-libcpupower.bin \ 41 42 test-libtracefs.bin \ 42 43 test-libcrypto.bin \ 43 44 test-libunwind.bin \ ··· 248 247 249 248 $(OUTPUT)test-libtraceevent.bin: 250 249 $(BUILD) -ltraceevent 250 + 251 + $(OUTPUT)test-libcpupower.bin: 252 + $(BUILD) -lcpupower 251 253 252 254 $(OUTPUT)test-libtracefs.bin: 253 255 $(BUILD) $(shell $(PKG_CONFIG) --cflags libtracefs 2>/dev/null) -ltracefs
+8
tools/build/feature/test-libcpupower.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + #include <cpuidle.h> 3 + 4 + int main(void) 5 + { 6 + int rv = cpuidle_state_count(0); 7 + return rv; 8 + }
+2
tools/tracing/rtla/Makefile
··· 32 32 33 33 FEATURE_TESTS := libtraceevent 34 34 FEATURE_TESTS += libtracefs 35 + FEATURE_TESTS += libcpupower 35 36 FEATURE_DISPLAY := libtraceevent 36 37 FEATURE_DISPLAY += libtracefs 38 + FEATURE_DISPLAY += libcpupower 37 39 38 40 ifeq ($(V),1) 39 41 Q =
+10
tools/tracing/rtla/Makefile.config
··· 43 43 $(info libtracefs is missing. Please install libtracefs-dev/libtracefs-devel) 44 44 endif 45 45 46 + $(call feature_check,libcpupower) 47 + ifeq ($(feature-libcpupower), 1) 48 + $(call detected,CONFIG_LIBCPUPOWER) 49 + CFLAGS += -DHAVE_LIBCPUPOWER_SUPPORT 50 + EXTLIBS += -lcpupower 51 + else 52 + $(info libcpupower is missing, building without --deepest-idle-state support.) 53 + $(info Please install libcpupower-dev/kernel-tools-libs-devel) 54 + endif 55 + 46 56 ifeq ($(STOP_ERROR),1) 47 57 $(error Please, check the errors above.) 48 58 endif
+4
tools/tracing/rtla/README.txt
··· 11 11 12 12 - libtracefs 13 13 - libtraceevent 14 + - libcpupower (optional, for --deepest-idle-state) 14 15 15 16 It also depends on python3-docutils to compile man pages. 16 17 ··· 27 26 $ make 28 27 $ sudo make install 29 28 $ cd .. 29 + $ cd $libcpupower_src 30 + $ make 31 + $ sudo make install 30 32 $ cd $rtla_src 31 33 $ make 32 34 $ sudo make install
+30 -26
tools/tracing/rtla/sample/timerlat_load.py
··· 25 25 import os 26 26 27 27 parser = argparse.ArgumentParser(description='user-space timerlat thread in Python') 28 - parser.add_argument("cpu", help='CPU to run timerlat thread') 29 - parser.add_argument("-p", "--prio", help='FIFO priority') 30 - 28 + parser.add_argument("cpu", type=int, help='CPU to run timerlat thread') 29 + parser.add_argument("-p", "--prio", type=int, help='FIFO priority') 31 30 args = parser.parse_args() 32 31 33 32 try: 34 - affinity_mask = { int(args.cpu) } 35 - except: 36 - print("Invalid cpu: " + args.cpu) 37 - exit(1) 33 + affinity_mask = {args.cpu} 34 + os.sched_setaffinity(0, affinity_mask) 35 + except Exception as e: 36 + print(f"Error setting affinity: {e}") 37 + sys.exit(1) 38 38 39 - try: 40 - os.sched_setaffinity(0, affinity_mask); 41 - except: 42 - print("Error setting affinity") 43 - exit(1) 44 - 45 - if (args.prio): 39 + if args.prio: 46 40 try: 47 - param = os.sched_param(int(args.prio)) 41 + param = os.sched_param(args.prio) 48 42 os.sched_setscheduler(0, os.SCHED_FIFO, param) 49 - except: 50 - print("Error setting priority") 51 - exit(1) 43 + except Exception as e: 44 + print(f"Error setting priority: {e}") 45 + sys.exit(1) 52 46 53 47 try: 54 - timerlat_path = "/sys/kernel/tracing/osnoise/per_cpu/cpu" + args.cpu + "/timerlat_fd" 48 + timerlat_path = f"/sys/kernel/tracing/osnoise/per_cpu/cpu{args.cpu}/timerlat_fd" 55 49 timerlat_fd = open(timerlat_path, 'r') 56 - except: 50 + except PermissionError: 51 + print("Permission denied. Please check your access rights.") 52 + sys.exit(1) 53 + except OSError: 57 54 print("Error opening timerlat fd, did you run timerlat -U?") 58 - exit(1) 55 + sys.exit(1) 59 56 60 57 try: 61 - data_fd = open("/dev/full", 'r'); 62 - except: 63 - print("Error opening data fd") 58 + data_fd = open("/dev/full", 'r') 59 + except Exception as e: 60 + print(f"Error opening data fd: {e}") 61 + sys.exit(1) 64 62 65 63 while True: 66 64 try: 67 65 timerlat_fd.read(1) 68 - data_fd.read(20*1024*1024) 69 - except: 66 + data_fd.read(20 * 1024 * 1024) 67 + except KeyboardInterrupt: 70 68 print("Leaving") 69 + break 70 + except IOError as e: 71 + print(f"I/O error occurred: {e}") 72 + break 73 + except Exception as e: 74 + print(f"Unexpected error: {e}") 71 75 break 72 76 73 77 timerlat_fd.close()
+1 -1
tools/tracing/rtla/src/osnoise_top.c
··· 627 627 auto_house_keeping(&params->monitored_cpus); 628 628 } 629 629 630 - if (isatty(1) && !params->quiet) 630 + if (isatty(STDOUT_FILENO) && !params->quiet) 631 631 params->pretty_output = 1; 632 632 633 633 return 0;
+52 -12
tools/tracing/rtla/src/timerlat_hist.c
··· 55 55 int entries; 56 56 int warmup; 57 57 int buffer_size; 58 + int deepest_idle_state; 58 59 }; 59 60 60 61 struct timerlat_hist_cpu { ··· 63 62 int *thread; 64 63 int *user; 65 64 66 - int irq_count; 67 - int thread_count; 68 - int user_count; 65 + unsigned long long irq_count; 66 + unsigned long long thread_count; 67 + unsigned long long user_count; 69 68 70 69 unsigned long long min_irq; 71 70 unsigned long long sum_irq; ··· 305 304 continue; 306 305 307 306 if (!params->no_irq) 308 - trace_seq_printf(trace->seq, "%9d ", 307 + trace_seq_printf(trace->seq, "%9llu ", 309 308 data->hist[cpu].irq_count); 310 309 311 310 if (!params->no_thread) 312 - trace_seq_printf(trace->seq, "%9d ", 311 + trace_seq_printf(trace->seq, "%9llu ", 313 312 data->hist[cpu].thread_count); 314 313 315 314 if (params->user_hist) 316 - trace_seq_printf(trace->seq, "%9d ", 315 + trace_seq_printf(trace->seq, "%9llu ", 317 316 data->hist[cpu].user_count); 318 317 } 319 318 trace_seq_printf(trace->seq, "\n"); ··· 489 488 trace_seq_printf(trace->seq, "count:"); 490 489 491 490 if (!params->no_irq) 492 - trace_seq_printf(trace->seq, "%9d ", 491 + trace_seq_printf(trace->seq, "%9llu ", 493 492 sum.irq_count); 494 493 495 494 if (!params->no_thread) 496 - trace_seq_printf(trace->seq, "%9d ", 495 + trace_seq_printf(trace->seq, "%9llu ", 497 496 sum.thread_count); 498 497 499 498 if (params->user_hist) 500 - trace_seq_printf(trace->seq, "%9d ", 499 + trace_seq_printf(trace->seq, "%9llu ", 501 500 sum.user_count); 502 501 503 502 trace_seq_printf(trace->seq, "\n"); ··· 656 655 " [-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\", 657 656 " [-P priority] [-E N] [-b N] [--no-irq] [--no-thread] [--no-header] [--no-summary] \\", 658 657 " [--no-index] [--with-zeros] [--dma-latency us] [-C[=cgroup_name]] [--no-aa] [--dump-task] [-u|-k]", 659 - " [--warm-up s]", 658 + " [--warm-up s] [--deepest-idle-state n]", 660 659 "", 661 660 " -h/--help: print this menu", 662 661 " -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit", ··· 696 695 " -U/--user-load: enable timerlat for user-defined user-space workload", 697 696 " --warm-up s: let the workload run for s seconds before collecting data", 698 697 " --trace-buffer-size kB: set the per-cpu trace buffer size in kB", 698 + " --deepest-idle-state n: only go down to idle state n on cpus used by timerlat to reduce exit from idle latency", 699 699 NULL, 700 700 }; 701 701 ··· 733 731 734 732 /* disabled by default */ 735 733 params->dma_latency = -1; 734 + 735 + /* disabled by default */ 736 + params->deepest_idle_state = -2; 736 737 737 738 /* display data in microseconds */ 738 739 params->output_divisor = 1000; ··· 777 772 {"dump-task", no_argument, 0, '\1'}, 778 773 {"warm-up", required_argument, 0, '\2'}, 779 774 {"trace-buffer-size", required_argument, 0, '\3'}, 775 + {"deepest-idle-state", required_argument, 0, '\4'}, 780 776 {0, 0, 0, 0} 781 777 }; 782 778 783 779 /* getopt_long stores the option index here. */ 784 780 int option_index = 0; 785 781 786 - c = getopt_long(argc, argv, "a:c:C::b:d:e:E:DhH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3", 782 + c = getopt_long(argc, argv, "a:c:C::b:d:e:E:DhH:i:knp:P:s:t::T:uU0123456:7:8:9\1\2:\3:", 787 783 long_options, &option_index); 788 784 789 785 /* detect the end of the options. */ ··· 966 960 case '\3': 967 961 params->buffer_size = get_llong_from_str(optarg); 968 962 break; 963 + case '\4': 964 + params->deepest_idle_state = get_llong_from_str(optarg); 965 + break; 969 966 default: 970 967 timerlat_hist_usage("Invalid option"); 971 968 } ··· 1073 1064 * If the user did not specify a type of thread, try user-threads first. 1074 1065 * Fall back to kernel threads otherwise. 1075 1066 */ 1076 - if (!params->kernel_workload && !params->user_workload) { 1067 + if (!params->kernel_workload && !params->user_hist) { 1077 1068 retval = tracefs_file_exists(NULL, "osnoise/per_cpu/cpu0/timerlat_fd"); 1078 1069 if (retval) { 1079 1070 debug_msg("User-space interface detected, setting user-threads\n"); ··· 1161 1152 int return_value = 1; 1162 1153 pthread_t timerlat_u; 1163 1154 int retval; 1155 + int nr_cpus, i; 1164 1156 1165 1157 params = timerlat_hist_parse_args(argc, argv); 1166 1158 if (!params) ··· 1208 1198 if (dma_latency_fd < 0) { 1209 1199 err_msg("Could not set /dev/cpu_dma_latency.\n"); 1210 1200 goto out_free; 1201 + } 1202 + } 1203 + 1204 + if (params->deepest_idle_state >= -1) { 1205 + if (!have_libcpupower_support()) { 1206 + err_msg("rtla built without libcpupower, --deepest-idle-state is not supported\n"); 1207 + goto out_free; 1208 + } 1209 + 1210 + nr_cpus = sysconf(_SC_NPROCESSORS_CONF); 1211 + 1212 + for (i = 0; i < nr_cpus; i++) { 1213 + if (params->cpus && !CPU_ISSET(i, &params->monitored_cpus)) 1214 + continue; 1215 + if (save_cpu_idle_disable_state(i) < 0) { 1216 + err_msg("Could not save cpu idle state.\n"); 1217 + goto out_free; 1218 + } 1219 + if (set_deepest_cpu_idle_state(i, params->deepest_idle_state) < 0) { 1220 + err_msg("Could not set deepest cpu idle state.\n"); 1221 + goto out_free; 1222 + } 1211 1223 } 1212 1224 } 1213 1225 ··· 1364 1332 timerlat_aa_destroy(); 1365 1333 if (dma_latency_fd >= 0) 1366 1334 close(dma_latency_fd); 1335 + if (params->deepest_idle_state >= -1) { 1336 + for (i = 0; i < nr_cpus; i++) { 1337 + if (params->cpus && !CPU_ISSET(i, &params->monitored_cpus)) 1338 + continue; 1339 + restore_cpu_idle_disable_state(i); 1340 + } 1341 + } 1367 1342 trace_events_destroy(&record->trace, params->events); 1368 1343 params->events = NULL; 1369 1344 out_free: ··· 1379 1340 osnoise_destroy_tool(record); 1380 1341 osnoise_destroy_tool(tool); 1381 1342 free(params); 1343 + free_cpu_idle_disable_states(); 1382 1344 out_exit: 1383 1345 exit(return_value); 1384 1346 }
+47 -7
tools/tracing/rtla/src/timerlat_top.c
··· 48 48 int pretty_output; 49 49 int warmup; 50 50 int buffer_size; 51 + int deepest_idle_state; 51 52 cpu_set_t hk_cpu_set; 52 53 struct sched_attr sched_param; 53 54 struct trace_events *events; 54 55 }; 55 56 56 57 struct timerlat_top_cpu { 57 - int irq_count; 58 - int thread_count; 59 - int user_count; 58 + unsigned long long irq_count; 59 + unsigned long long thread_count; 60 + unsigned long long user_count; 60 61 61 62 unsigned long long cur_irq; 62 63 unsigned long long min_irq; ··· 281 280 /* 282 281 * Unless trace is being lost, IRQ counter is always the max. 283 282 */ 284 - trace_seq_printf(s, "%3d #%-9d |", cpu, cpu_data->irq_count); 283 + trace_seq_printf(s, "%3d #%-9llu |", cpu, cpu_data->irq_count); 285 284 286 285 if (!cpu_data->irq_count) { 287 286 trace_seq_printf(s, "%s %s %s %s |", no_value, no_value, no_value, no_value); ··· 448 447 "", 449 448 " usage: rtla timerlat [top] [-h] [-q] [-a us] [-d s] [-D] [-n] [-p us] [-i us] [-T us] [-s us] \\", 450 449 " [[-t[file]] [-e sys[:event]] [--filter <filter>] [--trigger <trigger>] [-c cpu-list] [-H cpu-list]\\", 451 - " [-P priority] [--dma-latency us] [--aa-only us] [-C[=cgroup_name]] [-u|-k] [--warm-up s]", 450 + " [-P priority] [--dma-latency us] [--aa-only us] [-C[=cgroup_name]] [-u|-k] [--warm-up s] [--deepest-idle-state n]", 452 451 "", 453 452 " -h/--help: print this menu", 454 453 " -a/--auto: set automatic trace mode, stopping the session if argument in us latency is hit", ··· 482 481 " -U/--user-load: enable timerlat for user-defined user-space workload", 483 482 " --warm-up s: let the workload run for s seconds before collecting data", 484 483 " --trace-buffer-size kB: set the per-cpu trace buffer size in kB", 484 + " --deepest-idle-state n: only go down to idle state n on cpus used by timerlat to reduce exit from idle latency", 485 485 NULL, 486 486 }; 487 487 ··· 520 518 /* disabled by default */ 521 519 params->dma_latency = -1; 522 520 521 + /* disabled by default */ 522 + params->deepest_idle_state = -2; 523 + 523 524 /* display data in microseconds */ 524 525 params->output_divisor = 1000; 525 526 ··· 555 550 {"aa-only", required_argument, 0, '5'}, 556 551 {"warm-up", required_argument, 0, '6'}, 557 552 {"trace-buffer-size", required_argument, 0, '7'}, 553 + {"deepest-idle-state", required_argument, 0, '8'}, 558 554 {0, 0, 0, 0} 559 555 }; 560 556 ··· 732 726 case '7': 733 727 params->buffer_size = get_llong_from_str(optarg); 734 728 break; 729 + case '8': 730 + params->deepest_idle_state = get_llong_from_str(optarg); 731 + break; 735 732 default: 736 733 timerlat_top_usage("Invalid option"); 737 734 } ··· 839 830 * If the user did not specify a type of thread, try user-threads first. 840 831 * Fall back to kernel threads otherwise. 841 832 */ 842 - if (!params->kernel_workload && !params->user_workload) { 833 + if (!params->kernel_workload && !params->user_top) { 843 834 retval = tracefs_file_exists(NULL, "osnoise/per_cpu/cpu0/timerlat_fd"); 844 835 if (retval) { 845 836 debug_msg("User-space interface detected, setting user-threads\n"); ··· 859 850 } 860 851 } 861 852 862 - if (isatty(1) && !params->quiet) 853 + if (isatty(STDOUT_FILENO) && !params->quiet) 863 854 params->pretty_output = 1; 864 855 865 856 return 0; ··· 931 922 int return_value = 1; 932 923 char *max_lat; 933 924 int retval; 925 + int nr_cpus, i; 934 926 935 927 params = timerlat_top_parse_args(argc, argv); 936 928 if (!params) ··· 978 968 if (dma_latency_fd < 0) { 979 969 err_msg("Could not set /dev/cpu_dma_latency.\n"); 980 970 goto out_free; 971 + } 972 + } 973 + 974 + if (params->deepest_idle_state >= -1) { 975 + if (!have_libcpupower_support()) { 976 + err_msg("rtla built without libcpupower, --deepest-idle-state is not supported\n"); 977 + goto out_free; 978 + } 979 + 980 + nr_cpus = sysconf(_SC_NPROCESSORS_CONF); 981 + 982 + for (i = 0; i < nr_cpus; i++) { 983 + if (params->cpus && !CPU_ISSET(i, &params->monitored_cpus)) 984 + continue; 985 + if (save_cpu_idle_disable_state(i) < 0) { 986 + err_msg("Could not save cpu idle state.\n"); 987 + goto out_free; 988 + } 989 + if (set_deepest_cpu_idle_state(i, params->deepest_idle_state) < 0) { 990 + err_msg("Could not set deepest cpu idle state.\n"); 991 + goto out_free; 992 + } 981 993 } 982 994 } 983 995 ··· 1157 1125 timerlat_aa_destroy(); 1158 1126 if (dma_latency_fd >= 0) 1159 1127 close(dma_latency_fd); 1128 + if (params->deepest_idle_state >= -1) { 1129 + for (i = 0; i < nr_cpus; i++) { 1130 + if (params->cpus && !CPU_ISSET(i, &params->monitored_cpus)) 1131 + continue; 1132 + restore_cpu_idle_disable_state(i); 1133 + } 1134 + } 1160 1135 trace_events_destroy(&record->trace, params->events); 1161 1136 params->events = NULL; 1162 1137 out_free: ··· 1173 1134 osnoise_destroy_tool(record); 1174 1135 osnoise_destroy_tool(top); 1175 1136 free(params); 1137 + free_cpu_idle_disable_states(); 1176 1138 out_exit: 1177 1139 exit(return_value); 1178 1140 }
+166 -20
tools/tracing/rtla/src/utils.c
··· 4 4 */ 5 5 6 6 #define _GNU_SOURCE 7 + #ifdef HAVE_LIBCPUPOWER_SUPPORT 8 + #include <cpuidle.h> 9 + #endif /* HAVE_LIBCPUPOWER_SUPPORT */ 7 10 #include <dirent.h> 8 11 #include <stdarg.h> 9 12 #include <stdlib.h> ··· 214 211 /* 215 212 * This is a set of helper functions to use SCHED_DEADLINE. 216 213 */ 217 - #ifdef __x86_64__ 218 - # define __NR_sched_setattr 314 219 - # define __NR_sched_getattr 315 220 - #elif __i386__ 221 - # define __NR_sched_setattr 351 222 - # define __NR_sched_getattr 352 223 - #elif __arm__ 224 - # define __NR_sched_setattr 380 225 - # define __NR_sched_getattr 381 226 - #elif __aarch64__ || __riscv 227 - # define __NR_sched_setattr 274 228 - # define __NR_sched_getattr 275 229 - #elif __powerpc__ 230 - # define __NR_sched_setattr 355 231 - # define __NR_sched_getattr 356 232 - #elif __s390x__ 233 - # define __NR_sched_setattr 345 234 - # define __NR_sched_getattr 346 214 + #ifndef __NR_sched_setattr 215 + # ifdef __x86_64__ 216 + # define __NR_sched_setattr 314 217 + # elif __i386__ 218 + # define __NR_sched_setattr 351 219 + # elif __arm__ 220 + # define __NR_sched_setattr 380 221 + # elif __aarch64__ || __riscv 222 + # define __NR_sched_setattr 274 223 + # elif __powerpc__ 224 + # define __NR_sched_setattr 355 225 + # elif __s390x__ 226 + # define __NR_sched_setattr 345 227 + # endif 235 228 #endif 236 229 237 230 #define SCHED_DEADLINE 6 238 231 239 - static inline int sched_setattr(pid_t pid, const struct sched_attr *attr, 232 + static inline int syscall_sched_setattr(pid_t pid, const struct sched_attr *attr, 240 233 unsigned int flags) { 241 234 return syscall(__NR_sched_setattr, pid, attr, flags); 242 235 } ··· 242 243 int flags = 0; 243 244 int retval; 244 245 245 - retval = sched_setattr(pid, attr, flags); 246 + retval = syscall_sched_setattr(pid, attr, flags); 246 247 if (retval < 0) { 247 248 err_msg("Failed to set sched attributes to the pid %d: %s\n", 248 249 pid, strerror(errno)); ··· 517 518 518 519 return fd; 519 520 } 521 + 522 + #ifdef HAVE_LIBCPUPOWER_SUPPORT 523 + static unsigned int **saved_cpu_idle_disable_state; 524 + static size_t saved_cpu_idle_disable_state_alloc_ctr; 525 + 526 + /* 527 + * save_cpu_idle_state_disable - save disable for all idle states of a cpu 528 + * 529 + * Saves the current disable of all idle states of a cpu, to be subsequently 530 + * restored via restore_cpu_idle_disable_state. 531 + * 532 + * Return: idle state count on success, negative on error 533 + */ 534 + int save_cpu_idle_disable_state(unsigned int cpu) 535 + { 536 + unsigned int nr_states; 537 + unsigned int state; 538 + int disabled; 539 + int nr_cpus; 540 + 541 + nr_states = cpuidle_state_count(cpu); 542 + 543 + if (nr_states == 0) 544 + return 0; 545 + 546 + if (saved_cpu_idle_disable_state == NULL) { 547 + nr_cpus = sysconf(_SC_NPROCESSORS_CONF); 548 + saved_cpu_idle_disable_state = calloc(nr_cpus, sizeof(unsigned int *)); 549 + if (!saved_cpu_idle_disable_state) 550 + return -1; 551 + } 552 + 553 + saved_cpu_idle_disable_state[cpu] = calloc(nr_states, sizeof(unsigned int)); 554 + if (!saved_cpu_idle_disable_state[cpu]) 555 + return -1; 556 + saved_cpu_idle_disable_state_alloc_ctr++; 557 + 558 + for (state = 0; state < nr_states; state++) { 559 + disabled = cpuidle_is_state_disabled(cpu, state); 560 + if (disabled < 0) 561 + return disabled; 562 + saved_cpu_idle_disable_state[cpu][state] = disabled; 563 + } 564 + 565 + return nr_states; 566 + } 567 + 568 + /* 569 + * restore_cpu_idle_disable_state - restore disable for all idle states of a cpu 570 + * 571 + * Restores the current disable state of all idle states of a cpu that was 572 + * previously saved by save_cpu_idle_disable_state. 573 + * 574 + * Return: idle state count on success, negative on error 575 + */ 576 + int restore_cpu_idle_disable_state(unsigned int cpu) 577 + { 578 + unsigned int nr_states; 579 + unsigned int state; 580 + int disabled; 581 + int result; 582 + 583 + nr_states = cpuidle_state_count(cpu); 584 + 585 + if (nr_states == 0) 586 + return 0; 587 + 588 + if (!saved_cpu_idle_disable_state) 589 + return -1; 590 + 591 + for (state = 0; state < nr_states; state++) { 592 + if (!saved_cpu_idle_disable_state[cpu]) 593 + return -1; 594 + disabled = saved_cpu_idle_disable_state[cpu][state]; 595 + result = cpuidle_state_disable(cpu, state, disabled); 596 + if (result < 0) 597 + return result; 598 + } 599 + 600 + free(saved_cpu_idle_disable_state[cpu]); 601 + saved_cpu_idle_disable_state[cpu] = NULL; 602 + saved_cpu_idle_disable_state_alloc_ctr--; 603 + if (saved_cpu_idle_disable_state_alloc_ctr == 0) { 604 + free(saved_cpu_idle_disable_state); 605 + saved_cpu_idle_disable_state = NULL; 606 + } 607 + 608 + return nr_states; 609 + } 610 + 611 + /* 612 + * free_cpu_idle_disable_states - free saved idle state disable for all cpus 613 + * 614 + * Frees the memory used for storing cpu idle state disable for all cpus 615 + * and states. 616 + * 617 + * Normally, the memory is freed automatically in 618 + * restore_cpu_idle_disable_state; this is mostly for cleaning up after an 619 + * error. 620 + */ 621 + void free_cpu_idle_disable_states(void) 622 + { 623 + int cpu; 624 + int nr_cpus; 625 + 626 + if (!saved_cpu_idle_disable_state) 627 + return; 628 + 629 + nr_cpus = sysconf(_SC_NPROCESSORS_CONF); 630 + 631 + for (cpu = 0; cpu < nr_cpus; cpu++) { 632 + free(saved_cpu_idle_disable_state[cpu]); 633 + saved_cpu_idle_disable_state[cpu] = NULL; 634 + } 635 + 636 + free(saved_cpu_idle_disable_state); 637 + saved_cpu_idle_disable_state = NULL; 638 + } 639 + 640 + /* 641 + * set_deepest_cpu_idle_state - limit idle state of cpu 642 + * 643 + * Disables all idle states deeper than the one given in 644 + * deepest_state (assuming states with higher number are deeper). 645 + * 646 + * This is used to reduce the exit from idle latency. Unlike 647 + * set_cpu_dma_latency, it can disable idle states per cpu. 648 + * 649 + * Return: idle state count on success, negative on error 650 + */ 651 + int set_deepest_cpu_idle_state(unsigned int cpu, unsigned int deepest_state) 652 + { 653 + unsigned int nr_states; 654 + unsigned int state; 655 + int result; 656 + 657 + nr_states = cpuidle_state_count(cpu); 658 + 659 + for (state = deepest_state + 1; state < nr_states; state++) { 660 + result = cpuidle_state_disable(cpu, state, 1); 661 + if (result < 0) 662 + return result; 663 + } 664 + 665 + return nr_states; 666 + } 667 + #endif /* HAVE_LIBCPUPOWER_SUPPORT */ 520 668 521 669 #define _STR(x) #x 522 670 #define STR(x) _STR(x)
+15
tools/tracing/rtla/src/utils.h
··· 46 46 *a += *b; 47 47 } 48 48 49 + #ifndef SCHED_ATTR_SIZE_VER0 49 50 struct sched_attr { 50 51 uint32_t size; 51 52 uint32_t sched_policy; ··· 57 56 uint64_t sched_deadline; 58 57 uint64_t sched_period; 59 58 }; 59 + #endif /* SCHED_ATTR_SIZE_VER0 */ 60 60 61 61 int parse_prio(char *arg, struct sched_attr *sched_param); 62 62 int parse_cpu_set(char *cpu_list, cpu_set_t *set); ··· 66 64 int set_comm_cgroup(const char *comm_prefix, const char *cgroup); 67 65 int set_pid_cgroup(pid_t pid, const char *cgroup); 68 66 int set_cpu_dma_latency(int32_t latency); 67 + #ifdef HAVE_LIBCPUPOWER_SUPPORT 68 + int save_cpu_idle_disable_state(unsigned int cpu); 69 + int restore_cpu_idle_disable_state(unsigned int cpu); 70 + void free_cpu_idle_disable_states(void); 71 + int set_deepest_cpu_idle_state(unsigned int cpu, unsigned int state); 72 + static inline int have_libcpupower_support(void) { return 1; } 73 + #else 74 + static inline int save_cpu_idle_disable_state(unsigned int cpu) { return -1; } 75 + static inline int restore_cpu_idle_disable_state(unsigned int cpu) { return -1; } 76 + static inline void free_cpu_idle_disable_states(void) { } 77 + static inline int set_deepest_cpu_idle_state(unsigned int cpu, unsigned int state) { return -1; } 78 + static inline int have_libcpupower_support(void) { return 0; } 79 + #endif /* HAVE_LIBCPUPOWER_SUPPORT */ 69 80 int auto_house_keeping(cpu_set_t *monitored_cpus); 70 81 71 82 #define ns_to_usf(x) (((double)x/1000))
+9 -9
tools/verification/dot2/automata.py
··· 29 29 30 30 def __get_model_name(self): 31 31 basename = ntpath.basename(self.__dot_path) 32 - if basename.endswith(".dot") == False: 32 + if not basename.endswith(".dot") and not basename.endswith(".gv"): 33 33 print("not a dot file") 34 34 raise Exception("not a dot file: %s" % self.__dot_path) 35 35 36 - model_name = basename[0:-4] 36 + model_name = ntpath.splitext(basename)[0] 37 37 if model_name.__len__() == 0: 38 38 raise Exception("not a dot file: %s" % self.__dot_path) 39 39 ··· 68 68 def __get_cursor_begin_events(self): 69 69 cursor = 0 70 70 while self.__dot_lines[cursor].split()[0] != "{node": 71 - cursor += 1 71 + cursor += 1 72 72 while self.__dot_lines[cursor].split()[0] == "{node": 73 - cursor += 1 73 + cursor += 1 74 74 # skip initial state transition 75 75 cursor += 1 76 76 return cursor ··· 94 94 initial_state = state[7:] 95 95 else: 96 96 states.append(state) 97 - if self.__dot_lines[cursor].__contains__("doublecircle") == True: 97 + if "doublecircle" in self.__dot_lines[cursor]: 98 98 final_states.append(state) 99 99 has_final_states = True 100 100 101 - if self.__dot_lines[cursor].__contains__("ellipse") == True: 101 + if "ellipse" in self.__dot_lines[cursor]: 102 102 final_states.append(state) 103 103 has_final_states = True 104 104 ··· 110 110 # Insert the initial state at the bein og the states 111 111 states.insert(0, initial_state) 112 112 113 - if has_final_states == False: 113 + if not has_final_states: 114 114 final_states.append(initial_state) 115 115 116 116 return states, initial_state, final_states ··· 120 120 cursor = self.__get_cursor_begin_events() 121 121 122 122 events = [] 123 - while self.__dot_lines[cursor][1] == '"': 123 + while self.__dot_lines[cursor].lstrip()[0] == '"': 124 124 # transitions have the format: 125 125 # "all_fired" -> "both_fired" [ label = "disable_irq" ]; 126 126 # ------------ event is here ------------^^^^^ ··· 161 161 # and we are back! Let's fill the matrix 162 162 cursor = self.__get_cursor_begin_events() 163 163 164 - while self.__dot_lines[cursor][1] == '"': 164 + while self.__dot_lines[cursor].lstrip()[0] == '"': 165 165 if self.__dot_lines[cursor].split()[1] == "->": 166 166 line = self.__dot_lines[cursor].split() 167 167 origin_state = line[0].replace('"','').replace(',','_')
+2 -2
tools/verification/rv/src/in_kernel.c
··· 332 332 * ikm_event_handler - callback to handle event events 333 333 * 334 334 * Called any time a rv:"monitor"_event events is generated. 335 - * It parses and print event. 335 + * It parses and prints event. 336 336 */ 337 337 static int 338 338 ikm_event_handler(struct trace_seq *s, struct tep_record *record, ··· 384 384 * ikm_error_handler - callback to handle error events 385 385 * 386 386 * Called any time a rv:"monitor"_errors events is generated. 387 - * It parses and print event. 387 + * It parses and prints event. 388 388 */ 389 389 static int 390 390 ikm_error_handler(struct trace_seq *s, struct tep_record *record,
+1 -1
tools/verification/rv/src/trace.c
··· 81 81 } 82 82 83 83 /** 84 - * trace_instance_init - create an trace instance 84 + * trace_instance_init - create a trace instance 85 85 * 86 86 * It is more than the tracefs instance, as it contains other 87 87 * things required for the tracing, such as the local events and