Changeset 39e1b9a in mainline for kernel/generic/src/console/console.c


Ignore:
Timestamp:
2025-04-17T15:37:05Z (5 days ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
250a435
Parents:
690ad20
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2025-04-14 16:54:54)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2025-04-17 15:37:05)
Message:

Convert console output devices to batch printing

File:
1 edited

Legend:

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

    r690ad20 r39e1b9a  
    8080IRQ_SPINLOCK_INITIALIZE(kio_lock);
    8181
     82static IRQ_SPINLOCK_INITIALIZE(flush_lock);
     83
    8284static IRQ_SPINLOCK_INITIALIZE(early_mbstate_lock);
    8385static mbstate_t early_mbstate;
     
    9395};
    9496
    95 static void stdout_write(outdev_t *, char32_t);
     97static void stdout_write(outdev_t *, const char *, size_t);
    9698static void stdout_redraw(outdev_t *);
    9799static void stdout_scroll_up(outdev_t *);
     
    146148}
    147149
    148 static void stdout_write(outdev_t *dev, char32_t ch)
     150static void stdout_write(outdev_t *dev, const char *s, size_t n)
    149151{
    150152        list_foreach(dev->list, link, outdev_t, sink) {
    151153                if ((sink) && (sink->op->write))
    152                         sink->op->write(sink, ch);
     154                        sink->op->write(sink, s, n);
    153155        }
    154156}
     
    249251        irq_spinlock_lock(&kio_lock, true);
    250252
    251         static mbstate_t mbstate;
     253        if (!irq_spinlock_trylock(&flush_lock)) {
     254                /* Someone is currently flushing. */
     255                irq_spinlock_unlock(&kio_lock, true);
     256                return;
     257        }
     258
     259        /* A small-ish local buffer so that we can write to output in chunks. */
     260        char buffer[256];
    252261
    253262        /* Print characters that weren't printed earlier */
     
    255264                size_t offset = kio_processed % KIO_LENGTH;
    256265                size_t len = min(kio_written - kio_processed, KIO_LENGTH - offset);
    257                 size_t bytes = 0;
    258 
    259                 char32_t ch = str_decode_r(&kio[offset], &bytes, len, U'�', &mbstate);
    260                 assert(bytes <= 4);
    261                 kio_processed += bytes;
     266                len = min(len, sizeof(buffer));
     267
     268                /* Take out a chunk of the big buffer. */
     269                memcpy(buffer, &kio[offset], len);
     270                kio_processed += len;
    262271
    263272                /*
    264                  * We need to give up the spinlock for
    265                  * the physical operation of writing out
    266                  * the character.
     273                 * We need to give up the spinlock for the physical operation of writing
     274                 * out the buffer.
    267275                 */
    268276                irq_spinlock_unlock(&kio_lock, true);
    269                 stdout->op->write(stdout, ch);
     277                stdout->op->write(stdout, buffer, len);
    270278                irq_spinlock_lock(&kio_lock, true);
    271279        }
    272280
     281        irq_spinlock_unlock(&flush_lock, false);
    273282        irq_spinlock_unlock(&kio_lock, true);
    274283}
Note: See TracChangeset for help on using the changeset viewer.