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

Re: [UNIKRAFT PATCH v2 1/2] build: Add PGO support



Hi Razvan,

The reason I had to use the profile-generate flag only when compiling the application to be executed in Unikraft was that the functions in the libgcov library use structures as TLS and TCB. Thus, if I used the profile-generate flag to compile all the libraries, including the Unikernel, I would receive errors. So, before calling each function in the system, a profiling function is called from the libgcov library, and this function needed the allocated TLS and TCB structures.

Alice

În sâm., 21 nov. 2020 la 18:15, Razvan Deaconescu <razvan.deaconescu@xxxxxxxxx> a scris:
Hi, Alice, Simon.

I applied these patches and it went OK to generate PGO files (the
.gcda file generated by gcov).

I've two remarks:
* LDFLAGS is used for linking, not for compiling. I don't see why
$(COMPFLAGS) should be here. Maybe it should actually be CFLAGS. The
-fprofile-generate option needs to be part of both the compiling and
linking phases, while the -fprofile-use option needs to only be part
of the compiling phase.
* The application / library Makefile needs to be appended with something like
```
APPHELLOWORLD_CFLAGS-$(CONFIG_OPTIMIZE_PGO_GENERATE) += -fprofile-generate
APPHELLOWORLD_CFLAGS-$(CONFIG_OPTIMIZE_PGO_USE) += -fprofile-use
```
** Firstly, this ^ needs to be documented in the source code, maybe in
the README file.
** Secondly, why is this required? Why won't simply selecting the
CONFIG_OPTIMIZE_PGO_... option append the compiling / linking flags
for all software components (including the Unikernel) and that's that?
Is this a limitation of the build system, or is it an approach to
granularly configure profile generation per software component?

Razvan

On Mon, Jun 8, 2020 at 12:08 PM Alice Suiu <alicesuiu17@xxxxxxxxx> wrote:
>
> Profile-Guided Optimization is a method used by compilers to produce
> optimal code by using application runtime data. PGO involves two
> phases one that implies a compilation and a run that will generate
> the profiling files for the application and one that implies a
> compilation in which the compiler uses the profiling data to make a
> better estimate of the program’s control flow and to produce an optimized
> executable file.
>
> Add the configuration for PGO phases in MENUCONFIG and the correspondent
> flag for LDFLAGS.
>
> Signed-off-by: Alice Suiu <alicesuiu17@xxxxxxxxx>
> ---
>  Config.uk   | 26 ++++++++++++++++++++++++++
>  Makefile.uk |  8 ++++++++
>  2 files changed, 34 insertions(+)
>
> diff --git a/Config.uk b/Config.uk
> index 3235b91..a815b6b 100644
> --- a/Config.uk
> +++ b/Config.uk
> @@ -86,6 +86,32 @@ config OPTIMIZE_LTO
>                 will increase overall building time but creates more efficient
>                 Unikraft binaries.
>
> +config OPTIMIZE_PGO
> +       bool "PGO - Profile-guided optimization"
> +       default n
> +       help
> +               Enables GCC to do code optimizations through PGO.
> +
> +if OPTIMIZE_PGO
> +       choice PGO_PHASES
> +       prompt "PGO Options"
> +       default OPTIMIZE_PGO_GENERATE
> +       help
> +               Enables GCC to do code optimizations through PGO.
> +
> +       config OPTIMIZE_PGO_GENERATE
> +               bool "profile-generate"
> +               help
> +                       Enables GCC to generate data for code optimization through PGO.
> +
> +       config OPTIMIZE_PGO_USE
> +               bool "profile-use"
> +               help
> +                       Enables GCC to do code optimizations using data generated from
> +                       the profile-generated phase of PGO.
> +       endchoice
> +endif
> +
>  choice
>         prompt "Debug information level"
>         default DEBUG_SYMBOLS_LVL3
> diff --git a/Makefile.uk b/Makefile.uk
> index a78afc0..78d802c 100644
> --- a/Makefile.uk
> +++ b/Makefile.uk
> @@ -36,6 +36,14 @@ COMPFLAGS-$(CONFIG_OPTIMIZE_LTO)          += -flto
>  LIBLDFLAGS-$(CONFIG_OPTIMIZE_LTO)         += $(COMPFLAGS) $(COMPFLAGS-y) $(ARCHFLAGS) $(ARCHFLAGS-y)
>  LDFLAGS-$(CONFIG_OPTIMIZE_LTO)            += $(COMPFLAGS) $(COMPFLAGS-y) $(ARCHFLAGS) $(ARCHFLAGS-y)
>
> +# PGO - profile-generate phase - requires the -fprofile-generate flag
> +# when compiling the application and linking all libraries in the system.
> +LDFLAGS-$(CONFIG_OPTIMIZE_PGO_GENERATE)   += $(COMPFLAGS) $(COMPFLAGS-y) $(ARCHFLAGS) $(ARCHFLAGS-y) -fprofile-generate
> +
> +# PGO - profile-use phase - requires the -fprofile-use flag
> +# when compiling the application and linking all libraries in the system.
> +LDFLAGS-$(CONFIG_OPTIMIZE_PGO_USE)        += $(COMPFLAGS) $(COMPFLAGS-y) $(ARCHFLAGS) $(ARCHFLAGS-y) -fprofile-use
> +
>  DBGFLAGS-$(CONFIG_DEBUG_SYMBOLS_LVL0)     += -g0
>  DBGFLAGS-$(CONFIG_DEBUG_SYMBOLS_LVL1)     += -g1
>  DBGFLAGS-$(CONFIG_DEBUG_SYMBOLS_LVL2)     += -g2
> --
> 2.17.1
>
>

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.