Changeset df29f24 in mainline for kernel/generic/src/console/console.c


Ignore:
Timestamp:
2011-06-01T09:04:08Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0a7627b, c9f0975
Parents:
e51a514 (diff), 5d1b3aa (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 mainline changes

Conflicts - trivial to solve
In kernel/generic/src/mm/page.c - sys_page_find_mapping does
not use locking when accessing page tables (hope that is correct).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/console/console.c

    re51a514 rdf29f24  
    5555#define KLOG_PAGES    8
    5656#define KLOG_LENGTH   (KLOG_PAGES * PAGE_SIZE / sizeof(wchar_t))
    57 #define KLOG_LATENCY  8
    5857
    5958/** Kernel log cyclic buffer */
     
    6160
    6261/** Kernel log initialized */
    63 static bool klog_inited = false;
     62static atomic_t klog_inited = {false};
    6463
    6564/** First kernel log characters */
     
    7675
    7776/** Kernel log spinlock */
    78 SPINLOCK_STATIC_INITIALIZE_NAME(klog_lock, "*klog_lock");
     77SPINLOCK_STATIC_INITIALIZE_NAME(klog_lock, "klog_lock");
    7978
    8079/** Physical memory area used for klog buffer */
     
    165164        sysinfo_set_item_val("klog.faddr", NULL, (sysarg_t) faddr);
    166165        sysinfo_set_item_val("klog.pages", NULL, KLOG_PAGES);
    167 
     166       
    168167        event_set_unmask_callback(EVENT_KLOG, klog_update);
    169        
    170         spinlock_lock(&klog_lock);
    171         klog_inited = true;
    172         spinlock_unlock(&klog_lock);
     168        atomic_set(&klog_inited, true);
    173169}
    174170
     
    265261void klog_update(void)
    266262{
     263        if (!atomic_get(&klog_inited))
     264                return;
     265       
    267266        spinlock_lock(&klog_lock);
    268267       
    269         if ((klog_inited) && (klog_uspace > 0)) {
     268        if (klog_uspace > 0) {
    270269                if (event_notify_3(EVENT_KLOG, true, klog_start, klog_len,
    271270                    klog_uspace) == EOK)
     
    278277void putchar(const wchar_t ch)
    279278{
     279        bool ordy = ((stdout) && (stdout->op->write));
     280       
    280281        spinlock_lock(&klog_lock);
    281282       
    282         if ((klog_stored > 0) && (stdout) && (stdout->op->write)) {
    283                 /* Print charaters stored in kernel log */
    284                 size_t i;
    285                 for (i = klog_len - klog_stored; i < klog_len; i++)
    286                         stdout->op->write(stdout, klog[(klog_start + i) % KLOG_LENGTH], silent);
    287                 klog_stored = 0;
     283        /* Print charaters stored in kernel log */
     284        if (ordy) {
     285                while (klog_stored > 0) {
     286                        wchar_t tmp = klog[(klog_start + klog_len - klog_stored) % KLOG_LENGTH];
     287                        klog_stored--;
     288                       
     289                        /*
     290                         * We need to give up the spinlock for
     291                         * the physical operation of writting out
     292                         * the character.
     293                         */
     294                        spinlock_unlock(&klog_lock);
     295                        stdout->op->write(stdout, tmp, silent);
     296                        spinlock_lock(&klog_lock);
     297                }
    288298        }
    289299       
     
    295305                klog_start = (klog_start + 1) % KLOG_LENGTH;
    296306       
    297         if ((stdout) && (stdout->op->write))
     307        if (!ordy) {
     308                if (klog_stored < klog_len)
     309                        klog_stored++;
     310        }
     311       
     312        /* The character is stored for uspace */
     313        if (klog_uspace < klog_len)
     314                klog_uspace++;
     315       
     316        spinlock_unlock(&klog_lock);
     317       
     318        if (ordy) {
     319                /*
     320                 * Output the character. In this case
     321                 * it should be no longer buffered.
     322                 */
    298323                stdout->op->write(stdout, ch, silent);
    299         else {
     324        } else {
    300325                /*
    301326                 * No standard output routine defined yet.
     
    307332                 * Note that the early_putc() function might be
    308333                 * a no-op on certain hardware configurations.
    309                  *
    310334                 */
    311335                early_putchar(ch);
    312                
    313                 if (klog_stored < klog_len)
    314                         klog_stored++;
    315         }
    316        
    317         /* The character is stored for uspace */
    318         if (klog_uspace < klog_len)
    319                 klog_uspace++;
    320        
    321         /* Check notify uspace to update */
    322         bool update;
    323         if ((klog_uspace > KLOG_LATENCY) || (ch == '\n'))
    324                 update = true;
    325         else
    326                 update = false;
    327        
    328         spinlock_unlock(&klog_lock);
    329        
    330         if (update)
     336        }
     337       
     338        /* Force notification on newline */
     339        if (ch == '\n')
    331340                klog_update();
    332341}
Note: See TracChangeset for help on using the changeset viewer.