Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/codestyle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,14 @@ jobs:
run: yamllint -f parsable
-d "$yamllint_config"
--strict .github/workflows/*.yml *.yml

kernel-includes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
filter: 'tree:0'

- name: no kernel-only headers in user-space code
# see scripts/check_kernel_includes.py
run: python3 scripts/check_kernel_includes.py --sources --strict
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ add_library(sof_options INTERFACE)

target_link_libraries(sof_options INTERFACE sof_public_headers)

# kernel-only headers, included as <sof/kernel/...>, not part of the public headers
target_include_directories(sof_options INTERFACE ${PROJECT_SOURCE_DIR}/src/kernel/include)

if(BUILD_COUNTERS)
target_compile_definitions(sof_options INTERFACE BLD_COUNTERS=1)
else()
Expand Down
5 changes: 2 additions & 3 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
# https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners

# include files
src/include/sof/drivers/dmic.h @singalsu
src/include/ipc/** @thesofproject/steering-committee
src/include/ipc/** @randerwang @tmleman @pblaszko
src/include/ipc4/** @randerwang @tmleman @pblaszko
Expand All @@ -22,8 +21,8 @@ src/include/sof/audio/mux.h @fkwasowi
src/include/sof/audio/up_down_mixer/* @abonislawski
src/include/sof/audio/codec_adapter/* @cujomalainey @abonislawski @dbaluta
src/include/sof/audio/module_adapter/* @ranj063 @jxstelter
src/include/sof/drivers/acp_dai_dma.h @bhiregoudar @sunilkumardommati
src/include/sof/drivers/afe* @yaochunhung
src/kernel/include/sof/kernel/drivers/acp_dai_dma.h @bhiregoudar @sunilkumardommati
src/kernel/include/sof/kernel/drivers/afe* @yaochunhung

# audio component
src/audio/src* @singalsu @abonislawski
Expand Down
6 changes: 3 additions & 3 deletions doc/mainpage.dox
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@
* <td>
* - @ref zephyr/include/rtos/alloc.h "rtos/alloc.h"<br/>
* - @ref src/include/sof/lib/vregion.h "sof/lib/vregion.h"<br/>
* - @ref zephyr/include/sof/lib/regions_mm.h "sof/lib/regions_mm.h"<br/>
* - @ref zephyr/include/sof/lib/vpage.h "sof/lib/vpage.h"<br/>
* - @ref src/kernel/include/sof/kernel/lib/regions_mm.h "sof/kernel/lib/regions_mm.h"<br/>
* - @ref src/kernel/include/sof/kernel/lib/vpage.h "sof/kernel/lib/vpage.h"<br/>
* - @ref src/include/sof/lib/fast-get.h "sof/lib/fast-get.h"<br/>
* - @ref zephyr/include/sof/lib/memory.h "sof/lib/memory.h"
* </td>
Expand Down Expand Up @@ -232,7 +232,7 @@
* - @ref zephyr/include/sof/lib/dai.h "sof/lib/dai.h"<br/>
* - @ref zephyr/include/sof/lib/dma.h "sof/lib/dma.h"<br/>
* - @ref zephyr/include/sof/lib/pm_runtime.h "pm_runtime.h"<br/>
* - @ref src/include/sof/platform.h "sof/platform.h"
* - @ref src/kernel/include/sof/kernel/platform.h "sof/kernel/platform.h"
* </td>
* <td>
* Low-level peripheral drivers: Digital Audio Interfaces (I2S/SSP, SoundWire, DMIC/PDM, HDA),
Expand Down
2 changes: 1 addition & 1 deletion posix/include/rtos/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <rtos/clk.h>
#include <sof/lib/cpu.h>
#include <rtos/sof.h>
#include <sof/platform.h>
#include <sof/kernel/platform.h>
#include <stdint.h>

struct comp_dev;
Expand Down
64 changes: 63 additions & 1 deletion scripts/check_kernel_includes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,20 @@
checked builds are reported, so that they can be dropped from the list
once they are clean in every configuration.

With --sources it checks the source tree instead of build directories:
kernel-only headers in src/kernel/include are included as
<sof/kernel/...>, and no user-space source or header may include one.
This covers code that no checked build compiles, and has no baseline.

Usage:
check_kernel_includes.py [--strict] [--summary] <build-dir> [<build-dir>...]
check_kernel_includes.py --sources [--strict]
"""

import argparse
import fnmatch
import os
import re
import subprocess
import sys
from collections import defaultdict
Expand Down Expand Up @@ -122,9 +129,50 @@ def check_build(build_dir, manifest, sof_root, zephyr_base):
return leaks, built


KERNEL_INCLUDE = re.compile(r'^\s*#\s*include\s*[<"](sof/kernel/[^>"]+)[>"]', re.M)


def source_files(sof_root):
"""Return the files of the SOF source tree, relative to it."""
try:
out = subprocess.run(['git', '-C', sof_root, 'ls-files'],
check=True, capture_output=True, text=True).stdout
return out.split()
except (OSError, subprocess.CalledProcessError):
files = []
for top, _, names in os.walk(sof_root):
files += [os.path.relpath(os.path.join(top, n), sof_root) for n in names]
return files


def check_sources(manifest, sof_root):
"""Return {user-space file: [kernel header includes]} from the source tree."""
user_src = manifest['user-sources']
not_user = manifest['not-user-sources']
user_hdr = manifest['user-headers']
kernel_hdr = manifest['kernel-headers']

found = {}
for rel in source_files(sof_root):
if rel.endswith(SOURCE_EXTS):
if not matches(rel, user_src) or matches(rel, not_user):
continue
elif not (rel.endswith('.h') and matches(rel, user_hdr)) or \
matches(rel, kernel_hdr):
continue
path = os.path.join(sof_root, rel)
if not os.path.isfile(path):
continue
with open(path, encoding='utf-8', errors='replace') as f:
incs = KERNEL_INCLUDE.findall(f.read())
if incs:
found[rel] = incs
return found


def main():
parser = argparse.ArgumentParser(description=__doc__.split('\n', 1)[0])
parser.add_argument('build_dirs', nargs='+', metavar='build-dir')
parser.add_argument('build_dirs', nargs='*', metavar='build-dir')
parser.add_argument('--manifest', default=DEFAULT_MANIFEST)
parser.add_argument('--sof-root', default=SOF_ROOT,
help='SOF source directory the build directories were built from')
Expand All @@ -135,9 +183,23 @@ def main():
'includes a kernel-only header')
parser.add_argument('--summary', action='store_true',
help='only print per-header counts, not every source file')
parser.add_argument('--sources', action='store_true',
help='check the source tree for <sof/kernel/...> includes from '
'user-space code instead of build directories')
args = parser.parse_args()

manifest = parse_manifest(args.manifest)

if args.sources:
found = check_sources(manifest, args.sof_root)
for src in sorted(found):
print(f'{src}:')
for inc in found[src]:
print(f'\t{inc}')
print(f'{len(found)} user-space files include headers from src/kernel/include')
return 1 if args.strict and found else 0
if not args.build_dirs:
parser.error('build directories or --sources are required')
zephyr_base = args.zephyr_base if os.path.isdir(args.zephyr_base) else None

leaks = defaultdict(set)
Expand Down
21 changes: 14 additions & 7 deletions scripts/kernel_user_partition.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,23 @@
[user-sources]
src/*

# Kernel sources inside src/: src/kernel/ and the legacy drivers.
# Kernel sources inside src/: src/kernel/, and the legacy drivers and LL
# scheduling domains, which go with the legacy drivers.
[not-user-sources]
src/kernel/*
src/audio/dai-legacy.c
src/audio/host-legacy.c
src/schedule/dma_multi_chan_domain.c
src/schedule/dma_single_chan_domain.c
src/schedule/ll_schedule_xtos.c
src/schedule/zephyr_dma_domain.c

# Headers that user-space code includes, checked with --sources: they must
# not include headers from src/kernel/include. The [kernel-headers] below
# are excluded.
[user-headers]
src/include/*
src/platform/*

# SOF headers that only kernel code may include.
# Not listed on purpose: rtos/init.h, which only provides the
Expand All @@ -32,10 +44,7 @@ src/audio/host-legacy.c
# LL and IPC threads, and their layout is in the user-space platform
# headers in src/platform.
[kernel-headers]
src/include/sof/drivers/*
src/include/sof/platform.h
src/include/sof/llext_manager.h
src/include/sof/ipc/driver.h
src/kernel/include/*
src/include/sof/lib/agent.h
src/include/sof/lib/cpu-clk-manager.h
src/include/sof/lib/perf_cnt.h
Expand All @@ -52,8 +61,6 @@ zephyr/include/sof/lib/io.h
zephyr/include/sof/lib/memory.h
zephyr/include/sof/lib/mm_heap.h
zephyr/include/sof/lib/pm_runtime.h
zephyr/include/sof/lib/regions_mm.h
zephyr/include/sof/lib/vpage.h

# Zephyr headers that only kernel code may include: kernel internals and
# driver APIs that are not system calls.
Expand Down
150 changes: 0 additions & 150 deletions src/debug/panic.c

This file was deleted.

Loading
Loading