Skip to content

Introducing virtual FE #8

Closed
ranj063 wants to merge 6 commits into
thesofproject:topic/sof-devfrom
ranj063:topic/tone-1
Closed

Introducing virtual FE #8
ranj063 wants to merge 6 commits into
thesofproject:topic/sof-devfrom
ranj063:topic/tone-1

Conversation

@ranj063
Copy link
Copy Markdown
Collaborator

@ranj063 ranj063 commented Jun 25, 2018

This set of patches introduces the concept of a virtual FE dai link.
Previously, when trying to enable the hostless pipeline, it was
discovered that the codec does not get enabled and the tone remained inaudible.
Therefore, in such cases, a virtual FE dai link will be used to establish
a connection to the BE dai and enable the codec when the pipeline is triggered.

The virtual FE will be created when a siggen widget is loaded and freed when
the siggen widget is unloaded. It will be used for enabling the BE dai in the
kcontrol IO handler for the kcontrol attached to the siggen by calling
the soc_spcm_runtime_update() method.

Comment thread include/sound/soc.h Outdated
* This connection will be established at runtime by triggering the
* hostless pipeline with a kcontrol attached to the component.
*/
unsigned int virtual:1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just wondering if we can set dynamic = 1 and no_pcm = 1 to achieve the same effect and hence no need for this ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i had the same question, it feels somewhat redundant with existing mechanisms

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in the revised version

Comment thread sound/soc/soc-pcm.c Outdated
/* define virtual FE DAI link */
link->virtual = 1;
link->name = link_name;
link->id = 1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Pass ID in ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I removed the ID as it isnt really needed

Comment thread sound/soc/soc-pcm.c Outdated
link->platform_name = platform_name;
link->codec_name = "snd-soc-dummy";
link->codec_dai_name = "snd-soc-dummy-dai";
link->num_codecs = 1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we need codecs ? should it b 0 ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

Comment thread sound/soc/soc-pcm.c Outdated
link->dynamic = 1;

/*TODO: check if we need to handle capture for virtual FE */
link->dpcm_playback = 1;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

capture ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yes, this looks like a generic capability on capture where a component can capture audio and throw some sort of non-audio event DAPM knows nothing about.

Copy link
Copy Markdown
Collaborator Author

@ranj063 ranj063 Jun 27, 2018

Choose a reason for hiding this comment

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

Should the virtual FE have both dpcm_playback and dpcm_capture enabled by default ?
Or does it depend on the widget that calls vfe_new(). So in the case of tone, I can only have dpcm_playback enabled?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I've added capture support in virtual FE too. The widget creating the vfe must specify the stream direction.

Comment thread sound/soc/soc-pcm.c Outdated
EXPORT_SYMBOL_GPL(soc_dpcm_vfe_new);

/* free virtual FE DAI link */
int soc_dpcm_vfe_free(struct snd_soc_card *card)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

we need to individually delete these link by link.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Is the idea then that the widget that created the virtual fe, will delete it?
In that case, can I associate the link with the comp by adding it to the snd_sof_control associated with the comp?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

FIxed to delete vfe by name

Comment thread sound/soc/soc-pcm.c Outdated
for_each_rtdcom_safe(rtd, rtdcom1, rtdcom2)
kfree(rtdcom1);

INIT_LIST_HEAD(&rtd->component_list);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is the list head init here in free() ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

fixed

Comment thread sound/soc/soc-dapm.c

/* Drop starting point */
list_del(widgets.next);
if (!list_is_singular(&widgets))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What happens if you have more than one widget between widget and BE, it's valid and could be constructed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This part is a bit unclear to me. The problem I was facing was that the snd_soc_dapm_dai_get_connected_widgets() returned a list with only the BE DAI in the case of the tone pipeline and dropping the starting point resulted in an empty list of paths to process.

the dai argument passed to this method was the cpu_dai->playback_widget() which is the BE dai in my case. And this was the only way I could get it to be enabled. I could use some help here to figure out the right way to do it.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, what happens if you have tone followed by a volume control?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We do have a tone followed by volume in my topology. But the snd_soc_dapm_dai_get_connected_widgets() is called starting with the dai->playback_widget as the starting point. And this is the BE DAI.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should also state in a comment what we are doing here and why.

