Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standalone krnlmon build #56

Merged
merged 2 commits into from
Oct 19, 2023
Merged

Standalone krnlmon build #56

merged 2 commits into from
Oct 19, 2023

Conversation

ffoulkes
Copy link
Contributor

@ffoulkes ffoulkes commented Oct 6, 2023

This CL makes it possible to build the Kernel Monitor from its own cmake listfile, independently (more or less) of P4 Control Plane.

For example:

export SDE_INSTALL=<es2k-sde-dir>
cd krnlmon/krnlmon

cmake -B build \
    -DSAI_SOURCE_DIR=../SAI \
    -DCMAKE_MODULE_PATH=../../cmake \
    -DCMAKE_INSTALL_PREFIX=install \
    -DTDI_TARGET=es2k

cmake --build build -j4

The chief awkwardness is making the SelectTdiTarget, FindDpdkDriver, and FindTofinoDriver modules available to the standalone build. The long-term solution is probably to create a separate repository that contains the common modules and reference it through a cmake variable in any project that requires them.

Reasons for supporting standalone build:

  • Makes the Kernel Monitor a component in its own right, and hence easier to reuse the code in other projects.
  • Allows us to do test builds and run unit tests on the component itself (e.g., when a PR is created to update krnlmon).
  • Improves our ability to do incremental builds of larger systems (something we very much want to do for MEV).
  • Allows us to run analyzers such as include-what-you-use on Kernel Monitor (Add support for include-what-you-use #61).

The effort has led to additional error checks and some improvements in the krnlmon build.

@ffoulkes ffoulkes requested review from 5abeel and aashishkuma October 6, 2023 22:38
@ffoulkes ffoulkes added minor effort Minimal effort required cmake Affects CMake build system medium effort Moderate effort required and removed minor effort Minimal effort required labels Oct 6, 2023
@ffoulkes ffoulkes changed the title Experimental support for standalone build Support for standalone build Oct 8, 2023
@ffoulkes ffoulkes changed the title Support for standalone build Standalone krnlmon build Oct 8, 2023
@ffoulkes ffoulkes added minor effort Minimal effort required and removed medium effort Moderate effort required labels Oct 13, 2023
@ffoulkes
Copy link
Contributor Author

ffoulkes commented Oct 13, 2023

An even cooler way to do standalone builds:

es2k-config.cmake

set(DEPEND_INSTALL_DIR "/opt/deps" CACHE PATH
    "config: Dependencies install directory")

set(SDE_INSTALL_DIR "/opt/p4sde/mev" CACHE PATH
    "config: SDE install directory")

get_filename_component(_path "${CMAKE_SOURCE_DIR}/../SAI" REALPATH)
set(SAI_SOURCE_DIR "${_path}" CACHE PATH "config: SAI source directory")

# P4 Control Plane cmake modules
get_filename_component(_path "${CMAKE_SOURCE_DIR}/../../cmake" REALPATH)
set(CMAKE_MODULE_PATH "${_path}" CACHE PATH "" FORCE)

set(CMAKE_INSTALL_PREFIX "${CMAKE_SOURCE_DIR}/install" CACHE PATH "")

set(TDI_TARGET "es2k" CACHE STRING "config: TDI target type")

unset(_path)

Usage

cmake -B build -C es2k-config.cmake
cmake --build build -j4

Copy link
Collaborator

@5abeel 5abeel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question on the PROJECT VERSION. Rest LGTM

@@ -7,16 +7,28 @@
# Version 3.15 is the baseline for P4 Control Plane.
cmake_minimum_required(VERSION 3.15)

project(krnlmon LANGUAGES C CXX)
project(krnlmon VERSION 2.0 LANGUAGES C CXX)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we (planning to) giving each submodule a version number?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm leaning in favor of versioning cmake projects that are, or may be considered to be, discrete packages or components.

krnlmon already had a version number of sorts, defined by the VERSION variable later in this file and substituted into the libkrnlmon pkg-config file.

This CL moves the definition to the cmake project() command, bumps the version number from 1.0 to 2.0, and replaces the VERSION variable with PROJECT_VERSION when creating the pkg-config file.

CMake defines PROJECT_VERSION when you specify project(VERSION x.x).

- Set the recommended compiler options in standalone mode.

- Update internal documentation.

Signed-off-by: Derek G Foster <[email protected]>
@ffoulkes ffoulkes merged commit cad209b into main Oct 19, 2023
@ffoulkes ffoulkes deleted the standalone-build branch October 19, 2023 01:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cmake Affects CMake build system minor effort Minimal effort required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants