Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 6f7071b in mainline


Ignore:
Timestamp:
2018-11-05T09:13:04Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master
Children:
4a8d0dd1
Parents:
9c26ef0
git-author:
Jiri Svoboda <jiri@…> (2018-10-04 18:11:52)
git-committer:
Jiri Svoboda <jiri@…> (2018-11-05 09:13:04)
Message:

Use ordered dictionary for kernel pareas instead of B+ tree.

Location:
kernel
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/sparc64/src/drivers/niagara.c

    r9c26ef0 r6f7071b  
    221221            INPUT_BUFFER_SIZE);
    222222
     223        ddi_parea_init(&outbuf_parea);
    223224        outbuf_parea.pbase = (uintptr_t) (KA2PA(&output_buffer));
    224225        outbuf_parea.frames = 1;
  • kernel/genarch/src/drivers/dsrln/dsrlnout.c

    r9c26ef0 r6f7071b  
    8484
    8585        instance->base = base;
    86         link_initialize(&instance->parea.link);
     86        ddi_parea_init(&instance->parea);
    8787        instance->parea.pbase = KA2PA(base);
    8888        instance->parea.frames = 1;
  • kernel/genarch/src/drivers/ega/ega.c

    r9c26ef0 r6f7071b  
    616616        }
    617617
    618         link_initialize(&instance->parea.link);
     618        ddi_parea_init(&instance->parea);
    619619        instance->parea.pbase = addr;
    620620        instance->parea.frames = SIZE2FRAMES(EGA_VRAM_SIZE);
  • kernel/genarch/src/drivers/ns16550/ns16550.c

    r9c26ef0 r6f7071b  
    175175                instance->irq.cir_arg = cir_arg;
    176176
     177                ddi_parea_init(&instance->parea);
    177178                instance->parea.pbase = (uintptr_t) dev;
    178179                instance->parea.frames = 1;
  • kernel/genarch/src/drivers/s3c24xx/uart.c

    r9c26ef0 r6f7071b  
    135135            pio_read_32(&uart->io->ucon) & ~UCON_RX_INT_LEVEL);
    136136
    137         link_initialize(&uart->parea.link);
     137        ddi_parea_init(&uart->parea);
    138138        uart->parea.pbase = paddr;
    139139        uart->parea.frames = 1;
  • kernel/genarch/src/fb/fb.c

    r9c26ef0 r6f7071b  
    647647        glyphs_render(instance);
    648648
    649         link_initialize(&instance->parea.link);
     649        ddi_parea_init(&instance->parea);
    650650        instance->parea.pbase = props->addr;
    651651        instance->parea.frames = SIZE2FRAMES(fbsize);
  • kernel/generic/include/ddi/ddi.h

    r9c26ef0 r6f7071b  
    3939#include <abi/ddi/arg.h>
    4040#include <proc/task.h>
    41 #include <adt/list.h>
     41#include <adt/odict.h>
    4242
    4343/** Structure representing contiguous physical memory area. */
    4444typedef struct {
    45         /** Linked list link */
    46         link_t link;
     45        /** Link to @c pareas ordered dictionary */
     46        odlink_t lpareas;
    4747
    4848        /** Physical base of the area. */
     
    5757
    5858extern void ddi_init(void);
     59extern void ddi_parea_init(parea_t *);
    5960extern void ddi_parea_register(parea_t *);
    6061
  • kernel/generic/include/proc/task.h

    r9c26ef0 r6f7071b  
    4444#include <synch/futex.h>
    4545#include <synch/workqueue.h>
    46 #include <adt/btree.h>
    4746#include <adt/cht.h>
    4847#include <adt/list.h>
  • kernel/generic/src/console/console.c

    r9c26ef0 r6f7071b  
    193193        assert((uintptr_t) faddr % FRAME_SIZE == 0);
    194194
     195        ddi_parea_init(&kio_parea);
    195196        kio_parea.pbase = (uintptr_t) faddr;
    196197        kio_parea.frames = SIZE2FRAMES(sizeof(kio));
  • kernel/generic/src/ddi/ddi.c

    r9c26ef0 r6f7071b  
    4949#include <synch/mutex.h>
    5050#include <syscall/copy.h>
    51 #include <adt/btree.h>
     51#include <adt/odict.h>
    5252#include <arch.h>
    5353#include <align.h>
    5454#include <errno.h>
     55#include <mem.h>
    5556#include <trace.h>
    5657#include <bitops.h>
    5758
    58 /** This lock protects the parea_btree. */
    59 static mutex_t parea_lock;
    60 
    61 /** B+tree with enabled physical memory areas. */
    62 static btree_t parea_btree;
     59/** This lock protects the @c pareas ordered dictionary. */
     60static mutex_t pareas_lock;
     61
     62/** Ordered dictionary of enabled physical memory areas by base address. */
     63static odict_t pareas;
     64
     65static void *pareas_getkey(odlink_t *);
     66static int pareas_cmp(void *, void *);
    6367
    6468/** Initialize DDI.
     
    6771void ddi_init(void)
    6872{
    69         btree_create(&parea_btree);
    70         mutex_initialize(&parea_lock, MUTEX_PASSIVE);
     73        odict_initialize(&pareas, pareas_getkey, pareas_cmp);
     74        mutex_initialize(&pareas_lock, MUTEX_PASSIVE);
     75}
     76
     77/** Initialize physical area structure.
     78 *
     79 * This should always be called first on the parea structure before
     80 * filling in fields and calling ddi_parea_register.
     81 *
     82 * @param parea Pointer to physical area structure.
     83 *
     84 */
     85void ddi_parea_init(parea_t *parea)
     86{
     87        memset(parea, 0, sizeof(parea_t));
    7188}
    7289
     
    7895void ddi_parea_register(parea_t *parea)
    7996{
    80         mutex_lock(&parea_lock);
     97        mutex_lock(&pareas_lock);
    8198
    8299        /*
    83100         * We don't check for overlaps here as the kernel is pretty sane.
    84101         */
    85         btree_insert(&parea_btree, (btree_key_t) parea->pbase, parea, NULL);
    86 
    87         mutex_unlock(&parea_lock);
     102        odict_insert(&parea->lpareas, &pareas, NULL);
     103
     104        mutex_unlock(&pareas_lock);
    88105}
    89106
     
    129146         */
    130147
    131         mutex_lock(&parea_lock);
    132         btree_node_t *nodep;
    133         parea_t *parea = (parea_t *) btree_search(&parea_btree,
    134             (btree_key_t) phys, &nodep);
     148        mutex_lock(&pareas_lock);
     149        odlink_t *odlink = odict_find_eq(&pareas, &phys, NULL);
     150        parea_t *parea = odlink != NULL ?
     151            odict_get_instance(odlink, parea_t, lpareas) : NULL;
    135152
    136153        if ((parea != NULL) && (parea->frames >= pages)) {
    137154                if ((!priv) && (!parea->unpriv)) {
    138                         mutex_unlock(&parea_lock);
     155                        mutex_unlock(&pareas_lock);
    139156                        return EPERM;
    140157                }
     
    144161
    145162        parea = NULL;
    146         mutex_unlock(&parea_lock);
     163        mutex_unlock(&pareas_lock);
    147164
    148165        /*
     
    193210
    194211                if (parea != NULL)
    195                         mutex_unlock(&parea_lock);
     212                        mutex_unlock(&pareas_lock);
    196213
    197214                return ENOMEM;
     
    204221        if (parea != NULL) {
    205222                parea->mapped = true;
    206                 mutex_unlock(&parea_lock);
     223                mutex_unlock(&pareas_lock);
    207224        }
    208225
     
    255272}
    256273
     274/** Get key function for the @c pareas ordered dictionary.
     275 *
     276 * @param odlink Link
     277 * @return Pointer to base address cast as 'void *'
     278 */
     279static void *pareas_getkey(odlink_t *odlink)
     280{
     281        parea_t *parea = odict_get_instance(odlink, parea_t, lpareas);
     282        return (void *) &parea->pbase;
     283}
     284
     285/** Key comparison function for the @c pareas ordered dictionary.
     286 *
     287 * @param a Pointer to parea A base
     288 * @param b Pointer to parea B base
     289 * @return -1, 0, 1 iff base of A is less than, equal to, greater than B
     290 */
     291static int pareas_cmp(void *a, void *b)
     292{
     293        uintptr_t pa = *(uintptr_t *)a;
     294        uintptr_t pb = *(uintptr_t *)b;
     295
     296        if (pa < pb)
     297                return -1;
     298        else if (pa == pb)
     299                return 0;
     300        else
     301                return +1;
     302}
     303
    257304/** Enable range of I/O space for task.
    258305 *
     
    288335        }
    289336
    290         /* Lock the task and release the lock protecting tasks_btree. */
     337        /* Lock the task and release the lock protecting tasks dictionary. */
    291338        irq_spinlock_exchange(&tasks_lock, &task->lock);
    292339        errno_t rc = ddi_iospace_enable_arch(task, ioaddr, size);
     
    329376        }
    330377
    331         /* Lock the task and release the lock protecting tasks_btree. */
     378        /* Lock the task and release the lock protecting tasks dictionary. */
    332379        irq_spinlock_exchange(&tasks_lock, &task->lock);
    333380        errno_t rc = ddi_iospace_disable_arch(task, ioaddr, size);
  • kernel/generic/src/lib/rd.c

    r9c26ef0 r6f7071b  
    5959        assert((base % FRAME_SIZE) == 0);
    6060
     61        ddi_parea_init(&rd_parea);
    6162        rd_parea.pbase = base;
    6263        rd_parea.frames = SIZE2FRAMES(size);
  • kernel/generic/src/proc/task.c

    r9c26ef0 r6f7071b  
    4848#include <arch.h>
    4949#include <barrier.h>
    50 #include <adt/btree.h>
    5150#include <adt/list.h>
    5251#include <adt/odict.h>
  • kernel/generic/src/time/clock.c

    r9c26ef0 r6f7071b  
    9191        uptime->useconds = 0;
    9292
     93        ddi_parea_init(&clock_parea);
    9394        clock_parea.pbase = faddr;
    9495        clock_parea.frames = 1;
Note: See TracChangeset for help on using the changeset viewer.