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

Add cpio binary and help with silent and parallel builds #20

Merged
merged 2 commits into from
Sep 19, 2024

Conversation

srikard
Copy link
Contributor

@srikard srikard commented Sep 4, 2024

Sometimes kernel build fails due to non availability of cpio archive in the container.
the kernel/gen_kheaders.sh file needs cpio archive to build kernel/kheaders_data.tar.xz

Similarly silent and parallel builds will help to build faster and show only relevant warnings or error messages.

cpio is needed by kernel/gen_kheaders.sh to build
kernel/kheaders_data.tar.bz2. Hence include it as part of Dockerfile.

python3 make_linux.py -a x86_64 -s ~/linux -o ~/linux/out -c clang-17 -k ~/linux/out/.config
[+] Going to build the Linux kernel for x86_64
[+] Using "/home/srikar/linux/out/.config" as kernel config
[+] Using "/home/srikar/linux" as Linux kernel sources directory
[+] Using "/home/srikar/linux/out" as build output directory
[+] Going to build with: clang-17

=== Building with clang-17 ===
Output subdirectory for this build: /home/srikar/linux/out/.config__x86_64__clang-17
Output subdirectory already exists, use it (no cleaning!)
kconfig files "/home/srikar/linux/out/.config" and "/home/srikar/linux/out/.config__x86_64__clang-17/.config" are identical, proceed
Going to save build log to "build_log.txt" in output subdirectory
Compiling with clang requires 'CC=clang'
Run the container: bash ./start_container.sh clang-17 /home/srikar/linux /home/srikar/linux/out/.config__x86_64__clang-17 -n -- make O=../out/ CC=clang 2>&1
    Hey, we gonna use sudo for running docker
    Run docker in NON-interactive mode
    Starting "kernel-build-container:clang-17"
    Mount source code directory "/home/srikar/linux" at "/home/srikar/src"
    Mount build output directory "/home/srikar/linux/out/.config__x86_64__clang-17" at "/home/srikar/out"
    Gonna run command "make O=../out/ CC=clang 2>&1"

    make[1]: Entering directory '/home/srikar/out'
      SYNC    include/config/auto.conf.cmd
      GEN     Makefile
      GEN     Makefile
      UPD     include/generated/compile.h
      CALL    /home/srikar/src/scripts/checksyscalls.sh
      CC      init/version.o
      AR      init/built-in.a
    make[4]: *** [/home/srikar/src/kernel/Makefile:158: kernel/kheaders_data.tar.xz] Error 127
    make[3]: *** [/home/srikar/src/scripts/Makefile.build:480: kernel] Error 2
    make[2]: *** [/home/srikar/src/Makefile:2032: .] Error 2
    make[1]: *** [/home/srikar/src/Makefile:234: __sub-make] Error 2
    make[1]: Leaving directory '/home/srikar/out'
    make: *** [Makefile:234: __sub-make] Error 2
The container returned 2
Finish building the kernel
Only remove the container id file:
    Hey, we gonna use sudo for running docker
    Search "container.id" file in build output directory "/home/srikar/linux/out/.config__x86_64__clang-17"
    OK, "container.id" file exists, removing it
    OK, container 460138d7243910b6ab58ba8da6d28ac10022c4b551b968004af848dfb5f3291f doesn't run
The finish_container.sh script returned 0
See the build log: /home/srikar/linux/out/.config__x86_64__clang-17/build_log.txt

[+] Done, see the results

Signed-off-by: Srikar Dronamraju <[email protected]>
Linux kernel build supports silent build and parallel build.
By default build, its easy to miss the warnings and errors in the
compile log, especially when in interactive mode.

Similarly parallel build will help to get the build the kernel faster.

Signed-off-by: Srikar Dronamraju <[email protected]>
@a13xp0p0v
Copy link
Owner

Hello @srikard,

Thanks a lot for your pull request! I like the idea.

I agree that parallel build should become default.
But we should provide a parameter for make_linux.py for disabling it and having a single-thread build (there are cases when it's useful).
Could you please implement a -t (single Tread build) parameter for make_linux.py?

And I think that verbose kernel build should stay default.
Could you please add a -q (quiet) parameter for make_linux.py for silent build?

Would you like to work on it?

@srikard
Copy link
Contributor Author

srikard commented Sep 4, 2024 via email

@a13xp0p0v
Copy link
Owner

The -s parameter is already used for source path. So I would recommend -q like quiet.

The -j parameter doesn't fit: we need parallel build as default behavior for make_linux.py (without parameters).
So we need a make_linux.py parameter for a single-tread build, corresponding to make -j1. How about -t (single Tread build). Any other ideas?

@Willenst Willenst mentioned this pull request Sep 17, 2024
a13xp0p0v added a commit that referenced this pull request Sep 19, 2024
a13xp0p0v added a commit that referenced this pull request Sep 19, 2024
a13xp0p0v added a commit that referenced this pull request Sep 19, 2024
a13xp0p0v added a commit that referenced this pull request Sep 19, 2024
@a13xp0p0v a13xp0p0v merged commit 8c98ee6 into a13xp0p0v:master Sep 19, 2024
a13xp0p0v added a commit that referenced this pull request Sep 19, 2024
@a13xp0p0v
Copy link
Owner

a13xp0p0v commented Sep 19, 2024

Hello @srikard,

I've finished the implementation and merged this branch: c9a015c.

Finally, the feature looks like this:

+    parser.add_argument('-q', action='store_true',
+                        help='for running `make` in quiet mode')
+    parser.add_argument('-t', action='store_true',
+                        help='for running `make` in single-threaded mode (multi-threaded by default)')
     parser.add_argument('make_args', metavar='...', nargs=argparse.REMAINDER,
                         help='additional arguments for \'make\', can be separated by -- delimiter')
     args = parser.parse_args()
@@ -197,6 +201,19 @@ def main():
                 sys.exit('[-] Don\'t specify "CROSS_COMPILE=", we will take care of that')
             if arg.startswith('CC='):
                 sys.exit('[-] Don\'t specify "CC=", we will take care of that')
+            if arg.startswith('-j'):
+                sys.exit('[-] Don\'t specify "-j", by default we run \'make\' in parallel on all CPUs')
+
+    if args.q:
+        print('[+] Going to run \'make\' in quiet mode')
+        make_args.insert(0, '-s')
+
+    if not args.t:
+        cpu_count = os.sysconf('SC_NPROCESSORS_ONLN')
+        print(f'[+] Going to run \'make\' on {cpu_count} CPUs')
+        make_args = ['-j', str(cpu_count)] + make_args
+    else:
+        print(f'[+] Going to run \'make\' in single-threaded mode')
 
     build_kernels(args.a, args.k, args.s, args.o, compilers, make_args)

Does it work for you?

@srikard
Copy link
Contributor Author

srikard commented Sep 19, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants