Add support for multithreaded lzma encoder

liblzma already has support for a multithreaded encoder.  The plumbing
needed to enable it is pretty small, and can be done at runtime.  This
sets us up to compress more than 1 core of data, potentially.

I did some basic profiling testing, and the block size should be left at
the default for optimal performance.  I made it configurable otherwise
it is so big that the tests don't pass.  Decreasing the block size
increases overhead and decreases performance significantly.  The timeout
parameter seems to have little effect for reasonable workloads.

Change-Id: Ia886bc8576db19f1b59a76b41dc7cdc2e85d52bd
Signed-off-by: Austin Schuh <austin.schuh@bluerivertech.com>
diff --git a/aos/events/logging/lzma_encoder_test.cc b/aos/events/logging/lzma_encoder_test.cc
index bbd0c60..1b8c895 100644
--- a/aos/events/logging/lzma_encoder_test.cc
+++ b/aos/events/logging/lzma_encoder_test.cc
@@ -5,12 +5,37 @@
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
+DECLARE_int32(lzma_threads);
+
 namespace aos::logger::testing {
 
 INSTANTIATE_TEST_SUITE_P(
+    MtLzma, BufferEncoderTest,
+    ::testing::Combine(::testing::Values([]() {
+                         FLAGS_lzma_threads = 3;
+                         return std::make_unique<LzmaEncoder>(2, 4096);
+                       }),
+                       ::testing::Values([](std::string_view filename) {
+                         return std::make_unique<LzmaDecoder>(filename);
+                       }),
+                       ::testing::Range(0, 100)));
+
+INSTANTIATE_TEST_SUITE_P(
+    MtLzmaThreaded, BufferEncoderTest,
+    ::testing::Combine(::testing::Values([]() {
+                         FLAGS_lzma_threads = 3;
+                         return std::make_unique<LzmaEncoder>(5, 4096);
+                       }),
+                       ::testing::Values([](std::string_view filename) {
+                         return std::make_unique<ThreadedLzmaDecoder>(filename);
+                       }),
+                       ::testing::Range(0, 100)));
+
+INSTANTIATE_TEST_SUITE_P(
     Lzma, BufferEncoderTest,
     ::testing::Combine(::testing::Values([]() {
-                         return std::make_unique<LzmaEncoder>(2);
+                         FLAGS_lzma_threads = 1;
+                         return std::make_unique<LzmaEncoder>(2, 4096);
                        }),
                        ::testing::Values([](std::string_view filename) {
                          return std::make_unique<LzmaDecoder>(filename);
@@ -20,7 +45,8 @@
 INSTANTIATE_TEST_SUITE_P(
     LzmaThreaded, BufferEncoderTest,
     ::testing::Combine(::testing::Values([]() {
-                         return std::make_unique<LzmaEncoder>(2);
+                         FLAGS_lzma_threads = 1;
+                         return std::make_unique<LzmaEncoder>(5, 4096);
                        }),
                        ::testing::Values([](std::string_view filename) {
                          return std::make_unique<ThreadedLzmaDecoder>(filename);