Changeset 91db0280 in mainline


Ignore:
Timestamp:
2014-01-05T19:59:56Z (10 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
927cd9c
Parents:
6fa9a99d
Message:

Cherrypick kernel logging facility

Files:
6 added
7 edited

Legend:

Unmodified
Added
Removed
  • abi/include/abi/ipc/event.h

    r6fa9a99d r91db0280  
    4444        /** A task/thread has faulted and will be terminated */
    4545        EVENT_FAULT,
     46        /** New data available in kernel log */
     47        EVENT_KLOG,
    4648        EVENT_END
    4749} event_type_t;
  • kernel/Makefile

    r6fa9a99d r91db0280  
    212212        generic/src/debug/debug.c \
    213213        generic/src/interrupt/interrupt.c \
     214        generic/src/log/log.c \
    214215        generic/src/main/main.c \
    215216        generic/src/main/kinit.c \
  • kernel/generic/include/console/console.h

    r6fa9a99d r91db0280  
    3939#include <print.h>
    4040#include <console/chardev.h>
     41#include <synch/spinlock.h>
    4142
    4243#define PAGING(counter, increment, before, after) \
     
    6465extern void kio_init(void);
    6566extern void kio_update(void *);
     67extern void kio_flush(void);
     68extern void kio_push_char(const wchar_t);
     69SPINLOCK_EXTERN(kio_lock);
    6670
    6771extern wchar_t getc(indev_t *indev);
  • kernel/generic/include/debug.h

    r6fa9a99d r91db0280  
    107107#define LOG(format, ...) \
    108108        do { \
    109                 printf("%s() from %s at %s:%u: " format "\n", __func__, \
     109                log(LF_OTHER, LVL_DEBUG, \
     110                    "%s() from %s at %s:%u: " format,__func__, \
    110111                    symtab_fmt_name_lookup(CALLER), __FILE__, __LINE__, \
    111112                    ##__VA_ARGS__); \
  • kernel/generic/src/console/console.c

    r6fa9a99d r91db0280  
    7676
    7777/** Kernel log spinlock */
    78 SPINLOCK_STATIC_INITIALIZE_NAME(kio_lock, "kio_lock");
     78SPINLOCK_INITIALIZE_NAME(kio_lock, "kio_lock");
    7979
    8080/** Physical memory area used for kio buffer */
     
    263263}
    264264
    265 void putchar(const wchar_t ch)
     265/** Flush characters that are stored in the output buffer
     266 *
     267 */
     268void kio_flush(void)
    266269{
    267270        bool ordy = ((stdout) && (stdout->op->write));
    268271       
     272        if (!ordy)
     273                return;
     274
    269275        spinlock_lock(&kio_lock);
    270        
    271         /* Print charaters stored in kernel log */
    272         if (ordy) {
    273                 while (kio_stored > 0) {
    274                         wchar_t tmp = kio[(kio_start + kio_len - kio_stored) % KIO_LENGTH];
    275                         kio_stored--;
    276                        
    277                         /*
    278                          * We need to give up the spinlock for
    279                          * the physical operation of writting out
    280                          * the character.
    281                          */
    282                         spinlock_unlock(&kio_lock);
    283                         stdout->op->write(stdout, tmp);
    284                         spinlock_lock(&kio_lock);
    285                 }
    286         }
    287        
    288         /* Store character in the cyclic kernel log */
     276
     277        /* Print characters that weren't printed earlier */
     278        while (kio_stored > 0) {
     279                wchar_t tmp = kio[(kio_start + kio_len - kio_stored) % KIO_LENGTH];
     280                kio_stored--;
     281
     282                /*
     283                 * We need to give up the spinlock for
     284                 * the physical operation of writing out
     285                 * the character.
     286                 */
     287                spinlock_unlock(&kio_lock);
     288                stdout->op->write(stdout, tmp);
     289                spinlock_lock(&kio_lock);
     290        }
     291
     292        spinlock_unlock(&kio_lock);
     293}
     294
     295/** Put a character into the output buffer.
     296 *
     297 * The caller is required to hold kio_lock
     298 */
     299void kio_push_char(const wchar_t ch)
     300{
    289301        kio[(kio_start + kio_len) % KIO_LENGTH] = ch;
    290302        if (kio_len < KIO_LENGTH)
     
    293305                kio_start = (kio_start + 1) % KIO_LENGTH;
    294306       
    295         if (!ordy) {
    296                 if (kio_stored < kio_len)
    297                         kio_stored++;
    298         }
     307        if (kio_stored < kio_len)
     308                kio_stored++;
    299309       
    300310        /* The character is stored for uspace */
    301311        if (kio_uspace < kio_len)
    302312                kio_uspace++;
    303        
     313}
     314
     315void putchar(const wchar_t ch)
     316{
     317        bool ordy = ((stdout) && (stdout->op->write));
     318       
     319        spinlock_lock(&kio_lock);
     320        kio_push_char(ch);
    304321        spinlock_unlock(&kio_lock);
    305322       
    306         if (ordy) {
    307                 /*
    308                  * Output the character. In this case
    309                  * it should be no longer buffered.
    310                  */
    311                 stdout->op->write(stdout, ch);
    312         } else {
     323        /* Output stored characters */
     324        kio_flush();
     325       
     326        if (!ordy) {
    313327                /*
    314328                 * No standard output routine defined yet.
  • kernel/generic/src/main/main.c

    r6fa9a99d r91db0280  
    6262#include <console/kconsole.h>
    6363#include <console/console.h>
     64#include <log.h>
    6465#include <cpu.h>
    6566#include <align.h>
     
    282283        event_init();
    283284        kio_init();
     285        log_init();
    284286        stats_init();
    285287       
  • uspace/lib/c/include/io/log.h

    r6fa9a99d r91db0280  
    3939#include <io/verify.h>
    4040
    41 /** Log message level. */
    42 typedef enum {
    43         /** Fatal error, program is not able to recover at all. */
    44         LVL_FATAL,
    45         /** Serious error but the program can recover from it. */
    46         LVL_ERROR,
    47         /** Easily recoverable problem. */
    48         LVL_WARN,
    49         /** Information message that ought to be printed by default. */
    50         LVL_NOTE,
    51         /** Debugging purpose message. */
    52         LVL_DEBUG,
    53         /** More detailed debugging message. */
    54         LVL_DEBUG2,
    55        
    56         /** For checking range of values */
    57         LVL_LIMIT
    58 } log_level_t;
     41#include <abi/log.h>
    5942
    6043/** Log itself (logging target). */
Note: See TracChangeset for help on using the changeset viewer.