<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">
I’m having code size issues using the sdbusplus library. As I mentioned during the conference, I suspected it was a combinatorial expansion forced by the use of variant in a template. As a result, my “tiny” FRU dumping utility uses almost 3 MB on Tioga Pass
and can only be stored on /tmp.. My sensor dumping utility, using the same structure by way of calling GetManagedObjects weighed in close to 9 MB, presumably because there are several loops that walk the structure, with even more templated function instantiation,
which sux0rs when you only have a 32MB part. Even the best darn FRU utility in the world isn’t worth 25% of your available code space.
<div class=""><br class="">
</div>
<div class="">I hope I’m doing something wrong. The data structure is as recommended by Ed Tanous and I don’t see an obvious way to simplify the variant out of the structure. My current thoughts for proceeding are to (a) write my own task specific D-Bus library
that isn’t as template-happy or (b) to re-implement with low-level D-Bus calls. Neither is particularly desirable since I would think all components should use the same library to access the D-Bus</div>
<div class=""><br class="">
</div>
<div class="">My colleagues suspected I was statically linking the sdbusplus libraries, but as I’ll prove in the next section, the bloat doesn’t occur until I have code that touches the D-Bus response, and the code size scales directly with the number of variant
types. That should be orthogonal to the penalty for linking statically, unless the template permutations are in the library itself, but libsdbusplus.so is a meager <span style="font-family: Menlo; font-size: 11px;" class="">18,140 bytes.</span><span style="font-family: "Helvetica Neue";" class="">Code
size here is increasing by 80,345 bytes per additional variant type, which is 4x the size of the entire SO.</span></div>
<div class=""><span style="font-family: "Helvetica Neue";" class=""><br class="">
</span></div>
<div class=""><font face="Helvetica Neue" class="">My presumption is that I’m off in the weeds, and someone will kindly guide me back to the main road.</font></div>
<div class=""><span style="font-family: "Helvetica Neue";" class=""><br class="">
</span></div>
<div class=""><span style="font-family: "Helvetica Neue";" class="">Experiment 1: A minimal application</span></div>
<div class="">
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
#include <iostream></div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
int main( int argc, char *argv ) {</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
<span class="Apple-tab-span" style="white-space:pre"></span>std::cout << "Sizing app" << std::endl;</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
<span class="Apple-tab-span" style="white-space:pre"></span>}</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
add_executable( sizing.bin source/sizing.cpp )</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
target_link_libraries( sizing.bin sdbusplus.so )</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
install( TARGETS sizing.bin )</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
104,828 bytes with or without link to sdbusplus.so</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
——————————————————————————————</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
Experiment 2: Add code to perform a GetManagedObjects. This increases the code payload substantially more than expected, but is still reasonable.</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
#include <iostream></div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
#include <sdbusplus/bus.hpp></div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
int main( int argc, char **argv ) {</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
<span class="Apple-tab-span" style="white-space:pre"></span>std::cout << "Sizing app" << std::endl;</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
auto bus = sdbusplus::bus::new_default_system();</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
auto method = bus.new_method_call("xyz.openbmc_project.FruDevice",</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
"/",</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
"org.freedesktop.DBus.ObjectManager",</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
"GetManagedObjects");</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
auto response = bus.call(method);</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
<span class="Apple-tab-span" style="white-space:pre"></span>}</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
add_executable( sizing.bin source/sizing.cpp )</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
target_link_libraries( sizing.bin sdbusplus.so</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
systemd.so )</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
install( TARGETS sizing.bin )</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
255,212 bytes</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
——————————————————————————————————</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
Experiment 3: Added the structure to read the result into, and the size grows too 10x. Note that I’m not even doing anything with the result. It’s the interaction between the “read” and the storage type.</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
#include <iostream></div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
#include <sdbusplus/bus.hpp></div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
#include <boost/container/flat_map.hpp></div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
typedef sdbusplus::message::variant< std::string,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
bool,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
uint8_t,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
int16_t,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
uint16_t,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
int32_t,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
uint32_t,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
int64_t,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
uint64_t,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
double,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
std::vector<std::string>> AnyType;</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
typedef boost::container::flat_map< std::string, AnyType> AnyTypeMap;</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
typedef std::vector<std::pair<std::string, AnyTypeMap>> NamedArrayOfAnyTypeMaps;</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
typedef std::vector<std::pair<sdbusplus::message::object_path, NamedArrayOfAnyTypeMaps>> ArrayOfObjectPathsAndTieredAnyTypeMaps;</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
int main( int argc, char **argv ) {</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
ArrayOfObjectPathsAndTieredAnyTypeMaps result;</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
<span class="Apple-tab-span" style="white-space:pre"></span>std::cout << "Sizing app" << std::endl;</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
auto bus = sdbusplus::bus::new_default_system();</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
auto method = bus.new_method_call("xyz.openbmc_project.FruDevice",</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
"/",</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
"org.freedesktop.DBus.ObjectManager",</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
"GetManagedObjects");</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
auto response = bus.call(method);</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
response.read( result );</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
<span class="Apple-tab-span" style="white-space:pre"></span>}</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
2,274,736 bytes</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
—————————————————————————————————————</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
Experiment 4: If I reduce the number of permutations to 2, the code payload remains huge, but shrinks.</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
#include <iostream></div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
#include <sdbusplus/bus.hpp></div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
#include <boost/container/flat_map.hpp></div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
typedef sdbusplus::message::variant< std::string,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
// bool,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
// uint8_t,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
// int16_t,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
// uint16_t,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
// int32_t,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
// uint32_t,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
// int64_t,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
// uint64_t,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
// double,</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
std::vector<std::string>> AnyType;</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
typedef boost::container::flat_map< std::string, AnyType> AnyTypeMap;</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
typedef std::vector<std::pair<std::string, AnyTypeMap>> NamedArrayOfAnyTypeMaps;</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
typedef std::vector<std::pair<sdbusplus::message::object_path, NamedArrayOfAnyTypeMaps>> ArrayOfObjectPathsAndTieredAnyTypeMaps;</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
int main( int argc, char **argv ) {</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
ArrayOfObjectPathsAndTieredAnyTypeMaps result;</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
<span class="Apple-tab-span" style="white-space:pre"></span>std::cout << "Sizing app" << std::endl;</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
auto bus = sdbusplus::bus::new_default_system();</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
auto method = bus.new_method_call("xyz.openbmc_project.FruDevice",</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
"/",</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
"org.freedesktop.DBus.ObjectManager",</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
"GetManagedObjects");</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
auto response = bus.call(method);</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
response.read( result );</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
<span class="Apple-tab-span" style="white-space:pre"></span>}</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue"; min-height: 14px;" class="">
<br class="">
</div>
<div style="margin: 0px; font-stretch: normal; line-height: normal; font-family: "Helvetica Neue";" class="">
1,551,624 bytes</div>
</div>
</body>
</html>