SlideShare a Scribd company logo
Strategies to improve embedded
Linux applications’ performance
   beyond ordinary techniques
         Anderson Medeiros
       Software Engineer, Motorola
             André Oriani
       Software Engineer, Motorola
Agenda



•  The performance problem faced by Motorola’s IM team
•  Linux’s Dynamic Loader
•  Prelink
•  Libraries Tools
•  Dymically loading Libraries
•  Tuning Shared Libraries
•  UI Time Perception
•  Q & A
Motivation
Our Problem
The basic recipe



Measure


Analyze


Optimize
Our Discover




User clicks   fork()                    main()   Screen.show()



                       DYNAMIC LOADER



                                                      t
Linux’s Dynamic Loader
Loading a dynamically
                              linked program

   .interp
                                        A


Load dynamic
    linker                                         .rel.text
                                    Relocation
                                                  .rel.data

  .dynamic
               Libraries               .init

Dependency
  libraries
                                    Program’s
               Symbol               entry point
                tables
     A
A closer look at relocation

  Relative              Symbol-based
               Type

                                                                Lookup failed
                            Symbol’s
Compute
                              hash                                    Yes
 offset

                                                                  Lookup
                             Hash          Next            No
                                                                   scope
Add load                     bucket        object                  empty
 address

                      Yes                   Next
                             Match
                                           element
                                No         No
           Adjust
                                           Chain     Yes
           address
                                           empty
prelink
Motivation
How does prelink work? I

•  Collects ELF binaries which should be prelinked and all the ELF
   shared libraries they depend on
•  Assigns a unique virtual address space slot for each library and
   relinks the shared library to that base address
•  Resolves all relocations in the binary or library against its
   dependant libraries and stores the relocations into the ELF object
•  Stores a list of all dependant libraries together with their
   checksums into the binary or library
•  For binaries, it also computes a list of conflicts and stores it into a
   special ELF section



      Note: Libraries shall be compiled with the GCC option -fPIC
How does prelink work? II


•  At runtime, the dynamic linker first checks if it is prelinked itself
•  Just before starting an application, the dynamic linker checks if:
   •  There is a library list section created by prelink
   •  They are present in symbol search scope in the same order
   •  None have been modified since prelinking
   •  There aren’t any new shared libraries loaded either
•  If all conditions are satisfied, prelinking is used:
   •  Dynamic linker processes the fixup section and skips all normal
      relocation handling
•  If at least one condition fails:
   •  Dynamic linker continues with normal relocation processing in the
      executable and all shared libraries
Results




          t
Library tools
How to use prelink?


•  prelink –avf --ld-library-path=PATH --dynamic-linker=LDSO
   •  -a --all
       •  Prelink all binaries and dependant libraries found in directory hierarchies
          specified in /etc/prelink.conf
   •  -v --verbose
       •  Verbose mode. Print the virtual address slot assignment to libraries
   •  -f --force
       •  Force re-prelinking even for already prelinked objects for which no
           dependencies changed
   •  --ld-library-path=PATH
       •  Specify special LD_LIBRARY_PATH to be used when prelink queries
          dynamic linker about symbol resolution details
   •  --dynamic-linker=LDSO
       •  Specify alternate dynamic linker instead of the default
Dynamically Loading Libraries
Motivation
Motivation II




If there are any libraries you are going to use
   only on special occasions, it is better to load
   them when they are really needed.
The Basics

#include <dlfcn.h>

void*   dlopen    ( const char* filename, int flags);
void*   dlsym     ( void* handle, const char* symbol);
char*   dlerror   (void);
int     dlclose   (void* handle);




#echo Although you don’t have to link against the
 library
#echo you still have to link against libdl
#
#gcc main.cpp -ldl -o program
Loading C++ Libraries

                                C++ uses mangling!




int mod (int a , int b);                 _Z3sumii
float mod (float a, float b);            _Z3sumff




     math.cpp                                 math.o
The example



