diff options
author | android-build-prod (mdb) <android-build-team-robot@google.com> | 2020-05-27 21:06:08 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2020-05-27 21:06:08 +0000 |
commit | b0991eb0dcba10a87adb7426905c667dad76e116 (patch) | |
tree | 0a771f7b19ea60fe9869f702fd1be8b63867fc87 | |
parent | 12f716a5719f8daa22c660227116a87b8d368d85 (diff) | |
parent | 8894685137c1185d76cdaf91daae11bd1df22ca1 (diff) | |
download | extras-b0991eb0dcba10a87adb7426905c667dad76e116.tar.gz |
Merge "Snap for 6533464 from 8279e6342e4a79b6579129f1ab05dddd27688c94 to sdk-release" into sdk-releaseplatform-tools-30.0.3platform-tools-30.0.2
19 files changed, 83 insertions, 0 deletions
diff --git a/METADATA b/METADATA new file mode 100644 index 00000000..d97975ca --- /dev/null +++ b/METADATA @@ -0,0 +1,3 @@ +third_party { + license_type: NOTICE +} diff --git a/libfscrypt/fscrypt.cpp b/libfscrypt/fscrypt.cpp index 622b4cdb..a52ed90c 100644 --- a/libfscrypt/fscrypt.cpp +++ b/libfscrypt/fscrypt.cpp @@ -153,6 +153,9 @@ bool OptionsToStringForApiLevel(unsigned int first_api_level, const EncryptionOp if ((options.flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64)) { *options_string += "+inlinecrypt_optimized"; } + if ((options.flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32)) { + *options_string += "+emmc_optimized"; + } if (options.use_hw_wrapped_key) { *options_string += "+wrappedkey_v0"; } @@ -214,6 +217,8 @@ bool ParseOptionsForApiLevel(unsigned int first_api_level, const std::string& op options->version = 2; } else if (flag == "inlinecrypt_optimized") { options->flags |= FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64; + } else if (flag == "emmc_optimized") { + options->flags |= FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32; } else if (flag == "wrappedkey_v0") { options->use_hw_wrapped_key = true; } else { @@ -248,6 +253,18 @@ bool ParseOptionsForApiLevel(unsigned int first_api_level, const std::string& op LOG(ERROR) << "Adiantum must be both contents and filenames mode or neither, invalid options: " << options_string; return false; } + + // IV generation methods are mutually exclusive + int iv_methods = 0; + iv_methods += !!(options->flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64); + iv_methods += !!(options->flags & FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32); + iv_methods += !!(options->flags & FSCRYPT_POLICY_FLAG_DIRECT_KEY); + if (iv_methods > 1) { + LOG(ERROR) << "At most one IV generation method can be set, invalid options: " + << options_string; + return false; + } + return true; } diff --git a/libfscrypt/include/fscrypt/fscrypt.h b/libfscrypt/include/fscrypt/fscrypt.h index 78b12560..b1ba1dfe 100644 --- a/libfscrypt/include/fscrypt/fscrypt.h +++ b/libfscrypt/include/fscrypt/fscrypt.h @@ -19,6 +19,12 @@ #include <string> +#ifndef FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32 +// When FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32 is added to Bionic's linux/fscrypt.h +// then this whole stanza should be removed. +#define FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32 0x10 +#endif + bool fscrypt_is_native(); static const char* fscrypt_unencrypted_folder = "/unencrypted"; diff --git a/libfscrypt/tests/fscrypt_test.cpp b/libfscrypt/tests/fscrypt_test.cpp index 457ac684..4fbd742c 100644 --- a/libfscrypt/tests/fscrypt_test.cpp +++ b/libfscrypt/tests/fscrypt_test.cpp @@ -156,6 +156,18 @@ TEST(fscrypt, ParseOptions) { EXPECT_EQ(FSCRYPT_POLICY_FLAGS_PAD_16 | FSCRYPT_POLICY_FLAG_IV_INO_LBLK_64, options.flags); } + { + TEST_STRING(30, "::emmc_optimized", "aes-256-xts:aes-256-cts:v2+emmc_optimized"); + EXPECT_EQ(2, options.version); + EXPECT_EQ(FSCRYPT_MODE_AES_256_XTS, options.contents_mode); + EXPECT_EQ(FSCRYPT_MODE_AES_256_CTS, options.filenames_mode); + EXPECT_EQ(FSCRYPT_POLICY_FLAGS_PAD_16 | FSCRYPT_POLICY_FLAG_IV_INO_LBLK_32, options.flags); + } + EXPECT_FALSE( + ParseOptionsForApiLevel(30, "::inlinecrypt_optimized+emmc_optimized", &dummy_options)); + EXPECT_FALSE(ParseOptionsForApiLevel(30, "adiantum::inlinecrypt_optimized", &dummy_options)); + EXPECT_FALSE(ParseOptionsForApiLevel(30, "adiantum::emmc_optimized", &dummy_options)); + EXPECT_FALSE(ParseOptionsForApiLevel(29, "aes-256-xts:aes-256-cts:v2:", &dummy_options)); EXPECT_FALSE(ParseOptionsForApiLevel(29, "aes-256-xts:aes-256-cts:v2:foo", &dummy_options)); EXPECT_FALSE(ParseOptionsForApiLevel(29, "aes-256-xts:aes-256-cts:blah", &dummy_options)); diff --git a/simpleperf/doc/android_platform_profiling.md b/simpleperf/doc/android_platform_profiling.md index afa1927b..797d640a 100644 --- a/simpleperf/doc/android_platform_profiling.md +++ b/simpleperf/doc/android_platform_profiling.md @@ -1,5 +1,14 @@ # Android platform profiling +## Table of Contents +- [Android platform profiling](#android-platform-profiling) + - [Table of Contents](#table-of-contents) + - [General Tips](#general-tips) + - [Start simpleperf from system_server process](#start-simpleperf-from-systemserver-process) + - [Hardware PMU counter limit](#hardware-pmu-counter-limit) + +## General Tips + Here are some tips for Android platform developers, who build and flash system images on rooted devices: 1. After running `adb root`, simpleperf can be used to profile any process or system wide. @@ -34,3 +43,39 @@ $ python binary_cache_builder.py -lib $ANDROID_PRODUCT_OUT/symbols $ python report_html.py --add_source_code --source_dirs $ANDROID_BUILD_TOP --add_disassembly \ --binary_filter surfaceflinger.so ``` + +## Start simpleperf from system_server process + +Sometimes we want to profile a process/system-wide when a special situation happens. In this case, +we can add code starting simpleperf at the point where the situation is detected. + +1. Disable selinux by `adb shell setenforce 0`. Because selinux only allows simpleperf running + in shell or debuggable/profileable apps. + +2. Add below code at the point where the special situation is detected. + +```java +try { + // for capability check + Os.prctl(OsConstants.PR_CAP_AMBIENT, OsConstants.PR_CAP_AMBIENT_RAISE, + OsConstants.CAP_SYS_PTRACE, 0, 0); + // Write to /data instead of /data/local/tmp. Because /data can be written by system user. + Runtime.getRuntime().exec("/system/bin/simpleperf record -g -p " + String.valueOf(Process.myPid()) + + " -o /data/perf.data --duration 30 --log-to-android-buffer --log verbose"); +} catch (Exception e) { + Slog.e(TAG, "error while running simpleperf"); + e.printStackTrace(); +} +``` + +## Hardware PMU counter limit + +When monitoring instruction and cache related perf events (in hw/cache/raw/pmu category of list cmd), +these events are mapped to PMU counters on each cpu core. But each core only has a limited number +of PMU counters. If number of events > number of PMU counters, then the counters are multiplexed +among events, which probably isn't what we want. + +On Pixel devices, the number of PMU counters on each core is usually 7, of which 4 of them are used +by the kernel to monitor memory latency. So only 3 counters are available. It's fine to monitor up +to 3 PMU events at the same time. To monitor more than 3 events, the `--use-devfreq-counters` option +can be used to borrow from the counters used by the kernel. diff --git a/simpleperf/scripts/bin/android/arm/simpleperf b/simpleperf/scripts/bin/android/arm/simpleperf Binary files differindex 9a29c7f8..7379680d 100755 --- a/simpleperf/scripts/bin/android/arm/simpleperf +++ b/simpleperf/scripts/bin/android/arm/simpleperf diff --git a/simpleperf/scripts/bin/android/arm64/simpleperf b/simpleperf/scripts/bin/android/arm64/simpleperf Binary files differindex cbc1da5c..d4c58a17 100755 --- a/simpleperf/scripts/bin/android/arm64/simpleperf +++ b/simpleperf/scripts/bin/android/arm64/simpleperf diff --git a/simpleperf/scripts/bin/android/x86/simpleperf b/simpleperf/scripts/bin/android/x86/simpleperf Binary files differindex a6119599..ddbf3954 100755 --- a/simpleperf/scripts/bin/android/x86/simpleperf +++ b/simpleperf/scripts/bin/android/x86/simpleperf diff --git a/simpleperf/scripts/bin/android/x86_64/simpleperf b/simpleperf/scripts/bin/android/x86_64/simpleperf Binary files differindex 0470a5d5..af95c1a2 100755 --- a/simpleperf/scripts/bin/android/x86_64/simpleperf +++ b/simpleperf/scripts/bin/android/x86_64/simpleperf diff --git a/simpleperf/scripts/bin/darwin/x86_64/libsimpleperf_report.dylib b/simpleperf/scripts/bin/darwin/x86_64/libsimpleperf_report.dylib Binary files differindex cbe96228..2dfef2fd 100755 --- a/simpleperf/scripts/bin/darwin/x86_64/libsimpleperf_report.dylib +++ b/simpleperf/scripts/bin/darwin/x86_64/libsimpleperf_report.dylib diff --git a/simpleperf/scripts/bin/darwin/x86_64/simpleperf b/simpleperf/scripts/bin/darwin/x86_64/simpleperf Binary files differindex b056f29d..0dbdbb09 100755 --- a/simpleperf/scripts/bin/darwin/x86_64/simpleperf +++ b/simpleperf/scripts/bin/darwin/x86_64/simpleperf diff --git a/simpleperf/scripts/bin/linux/x86_64/libsimpleperf_report.so b/simpleperf/scripts/bin/linux/x86_64/libsimpleperf_report.so Binary files differindex 480d2890..5f2c5ba5 100755 --- a/simpleperf/scripts/bin/linux/x86_64/libsimpleperf_report.so +++ b/simpleperf/scripts/bin/linux/x86_64/libsimpleperf_report.so diff --git a/simpleperf/scripts/bin/linux/x86_64/simpleperf b/simpleperf/scripts/bin/linux/x86_64/simpleperf Binary files differindex 372d42e2..e9606ff6 100755 --- a/simpleperf/scripts/bin/linux/x86_64/simpleperf +++ b/simpleperf/scripts/bin/linux/x86_64/simpleperf diff --git a/simpleperf/scripts/bin/windows/x86/libsimpleperf_report.dll b/simpleperf/scripts/bin/windows/x86/libsimpleperf_report.dll Binary files differindex 33326d3e..330cad54 100755 --- a/simpleperf/scripts/bin/windows/x86/libsimpleperf_report.dll +++ b/simpleperf/scripts/bin/windows/x86/libsimpleperf_report.dll diff --git a/simpleperf/scripts/bin/windows/x86/libwinpthread-1.dll b/simpleperf/scripts/bin/windows/x86/libwinpthread-1.dll Binary files differindex a41127ab..202ec47b 100755 --- a/simpleperf/scripts/bin/windows/x86/libwinpthread-1.dll +++ b/simpleperf/scripts/bin/windows/x86/libwinpthread-1.dll diff --git a/simpleperf/scripts/bin/windows/x86/simpleperf.exe b/simpleperf/scripts/bin/windows/x86/simpleperf.exe Binary files differindex daee828f..9b263111 100755 --- a/simpleperf/scripts/bin/windows/x86/simpleperf.exe +++ b/simpleperf/scripts/bin/windows/x86/simpleperf.exe diff --git a/simpleperf/scripts/bin/windows/x86_64/libsimpleperf_report.dll b/simpleperf/scripts/bin/windows/x86_64/libsimpleperf_report.dll Binary files differindex 176e8b6a..cc0d878e 100755 --- a/simpleperf/scripts/bin/windows/x86_64/libsimpleperf_report.dll +++ b/simpleperf/scripts/bin/windows/x86_64/libsimpleperf_report.dll diff --git a/simpleperf/scripts/bin/windows/x86_64/libwinpthread-1.dll b/simpleperf/scripts/bin/windows/x86_64/libwinpthread-1.dll Binary files differindex 5a12ce3c..971ffb14 100755 --- a/simpleperf/scripts/bin/windows/x86_64/libwinpthread-1.dll +++ b/simpleperf/scripts/bin/windows/x86_64/libwinpthread-1.dll diff --git a/simpleperf/scripts/bin/windows/x86_64/simpleperf.exe b/simpleperf/scripts/bin/windows/x86_64/simpleperf.exe Binary files differindex 89dbc9b0..2176054f 100755 --- a/simpleperf/scripts/bin/windows/x86_64/simpleperf.exe +++ b/simpleperf/scripts/bin/windows/x86_64/simpleperf.exe |