Skip to content

Commit ce7f99b

Browse files
authored
Merge pull request #466 from tlauda/topic/smp-notifier
notifier: add notifier to core_context
2 parents b180af8 + bebfad8 commit ce7f99b

9 files changed

Lines changed: 147 additions & 30 deletions

File tree

src/arch/xtensa/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ sof_SOURCES += \
5454
smp/xtos/_vectors.S \
5555
smp/cpu.c \
5656
smp/init.c \
57+
smp/notifier.c \
5758
smp/schedule.c \
5859
smp/task.c \
5960
smp/work.c
@@ -63,6 +64,7 @@ sof_SOURCES += \
6364
up/xtos/_vectors.S \
6465
up/cpu.c \
6566
up/init.c \
67+
up/notifier.c \
6668
up/schedule.c \
6769
up/task.c \
6870
up/work.c

src/arch/xtensa/smp/cpu.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ void cpu_power_down_core(void)
107107

108108
free_system_workq();
109109

110+
free_system_notify();
111+
110112
/* free entire sys heap, an instance dedicated for this core */
111113
free_heap(RZONE_SYS);
112114

src/arch/xtensa/smp/notifier.c

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* * Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* * Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
* * Neither the name of the Intel Corporation nor the
13+
* names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*
28+
* Author: Tomasz Lauda <tomasz.lauda@linux.intel.com>
29+
*
30+
*/
31+
32+
/**
33+
* \file arch/xtensa/smp/notifier.c
34+
* \brief Xtensa SMP notifier implementation file
35+
* \authors Tomasz Lauda <tomasz.lauda@linux.intel.com>
36+
*/
37+
38+
#include <xtos-structs.h>
39+
#include <arch/cpu.h>
40+
#include <sof/notifier.h>
41+
42+
struct notify **arch_notify_get(void)
43+
{
44+
struct core_context *ctx = (struct core_context *)cpu_read_threadptr();
45+
46+
return &ctx->notify;
47+
}

src/arch/xtensa/smp/xtos/xtos-structs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
struct idc;
3737
struct irq_task;
38+
struct notify;
3839
struct schedule_data;
3940
struct work_queue;
4041

@@ -59,6 +60,7 @@ struct core_context {
5960
struct irq_task *irq_high_task;
6061
struct schedule_data *sch;
6162
struct work_queue *queue;
63+
struct notify *notify;
6264
struct idc *idc;
6365
};
6466

src/arch/xtensa/up/notifier.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (c) 2018, Intel Corporation
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are met:
7+
* * Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* * Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
* * Neither the name of the Intel Corporation nor the
13+
* names of its contributors may be used to endorse or promote products
14+
* derived from this software without specific prior written permission.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
*
28+
* Author: Tomasz Lauda <tomasz.lauda@linux.intel.com>
29+
*
30+
*/
31+
32+
/**
33+
* \file arch/xtensa/up/notifier.c
34+
* \brief Xtensa UP notifier implementation file
35+
* \authors Tomasz Lauda <tomasz.lauda@linux.intel.com>
36+
*/
37+
38+
#include <sof/notifier.h>
39+
40+
/** \brief Notify data pointer. */
41+
static struct notify *notify;
42+
43+
struct notify **arch_notify_get(void)
44+
{
45+
return &notify;
46+
}

src/include/sof/notifier.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,35 @@
3333

3434
#include <stdint.h>
3535
#include <sof/list.h>
36+
#include <sof/lock.h>
3637

3738
struct sof;
3839

3940
/* notifier general IDs */
4041
#define NOTIFIER_ID_CPU_FREQ 0
4142
#define NOTIFIER_ID_SSP_FREQ 1
4243

44+
struct notify {
45+
spinlock_t lock; /* notifier lock */
46+
struct list_item list; /* list of notifiers */
47+
};
48+
4349
struct notifier {
4450
uint32_t id;
4551
struct list_item list;
4652
void *cb_data;
4753
void (*cb)(int message, void *cb_data, void *event_data);
4854
};
4955

56+
struct notify **arch_notify_get(void);
57+
5058
void notifier_register(struct notifier *notifier);
5159
void notifier_unregister(struct notifier *notifier);
5260

5361
void notifier_event(int id, int message, void *event_data);
5462

5563
void init_system_notify(struct sof *sof);
5664

65+
void free_system_notify(void);
66+
5767
#endif

src/init/init.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ int slave_core_init(struct sof *sof)
100100
if (err < 0)
101101
panic(SOF_IPC_PANIC_ARCH);
102102