class Foo
{
     public:
        Foo(){}
        ~Foo(){}
        void bar(const char * msg)
        {
           std::cout<<"Msg:"<<msg<<std::endl;
        }
  };
The solution

Step 1 Define an interface for your class.




                                 Foo
                         + Foo()
                         + ~Foo()
                         + void bar(const char*)
The solution

Step 1 Define an interface for your class.


                              <<interface>>

                                 Foo
                         + virtual void bar(const
                         char*) = 0




                             FooImpl
                         + Foo()
                         + ~Foo()
                         + void bar(const char*)
The solution - Lib’s Header file

Step 1 Define an interface for your class



#ifndef FOO_H__
#define FOO_H__

class Foo
{
    public:
        virtual void bar (const char*) = 0;
};
The solution - Lib’s Header file

Step 2 Create “C functions” to create and destroy instances
  of your class
Step 3 You might want to create typedefs


 extern "C" Foo* createFoo();
 extern "C" void destroyFoo(Foo*);

 typedef Foo* (*createFoo_t) ();
 typedef void (*destroyFoo_t)(Foo*);

 #endif
The solution - Lib’s Implementation file


Step 4 Implement your interface and “C functions”

 #include "foo.h"                        Foo* createFoo()
 #include <iostream.h>                   {
                                            return new FooImpl();
 class FooImpl:public Foo                 }
 {
  public:                                void destroyFoo(Foo* foo)
    FooImpl(){}                          {
    virtual ~FooImpl(){}                   FooImpl* fooImpl =
    virtual void bar(const char * msg)    static_cast<FooImpl*>(foo);
    {                                      delete fooImpl;
      cout<<"Msg: "<<msg<<endl;          }
    }
 };
The solution - The program
#include <foo.h>
#include <assert.h>
#include <dlfcn.h>

int main()
{
   void* handle = dlopen("./libfoo.so",RTLD_LAZY);
   assert(handle);
   createFoo_t dyn_createFoo = (createFoo_t)dlsym(handle,"createFoo");
   assert(!dlerror());
   Foo* foo = dyn_createFoo();
   if(foo)
       foo->bar("The method bar is being called");
   destroyFoo_t dyn_destroyFoo = (destroyFoo_t)dlsym(handle,"destroyFoo");
   assert(!dlerror());
   dyn_destroyFoo(foo);
   dlclose(handle);
   return 0;
}
Tunning Shared Libraries
Inspiration




     “How To Write Shared Libraries”
          Ulrich Drepper- Red Hat
http://people.redhat.com/drepper/dsohowto.pdf
Less is always better

Keep at minimum…

•  The number of libraries you directly or indirectly depend
•  The size of libraries you link against shall have the smallest size possible
•  The number for search directories for libraries, ideally one directory
•  The number of exported symbols
•  The length of symbols strings
•  The numbers of relocations
Search directories for libs
Reducing search space

Step 1 Set LD_LIBRARY_PATH to empty

Step 2 When linking use the options:
   -rpath-link <dir> to the specify your system’s directory for
    libraries
   -z nodeflib to avoid searching on /lib, /usr/lib and others
    places specified by /etc/ld.so.conf and /etc/ld.so.cache



     #export LD_LIBRARY_PATH=“”
     #gcc main.cpp -Wl,-z,nodeflib -Wl,-rpath-link,/lib
     -lfoo -o program
Reducing exported symbols

Using GCC’s attribute feature

 int localVar __attribute__((visibility(“hidden”)));

 int localFunction() __attribute__((visibility(“hidden”)));

 class Someclass
 {
     private:
        static int a __attribute__((visibility(“hidden”)));
        int b;
        int doSomething(int d)__attribute__((visibility
   (“hidden”)));

      public:
         Someclass(int c);
         int doSomethingImportant();
 };
Reducing exported symbols II

