mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <thomas@t-8ch.de>
To: Tamir Duberstein <tamird@gmail.com>
Cc: Alyssa Ross <hi@alyssa.is>,
	 Brendan Higgins <brendan.higgins@linux.dev>,
	David Gow <davidgow@google.com>, Rae Moar <rmoar@google.com>,
	 linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] kunit: enable hardware acceleration when available
Date: Fri, 1 Nov 2024 15:23:16 +0000	[thread overview]
Message-ID: <5d855199-d054-43f2-b209-23bbfa5f6d92@t-8ch.de> (raw)
In-Reply-To: <CAJ-ks9m8AD2fon4Nxvc_S-DwY4TkRPHpq0icT0jPwCiCxy6Tqw@mail.gmail.com>

On 2024-11-01 10:49:36-0400, Tamir Duberstein wrote:
> On Fri, Nov 1, 2024, 09:52 Alyssa Ross <hi@alyssa.is> wrote:
> >
> > On Fri, Oct 25, 2024 at 05:03:54PM -0400, Tamir Duberstein wrote:
> > > @@ -124,6 +125,29 @@ class LinuxSourceTreeOperationsQemu(LinuxSourceTreeOperations):
> > >                               '-no-reboot',
> > >                               '-nographic',
> > >                               '-serial', self._serial] + self._extra_qemu_params
> > > +             accelerators = {
> > > +                     line.strip()
> > > +                     for line in subprocess.check_output([qemu_binary, "-accel", "help"], text=True).splitlines()
> > > +                     if line and line.islower()
> > > +             }
> > > +             if 'kvm' in accelerators:
> > > +                     try:
> > > +                             with open('/dev/kvm', 'rb+'):
> > > +                                     qemu_command.extend(['-accel', 'kvm'])
> > > +                     except OSError as e:
> > > +                             print(e)
> > > +             elif 'hvf' in accelerators:
> > > +                     try:
> > > +                             for line in subprocess.check_output(['sysctl', 'kern.hv_support'], text=True).splitlines():
> > > +                                     if not line:
> > > +                                             continue
> > > +                                     key, value = line.split(':')
> > > +                                     if key == 'kern.hv_support' and bool(value):
> > > +                                             qemu_command.extend(['-accel', 'hvf'])
> > > +                                             break
> > > +                     except subprocess.CalledProcessError as e:
> > > +                             print(e)
> > > +
> >
> > QEMU supports falling back if one accelerator is not available, if you
> > specify multiple like -accel kvm:tcg.  Couldn't you rely on that rather
> > than re-implementing the availability checks here?
> 
> Have you ever used that? Here's what I get when I try:
> 
> tamird@Tamirs-MacBook-Pro linux % tools/testing/kunit/kunit.py run
> --arch arm64 --make_options LLVM=1 --raw_output=all
> [10:45:03] Configuring KUnit Kernel ...
> [10:45:03] Building KUnit Kernel ...
> Populating config with:
> $ make ARCH=arm64 O=.kunit olddefconfig LLVM=1
> Building with:
> $ make all compile_commands.json ARCH=arm64 O=.kunit --jobs=12 LLVM=1
> [10:45:07] Starting KUnit Kernel (1/1)...
> Running tests with:
> $ qemu-system-aarch64 -nodefaults -m 1024 -kernel
> .kunit/arch/arm64/boot/Image.gz -append 'kunit.enable=1
> console=ttyAMA0 kunit_shutdown=reboot' -no-reboot -nographic -serial
> stdio -accel kvm:tcg -machine virt -cpu max
> qemu-system-aarch64: -accel kvm:tcg: invalid accelerator kvm:tcg
> 
> The same thing happens with hvf:kvm:tcg or just hvf:tcg.

That syntax is for -machine accel=hvf:kvm:tcg.
But you can also specify -accel multiple times.

> I also can't find this in the documentation.

-accel name[,prop=value[,...]]
      This  is used to enable an accelerator. [..]
      If there is more than one accelerator specified,
      the next one is used if the previous one fails to initialize.

-machine [type=]name[,prop=value[,...]]
      Supported machine properties are:

      accel=accels1[:accels2[:...]]
	     [..]
	     If there is more than one accelerator specified,
	     the next one is used if the  previous one fails to initialize.


Thomas

  reply	other threads:[~2024-11-01 15:23 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-25 21:03 [PATCH 0/2] kunit: enable hardware virtualization Tamir Duberstein
2024-10-25 21:03 ` [PATCH 1/2] kunit: add fallback for os.sched_getaffinity Tamir Duberstein
2024-10-25 21:03 ` [PATCH 2/2] kunit: enable hardware acceleration when available Tamir Duberstein
2024-11-01 13:52   ` Alyssa Ross
2024-11-01 14:49     ` Tamir Duberstein
2024-11-01 15:23       ` Thomas Weißschuh [this message]
2024-11-02 11:10         ` Tamir Duberstein

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5d855199-d054-43f2-b209-23bbfa5f6d92@t-8ch.de \
    --to=thomas@t-8ch.de \
    --cc=brendan.higgins@linux.dev \
    --cc=davidgow@google.com \
    --cc=hi@alyssa.is \
    --cc=kunit-dev@googlegroups.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=rmoar@google.com \
    --cc=tamird@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®