Skip to content

mux: add missing buffer locks - #2545

Merged
tlauda merged 1 commit into
thesofproject:masterfrom
tlauda:topic/mux-add-missing-locks
Mar 17, 2020
Merged

tlauda merged 1 commit into
thesofproject:masterfrom
tlauda:topic/mux-add-missing-locks

Conversation

@tlauda

@tlauda tlauda commented Mar 13, 2020

Copy link
Copy Markdown
Contributor

Adds missing buffer locks to mux_copy function.
demux_copy has already had them before.

Signed-off-by: Tomasz Lauda tomasz.lauda@linux.intel.com

@tlauda
tlauda requested a review from akloniex as a code owner March 13, 2020 10:01
@akloniex

Copy link
Copy Markdown
Member

@tlauda Should we have similar locks for Demux? Mux and Demux have separate copy functions, so that might need some adjustments there also.

@tlauda

tlauda commented Mar 13, 2020

Copy link
Copy Markdown
Contributor Author

@tlauda Should we have similar locks for Demux? Mux and Demux have separate copy functions, so that might need some adjustments there also.

mux_copy has been the only function missing them (see commit description).

Comment thread src/audio/mux/mux.c Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

where is the corresponding buffer_lock for this? Code looks strange.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@dbaluta I think it's the one on line 403 (it's in the same function).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I see. thanks.

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.

Yeah, I'm not seeing this, I can see lock(source) and unlock(sources[i]) which seem unaligned as they are different objects. Some inline comments may help here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@lgirdwood They are the same objects.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@tlauda this looks error prone.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dbaluta What do you mean?

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 wonder if simplification would be better here. i.e.

	/* align source streams with their respective configurations */
	list_for_item(clist, &dev->bsource_list) {
		source = container_of(clist, struct comp_buffer, sink_list);
		buffer_lock(source, &flags);
		if (source->source->state == dev->state) {
			num_sources++;
			i = get_stream_index(cd, source->pipeline_id);
			sources[i] = source;
			sources_stream[i] = &source->stream;
		} else {
			buffer_unlock(source, flags);
		}
	}

Means we only have certain source buffers locked, i.e only the buffers that out configuration is telling us to copy from. Would it make more sense to just lock all sources and then unlock all sources ?

Another thing that we should do is to change the buffer locks to reader and writer locking.

buffer_rlock(buffer, flags);
buffer_wlock(buffer, flags);

This way we only lock a buffer for reading or writing (i.e.reader lock updates r_ptr and avail, writer lock updates w_ptr and free). This would allow cross core buffers that would not block a core that the current implementation might.

@tlauda tlauda Mar 16, 2020 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@lgirdwood It's definitely candidate for future improvement. This patch is about aligning with rest of the components. mux_copy function is the only one missing locks currently.

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.

Ok, great for the r/w buffer locking update.

Comment thread src/audio/mux/mux.c Outdated
Adds missing buffer locks to mux_copy function.
demux_copy has already had them before.

Signed-off-by: Tomasz Lauda <tomasz.lauda@linux.intel.com>
@tlauda
tlauda force-pushed the topic/mux-add-missing-locks branch from 2737e48 to 908b9d0 Compare March 16, 2020 07:36
@tlauda
tlauda merged commit cd9a0d3 into thesofproject:master Mar 17, 2020
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.

5 participants