Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/audio/component.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,24 @@ DECLARE_TR_CTX(comp_tr, SOF_UUID(component_uuid), LOG_LEVEL_INFO);
int comp_register(struct comp_driver_info *drv)
{
struct comp_driver_list *drivers = comp_drivers_get();
k_spinlock_key_t key;

key = k_spin_lock(&drivers->lock);
/*
* No locking needed: the driver list is only modified at FW boot,
* where module init runs serially on the primary core, and at
* runtime from the serialized IPC thread (library load). These
* never overlap, so concurrent modification is not possible.
*/
list_item_prepend(&drv->list, &drivers->list);
k_spin_unlock(&drivers->lock, key);

return 0;
}

void comp_unregister(struct comp_driver_info *drv)
{
struct comp_driver_list *drivers = comp_drivers_get();
k_spinlock_key_t key;

key = k_spin_lock(&drivers->lock);
/* see comp_register() on why no locking is needed */
list_item_del(&drv->list);
k_spin_unlock(&drivers->lock, key);
}

int comp_set_adapter_ops(const struct comp_driver *drv, const struct module_interface *ops)
Expand Down Expand Up @@ -190,7 +191,6 @@ void sys_comp_init(struct sof *sof)
sof->comp_drivers = platform_shared_get(&cd, sizeof(cd));

list_init(&sof->comp_drivers->list);
k_spinlock_init(&sof->comp_drivers->lock);
}

void comp_get_copy_limits(struct comp_buffer *source,
Expand Down
1 change: 0 additions & 1 deletion src/include/sof/audio/component_ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
/** \brief Holds list of registered components' drivers */
struct comp_driver_list {
struct list_item list; /**< list of component drivers */
struct k_spinlock lock; /**< list lock */
};

/** \brief Retrieves the component device buffer list. */
Expand Down
10 changes: 4 additions & 6 deletions src/ipc/ipc3/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ static const struct comp_driver *get_drv(struct sof_ipc_comp *comp)
struct comp_driver_info *info;
struct sof_ipc_comp_ext *comp_ext;
uintptr_t offset;
k_spinlock_key_t key;

/* do we have extended data ? */
if (!comp->ext_data_length) {
Expand Down Expand Up @@ -127,9 +126,10 @@ static const struct comp_driver *get_drv(struct sof_ipc_comp *comp)
goto out;
}

/* search driver list with UUID */
key = k_spin_lock(&drivers->lock);

/*
* search driver list with UUID; no locking needed as the driver
* list is only modified at boot and from the serialized IPC thread
*/
list_for_item(clist, &drivers->list) {
info = container_of(clist, struct comp_driver_info,
list);
Expand All @@ -148,8 +148,6 @@ static const struct comp_driver *get_drv(struct sof_ipc_comp *comp)
*(uint32_t *)(&comp_ext->uuid[8]),
*(uint32_t *)(&comp_ext->uuid[12]));

k_spin_unlock(&drivers->lock, key);

out:
if (drv)
tr_dbg(&comp_tr, "get_drv(), found driver type %d, uuid %pU",
Expand Down
4 changes: 0 additions & 4 deletions src/ipc/ipc4/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -1142,12 +1142,9 @@ __cold static const struct comp_driver *ipc4_search_for_drv(const void *uuid)
struct list_item *clist;
const struct comp_driver *drv = NULL;
struct comp_driver_info *info;
uint32_t flags;

assert_can_be_cold();

irq_local_disable(flags);

/* search driver list with UUID */
list_for_item(clist, &drivers->list) {

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.

looking at other locations, where the driver list is manipulated, we find 3 cases in component.c in functions like comp_register(). And there the list is protected by a dedicated spin-lock (as is the right way to do that). But if we now decide that it needs no protection, maybe we can remove those too. Or maybe make ipc4_get_comp_drv() a syscall and have it take this lock too?

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.

Perhaps @lyakh but this PR is still valid, right?

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.

Perhaps @lyakh but this PR is still valid, right?

@kv2019i sorry, but I tend to reason "no." It is the same driver list, so locking it on one flow and not locking it at another one doesn't seem correct. At the very least I'd put next to one or more of these locations a huge red warning, but those tend to be left unaddressed for years...

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.

Fair enough, back to draft, I study other options.

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.

Now removed the lock from all places (in V2 patchset pushed today).

info = container_of(clist, struct comp_driver_info,
Expand All @@ -1162,7 +1159,6 @@ __cold static const struct comp_driver *ipc4_search_for_drv(const void *uuid)
}
}

irq_local_enable(flags);
return drv;
}

Expand Down
Loading