Changeset fd07e57b in mainline for uspace


Ignore:
Timestamp:
2014-01-05T21:25:41Z (11 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4aa2a27
Parents:
aacdb8e (diff), ca05e9b (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge cherrypicked kernel logger.

  • Old klog sybsystem was renamed to kio
  • Kernel and user-space log messages are stored in both logs (kernel logs end up in log/kernel file)
Location:
uspace
Files:
4 added
12 edited
2 moved

Legend:

Unmodified
Added
Removed
  • uspace/Makefile

    raacdb8e rfd07e57b  
    5050        app/kill \
    5151        app/killall \
    52         app/klog \
     52        app/kio \
    5353        app/loc \
    5454        app/logset \
     
    9292        srv/locsrv \
    9393        srv/logger \
     94        srv/klog \
    9495        srv/devman \
    9596        srv/loader \
  • uspace/app/init/init.c

    raacdb8e rfd07e57b  
    336336                srv_start("/srv/tmpfs");
    337337       
     338        srv_start("/srv/klog");
    338339        srv_start("/srv/locfs");
    339340        srv_start("/srv/taskmon");
  • uspace/app/kio/Makefile

    raacdb8e rfd07e57b  
    3131LIBS = $(LIBCLUI_PREFIX)/libclui.a
    3232EXTRA_CFLAGS = -I$(LIBCLUI_PREFIX)
    33 BINARY = klog
     33BINARY = kio
    3434
    3535SOURCES = \
    36         klog.c
     36        kio.c
    3737
    3838include $(USPACE_PREFIX)/Makefile.common
  • uspace/app/kio/kio.c

    raacdb8e rfd07e57b  
    2727 */
    2828
    29 /** @addtogroup klog KLog
    30  * @brief HelenOS KLog
     29/** @addtogroup kio KIO
     30 * @brief HelenOS KIO
    3131 * @{
    3232 */
     
    4242#include <errno.h>
    4343#include <str_error.h>
    44 #include <io/klog.h>
     44#include <io/kio.h>
    4545#include <sysinfo.h>
    4646#include <malloc.h>
     
    5050#include <tinput.h>
    5151
    52 #define NAME       "klog"
    53 #define LOG_FNAME  "/log/klog"
     52#define NAME       "kio"
     53#define LOG_FNAME  "/log/kio"
    5454
    5555/* Producer/consumer buffers */
     
    6262static prodcons_t pc;
    6363
    64 /* Pointer to klog area */
    65 static wchar_t *klog;
    66 static size_t klog_length;
     64/* Pointer to kio area */
     65static wchar_t *kio;
     66static size_t kio_length;
    6767
    6868/* Notification mutex */
     
    7575 *
    7676 * @param length Number of characters to copy.
    77  * @param data   Pointer to the kernel klog buffer.
     77 * @param data   Pointer to the kernel kio buffer.
    7878 *
    7979 */
     
    142142/** Kernel notification handler
    143143 *
    144  * Receives kernel klog notifications.
     144 * Receives kernel kio notifications.
    145145 *
    146146 * @param callid IPC call ID
     
    156156         * starving.
    157157         *
    158          * Note: Usually the automatic masking of the klog
     158         * Note: Usually the automatic masking of the kio
    159159         * notifications on the kernel side does the trick
    160160         * of limiting the chance of accidentally copying
    161161         * the same data multiple times. However, due to
    162          * the non-blocking architecture of klog notifications,
     162         * the non-blocking architecture of kio notifications,
    163163         * this possibility cannot be generally avoided.
    164164         */
     
    166166        fibril_mutex_lock(&mtx);
    167167       
    168         size_t klog_start = (size_t) IPC_GET_ARG1(*call);
    169         size_t klog_len = (size_t) IPC_GET_ARG2(*call);
    170         size_t klog_stored = (size_t) IPC_GET_ARG3(*call);
    171        
    172         size_t offset = (klog_start + klog_len - klog_stored) % klog_length;
     168        size_t kio_start = (size_t) IPC_GET_ARG1(*call);
     169        size_t kio_len = (size_t) IPC_GET_ARG2(*call);
     170        size_t kio_stored = (size_t) IPC_GET_ARG3(*call);
     171       
     172        size_t offset = (kio_start + kio_len - kio_stored) % kio_length;
    173173       
    174174        /* Copy data from the ring buffer */
    175         if (offset + klog_stored >= klog_length) {
    176                 size_t split = klog_length - offset;
    177                
    178                 producer(split, klog + offset);
    179                 producer(klog_stored - split, klog);
     175        if (offset + kio_stored >= kio_length) {
     176                size_t split = kio_length - offset;
     177               
     178                producer(split, kio + offset);
     179                producer(kio_stored - split, kio);
    180180        } else
    181                 producer(klog_stored, klog + offset);
    182        
    183         event_unmask(EVENT_KLOG);
     181                producer(kio_stored, kio + offset);
     182       
     183        event_unmask(EVENT_KIO);
    184184        fibril_mutex_unlock(&mtx);
    185185}
     
    188188{
    189189        size_t pages;
    190         int rc = sysinfo_get_value("klog.pages", &pages);
    191         if (rc != EOK) {
    192                 fprintf(stderr, "%s: Unable to get number of klog pages\n",
     190        int rc = sysinfo_get_value("kio.pages", &pages);
     191        if (rc != EOK) {
     192                fprintf(stderr, "%s: Unable to get number of kio pages\n",
    193193                    NAME);
    194194                return rc;
     
    196196       
    197197        uintptr_t faddr;
    198         rc = sysinfo_get_value("klog.faddr", &faddr);
    199         if (rc != EOK) {
    200                 fprintf(stderr, "%s: Unable to get klog physical address\n",
     198        rc = sysinfo_get_value("kio.faddr", &faddr);
     199        if (rc != EOK) {
     200                fprintf(stderr, "%s: Unable to get kio physical address\n",
    201201                    NAME);
    202202                return rc;
     
    204204       
    205205        size_t size = pages * PAGE_SIZE;
    206         klog_length = size / sizeof(wchar_t);
     206        kio_length = size / sizeof(wchar_t);
    207207       
    208208        rc = physmem_map(faddr, pages, AS_AREA_READ | AS_AREA_CACHEABLE,
    209             (void *) &klog);
    210         if (rc != EOK) {
    211                 fprintf(stderr, "%s: Unable to map klog\n", NAME);
     209            (void *) &kio);
     210        if (rc != EOK) {
     211                fprintf(stderr, "%s: Unable to map kio\n", NAME);
    212212                return rc;
    213213        }
     
    215215        prodcons_initialize(&pc);
    216216        async_set_interrupt_received(notification_received);
    217         rc = event_subscribe(EVENT_KLOG, 0);
    218         if (rc != EOK) {
    219                 fprintf(stderr, "%s: Unable to register klog notifications\n",
     217        rc = event_subscribe(EVENT_KIO, 0);
     218        if (rc != EOK) {
     219                fprintf(stderr, "%s: Unable to register kio notifications\n",
    220220                    NAME);
    221221                return rc;
     
    236236
    237237        fibril_add_ready(fid);
    238         event_unmask(EVENT_KLOG);
    239         klog_update();
    240        
    241         tinput_set_prompt(input, "klog> ");
     238        event_unmask(EVENT_KIO);
     239        kio_update();
     240       
     241        tinput_set_prompt(input, "kio> ");
    242242
    243243        char *str;
     
    248248                }
    249249
    250                 klog_command(str, str_size(str));
     250                kio_command(str, str_size(str));
    251251                free(str);
    252252        }
  • uspace/app/trace/syscalls.c

    raacdb8e rfd07e57b  
    3838
    3939const sc_desc_t syscall_desc[] = {
    40     [SYS_KLOG] ={ "klog",                               3,      V_INT_ERRNO },
     40    [SYS_KIO] ={ "kio",                                 3,      V_INT_ERRNO },
    4141    [SYS_TLS_SET] = { "tls_set",                        1,      V_ERRNO },
    4242
  • uspace/lib/c/Makefile

    raacdb8e rfd07e57b  
    107107        generic/io/log.c \
    108108        generic/io/logctl.c \
     109        generic/io/kio.c \
    109110        generic/io/klog.c \
    110111        generic/io/snprintf.c \
  • uspace/lib/c/generic/assert.c

    raacdb8e rfd07e57b  
    3333#include <assert.h>
    3434#include <stdio.h>
    35 #include <io/klog.h>
     35#include <io/kio.h>
    3636#include <stdlib.h>
    3737#include <atomic.h>
     
    4444{
    4545        /*
    46          * Send the message safely to klog. Nested asserts should not occur.
     46         * Send the message safely to kio. Nested asserts should not occur.
    4747         */
    48         klog_printf("Assertion failed (%s) in file \"%s\", line %u.\n",
     48        kio_printf("Assertion failed (%s) in file \"%s\", line %u.\n",
    4949            cond, file, line);
    5050       
  • uspace/lib/c/generic/io/io.c

    raacdb8e rfd07e57b  
    4242#include <malloc.h>
    4343#include <async.h>
    44 #include <io/klog.h>
     44#include <io/kio.h>
    4545#include <vfs/vfs.h>
    4646#include <vfs/vfs_sess.h>
     
    5757        .error = true,
    5858        .eof = true,
    59         .klog = false,
     59        .kio = false,
    6060        .sess = NULL,
    6161        .btype = _IONBF,
     
    6767};
    6868
    69 static FILE stdout_klog = {
     69static FILE stdout_kio = {
    7070        .fd = -1,
    7171        .error = false,
    7272        .eof = false,
    73         .klog = true,
     73        .kio = true,
    7474        .sess = NULL,
    7575        .btype = _IOLBF,
     
    8181};
    8282
    83 static FILE stderr_klog = {
     83static FILE stderr_kio = {
    8484        .fd = -1,
    8585        .error = false,
    8686        .eof = false,
    87         .klog = true,
     87        .kio = true,
    8888        .sess = NULL,
    8989        .btype = _IONBF,
     
    113113                stdout = fdopen(1, "w");
    114114        } else {
    115                 stdout = &stdout_klog;
     115                stdout = &stdout_kio;
    116116                list_append(&stdout->link, &files);
    117117        }
     
    120120                stderr = fdopen(2, "w");
    121121        } else {
    122                 stderr = &stderr_klog;
     122                stderr = &stderr_kio;
    123123                list_append(&stderr->link, &files);
    124124        }
     
    267267        stream->error = false;
    268268        stream->eof = false;
    269         stream->klog = false;
     269        stream->kio = false;
    270270        stream->sess = NULL;
    271271        stream->need_sync = false;
     
    289289        stream->error = false;
    290290        stream->eof = false;
    291         stream->klog = false;
     291        stream->kio = false;
    292292        stream->sess = NULL;
    293293        stream->need_sync = false;
     
    314314       
    315315        if ((stream != &stdin_null)
    316             && (stream != &stdout_klog)
    317             && (stream != &stderr_klog))
     316            && (stream != &stdout_kio)
     317            && (stream != &stderr_kio))
    318318                free(stream);
    319319       
     
    382382                ssize_t wr;
    383383               
    384                 if (stream->klog)
    385                         wr = klog_write(buf + done, left);
     384                if (stream->kio)
     385                        wr = kio_write(buf + done, left);
    386386                else
    387387                        wr = write(stream->fd, buf + done, left);
     
    705705        _fflushbuf(stream);
    706706       
    707         if (stream->klog) {
    708                 klog_update();
     707        if (stream->kio) {
     708                kio_update();
    709709                return EOK;
    710710        }
     
    740740int fileno(FILE *stream)
    741741{
    742         if (stream->klog) {
     742        if (stream->kio) {
    743743                errno = EBADF;
    744744                return -1;
  • uspace/lib/c/generic/io/klog.c

    raacdb8e rfd07e57b  
    11/*
    2  * Copyright (c) 2006 Josef Cejka
    3  * Copyright (c) 2006 Jakub Vana
     2 * Copyright (c) 2013 Martin Sucha
    43 * All rights reserved.
    54 *
     
    4140#include <abi/klog.h>
    4241#include <io/klog.h>
    43 #include <io/printf_core.h>
     42#include <abi/log.h>
    4443
    45 size_t klog_write(const void *buf, size_t size)
     44size_t klog_write(log_level_t lvl, const void *buf, size_t size)
    4645{
    47         ssize_t ret = (ssize_t) __SYSCALL3(SYS_KLOG, KLOG_WRITE, (sysarg_t) buf, size);
     46        ssize_t ret = (ssize_t) __SYSCALL4(SYS_KLOG, KLOG_WRITE, (sysarg_t) buf,
     47            size, lvl);
    4848       
    4949        if (ret >= 0)
     
    5353}
    5454
    55 void klog_update(void)
     55int klog_read(void *data, size_t size)
    5656{
    57         (void) __SYSCALL3(SYS_KLOG, KLOG_UPDATE, (uintptr_t) NULL, 0);
    58 }
    59 
    60 void klog_command(const void *buf, size_t size)
    61 {
    62         (void) __SYSCALL3(SYS_KLOG, KLOG_COMMAND, (sysarg_t) buf, (sysarg_t) size);
    63 }
    64 
    65 /** Print formatted text to klog.
    66  *
    67  * @param fmt Format string
    68  *
    69  * \see For more details about format string see printf_core.
    70  *
    71  */
    72 int klog_printf(const char *fmt, ...)
    73 {
    74         va_list args;
    75         va_start(args, fmt);
    76        
    77         int ret = klog_vprintf(fmt, args);
    78        
    79         va_end(args);
    80        
    81         return ret;
    82 }
    83 
    84 static int klog_vprintf_str_write(const char *str, size_t size, void *data)
    85 {
    86         size_t wr = klog_write(str, size);
    87         return str_nlength(str, wr);
    88 }
    89 
    90 static int klog_vprintf_wstr_write(const wchar_t *str, size_t size, void *data)
    91 {
    92         size_t offset = 0;
    93         size_t chars = 0;
    94        
    95         while (offset < size) {
    96                 char buf[STR_BOUNDS(1)];
    97                 size_t sz = 0;
    98                
    99                 if (chr_encode(str[chars], buf, &sz, STR_BOUNDS(1)) == EOK)
    100                         klog_write(buf, sz);
    101                
    102                 chars++;
    103                 offset += sizeof(wchar_t);
    104         }
    105        
    106         return chars;
    107 }
    108 
    109 /** Print formatted text to klog.
    110  *
    111  * @param fmt Format string
    112  * @param ap  Format parameters
    113  *
    114  * \see For more details about format string see printf_core.
    115  *
    116  */
    117 int klog_vprintf(const char *fmt, va_list ap)
    118 {
    119         printf_spec_t ps = {
    120                 klog_vprintf_str_write,
    121                 klog_vprintf_wstr_write,
    122                 NULL
    123         };
    124        
    125         return printf_core(fmt, &ps, ap);
     57        return (int) __SYSCALL4(SYS_KLOG, KLOG_READ, (uintptr_t) data, size, 0);
    12658}
    12759
  • uspace/lib/c/generic/private/stdio.h

    raacdb8e rfd07e57b  
    5353        int eof;
    5454       
    55         /** Klog indicator */
    56         int klog;
     55        /** KIO indicator */
     56        int kio;
    5757       
    5858        /** Session to the file provider */
  • uspace/lib/c/include/io/klog.h

    raacdb8e rfd07e57b  
    11/*
    2  * Copyright (c) 2006 Jakub Vana
     2 * Copyright (c) 2013 Martin Sucha
    33 * All rights reserved.
    44 *
     
    3939#include <stdarg.h>
    4040#include <io/verify.h>
     41#include <stdio.h>
     42#include <stdlib.h>
     43#include <str.h>
     44#include <abi/log.h>
    4145
    42 extern size_t klog_write(const void *, size_t);
    43 extern void klog_update(void);
    44 extern void klog_command(const void *, size_t);
    45 extern int klog_printf(const char *, ...)
    46     PRINTF_ATTRIBUTE(1, 2);
    47 extern int klog_vprintf(const char *, va_list);
     46extern size_t klog_write(log_level_t, const void *, size_t);
     47extern int klog_read(void *, size_t);
     48
     49#define KLOG_PRINTF(lvl, fmt, ...) ({ \
     50        char *_fmt = str_dup(fmt); \
     51        size_t _fmtsize = str_size(_fmt); \
     52        if (_fmtsize > 0 && _fmt[_fmtsize - 1] == '\n') \
     53                _fmt[_fmtsize - 1] = 0; \
     54        char *_s; \
     55        int _c = asprintf(&_s, _fmt, ##__VA_ARGS__); \
     56        free(_fmt); \
     57        if (_c >= 0) { \
     58                _c = klog_write((lvl), _s, str_size(_s)); \
     59                free(_s); \
     60        }; \
     61        (_c >= 0); \
     62})
    4863
    4964#endif
  • uspace/lib/c/include/io/log.h

    raacdb8e rfd07e57b  
    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). */
  • uspace/lib/c/include/stdio.h

    raacdb8e rfd07e57b  
    4040#include <str.h>
    4141#include <io/verify.h>
    42 #include <abi/klog.h>
     42#include <abi/kio.h>
    4343
    4444#define EOF  (-1)
     
    5252                int _n = snprintf(_buf, sizeof(_buf), fmt, ##__VA_ARGS__); \
    5353                if (_n > 0) \
    54                         (void) __SYSCALL3(SYS_KLOG, KLOG_WRITE, (sysarg_t) _buf, str_size(_buf)); \
     54                        (void) __SYSCALL3(SYS_KIO, KIO_WRITE, (sysarg_t) _buf, str_size(_buf)); \
    5555        }
    5656
  • uspace/srv/logger/writer.c

    raacdb8e rfd07e57b  
    4040#include <io/log.h>
    4141#include <io/logctl.h>
     42#include <io/klog.h>
    4243#include <ns.h>
    4344#include <async.h>
     
    7980        }
    8081
    81         printf("[%s] %s: %s\n",
     82        KLOG_PRINTF(level, "[%s] %s: %s\n",
    8283            log->full_name, log_level_str(level),
    8384            (const char *) message);
Note: See TracChangeset for help on using the changeset viewer.