From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=0.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E61ADC433DB for ; Thu, 28 Jan 2021 17:37:31 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 71F1364E15 for ; Thu, 28 Jan 2021 17:37:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 71F1364E15 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Received: from localhost ([::1]:48546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l5BEY-00036r-Hq for qemu-devel@archiver.kernel.org; Thu, 28 Jan 2021 12:37:30 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:58688) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l5BBR-00016D-3h for qemu-devel@nongnu.org; Thu, 28 Jan 2021 12:34:17 -0500 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:42765) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l5BBP-0005LX-2T for qemu-devel@nongnu.org; Thu, 28 Jan 2021 12:34:16 -0500 Received: by mail-pg1-x533.google.com with SMTP id g15so4726350pgu.9 for ; Thu, 28 Jan 2021 09:34:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=IzKdJ3qCqMCJGXOb0Hfwkp4SCbZ2e5K3dltAFrMCK7o=; b=fPVdPevrMkua2P+EszCep5siKP5SKlDm1KN5m8eS3Tx8669JuxDF/xI6m9ZkE16hLK JMkV/3qKZ85Mde/3ijbmFSAByQVY9VTN7SxiJg22stWRy+gqTfR1Zy1KEU383bbJeQ6O I+rlNx+fPHl4d6R+9WPr+uKSD+qugUvEKMSu0K/oZANSr8OXCJouUZqbMv+hF+72mX99 LWW7ID61Ygv6zlBxSzrQUhoQWTFMqwGWOZIaaTl8tdkOtOMPy1UotDWWQzjriGPX4km/ tmnFm7eK7fJRS0sJvH6tHtEtrxLf4j4AhKxGP/JVcbjGnJvNPINDeFxSppvCLvrHBIH8 8nrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=IzKdJ3qCqMCJGXOb0Hfwkp4SCbZ2e5K3dltAFrMCK7o=; b=oa+MWmbrS5BQ/Ksb8zZE9kOGcXCQQbp5Tn0++qQD10Mpan7rtQpGuMNOfOzSwRqeB5 JS+Snke+bM1o3McMy5aGBCvX4kO+YkQdEocttoHOVK6rpuCPmvgGfcZyPERh2NihIje1 VU3FbHltJ+fKjmZwRmJTG3Elpji4ymy+zfv4IolnEe1VsW64eVDMSX4hkoI/i6fADN1n mfhCZHVuzWQ2IIa3a8aYspaAmzkU0LiYryhwTIFC2S8TKFOudBJkcnIHyOPwHiOZRo+1 44rquXwbyM3uelwgW3K/ugbEpb8nHyK8Y4bX8YoE/sJO4oZTE7CqC7xMq9PpEF5UQSuX xj1w== X-Gm-Message-State: AOAM533ScLhICu7SBWLpDKZKI1bb5RcbBB+RKTw9cMp8BDz2f4VTDIrD iNwf+Lo9JgbruZ7SHp0QGPHMlXGljSNDq6A6VPk= X-Google-Smtp-Source: ABdhPJwoGcEqHAYav9vydUh5xhxep2gEnxlU8hTB1LsqIaN4sfYin0IaisokbCTd7FKy5KNM5K8bAOMYKPFgSewimns= X-Received: by 2002:a63:1626:: with SMTP id w38mr560801pgl.278.1611855253486; Thu, 28 Jan 2021 09:34:13 -0800 (PST) MIME-Version: 1.0 References: <87ft33l8an.fsf@linaro.org> <87v9blmf1x.fsf@linaro.org> <20210128112541.qjpve3qbjy46ofkk@sirius.home.kraxel.org> <20210128163001.jjptft2t5fbdlvyn@sirius.home.kraxel.org> In-Reply-To: <20210128163001.jjptft2t5fbdlvyn@sirius.home.kraxel.org> From: Shreyansh Chouhan Date: Thu, 28 Jan 2021 23:04:01 +0530 Message-ID: Subject: Re: Fwd: VirtioSound device emulation implementation To: Gerd Hoffmann Content-Type: multipart/alternative; boundary="000000000000d041a905b9f94bb7" Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=chouhan.shreyansh2702@gmail.com; helo=mail-pg1-x533.google.com X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?B?QWxleCBCZW5uw6ll?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: "Qemu-devel" --000000000000d041a905b9f94bb7 Content-Type: text/plain; charset="UTF-8" On Thu, 28 Jan 2021 at 22:00, Gerd Hoffmann wrote: > On Thu, Jan 28, 2021 at 09:20:31PM +0530, Shreyansh Chouhan wrote: > > (Gerd, I wasn't able to get gmail to quote your email, so I have just > copy > > pasted the relavant parts.) > > > > > Yes. net_conf is common config (backend, mac address, maybe more) for > > > network devices. For sound devices that would audiodev (link the > device > > > to a backend which then handles alsa/pulse/jack/oss/sdl/whatever). > > > > Ah I see, so the net_conf corresponds to audiodev? > > Oops. Confused that. nic_conf (struct NICConf) is the common config > for all network devices, not net_conf. > > See DEFINE_NIC_PROPERTIES() in include/net/net.h > > NICConf.peers (exposed as "netdev" property) links the emulated device > (frontend) to a netdev (backend) which actually processes the packets > sent by the guest. > > In a simliar way the audiodev property links the emulated audio device > to a backend which handles the host-side audio playback using alsa, > pulseaudio or something else. > > > I thought it would correspond to `virtio_snd_conf`. So as alex said, > > `virtio_snd_conf` is the front end configuration. > > Correct. > > The backend is configured separately, i.e. > > -netdev user,id=net0,$moreargs > > or > > -audiodev alsa,id=snd0,$moreargs > > Then the two are linked by id, i.e. > > -device virtio-net-pci,netdev=net0 > > or > > -device virtio-sound-pci,audiodev=snd0 > Ah ha! So `virtio-snd-conf` corresponds to the `-device` configuration and `audiodev` to the backend configuration. I think the audio code now makes more sense to me. I will give it another read. > > The only thing really required is the audiodev property. Everything > > > else can be hard-coded initially, and once the basics are working > > > refined (like adding properties for jack labels, ...). > > > > So in the realize function I set up the audiodev, right? Also in that > case > > why the difference between the net and sound devices? In the net > > device we set up the common config in net_conf. Does the net_conf > > somehow later sets up NetDev too? > > > > And what is a NetClientState? Is the NetClient the emulated guest? This > > confuses me a lot. I can't understand what will be the parellel audio > device > > property. > > Not fully sure what NetClientState is, I guess it is shared struct for > both frontend and backend to manage the connection state. > > The audio subsystem has simliar structs, SWVoiceIn and SWVoiceOut for > example. There also is QEMUSoundCard. I'd suggest to check out the > source code of other audio devices for code examples. > I will read it and revert back if I have any queries. > > > Also I can't seem to find where we parse the command line options > > passed to qemu. The code structure is a bit different from what I had > > expected. In virtio_net_device_realize we set duplex to half or full > > depending on the value of the net_conf.duplex_str. But I couldn't find > > where we actually set it. > > See virtio_net_properties[]. There is a line in the array: > > DEFINE_PROP_STRING("duplex", VirtIONet, net_conf.duplex_str), > I thought this just declared a property, and didn't set it. But now that in retrospect we already declared the variable when we defined the struct so that doesn't make sense. > > And the whole array is registered using: > > device_class_set_props(dc, virtio_net_properties); > > That is enough to make those properties work, the qemu core handles > everything for you. See hw/core/qdev-properties.c if you are curious, > but you can also just consider that a black box at service for you ;) > I think I will give it a quick look :P > > take care, > Gerd > > Thanks a lot! -- Shreyansh --000000000000d041a905b9f94bb7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


=
On Thu, 28 Jan 2021 at 22:00, Gerd Ho= ffmann <kraxel@redhat.com> w= rote:
On Thu, Ja= n 28, 2021 at 09:20:31PM +0530, Shreyansh Chouhan wrote:
> (Gerd, I wasn't able to get gmail to quote your email, so I have j= ust copy
> pasted the relavant parts.)
>
> > Yes.=C2=A0 net_conf is common config (backend, mac address, maybe= more) for
> > network devices.=C2=A0 For sound devices that would audiodev (lin= k the device
> > to a backend which then handles alsa/pulse/jack/oss/sdl/whatever)= .
>
> Ah I see, so the net_conf corresponds to audiodev?

Oops.=C2=A0 Confused that.=C2=A0 nic_conf (struct NICConf) is the common co= nfig
for all network devices, not net_conf.

See DEFINE_NIC_PROPERTIES() in include/net/net.h

NICConf.peers (exposed as "netdev" property) links the emulated d= evice
(frontend) to a netdev (backend) which actually processes the packets
sent by the guest.

In a simliar way the audiodev property links the emulated audio device
to a backend which handles the host-side audio playback using alsa,
pulseaudio or something else.

> I thought it would correspond to `virtio_snd_conf`. So as alex said, > `virtio_snd_conf` is the front end configuration.

Correct.

The backend is configured separately, i.e.

=C2=A0 -netdev user,id=3Dnet0,$moreargs

or

=C2=A0 -audiodev alsa,id=3Dsnd0,$moreargs

Then the two are linked by id, i.e.

=C2=A0 -device virtio-net-pci,netdev=3Dnet0

or

=C2=A0 -device virtio-sound-pci,audiodev=3Dsnd0
=C2=A0=
Ah ha! So `virtio-snd-conf` corresponds to the `-device` configu= ration
and `audiodev` to the backend configuration. I think the a= udio code
now makes more sense to me. I will give it another read= .

> > The only thing really required is the audiodev property.=C2=A0 Ev= erything
> > else can be hard-coded initially, and once the basics are working=
> > refined (like adding properties for jack labels, ...).
>
> So in the realize function I set up the audiodev, right? Also in that = case
> why the difference between the net and sound devices? In the net
> device we set up the common config in net_conf. Does the net_conf
> somehow later sets up NetDev too?
>
> And what is a NetClientState? Is the NetClient the emulated guest? Thi= s
> confuses me a lot. I can't understand what will be the parellel au= dio device
> property.

Not fully sure what NetClientState is, I guess it is shared struct for
both frontend and backend to manage the connection state.

The audio subsystem has simliar structs, SWVoiceIn and SWVoiceOut for
example.=C2=A0 There also is QEMUSoundCard.=C2=A0 I'd suggest to check = out the
source code of other audio devices for code examples.
= I will read it and revert back if I have any queries.

> Also I can't seem to find where we parse the command line options<= br> > passed to qemu.=C2=A0 The code structure is a bit different from what = I had
> expected. In virtio_net_device_realize we set duplex to half or full > depending on the value of the net_conf.duplex_str. But I couldn't = find
> where we actually set it.

See virtio_net_properties[].=C2=A0 There is a line in the array:

=C2=A0 =C2=A0 DEFINE_PROP_STRING("duplex", VirtIONet, net_conf.du= plex_str),
I thought this just declared a property, an= d didn't set it. But now that in retrospect
we already declar= ed the variable when we defined the struct so that doesn't make
sense.

And the whole array is registered using:

=C2=A0 =C2=A0device_class_set_props(dc, virtio_net_properties);

That is enough to make those properties work, the qemu core handles
everything for you.=C2=A0 See hw/core/qdev-properties.c if you are curious,=
but you can also just consider that a black box at service for you ;)
I think I will give it a quick look :P

take care,
=C2=A0 Gerd

Thanks a lot!
--
Shreyansh

--000000000000d041a905b9f94bb7--