diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2021-06-21 14:29:53 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2021-06-21 14:29:53 +0000 |
commit | e15efde51ecf8fe38d24f53c2cd7e129c2aa9121 (patch) | |
tree | 8244c63404e59d5a776e6371701ca88a919bab37 | |
parent | 4273e3bca33cf3fa696512945c85033862f3856a (diff) | |
parent | 35a9eddaa4c2c88205b1a1ac9e163bbb12e76455 (diff) | |
download | ltp-android12-mainline-documentsui-release.tar.gz |
Snap for 7478028 from 35a9eddaa4c2c88205b1a1ac9e163bbb12e76455 to mainline-documentsui-releaseandroid-mainline-12.0.0_r26android-mainline-12.0.0_r2aml_doc_310851020android12-mainline-documentsui-release
Change-Id: I99612326bf564bf7f4c8ca1ab7ff33c2ef72fdda
27 files changed, 331 insertions, 166 deletions
diff --git a/Android.bp b/Android.bp index 8b7f2e75c..03821b6c9 100644 --- a/Android.bp +++ b/Android.bp @@ -15,13 +15,63 @@ // // Include the generated rules +// *** THIS PACKAGE HAS SPECIAL LICENSING CONDITIONS. PLEASE +// CONSULT THE OWNERS AND opensource-licensing@google.com BEFORE +// DEPENDING ON IT IN YOUR PROJECT. *** +package { + default_applicable_licenses: ["external_ltp_license"], +} + +// Added automatically by a large-scale-change that took the approach of +// 'apply every license found to every target'. While this makes sure we respect +// every license restriction, it may not be entirely correct. +// +// e.g. GPL in an MIT project might only apply to the contrib/ directory. +// +// Please consider splitting the single license below into multiple licenses, +// taking care not to lose any license_kind information, and overriding the +// default license using the 'licenses: [...]' property on targets as needed. +// +// For unused files, consider creating a 'fileGroup' with "//visibility:private" +// to attach the license to, and including a comment whether the files may be +// used in the current project. +// +// large-scale-change included anything that looked like it might be a license +// text as a license_text. e.g. LICENSE, NOTICE, COPYING etc. +// +// Please consider removing redundant or irrelevant files from 'license_text:'. +// See: http://go/android-license-faq +license { + name: "external_ltp_license", + visibility: [":__subpackages__"], + license_kinds: [ + "SPDX-license-identifier-APSL-1.1", + "SPDX-license-identifier-Apache-2.0", + "SPDX-license-identifier-BSD", + "SPDX-license-identifier-BSD-2-Clause", + "SPDX-license-identifier-BSD-3-Clause", + "SPDX-license-identifier-GFDL", // by exception only + "SPDX-license-identifier-GPL", + "SPDX-license-identifier-GPL-2.0", + "SPDX-license-identifier-GPL-3.0", + "SPDX-license-identifier-ISC", + "SPDX-license-identifier-LGPL", + ], + license_text: [ + "COPYING", + "NOTICE", + ], +} + build = ["gen.bp"] genrule { name: "ltp_syscalls_h", - tool_files: ["include/lapi/syscalls/regen.sh"], + tool_files: [ + "include/lapi/syscalls/regen.sh", + "include/lapi/syscalls/*.in", + ], cmd: "$(location) $(genDir)/lapi/syscalls.h", - srcs: ["include/lapi/syscalls/*.in"], out: ["lapi/syscalls.h"], } diff --git a/METADATA b/METADATA new file mode 100644 index 000000000..d15c65dcc --- /dev/null +++ b/METADATA @@ -0,0 +1,8 @@ +# *** THIS PACKAGE HAS SPECIAL LICENSING CONDITIONS. PLEASE +# CONSULT THE OWNERS AND opensource-licensing@google.com BEFORE +# DEPENDING ON IT IN YOUR PROJECT. *** +third_party { + # would be RESTRICTED save for GFDL in: + # testcases/kernel/device-drivers/v4l/user_space/doc/spec/*.htm* + license_type: BY_EXCEPTION_ONLY +} diff --git a/android/Android.mk b/android/Android.mk index 8db2c0370..c627356b7 100644 --- a/android/Android.mk +++ b/android/Android.mk @@ -23,6 +23,9 @@ ltp_build_prebuilt := include $(CLEAR_VARS) LOCAL_MODULE := ltp +LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-GPL-2.0 +LOCAL_LICENSE_CONDITIONS := notice restricted +LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../COPYING $(LOCAL_PATH)/../NOTICE LOCAL_MODULE_STEM := disabled_tests.txt LOCAL_PREBUILT_MODULE_FILE := $(LOCAL_PATH)/tools/disabled_tests.txt LOCAL_MODULE_RELATIVE_PATH := ltp diff --git a/android/Android.prebuilt.mk b/android/Android.prebuilt.mk index 2fb5daa3c..5fa2e4b58 100644 --- a/android/Android.prebuilt.mk +++ b/android/Android.prebuilt.mk @@ -18,6 +18,9 @@ module_stem := $(notdir $(module_prebuilt)) module_path := $(patsubst %/,%,$(dir $(module_prebuilt))) LOCAL_MODULE := $(module_name) +LOCAL_LICENSE_KINDS := SPDX-license-identifier-Apache-2.0 SPDX-license-identifier-GPL-2.0 +LOCAL_LICENSE_CONDITIONS := notice restricted +LOCAL_NOTICE_FILE := $(LOCAL_PATH)/../COPYING $(LOCAL_PATH)/../NOTICE LOCAL_INSTALLED_MODULE_STEM := $(module_stem) LOCAL_PREBUILT_MODULE_FILE := $(local_ltp_root)/$(module_src_files) LOCAL_MODULE_RELATIVE_PATH := ltp/$(module_path) diff --git a/android/include/config.h b/android/include/config.h index 49a64e3e4..bb216469e 100644 --- a/android/include/config.h +++ b/android/include/config.h @@ -262,7 +262,7 @@ #define HAVE_PIDFD_OPEN 1 /* Define to 1 if you have the `pidfd_send_signal' function. */ -/* #undef HAVE_PIDFD_SEND_SIGNAL */ +#define HAVE_PIDFD_SEND_SIGNAL 1 /* Define to 1 if you have the `pkey_mprotect' function. */ /* #undef HAVE_PKEY_MPROTECT */ diff --git a/include/tst_cpu.h b/include/tst_cpu.h index 1aacf8593..2e21384f9 100644 --- a/include/tst_cpu.h +++ b/include/tst_cpu.h @@ -22,8 +22,10 @@ long tst_ncpus(void); long tst_ncpus_conf(void); long tst_ncpus_max(void); +#define VIRT_ANY 0 /* catch-all argument for tst_is_virt() */ #define VIRT_XEN 1 /* xen dom0/domU */ #define VIRT_KVM 2 /* only default virtual CPU */ +#define VIRT_OTHER 0xffff /* unrecognized hypervisor */ int tst_is_virt(int virt_type); diff --git a/lib/tst_timer_test.c b/lib/tst_timer_test.c index 13e9deff2..196c51272 100644 --- a/lib/tst_timer_test.c +++ b/lib/tst_timer_test.c @@ -26,6 +26,7 @@ static long long *samples; static unsigned int cur_sample; static unsigned int monotonic_resolution; static unsigned int timerslack; +static int virt_env; static char *print_frequency_plot; static char *file_name; @@ -306,7 +307,10 @@ void do_timer_test(long long usec, unsigned int nsamples) samples[nsamples-1], samples[0], median, 1.00 * trunc_mean / keep_samples, discard); - if (trunc_mean > (nsamples - discard) * usec + threshold) { + if (virt_env) { + tst_res(TINFO, + "Virtualisation detected, skipping oversleep checks"); + } else if (trunc_mean > (nsamples - discard) * usec + threshold) { tst_res(TFAIL, "%s slept for too long", scall); if (!print_frequency_plot) @@ -343,6 +347,11 @@ static void timer_setup(void) if (setup) setup(); + /* + * Running tests in VM may cause timing issues, disable upper bound + * checks if any hypervisor is detected. + */ + virt_env = tst_is_virt(VIRT_ANY); tst_clock_getres(CLOCK_MONOTONIC, &t); tst_res(TINFO, "CLOCK_MONOTONIC resolution %lins", (long)t.tv_nsec); diff --git a/lib/tst_virt.c b/lib/tst_virt.c index e95cf5e70..d21f74c1c 100644 --- a/lib/tst_virt.c +++ b/lib/tst_virt.c @@ -23,9 +23,20 @@ */ #include <unistd.h> +#include <sys/stat.h> #include "test.h" #include "safe_macros.h" +static int file_exist(const char *path) +{ + struct stat st; + + if (!access(path, R_OK) && !stat(path, &st)) + return 1; + + return 0; +} + static int is_kvm(void) { FILE *cpuinfo; @@ -44,12 +55,16 @@ static int is_kvm(void) } SAFE_FCLOSE(NULL, cpuinfo); + + if (file_exist("/dev/vda") || file_exist("/dev/block/vda")) + found = 1; + return found; } static int is_xen(void) { - char hypervisor_type[3]; + char hypervisor_type[4]; if (access("/proc/xen", F_OK) == 0) return 1; @@ -90,30 +105,41 @@ static int try_systemd_detect_virt(void) * systemd-detect-virt not found by shell or no virtualization detected * (systemd-detect-virt returns non-zero) */ + if (ret < 0 || (WIFEXITED(ret) && WEXITSTATUS(ret) == 127)) + return -1; + if (ret) return 0; - if (strncmp("kvm", virt_type, 3)) + if (!strncmp("kvm", virt_type, 3)) return VIRT_KVM; - if (strncmp("xen", virt_type, 3)) + if (!strncmp("xen", virt_type, 3)) return VIRT_XEN; - return 0; + return VIRT_OTHER; } int tst_is_virt(int virt_type) { int ret = try_systemd_detect_virt(); - if (ret) - return ret == virt_type; + if (ret >= 0) { + if (virt_type == VIRT_ANY) + return ret != 0; + else + return ret == virt_type; + } switch (virt_type) { + case VIRT_ANY: + return is_xen() || is_kvm(); case VIRT_XEN: return is_xen(); case VIRT_KVM: return is_kvm(); + case VIRT_OTHER: + return 0; } tst_brkm(TBROK, NULL, "invalid virt_type flag: %d", virt_type); diff --git a/testcases/kernel/sched/eas/eas_big_to_small.c b/testcases/kernel/sched/eas/eas_big_to_small.c index 36f9598cd..d1e14378f 100644 --- a/testcases/kernel/sched/eas/eas_big_to_small.c +++ b/testcases/kernel/sched/eas/eas_big_to_small.c @@ -35,7 +35,7 @@ static void *task_fn(void *arg LTP_ATTRIBUTE_UNUSED) burn(BURN_SEC * USEC_PER_SEC, 0); printf("Changing to small task...\n"); - SAFE_FILE_PRINTF(TRACING_DIR "trace_marker", "SMALL TASK"); + tracefs_write("trace_marker", "SMALL TASK"); burn(BURN_SEC * USEC_PER_SEC, 1); return NULL; @@ -50,6 +50,7 @@ static int parse_results(void) unsigned long long big_task_us = 0; unsigned long long small_task_us = 0; unsigned long long smalltask_ts_usec = 0; + unsigned long long smalltask_tm_usec = 0; unsigned long long downmigrate_ts_usec = 0; unsigned long long downmigrate_latency_usec = 0; cpu_set_t cpuset; @@ -62,10 +63,11 @@ static int parse_results(void) for (i = 0; i < num_trace_records; i++) { unsigned long long segment_us; struct trace_sched_switch *t = trace[i].event_data; + unsigned long long trace_ts_usec = TS_TO_USEC(trace[i].ts); if (trace[i].event_type == TRACE_RECORD_TRACING_MARK_WRITE && !strcmp(trace[i].event_data, "SMALL TASK")) { - smalltask_ts_usec = TS_TO_USEC(trace[i].ts); + smalltask_tm_usec = trace_ts_usec; continue; } @@ -73,12 +75,15 @@ static int parse_results(void) continue; if (t->next_pid == task_tid) { + if (!smalltask_ts_usec && smalltask_tm_usec && + trace_ts_usec > smalltask_tm_usec) + smalltask_ts_usec = trace_ts_usec; /* Start of task execution segment. */ if (exec_start_us) { printf("Trace parse fail: double exec start\n"); return -1; } - exec_start_us = TS_TO_USEC(trace[i].ts); + exec_start_us = trace_ts_usec; if (smalltask_ts_usec && !downmigrate_ts_usec && CPU_ISSET(trace[i].cpu, &cpuset)) downmigrate_ts_usec = exec_start_us; @@ -87,7 +92,7 @@ static int parse_results(void) if (t->prev_pid != task_tid) continue; /* End of task execution segment. */ - segment_us = TS_TO_USEC(trace[i].ts); + segment_us = trace_ts_usec; segment_us -= exec_start_us; exec_start_us = 0; if (CPU_ISSET(trace[i].cpu, &cpuset)) { @@ -146,17 +151,17 @@ static void run(void) MAX_DOWNMIGRATE_LATENCY_US); /* configure and enable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); - SAFE_FILE_PRINTF(TRACING_DIR "buffer_size_kb", "16384"); - SAFE_FILE_PRINTF(TRACING_DIR "set_event", TRACE_EVENTS); - SAFE_FILE_PRINTF(TRACING_DIR "trace", "\n"); - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "1"); + tracefs_write("tracing_on", "0"); + tracefs_write("buffer_size_kb", "16384"); + tracefs_write("set_event", TRACE_EVENTS); + tracefs_write("trace", "\n"); + tracefs_write("tracing_on", "1"); SAFE_PTHREAD_CREATE(&task_thread, NULL, task_fn, NULL); SAFE_PTHREAD_JOIN(task_thread, NULL); /* disable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); + tracefs_write("tracing_on", "0"); LOAD_TRACE(); if (parse_results()) @@ -169,5 +174,6 @@ static void run(void) static struct tst_test test = { .test_all = run, + .setup = trace_setup, .cleanup = trace_cleanup, }; diff --git a/testcases/kernel/sched/eas/eas_one_big_task.c b/testcases/kernel/sched/eas/eas_one_big_task.c index 5886e9e49..ab066f51a 100644 --- a/testcases/kernel/sched/eas/eas_one_big_task.c +++ b/testcases/kernel/sched/eas/eas_one_big_task.c @@ -111,17 +111,17 @@ static void run(void) MAX_UPMIGRATE_LATENCY_US); /* configure and enable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); - SAFE_FILE_PRINTF(TRACING_DIR "buffer_size_kb", "16384"); - SAFE_FILE_PRINTF(TRACING_DIR "set_event", TRACE_EVENTS); - SAFE_FILE_PRINTF(TRACING_DIR "trace", "\n"); - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "1"); + tracefs_write("tracing_on", "0"); + tracefs_write("buffer_size_kb", "16384"); + tracefs_write("set_event", TRACE_EVENTS); + tracefs_write("trace", "\n"); + tracefs_write("tracing_on", "1"); SAFE_PTHREAD_CREATE(&task_thread, NULL, task_fn, NULL); SAFE_PTHREAD_JOIN(task_thread, NULL); /* disable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); + tracefs_write("tracing_on", "0"); LOAD_TRACE(); if (parse_results()) @@ -134,5 +134,6 @@ static void run(void) static struct tst_test test = { .test_all = run, + .setup = trace_setup, .cleanup = trace_cleanup, }; diff --git a/testcases/kernel/sched/eas/eas_one_small_task.c b/testcases/kernel/sched/eas/eas_one_small_task.c index 74b3a93f8..3885d60bb 100644 --- a/testcases/kernel/sched/eas/eas_one_small_task.c +++ b/testcases/kernel/sched/eas/eas_one_small_task.c @@ -94,17 +94,17 @@ static void run(void) MIN_CORRECT_CLUSTER_PCT); /* configure and enable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); - SAFE_FILE_PRINTF(TRACING_DIR "buffer_size_kb", "16384"); - SAFE_FILE_PRINTF(TRACING_DIR "set_event", TRACE_EVENTS); - SAFE_FILE_PRINTF(TRACING_DIR "trace", "\n"); - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "1"); + tracefs_write("tracing_on", "0"); + tracefs_write("buffer_size_kb", "16384"); + tracefs_write("set_event", TRACE_EVENTS); + tracefs_write("trace", "\n"); + tracefs_write("tracing_on", "1"); SAFE_PTHREAD_CREATE(&task_thread, NULL, task_fn, NULL); SAFE_PTHREAD_JOIN(task_thread, NULL); /* disable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); + tracefs_write("tracing_on", "0"); LOAD_TRACE(); if (parse_results()) @@ -115,5 +115,6 @@ static void run(void) static struct tst_test test = { .test_all = run, + .setup = trace_setup, .cleanup = trace_cleanup, }; diff --git a/testcases/kernel/sched/eas/eas_small_big_toggle.c b/testcases/kernel/sched/eas/eas_small_big_toggle.c index c0d98b021..760949ff1 100644 --- a/testcases/kernel/sched/eas/eas_small_big_toggle.c +++ b/testcases/kernel/sched/eas/eas_small_big_toggle.c @@ -36,10 +36,10 @@ static void *task_fn(void *arg LTP_ATTRIBUTE_UNUSED) task_tid = gettid(); while (loops--) { - SAFE_FILE_PRINTF(TRACING_DIR "trace_marker", "SMALL TASK"); + tracefs_write("trace_marker", "SMALL TASK"); burn(BURN_SEC * USEC_PER_SEC, 1); - SAFE_FILE_PRINTF(TRACING_DIR "trace_marker", "CPU HOG"); + tracefs_write("trace_marker", "CPU HOG"); burn(BURN_SEC * USEC_PER_SEC, 0); } @@ -204,17 +204,17 @@ static void run(void) BURN_SEC * NUM_LOOPS * 2); /* configure and enable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); - SAFE_FILE_PRINTF(TRACING_DIR "buffer_size_kb", "16384"); - SAFE_FILE_PRINTF(TRACING_DIR "set_event", TRACE_EVENTS); - SAFE_FILE_PRINTF(TRACING_DIR "trace", "\n"); - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "1"); + tracefs_write("tracing_on", "0"); + tracefs_write("buffer_size_kb", "16384"); + tracefs_write("set_event", TRACE_EVENTS); + tracefs_write("trace", "\n"); + tracefs_write("tracing_on", "1"); SAFE_PTHREAD_CREATE(&task_thread, NULL, task_fn, NULL); SAFE_PTHREAD_JOIN(task_thread, NULL); /* disable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); + tracefs_write("tracing_on", "0"); LOAD_TRACE(); if (parse_results()) @@ -227,5 +227,6 @@ static void run(void) static struct tst_test test = { .test_all = run, + .setup = trace_setup, .cleanup = trace_cleanup, }; diff --git a/testcases/kernel/sched/eas/eas_small_to_big.c b/testcases/kernel/sched/eas/eas_small_to_big.c index 0e2c04a1a..dd194d5d1 100644 --- a/testcases/kernel/sched/eas/eas_small_to_big.c +++ b/testcases/kernel/sched/eas/eas_small_to_big.c @@ -36,7 +36,7 @@ static void *task_fn(void *arg LTP_ATTRIBUTE_UNUSED) burn(BURN_SEC * USEC_PER_SEC, 1); printf("Changing to big task...\n"); - SAFE_FILE_PRINTF(TRACING_DIR "trace_marker", "CPU HOG"); + tracefs_write("trace_marker", "CPU HOG"); burn(BURN_SEC * USEC_PER_SEC, 0); return NULL; @@ -146,17 +146,17 @@ static void run(void) MAX_UPMIGRATE_LATENCY_US); /* configure and enable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); - SAFE_FILE_PRINTF(TRACING_DIR "buffer_size_kb", "16384"); - SAFE_FILE_PRINTF(TRACING_DIR "set_event", TRACE_EVENTS); - SAFE_FILE_PRINTF(TRACING_DIR "trace", "\n"); - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "1"); + tracefs_write("tracing_on", "0"); + tracefs_write("buffer_size_kb", "16384"); + tracefs_write("set_event", TRACE_EVENTS); + tracefs_write("trace", "\n"); + tracefs_write("tracing_on", "1"); SAFE_PTHREAD_CREATE(&task_thread, NULL, task_fn, NULL); SAFE_PTHREAD_JOIN(task_thread, NULL); /* disable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); + tracefs_write("tracing_on", "0"); LOAD_TRACE(); if (parse_results()) @@ -169,5 +169,6 @@ static void run(void) static struct tst_test test = { .test_all = run, + .setup = trace_setup, .cleanup = trace_cleanup, }; diff --git a/testcases/kernel/sched/eas/eas_two_big_three_small.c b/testcases/kernel/sched/eas/eas_two_big_three_small.c index 000b9425b..e6149b1af 100644 --- a/testcases/kernel/sched/eas/eas_two_big_three_small.c +++ b/testcases/kernel/sched/eas/eas_two_big_three_small.c @@ -116,11 +116,11 @@ static void run(void) printf("Tasks running for %d sec\n", BURN_SEC); /* configure and enable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); - SAFE_FILE_PRINTF(TRACING_DIR "buffer_size_kb", "16384"); - SAFE_FILE_PRINTF(TRACING_DIR "set_event", TRACE_EVENTS); - SAFE_FILE_PRINTF(TRACING_DIR "trace", "\n"); - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "1"); + tracefs_write("tracing_on", "0"); + tracefs_write("buffer_size_kb", "16384"); + tracefs_write("set_event", TRACE_EVENTS); + tracefs_write("trace", "\n"); + tracefs_write("tracing_on", "1"); for (i = 0; i < NUM_TASKS; i++) SAFE_PTHREAD_CREATE(&tasks[i], NULL, task_fn, &task_tids[i]); @@ -128,7 +128,7 @@ static void run(void) SAFE_PTHREAD_JOIN(tasks[i], NULL); /* disable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); + tracefs_write("tracing_on", "0"); LOAD_TRACE(); if (parse_results()) @@ -139,5 +139,6 @@ static void run(void) static struct tst_test test = { .test_all = run, + .setup = trace_setup, .cleanup = trace_cleanup, }; diff --git a/testcases/kernel/sched/eas/sched_boost.c b/testcases/kernel/sched/eas/sched_boost.c index 26a72ae66..6554a42da 100644 --- a/testcases/kernel/sched/eas/sched_boost.c +++ b/testcases/kernel/sched/eas/sched_boost.c @@ -78,7 +78,7 @@ static void *test_fn(void *arg LTP_ATTRIBUTE_UNUSED) // give time for utilization to track real task usage do_work(); // start measuring - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "1"); + tracefs_write("tracing_on", "1"); do_work(); sem_post(&result_sem); tests_done++; @@ -110,10 +110,10 @@ static void run_test(void) { SAFE_FILE_PRINTF(STUNE_TEST_PATH "/schedtune.boost", "%d", test_boost[test_index]); - SAFE_FILE_PRINTF(TRACING_DIR "trace", "\n"); + tracefs_write("trace", "\n"); sem_post(&test_sem); sem_wait(&result_sem); - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); + tracefs_write("tracing_on", "0"); LOAD_TRACE(); parse_results(); test_index++; @@ -182,9 +182,9 @@ static void run(void) SAFE_PTHREAD_CREATE(&test_thread, NULL, test_fn, NULL); - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); - SAFE_FILE_PRINTF(TRACING_DIR "buffer_size_kb", "16384"); - SAFE_FILE_PRINTF(TRACING_DIR "set_event", TRACE_EVENTS); + tracefs_write("tracing_on", "0"); + tracefs_write("buffer_size_kb", "16384"); + tracefs_write("set_event", TRACE_EVENTS); while (test_index < NUM_TESTS) run_test(); @@ -196,5 +196,6 @@ static void run(void) static struct tst_test test = { .test_all = run, + .setup = trace_setup, .cleanup = trace_cleanup, }; diff --git a/testcases/kernel/sched/eas/sched_cfs_prio.c b/testcases/kernel/sched/eas/sched_cfs_prio.c index 92d2dced6..b54d0d5b5 100644 --- a/testcases/kernel/sched/eas/sched_cfs_prio.c +++ b/testcases/kernel/sched/eas/sched_cfs_prio.c @@ -181,11 +181,11 @@ static void run(void) NUM_TASKS, TEST_TASK_SECONDS); /* configure and enable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); - SAFE_FILE_PRINTF(TRACING_DIR "buffer_size_kb", "16384"); - SAFE_FILE_PRINTF(TRACING_DIR "set_event", TRACE_EVENTS); - SAFE_FILE_PRINTF(TRACING_DIR "trace", "\n"); - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "1"); + tracefs_write("tracing_on", "0"); + tracefs_write("buffer_size_kb", "16384"); + tracefs_write("set_event", TRACE_EVENTS); + tracefs_write("trace", "\n"); + tracefs_write("tracing_on", "1"); for (i = 0; i < NUM_TASKS; i++) SAFE_PTHREAD_CREATE(&tasks[i], NULL, task_fn, @@ -194,7 +194,7 @@ static void run(void) SAFE_PTHREAD_JOIN(tasks[i], NULL); /* disable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); + tracefs_write("tracing_on", "0"); LOAD_TRACE(); if (parse_results()) @@ -207,5 +207,6 @@ static void run(void) static struct tst_test test = { .test_all = run, + .setup = trace_setup, .cleanup = trace_cleanup, }; diff --git a/testcases/kernel/sched/eas/sched_dl_runtime.c b/testcases/kernel/sched/eas/sched_dl_runtime.c index 27f0564d4..18fadea9e 100644 --- a/testcases/kernel/sched/eas/sched_dl_runtime.c +++ b/testcases/kernel/sched/eas/sched_dl_runtime.c @@ -49,7 +49,7 @@ static void *dl_fn(void *arg LTP_ATTRIBUTE_UNUSED) attr.sched_period = 20000000; attr.sched_deadline = 10000000; - SAFE_FILE_PRINTF(TRACING_DIR "trace_marker", "DL START"); + tracefs_write("trace_marker", "DL START"); ERROR_CHECK(sched_setattr(0, &attr, 0)); dl_task_tid = gettid(); @@ -126,6 +126,7 @@ static int parse_results(void) periods_parsed++; next_deadline_ts_us += 20000; next_period_ts_us += 20000; + period_exec_time_us = 0; } if (trace[i].event_type == TRACE_RECORD_SCHED_SWITCH) { struct trace_sched_switch *t = trace[i].event_data; @@ -173,17 +174,17 @@ static void run(void) &dl_thread_sched_params)); /* configure and enable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); - SAFE_FILE_PRINTF(TRACING_DIR "buffer_size_kb", "16384"); - SAFE_FILE_PRINTF(TRACING_DIR "set_event", TRACE_EVENTS); - SAFE_FILE_PRINTF(TRACING_DIR "trace", "\n"); - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "1"); + tracefs_write("tracing_on", "0"); + tracefs_write("buffer_size_kb", "16384"); + tracefs_write("set_event", TRACE_EVENTS); + tracefs_write("trace", "\n"); + tracefs_write("tracing_on", "1"); SAFE_PTHREAD_CREATE(&dl_thread, NULL, dl_fn, NULL); SAFE_PTHREAD_JOIN(dl_thread, NULL); /* disable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); + tracefs_write("tracing_on", "0"); LOAD_TRACE(); if (parse_results()) @@ -193,6 +194,7 @@ static void run(void) } static struct tst_test test = { + .setup = trace_setup, .test_all = run, .cleanup = trace_cleanup, }; diff --git a/testcases/kernel/sched/eas/sched_latency_dl.c b/testcases/kernel/sched/eas/sched_latency_dl.c index 486c4cf4d..e66fc21f7 100644 --- a/testcases/kernel/sched/eas/sched_latency_dl.c +++ b/testcases/kernel/sched/eas/sched_latency_dl.c @@ -61,7 +61,7 @@ static void *dl_fn(void *arg LTP_ATTRIBUTE_UNUSED) static void *cfs_fn(void *arg LTP_ATTRIBUTE_UNUSED) { usleep(5000); - SAFE_FILE_PRINTF(TRACING_DIR "trace_marker", "WAKING"); + tracefs_write("trace_marker", "WAKING"); sem_post(&sem); burn(USEC_PER_SEC, 0); @@ -135,11 +135,11 @@ static void run(void) sem_init(&sem, 0, 0); /* configure and enable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); - SAFE_FILE_PRINTF(TRACING_DIR "buffer_size_kb", "16384"); - SAFE_FILE_PRINTF(TRACING_DIR "set_event", TRACE_EVENTS); - SAFE_FILE_PRINTF(TRACING_DIR "trace", "\n"); - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "1"); + tracefs_write("tracing_on", "0"); + tracefs_write("buffer_size_kb", "16384"); + tracefs_write("set_event", TRACE_EVENTS); + tracefs_write("trace", "\n"); + tracefs_write("tracing_on", "1"); SAFE_PTHREAD_CREATE(&cfs_thread, &cfs_thread_attrs, cfs_fn, NULL); SAFE_PTHREAD_CREATE(&dl_thread, &dl_thread_attrs, dl_fn, NULL); @@ -147,7 +147,7 @@ static void run(void) SAFE_PTHREAD_JOIN(dl_thread, NULL); /* disable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); + tracefs_write("tracing_on", "0"); LOAD_TRACE(); if (parse_results()) @@ -160,5 +160,6 @@ static void run(void) static struct tst_test test = { .test_all = run, + .setup = trace_setup, .cleanup = trace_cleanup, }; diff --git a/testcases/kernel/sched/eas/sched_latency_rt.c b/testcases/kernel/sched/eas/sched_latency_rt.c index 3a5a91fde..68fb45a26 100644 --- a/testcases/kernel/sched/eas/sched_latency_rt.c +++ b/testcases/kernel/sched/eas/sched_latency_rt.c @@ -43,7 +43,7 @@ static void *cfs_fn(void *arg LTP_ATTRIBUTE_UNUSED) affine(0); usleep(5000); - SAFE_FILE_PRINTF(TRACING_DIR "trace_marker", "WAKING"); + tracefs_write("trace_marker", "WAKING"); sem_post(&sem); burn(USEC_PER_SEC, 0); @@ -117,11 +117,11 @@ static void run(void) sem_init(&sem, 0, 0); /* configure and enable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); - SAFE_FILE_PRINTF(TRACING_DIR "buffer_size_kb", "16384"); - SAFE_FILE_PRINTF(TRACING_DIR "set_event", TRACE_EVENTS); - SAFE_FILE_PRINTF(TRACING_DIR "trace", "\n"); - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "1"); + tracefs_write("tracing_on", "0"); + tracefs_write("buffer_size_kb", "16384"); + tracefs_write("set_event", TRACE_EVENTS); + tracefs_write("trace", "\n"); + tracefs_write("tracing_on", "1"); SAFE_PTHREAD_CREATE(&cfs_thread, &cfs_thread_attrs, cfs_fn, NULL); SAFE_PTHREAD_CREATE(&rt_thread, &rt_thread_attrs, rt_fn, NULL); @@ -129,7 +129,7 @@ static void run(void) SAFE_PTHREAD_JOIN(rt_thread, NULL); /* disable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); + tracefs_write("tracing_on", "0"); LOAD_TRACE(); if (parse_results()) @@ -142,5 +142,6 @@ static void run(void) static struct tst_test test = { .test_all = run, + .setup = trace_setup, .cleanup = trace_cleanup, }; diff --git a/testcases/kernel/sched/eas/sched_prio_3_fifo.c b/testcases/kernel/sched/eas/sched_prio_3_fifo.c index 4244f17c0..29f704f92 100644 --- a/testcases/kernel/sched/eas/sched_prio_3_fifo.c +++ b/testcases/kernel/sched/eas/sched_prio_3_fifo.c @@ -225,7 +225,7 @@ static void *rt_low_fn_a(void *arg LTP_ATTRIBUTE_UNUSED) fixup_expected_events(); - SAFE_FILE_PRINTF(TRACING_DIR "trace_marker", "TEST START"); + tracefs_write("trace_marker", "TEST START"); /* Wake up rt_low_fn_b. We should continue to run though. */ sem_post(&sem_low_b); @@ -353,11 +353,11 @@ static void run(void) sem_init(&sem_low_a, 0, 0); /* configure and enable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); - SAFE_FILE_PRINTF(TRACING_DIR "buffer_size_kb", "16384"); - SAFE_FILE_PRINTF(TRACING_DIR "set_event", TRACE_EVENTS); - SAFE_FILE_PRINTF(TRACING_DIR "trace", "\n"); - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "1"); + tracefs_write("tracing_on", "0"); + tracefs_write("buffer_size_kb", "16384"); + tracefs_write("set_event", TRACE_EVENTS); + tracefs_write("trace", "\n"); + tracefs_write("tracing_on", "1"); create_rt_thread(70, rt_low_fn_a, &rt_low_a); create_rt_thread(70, rt_low_fn_b, &rt_low_b); @@ -374,7 +374,7 @@ static void run(void) SAFE_PTHREAD_JOIN(rt_high_b, NULL); /* disable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); + tracefs_write("tracing_on", "0"); LOAD_TRACE(); if (parse_results()) @@ -387,5 +387,6 @@ static void run(void) static struct tst_test test = { .test_all = run, + .setup = trace_setup, .cleanup = trace_cleanup, }; diff --git a/testcases/kernel/sched/eas/sched_prio_3_rr.c b/testcases/kernel/sched/eas/sched_prio_3_rr.c index 8403da5fe..43bcce7a7 100644 --- a/testcases/kernel/sched/eas/sched_prio_3_rr.c +++ b/testcases/kernel/sched/eas/sched_prio_3_rr.c @@ -24,7 +24,7 @@ #define TRACE_EVENTS "sched_wakeup sched_switch sched_process_exit" -#define EXEC_MIN_PCT 33 +#define EXEC_MIN_PCT 32 #define EXEC_MAX_PCT 34 static sem_t sem; @@ -58,7 +58,7 @@ static void *rt_a_fn(void *arg LTP_ATTRIBUTE_UNUSED) affine(0); /* Give all other tasks a chance to affine and block. */ usleep(3000); - SAFE_FILE_PRINTF(TRACING_DIR "trace_marker", "TEST START"); + tracefs_write("trace_marker", "TEST START"); sem_post(&sem); sem_post(&sem); burn(BUSY_WAIT_USECS, 0); @@ -147,11 +147,11 @@ static void run(void) printf("Running %d RT RR tasks for 10 seconds...\n", NUM_TASKS); /* configure and enable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); - SAFE_FILE_PRINTF(TRACING_DIR "buffer_size_kb", "16384"); - SAFE_FILE_PRINTF(TRACING_DIR "set_event", TRACE_EVENTS); - SAFE_FILE_PRINTF(TRACING_DIR "trace", "\n"); - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "1"); + tracefs_write("tracing_on", "0"); + tracefs_write("buffer_size_kb", "16384"); + tracefs_write("set_event", TRACE_EVENTS); + tracefs_write("trace", "\n"); + tracefs_write("tracing_on", "1"); create_rt_thread(70, rt_a_fn, &rt_a); create_rt_thread(70, rt_b_fn, &rt_b); @@ -162,7 +162,7 @@ static void run(void) SAFE_PTHREAD_JOIN(rt_c, NULL); /* disable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); + tracefs_write("tracing_on", "0"); LOAD_TRACE(); if (parse_results()) @@ -175,5 +175,6 @@ static void run(void) static struct tst_test test = { .test_all = run, + .setup = trace_setup, .cleanup = trace_cleanup, }; diff --git a/testcases/kernel/sched/eas/sugov_latency.c b/testcases/kernel/sched/eas/sugov_latency.c index 923948edc..35154d83b 100644 --- a/testcases/kernel/sched/eas/sugov_latency.c +++ b/testcases/kernel/sched/eas/sugov_latency.c @@ -65,9 +65,9 @@ static void *burn_fn(void *arg LTP_ATTRIBUTE_UNUSED) return NULL; } - SAFE_FILE_PRINTF(TRACING_DIR "trace_marker", "affined"); + tracefs_write("trace_marker", "affined"); burn(BURN_MSEC * 1000, 0); - SAFE_FILE_PRINTF(TRACING_DIR "trace_marker", "small task"); + tracefs_write("trace_marker", "small task"); burn(BURN_MSEC * 1000, 1); return NULL; @@ -205,17 +205,17 @@ static void run(void) printf("CPU hog will be bound to CPU %d.\n", test_cpu); /* configure and enable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); - SAFE_FILE_PRINTF(TRACING_DIR "buffer_size_kb", "16384"); - SAFE_FILE_PRINTF(TRACING_DIR "set_event", TRACE_EVENTS); - SAFE_FILE_PRINTF(TRACING_DIR "trace", "\n"); - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "1"); + tracefs_write("tracing_on", "0"); + tracefs_write("buffer_size_kb", "16384"); + tracefs_write("set_event", TRACE_EVENTS); + tracefs_write("trace", "\n"); + tracefs_write("tracing_on", "1"); SAFE_PTHREAD_CREATE(&burn_thread, NULL, burn_fn, NULL); SAFE_PTHREAD_JOIN(burn_thread, NULL); /* disable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); + tracefs_write("tracing_on", "0"); LOAD_TRACE(); if (parse_results()) @@ -226,5 +226,6 @@ static void run(void) static struct tst_test test = { .test_all = run, + .setup = trace_setup, .cleanup = trace_cleanup, }; diff --git a/testcases/kernel/sched/eas/sugov_stale_util.c b/testcases/kernel/sched/eas/sugov_stale_util.c index 685d1bd19..b02882c93 100644 --- a/testcases/kernel/sched/eas/sugov_stale_util.c +++ b/testcases/kernel/sched/eas/sugov_stale_util.c @@ -53,11 +53,9 @@ static void *event_fn(void *arg LTP_ATTRIBUTE_UNUSED) sem_wait(&sem); - SAFE_FILE_PRINTF(TRACING_DIR "trace_marker", - "event task sleep"); + tracefs_write("trace_marker", "event task sleep"); usleep(MAX_STALE_USEC); - SAFE_FILE_PRINTF(TRACING_DIR "trace_marker", - "event task wake"); + tracefs_write("trace_marker", "event task wake"); /* * Waking up should be sufficient to get the cpufreq policy to * re-evaluate. @@ -83,7 +81,7 @@ static void *burn_fn(void *arg LTP_ATTRIBUTE_UNUSED) * Sleep. The next sugov update after TICK_NSEC should not include * this task's contribution. */ - SAFE_FILE_PRINTF(TRACING_DIR "trace_marker", "sleeping"); + tracefs_write("trace_marker", "sleeping"); /* * Wake up task on another CPU in the same policy which will sleep @@ -205,11 +203,11 @@ static void run(void) sem_init(&sem, 0, 0); /* configure and enable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); - SAFE_FILE_PRINTF(TRACING_DIR "buffer_size_kb", "16384"); - SAFE_FILE_PRINTF(TRACING_DIR "set_event", TRACE_EVENTS); - SAFE_FILE_PRINTF(TRACING_DIR "trace", "\n"); - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "1"); + tracefs_write("tracing_on", "0"); + tracefs_write("buffer_size_kb", "16384"); + tracefs_write("set_event", TRACE_EVENTS); + tracefs_write("trace", "\n"); + tracefs_write("tracing_on", "1"); SAFE_PTHREAD_CREATE(&burn_thread, NULL, burn_fn, NULL); SAFE_PTHREAD_CREATE(&event_thread, NULL, event_fn, NULL); @@ -218,7 +216,7 @@ static void run(void) SAFE_PTHREAD_JOIN(event_thread, NULL); /* disable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); + tracefs_write("tracing_on", "0"); LOAD_TRACE(); if (parse_results()) @@ -231,5 +229,6 @@ static void run(void) static struct tst_test test = { .test_all = run, + .setup = trace_setup, .cleanup = trace_cleanup, }; diff --git a/testcases/kernel/sched/eas/sugov_wakeups.c b/testcases/kernel/sched/eas/sugov_wakeups.c index c1f6f2f08..b068b1fe9 100644 --- a/testcases/kernel/sched/eas/sugov_wakeups.c +++ b/testcases/kernel/sched/eas/sugov_wakeups.c @@ -34,16 +34,16 @@ static void run(void) "%d wakeups allowed\n", SLEEP_SEC, MAX_WAKEUPS); /* configure and enable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); - SAFE_FILE_PRINTF(TRACING_DIR "buffer_size_kb", "16384"); - SAFE_FILE_PRINTF(TRACING_DIR "set_event", TRACE_EVENTS); - SAFE_FILE_PRINTF(TRACING_DIR "trace", "\n"); - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "1"); + tracefs_write("tracing_on", "0"); + tracefs_write("buffer_size_kb", "16384"); + tracefs_write("set_event", TRACE_EVENTS); + tracefs_write("trace", "\n"); + tracefs_write("tracing_on", "1"); sleep(SLEEP_SEC); /* disable tracing */ - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); + tracefs_write("tracing_on", "0"); LOAD_TRACE(); for (i = 0; i < num_trace_records; i++) { @@ -64,5 +64,6 @@ static void run(void) static struct tst_test test = { .test_all = run, + .setup = trace_setup, .cleanup = trace_cleanup, }; diff --git a/testcases/kernel/sched/eas/trace_parse.c b/testcases/kernel/sched/eas/trace_parse.c index a4c158a1b..46bc0bdb4 100644 --- a/testcases/kernel/sched/eas/trace_parse.c +++ b/testcases/kernel/sched/eas/trace_parse.c @@ -20,12 +20,18 @@ #include "trace_parse.h" +#define TRACEFS_MAX_PATH_LEN 512 + int num_trace_records = 0; struct trace_record *trace = NULL; static int trace_fd = -1; static char *trace_buffer = NULL; +const char *tracefs_root = "/sys/kernel/tracing/"; +const char *debugfs_tracefs_root = "/sys/kernel/debug/tracing/"; +char *ftrace_root_dir; + static int parse_event_type(char *event_name) { if (!strcmp(event_name, "sched_process_exit")) @@ -86,9 +92,28 @@ void print_trace_record(struct trace_record *tr) printf("(other)\n"); } +void trace_setup(void) +{ + struct stat buf; + + if (stat("/sys/kernel/tracing/trace", &buf) == 0) + ftrace_root_dir = tracefs_root; + else + ftrace_root_dir = debugfs_tracefs_root; + +} + +void tracefs_write(const char *file_name, const char *value) +{ + char buf[TRACEFS_MAX_PATH_LEN]; + + snprintf(buf, sizeof(buf), "%s%s", ftrace_root_dir, file_name); + SAFE_FILE_PRINTF(buf, value); +} + void trace_cleanup(void) { - SAFE_FILE_PRINTF(TRACING_DIR "tracing_on", "0"); + tracefs_write("tracing_on", "0"); } @@ -231,15 +256,15 @@ static void *parse_event_data(unsigned int event_type, char *data) * First 16 chars are the currently running thread name. Drop leading spaces. * Next char is a dash * Next 5 chars are PID. Drop trailing spaces. - * Next char is a space. + * Next is some number of spaces. * Next five chars are the CPU, i.e. [001]. - * Next char is a space. + * Next is some number of spaces. * Next letter is whether IRQs are off. * Next letter is if NEED_RESCHED is set. * Next letter is if this is in hard or soft IRQ context. * Next letter is the preempt disable depth. - * Next char is a space. - * Next twelve letters are the timestamp. Drop leading spaces. + * Next is some number of spaces. + * Next twelve letters are the timestamp. * Next char is colon. * Next char is space. * Next twelve letters are the event name. @@ -247,7 +272,7 @@ static void *parse_event_data(unsigned int event_type, char *data) * Rest of line is string specific to event. */ static int parse_trace_record(struct trace_record *tr, char *line) { - unsigned int idx = 0; + unsigned int field_start, idx = 0; char *found; /* Skip leading spaces in the task name. */ @@ -266,83 +291,100 @@ static int parse_trace_record(struct trace_record *tr, char *line) { return -1; } idx = 17; - if (line[22] != ' ') { - printf("Malformatted trace record, no space between" - "pid and CPU:\n"); + while(line[idx] && line[idx] != '[') idx++; + if (!line[idx]) { + printf("Malformatted trace record, no open bracket for" + "CPU after pid:\n"); printf("%s", line); return -1; } - line[22] = 0; + line[idx-1] = 0; if (sscanf(&line[17], "%hd", &tr->pid) != 1) { printf("Malformatted trace record, error parsing" "pid:\n"); printf("%s", line); return -1; } - if (line[28] != ' ') { - printf("Malformatted trace record, no space between" - "CPU and flags:\n"); + field_start = idx; + while(line[idx] && line[idx] != ']') idx++; + if (!line[idx]) { + printf("Malformatted trace record, no closing bracket for" + "CPU:\n"); + printf("%s", line); + return -1; + } + idx++; + if (line[idx] != ' ') { + printf("Malformatted trace record, no space following CPU:\n"); printf("%s", line); return -1; } - line[28] = 0; - if (sscanf(&line[23], "[%hd]", &tr->cpu) != 1) { + line[idx] = 0; + idx++; + if (sscanf(&line[field_start], "[%hd]", &tr->cpu) != 1) { printf("Malformatted trace record, error parsing CPU:\n"); printf("%s", line); return -1; } - if (line[29] == 'd') { + + if (line[idx] == 'd') { tr->flags |= TRACE_RECORD_IRQS_OFF; - } else if (line[29] != '.') { + } else if (line[idx] != '.') { printf("Malformatted trace record, error parsing irqs-off:\n"); printf("%s", line); return -1; } - if (line[30] == 'N') { + idx++; + if (line[idx] == 'N') { tr->flags |= TRACE_RECORD_TIF_NEED_RESCHED; tr->flags |= TRACE_RECORD_PREEMPT_NEED_RESCHED; - } else if (line[30] == 'n') { + } else if (line[idx] == 'n') { tr->flags |= TRACE_RECORD_TIF_NEED_RESCHED; - } else if (line[30] == 'p') { + } else if (line[idx] == 'p') { tr->flags |= TRACE_RECORD_PREEMPT_NEED_RESCHED; - } else if (line[30] != '.') { + } else if (line[idx] != '.') { printf("Malformatted trace record, error parsing " "need-resched:\n"); printf("%s", line); return -1; } + idx++; - if (line[31] != IRQ_CONTEXT_NORMAL && line[31] != IRQ_CONTEXT_SOFT && - line[31] != IRQ_CONTEXT_HARD && - line[31] != IRQ_CONTEXT_HARD_IN_SOFT && - line[31] != IRQ_CONTEXT_NMI && line[31] != IRQ_CONTEXT_NMI_IN_HARD) { + if (line[idx] != IRQ_CONTEXT_NORMAL && line[idx] != IRQ_CONTEXT_SOFT && + line[idx] != IRQ_CONTEXT_HARD && + line[idx] != IRQ_CONTEXT_HARD_IN_SOFT && + line[idx] != IRQ_CONTEXT_NMI && line[idx] != IRQ_CONTEXT_NMI_IN_HARD) { printf("Malformatted trace record, error parsing irq " "context:\n"); printf("%s", line); return -1; } - tr->irq_context = line[31]; + tr->irq_context = line[idx]; + idx++; - if (line[33] != ' ') { + if (line[idx+1] != ' ') { printf("Malformatted trace record, no space between" "flags and timestamp:\n"); printf("%s", line); return -1; } - line[33] = 0; - if (line[32] == '.') { + line[idx+1] = 0; + if (line[idx] == '.') { tr->preempt_depth = 0; - } else if (sscanf(&line[32], "%hx", &tr->preempt_depth) != 1) { + } else if (sscanf(&line[idx], "%hx", &tr->preempt_depth) != 1) { printf("Malformatted trace record, error parsing " "preempt-depth:\n"); printf("%s", line); return -1; } + idx += 2; - /* timestamp starts as early as line[34], skip leading spaces */ - idx = 34; - while (idx < 38 && line[idx] == ' ') - idx++; + while (line[idx] && line[idx] == ' ') idx++; + if (!line[idx]) { + printf("Malformatted trace record, missing timestamp:\n"); + printf("%s", line); + return -1; + } if (sscanf(&line[idx], "%d.%d: ", &tr->ts.sec, &tr->ts.usec) != 2) { printf("Malformatted trace record, error parsing " @@ -380,12 +422,15 @@ static int refill_buffer(char *buffer, char *idx) int bytes_to_read; int bytes_read = 0; int rv; + char buf[256]; bytes_in_buffer = TRACE_BUFFER_SIZE - (idx - buffer) - 1; bytes_to_read = TRACE_BUFFER_SIZE - bytes_in_buffer - 1; if (trace_fd == -1) { - trace_fd = open(TRACING_DIR "trace", O_RDONLY); + snprintf(buf, sizeof(buf), "%strace", ftrace_root_dir); + + trace_fd = open(buf, O_RDONLY); if (trace_fd == -1) { printf("Could not open trace file!\n"); return 0; diff --git a/testcases/kernel/sched/eas/trace_parse.h b/testcases/kernel/sched/eas/trace_parse.h index 436b6d7d8..afce586a9 100644 --- a/testcases/kernel/sched/eas/trace_parse.h +++ b/testcases/kernel/sched/eas/trace_parse.h @@ -7,10 +7,6 @@ #ifndef _LTP_TRACE_PARSE_H_ #define _LTP_TRACE_PARSE_H_ -/* - * It is necessary to define TRACE_EVENTS to communicate the events to trace. */ -#define TRACING_DIR "/sys/kernel/debug/tracing/" - enum { TRACE_RECORD_OTHER = 0, TRACE_RECORD_SCHED_PROCESS_EXIT, @@ -91,7 +87,10 @@ struct trace_record { extern int num_trace_records; extern struct trace_record *trace; +extern char *ftrace_root_dir; +void tracefs_write(const char *file_name, const char *value); +void trace_setup(void); void trace_cleanup(void); void print_trace_record(struct trace_record *tr); struct trace_record *load_trace(void); diff --git a/testcases/kernel/sched/eas/util.h b/testcases/kernel/sched/eas/util.h index 2433a53d6..7108dcbe9 100644 --- a/testcases/kernel/sched/eas/util.h +++ b/testcases/kernel/sched/eas/util.h @@ -13,7 +13,7 @@ #define USEC_PER_SEC 1000000 -#define TS_TO_USEC(x) (x.usec + x.sec * USEC_PER_SEC) +#define TS_TO_USEC(x) (x.usec + (unsigned long long)x.sec * USEC_PER_SEC) #ifndef SCHED_DEADLINE #define SCHED_DEADLINE 6 |