{                                You can tell the linker which
    global:                      symbols shall be exported
     cFunction*;                 using export maps
    extern “C++”
    {
      cppFunction*;
      *Someclass;
      Someclass::Someclass*;    #g++ -shared example.cpp -o
      Someclass::?Someclass*;    libexample.so.1 -Wl,
      Someclass::method*        -soname=libexample.so.1 -Wl,-
    };                          -version-script=example.map

    local: *;

};
Pro and Cons

                Pros                                        Cons

Visibility attribute                         Visibility attribute
•  Compiler can generate optimal             •  GCC’s specific feature;
   code;                                     •  Code become less readable;



Export Maps                                  Export Maps
•  More practical;                           •  No optimization can be done by
•  Centralizes the definition of library’s      compiler because any symbol may
   API;                                         be exported
Restricting symbol string’s lenght

namespace java
{
    namespace lang
    {
       class Math
       {
         static const int PI;
         static double sin(double d);
         static double cos(double d);
         static double FastFourierTransform
               (double a, int b,const int** const c);

        };        _ZN4java4lang4Math2PIE
    }             _ZN4java4lang4Math3sinEd
}                 _ZN4java4lang4Math3cosEd
                  _ZN4java4lang4Math20FastFourierTransformEdiPPKi
Avoiding relocations



  char* a = “ABC”;                    A B C 0
                          .data



const char a[] = “ABC”;             A B C 0
                          .rodata

                                      ELF
UI Time perception
Motivation

X hours to deliver    X hours to deliver
    $ to ship             $ to ship
Package tracking         No tracking
Motivation II
Improving responsiveness

It is not always possible to optimize code because:

•  You might not have access to problematic code;
•  It demands too much effort or it is too risky to change it.
•  There is nothing you can do (I/O latency, etc…).
•  Other reasons ...
Can I postpone ?




loading Plug-Ins …
Can I postpone ?




            Loading
            plug-ins
Can I parallelize?
Can I parallelize?




Sending
 file…
Can I remove it ?
In conclusion …

•  You learned that libraries may play an important role in the startup
   performance of your application;
•  You saw how dynamic link works on Linux;
•  You were introduce to prelink and and became aware of its potential
   to boost the startup;
•  You learned how to load a shared object on demand, preventing
   that some them be a burden at startup;
•  You got some tips on how to write libraries to get the best
   performance;
•  You understood that an UI that provides quick user feedback is more
   important than performance;
Q&A

More Related Content

What's hot

Kotlin- Basic to Advance
Kotlin- Basic to Advance Kotlin- Basic to Advance
Kotlin- Basic to Advance
Coder Tech
 
Detecting Occurrences of Refactoring with Heuristic Search
Detecting Occurrences of Refactoring with Heuristic SearchDetecting Occurrences of Refactoring with Heuristic Search
Detecting Occurrences of Refactoring with Heuristic Search
Shinpei Hayashi
 
Assembler
AssemblerAssembler
Assembler
rahulmnnit_cs
 
Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java Developers
Muhammad Abdullah
 
Basics of building a blackfin application
Basics of building a blackfin applicationBasics of building a blackfin application
Basics of building a blackfin application
Pantech ProLabs India Pvt Ltd
 
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
Bhavsingh Maloth
 
06 - ELF format, knowing your friend
06 - ELF format, knowing your friend06 - ELF format, knowing your friend
06 - ELF format, knowing your friend
Alexandre Moneger
 
Compilation and Execution
Compilation and ExecutionCompilation and Execution
Compilation and Execution
Chong-Kuan Chen
 
Sentence-to-Code Traceability Recovery with Domain Ontologies
Sentence-to-Code Traceability Recovery with Domain OntologiesSentence-to-Code Traceability Recovery with Domain Ontologies
Sentence-to-Code Traceability Recovery with Domain Ontologies
Shinpei Hayashi
 
Inside PHP [OSCON 2012]
Inside PHP [OSCON 2012]Inside PHP [OSCON 2012]
Inside PHP [OSCON 2012]
Tom Lee
 
Python and You Series
Python and You SeriesPython and You Series
Python and You Series
Karthik Prakash
 
