Changes in kernel/generic/src/log/log.c [28a5ebd:690ad20] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/log/log.c
r28a5ebd r690ad20 33 33 */ 34 34 35 #include <sysinfo/sysinfo.h> 36 #include <synch/spinlock.h> 37 #include <typedefs.h> 35 #include <abi/log.h> 36 #include <arch.h> 37 #include <atomic.h> 38 #include <console/console.h> 39 #include <ddi/ddi.h> 38 40 #include <ddi/irq.h> 39 #include < ddi/ddi.h>41 #include <errno.h> 40 42 #include <ipc/event.h> 41 43 #include <ipc/irq.h> 42 #include < arch.h>44 #include <log.h> 43 45 #include <panic.h> 44 #include <putchar.h> 45 #include <atomic.h> 46 #include <print.h> 47 #include <printf_core.h> 48 #include <stdarg.h> 49 #include <stdlib.h> 50 #include <str.h> 51 #include <synch/spinlock.h> 46 52 #include <syscall/copy.h> 47 #include <errno.h> 48 #include <str.h> 49 #include <print.h> 50 #include <printf/printf_core.h> 51 #include <stdarg.h> 52 #include <log.h> 53 #include <console/console.h> 54 #include <abi/log.h> 55 #include <stdlib.h> 53 #include <sysinfo/sysinfo.h> 54 #include <typedefs.h> 56 55 57 56 #define LOG_PAGES 8 … … 60 59 61 60 /** Cyclic buffer holding the data for kernel log */ 62 uint8_t log_buffer[LOG_LENGTH] __attribute__((aligned(PAGE_SIZE)));61 static uint8_t log_buffer[LOG_LENGTH] __attribute__((aligned(PAGE_SIZE))); 63 62 64 63 /** Kernel log initialized */ … … 66 65 67 66 /** Position in the cyclic buffer where the first log entry starts */ 68 s ize_t log_start = 0;67 static size_t log_start = 0; 69 68 70 69 /** Sum of length of all log entries currently stored in the cyclic buffer */ 71 s ize_t log_used = 0;70 static size_t log_used = 0; 72 71 73 72 /** Log spinlock */ 74 SPINLOCK_STATIC_INITIALIZE_NAME(log_lock, "log_lock");73 static IRQ_SPINLOCK_INITIALIZE(log_lock); 75 74 76 75 /** Overall count of logged messages, which may overflow as needed */ … … 151 150 void log_begin(log_facility_t fac, log_level_t level) 152 151 { 153 spinlock_lock(&log_lock); 154 spinlock_lock(&kio_lock); 152 console_lock(); 153 irq_spinlock_lock(&log_lock, true); 154 irq_spinlock_lock(&kio_lock, true); 155 155 156 156 log_current_start = (log_start + log_used) % LOG_LENGTH; … … 178 178 log_used += log_current_len; 179 179 180 kio_push_ char('\n');181 spinlock_unlock(&kio_lock);182 spinlock_unlock(&log_lock);180 kio_push_bytes("\n", 1); 181 irq_spinlock_unlock(&kio_lock, true); 182 irq_spinlock_unlock(&log_lock, true); 183 183 184 184 /* This has to be called after we released the locks above */ … … 186 186 kio_update(NULL); 187 187 log_update(NULL); 188 console_unlock(); 188 189 } 189 190 … … 193 194 return; 194 195 195 spinlock_lock(&log_lock);196 irq_spinlock_lock(&log_lock, true); 196 197 if (next_for_uspace < log_used) 197 198 event_notify_0(EVENT_KLOG, true); 198 spinlock_unlock(&log_lock);199 irq_spinlock_unlock(&log_lock, true); 199 200 } 200 201 201 202 static int log_printf_str_write(const char *str, size_t size, void *data) 202 203 { 203 size_t offset = 0; 204 size_t chars = 0; 205 206 while (offset < size) { 207 kio_push_char(str_decode(str, &offset, size)); 208 chars++; 209 } 210 204 kio_push_bytes(str, size); 211 205 log_append((const uint8_t *)str, size); 212 213 return chars; 214 } 215 216 static int log_printf_wstr_write(const char32_t *wstr, size_t size, void *data) 217 { 218 char buffer[16]; 219 size_t offset = 0; 220 size_t chars = 0; 221 222 for (offset = 0; offset < size; offset += sizeof(char32_t), chars++) { 223 kio_push_char(wstr[chars]); 224 225 size_t buffer_offset = 0; 226 errno_t rc = chr_encode(wstr[chars], buffer, &buffer_offset, 16); 227 if (rc != EOK) { 228 return EOF; 229 } 230 231 log_append((const uint8_t *)buffer, buffer_offset); 232 } 233 234 return chars; 206 return EOK; 235 207 } 236 208 … … 241 213 int log_vprintf(const char *fmt, va_list args) 242 214 { 243 int ret;244 245 215 printf_spec_t ps = { 246 216 log_printf_str_write, 247 log_printf_wstr_write,248 217 NULL 249 218 }; 250 219 251 ret = printf_core(fmt, &ps, args); 252 253 return ret; 220 return printf_core(fmt, &ps, args); 254 221 } 255 222 … … 334 301 rc = EOK; 335 302 336 spinlock_lock(&log_lock);303 irq_spinlock_lock(&log_lock, true); 337 304 338 305 while (next_for_uspace < log_used) { … … 364 331 } 365 332 366 spinlock_unlock(&log_lock);333 irq_spinlock_unlock(&log_lock, true); 367 334 368 335 if (rc != EOK) {
Note:
See TracChangeset
for help on using the changeset viewer.