Skip to content
Merged
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
6 changes: 4 additions & 2 deletions src/arch/xtensa/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ sof_SOURCES += \
smp/cpu.c \
smp/init.c \
smp/schedule.c \
smp/task.c
smp/task.c \
smp/work.c
else
sof_SOURCES += \
up/xtos/crt1-boards.S \
up/xtos/_vectors.S \
up/cpu.c \
up/init.c \
up/schedule.c \
up/task.c
up/task.c \
up/work.c
endif

if BUILD_BOOTLOADER
Expand Down
2 changes: 2 additions & 0 deletions src/arch/xtensa/smp/cpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ void cpu_power_down_core(void)

scheduler_free();

free_system_workq();

free_core_context(arch_cpu_get_id());

dcache_writeback_invalidate_all();
Expand Down
47 changes: 47 additions & 0 deletions src/arch/xtensa/smp/work.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (c) 2018, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Intel Corporation nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Tomasz Lauda <tomasz.lauda@linux.intel.com>
*
*/

/**
* \file arch/xtensa/smp/work.c
* \brief Xtensa SMP work queue implementation file
* \authors Tomasz Lauda <tomasz.lauda@linux.intel.com>
*/

#include <xtos-structs.h>
#include <arch/cpu.h>
#include <sof/work.h>

struct work_queue **arch_work_queue_get(void)

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 do we return a ** ?

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.

Also, could this be static inline ?

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.

  1. ** to be able to assign pointer per core using the same init function.
    It's the same as of other core_context members.
  2. It could be problematic as implementation is in .c files and for up needs to access static struct.

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.

Sorry, not following 1. Are you saying there there would be differences to init function on each core without this ?

{
struct core_context *ctx = (struct core_context *)cpu_read_threadptr();

return &ctx->queue;
}
2 changes: 2 additions & 0 deletions src/arch/xtensa/smp/xtos/xtos-structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
struct idc;
struct irq_task;
struct schedule_data;
struct work_queue;

struct thread_data {
xtos_structures_pointers xtos_ptrs;
Expand All @@ -57,6 +58,7 @@ struct core_context {
struct irq_task *irq_med_task;
struct irq_task *irq_high_task;
struct schedule_data *sch;
struct work_queue *queue;
struct idc *idc;
};

Expand Down
46 changes: 46 additions & 0 deletions src/arch/xtensa/up/work.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2018, Intel Corporation
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Intel Corporation nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* Author: Tomasz Lauda <tomasz.lauda@linux.intel.com>
*
*/

/**
* \file arch/xtensa/up/work.c
* \brief Xtensa UP work queue implementation file
* \authors Tomasz Lauda <tomasz.lauda@linux.intel.com>
*/

#include <sof/work.h>

/** \brief Generic system work queue. */
static struct work_queue *queue;

struct work_queue **arch_work_queue_get(void)
{
return &queue;
}
5 changes: 5 additions & 0 deletions src/include/sof/work.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ struct work_queue_timesource {
(w)->cb_data = xd; \
(w)->flags = xflags;

struct work_queue **arch_work_queue_get(void);

/* schedule/cancel work on work queue */
void work_schedule(struct work_queue *queue, struct work *w, uint64_t timeout);
void work_reschedule(struct work_queue *queue, struct work *w, uint64_t timeout);
Expand All @@ -85,4 +87,7 @@ struct work_queue *work_new_queue(struct work_queue_timesource *ts);
/* init system workq */
void init_system_workq(struct work_queue_timesource *ts);

/* free system workq */
void free_system_workq(void);

#endif
35 changes: 25 additions & 10 deletions src/lib/work.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ struct work_queue {
uint64_t run_ticks; /* ticks when last run */
};

/* generic system work queue */
static struct work_queue *queue_;

static inline int work_set_timer(struct work_queue *queue, uint64_t ticks)
{
int ret;
Expand Down Expand Up @@ -363,7 +360,7 @@ void work_schedule(struct work_queue *queue, struct work *w, uint64_t timeout)

void work_schedule_default(struct work *w, uint64_t timeout)
{
work_schedule(queue_, w, timeout);
work_schedule(*arch_work_queue_get(), w, timeout);
}

static void reschedule(struct work_queue *queue, struct work *w, uint64_t time)
Expand Down Expand Up @@ -406,17 +403,18 @@ void work_reschedule(struct work_queue *queue, struct work *w, uint64_t timeout)

void work_reschedule_default(struct work *w, uint64_t timeout)
{
struct work_queue *queue = *arch_work_queue_get();
uint64_t time;

/* convert timeout micro seconds to CPU clock ticks */
time = queue_->ticks_per_usec * timeout + work_get_timer(queue_);
time = queue->ticks_per_usec * timeout + work_get_timer(queue);

reschedule(queue_, w, time);
reschedule(queue, w, time);
}

void work_reschedule_default_at(struct work *w, uint64_t time)
{
reschedule(queue_, w, time);
reschedule(*arch_work_queue_get(), w, time);
}

void work_cancel(struct work_queue *queue, struct work *w)
Expand All @@ -436,15 +434,15 @@ void work_cancel(struct work_queue *queue, struct work *w)

void work_cancel_default(struct work *w)
{
work_cancel(queue_, w);
work_cancel(*arch_work_queue_get(), w);
}

struct work_queue *work_new_queue(struct work_queue_timesource *ts)
{
struct work_queue *queue;

/* init work queue */
queue = rmalloc(RZONE_SYS, SOF_MEM_CAPS_RAM, sizeof(*queue_));
queue = rmalloc(RZONE_RUNTIME, SOF_MEM_CAPS_RAM, sizeof(*queue));

list_init(&queue->work);
spinlock_init(&queue->lock);
Expand All @@ -466,5 +464,22 @@ struct work_queue *work_new_queue(struct work_queue_timesource *ts)

void init_system_workq(struct work_queue_timesource *ts)
{
queue_ = work_new_queue(ts);
struct work_queue **queue = arch_work_queue_get();
*queue = work_new_queue(ts);
}

void free_system_workq(void)
{
struct work_queue **queue = arch_work_queue_get();
uint32_t flags;

spin_lock_irq(&(*queue)->lock, flags);

timer_unregister(&(*queue)->ts->timer);
notifier_unregister(&(*queue)->notifier);
list_item_del(&(*queue)->work);

spin_unlock_irq(&(*queue)->lock, flags);

rfree(*queue);
}