103+
trace_point(TRACE_BOOT_SYS_NOTE);
104+
init_system_notify(sof);
105+
103106
trace_point(TRACE_BOOT_SYS_SCHED);
104107
scheduler_init(sof);
105108

src/lib/notifier.c

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,56 +30,64 @@
3030

3131
#include <sof/notifier.h>
3232
#include <sof/sof.h>
33-
#include <sof/lock.h>
3433
#include <sof/list.h>
35-
36-
/* General purpose notifiers */
37-
38-
struct notify {
39-
spinlock_t lock;
40-
struct list_item list; /* list of notifiers */
41-
};
42-
43-
static struct notify _notify;
34+
#include <sof/alloc.h>
4435

4536
void notifier_register(struct notifier *notifier)
4637
{
47-
spin_lock(&_notify.lock);
48-
list_item_prepend(&notifier->list, &_notify.list);
49-
spin_unlock(&_notify.lock);
38+
struct notify *notify = *arch_notify_get();
39+
40+
spin_lock(&notify->lock);
41+
list_item_prepend(&notifier->list, &notify->list);
42+
spin_unlock(&notify->lock);
5043
}
5144

5245
void notifier_unregister(struct notifier *notifier)
5346
{
54-
spin_lock(&_notify.lock);
47+
struct notify *notify = *arch_notify_get();
48+
49+
spin_lock(&notify->lock);
5550
list_item_del(&notifier->list);
56-
spin_unlock(&_notify.lock);
51+
spin_unlock(&notify->lock);
5752
}
5853

5954
void notifier_event(int id, int message, void *event_data)
6055
{
56+
struct notify *notify = *arch_notify_get();
6157
struct list_item *wlist;
6258
struct notifier *n;
6359

64-
spin_lock(&_notify.lock);
60+
spin_lock(&notify->lock);
6561

66-
if (list_is_empty(&_notify.list))
62+
if (list_is_empty(&notify->list))
6763
goto out;
6864

6965
/* iterate through notifiers and send event to interested clients */
70-
list_for_item(wlist, &_notify.list) {
66+
list_for_item(wlist, &notify->list) {
7167

7268
n = container_of(wlist, struct notifier, list);
7369
if (n->id == id)
7470
n->cb(message, n->cb_data, event_data);
7571
}
7672

7773
out:
78-
spin_unlock(&_notify.lock);
74+
spin_unlock(&notify->lock);
7975
}
8076

8177
void init_system_notify(struct sof *sof)
8278
{
83-
list_init(&_notify.list);
84-
spinlock_init(&_notify.lock);
79+
struct notify **notify = arch_notify_get();
80+
*notify = rzalloc(RZONE_SYS, SOF_MEM_CAPS_RAM, sizeof(**notify));
81+
82+
list_init(&(*notify)->list);
83+
spinlock_init(&(*notify)->lock);
84+
}
85+
86+
void free_system_notify(void)
87+
{
88+
struct notify *notify = *arch_notify_get();
89+
90+
spin_lock(&notify->lock);
91+
list_item_del(&notify->list);
92+
spin_unlock(&notify->lock);
8593
}

src/lib/work.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -501,13 +501,11 @@ struct work_queue *work_new_queue(struct work_queue_timesource *ts)
501501
/* TODO: configurable through IPC */
502502
queue->timeout = PLATFORM_WORKQ_DEFAULT_TIMEOUT;
503503

504-
if (cpu_get_id() == PLATFORM_MASTER_CORE_ID) {
505-
/* notification of clk changes */
506-
queue->notifier.cb = work_notify;
507-
queue->notifier.cb_data = queue;
508-
queue->notifier.id = ts->notifier;
509-
notifier_register(&queue->notifier);
510-
}
504+
/* notification of clk changes */
505+
queue->notifier.cb = work_notify;
506+
queue->notifier.cb_data = queue;
507+
queue->notifier.id = ts->notifier;
508+
notifier_register(&queue->notifier);
511509

512510
/* register system timer */
513511
timer_register(&queue->ts->timer, queue_run, queue);
@@ -539,8 +537,7 @@ void free_system_workq(void)
539537

540538
timer_unregister(&(*queue)->ts->timer);
541539

542-
if (cpu_get_id() == PLATFORM_MASTER_CORE_ID)
543-
notifier_unregister(&(*queue)->notifier);
540+
notifier_unregister(&(*queue)->notifier);
544541

545542
list_item_del(&(*queue)->work);
546543

0 commit comments

Comments
 (0)