+ All Categories
Home > Documents > Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX...

Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX...

Date post: 22-Sep-2020
Category:
Upload: others
View: 3 times
Download: 0 times
Share this document with a friend
23
Exploring Profile Guided Optimization of the Linux Kernel ian Bearman Principal Software Engineering Manger @ Microsoft [email protected] @manbearian https://www.linkedin.com/in/manbearian/ https://github.com/manbearian
Transcript
Page 1: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Exploring Profile Guided Optimization of the Linux Kernel

ian Bearman

Principal Software Engineering Manger @ Microsoft

[email protected]

@manbearian

https://www.linkedin.com/in/manbearian/

https://github.com/manbearian

Page 2: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV
Page 3: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Introduction

Page 4: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

GNU/Linux Dev Tools @ Microsoft

Our Mission: Support Linux dev tooling needs for Microsoft

• Across Multiple Platforms• Azure Cloud

• Half (or more) of all instance in Azure are running Linux!

• Windows Subsystem for Linux• IoT (such as Azure Sphere)

• Across Multiple Features and Tools• Correctness, Performance, and Security

Page 5: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Optimize Single Service Instance

Internal customer request• Linux-hosted cloud service• Instance runs a single service• 64-bit x86 and ARM• Willing to build their own kernel• Goal: Maximize Performance

How can a tools team help?• Brainstorming: Profile Guided Optimization!

Complications• Workload isn’t fully known (service and architecture isn’t completed)!• No benchmarks provided

Page 6: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Background

Page 7: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

LTO and PGO – quick primer

PGO - Profile Guided Optimization (aka Pogo, FDO, -fprofile-use)• Consume profile information to improve code generation• Allow placement of code (and data) for spatial and temporal locality• Drive inlining decisions (inline hot paths, ignore cold paths)• Intra-function Code layout

LTO - Link Time Optimization (aka LTCG, WPA/WPO/IPA)• Compile entire module/binary at once• Inline across CPP files• Interprocedural analysis and optimization• Optimize using “whole program view”

Page 8: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

GCC 9.2.1 SPEC 2017ARM64

Page 9: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Previous Research

PGO + Linux Kernel

Yuan (2014)• http://sei.pku.edu.cn/~yaoguo/papers/Yuan-ApSys-14.pdf

Yuan (2015)• http://sei.pku.edu.cn/~yaoguo/papers/Yuan-APSys-15.pdf

Page 10: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Methodology

Page 11: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Setup

Software: Ubuntu 19.10 with GCC 9.2.1, binutils 2.33, kernel 5.3

Hardware: Marvell Thunder X2 (ARM64)

Enabling LTO + PGO• We reached out to Andi Kleen for help with LTO• After a few back-and-forths (and one patch) we had LTO working• Docs + trial-and-error all that was needed to get PGO working

Page 12: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Profiling the Kernel

Instrumentation-based profiling

Kernel Configuration:

• Build and install kernel with instrumentation• Run scenario• After run trace location is @

/sys/kernel/debug/gcov*.gcda; *.gcnoowned by `root` (so chown/chmod)

CONFIG_DEBUG_FS=yCONFIG_GCOV_KERNEL=yCONFIG_GCOV_PROFILE_ALL=y

Page 13: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Optimizing the Kernel

Remember: clean your build• follow normal clean steps; and• Ensure previous coverage options are disabled!

GCC expects the profile data to be in a specific location in the kernel build directory or in a flattened path

Set build flags to add `-fprofile-use`

Work around breakages

KCFLAGS="-fprofile-use=/home/user81/gcov-test/generic-instr/gcov -Wno-coverage-mismatch -Wno-error=coverage-mismatch"

CFLAGS_lockref.o=-fno-profile-use -O0 to linux/lib/Makefile.

'#home#user81#linux-build#linux-5.3.0#debian#build#build-generic#some#dir#with#a#file.gcda

Page 14: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Results

Page 15: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Scenarios

redis Popular database, cache, hash, BSD licensed

built-in benchmarking (redis-benchmark)

https://redis.io

Page 16: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Redis

0.95

0.96

0.97

0.98

0.99

1

1.01

1.02

1.03

1.04

1.05

redis-benchmark on ARM64Baseline-5.3 O3-5.3 PGO-5.3

Page 17: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Redis

0.95

0.96

0.97

0.98

0.99

1

1.01

1.02

1.03

1.04

1.05

redis-benchmark on ARM64Baseline-5.3 O3-5.3 PGO-5.3

Page 18: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Conclusion & Wrap-up

Page 19: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Conclusion

We saw wins with PGO in Redis• Close to the limit for non-kernel bound scenario

We would a better measurement of core kernel performance• Stable benchmarks for filesystem, network, scheduler, etc.

We’d love to see more• Microsoft Windows heavily utilizes both LTO (LTCG) and PGO• Windows sees 5-20% improvements from PGO

• we want to investigate if this is relatable

Cyclic Dependency• Usage drives quality; quality drives usage

Page 20: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Acknowledgements

Fellow Team MembersRoman “@kromych” (Microsoft)Di "Modi" Mo (Facebook)

Other FolksAndi Kleen (Intel)

Page 21: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Q & A

Page 22: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Jobs!

Microsoft is hiring Linux developers and folks with Linux experience!

https://careers.microsoft.com/us/en/search-results?keywords=Linux

Page 23: Exploring Profile Guided Optimization of the Linux Kernel - FINAL · 2020. 8. 26. · KWWS VHL SNX HGX FQ a\DRJXR SDSHUV

Thank [email protected]

@manbearian

https://www.linkedin.com/in/manbearian/

https://github.com/manbearian


Recommended