Changeset 25a76ab8 in mainline for kernel/generic/src


Ignore:
Timestamp:
2010-05-08T07:53:23Z (16 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
051bc69a
Parents:
6c39a907 (diff), 1317380 (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.

Location:
kernel/generic/src
Files:
18 edited

Legend:

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

    r6c39a907 r25a76ab8  
    837837        bool pointer = false;
    838838        int rc;
    839 
    840         if (((char *)argv->buffer)[0] == '*') {
     839       
     840        if (((char *) argv->buffer)[0] == '*') {
    841841                rc = symtab_addr_lookup((char *) argv->buffer + 1, &addr);
    842842                pointer = true;
    843         } else if (((char *) argv->buffer)[0] >= '0' &&
    844                    ((char *)argv->buffer)[0] <= '9') {
    845                 rc = EOK;
    846                 addr = atoi((char *)argv->buffer);
    847         } else {
     843        } else if (((char *) argv->buffer)[0] >= '0' &&
     844                   ((char *) argv->buffer)[0] <= '9') {
     845                uint64_t value;
     846                rc = str_uint64((char *) argv->buffer, NULL, 0, true, &value);
     847                if (rc == EOK)
     848                        addr = (uintptr_t) value;
     849        } else
    848850                rc = symtab_addr_lookup((char *) argv->buffer, &addr);
    849         }
    850 
     851       
    851852        if (rc == ENOENT)
    852853                printf("Symbol %s not found.\n", argv->buffer);
     854        else if (rc == EINVAL)
     855                printf("Invalid address.\n");
    853856        else if (rc == EOVERFLOW) {
    854857                symtab_print_search((char *) argv->buffer);
    855                 printf("Duplicate symbol, be more specific.\n");
     858                printf("Duplicate symbol (be more specific) or address overflow.\n");
    856859        } else if (rc == EOK) {
    857860                if (pointer)
     
    859862                printf("Writing %#" PRIx64 " -> %p\n", arg1, addr);
    860863                *(uint32_t *) addr = arg1;
    861         } else {
     864        } else
    862865                printf("No symbol information available.\n");
    863         }
    864866       
    865867        return 1;
  • kernel/generic/src/console/kconsole.c

    r6c39a907 r25a76ab8  
    455455                        printf("No symbol information available.\n");
    456456                        return false;
    457                 }
    458                
    459                 if (isaddr)
    460                         *result = (unative_t) symaddr;
    461                 else if (isptr)
    462                         *result = **((unative_t **) symaddr);
    463                 else
    464                         *result = *((unative_t *) symaddr);
     457                case EOK:
     458                        if (isaddr)
     459                                *result = (unative_t) symaddr;
     460                        else if (isptr)
     461                                *result = **((unative_t **) symaddr);
     462                        else
     463                                *result = *((unative_t *) symaddr);
     464                        break;
     465                default:
     466                        printf("Unknown error.\n");
     467                        return false;
     468                }
    465469        } else {
    466470                /* It's a number - convert it */
    467                 *result = atoi(text);
    468                 if (isptr)
    469                         *result = *((unative_t *) *result);
     471                uint64_t value;
     472                int rc = str_uint64(text, NULL, 0, true, &value);
     473                switch (rc) {
     474                case EINVAL:
     475                        printf("Invalid number.\n");
     476                        return false;
     477                case EOVERFLOW:
     478                        printf("Integer overflow.\n");
     479                        return false;
     480                case EOK:
     481                        *result = (unative_t) value;
     482                        if (isptr)
     483                                *result = *((unative_t *) *result);
     484                        break;
     485                default:
     486                        printf("Unknown error.\n");
     487                        return false;
     488                }
    470489        }
    471490       
  • kernel/generic/src/ddi/ddi.c

    r6c39a907 r25a76ab8  
    4646#include <mm/frame.h>
    4747#include <mm/as.h>
    48 #include <synch/spinlock.h>
     48#include <synch/mutex.h>
    4949#include <syscall/copy.h>
    5050#include <adt/btree.h>
     
    5454
    5555/** This lock protects the parea_btree. */
    56 SPINLOCK_INITIALIZE(parea_lock);
     56static mutex_t parea_lock;
    5757
    5858/** B+tree with enabled physical memory areas. */
     
    6363{
    6464        btree_create(&parea_btree);
     65        mutex_initialize(&parea_lock, MUTEX_PASSIVE);
    6566}
    6667
     
    7273void ddi_parea_register(parea_t *parea)
    7374{
    74         ipl_t ipl = interrupts_disable();
    75         spinlock_lock(&parea_lock);
     75        mutex_lock(&parea_lock);
    7676       
    7777        /*
     
    8080        btree_insert(&parea_btree, (btree_key_t) parea->pbase, parea, NULL);
    8181       
    82         spinlock_unlock(&parea_lock);
    83         interrupts_restore(ipl);
     82        mutex_unlock(&parea_lock);
    8483}
    8584
     
    141140                spinlock_unlock(&zones.lock);
    142141               
    143                 spinlock_lock(&parea_lock);
     142                mutex_lock(&parea_lock);
    144143                btree_node_t *nodep;
    145144                parea_t *parea = (parea_t *) btree_search(&parea_btree,
     
    147146               
    148147                if ((!parea) || (parea->frames < pages)) {
    149                         spinlock_unlock(&parea_lock);
     148                        mutex_unlock(&parea_lock);
    150149                        goto err;
    151150                }
    152151               
    153                 spinlock_unlock(&parea_lock);
     152                mutex_unlock(&parea_lock);
    154153                goto map;
    155154        }
     
    161160       
    162161map:
    163         spinlock_lock(&TASK->lock);
    164        
     162        interrupts_restore(ipl);
     163
    165164        if (!as_area_create(TASK->as, flags, pages * PAGE_SIZE, vp,
    166165            AS_AREA_ATTR_NONE, &phys_backend, &backend_data)) {
     
    169168                 * We report it using ENOMEM.
    170169                 */
    171                 spinlock_unlock(&TASK->lock);
    172                 interrupts_restore(ipl);
    173170                return ENOMEM;
    174171        }
     
    177174         * Mapping is created on-demand during page fault.
    178175         */
    179        
    180         spinlock_unlock(&TASK->lock);
    181         interrupts_restore(ipl);
    182176        return 0;
    183177}
  • kernel/generic/src/ipc/ipc.c

    r6c39a907 r25a76ab8  
    218218        answerbox_t *callerbox = call->callerbox;
    219219        bool do_lock = ((!selflocked) || callerbox != (&TASK->answerbox));
     220        ipl_t ipl;
    220221
    221222        /* Count sent answer */
     223        ipl = interrupts_disable();
    222224        spinlock_lock(&TASK->lock);
    223225        TASK->ipc_info.answer_sent++;
    224226        spinlock_unlock(&TASK->lock);
     227        interrupts_restore(ipl);
    225228
    226229        call->flags |= IPC_CALL_ANSWERED;
     
    281284static void _ipc_call(phone_t *phone, answerbox_t *box, call_t *call)
    282285{
     286        ipl_t ipl;
     287
    283288        /* Count sent ipc call */
     289        ipl = interrupts_disable();
    284290        spinlock_lock(&TASK->lock);
    285291        TASK->ipc_info.call_sent++;
    286292        spinlock_unlock(&TASK->lock);
     293        interrupts_restore(ipl);
    287294
    288295        if (!(call->flags & IPC_CALL_FORWARDED)) {
     
    386393int ipc_forward(call_t *call, phone_t *newphone, answerbox_t *oldbox, int mode)
    387394{
     395        ipl_t ipl;
     396
    388397        /* Count forwarded calls */
     398        ipl = interrupts_disable();
    389399        spinlock_lock(&TASK->lock);
    390400        TASK->ipc_info.forwarded++;
    391401        spinlock_unlock(&TASK->lock);
     402        interrupts_restore(ipl);
    392403
    393404        spinlock_lock(&oldbox->lock);
     
    422433        call_t *request;
    423434        ipl_t ipl;
     435        uint64_t irq_cnt = 0;
     436        uint64_t answer_cnt = 0;
     437        uint64_t call_cnt = 0;
    424438        int rc;
    425439
     
    431445        spinlock_lock(&box->lock);
    432446        if (!list_empty(&box->irq_notifs)) {
    433 
    434447                /* Count recieved IRQ notification */
    435                 spinlock_lock(&TASK->lock);
    436                 TASK->ipc_info.irq_notif_recieved++;
    437                 spinlock_unlock(&TASK->lock);
     448                irq_cnt++;     
    438449
    439450                ipl = interrupts_disable();
     
    447458        } else if (!list_empty(&box->answers)) {
    448459                /* Count recieved answer */
    449                 spinlock_lock(&TASK->lock);
    450                 TASK->ipc_info.answer_recieved++;
    451                 spinlock_unlock(&TASK->lock);
     460                answer_cnt++;
    452461
    453462                /* Handle asynchronous answers */
     
    457466        } else if (!list_empty(&box->calls)) {
    458467                /* Count recieved call */
    459                 spinlock_lock(&TASK->lock);
    460                 TASK->ipc_info.call_recieved++;
    461                 spinlock_unlock(&TASK->lock);
     468                call_cnt++;
    462469
    463470                /* Handle requests */
     
    472479        }
    473480        spinlock_unlock(&box->lock);
     481       
     482        ipl = interrupts_disable();
     483        spinlock_lock(&TASK->lock);
     484        TASK->ipc_info.irq_notif_recieved += irq_cnt;
     485        TASK->ipc_info.answer_recieved += answer_cnt;
     486        TASK->ipc_info.call_recieved += call_cnt;
     487        spinlock_unlock(&TASK->lock);
     488        interrupts_restore(ipl);
     489
    474490        return request;
    475491}
     
    675691        call_t *call;
    676692        link_t *tmp;
     693        ipl_t ipl;
    677694       
     695        ipl = interrupts_disable();
    678696        spinlock_lock(&tasks_lock);
    679697        task = task_find_by_id(taskid);
     
    681699                spinlock_lock(&task->lock);
    682700        spinlock_unlock(&tasks_lock);
    683         if (!task)
     701        if (!task) {
     702                interrupts_restore(ipl);
    684703                return;
     704        }
    685705
    686706        /* Print opened phones & details */
     
    765785        spinlock_unlock(&task->answerbox.lock);
    766786        spinlock_unlock(&task->lock);
     787        interrupts_restore(ipl);
    767788}
    768789
  • kernel/generic/src/lib/func.c

    r6c39a907 r25a76ab8  
    2727 */
    2828
    29 /** @addtogroup generic 
     29/** @addtogroup generic
    3030 * @{
    3131 */
     
    3333/**
    3434 * @file
    35  * @brief       Miscellaneous functions.
     35 * @brief Miscellaneous functions.
    3636 */
    3737
     
    7979}
    8080
    81 /** Convert ascii representation to unative_t
    82  *
    83  * Supports 0x for hexa & 0 for octal notation.
    84  * Does not check for overflows, does not support negative numbers
    85  *
    86  * @param text Textual representation of number
    87  * @return Converted number or 0 if no valid number ofund
    88  */
    89 unative_t atoi(const char *text)
    90 {
    91         int base = 10;
    92         unative_t result = 0;
    93 
    94         if (text[0] == '0' && text[1] == 'x') {
    95                 base = 16;
    96                 text += 2;
    97         } else if (text[0] == '0')
    98                 base = 8;
    99 
    100         while (*text) {
    101                 if (base != 16 && \
    102                     ((*text >= 'A' && *text <= 'F' )
    103                      || (*text >='a' && *text <='f')))
    104                         break;
    105                 if (base == 8 && *text >='8')
    106                         break;
    107 
    108                 if (*text >= '0' && *text <= '9') {
    109                         result *= base;
    110                         result += *text - '0';
    111                 } else if (*text >= 'A' && *text <= 'F') {
    112                         result *= base;
    113                         result += *text - 'A' + 10;
    114                 } else if (*text >= 'a' && *text <= 'f') {
    115                         result *= base;
    116                         result += *text - 'a' + 10;
    117                 } else
    118                         break;
    119                 text++;
    120         }
    121 
    122         return result;
    123 }
    124 
    12581/** @}
    12682 */
  • kernel/generic/src/lib/str.c

    r6c39a907 r25a76ab8  
    823823                                str++;
    824824                                break;
     825                        default:
     826                                str--;
    825827                        }
    826828                }
     
    886888 * @param base   Zero or number between 2 and 36 inclusive.
    887889 * @param strict Do not allow any trailing characters.
    888  * @apram result Result of the conversion.
     890 * @param result Result of the conversion.
    889891 *
    890892 * @return EOK if conversion was successful.
  • kernel/generic/src/mm/as.c

    r6c39a907 r25a76ab8  
    11/*
    2  * Copyright (c) 2001-2006 Jakub Jermar
     2 * Copyright (c) 2010 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    152152         * reference count never drops to zero.
    153153         */
    154         atomic_set(&AS_KERNEL->refcount, 1);
     154        as_hold(AS_KERNEL);
    155155}
    156156
     
    200200        DEADLOCK_PROBE_INIT(p_asidlock);
    201201
     202        ASSERT(as != AS);
    202203        ASSERT(atomic_get(&as->refcount) == 0);
    203204       
    204205        /*
    205          * Since there is no reference to this area,
    206          * it is safe not to lock its mutex.
     206         * Since there is no reference to this address space, it is safe not to
     207         * lock its mutex.
    207208         */
    208209
     
    225226        preemption_enable();    /* Interrupts disabled, enable preemption */
    226227        if (as->asid != ASID_INVALID && as != AS_KERNEL) {
    227                 if (as != AS && as->cpu_refcount == 0)
     228                if (as->cpu_refcount == 0)
    228229                        list_remove(&as->inactive_as_with_asid_link);
    229230                asid_put(as->asid);
     
    258259
    259260        slab_free(as_slab, as);
     261}
     262
     263/** Hold a reference to an address space.
     264 *
     265 * Holding a reference to an address space prevents destruction of that address
     266 * space.
     267 *
     268 * @param a             Address space to be held.
     269 */
     270void as_hold(as_t *as)
     271{
     272        atomic_inc(&as->refcount);
     273}
     274
     275/** Release a reference to an address space.
     276 *
     277 * The last one to release a reference to an address space destroys the address
     278 * space.
     279 *
     280 * @param a             Address space to be released.
     281 */
     282void as_release(as_t *as)
     283{
     284        if (atomic_predec(&as->refcount) == 0)
     285                as_destroy(as);
    260286}
    261287
  • kernel/generic/src/mm/frame.c

    r6c39a907 r25a76ab8  
    10331033                spinlock_unlock(&zones.lock);
    10341034                interrupts_restore(ipl);
     1035
     1036                if (!THREAD)
     1037                        panic("Cannot wait for memory to become available.");
    10351038               
    10361039                /*
  • kernel/generic/src/mm/slab.c

    r6c39a907 r25a76ab8  
    555555 * Initialize mag_cache structure in slab cache
    556556 */
    557 static void make_magcache(slab_cache_t *cache)
     557static bool make_magcache(slab_cache_t *cache)
    558558{
    559559        unsigned int i;
     
    562562
    563563        cache->mag_cache = malloc(sizeof(slab_mag_cache_t) * config.cpu_count,
    564             0);
     564            FRAME_ATOMIC);
     565        if (!cache->mag_cache)
     566                return false;
     567
    565568        for (i = 0; i < config.cpu_count; i++) {
    566569                memsetb(&cache->mag_cache[i], sizeof(cache->mag_cache[i]), 0);
     
    568571                    "slab_maglock_cpu");
    569572        }
     573        return true;
    570574}
    571575
     
    597601        spinlock_initialize(&cache->maglock, "slab_maglock");
    598602        if (!(cache->flags & SLAB_CACHE_NOMAGAZINE))
    599                 make_magcache(cache);
     603                (void) make_magcache(cache);
    600604
    601605        /* Compute slab sizes, object counts in slabs etc. */
     
    923927                    SLAB_CACHE_MAGDEFERRED)
    924928                        continue;
    925                 make_magcache(s);
     929                (void) make_magcache(s);
    926930                s->flags &= ~SLAB_CACHE_MAGDEFERRED;
    927931        }
  • kernel/generic/src/printf/printf_core.c

    r6c39a907 r25a76ab8  
    261261        if (str == NULL)
    262262                return printf_putstr(nullstr, ps);
    263 
     263       
    264264        /* Print leading spaces. */
    265265        size_t strw = str_length(str);
    266266        if (precision == 0)
    267267                precision = strw;
    268 
     268       
    269269        /* Left padding */
    270270        size_t counter = 0;
     
    276276                }
    277277        }
    278 
     278       
    279279        /* Part of @a str fitting into the alloted space. */
    280280        int retval;
     
    391391         */
    392392        if (flags & __PRINTF_FLAG_PREFIX) {
    393                 switch(base) {
     393                switch (base) {
    394394                case 2:
    395395                        /* Binary formating is not standard, but usefull */
     
    455455        /* Print prefix */
    456456        if (flags & __PRINTF_FLAG_PREFIX) {
    457                 switch(base) {
     457                switch (base) {
    458458                case 2:
    459459                        /* Binary formating is not standard, but usefull */
     
    570570 *
    571571 *  - P, p Print value of a pointer. Void * value is expected and it is
    572  *         printed in hexadecimal notation with prefix (as with \%#X / \%#x
    573  *         for 32-bit or \%#X / \%#x for 64-bit long pointers).
     572 *         printed in hexadecimal notation with prefix (as with
     573 *         \%#0.8X / \%#0.8x for 32-bit or \%#0.16lX / \%#0.16lx for 64-bit
     574 *         long pointers).
    574575 *
    575576 *  - b Print value as unsigned binary number. Prefix is not printed by
     
    784785                        case 'p':
    785786                                flags |= __PRINTF_FLAG_PREFIX;
     787                                flags |= __PRINTF_FLAG_ZEROPADDED;
    786788                                base = 16;
    787789                                qualifier = PrintfQualifierPointer;
     
    846848                        case PrintfQualifierPointer:
    847849                                size = sizeof(void *);
    848                                 number = (uint64_t) (unsigned long) va_arg(ap, void *);
     850                                precision = size << 1;
     851                                number = (uint64_t) (uintptr_t) va_arg(ap, void *);
    849852                                break;
    850853                        default:
  • kernel/generic/src/proc/scheduler.c

    r6c39a907 r25a76ab8  
    11/*
    2  * Copyright (c) 2001-2007 Jakub Jermar
     2 * Copyright (c) 2010 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    187187
    188188loop:
    189         interrupts_enable();
    190189       
    191190        if (atomic_get(&CPU->nrdy) == 0) {
     
    196195                 */
    197196
    198                 /*
     197                 /* Mark CPU as it was idle this clock tick */
     198                 spinlock_lock(&CPU->lock);
     199                 CPU->idle = true;
     200                 spinlock_unlock(&CPU->lock);
     201
     202                 interrupts_enable();
     203                 /*
    199204                 * An interrupt might occur right now and wake up a thread.
    200205                 * In such case, the CPU will continue to go to sleep
    201206                 * even though there is a runnable thread.
    202207                 */
    203 
    204                  spinlock_lock(&CPU->lock);
    205                  CPU->idle = true;
    206                  spinlock_unlock(&CPU->lock);
    207208                 cpu_sleep();
     209                 interrupts_disable();
    208210                 goto loop;
    209211        }
    210 
    211         interrupts_disable();
    212212       
    213213        for (i = 0; i < RQ_COUNT; i++) {
     
    382382        int priority;
    383383        DEADLOCK_PROBE_INIT(p_joinwq);
     384        task_t *old_task = TASK;
     385        as_t *old_as = AS;
    384386
    385387        ASSERT(CPU != NULL);
    386388       
     389        /*
     390         * Hold the current task and the address space to prevent their
     391         * possible destruction should thread_destroy() be called on this or any
     392         * other processor while the scheduler is still using them.
     393         */
     394        if (old_task)
     395                task_hold(old_task);
     396        if (old_as)
     397                as_hold(old_as);
     398
    387399        if (THREAD) {
    388400                /* must be run after the switch to scheduler stack */
     
    476488         */
    477489        if (TASK != THREAD->task) {
    478                 as_t *as1 = NULL;
    479                 as_t *as2;
    480 
    481                 if (TASK) {
    482                         spinlock_lock(&TASK->lock);
    483                         as1 = TASK->as;
    484                         spinlock_unlock(&TASK->lock);
    485                 }
    486 
    487                 spinlock_lock(&THREAD->task->lock);
    488                 as2 = THREAD->task->as;
    489                 spinlock_unlock(&THREAD->task->lock);
     490                as_t *new_as = THREAD->task->as;
    490491               
    491492                /*
     
    493494                 * space.
    494495                 */
    495                 if (as1 != as2) {
     496                if (old_as != new_as) {
    496497                        /*
    497498                         * Both tasks and address spaces are different.
    498499                         * Replace the old one with the new one.
    499500                         */
    500                         as_switch(as1, as2);
     501                        as_switch(old_as, new_as);
    501502                }
     503
    502504                TASK = THREAD->task;
    503505                before_task_runs();
    504506        }
    505507
     508        if (old_task)
     509                task_release(old_task);
     510        if (old_as)
     511                as_release(old_as);
     512       
    506513        spinlock_lock(&THREAD->lock);   
    507514        THREAD->state = Running;
  • kernel/generic/src/proc/task.c

    r6c39a907 r25a76ab8  
    11/*
    2  * Copyright (c) 2001-2004 Jakub Jermar
     2 * Copyright (c) 2010 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    210210        btree_create(&ta->futexes);
    211211       
     212        /*
     213         * Get a reference to the address space.
     214         */
     215        as_hold(ta->as);
     216
    212217        ipl = interrupts_disable();
    213         atomic_inc(&as->refcount);
    214218        spinlock_lock(&tasks_lock);
    215219        ta->taskid = ++task_counter;
     
    250254         * Drop our reference to the address space.
    251255         */
    252         if (atomic_predec(&t->as->refcount) == 0)
    253                 as_destroy(t->as);
     256        as_release(t->as);
    254257       
    255258        slab_free(task_slab, t);
    256         TASK = NULL;
     259}
     260
     261/** Hold a reference to a task.
     262 *
     263 * Holding a reference to a task prevents destruction of that task.
     264 *
     265 * @param t             Task to be held.
     266 */
     267void task_hold(task_t *t)
     268{
     269        atomic_inc(&t->refcount);
     270}
     271
     272/** Release a reference to a task.
     273 *
     274 * The last one to release a reference to a task destroys the task.
     275 *
     276 * @param t             Task to be released.
     277 */
     278void task_release(task_t *t)
     279{
     280        if ((atomic_predec(&t->refcount)) == 0)
     281                task_destroy(t);
    257282}
    258283
  • kernel/generic/src/proc/thread.c

    r6c39a907 r25a76ab8  
    11/*
    2  * Copyright (c) 2001-2004 Jakub Jermar
     2 * Copyright (c) 2010 Jakub Jermar
    33 * All rights reserved.
    44 *
     
    409409
    410410        /*
    411          * t is guaranteed to be the very last thread of its task.
    412          * It is safe to destroy the task.
     411         * Drop the reference to the containing task.
    413412         */
    414         if (atomic_predec(&t->task->refcount) == 0)
    415                 task_destroy(t->task);
     413        task_release(t->task);
    416414       
    417415        slab_free(thread_slab, t);
     
    436434        spinlock_lock(&task->lock);
    437435
    438         atomic_inc(&task->refcount);
     436        /* Hold a reference to the task. */
     437        task_hold(task);
    439438
    440439        /* Must not count kbox thread into lifecount */
  • kernel/generic/src/synch/mutex.c

    r6c39a907 r25a76ab8  
    4040#include <synch/synch.h>
    4141#include <debug.h>
     42#include <arch.h>
    4243
    4344/** Initialize mutex.
     
    6970        int rc;
    7071
    71         if (mtx->type == MUTEX_PASSIVE) {
     72        if (mtx->type == MUTEX_PASSIVE && THREAD) {
    7273                rc = _semaphore_down_timeout(&mtx->sem, usec, flags);
    7374        } else {
    74                 ASSERT(mtx->type == MUTEX_ACTIVE);
     75                ASSERT(mtx->type == MUTEX_ACTIVE || !THREAD);
    7576                ASSERT(usec == SYNCH_NO_TIMEOUT);
    7677                ASSERT(!(flags & SYNCH_FLAGS_INTERRUPTIBLE));
  • kernel/generic/src/synch/spinlock.c

    r6c39a907 r25a76ab8  
    120120}
    121121
     122/** Unlock spinlock
     123 *
     124 * Unlock spinlock.
     125 *
     126 * @param sl Pointer to spinlock_t structure.
     127 */
     128void spinlock_unlock_debug(spinlock_t *lock)
     129{
     130        ASSERT(atomic_get(&lock->val) != 0);
     131       
     132        /*
     133         * Prevent critical section code from bleeding out this way down.
     134         */
     135        CS_LEAVE_BARRIER();
     136       
     137        atomic_set(&lock->val, 0);
     138        preemption_enable();
     139}
     140
    122141#endif
    123142
  • kernel/generic/src/sysinfo/stats.c

    r6c39a907 r25a76ab8  
    3838#include <sysinfo/stats.h>
    3939#include <sysinfo/sysinfo.h>
     40#include <synch/spinlock.h>
     41#include <synch/mutex.h>
    4042#include <time/clock.h>
    4143#include <mm/frame.h>
     
    6870static load_t avenrdy[LOAD_STEPS] = {0, 0, 0};
    6971
    70 /** Load calculation spinlock */
    71 SPINLOCK_STATIC_INITIALIZE_NAME(load_lock, "load_lock");
     72/** Load calculation lock */
     73static mutex_t load_lock;
    7274
    7375/** Get system uptime
     
    156158static size_t get_task_virtmem(as_t *as)
    157159{
    158         mutex_lock(&as->lock);
    159        
    160160        size_t result = 0;
     161
     162        /*
     163         * We are holding some spinlocks here and therefore are not allowed to
     164         * block. Only attempt to lock the address space and address space area
     165         * mutexes conditionally. If it is not possible to lock either object,
     166         * allow the statistics to be inexact by skipping the respective object.
     167         *
     168         * Note that it may be infinitely better to let the address space
     169         * management code compute these statistics as it proceeds instead of
     170         * having them calculated here over and over again here.
     171         */
     172
     173        if (SYNCH_FAILED(mutex_trylock(&as->lock)))
     174                return result * PAGE_SIZE;
    161175       
    162176        /* Walk the B+ tree and count pages */
     
    171185                        as_area_t *area = node->value[i];
    172186                       
    173                         mutex_lock(&area->lock);
     187                        if (SYNCH_FAILED(mutex_trylock(&area->lock)))
     188                                continue;
    174189                        result += area->pages;
    175190                        mutex_unlock(&area->lock);
     
    331346       
    332347        /* Interrupts are already disabled */
    333         spinlock_lock(&(thread->lock));
     348        spinlock_lock(&thread->lock);
    334349       
    335350        /* Record the statistics and increment the iterator */
     
    337352        (*iterator)++;
    338353       
    339         spinlock_unlock(&(thread->lock));
     354        spinlock_unlock(&thread->lock);
    340355       
    341356        return true;
     
    602617        }
    603618       
    604         /* To always get consistent values acquire the spinlock */
    605         ipl_t ipl = interrupts_disable();
    606         spinlock_lock(&load_lock);
     619        /* To always get consistent values acquire the mutex */
     620        mutex_lock(&load_lock);
    607621       
    608622        unsigned int i;
     
    610624                stats_load[i] = avenrdy[i] << LOAD_FIXED_SHIFT;
    611625       
    612         spinlock_unlock(&load_lock);
    613         interrupts_restore(ipl);
     626        mutex_unlock(&load_lock);
    614627       
    615628        return ((void *) stats_load);
     
    642655               
    643656                /* Mutually exclude with get_stats_load() */
    644                 ipl_t ipl = interrupts_disable();
    645                 spinlock_lock(&load_lock);
     657                mutex_lock(&load_lock);
    646658               
    647659                unsigned int i;
     
    649661                        avenrdy[i] = load_calc(avenrdy[i], load_exp[i], ready);
    650662               
    651                 spinlock_unlock(&load_lock);
    652                 interrupts_restore(ipl);
     663                mutex_unlock(&load_lock);
    653664               
    654665                thread_sleep(LOAD_INTERVAL);
     
    661672void stats_init(void)
    662673{
     674        mutex_initialize(&load_lock, MUTEX_PASSIVE);
     675
    663676        sysinfo_set_item_fn_val("system.uptime", NULL, get_stats_uptime);
    664677        sysinfo_set_item_fn_data("system.cpus", NULL, get_stats_cpus);
  • kernel/generic/src/sysinfo/sysinfo.c

    r6c39a907 r25a76ab8  
    3737#include <print.h>
    3838#include <syscall/copy.h>
    39 #include <synch/spinlock.h>
     39#include <synch/mutex.h>
    4040#include <arch/asm.h>
    4141#include <errno.h>
     
    5252static slab_cache_t *sysinfo_item_slab;
    5353
    54 /** Sysinfo spinlock */
    55 SPINLOCK_STATIC_INITIALIZE_NAME(sysinfo_lock, "sysinfo_lock");
     54/** Sysinfo lock */
     55static mutex_t sysinfo_lock;
    5656
    5757/** Sysinfo item constructor
     
    9898            sizeof(sysinfo_item_t), 0, sysinfo_item_constructor,
    9999            sysinfo_item_destructor, SLAB_CACHE_MAGDEFERRED);
     100
     101        mutex_initialize(&sysinfo_lock, MUTEX_ACTIVE);
    100102}
    101103
    102104/** Recursively find an item in sysinfo tree
    103105 *
    104  * Should be called with interrupts disabled
    105  * and sysinfo_lock held.
     106 * Should be called with sysinfo_lock held.
    106107 *
    107108 * @param name    Current sysinfo path suffix.
     
    168169/** Recursively create items in sysinfo tree
    169170 *
    170  * Should be called with interrupts disabled
    171  * and sysinfo_lock held.
     171 * Should be called with sysinfo_lock held.
    172172 *
    173173 * @param name     Current sysinfo path suffix.
     
    299299{
    300300        /* Protect sysinfo tree consistency */
    301         ipl_t ipl = interrupts_disable();
    302         spinlock_lock(&sysinfo_lock);
     301        mutex_lock(&sysinfo_lock);
    303302       
    304303        if (root == NULL)
     
    311310        }
    312311       
    313         spinlock_unlock(&sysinfo_lock);
    314         interrupts_restore(ipl);
     312        mutex_unlock(&sysinfo_lock);
    315313}
    316314
     
    332330{
    333331        /* Protect sysinfo tree consistency */
    334         ipl_t ipl = interrupts_disable();
    335         spinlock_lock(&sysinfo_lock);
     332        mutex_lock(&sysinfo_lock);
    336333       
    337334        if (root == NULL)
     
    345342        }
    346343       
    347         spinlock_unlock(&sysinfo_lock);
    348         interrupts_restore(ipl);
     344        mutex_unlock(&sysinfo_lock);
    349345}
    350346
     
    361357{
    362358        /* Protect sysinfo tree consistency */
    363         ipl_t ipl = interrupts_disable();
    364         spinlock_lock(&sysinfo_lock);
     359        mutex_lock(&sysinfo_lock);
    365360       
    366361        if (root == NULL)
     
    373368        }
    374369       
    375         spinlock_unlock(&sysinfo_lock);
    376         interrupts_restore(ipl);
     370        mutex_unlock(&sysinfo_lock);
    377371}
    378372
     
    394388{
    395389        /* Protect sysinfo tree consistency */
    396         ipl_t ipl = interrupts_disable();
    397         spinlock_lock(&sysinfo_lock);
     390        mutex_lock(&sysinfo_lock);
    398391       
    399392        if (root == NULL)
     
    406399        }
    407400       
    408         spinlock_unlock(&sysinfo_lock);
    409         interrupts_restore(ipl);
     401        mutex_unlock(&sysinfo_lock);
    410402}
    411403
     
    420412{
    421413        /* Protect sysinfo tree consistency */
    422         ipl_t ipl = interrupts_disable();
    423         spinlock_lock(&sysinfo_lock);
     414        mutex_lock(&sysinfo_lock);
    424415       
    425416        if (root == NULL)
     
    430421                item->val_type = SYSINFO_VAL_UNDEFINED;
    431422       
    432         spinlock_unlock(&sysinfo_lock);
    433         interrupts_restore(ipl);
     423        mutex_unlock(&sysinfo_lock);
    434424}
    435425
     
    446436{
    447437        /* Protect sysinfo tree consistency */
    448         ipl_t ipl = interrupts_disable();
    449         spinlock_lock(&sysinfo_lock);
     438        mutex_lock(&sysinfo_lock);
    450439       
    451440        if (root == NULL)
     
    461450        }
    462451       
    463         spinlock_unlock(&sysinfo_lock);
    464         interrupts_restore(ipl);
     452        mutex_unlock(&sysinfo_lock);
    465453}
    466454
     
    479467/** Dump the structure of sysinfo tree
    480468 *
    481  * Should be called with interrupts disabled
    482  * and sysinfo_lock held. Because this routine
    483  * might take a reasonable long time to proceed,
    484  * having the spinlock held is not optimal, but
    485  * there is no better simple solution.
     469 * Should be called with sysinfo_lock held.
    486470 *
    487471 * @param root  Root item of the current (sub)tree.
     
    559543        /* Avoid other functions to mess with sysinfo
    560544           while we are dumping it */
    561         ipl_t ipl = interrupts_disable();
    562         spinlock_lock(&sysinfo_lock);
     545        mutex_lock(&sysinfo_lock);
    563546       
    564547        if (root == NULL)
     
    567550                sysinfo_dump_internal(root, 0);
    568551       
    569         spinlock_unlock(&sysinfo_lock);
    570         interrupts_restore(ipl);
     552        mutex_unlock(&sysinfo_lock);
    571553}
    572554
    573555/** Return sysinfo item value determined by name
    574556 *
    575  * Should be called with interrupts disabled
    576  * and sysinfo_lock held.
     557 * Should be called with sysinfo_lock held.
    577558 *
    578559 * @param name    Sysinfo path.
     
    632613/** Return sysinfo item determined by name from user space
    633614 *
    634  * Should be called with interrupts disabled
    635  * and sysinfo_lock held. The path string passed from
    636  * the user space has to be properly null-terminated
     615 * The path string passed from the user space has to be properly null-terminated
    637616 * (the last passed character must be null).
    638617 *
     
    656635       
    657636        if ((copy_from_uspace(path, ptr, size + 1) == 0)
    658             && (path[size] == 0))
     637            && (path[size] == 0)) {
     638                /*
     639                 * Prevent other functions from messing with sysinfo while we
     640                 * are reading it.
     641                 */
     642                mutex_lock(&sysinfo_lock);
    659643                ret = sysinfo_get_item(path, NULL, dry_run);
    660        
     644                mutex_unlock(&sysinfo_lock);
     645        }
    661646        free(path);
    662647        return ret;
     
    677662unative_t sys_sysinfo_get_tag(void *path_ptr, size_t path_size)
    678663{
    679         /* Avoid other functions to mess with sysinfo
    680            while we are reading it */
    681         ipl_t ipl = interrupts_disable();
    682         spinlock_lock(&sysinfo_lock);
    683        
    684         /* Get the item.
    685        
    686            N.B.: There is no need to free any potential generated
    687            binary data since we request a dry run */
     664        /*
     665         * Get the item.
     666         *
     667         * N.B.: There is no need to free any potential generated
     668         * binary data since we request a dry run.
     669         */
    688670        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
    689671       
    690         /* Map generated value types to constant types
    691            (user space does not care whether the
    692            value is constant or generated) */
     672        /*
     673         * Map generated value types to constant types (user space does not care
     674         * whether the value is constant or generated).
     675         */
    693676        if (ret.tag == SYSINFO_VAL_FUNCTION_VAL)
    694677                ret.tag = SYSINFO_VAL_VAL;
     
    696679                ret.tag = SYSINFO_VAL_DATA;
    697680       
    698         spinlock_unlock(&sysinfo_lock);
    699         interrupts_restore(ipl);
    700        
    701681        return (unative_t) ret.tag;
    702682}
     
    719699    void *value_ptr)
    720700{
    721         /* Avoid other functions to mess with sysinfo
    722            while we are reading it */
    723         ipl_t ipl = interrupts_disable();
    724         spinlock_lock(&sysinfo_lock);
    725        
    726         /* Get the item.
    727        
    728            N.B.: There is no need to free any potential generated
    729            binary data since we request a dry run */
     701        int rc;
     702
     703        /*
     704         * Get the item.
     705         *
     706         * N.B.: There is no need to free any potential generated binary data
     707         * since we request a dry run.
     708         */
    730709        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
    731         int rc;
    732710       
    733711        /* Only constant or generated numerical value is returned */
     
    737715                rc = EINVAL;
    738716       
    739         spinlock_unlock(&sysinfo_lock);
    740         interrupts_restore(ipl);
    741        
    742717        return (unative_t) rc;
    743718}
     
    760735    void *size_ptr)
    761736{
    762         /* Avoid other functions to mess with sysinfo
    763            while we are reading it */
    764         ipl_t ipl = interrupts_disable();
    765         spinlock_lock(&sysinfo_lock);
    766        
    767         /* Get the item.
    768        
    769            N.B.: There is no need to free any potential generated
    770            binary data since we request a dry run */
     737        int rc;
     738       
     739        /*
     740         * Get the item.
     741         *
     742         * N.B.: There is no need to free any potential generated binary data
     743         * since we request a dry run.
     744         */
    771745        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, true);
    772         int rc;
    773746       
    774747        /* Only the size of constant or generated binary data is considered */
     
    779752                rc = EINVAL;
    780753       
    781         spinlock_unlock(&sysinfo_lock);
    782         interrupts_restore(ipl);
    783        
    784754        return (unative_t) rc;
    785755}
     
    807777    void *buffer_ptr, size_t buffer_size)
    808778{
    809         /* Avoid other functions to mess with sysinfo
    810            while we are reading it */
    811         ipl_t ipl = interrupts_disable();
    812         spinlock_lock(&sysinfo_lock);
     779        int rc;
    813780       
    814781        /* Get the item */
    815782        sysinfo_return_t ret = sysinfo_get_item_uspace(path_ptr, path_size, false);
    816         int rc;
    817        
     783
    818784        /* Only constant or generated binary data is considered */
    819785        if ((ret.tag == SYSINFO_VAL_DATA) || (ret.tag == SYSINFO_VAL_FUNCTION_DATA)) {
     
    831797                free(ret.data.data);
    832798       
    833         spinlock_unlock(&sysinfo_lock);
    834         interrupts_restore(ipl);
    835        
    836799        return (unative_t) rc;
    837800}
  • kernel/generic/src/time/clock.c

    r6c39a907 r25a76ab8  
    140140        /* Account lost ticks to CPU usage */
    141141        if (CPU->idle) {
    142                 ASSERT(missed_clock_ticks == 0);
    143                 CPU->idle_ticks++;
     142                CPU->idle_ticks += missed_clock_ticks + 1;
    144143        } else {
    145144                CPU->busy_ticks += missed_clock_ticks + 1;
Note: See TracChangeset for help on using the changeset viewer.