MidwestPHP Symfony2 Internals
MidwestPHP Symfony2 InternalsMidwestPHP Symfony2 Internals
MidwestPHP Symfony2 Internals
Raul Fraile
 
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
Bhavsingh Maloth
 
A hands-on introduction to the ELF Object file format
A hands-on introduction to the ELF Object file formatA hands-on introduction to the ELF Object file format
A hands-on introduction to the ELF Object file format
rety61
 
The essence of the VivaCore code analysis library
The essence of the VivaCore code analysis libraryThe essence of the VivaCore code analysis library
The essence of the VivaCore code analysis library
PVS-Studio
 
Inside Python [OSCON 2012]
Inside Python [OSCON 2012]Inside Python [OSCON 2012]
Inside Python [OSCON 2012]
Tom Lee
 
Your Own Metric System
Your Own Metric SystemYour Own Metric System
Your Own Metric System
Erin Dees
 
JDK8 Functional API
JDK8 Functional APIJDK8 Functional API
JDK8 Functional API
Justin Lin
 
Thnad's Revenge
Thnad's RevengeThnad's Revenge
Thnad's Revenge
Erin Dees
 
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
Tom Lee
 

What's hot (20)

Kotlin- Basic to Advance
Kotlin- Basic to Advance Kotlin- Basic to Advance
Kotlin- Basic to Advance
 
Detecting Occurrences of Refactoring with Heuristic Search
Detecting Occurrences of Refactoring with Heuristic SearchDetecting Occurrences of Refactoring with Heuristic Search
Detecting Occurrences of Refactoring with Heuristic Search
 
Assembler
AssemblerAssembler
Assembler
 
Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java Developers
 
Basics of building a blackfin application
Basics of building a blackfin applicationBasics of building a blackfin application
Basics of building a blackfin application
 
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VI BY BHAVSINGH MALOTH
 
06 - ELF format, knowing your friend
06 - ELF format, knowing your friend06 - ELF format, knowing your friend
06 - ELF format, knowing your friend
 
Compilation and Execution
Compilation and ExecutionCompilation and Execution
Compilation and Execution
 
Sentence-to-Code Traceability Recovery with Domain Ontologies
Sentence-to-Code Traceability Recovery with Domain OntologiesSentence-to-Code Traceability Recovery with Domain Ontologies
Sentence-to-Code Traceability Recovery with Domain Ontologies
 
Inside PHP [OSCON 2012]
Inside PHP [OSCON 2012]Inside PHP [OSCON 2012]
Inside PHP [OSCON 2012]
 
Python and You Series
Python and You SeriesPython and You Series
Python and You Series
 
MidwestPHP Symfony2 Internals
MidwestPHP Symfony2 InternalsMidwestPHP Symfony2 Internals
MidwestPHP Symfony2 Internals
 
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTHWEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
WEB PROGRAMMING UNIT VIII BY BHAVSINGH MALOTH
 
A hands-on introduction to the ELF Object file format
A hands-on introduction to the ELF Object file formatA hands-on introduction to the ELF Object file format
A hands-on introduction to the ELF Object file format
 
The essence of the VivaCore code analysis library
The essence of the VivaCore code analysis libraryThe essence of the VivaCore code analysis library
The essence of the VivaCore code analysis library
 
Inside Python [OSCON 2012]
Inside Python [OSCON 2012]Inside Python [OSCON 2012]
Inside Python [OSCON 2012]
 
Your Own Metric System
Your Own Metric SystemYour Own Metric System
Your Own Metric System
 
JDK8 Functional API
JDK8 Functional APIJDK8 Functional API
JDK8 Functional API
 
Thnad's Revenge
Thnad's RevengeThnad's Revenge
Thnad's Revenge
 
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
A(n abridged) tour of the Rust compiler [PDX-Rust March 2014]
 

Similar to Strategies to improve embedded Linux application performance beyond ordinary techniques

Whirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic LinkerWhirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic Linker
Gonçalo Gomes
 
Exciting JavaScript - Part I
Exciting JavaScript - Part IExciting JavaScript - Part I
Exciting JavaScript - Part I
Eugene Lazutkin
 
Native hook mechanism in Android Bionic linker
Native hook mechanism in Android Bionic linkerNative hook mechanism in Android Bionic linker
Native hook mechanism in Android Bionic linker
Kevin Mai-Hsuan Chia
 
Linkers And Loaders
Linkers And LoadersLinkers And Loaders
Linkers And Loaders
Satpal Parmar
 
嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain
艾鍗科技
 
The Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhoneThe Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhone
James Long
 
DEF CON 27 - DIMITRY SNEZHKOV - zombie ant farm practical tips
DEF CON 27 - DIMITRY SNEZHKOV - zombie ant farm practical tipsDEF CON 27 - DIMITRY SNEZHKOV - zombie ant farm practical tips
DEF CON 27 - DIMITRY SNEZHKOV - zombie ant farm practical tips
Felipe Prado
 
Advanced c programming in Linux
Advanced c programming in Linux Advanced c programming in Linux
Advanced c programming in Linux
Mohammad Golyani
 
[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler Collection[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler Collection
Moabi.com
 
Ch3 gnu make
Ch3 gnu makeCh3 gnu make
Ch3 gnu make
艾鍗科技
 
olibc: Another C Library optimized for Embedded Linux
olibc: Another C Library optimized for Embedded Linuxolibc: Another C Library optimized for Embedded Linux
olibc: Another C Library optimized for Embedded Linux
National Cheng Kung University
 
PHP = PHunctional Programming
PHP = PHunctional ProgrammingPHP = PHunctional Programming
PHP = PHunctional Programming
Luis Atencio
 
Exciting JavaScript - Part II
Exciting JavaScript - Part IIExciting JavaScript - Part II
Exciting JavaScript - Part II
Eugene Lazutkin
 
Post exploitation techniques on OSX and Iphone, EuSecWest 2009
Post exploitation techniques on OSX and Iphone, EuSecWest 2009Post exploitation techniques on OSX and Iphone, EuSecWest 2009
Post exploitation techniques on OSX and Iphone, EuSecWest 2009
Vincenzo Iozzo
 
Understanding how C program works
Understanding how C program worksUnderstanding how C program works
Understanding how C program works
MindBridgeTech
 
Libraries
LibrariesLibraries
Libraries
Ashwanth Selvam
 
From gcc to the autotools
From gcc to the autotoolsFrom gcc to the autotools
From gcc to the autotools
Thierry Gayet
 
Eusecwest
EusecwestEusecwest
Eusecwest
zynamics GmbH
 
Functional Programming #FTW
Functional Programming #FTWFunctional Programming #FTW
Functional Programming #FTW
Adriano Bonat
 
cbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxcbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptx
SRamadossbiher
 

Similar to Strategies to improve embedded Linux application performance beyond ordinary techniques (20)

Whirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic LinkerWhirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic Linker
 
Exciting JavaScript - Part I
Exciting JavaScript - Part IExciting JavaScript - Part I
Exciting JavaScript - Part I
 
Native hook mechanism in Android Bionic linker
Native hook mechanism in Android Bionic linkerNative hook mechanism in Android Bionic linker
Native hook mechanism in Android Bionic linker
 
Linkers And Loaders
Linkers And LoadersLinkers And Loaders
Linkers And Loaders
 
嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain
 
The Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhoneThe Scheme Language -- Using it on the iPhone
The Scheme Language -- Using it on the iPhone
 
DEF CON 27 - DIMITRY SNEZHKOV - zombie ant farm practical tips
DEF CON 27 - DIMITRY SNEZHKOV - zombie ant farm practical tipsDEF CON 27 - DIMITRY SNEZHKOV - zombie ant farm practical tips
DEF CON 27 - DIMITRY SNEZHKOV - zombie ant farm practical tips
 
Advanced c programming in Linux
Advanced c programming in Linux Advanced c programming in Linux
Advanced c programming in Linux
 
[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler Collection[Defcon24] Introduction to the Witchcraft Compiler Collection
[Defcon24] Introduction to the Witchcraft Compiler Collection
 
Ch3 gnu make
Ch3 gnu makeCh3 gnu make
Ch3 gnu make
 
olibc: Another C Library optimized for Embedded Linux
olibc: Another C Library optimized for Embedded Linuxolibc: Another C Library optimized for Embedded Linux
olibc: Another C Library optimized for Embedded Linux
 
PHP = PHunctional Programming
PHP = PHunctional ProgrammingPHP = PHunctional Programming
PHP = PHunctional Programming
 
Exciting JavaScript - Part II
Exciting JavaScript - Part IIExciting JavaScript - Part II
Exciting JavaScript - Part II
 
Post exploitation techniques on OSX and Iphone, EuSecWest 2009
Post exploitation techniques on OSX and Iphone, EuSecWest 2009Post exploitation techniques on OSX and Iphone, EuSecWest 2009
Post exploitation techniques on OSX and Iphone, EuSecWest 2009
 
Understanding how C program works
Understanding how C program worksUnderstanding how C program works
Understanding how C program works
 
Libraries
LibrariesLibraries
Libraries
 
From gcc to the autotools
From gcc to the autotoolsFrom gcc to the autotools
From gcc to the autotools
 
Eusecwest
EusecwestEusecwest
Eusecwest
 
Functional Programming #FTW
Functional Programming #FTWFunctional Programming #FTW
Functional Programming #FTW
 
cbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptxcbybalaguruswami-e-180803051831.pptx
cbybalaguruswami-e-180803051831.pptx
 

Recently uploaded

Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Jeffrey Haguewood
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Jeffrey Haguewood
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
Dinusha Kumarasiri
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
LucaBarbaro3
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
Pravash Chandra Das
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
flufftailshop
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
GDSC PJATK
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Wask
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Safe Software
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 

Recently uploaded (20)

Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
 
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
Salesforce Integration for Bonterra Impact Management (fka Social Solutions A...
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
Azure API Management to expose backend services securely
Azure API Management to expose backend services securelyAzure API Management to expose backend services securely
Azure API Management to expose backend services securely
 
Trusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process MiningTrusted Execution Environment for Decentralized Process Mining
Trusted Execution Environment for Decentralized Process Mining
 
Operating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptxOperating System Used by Users in day-to-day life.pptx
Operating System Used by Users in day-to-day life.pptx
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
 
Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!Finale of the Year: Apply for Next One!
Finale of the Year: Apply for Next One!
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Digital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying AheadDigital Marketing Trends in 2024 | Guide for Staying Ahead
Digital Marketing Trends in 2024 | Guide for Staying Ahead
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Driving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success StoryDriving Business Innovation: Latest Generative AI Advancements & Success Story
Driving Business Innovation: Latest Generative AI Advancements & Success Story
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 

Strategies to improve embedded Linux application performance beyond ordinary techniques

  • 1. Strategies to improve embedded Linux applications’ performance beyond ordinary techniques Anderson Medeiros Software Engineer, Motorola André Oriani Software Engineer, Motorola
  • 2. Agenda •  The performance problem faced by Motorola’s IM team •  Linux’s Dynamic Loader •  Prelink •  Libraries Tools •  Dymically loading Libraries •  Tuning Shared Libraries •  UI Time Perception •  Q & A
  • 6. Our Discover User clicks fork() main() Screen.show() DYNAMIC LOADER t
  • 8. Loading a dynamically linked program .interp A Load dynamic linker .rel.text Relocation .rel.data .dynamic Libraries .init Dependency libraries Program’s Symbol entry point tables A
  • 9. A closer look at relocation Relative Symbol-based Type Lookup failed Symbol’s Compute hash Yes offset Lookup Hash Next No scope Add load bucket object empty address Yes Next Match element No No Adjust Chain Yes address empty
  • 12. How does prelink work? I •  Collects ELF binaries which should be prelinked and all the ELF shared libraries they depend on •  Assigns a unique virtual address space slot for each library and relinks the shared library to that base address •  Resolves all relocations in the binary or library against its dependant libraries and stores the relocations into the ELF object •  Stores a list of all dependant libraries together with their checksums into the binary or library •  For binaries, it also computes a list of conflicts and stores it into a special ELF section Note: Libraries shall be compiled with the GCC option -fPIC
  • 13. How does prelink work? II •  At runtime, the dynamic linker first checks if it is prelinked itself •  Just before starting an application, the dynamic linker checks if: •  There is a library list section created by prelink •  They are present in symbol search scope in the same order •  None have been modified since prelinking •  There aren’t any new shared libraries loaded either •  If all conditions are satisfied, prelinking is used: •  Dynamic linker processes the fixup section and skips all normal relocation handling •  If at least one condition fails: •  Dynamic linker continues with normal relocation processing in the executable and all shared libraries
  • 14. Results t
  • 16. How to use prelink? •  prelink –avf --ld-library-path=PATH --dynamic-linker=LDSO •  -a --all •  Prelink all binaries and dependant libraries found in directory hierarchies specified in /etc/prelink.conf •  -v --verbose •  Verbose mode. Print the virtual address slot assignment to libraries •  -f --force •  Force re-prelinking even for already prelinked objects for which no dependencies changed •  --ld-library-path=PATH •  Specify special LD_LIBRARY_PATH to be used when prelink queries dynamic linker about symbol resolution details •  --dynamic-linker=LDSO •  Specify alternate dynamic linker instead of the default
  • 19. Motivation II If there are any libraries you are going to use only on special occasions, it is better to load them when they are really needed.
  • 20. The Basics #include <dlfcn.h> void* dlopen ( const char* filename, int flags); void* dlsym ( void* handle, const char* symbol); char* dlerror (void); int dlclose (void* handle); #echo Although you don’t have to link against the library #echo you still have to link against libdl # #gcc main.cpp -ldl -o program
  • 21.
  • 22. Loading C++ Libraries C++ uses mangling! int mod (int a , int b); _Z3sumii float mod (float a, float b); _Z3sumff math.cpp math.o
  • 23. The example class Foo { public: Foo(){} ~Foo(){} void bar(const char * msg) { std::cout<<"Msg:"<<msg<<std::endl; } };
  • 24. The solution Step 1 Define an interface for your class. Foo + Foo() + ~Foo() + void bar(const char*)
  • 25. The solution Step 1 Define an interface for your class. <<interface>> Foo + virtual void bar(const char*) = 0 FooImpl + Foo() + ~Foo() + void bar(const char*)
  • 26. The solution - Lib’s Header file Step 1 Define an interface for your class #ifndef FOO_H__ #define FOO_H__ class Foo { public: virtual void bar (const char*) = 0; };
  • 27. The solution - Lib’s Header file Step 2 Create “C functions” to create and destroy instances of your class Step 3 You might want to create typedefs extern "C" Foo* createFoo(); extern "C" void destroyFoo(Foo*); typedef Foo* (*createFoo_t) (); typedef void (*destroyFoo_t)(Foo*); #endif
  • 28. The solution - Lib’s Implementation file Step 4 Implement your interface and “C functions” #include "foo.h" Foo* createFoo() #include <iostream.h> { return new FooImpl(); class FooImpl:public Foo } { public: void destroyFoo(Foo* foo) FooImpl(){} { virtual ~FooImpl(){} FooImpl* fooImpl = virtual void bar(const char * msg) static_cast<FooImpl*>(foo); { delete fooImpl; cout<<"Msg: "<<msg<<endl; } } };
  • 29. The solution - The program #include <foo.h> #include <assert.h> #include <dlfcn.h> int main() { void* handle = dlopen("./libfoo.so",RTLD_LAZY); assert(handle); createFoo_t dyn_createFoo = (createFoo_t)dlsym(handle,"createFoo"); assert(!dlerror()); Foo* foo = dyn_createFoo(); if(foo) foo->bar("The method bar is being called"); destroyFoo_t dyn_destroyFoo = (destroyFoo_t)dlsym(handle,"destroyFoo"); assert(!dlerror()); dyn_destroyFoo(foo); dlclose(handle); return 0; }
  • 31. Inspiration “How To Write Shared Libraries” Ulrich Drepper- Red Hat http://people.redhat.com/drepper/dsohowto.pdf
  • 32. Less is always better Keep at minimum… •  The number of libraries you directly or indirectly depend •  The size of libraries you link against shall have the smallest size possible •  The number for search directories for libraries, ideally one directory •  The number of exported symbols •  The length of symbols strings •  The numbers of relocations
  • 34. Reducing search space Step 1 Set LD_LIBRARY_PATH to empty Step 2 When linking use the options: -rpath-link <dir> to the specify your system’s directory for libraries -z nodeflib to avoid searching on /lib, /usr/lib and others places specified by /etc/ld.so.conf and /etc/ld.so.cache #export LD_LIBRARY_PATH=“” #gcc main.cpp -Wl,-z,nodeflib -Wl,-rpath-link,/lib -lfoo -o program
  • 35. Reducing exported symbols Using GCC’s attribute feature int localVar __attribute__((visibility(“hidden”))); int localFunction() __attribute__((visibility(“hidden”))); class Someclass { private: static int a __attribute__((visibility(“hidden”))); int b; int doSomething(int d)__attribute__((visibility (“hidden”))); public: Someclass(int c); int doSomethingImportant(); };
  • 36. Reducing exported symbols II { You can tell the linker which global: symbols shall be exported cFunction*; using export maps extern “C++” { cppFunction*; *Someclass; Someclass::Someclass*; #g++ -shared example.cpp -o Someclass::?Someclass*; libexample.so.1 -Wl, Someclass::method* -soname=libexample.so.1 -Wl,- }; -version-script=example.map local: *; };
  • 37. Pro and Cons Pros Cons Visibility attribute Visibility attribute •  Compiler can generate optimal •  GCC’s specific feature; code; •  Code become less readable; Export Maps Export Maps •  More practical; •  No optimization can be done by •  Centralizes the definition of library’s compiler because any symbol may API; be exported
  • 38. Restricting symbol string’s lenght namespace java { namespace lang { class Math { static const int PI; static double sin(double d); static double cos(double d); static double FastFourierTransform (double a, int b,const int** const c); }; _ZN4java4lang4Math2PIE } _ZN4java4lang4Math3sinEd } _ZN4java4lang4Math3cosEd _ZN4java4lang4Math20FastFourierTransformEdiPPKi
  • 39. Avoiding relocations char* a = “ABC”; A B C 0 .data const char a[] = “ABC”; A B C 0 .rodata ELF
  • 41. Motivation X hours to deliver X hours to deliver $ to ship $ to ship Package tracking No tracking
  • 43. Improving responsiveness It is not always possible to optimize code because: •  You might not have access to problematic code; •  It demands too much effort or it is too risky to change it. •  There is nothing you can do (I/O latency, etc…). •  Other reasons ...
  • 44. Can I postpone ? loading Plug-Ins …
  • 45. Can I postpone ? Loading plug-ins
  • 48. Can I remove it ?
  • 49. In conclusion … •  You learned that libraries may play an important role in the startup performance of your application; •  You saw how dynamic link works on Linux; •  You were introduce to prelink and and became aware of its potential to boost the startup; •  You learned how to load a shared object on demand, preventing that some them be a burden at startup; •  You got some tips on how to write libraries to get the best performance; •  You understood that an UI that provides quick user feedback is more important than performance;
  • 50. Q&A