Changes in / [5b26747:bed78cb] in mainline


Ignore:
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • HelenOS.config

    r5b26747 rbed78cb  
    578578# USB settings
    579579
    580 % USB release build (less logging)
    581 ! CONFIG_USB_RELEASE_BUILD (y/n)
     580% USB verbose messages
     581! CONFIG_USB_VERBOSE (n/y)
    582582
    583583% Start virtual USB host controller
  • kernel/arch/amd64/include/mm/page.h

    r5b26747 rbed78cb  
    3333 */
    3434
    35 /** Paging on AMD64
    36  *
    37  * The space is divided in positive numbers (uspace) and
    38  * negative numbers (kernel). The 'negative' space starting
    39  * with 0xffff800000000000 and ending with 0xffffffffffffffff
    40  * is identically mapped physical memory.
    41  *
    42  */
    43 
    4435#ifndef KERN_amd64_PAGE_H_
    4536#define KERN_amd64_PAGE_H_
  • kernel/genarch/src/mm/page_pt.c

    r5b26747 rbed78cb  
    4848#include <align.h>
    4949#include <macros.h>
     50#include <bitops.h>
    5051
    5152static void pt_mapping_insert(as_t *, uintptr_t, uintptr_t, unsigned int);
     
    292293}
    293294
     295/** Return the size of the region mapped by a single PTL0 entry.
     296 *
     297 * @return Size of the region mapped by a single PTL0 entry.
     298 */
     299static uintptr_t ptl0_step_get(void)
     300{
     301        size_t va_bits;
     302
     303        va_bits = fnzb(PTL0_ENTRIES) + fnzb(PTL1_ENTRIES) + fnzb(PTL2_ENTRIES) +
     304            fnzb(PTL3_ENTRIES) + PAGE_WIDTH;
     305
     306        return 1UL << (va_bits - fnzb(PTL0_ENTRIES));
     307}
     308
    294309/** Make the mappings in the given range global accross all address spaces.
    295310 *
     
    309324{
    310325        uintptr_t ptl0 = PA2KA((uintptr_t) AS_KERNEL->genarch.page_table);
    311         uintptr_t ptl0step = (((uintptr_t) -1) / PTL0_ENTRIES) + 1;
     326        uintptr_t ptl0_step = ptl0_step_get();
    312327        size_t order;
    313328        uintptr_t addr;
     
    321336#endif
    322337
    323         ASSERT(ispwr2(ptl0step));
    324338        ASSERT(size > 0);
    325339
    326         for (addr = ALIGN_DOWN(base, ptl0step); addr - 1 < base + size - 1;
    327             addr += ptl0step) {
     340        for (addr = ALIGN_DOWN(base, ptl0_step); addr - 1 < base + size - 1;
     341            addr += ptl0_step) {
    328342                uintptr_t l1;
    329343
  • kernel/generic/include/lib/ra.h

    r5b26747 rbed78cb  
    4242
    4343typedef struct {
    44         SPINLOCK_DECLARE(lock);
     44        IRQ_SPINLOCK_DECLARE(lock);
    4545        list_t spans;           /**< List of arena's spans. */
    4646} ra_arena_t;
  • kernel/generic/include/mm/slab.h

    r5b26747 rbed78cb  
    8181        slab_magazine_t *current;
    8282        slab_magazine_t *last;
    83         SPINLOCK_DECLARE(lock);
     83        IRQ_SPINLOCK_DECLARE(lock);
    8484} slab_mag_cache_t;
    8585
     
    113113        list_t full_slabs;     /**< List of full slabs */
    114114        list_t partial_slabs;  /**< List of partial slabs */
    115         SPINLOCK_DECLARE(slablock);
     115        IRQ_SPINLOCK_DECLARE(slablock);
    116116        /* Magazines */
    117117        list_t magazines;  /**< List o full magazines */
    118         SPINLOCK_DECLARE(maglock);
     118        IRQ_SPINLOCK_DECLARE(maglock);
    119119       
    120120        /** CPU cache */
  • kernel/generic/src/lib/ra.c

    r5b26747 rbed78cb  
    185185                return NULL;
    186186
    187         spinlock_initialize(&arena->lock, "arena_lock");
     187        irq_spinlock_initialize(&arena->lock, "arena_lock");
    188188        list_initialize(&arena->spans);
    189189
     
    209209
    210210        /* TODO: check for overlaps */
    211         spinlock_lock(&arena->lock);
     211        irq_spinlock_lock(&arena->lock, true);
    212212        list_append(&span->span_link, &arena->spans);
    213         spinlock_unlock(&arena->lock);
     213        irq_spinlock_unlock(&arena->lock, true);
    214214        return true;
    215215}
     
    390390        ASSERT(ispwr2(alignment));
    391391
    392         spinlock_lock(&arena->lock);
     392        irq_spinlock_lock(&arena->lock, true);
    393393        list_foreach(arena->spans, cur) {
    394394                ra_span_t *span = list_get_instance(cur, ra_span_t, span_link);
     
    398398                        break;
    399399        }
    400         spinlock_unlock(&arena->lock);
     400        irq_spinlock_unlock(&arena->lock, true);
    401401
    402402        return base;
     
    406406void ra_free(ra_arena_t *arena, uintptr_t base, size_t size)
    407407{
    408         spinlock_lock(&arena->lock);
     408        irq_spinlock_lock(&arena->lock, true);
    409409        list_foreach(arena->spans, cur) {
    410410                ra_span_t *span = list_get_instance(cur, ra_span_t, span_link);
     
    412412                if (iswithin(span->base, span->size, base, size)) {
    413413                        ra_span_free(span, base, size);
    414                         spinlock_unlock(&arena->lock);
     414                        irq_spinlock_unlock(&arena->lock, true);
    415415                        return;
    416416                }
    417417        }
    418         spinlock_unlock(&arena->lock);
     418        irq_spinlock_unlock(&arena->lock, true);
    419419
    420420        panic("Freeing to wrong arena (base=%" PRIxn ", size=%" PRIdn ").",
  • kernel/generic/src/mm/frame.c

    r5b26747 rbed78cb  
    10861086#endif
    10871087               
     1088                /*
     1089                 * Since the mem_avail_mtx is an active mutex, we need to disable interrupts
     1090                 * to prevent deadlock with TLB shootdown.
     1091                 */
     1092                ipl_t ipl = interrupts_disable();
    10881093                mutex_lock(&mem_avail_mtx);
    10891094               
     
    10981103               
    10991104                mutex_unlock(&mem_avail_mtx);
     1105                interrupts_restore(ipl);
    11001106               
    11011107#ifdef CONFIG_DEBUG
     
    11611167         * Signal that some memory has been freed.
    11621168         */
     1169
     1170       
     1171        /*
     1172         * Since the mem_avail_mtx is an active mutex, we need to disable interrupts
     1173         * to prevent deadlock with TLB shootdown.
     1174         */
     1175        ipl_t ipl = interrupts_disable();
    11631176        mutex_lock(&mem_avail_mtx);
    11641177        if (mem_avail_req > 0)
     
    11701183        }
    11711184        mutex_unlock(&mem_avail_mtx);
     1185        interrupts_restore(ipl);
    11721186       
    11731187        if (!(flags & FRAME_NO_RESERVE))
  • kernel/generic/src/mm/slab.c

    r5b26747 rbed78cb  
    264264                freed = cache->destructor(obj);
    265265       
    266         spinlock_lock(&cache->slablock);
     266        irq_spinlock_lock(&cache->slablock, true);
    267267        ASSERT(slab->available < cache->objects);
    268268       
     
    275275                /* Free associated memory */
    276276                list_remove(&slab->link);
    277                 spinlock_unlock(&cache->slablock);
     277                irq_spinlock_unlock(&cache->slablock, true);
    278278               
    279279                return freed + slab_space_free(cache, slab);
     
    284284        }
    285285       
    286         spinlock_unlock(&cache->slablock);
     286        irq_spinlock_unlock(&cache->slablock, true);
    287287        return freed;
    288288}
     
    295295NO_TRACE static void *slab_obj_create(slab_cache_t *cache, unsigned int flags)
    296296{
    297         spinlock_lock(&cache->slablock);
     297        irq_spinlock_lock(&cache->slablock, true);
    298298       
    299299        slab_t *slab;
     
    308308                 *
    309309                 */
    310                 spinlock_unlock(&cache->slablock);
     310                irq_spinlock_unlock(&cache->slablock, true);
    311311                slab = slab_space_alloc(cache, flags);
    312312                if (!slab)
    313313                        return NULL;
    314314               
    315                 spinlock_lock(&cache->slablock);
     315                irq_spinlock_lock(&cache->slablock, true);
    316316        } else {
    317317                slab = list_get_instance(list_first(&cache->partial_slabs),
     
    329329                list_prepend(&slab->link, &cache->partial_slabs);
    330330       
    331         spinlock_unlock(&cache->slablock);
     331        irq_spinlock_unlock(&cache->slablock, true);
    332332       
    333333        if ((cache->constructor) && (cache->constructor(obj, flags))) {
     
    355355        link_t *cur;
    356356       
    357         spinlock_lock(&cache->maglock);
     357        irq_spinlock_lock(&cache->maglock, true);
    358358        if (!list_empty(&cache->magazines)) {
    359359                if (first)
     
    366366                atomic_dec(&cache->magazine_counter);
    367367        }
    368        
    369         spinlock_unlock(&cache->maglock);
     368        irq_spinlock_unlock(&cache->maglock, true);
     369
    370370        return mag;
    371371}
     
    377377    slab_magazine_t *mag)
    378378{
    379         spinlock_lock(&cache->maglock);
     379        irq_spinlock_lock(&cache->maglock, true);
    380380       
    381381        list_prepend(&mag->link, &cache->magazines);
    382382        atomic_inc(&cache->magazine_counter);
    383383       
    384         spinlock_unlock(&cache->maglock);
     384        irq_spinlock_unlock(&cache->maglock, true);
    385385}
    386386
     
    414414        slab_magazine_t *lastmag = cache->mag_cache[CPU->id].last;
    415415       
    416         ASSERT(spinlock_locked(&cache->mag_cache[CPU->id].lock));
     416        ASSERT(irq_spinlock_locked(&cache->mag_cache[CPU->id].lock));
    417417       
    418418        if (cmag) { /* First try local CPU magazines */
     
    451451                return NULL;
    452452       
    453         spinlock_lock(&cache->mag_cache[CPU->id].lock);
     453        irq_spinlock_lock(&cache->mag_cache[CPU->id].lock, true);
    454454       
    455455        slab_magazine_t *mag = get_full_current_mag(cache);
    456456        if (!mag) {
    457                 spinlock_unlock(&cache->mag_cache[CPU->id].lock);
     457                irq_spinlock_unlock(&cache->mag_cache[CPU->id].lock, true);
    458458                return NULL;
    459459        }
    460460       
    461461        void *obj = mag->objs[--mag->busy];
    462         spinlock_unlock(&cache->mag_cache[CPU->id].lock);
     462        irq_spinlock_unlock(&cache->mag_cache[CPU->id].lock, true);
    463463       
    464464        atomic_dec(&cache->cached_objs);
     
    481481        slab_magazine_t *lastmag = cache->mag_cache[CPU->id].last;
    482482       
    483         ASSERT(spinlock_locked(&cache->mag_cache[CPU->id].lock));
     483        ASSERT(irq_spinlock_locked(&cache->mag_cache[CPU->id].lock));
    484484       
    485485        if (cmag) {
     
    531531                return -1;
    532532       
    533         spinlock_lock(&cache->mag_cache[CPU->id].lock);
     533        irq_spinlock_lock(&cache->mag_cache[CPU->id].lock, true);
    534534       
    535535        slab_magazine_t *mag = make_empty_current_mag(cache);
    536536        if (!mag) {
    537                 spinlock_unlock(&cache->mag_cache[CPU->id].lock);
     537                irq_spinlock_unlock(&cache->mag_cache[CPU->id].lock, true);
    538538                return -1;
    539539        }
     
    541541        mag->objs[mag->busy++] = obj;
    542542       
    543         spinlock_unlock(&cache->mag_cache[CPU->id].lock);
     543        irq_spinlock_unlock(&cache->mag_cache[CPU->id].lock, true);
    544544       
    545545        atomic_inc(&cache->cached_objs);
     
    593593        for (i = 0; i < config.cpu_count; i++) {
    594594                memsetb(&cache->mag_cache[i], sizeof(cache->mag_cache[i]), 0);
    595                 spinlock_initialize(&cache->mag_cache[i].lock,
     595                irq_spinlock_initialize(&cache->mag_cache[i].lock,
    596596                    "slab.cache.mag_cache[].lock");
    597597        }
     
    624624        list_initialize(&cache->magazines);
    625625       
    626         spinlock_initialize(&cache->slablock, "slab.cache.slablock");
    627         spinlock_initialize(&cache->maglock, "slab.cache.maglock");
     626        irq_spinlock_initialize(&cache->slablock, "slab.cache.slablock");
     627        irq_spinlock_initialize(&cache->maglock, "slab.cache.maglock");
    628628       
    629629        if (!(cache->flags & SLAB_CACHE_NOMAGAZINE))
     
    704704                size_t i;
    705705                for (i = 0; i < config.cpu_count; i++) {
    706                         spinlock_lock(&cache->mag_cache[i].lock);
     706                        irq_spinlock_lock(&cache->mag_cache[i].lock, true);
    707707                       
    708708                        mag = cache->mag_cache[i].current;
     
    716716                        cache->mag_cache[i].last = NULL;
    717717                       
    718                         spinlock_unlock(&cache->mag_cache[i].lock);
     718                        irq_spinlock_unlock(&cache->mag_cache[i].lock, true);
    719719                }
    720720        }
  • kernel/generic/src/synch/mutex.c

    r5b26747 rbed78cb  
    4040#include <debug.h>
    4141#include <arch.h>
     42#include <stacktrace.h>
    4243
    4344/** Initialize mutex.
     
    6162        return semaphore_count_get(&mtx->sem) <= 0;
    6263}
     64
     65#define MUTEX_DEADLOCK_THRESHOLD        100000000
    6366
    6467/** Acquire mutex.
     
    8790                ASSERT(!(flags & SYNCH_FLAGS_INTERRUPTIBLE));
    8891               
     92                unsigned int cnt = 0;
     93                bool deadlock_reported = false;
    8994                do {
     95                        if (cnt++ > MUTEX_DEADLOCK_THRESHOLD) {
     96                                printf("cpu%u: looping on active mutex %p\n",
     97                                    CPU->id, mtx);
     98                                stack_trace();
     99                                cnt = 0;
     100                                deadlock_reported = true;
     101                        }
    90102                        rc = semaphore_trydown(&mtx->sem);
    91103                } while (SYNCH_FAILED(rc) &&
    92104                    !(flags & SYNCH_FLAGS_NON_BLOCKING));
     105                if (deadlock_reported)
     106                        printf("cpu%u: not deadlocked\n", CPU->id);
    93107        }
    94108
  • kernel/generic/src/synch/spinlock.c

    r5b26747 rbed78cb  
    4444#include <debug.h>
    4545#include <symtab.h>
     46#include <stacktrace.h>
    4647
    4748#ifdef CONFIG_SMP
     
    104105                            "caller=%p (%s)\n", CPU->id, lock, lock->name,
    105106                            (void *) CALLER, symtab_fmt_name_lookup(CALLER));
     107                        stack_trace();
    106108                       
    107109                        i = 0;
     
    260262        int rc = spinlock_trylock(&(lock->lock));
    261263       
    262         ASSERT_IRQ_SPINLOCK(!lock->guard, lock);
     264        ASSERT_IRQ_SPINLOCK(!rc || !lock->guard, lock);
    263265        return rc;
    264266}
  • uspace/lib/usb/include/usb/debug.h

    r5b26747 rbed78cb  
    8181
    8282/** Default log level. */
    83 #ifdef CONFIG_USB_RELEASE_BUILD
     83#ifdef CONFIG_USB_VERBOSE
     84#  define USB_LOG_LEVEL_DEFAULT USB_LOG_LEVEL_DEBUG
     85#else
    8486#  define USB_LOG_LEVEL_DEFAULT USB_LOG_LEVEL_INFO
    85 #else
    86 #  define USB_LOG_LEVEL_DEFAULT USB_LOG_LEVEL_DEBUG
    8787#endif
    8888
  • uspace/srv/net/tcp/ncsim.c

    r5b26747 rbed78cb  
    4444#include <io/log.h>
    4545#include <stdlib.h>
    46 #include <thread.h>
     46#include <fibril.h>
    4747#include "conn.h"
    4848#include "ncsim.h"
     
    119119}
    120120
    121 /** Network condition simulator handler thread. */
    122 static void tcp_ncsim_thread(void *arg)
     121/** Network condition simulator handler fibril. */
     122static int tcp_ncsim_fibril(void *arg)
    123123{
    124124        link_t *link;
     
    126126        int rc;
    127127
    128         log_msg(LVL_DEBUG, "tcp_ncsim_thread()");
     128        log_msg(LVL_DEBUG, "tcp_ncsim_fibril()");
    129129
    130130
     
    151151                free(sqe);
    152152        }
     153
     154        /* Not reached */
     155        return 0;
    153156}
    154157
    155 /** Start simulator handler thread. */
    156 void tcp_ncsim_thread_start(void)
     158/** Start simulator handler fibril. */
     159void tcp_ncsim_fibril_start(void)
    157160{
    158         thread_id_t tid;
    159         int rc;
     161        fid_t fid;
    160162
    161         log_msg(LVL_DEBUG, "tcp_ncsim_thread_start()");
     163        log_msg(LVL_DEBUG, "tcp_ncsim_fibril_start()");
    162164
    163         rc = thread_create(tcp_ncsim_thread, NULL, "ncsim", &tid);
    164         if (rc != EOK) {
    165                 log_msg(LVL_ERROR, "Failed creating ncsim thread.");
     165        fid = fibril_create(tcp_ncsim_fibril, NULL);
     166        if (fid == 0) {
     167                log_msg(LVL_ERROR, "Failed creating ncsim fibril.");
    166168                return;
    167169        }
     170
     171        fibril_add_ready(fid);
    168172}
    169173
  • uspace/srv/net/tcp/ncsim.h

    r5b26747 rbed78cb  
    4040extern void tcp_ncsim_init(void);
    4141extern void tcp_ncsim_bounce_seg(tcp_sockpair_t *, tcp_segment_t *);
    42 extern void tcp_ncsim_thread_start(void);
    43 
     42extern void tcp_ncsim_fibril_start(void);
    4443
    4544#endif
  • uspace/srv/net/tcp/rqueue.c

    r5b26747 rbed78cb  
    3939#include <io/log.h>
    4040#include <stdlib.h>
    41 #include <thread.h>
     41#include <fibril.h>
    4242#include "conn.h"
    4343#include "pdu.h"
     
    128128}
    129129
    130 /** Receive queue handler thread. */
    131 static void tcp_rqueue_thread(void *arg)
     130/** Receive queue handler fibril. */
     131static int tcp_rqueue_fibril(void *arg)
    132132{
    133133        link_t *link;
    134134        tcp_rqueue_entry_t *rqe;
    135135
    136         log_msg(LVL_DEBUG, "tcp_rqueue_thread()");
     136        log_msg(LVL_DEBUG, "tcp_rqueue_fibril()");
    137137
    138138        while (true) {
     
    142142                tcp_as_segment_arrived(&rqe->sp, rqe->seg);
    143143        }
     144
     145        /* Not reached */
     146        return 0;
    144147}
    145148
    146 /** Start receive queue handler thread. */
    147 void tcp_rqueue_thread_start(void)
     149/** Start receive queue handler fibril. */
     150void tcp_rqueue_fibril_start(void)
    148151{
    149         thread_id_t tid;
    150         int rc;
     152        fid_t fid;
    151153
    152         log_msg(LVL_DEBUG, "tcp_rqueue_thread_start()");
     154        log_msg(LVL_DEBUG, "tcp_rqueue_fibril_start()");
    153155
    154         rc = thread_create(tcp_rqueue_thread, NULL, "rqueue", &tid);
    155         if (rc != EOK) {
    156                 log_msg(LVL_ERROR, "Failed creating rqueue thread.");
     156        fid = fibril_create(tcp_rqueue_fibril, NULL);
     157        if (fid == 0) {
     158                log_msg(LVL_ERROR, "Failed creating rqueue fibril.");
    157159                return;
    158160        }
     161
     162        fibril_add_ready(fid);
    159163}
    160164
  • uspace/srv/net/tcp/rqueue.h

    r5b26747 rbed78cb  
    4242extern void tcp_rqueue_insert_seg(tcp_sockpair_t *, tcp_segment_t *);
    4343extern void tcp_rqueue_handler(void *);
    44 extern void tcp_rqueue_thread_start(void);
     44extern void tcp_rqueue_fibril_start(void);
    4545
    4646
  • uspace/srv/net/tcp/tcp.c

    r5b26747 rbed78cb  
    180180
    181181        tcp_rqueue_init();
    182         tcp_rqueue_thread_start();
     182        tcp_rqueue_fibril_start();
    183183
    184184        tcp_ncsim_init();
    185         tcp_ncsim_thread_start();
     185        tcp_ncsim_fibril_start();
    186186
    187187        if (0) tcp_test();
  • uspace/srv/net/tcp/test.c

    r5b26747 rbed78cb  
    3838#include <errno.h>
    3939#include <stdio.h>
    40 #include <thread.h>
     40#include <fibril.h>
    4141#include <str.h>
    4242#include "tcp_type.h"
     
    4747#define RCV_BUF_SIZE 64
    4848
    49 static void test_srv(void *arg)
     49static int test_srv(void *arg)
    5050{
    5151        tcp_conn_t *conn;
     
    8484
    8585        printf("test_srv() terminating\n");
     86        return 0;
    8687}
    8788
    88 static void test_cli(void *arg)
     89static int test_cli(void *arg)
    8990{
    9091        tcp_conn_t *conn;
     
    112113        printf("C: User close...\n");
    113114        tcp_uc_close(conn);
     115
     116        return 0;
    114117}
    115118
    116119void tcp_test(void)
    117120{
    118         thread_id_t srv_tid;
    119         thread_id_t cli_tid;
    120         int rc;
     121        fid_t srv_fid;
     122        fid_t cli_fid;
    121123
    122124        printf("tcp_test()\n");
     
    125127
    126128        if (0) {
    127                 rc = thread_create(test_srv, NULL, "test_srv", &srv_tid);
    128                 if (rc != EOK) {
    129                         printf("Failed to create server thread.\n");
     129                srv_fid = fibril_create(test_srv, NULL);
     130                if (srv_fid == 0) {
     131                        printf("Failed to create server fibril.\n");
    130132                        return;
    131133                }
     134
     135                fibril_add_ready(srv_fid);
    132136        }
    133137
    134138        if (0) {
    135                 rc = thread_create(test_cli, NULL, "test_cli", &cli_tid);
    136                 if (rc != EOK) {
    137                         printf("Failed to create client thread.\n");
     139                cli_fid = fibril_create(test_cli, NULL);
     140                if (cli_fid == 0) {
     141                        printf("Failed to create client fibril.\n");
    138142                        return;
    139143                }
     144
     145                fibril_add_ready(cli_fid);
    140146        }
    141147}
Note: See TracChangeset for help on using the changeset viewer.