1010#include <rtos/string.h>
1111#include <user/debug_stream.h>
1212#include <user/debug_stream_slot.h>
13+ #include <zephyr/kernel.h>
1314
1415LOG_MODULE_REGISTER (debug_stream_slot );
1516
1617struct cpu_mutex {
17- struct k_mutex m ;
18+ struct k_spinlock l ;
1819} __aligned (CONFIG_DCACHE_LINE_SIZE );
1920
2021/* CPU specific mutexes for each circular buffer */
@@ -66,6 +67,7 @@ int debug_stream_slot_send_record(struct debug_stream_record *rec)
6667 debug_stream_get_circular_buffer (& desc , arch_proc_id ());
6768 uint32_t record_size = rec -> size_words ;
6869 uint32_t record_start , buf_remain ;
70+ k_spinlock_key_t key ;
6971
7072 LOG_DBG ("Sending record %u id %u len %u" , rec -> seqno , rec -> id , rec -> size_words );
7173
@@ -77,7 +79,7 @@ int debug_stream_slot_send_record(struct debug_stream_record *rec)
7779 desc .buf_words , desc .core_id , desc .buf_words , desc .offset );
7880 return - ENOMEM ;
7981 }
80- k_mutex_lock (& cpu_mutex [arch_proc_id ()].m , K_FOREVER );
82+ key = k_spin_lock (& cpu_mutex [arch_proc_id ()].l );
8183
8284 rec -> seqno = buf -> next_seqno ++ ;
8385 rec -> size_words = record_size + 1 ; /* +1 for size at the end of record */
@@ -105,7 +107,7 @@ int debug_stream_slot_send_record(struct debug_stream_record *rec)
105107 buf -> data [buf -> w_ptr ] = record_size + 1 ;
106108 buf -> w_ptr = (buf -> w_ptr + 1 ) % desc .buf_words ;
107109
108- k_mutex_unlock (& cpu_mutex [arch_proc_id ()].m );
110+ k_spin_unlock (& cpu_mutex [arch_proc_id ()].l , key );
109111
110112 LOG_DBG ("Record %u id %u len %u sent" , rec -> seqno , rec -> id , record_size );
111113 return 0 ;
@@ -159,14 +161,6 @@ static int debug_stream_slot_init(void)
159161
160162 buf -> next_seqno = 0 ;
161163 buf -> w_ptr = 0 ;
162- k_mutex_init (& cpu_mutex [i ].m );
163- /* The core specific mutexes are now .bss which is uncached so the
164- * following line is commented out. However, since the mutexes are
165- * core specific there should be nothing preventing from having them
166- * in cached memory.
167- *
168- * sys_cache_data_flush_range(&cpu_mutex[i], sizeof(cpu_mutex[i]));
169- */
170164 }
171165 LOG_INF ("Debug stream slot initialized" );
172166
0 commit comments