Re: [PATCH v2 1/2] CMakeLists.txt: enable SHARED and STATIC lib creation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Em Tue, Jun 08, 2021 at 12:50:13AM +0530, Deepak Kumar Mishra escreveu:
> CMakeLists.txt does not allow creation of static library and link applications
> accordingly.
> 
> Creation of SHARED and STATIC should be allowed using -DBUILD_SHARED_LIBS
> If -DBUILD_SHARED_LIBS option is not supplied, CMakeLists.txt sets it to ON.
> 
> Ex:
> cmake -D__LIB=lib -DBUILD_SHARED_LIBS=OFF ..
> cmake -D__LIB=lib -DBUILD_SHARED_LIBS=ON ..

Had to do some fixups due to a previous patch touching CMakeLists.txt,
please check below.

I tested it and added some performance notes.

Thanks!

- Arnaldo

commit aa2027708659f172780f85698f14303c7de6a1d2
Author: Deepak Kumar Mishra <deepakkumar.mishra@xxxxxxx>
Date:   Tue Jun 8 00:50:13 2021 +0530

    CMakeLists.txt: Enable SHARED and STATIC lib creation
    
    CMakeLists.txt does not allow creation of static library and link applications
    accordingly.
    
    Creation of SHARED and STATIC should be allowed using -DBUILD_SHARED_LIBS
    If -DBUILD_SHARED_LIBS option is not supplied, CMakeLists.txt sets it to ON.
    
    Ex:
    
      $ cmake -D__LIB=lib -DBUILD_SHARED_LIBS=OFF ..
      $ cmake -D__LIB=lib -DBUILD_SHARED_LIBS=ON ..
    
    Committer testing:
    
    I had to fixup it a bit due to changes related to allowing building with
    libbpf-devel, test resuts:
    
    With the default, i.e. creating libdwarves.so and using it:
    
      ⬢[acme@toolbox pahole]$ rm -f vmlinux.btf ; perf stat -r5 pahole -j vmlinux.btf vmlinux && perf stat -r5 btfdiff vmlinux vmlinux.btf
    
       Performance counter stats for 'pahole -j vmlinux.btf vmlinux' (5 runs):
    
                8,612.69 msec task-clock:u              #    1.014 CPUs utilized            ( +-  0.68% )
                       0      context-switches:u        #    0.000 /sec
                       0      cpu-migrations:u          #    0.000 /sec
                 775,702      page-faults:u             #   91.330 K/sec                    ( +-  0.00% )
          33,720,048,514      cycles:u                  #    3.970 GHz                      ( +-  0.38% )  (83.33%)
             689,752,139      stalled-cycles-frontend:u #    2.05% frontend cycles idle     ( +-  2.57% )  (83.33%)
           5,070,723,369      stalled-cycles-backend:u  #   15.04% backend cycles idle      ( +-  1.20% )  (83.34%)
          77,270,640,084      instructions:u            #    2.29  insn per cycle
                                                        #    0.07  stalled cycles per insn  ( +-  0.01% )  (83.34%)
          18,164,028,242      branches:u                #    2.139 G/sec                    ( +-  0.04% )  (83.33%)
             150,194,338      branch-misses:u           #    0.83% of all branches          ( +-  0.17% )  (83.32%)
    
                  8.4979 +- 0.0590 seconds time elapsed  ( +-  0.69% )
    
       Performance counter stats for 'btfdiff vmlinux vmlinux.btf' (5 runs):
    
                7,001.79 msec task-clock:u              #    1.006 CPUs utilized            ( +-  1.02% )
                       0      context-switches:u        #    0.000 /sec
                       0      cpu-migrations:u          #    0.000 /sec
                 727,980      page-faults:u             #  104.736 K/sec                    ( +-  0.00% )
          26,912,307,448      cycles:u                  #    3.872 GHz                      ( +-  0.31% )  (83.33%)
             509,467,882      stalled-cycles-frontend:u #    1.90% frontend cycles idle     ( +-  2.44% )  (83.33%)
           3,602,777,263      stalled-cycles-backend:u  #   13.43% backend cycles idle      ( +-  1.34% )  (83.32%)
          66,192,815,701      instructions:u            #    2.47  insn per cycle
                                                        #    0.06  stalled cycles per insn  ( +-  0.01% )  (83.35%)
          15,753,663,095      branches:u                #    2.267 G/sec                    ( +-  0.02% )  (83.35%)
              98,345,696      branch-misses:u           #    0.62% of all branches          ( +-  0.14% )  (83.34%)
    
                  6.9586 +- 0.0720 seconds time elapsed  ( +-  1.03% )
    
      ⬢[acme@toolbox pahole]$
    
    Then building with:
    
      ⬢[acme@toolbox pahole]$ rm -rf build ; mkdir build ; cd build ; cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release .. ; cd .. ; make -C build
      ⬢[acme@toolbox pahole]$ ldd build/pahole
            linux-vdso.so.1 (0x00007ffff0172000)
            libdw.so.1 => /lib64/libdw.so.1 (0x00007fdd3905d000)
            libelf.so.1 => /lib64/libelf.so.1 (0x00007fdd39042000)
            libz.so.1 => /lib64/libz.so.1 (0x00007fdd39028000)
            libc.so.6 => /lib64/libc.so.6 (0x00007fdd38e59000)
            libdl.so.2 => /lib64/libdl.so.2 (0x00007fdd38e52000)
            libzstd.so.1 => /lib64/libzstd.so.1 (0x00007fdd38d5c000)
            liblzma.so.5 => /lib64/liblzma.so.5 (0x00007fdd38d2e000)
            libbz2.so.1 => /lib64/libbz2.so.1 (0x00007fdd38d1b000)
            libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fdd38cfa000)
            /lib64/ld-linux-x86-64.so.2 (0x00007fdd390ff000)
      ⬢[acme@toolbox pahole]$
    
    We get some performance improvement:
    
    - First is encoding detached BTF, i.e. read DWARF, generate BTF.
    - Second is about loading both DWARF and BTF, producing output for both, that must match.
    
      ⬢[acme@toolbox pahole]$ rm -f vmlinux.btf ; perf stat -r5 pahole -j vmlinux.btf vmlinux && perf stat -r5 btfdiff vmlinux vmlinux.btf
    
       Performance counter stats for 'pahole -j vmlinux.btf vmlinux' (5 runs):
    
                8,566.34 msec task-clock:u              #    1.025 CPUs utilized            ( +-  0.85% )
                       0      context-switches:u        #    0.000 /sec
                       0      cpu-migrations:u          #    0.000 /sec
                 775,685      page-faults:u             #   92.865 K/sec                    ( +-  0.00% )
          33,333,991,512      cycles:u                  #    3.991 GHz                      ( +-  0.23% )  (83.34%)
             799,187,919      stalled-cycles-frontend:u #    2.42% frontend cycles idle     ( +-  1.95% )  (83.33%)
           5,157,722,792      stalled-cycles-backend:u  #   15.61% backend cycles idle      ( +-  1.25% )  (83.33%)
          76,273,972,066      instructions:u            #    2.31  insn per cycle
                                                        #    0.07  stalled cycles per insn  ( +-  0.03% )  (83.33%)
          17,843,388,470      branches:u                #    2.136 G/sec                    ( +-  0.05% )  (83.33%)
             150,507,690      branch-misses:u           #    0.84% of all branches          ( +-  0.46% )  (83.33%)
    
                  8.3561 +- 0.0729 seconds time elapsed  ( +-  0.87% )
    
       Performance counter stats for 'btfdiff vmlinux vmlinux.btf' (5 runs):
    
                6,685.39 msec task-clock:u              #    0.986 CPUs utilized            ( +-  0.54% )
                       0      context-switches:u        #    0.000 /sec
                       0      cpu-migrations:u          #    0.000 /sec
                 727,931      page-faults:u             #  107.475 K/sec                    ( +-  0.00% )
          26,149,371,139      cycles:u                  #    3.861 GHz                      ( +-  0.15% )  (83.36%)
             525,918,808      stalled-cycles-frontend:u #    2.00% frontend cycles idle     ( +-  2.96% )  (83.33%)
           3,547,589,546      stalled-cycles-backend:u  #   13.51% backend cycles idle      ( +-  1.28% )  (83.35%)
          65,389,507,702      instructions:u            #    2.49  insn per cycle
                                                        #    0.06  stalled cycles per insn  ( +-  0.03% )  (83.29%)
          15,553,175,605      branches:u                #    2.296 G/sec                    ( +-  0.02% )  (83.34%)
              97,812,971      branch-misses:u           #    0.63% of all branches          ( +-  0.23% )  (83.34%)
    
                  6.7784 +- 0.0359 seconds time elapsed  ( +-  0.53% )
    
      ⬢[acme@toolbox pahole]$
    
    Signed-off-by: Deepak Kumar Mishra <deepakkumar.mishra@xxxxxxx>
    Tested-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
    Cc: Qais Yousef <qais.yousef@xxxxxxx>
    Signed-off-by: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>