Comment thread sound/soc/soc-pcm.c Outdated
* pcm device and substream for the requested direction
*/
if (rtd->dai_link->virtual) {
struct snd_pcm_str *pstr;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would offload this logic as a static function.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

and can any part of this be done by call core ALSA functions directly ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The only function that does this is snd_new_pcm() but that also registers the pcm device. So I created this to avoid that part.

@ranj063
Copy link
Copy Markdown
Collaborator Author

ranj063 commented Jun 26, 2018

Thanks, Liam and Pierre. Let me work on revising the patchset today.

ranj063 added 4 commits June 27, 2018 13:38
This patch proposes to enable kcontrols for siggen type
dapm widgets. This will allow triggering the tone generating siggen
component and also modifying the run-time attributes such as frequency,
amplitude etc.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
This patch adds the methods for create a virtual FE dal link
and add it to the sound card. It also adds the method to free
the virtual FE connected to the card.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
When walking the graph to discover the path from the virtual FE to
the BE, there is only one widget in the path. Do not remove
this BE widget from the list, so it can be used to connect with the
virtual FE dai link.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
…irtual dai link

Virtual FE dai links should be manually set to running
state by default with a pcm runtime. The active count of their cpu_dai
and codec_dai's should also be updated. This is required to establish
FE-BE connection and enable the BE DAI when the dpcm runtime is updated.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
@ranj063
Copy link
Copy Markdown
Collaborator Author

ranj063 commented Jun 27, 2018

@plbossart , @lgirdwood . I've pushed some changes. Could you please review the new version?

ranj063 added 2 commits June 27, 2018 13:52
Virtual FE dai links do not need to register the pcm device. So
just create the empty pcm device and substream in the
requested direction.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
the soc_dpcm_runtime_update() method will be called to establish a
connection to the BE and enable the codec. So make this method
accessible to modules.

Signed-off-by: Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
Copy link
Copy Markdown
Member

@plbossart plbossart left a comment

Choose a reason for hiding this comment

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

Looks better! I think it does make sense to reuse no_pcm and dynamic, this is easier to push upstream. but I am still not clear on a couple of comments related to init/free/activation.

Comment thread sound/soc/soc-pcm.c
dpcm_be_disconnect(rtd, stream_dir);

/* free pcm runtime */
kfree(rtd->dpcm[stream_dir].runtime);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Question: all these frees don't reflect what is done for the _new method, could we rely on a helper to avoid tracking all these actions? It looks like either copy-paste or something extracted from somewhere else.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is actually not a copy-paste at all. I traced all the steps from the point of adding the link to the time when the sound card is registered and freed all the data that is allocated. Here're the steps I traced:

  1. Bind DAI link: The PCM runtime and the dpcm runtime is created during this step.
    There are some other runtime child structures allocated during this step too ie codec dais and component list.
  2. Probe DAI link :The pcm device and the substream is created here.
  3. dpcm runtime update: the FE link is connected to the BE

So, in the vfe_free() method, I undid all of this.

But I wonder if I can avoid all of this manually in the free method. Let me dig into these steps a bit more.

Comment thread sound/soc/soc-dapm.c

/* Drop starting point */
list_del(widgets.next);
if (!list_is_singular(&widgets))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, what happens if you have tone followed by a volume control?

Comment thread sound/soc/soc-core.c

soc_add_pcm_runtime(card, rtd);

/* if this is a virtual FE link, create runtime and set it as active */
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't know what 'active' runtime means. I would think it becomes 'active' when the switch is On, but maybe it's a different concept you are referring to.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Oh, what I mean by active here is when the kcontrol is switched on and the dpcm_runtime_update() is called, it checks to see if playback or capture is active on the FE link. So I set the FE playback/capture active status by default.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see, but I wonder if this has negative implications related to suspend/resume? If there is nothing going on it's a bit odd to force a runtime to be active.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yes, thats a good point.

The problem is the runtime_update() method is oblivious to where it is being called from. It just looks for an active link to process the update.

Maybe I can avoid this by activating the FE in the kcontrol IO handler just before calling runtime_update.

Copy link
Copy Markdown
Member

@lgirdwood lgirdwood left a comment

Choose a reason for hiding this comment

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

Sorry, have more questions on the core changes.

Comment thread sound/soc/soc-pcm.c

/* Create any new FE <--> BE connections */
for (i = 0; i < list->num_widgets; i++) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

best to keep this line as is.

Comment thread sound/soc/soc-pcm.c
substream->pstr = pstr;
substream->number = 0;
substream->stream = stream_dir;
sprintf(substream->name, "subdevice #%i", 0);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is the name exposed by /sysff or /proc ? if so, do we have any naming collisions when we register 2 or more VFE ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

hmm I did not check if it is exposed. Let me try to make it unique

Comment thread sound/soc/soc-dapm.c
kcname_in_long_name = true;
} else {
switch (w->id) {
case snd_soc_dapm_siggen:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

as discussed last week, I wonder if we should also add a snd_soc_dapm_sig_sink (the dual of a generator). This would be very useful for testing e.g. by letting us set-up all sort of DMA channels with a self-test checking.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sure, I will add it to my next update.

@ranj063
Copy link
Copy Markdown
Collaborator Author

ranj063 commented Jul 5, 2018

@plbossart , @lgirdwood . I'm closing this pull request and replacing it with a new pull request that has all the commits to enable the tone generator. This will be helpful for you review the entire flow for enabling the VFE link and the pipeline. I have addressed your comments in the new pull request.

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.

3 participants