diff --git a/CMakeLists.txt b/CMakeLists.txt
index df16b8ec3031f3e6..669ea59167c7ef65 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -47,6 +47,11 @@ endif (NOT CMAKE_BUILD_TYPE)
 set(CMAKE_C_FLAGS_DEBUG "-Wall -Werror -ggdb -O0")
 set(CMAKE_C_FLAGS_RELEASE "-Wall -O2")
 
+if (NOT DEFINED BUILD_SHARED_LIBS)
+	set (BUILD_SHARED_LIBS ON)
+	message(STATUS "Setting BUILD_SHARED_LIBS = ${BUILD_SHARED_LIBS}")
+endif (NOT DEFINED BUILD_SHARED_LIBS)
+
 # Just for grepping, DWARVES_VERSION isn't used anywhere anymore
 # add_definitions(-D_GNU_SOURCE -DDWARVES_VERSION="v1.21")
 add_definitions(-D_GNU_SOURCE -DDWARVES_MAJOR_VERSION=1)
@@ -111,18 +116,18 @@ set(dwarves_LIB_SRCS dwarves.c dwarves_fprintf.c gobuffer.c strings.c
 if (NOT LIBBPF_FOUND)
 	list(APPEND dwarves_LIB_SRCS $<TARGET_OBJECTS:bpf>)
 endif()
-add_library(dwarves SHARED ${dwarves_LIB_SRCS})
+add_library(dwarves ${dwarves_LIB_SRCS})
 set_target_properties(dwarves PROPERTIES VERSION 1.0.0 SOVERSION 1)
 set_target_properties(dwarves PROPERTIES INTERFACE_LINK_LIBRARIES "")
 target_link_libraries(dwarves ${DWARF_LIBRARIES} ${ZLIB_LIBRARIES} ${LIBBPF_LIBRARIES})
 
 set(dwarves_emit_LIB_SRCS dwarves_emit.c)
-add_library(dwarves_emit SHARED ${dwarves_emit_LIB_SRCS})
+add_library(dwarves_emit ${dwarves_emit_LIB_SRCS})
 set_target_properties(dwarves_emit PROPERTIES VERSION 1.0.0 SOVERSION 1)
 target_link_libraries(dwarves_emit dwarves)
 
 set(dwarves_reorganize_LIB_SRCS dwarves_reorganize.c)
-add_library(dwarves_reorganize SHARED ${dwarves_reorganize_LIB_SRCS})
+add_library(dwarves_reorganize ${dwarves_reorganize_LIB_SRCS})
 set_target_properties(dwarves_reorganize PROPERTIES VERSION 1.0.0 SOVERSION 1)
 target_link_libraries(dwarves_reorganize dwarves)
 
@@ -169,8 +174,8 @@ target_link_libraries(syscse dwarves)
 install(TARGETS codiff ctracer dtagnames pahole pdwtags
 		pfunct pglobal prefcnt scncopy syscse RUNTIME DESTINATION
 		${CMAKE_INSTALL_PREFIX}/bin)
-install(TARGETS dwarves LIBRARY DESTINATION ${LIB_INSTALL_DIR})
-install(TARGETS dwarves dwarves_emit dwarves_reorganize LIBRARY DESTINATION ${LIB_INSTALL_DIR})
+install(TARGETS dwarves LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
+install(TARGETS dwarves dwarves_emit dwarves_reorganize LIBRARY DESTINATION ${LIB_INSTALL_DIR} ARCHIVE DESTINATION ${LIB_INSTALL_DIR})
 install(FILES dwarves.h dwarves_emit.h dwarves_reorganize.h
 	      dutil.h gobuffer.h list.h rbtree.h pahole_strings.h
 	      btf_encoder.h config.h ctf_encoder.h ctf.h



[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux